]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/perl | |
2 | #* | |
3 | #******************************************************************************* | |
4 | #* Copyright (C) 2006, International Business Machines | |
5 | #* Corporation and others. All Rights Reserved. | |
6 | #******************************************************************************* | |
7 | #* | |
8 | #* file name: genheaders.pl | |
9 | #* encoding: US-ASCII | |
10 | #* tab size: 8 (not used) | |
11 | #* indentation:4 | |
12 | #* | |
13 | #* Created by: Ram Viswanadha | |
14 | #* | |
15 | #* This tool filters the deprecated.html and friends file generated by Doxygen and generates udarft.h | |
16 | #* udeprctd.h and uobslete.h | |
17 | #* | |
18 | ||
19 | use File::Find; | |
20 | use File::Basename; | |
21 | use IO::File; | |
22 | use Cwd; | |
23 | use File::Copy; | |
24 | use Getopt::Long; | |
25 | use File::Path; | |
26 | use File::Copy; | |
27 | ||
28 | $draftHeaderName = "udraft.h"; | |
29 | $draftAppend = "DRAFT_API_DO_NOT_USE"; | |
30 | $draftDefine = "U_HIDE_DRAFT_API"; | |
31 | ||
32 | $deprecatedHeaderName = "udeprctd.h"; | |
33 | $deprecatedAppend = "DEPRECATED_API_DO_NOT_USE"; | |
34 | $deprecatedDefine = "U_HIDE_DEPRECATED_API"; | |
35 | ||
36 | $obsoleteHeaderName = "uobslete.h"; | |
37 | $obsoleteAppend = "OBSOLETE_API_DO_NOT_USE"; | |
38 | $obsoleteDefine = "U_HIDE_OBSOLETE_API"; | |
39 | ||
40 | $systemHeaderName = "usystem.h"; | |
41 | $systemAppend = "SYSTEM_API_DO_NOT_USE"; | |
42 | $systemDefine = "U_HIDE_SYSTEM_API"; | |
43 | ||
44 | $internalHeaderName = "uintrnal.h"; | |
45 | $internalAppend = "INTERNAL_API_DO_NOT_USE"; | |
46 | $internalDefine = "U_HIDE_INTERNAL_API"; | |
47 | ||
48 | $versionAppend=""; | |
49 | #run the program | |
50 | main(); | |
51 | ||
52 | #--------------------------------------------------------------------- | |
53 | # The main program | |
54 | ||
55 | sub main(){ | |
56 | GetOptions( | |
57 | "--srcdir=s" => \$srcDir, | |
58 | "--destdir=s" => \$destDir, | |
59 | "--version=s" => \$version, | |
60 | "--exclusion-list=s" => \$exclude, | |
61 | "--include-types" => \$includeTypes | |
62 | ); | |
63 | usage() unless defined $srcDir; | |
64 | usage() unless defined $destDir; | |
65 | usage() unless defined $version; | |
66 | usage() unless defined $exclude; | |
67 | $draftFile = "$srcDir/draft.html"; | |
68 | $deprecatedFile = "$srcDir/deprecated.html"; | |
69 | $obsoleteFile = "$srcDir/obsolete.html"; | |
70 | $systemFile = "$srcDir/system.html"; | |
71 | $internalFile = "$srcDir/internal.html"; | |
72 | ||
73 | $versionAppend = $version; | |
74 | $versionAppend=~ s/\./_/; | |
75 | $excludeFH = IO::File->new($exclude,"r") | |
76 | or die "could not open the file $exclude for reading: $! \n"; | |
77 | my %exclude; | |
78 | while (defined ($line = <$excludeFH>)){ | |
79 | next if( $line =~ /^#/); | |
80 | $line =~ s/^\s+//; | |
81 | $line =~ s/\s+\n$//; | |
82 | $exclude{$line}="EXCLUDE"; | |
83 | } | |
84 | ||
85 | writeFile($draftFile, $draftHeaderName, $destDir, $draftAppend, $draftDefine, \%exclude); | |
86 | writeFile($deprecatedFile, $deprecatedHeaderName, $destDir, $deprecatedAppend, $deprecatedDefine, \%exclude); | |
87 | writeFile($obsoleteFile, $obsoleteHeaderName, $destDir, $obsoleteAppend, $obsoleteDefine, \%exclude); | |
88 | writeFile($systemFile, $systemHeaderName, $destDir, $systemAppend, $systemDefine, \%exclude); | |
89 | writeFile($internalFile, $internalHeaderName, $destDir, $internalAppend, $internalDefine, \%exclude); | |
90 | } | |
91 | ||
92 | #----------------------------------------------------------------------- | |
93 | sub getHeaderDef{ | |
94 | ($headerName) = @_; | |
95 | $headerDef = uc($headerName); # this is building the constant for #define | |
96 | $headerDef =~ s/\./_/; | |
97 | return $headerDef; | |
98 | } | |
99 | ||
100 | #----------------------------------------------------------------------- | |
101 | sub writeFile{ | |
102 | ($infile,$outfile,$destDir, $symbolAppend, $symbolDef, $exclude) = @_; | |
103 | ||
104 | $headerDef = getHeaderDef($outfile); | |
105 | ||
106 | $outfile = $destDir."/".$outfile; | |
107 | ||
108 | $inFH = IO::File->new($infile,"r") | |
109 | or die "could not open the file $infile for reading: $! \n"; | |
110 | $outFH = IO::File->new($outfile,"w") | |
111 | or die "could not open the file $outfile for writing: $! \n"; | |
112 | ||
113 | #print "$headerDef>>> $outfile\n"; | |
114 | printHeader($outFH, $outFileName, $headerDef, $symbolDef); | |
115 | parseWriteFile($inFH, $outFH, $symbolAppend, $exclude); | |
116 | printFooter($outFH, $headerDef, $symbolDef); | |
117 | close($inFH); | |
118 | close($outFH); | |
119 | } | |
120 | ||
121 | #----------------------------------------------------------------------- | |
122 | sub printHeader{ | |
123 | ($outFH, $headername, $HEADERDEF, $symbolDef) = @_; | |
124 | ($DAY, $MONTH, $YEAR) = (localtime)[3,4,5]; | |
125 | $YEAR += 1900; | |
126 | #We will print our copyright here + warnings | |
127 | print $outFH <<END_HEADER_COMMENT; | |
128 | /* | |
129 | ******************************************************************************* | |
130 | * Copyright (C) 2004-$YEAR, International Business Machines | |
131 | * Corporation and others. All Rights Reserved. | |
132 | ******************************************************************************* | |
133 | * | |
134 | * file name: $headername | |
135 | * encoding: US-ASCII | |
136 | * tab size: 8 (not used) | |
137 | * indentation:4 | |
138 | * | |
139 | * Created by: genheaders.pl, a perl script written by Ram Viswanadha | |
140 | * | |
141 | * Contains data for commenting out APIs. | |
142 | * Gets included by umachine.h | |
143 | * | |
144 | * THIS FILE IS MACHINE-GENERATED, DON'T PLAY WITH IT IF YOU DON'T KNOW WHAT | |
145 | * YOU ARE DOING, OTHERWISE VERY BAD THINGS WILL HAPPEN! | |
146 | */ | |
147 | ||
148 | #ifndef $HEADERDEF | |
149 | #define $HEADERDEF | |
150 | ||
151 | #ifdef $symbolDef | |
152 | ||
153 | END_HEADER_COMMENT | |
154 | } | |
155 | ||
156 | #----------------------------------------------------------------------- | |
157 | sub parseWriteFile{ | |
158 | ($inFH, $outFH, $symbolAppend, $exclude) = @_; | |
159 | %disableRenaming; | |
160 | %enableRenaning; | |
161 | while (defined ($line = <$inFH>)){ | |
162 | #just process C APIs for now | |
163 | if($line =~ /\<dt\>/ ){ | |
164 | #special cases | |
165 | if( ($line =~ /LEUnicode/)|| ($line =~ /LanguageCodes/) || | |
166 | ($line =~ /ScriptCodes/) || ($line =~ /\:+/) || | |
167 | ($line =~ /Class/) ){ | |
168 | next; | |
169 | } | |
170 | #<dt>Global <a class="el" href="utrans_8h.html#a21">utrans_unregister</a> </dt> | |
171 | #<dt>Global <a class="el" href="classUnicodeString.html#w1w0">UnicodeString::kInvariant</a> </dt> | |
172 | # the below regular expression works for both the above formats. | |
173 | $line=~ m/\<dt\>.*\<a class=\".*\" href=\".*\">(.*)\<\/dt\>/; | |
174 | my $value = $1; | |
175 | $value =~ s/\<\/a\>\s*//g; | |
176 | $value =~ s/^\s+//; | |
177 | $value =~ s/\s+$//; | |
178 | #print "$exclude->{$value}\n"; | |
179 | if($exclude->{$value} eq "EXCLUDE"){ | |
180 | #print "$value $exclude->{$value}\n"; | |
181 | next; | |
182 | } | |
183 | #print "$value $realSymbol $nonExSymbol\n"; | |
184 | next if(isStringAcceptable($value)==1); | |
185 | $realSymbol = $value."_".$versionAppend; | |
186 | $nonExSymbol = $value."_".$symbolAppend; | |
187 | $disableRenaming{$value} = $nonExSymbol; | |
188 | $enableRenaming{$realSymbol} = $nonExSymbol; | |
189 | #print "$value $realSymbol $nonExSymbol\n"; | |
190 | ||
191 | } | |
192 | } | |
193 | print "size of disableRenaming: " . keys( %disableRenaming) . ".\n"; | |
194 | print "size of enableRenaming: " . keys( %enableRenaming) . ".\n"; | |
195 | print $outFH "# if U_DISABLE_RENAMING\n"; | |
196 | foreach $key (sort (keys(%disableRenaming))) { | |
197 | print $outFH "# define $key $disableRenaming{$key}\n"; | |
198 | delete($disableRenaming{$key}); | |
199 | } | |
200 | print $outFH "# else\n"; | |
201 | foreach $key (sort (keys(%enableRenaming))) { | |
202 | print $outFH "# define $key $enableRenaming{$key}\n"; | |
203 | delete($enableRenaming{$key}); | |
204 | } | |
205 | print $outFH "# endif /* U_DISABLE_RENAMING */\n"; | |
206 | } | |
207 | #----------------------------------------------------------------------- | |
208 | sub isStringAcceptable{ | |
209 | ($string) = @_; | |
210 | @str = split(//, $string); | |
211 | $ret = 1; | |
212 | foreach $val (@str){ | |
213 | if(($val ne "_") && !($val =~ /[0-9A-Z]/)){ | |
214 | #print "$val\n"; | |
215 | $ret = 0; | |
216 | } | |
217 | } | |
218 | #print "$string : $ret\n"; | |
219 | if(!(defined $includeTypes)){ | |
220 | if($ret==0 && $str[0] eq 'U'){ | |
221 | $ret=1; | |
222 | } | |
223 | } | |
224 | return $ret; | |
225 | } | |
226 | ||
227 | #----------------------------------------------------------------------- | |
228 | sub printFooter{ | |
229 | ||
230 | ($outFH, $headerDef, $symbolDef ) = @_; | |
231 | #print the footer | |
232 | print $outFH <<END_FOOTER; | |
233 | ||
234 | #endif /* $symbolDef */ | |
235 | #endif /* $headerDef */ | |
236 | ||
237 | END_FOOTER | |
238 | } | |
239 | #----------------------------------------------------------------------- | |
240 | sub usage { | |
241 | print << "END"; | |
242 | Usage: | |
243 | gendraft.pl | |
244 | Options: | |
245 | --srcdir=<directory> | |
246 | --destdir=<directory> | |
247 | --version=<current version of ICU> | |
248 | --exclusion-list=<file name> | |
249 | --include-types | |
250 | e.g.: genheaders.pl --srcdir=<icu>/source/common/docs/html --destdir=<icu>/source/common/unicode --version=2.8 --exclusion-list=exclude.txt | |
251 | END | |
252 | exit(0); | |
253 | } |