Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | #!/usr/bin/perl |
michael@0 | 2 | #* |
michael@0 | 3 | #******************************************************************************* |
michael@0 | 4 | #* Copyright (C) 2001-2012, International Business Machines |
michael@0 | 5 | #* Corporation and others. All Rights Reserved. |
michael@0 | 6 | #******************************************************************************* |
michael@0 | 7 | #* |
michael@0 | 8 | #* file name: genren.pl |
michael@0 | 9 | #* encoding: US-ASCII |
michael@0 | 10 | #* tab size: 8 (not used) |
michael@0 | 11 | #* indentation:4 |
michael@0 | 12 | #* |
michael@0 | 13 | #* Created by: Vladimir Weinstein |
michael@0 | 14 | #* 07/19/2001 |
michael@0 | 15 | #* |
michael@0 | 16 | #* Used to generate renaming headers. |
michael@0 | 17 | #* Run on UNIX platforms (linux) in order to catch all the exports |
michael@0 | 18 | |
michael@0 | 19 | use POSIX qw(strftime); |
michael@0 | 20 | |
michael@0 | 21 | $headername = 'urename.h'; |
michael@0 | 22 | |
michael@0 | 23 | $path = substr($0, 0, rindex($0, "/")+1)."../../common/unicode/uversion.h"; |
michael@0 | 24 | |
michael@0 | 25 | $nmopts = '-Cg -f s'; |
michael@0 | 26 | $post = ''; |
michael@0 | 27 | |
michael@0 | 28 | $mode = 'POSIX'; |
michael@0 | 29 | |
michael@0 | 30 | (-e $path) || die "Cannot find uversion.h"; |
michael@0 | 31 | |
michael@0 | 32 | open(UVERSION, $path); |
michael@0 | 33 | |
michael@0 | 34 | while(<UVERSION>) { |
michael@0 | 35 | if(/\#define U_ICU_VERSION_SUFFIX/) { |
michael@0 | 36 | chop; |
michael@0 | 37 | s/\#define U_ICU_VERSION_SUFFIX //; |
michael@0 | 38 | $U_ICU_VERSION_SUFFIX = "$_"; |
michael@0 | 39 | last; |
michael@0 | 40 | } |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | while($ARGV[0] =~ /^-/) { # detects whether there are any arguments |
michael@0 | 44 | $_ = shift @ARGV; # extracts the argument for processing |
michael@0 | 45 | /^-v/ && ($VERBOSE++, next); # verbose |
michael@0 | 46 | /^-h/ && (&printHelpMsgAndExit, next); # help |
michael@0 | 47 | /^-o/ && (($headername = shift (@ARGV)), next); # output file |
michael@0 | 48 | /^-n/ && (($nmopts = shift (@ARGV)), next); # nm opts |
michael@0 | 49 | /^-p/ && (($post = shift (@ARGV)), next); # nm opts |
michael@0 | 50 | /^-x/ && (($mode = shift (@ARGV)), next); # nm opts |
michael@0 | 51 | /^-S/ && (($U_ICU_VERSION_SUFFIX = shift(@ARGV)), next); # pick the suffix |
michael@0 | 52 | warn("Invalid option $_\n"); |
michael@0 | 53 | &printHelpMsgAndExit; |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | unless(@ARGV > 0) { |
michael@0 | 57 | warn "No libraries, exiting...\n"; |
michael@0 | 58 | &printHelpMsgAndExit; |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | #$headername = "uren".substr($ARGV[0], 6, index(".", $ARGV[0])-7).".h"; |
michael@0 | 62 | |
michael@0 | 63 | $HEADERDEF = uc($headername); # this is building the constant for #define |
michael@0 | 64 | $HEADERDEF =~ s/\./_/; |
michael@0 | 65 | |
michael@0 | 66 | |
michael@0 | 67 | open HEADER, ">$headername"; # opening a header file |
michael@0 | 68 | |
michael@0 | 69 | #We will print our copyright here + warnings |
michael@0 | 70 | |
michael@0 | 71 | $YEAR = strftime "%Y",localtime; |
michael@0 | 72 | |
michael@0 | 73 | print HEADER <<"EndOfHeaderComment"; |
michael@0 | 74 | /* |
michael@0 | 75 | ******************************************************************************* |
michael@0 | 76 | * Copyright (C) 2002-$YEAR, International Business Machines |
michael@0 | 77 | * Corporation and others. All Rights Reserved. |
michael@0 | 78 | ******************************************************************************* |
michael@0 | 79 | * |
michael@0 | 80 | * file name: $headername |
michael@0 | 81 | * encoding: US-ASCII |
michael@0 | 82 | * tab size: 8 (not used) |
michael@0 | 83 | * indentation:4 |
michael@0 | 84 | * |
michael@0 | 85 | * Created by: Perl script tools/genren.pl written by Vladimir Weinstein |
michael@0 | 86 | * |
michael@0 | 87 | * Contains data for renaming ICU exports. |
michael@0 | 88 | * Gets included by umachine.h |
michael@0 | 89 | * |
michael@0 | 90 | * THIS FILE IS MACHINE-GENERATED, DON'T PLAY WITH IT IF YOU DON'T KNOW WHAT |
michael@0 | 91 | * YOU ARE DOING, OTHERWISE VERY BAD THINGS WILL HAPPEN! |
michael@0 | 92 | */ |
michael@0 | 93 | |
michael@0 | 94 | #ifndef $HEADERDEF |
michael@0 | 95 | #define $HEADERDEF |
michael@0 | 96 | |
michael@0 | 97 | /* U_DISABLE_RENAMING can be defined in the following ways: |
michael@0 | 98 | * - when running configure, e.g. |
michael@0 | 99 | * runConfigureICU Linux --disable-renaming |
michael@0 | 100 | * - by changing the default setting of U_DISABLE_RENAMING in uconfig.h |
michael@0 | 101 | */ |
michael@0 | 102 | |
michael@0 | 103 | #include "unicode/uconfig.h" |
michael@0 | 104 | |
michael@0 | 105 | #if !U_DISABLE_RENAMING |
michael@0 | 106 | |
michael@0 | 107 | /* We need the U_ICU_ENTRY_POINT_RENAME definition. There's a default one in unicode/uvernum.h we can use, but we will give |
michael@0 | 108 | the platform a chance to define it first. |
michael@0 | 109 | Normally (if utypes.h or umachine.h was included first) this will not be necessary as it will already be defined. |
michael@0 | 110 | */ |
michael@0 | 111 | |
michael@0 | 112 | #ifndef U_ICU_ENTRY_POINT_RENAME |
michael@0 | 113 | #include "unicode/umachine.h" |
michael@0 | 114 | #endif |
michael@0 | 115 | |
michael@0 | 116 | /* If we still don't have U_ICU_ENTRY_POINT_RENAME use the default. */ |
michael@0 | 117 | #ifndef U_ICU_ENTRY_POINT_RENAME |
michael@0 | 118 | #include "unicode/uvernum.h" |
michael@0 | 119 | #endif |
michael@0 | 120 | |
michael@0 | 121 | /* Error out before the following defines cause very strange and unexpected code breakage */ |
michael@0 | 122 | #ifndef U_ICU_ENTRY_POINT_RENAME |
michael@0 | 123 | #error U_ICU_ENTRY_POINT_RENAME is not defined - cannot continue. Consider defining U_DISABLE_RENAMING if renaming should not be used. |
michael@0 | 124 | #endif |
michael@0 | 125 | |
michael@0 | 126 | EndOfHeaderComment |
michael@0 | 127 | |
michael@0 | 128 | $fileCount = 0; |
michael@0 | 129 | $itemCount = 0; |
michael@0 | 130 | $symbolCount = 0; |
michael@0 | 131 | |
michael@0 | 132 | for(;@ARGV; shift(@ARGV)) { |
michael@0 | 133 | $fileCount++; |
michael@0 | 134 | @NMRESULT = `nm $nmopts $ARGV[0] $post`; |
michael@0 | 135 | if($?) { |
michael@0 | 136 | warn "Couldn't do 'nm' for $ARGV[0], continuing...\n"; |
michael@0 | 137 | next; # Couldn't do nm for the file |
michael@0 | 138 | } |
michael@0 | 139 | if($mode =~ /POSIX/) { |
michael@0 | 140 | splice @NMRESULT, 0, 6; |
michael@0 | 141 | } elsif ($mode =~ /Mach-O/) { |
michael@0 | 142 | # splice @NMRESULT, 0, 10; |
michael@0 | 143 | } |
michael@0 | 144 | foreach (@NMRESULT) { # Process every line of result and stuff it in $_ |
michael@0 | 145 | $itemCount++; |
michael@0 | 146 | if($mode =~ /POSIX/) { |
michael@0 | 147 | &verbose(" $_"); |
michael@0 | 148 | ($_, $address, $type) = split(/\|/); |
michael@0 | 149 | chop $qtype; |
michael@0 | 150 | } elsif ($mode =~ /Mach-O/) { |
michael@0 | 151 | ($address, $type, $_) = split(/ /); |
michael@0 | 152 | if(/^_(.*)$/) { |
michael@0 | 153 | $_ = $1; |
michael@0 | 154 | } else { |
michael@0 | 155 | next; |
michael@0 | 156 | } |
michael@0 | 157 | } else { |
michael@0 | 158 | die "Unknown mode $mode"; |
michael@0 | 159 | } |
michael@0 | 160 | &verbose( "type: \"$type\" "); |
michael@0 | 161 | if(!($type =~ /[UAwW?]/)) { |
michael@0 | 162 | if(/@@/) { # These would be imports |
michael@0 | 163 | &verbose( "Import: $_ \"$type\"\n"); |
michael@0 | 164 | &verbose( "C++ method: $_\n"); |
michael@0 | 165 | } elsif (/^[^\(]*::/) { # C++ methods, stuff class name in associative array |
michael@0 | 166 | ## DON'T match ... ( foo::bar ... want :: to be to the left of paren |
michael@0 | 167 | ## icu::CharString::~CharString(void) -> CharString |
michael@0 | 168 | @CppName = split(/::/); ## remove scope stuff |
michael@0 | 169 | |
michael@0 | 170 | if(@CppName>1) { |
michael@0 | 171 | ## MessageFormat virtual table -> MessageFormat |
michael@0 | 172 | if(! ($CppName[0] =~ /icu/ )) { |
michael@0 | 173 | # *** WARNING Bad namespace (not 'icu') on ShoeSize::ShoeSize() |
michael@0 | 174 | warn "*** WARNING Bad namespace (not 'icu') on $_\n"; |
michael@0 | 175 | next; |
michael@0 | 176 | } |
michael@0 | 177 | &verbose ( "(Chopping scope $CppName[0] )"); |
michael@0 | 178 | @CppName = split(/ /, $CppName[1]); ## remove debug stuff |
michael@0 | 179 | } |
michael@0 | 180 | ## ures_getUnicodeStringByIndex(UResourceBundle -> ures_getUnicodeStringByIndex |
michael@0 | 181 | @CppName = split(/\(/, $CppName[0]); ## remove function args |
michael@0 | 182 | if($CppName[0] =~ /^operator/) { |
michael@0 | 183 | &verbose ("Skipping C++ function: $_\n"); |
michael@0 | 184 | } elsif($CppName[0] =~ /^~/) { |
michael@0 | 185 | &verbose ("Skipping C++ destructor: $_\n"); |
michael@0 | 186 | } else { |
michael@0 | 187 | &verbose( "Skipping C++ class: '$CppName[0]': $_ \n"); |
michael@0 | 188 | # $CppClasses{$CppName[0]}++; |
michael@0 | 189 | # $symbolCount++; |
michael@0 | 190 | } |
michael@0 | 191 | } elsif ( my ($cfn) = m/^([A-Za-z0-9_]*)\(.*/ ) { |
michael@0 | 192 | &verbose ( "$ARGV[0]: got global C++ function $cfn with '$_'\n" ); |
michael@0 | 193 | $CFuncs{$cfn}++; |
michael@0 | 194 | $symbolCount++; |
michael@0 | 195 | } elsif ( /\(/) { # These are strange functions |
michael@0 | 196 | print STDERR "$ARGV[0]: Not sure what to do with '$_'\n"; |
michael@0 | 197 | } elsif ( /^_init/ ) { |
michael@0 | 198 | &verbose( "$ARGV[0]: Skipped initializer $_\n" ); |
michael@0 | 199 | } elsif ( /^_fini/ ) { |
michael@0 | 200 | &verbose( "$ARGV[0]: Skipped finilizer $_\n" ); |
michael@0 | 201 | } elsif ( /icu_/) { |
michael@0 | 202 | print STDERR "$ARGV[0]: Skipped strange mangled function $_\n"; |
michael@0 | 203 | } elsif ( /^vtable for /) { |
michael@0 | 204 | print STDERR "$ARGV[0]: Skipped vtable $_\n"; |
michael@0 | 205 | } elsif ( /^typeinfo/) { |
michael@0 | 206 | print STDERR "$ARGV[0]: Skipped typeinfo $_\n"; |
michael@0 | 207 | } elsif ( /operator\+/ ) { |
michael@0 | 208 | print STDERR "$ARGV[0]: Skipped ignored function $_\n"; |
michael@0 | 209 | } else { # This is regular C function |
michael@0 | 210 | &verbose( "C func: $_\n"); |
michael@0 | 211 | @funcname = split(/[\(\s+]/); |
michael@0 | 212 | $CFuncs{$funcname[0]}++; |
michael@0 | 213 | $symbolCount++; |
michael@0 | 214 | } |
michael@0 | 215 | } else { |
michael@0 | 216 | &verbose( "Skipped: $_ $1\n"); |
michael@0 | 217 | } |
michael@0 | 218 | } |
michael@0 | 219 | } |
michael@0 | 220 | |
michael@0 | 221 | if( $fileCount == 0 ) { |
michael@0 | 222 | die "Error: $itemCount lines from $fileCount files processed, but $symbolCount symbols were found.\n"; |
michael@0 | 223 | } |
michael@0 | 224 | |
michael@0 | 225 | if( $symbolCount == 0 ) { |
michael@0 | 226 | die "Error: $itemCount lines from $fileCount files processed, but $symbolCount symbols were found.\n"; |
michael@0 | 227 | } |
michael@0 | 228 | |
michael@0 | 229 | print " Loaded $symbolCount symbols from $itemCount lines in $fileCount files.\n"; |
michael@0 | 230 | |
michael@0 | 231 | print HEADER "\n/* C exports renaming data */\n\n"; |
michael@0 | 232 | foreach(sort keys(%CFuncs)) { |
michael@0 | 233 | print HEADER "#define $_ U_ICU_ENTRY_POINT_RENAME($_)\n"; |
michael@0 | 234 | # print HEADER "#define $_ $_$U_ICU_VERSION_SUFFIX\n"; |
michael@0 | 235 | } |
michael@0 | 236 | |
michael@0 | 237 | print HEADER "\n#endif\n"; |
michael@0 | 238 | print HEADER "\n#endif\n"; |
michael@0 | 239 | |
michael@0 | 240 | close HEADER; |
michael@0 | 241 | |
michael@0 | 242 | sub verbose { |
michael@0 | 243 | if($VERBOSE) { |
michael@0 | 244 | print STDERR @_; |
michael@0 | 245 | } |
michael@0 | 246 | } |
michael@0 | 247 | |
michael@0 | 248 | |
michael@0 | 249 | sub printHelpMsgAndExit { |
michael@0 | 250 | print STDERR <<"EndHelpText"; |
michael@0 | 251 | Usage: $0 [OPTIONS] LIBRARY_FILES |
michael@0 | 252 | Options: |
michael@0 | 253 | -v - verbose |
michael@0 | 254 | -h - help |
michael@0 | 255 | -o - output file name (defaults to 'urename.h' |
michael@0 | 256 | -S - suffix (defaults to _MAJOR_MINOR of current ICU version) |
michael@0 | 257 | Will produce a renaming .h file |
michael@0 | 258 | |
michael@0 | 259 | EndHelpText |
michael@0 | 260 | |
michael@0 | 261 | exit 0; |
michael@0 | 262 | |
michael@0 | 263 | } |