]>
git.saurik.com Git - apple/icu.git/blob - icuSources/tools/genren/genren.pl
3 #*******************************************************************************
4 #* Copyright (C) 2001-2008, International Business Machines
5 #* Corporation and others. All Rights Reserved.
6 #*******************************************************************************
8 #* file name: genren.pl
10 #* tab size: 8 (not used)
13 #* Created by: Vladimir Weinstein
16 #* Used to generate renaming headers.
17 #* Run on UNIX platforms (linux) in order to catch all the exports
19 $headername = 'urename.h';
21 $path = substr($0, 0, rindex($0, "/")+1)."../../common/unicode/uversion.h";
28 (-e
$path) || die "Cannot find uversion.h";
30 open(UVERSION
, $path);
33 if(/\#define U_ICU_VERSION_SUFFIX/) {
35 s/\#define U_ICU_VERSION_SUFFIX //;
36 $U_ICU_VERSION_SUFFIX = "$_";
41 while($ARGV[0] =~ /^-/) { # detects whether there are any arguments
42 $_ = shift @ARGV; # extracts the argument for processing
43 /^-v/ && ($VERBOSE++, next); # verbose
44 /^-h/ && (&printHelpMsgAndExit
, next); # help
45 /^-o/ && (($headername = shift (@ARGV)), next); # output file
46 /^-n/ && (($nmopts = shift (@ARGV)), next); # nm opts
47 /^-p/ && (($post = shift (@ARGV)), next); # nm opts
48 /^-x/ && (($mode = shift (@ARGV)), next); # nm opts
49 /^-S/ && (($U_ICU_VERSION_SUFFIX = shift(@ARGV)), next); # pick the suffix
50 warn("Invalid option $_\n");
55 warn "No libraries, exiting...\n";
59 #$headername = "uren".substr($ARGV[0], 6, index(".", $ARGV[0])-7).".h";
61 $HEADERDEF = uc($headername); # this is building the constant for #define
62 $HEADERDEF =~ s/\./_/;
65 open HEADER
, ">$headername"; # opening a header file
67 #We will print our copyright here + warnings
68 print HEADER
<<"EndOfHeaderComment";
70 *******************************************************************************
71 * Copyright (C) 2002-2008, International Business Machines
72 * Corporation and others. All Rights Reserved.
73 *******************************************************************************
75 * file name: $headername
77 * tab size: 8 (not used)
80 * Created by: Perl script written by Vladimir Weinstein
82 * Contains data for renaming ICU exports.
83 * Gets included by umachine.h
85 * THIS FILE IS MACHINE-GENERATED, DON'T PLAY WITH IT IF YOU DON'T KNOW WHAT
86 * YOU ARE DOING, OTHERWISE VERY BAD THINGS WILL HAPPEN!
92 /* Uncomment the following line to disable renaming on platforms
93 that do not use Autoconf. */
94 /* #define U_DISABLE_RENAMING 1 */
96 #if !U_DISABLE_RENAMING
99 for(;@ARGV; shift(@ARGV)) {
100 @NMRESULT = `nm $nmopts $ARGV[0] $post`;
102 warn "Couldn't do 'nm' for $ARGV[0], continuing...\n";
103 next; # Couldn't do nm for the file
105 if($mode =~ /POSIX/) {
106 splice @NMRESULT, 0, 6;
107 } elsif ($mode =~ /Mach-O/) {
108 # splice @NMRESULT, 0, 10;
110 foreach (@NMRESULT) { # Process every line of result and stuff it in $_
111 if($mode =~ /POSIX/) {
112 ($_, $address, $type) = split(/\|/);
113 } elsif ($mode =~ /Mach-O/) {
114 if(/^(?:[0-9a-fA-F]){8} ([A-Z]) (?:_)?(.*)$/) {
115 ($_, $type) = ($2, $1);
120 die "Unknown mode $mode";
122 &verbose( "type: \"$type\" ");
123 if(!($type =~ /[UAwW?]/)) {
124 if(/@@/) { # These would be imports
125 &verbose( "Import: $_ \"$type\"\n");
126 } elsif (/::/) { # C++ methods, stuff class name in associative array
127 &verbose( "C++ method: $_\n");
128 ## icu_2_0::CharString::~CharString(void) -> CharString
129 @CppName = split(/::/); ## remove scope stuff
131 ## MessageFormat virtual table -> MessageFormat
132 @CppName = split(/ /, $CppName[1]); ## remove debug stuff
134 ## ures_getUnicodeStringByIndex(UResourceBundle -> ures_getUnicodeStringByIndex
135 @CppName = split(/\(/, $CppName[0]); ## remove function args
136 if($CppName[0] =~ /^operator/) {
137 &verbose ("Skipping C++ function: $_\n");
138 } elsif($CppName[0] =~ /^~/) {
139 &verbose ("Skipping C++ destructor: $_\n");
141 $CppClasses{$CppName[0]}++;
143 } elsif ( /\(/) { # These are strange functions
146 print STDERR "Skipped strange mangled function $_\n";
147 } elsif ( /^vtable for /) {
148 print STDERR "Skipped vtable $_\n";
149 } elsif ( /^typeinfo for /) {
150 print STDERR "Skipped typeinfo $_\n";
151 } elsif ( /operator\+/ ) {
152 print STDERR "Skipped ignored function $_\n";
153 } else { # This is regular C function
154 &verbose( "C func: $_\n");
155 @funcname = split(/[\(\s+]/);
156 $CFuncs{$funcname[0]}++;
159 &verbose( "Skipped: $_ $1\n");
164 print HEADER "\n/* C exports renaming data */\n\n";
165 foreach(sort keys(%CFuncs)) {
166 print HEADER "#define $_ $_$U_ICU_VERSION_SUFFIX\n";
169 print HEADER "/* C++ class names renaming defines */\n\n";
170 print HEADER "#ifdef XP_CPLUSPLUS\n";
171 print HEADER "#if !U_HAVE_NAMESPACE\n\n";
172 foreach(sort keys(%CppClasses)) {
173 print HEADER "#define $_ $_$U_ICU_VERSION_SUFFIX\n";
175 print HEADER "\n#endif\n";
176 print HEADER "#endif\n";
177 print HEADER "\n#endif\n";
178 print HEADER "\n#endif\n";
189 sub printHelpMsgAndExit {
190 print STDERR <<"EndHelpText";
191 Usage: $0 [OPTIONS] LIBRARY_FILES
195 -o - output file name (defaults to 'urename.h'
196 -S - suffix (defaults to _MAJOR_MINOR of current ICU version)
197 Will produce a renaming .h file