]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/perl | |
2 | #* | |
3 | #******************************************************************************* | |
4 | #* Copyright (C) 2001-2006, International Business Machines | |
5 | #* Corporation and others. All Rights Reserved. | |
6 | #******************************************************************************* | |
7 | #* | |
8 | #* file name: genren.pl | |
9 | #* encoding: US-ASCII | |
10 | #* tab size: 8 (not used) | |
11 | #* indentation:4 | |
12 | #* | |
13 | #* Created by: Vladimir Weinstein | |
14 | #* 07/19/2001 | |
15 | #* | |
16 | #* Used to generate renaming headers. | |
17 | #* Run on UNIX platforms (linux) in order to catch all the exports | |
18 | ||
19 | $headername = 'urename.h'; | |
20 | ||
21 | $path = substr($0, 0, rindex($0, "/")+1)."../../common/unicode/uversion.h"; | |
22 | ||
23 | (-e $path) || die "Cannot find uversion.h"; | |
24 | ||
25 | open(UVERSION, $path); | |
26 | ||
27 | while(<UVERSION>) { | |
28 | if(/\#define U_ICU_VERSION_SUFFIX/) { | |
29 | chop; | |
30 | s/\#define U_ICU_VERSION_SUFFIX //; | |
31 | $U_ICU_VERSION_SUFFIX = "$_"; | |
32 | last; | |
33 | } | |
34 | } | |
35 | ||
36 | while($ARGV[0] =~ /^-/) { # detects whether there are any arguments | |
37 | $_ = shift @ARGV; # extracts the argument for processing | |
38 | /^-v/ && ($VERBOSE++, next); # verbose | |
39 | /^-h/ && (&printHelpMsgAndExit, next); # help | |
40 | /^-o/ && (($headername = shift (@ARGV)), next); # output file | |
41 | /^-S/ && (($U_ICU_VERSION_SUFFIX = shift(@ARGV)), next); # pick the suffix | |
42 | warn("Invalid option $_\n"); | |
43 | &printHelpMsgAndExit; | |
44 | } | |
45 | ||
46 | unless(@ARGV > 0) { | |
47 | warn "No libraries, exiting...\n"; | |
48 | &printHelpMsgAndExit; | |
49 | } | |
50 | ||
51 | #$headername = "uren".substr($ARGV[0], 6, index(".", $ARGV[0])-7).".h"; | |
52 | ||
53 | $HEADERDEF = uc($headername); # this is building the constant for #define | |
54 | $HEADERDEF =~ s/\./_/; | |
55 | ||
56 | ||
57 | open HEADER, ">$headername"; # opening a header file | |
58 | ||
59 | #We will print our copyright here + warnings | |
60 | print HEADER <<"EndOfHeaderComment"; | |
61 | /* | |
62 | ******************************************************************************* | |
63 | * Copyright (C) 2002-2006, International Business Machines | |
64 | * Corporation and others. All Rights Reserved. | |
65 | ******************************************************************************* | |
66 | * | |
67 | * file name: $headername | |
68 | * encoding: US-ASCII | |
69 | * tab size: 8 (not used) | |
70 | * indentation:4 | |
71 | * | |
72 | * Created by: Perl script written by Vladimir Weinstein | |
73 | * | |
74 | * Contains data for renaming ICU exports. | |
75 | * Gets included by umachine.h | |
76 | * | |
77 | * THIS FILE IS MACHINE-GENERATED, DON'T PLAY WITH IT IF YOU DON'T KNOW WHAT | |
78 | * YOU ARE DOING, OTHERWISE VERY BAD THINGS WILL HAPPEN! | |
79 | */ | |
80 | ||
81 | #ifndef $HEADERDEF | |
82 | #define $HEADERDEF | |
83 | ||
84 | /* Uncomment the following line to disable renaming on platforms | |
85 | that do not use Autoconf. */ | |
86 | /* #define U_DISABLE_RENAMING 1 */ | |
87 | ||
88 | #if !U_DISABLE_RENAMING | |
89 | EndOfHeaderComment | |
90 | ||
91 | for(;@ARGV; shift(@ARGV)) { | |
92 | @NMRESULT = `nm -Cg -f s $ARGV[0]`; | |
93 | if($?) { | |
94 | warn "Couldn't do 'nm' for $ARGV[0], continuing...\n"; | |
95 | next; # Couldn't do nm for the file | |
96 | } | |
97 | splice @NMRESULT, 0, 6; | |
98 | ||
99 | foreach (@NMRESULT) { # Process every line of result and stuff it in $_ | |
100 | ($_, $address, $type) = split(/\|/); | |
101 | &verbose( "type: \"$type\" "); | |
102 | if(!($type =~ /[UAwW?]/)) { | |
103 | if(/@@/) { # These would be imports | |
104 | &verbose( "Import: $_ \"$type\"\n"); | |
105 | } elsif (/::/) { # C++ methods, stuff class name in associative array | |
106 | &verbose( "C++ method: $_\n"); | |
107 | ## icu_2_0::CharString::~CharString(void) -> CharString | |
108 | @CppName = split(/::/); ## remove scope stuff | |
109 | if(@CppName>1) { | |
110 | ## MessageFormat virtual table -> MessageFormat | |
111 | @CppName = split(/ /, $CppName[1]); ## remove debug stuff | |
112 | } | |
113 | ## ures_getUnicodeStringByIndex(UResourceBundle -> ures_getUnicodeStringByIndex | |
114 | @CppName = split(/\(/, $CppName[0]); ## remove function args | |
115 | $CppClasses{$CppName[0]}++; | |
116 | } elsif ( /\(/) { # These are strange functions | |
117 | print STDERR "$_\n"; | |
118 | } elsif ( /icu_/) { | |
119 | print STDERR "Skipped strange mangled function $_\n"; | |
120 | } else { # This is regular C function | |
121 | &verbose( "C func: $_\n"); | |
122 | @funcname = split(/[\(\s+]/); | |
123 | $CFuncs{$funcname[0]}++; | |
124 | } | |
125 | } else { | |
126 | &verbose( "Skipped: $_ $1\n"); | |
127 | } | |
128 | } | |
129 | } | |
130 | ||
131 | print HEADER "\n/* C exports renaming data */\n\n"; | |
132 | foreach(sort keys(%CFuncs)) { | |
133 | print HEADER "#define $_ $_$U_ICU_VERSION_SUFFIX\n"; | |
134 | } | |
135 | ||
136 | print HEADER "/* C++ class names renaming defines */\n\n"; | |
137 | print HEADER "#ifdef XP_CPLUSPLUS\n"; | |
138 | print HEADER "#if !U_HAVE_NAMESPACE\n\n"; | |
139 | foreach(sort keys(%CppClasses)) { | |
140 | print HEADER "#define $_ $_$U_ICU_VERSION_SUFFIX\n"; | |
141 | } | |
142 | print HEADER "\n#endif\n"; | |
143 | print HEADER "#endif\n"; | |
144 | print HEADER "\n#endif\n"; | |
145 | print HEADER "\n#endif\n"; | |
146 | ||
147 | close HEADER; | |
148 | ||
149 | sub verbose { | |
150 | if($VERBOSE) { | |
151 | print STDERR @_; | |
152 | } | |
153 | } | |
154 | ||
155 | ||
156 | sub printHelpMsgAndExit { | |
157 | print STDERR <<"EndHelpText"; | |
158 | Usage: $0 [OPTIONS] LIBRARY_FILES | |
159 | Options: | |
160 | -v - verbose | |
161 | -h - help | |
162 | -o - output file name (defaults to 'urename.h' | |
163 | -S - suffix (defaults to _MAJOR_MINOR of current ICU version) | |
164 | Will produce a renaming .h file | |
165 | ||
166 | EndHelpText | |
167 | ||
168 | exit 0; | |
169 | ||
170 | } | |
171 |