]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/perl | |
2 | #* | |
3 | #******************************************************************************* | |
4 | #* Copyright (C) 2004, International Business Machines | |
5 | #* Corporation and others. All Rights Reserved. | |
6 | #******************************************************************************* | |
7 | #* | |
8 | #* file name: gendraft.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 DraftAPI txt 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 | $versionAppend=""; | |
41 | ||
42 | #run the program | |
43 | main(); | |
44 | ||
45 | #--------------------------------------------------------------------- | |
46 | # The main program | |
47 | ||
48 | sub main(){ | |
49 | GetOptions( | |
50 | "--draft-file=s" => \$draftFile, | |
51 | "--deprecated-file=s" => \$deprecatedFile, | |
52 | "--obsolete-file=s" => \$obsoleteFile, | |
53 | "--destdir=s" => \$destDir, | |
54 | "--version=s" => \$version, | |
55 | ); | |
56 | usage() unless defined $draftFile; | |
57 | usage() unless defined $deprecatedFile; | |
58 | usage() unless defined $obsoleteFile; | |
59 | usage() unless defined $destDir; | |
60 | usage() unless defined $version; | |
61 | ||
62 | $versionAppend = $version; | |
63 | $versionAppend=~ s/\./_/; | |
64 | ||
65 | writeFile($draftFile, $draftHeaderName, $destDir, $draftAppend, $draftDefine); | |
66 | writeFile($deprecatedFile, $deprecatedHeaderName, $destDir, $deprecatedAppend, $deprecatedDefine); | |
67 | writeFile($obsoleteFile, $obsoleteHeaderName, $destDir, $obsoleteAppend, $obsoleteDefine); | |
68 | } | |
69 | ||
70 | #----------------------------------------------------------------------- | |
71 | sub getHeaderDef{ | |
72 | ($headerName) = @_; | |
73 | $headerDef = uc($headerName); # this is building the constant for #define | |
74 | $headerDef =~ s/\./_/; | |
75 | return $headerDef; | |
76 | } | |
77 | ||
78 | #----------------------------------------------------------------------- | |
79 | sub writeFile{ | |
80 | ($inFileName,$outFileName,$destDir, $symbolAppend, $symbolDef) = @_; | |
81 | ||
82 | $outFN = $destDir."/".$outFileName; | |
83 | ||
84 | $inFH = IO::File->new($inFileName,"r") | |
85 | or die "could not open the file $infile for reading: $! \n"; | |
86 | $outFH = IO::File->new($outFN,"w") | |
87 | or die "could not open the file $outfile for writing: $! \n"; | |
88 | ||
89 | $headerDef = getHeaderDef($outFileName); | |
90 | ||
91 | printHeader($outFH, $outFileName, $headerDef, $symbolDef); | |
92 | parseWriteFile($inFH, $outFH, $symbolAppend); | |
93 | printFooter($outFH, $headerDef, $symbolDef); | |
94 | close($inFH); | |
95 | close($outFH); | |
96 | } | |
97 | ||
98 | #----------------------------------------------------------------------- | |
99 | sub printHeader{ | |
100 | ($outFH, $headername, $HEADERDEF, $symbolDef) = @_; | |
101 | #We will print our copyright here + warnings | |
102 | print $outFH <<END_HEADER_COMMENT; | |
103 | /* | |
104 | ******************************************************************************* | |
105 | * Copyright (C) 2004, International Business Machines | |
106 | * Corporation and others. All Rights Reserved. | |
107 | ******************************************************************************* | |
108 | * | |
109 | * file name: $headername | |
110 | * encoding: US-ASCII | |
111 | * tab size: 8 (not used) | |
112 | * indentation:4 | |
113 | * | |
114 | * Created by: gendraft.pl, a perl script written by Ram Viswanadha | |
115 | * | |
116 | * Contains data for commenting out APIs. | |
117 | * Gets included by umachine.h | |
118 | * | |
119 | * THIS FILE IS MACHINE-GENERATED, DON'T PLAY WITH IT IF YOU DON'T KNOW WHAT | |
120 | * YOU ARE DOING, OTHERWISE VERY BAD THINGS WILL HAPPEN! | |
121 | */ | |
122 | ||
123 | #ifndef $HEADERDEF | |
124 | #define $HEADERDEF | |
125 | ||
126 | #ifdef $symbolDef | |
127 | ||
128 | END_HEADER_COMMENT | |
129 | } | |
130 | ||
131 | #----------------------------------------------------------------------- | |
132 | sub parseWriteFile{ | |
133 | ($inFH, $outFH, $symbolAppend) = @_; | |
134 | while (defined ($line = <$inFH>)){ | |
135 | ($a,$b,$c) = split( /\t/, $line); | |
136 | #just process C APIs for now | |
137 | if($b =~ /^[uU]/){ | |
138 | $realSymbol = $b."_".$versionAppend; | |
139 | $nonExSymbol = $b."_".$symbolAppend; | |
140 | print $outFH "#define ".$realSymbol." ".$nonExSymbol."\n"; | |
141 | } | |
142 | } | |
143 | } | |
144 | ||
145 | #----------------------------------------------------------------------- | |
146 | sub printFooter{ | |
147 | ||
148 | ($outFH, $headerDef, $symbolDef ) = @_; | |
149 | #print the footer | |
150 | print $outFH <<END_FOOTER; | |
151 | ||
152 | #endif /* $symbolDef */ | |
153 | #endif /* $headerDef */ | |
154 | ||
155 | END_FOOTER | |
156 | } | |
157 | #----------------------------------------------------------------------- | |
158 | sub usage { | |
159 | print << "END"; | |
160 | Usage: | |
161 | gendraft.pl | |
162 | Options: | |
163 | --draft-file=<path and name of output file of Doxygen containing draft API symbols> | |
164 | --deprecated-file=<path and name of output file of Doxygen containing deprecated API symbols> | |
165 | --obsolete-file=<path and name of output file of Doxygen containing obsolete API symbols> | |
166 | --destdir=<directory> | |
167 | --version=<current version of ICU> | |
168 | ||
169 | e.g.: gendraft.pl --draft-file=c:\blah\DraftAPI.txt --deprecated-file=c:\blah\DeprecatedAPI.txt --obsolete-file=c:\blah\ObsoleteFile.txt --destdir=<icu>/source/common/unicode --version=2.8 | |
170 | END | |
171 | exit(0); | |
172 | } |