]>
git.saurik.com Git - apple/icu.git/blob - icuSources/tools/gendraft/genheaders.pl
3 #*******************************************************************************
4 #* Copyright (C) 2006-2011, International Business Machines
5 #* Corporation and others. All Rights Reserved.
6 #*******************************************************************************
8 #* file name: genheaders.pl
10 #* tab size: 8 (not used)
13 #* Created by: Ram Viswanadha
15 #* This tool filters the deprecated.html and friends file generated by Doxygen and generates udarft.h
16 #* udeprctd.h and uobslete.h
28 $draftHeaderName = "udraft.h";
29 $draftAppend = "DRAFT_API_DO_NOT_USE";
30 $draftDefine = "U_HIDE_DRAFT_API";
32 $deprecatedHeaderName = "udeprctd.h";
33 $deprecatedAppend = "DEPRECATED_API_DO_NOT_USE";
34 $deprecatedDefine = "U_HIDE_DEPRECATED_API";
36 $obsoleteHeaderName = "uobslete.h";
37 $obsoleteAppend = "OBSOLETE_API_DO_NOT_USE";
38 $obsoleteDefine = "U_HIDE_OBSOLETE_API";
40 $systemHeaderName = "usystem.h";
41 $systemAppend = "SYSTEM_API_DO_NOT_USE";
42 $systemDefine = "U_HIDE_SYSTEM_API";
44 $internalHeaderName = "uintrnal.h";
45 $internalAppend = "INTERNAL_API_DO_NOT_USE";
46 $internalDefine = "U_HIDE_INTERNAL_API";
53 #---------------------------------------------------------------------
58 "--srcdir=s" => \
$srcDir,
59 "--destdir=s" => \
$destDir,
60 "--version=s" => \
$version,
61 "--exclusion-list=s" => \
$exclude,
62 "--include-types" => \
$includeTypes,
63 "--verbose" => \
$verbose
65 usage
() unless defined $srcDir;
66 usage
() unless defined $destDir;
67 usage
() unless defined $version;
68 usage
() unless defined $exclude;
69 $draftFile = "$srcDir/draft.html";
70 $deprecatedFile = "$srcDir/deprecated.html";
71 $obsoleteFile = "$srcDir/obsolete.html";
72 $systemFile = "$srcDir/system.html";
73 $internalFile = "$srcDir/internal.html";
75 $versionAppend = $version;
76 $versionAppend=~ s/^([0-9]+)\.([0-9]+).*/\1\2/; # _48
77 $excludeFH = IO
::File-
>new($exclude,"r")
78 or die "could not open the file $exclude for reading: $! \n";
80 while (defined ($line = <$excludeFH>)){
81 next if( $line =~ /^#/);
84 $exclude{$line}="EXCLUDE";
87 writeFile
($draftFile, $draftHeaderName, $destDir, $draftAppend, $draftDefine, \
%exclude);
88 writeFile
($deprecatedFile, $deprecatedHeaderName, $destDir, $deprecatedAppend, $deprecatedDefine, \
%exclude);
89 writeFile
($obsoleteFile, $obsoleteHeaderName, $destDir, $obsoleteAppend, $obsoleteDefine, \
%exclude);
90 writeFile
($systemFile, $systemHeaderName, $destDir, $systemAppend, $systemDefine, \
%exclude);
91 writeFile
($internalFile, $internalHeaderName, $destDir, $internalAppend, $internalDefine, \
%exclude);
94 #-----------------------------------------------------------------------
97 $headerDef = uc($headerName); # this is building the constant for #define
98 $headerDef =~ s/\./_/;
102 #-----------------------------------------------------------------------
104 ($infile,$outfile,$destDir, $symbolAppend, $symbolDef, $exclude) = @_;
106 my $outFileName = $outfile;
107 $headerDef = getHeaderDef
($outfile);
109 $outfile = $destDir."/".$outfile;
111 $inFH = IO
::File-
>new($infile,"r")
112 or die "could not open the file $infile for reading: $! \n";
113 $outFH = IO
::File-
>new($outfile,"w")
114 or die "could not open the file $outfile for writing: $! \n";
116 #print "$headerDef>>> $outfile\n";
117 printHeader
($outFH, $outFileName, $headerDef, $symbolDef);
118 parseWriteFile
($inFH, $outFH, $symbolAppend, $exclude);
119 printFooter
($outFH, $headerDef, $symbolDef);
124 #-----------------------------------------------------------------------
126 ($outFH, $headername, $HEADERDEF, $symbolDef) = @_;
127 ($DAY, $MONTH, $YEAR) = (localtime)[3,4,5];
129 #We will print our copyright here + warnings
130 print $outFH <<END_HEADER_COMMENT;
132 *******************************************************************************
133 * Copyright (C) 2004-$YEAR, International Business Machines
134 * Corporation and others. All Rights Reserved.
135 *******************************************************************************
137 * file name: $headername
139 * tab size: 8 (not used)
142 * Created by: genheaders.pl, a perl script written by Ram Viswanadha
144 * Contains data for commenting out APIs.
145 * Gets included by umachine.h
147 * THIS FILE IS MACHINE-GENERATED, DON'T PLAY WITH IT IF YOU DON'T KNOW WHAT
148 * YOU ARE DOING, OTHERWISE VERY BAD THINGS WILL HAPPEN!
159 #-----------------------------------------------------------------------
161 ($inFH, $outFH, $symbolAppend, $exclude) = @_;
164 while (defined ($line = <$inFH>)){
165 #just process C APIs for now
166 if($line =~ /\<dt\>/ ){
168 if( ($line =~ /LEUnicode/)|| ($line =~ /LanguageCodes/) ||
169 ($line =~ /ScriptCodes/) || ($line =~ /\:+/) ||
170 ($line =~ /Class/) ){
173 if( $line =~ /^\<dt\>File [^\>]*\>([^\<]*)/ ) {
174 print "Skipping file-scope $symbolAppend $1\n";
177 #<dt>Global <a class="el" href="utrans_8h.html#a21">utrans_unregister</a> </dt>
178 #<dt>Global <a class="el" href="classUnicodeString.html#w1w0">UnicodeString::kInvariant</a> </dt>
179 # the below regular expression works for both the above formats.
180 $line=~ m/\<dt\>.*\<a class=\".*\" href=\".*\">(.*)\<\/a\
>.*\
<\
/dt\>/;
182 $value =~ s/\<\/a\>\s*//g
;
185 #print "$exclude->{$value}\n";
186 if($exclude->{$value} eq "EXCLUDE"){
187 #print "$value $exclude->{$value}\n";
190 print "$value $realSymbol $nonExSymbol :: $line\n" if defined $verbose;
191 next if(isStringAcceptable
($value)==1);
192 if($value =~ /^operator[^a-zA-Z]/) {
193 print "Skipping operator $symbolAppend $value from $line\n";
196 $realSymbol = $value."_".$versionAppend;
197 $nonExSymbol = $value."_".$symbolAppend;
198 $disableRenaming{$value} = $nonExSymbol;
199 $enableRenaming{$realSymbol} = $nonExSymbol;
200 print "$value $realSymbol $nonExSymbol\n" if defined $verbose;
204 print "size of disableRenaming: " . keys( %disableRenaming) . ".\n";
205 print "size of enableRenaming: " . keys( %enableRenaming) . ".\n";
206 print $outFH "# if U_DISABLE_RENAMING\n";
207 foreach $key (sort (keys(%disableRenaming))) {
208 print $outFH "# define $key $disableRenaming{$key}\n";
209 delete($disableRenaming{$key});
211 print $outFH "# else\n";
212 foreach $key (sort (keys(%enableRenaming))) {
213 print $outFH "# define $key $enableRenaming{$key}\n";
214 delete($enableRenaming{$key});
216 print $outFH "# endif /* U_DISABLE_RENAMING */\n";
218 #-----------------------------------------------------------------------
219 sub isStringAcceptable
{
221 @str = split(//, $string);
224 if(($val ne "_") && !($val =~ /[0-9A-Z]/)){
229 #print "$string : $ret\n";
230 if(!(defined $includeTypes)){
231 if($ret==0 && $str[0] eq 'U'){
238 #-----------------------------------------------------------------------
241 ($outFH, $headerDef, $symbolDef ) = @_;
243 print $outFH <<END_FOOTER;
245 #endif /* $symbolDef */
246 #endif /* $headerDef */
250 #-----------------------------------------------------------------------
257 --destdir
=<directory
>
258 --version
=<current version of ICU
>
259 --exclusion-list
=<file name
>
261 e
.g
.: genheaders
.pl
--srcdir
=<icu
>/source/common
/docs/html
--destdir
=<icu
>/source/common
/unicode
--version
=2.8 --exclusion-list
=exclude
.txt