Debian Codegraph @

src/lib/gentoken.pl

raw
1 #!/usr/bin/env perl
2 #
3 # Version: MPL 1.1 / GPLv3.0+ / LGPLv3.0+
4 #
5 # The contents of this file are subject to the Mozilla Public License Version
6 # 1.1 (the "License"); you may not use this file except in compliance with
7 # the License. You may obtain a copy of the License at
8 # http://www.mozilla.org/MPL/
9 #
10 # Software distributed under the License is distributed on an "AS IS" basis,
11 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 # for the specific language governing rights and limitations under the
13 # License.
14 #
15 # The Initial Developer of the Original Code is
16 # Thorsten Behrens <[email protected]>
17 # All Rights Reserved.
18 #
19 # Contributor(s):
20 #
21 # Alternatively, the contents of this file may be used under the terms of
22 # either the GNU General Public License Version 3 or later (the "GPLv3+"), or
23 # the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
24 # in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
25 # instead of those above.
26
27
28 $ARGV0 = shift @ARGV;
29 $ARGV1 = shift @ARGV;
30 $ARGV2 = shift @ARGV;
31
32 open ( TOKENS, $ARGV0 ) || die "can't open token file: $!";
33 my %tokens;
34
35 while ( defined ($line = <TOKENS>) )
36 {
37 if( !($line =~ /^#/) )
38 {
39 chomp($line);
40 @token = split(/\s+/,$line);
41 if ( not defined ($token[1]) )
42 {
43 $token[1] = "XML_".$token[0];
44 $token[1] =~ tr/\-\.\:/___/;
45 $token[1] =~ s/\+/PLUS/g;
46 $token[1] =~ s/\-/MINUS/g;
47 }
48
49 $tokens{$token[0]} = uc($token[1]);
50 }
51 }
52 close ( TOKENS );
53
54 open ( HXX, ">$ARGV1" ) || die "can't open tokens.hxx file: $!";
55 open ( GPERF, ">$ARGV2" ) || die "can't open tokens.gperf file: $!";
56
57 print ( GPERF "%language=C++\n" );
58 print ( GPERF "%global-table\n" );
59 print ( GPERF "%null-strings\n" );
60 print ( GPERF "%struct-type\n" );
61 print ( GPERF "struct xmltoken\n" );
62 print ( GPERF "{\n" );
63 print ( GPERF " const char *name;\n int tokenId;\n" );
64 print ( GPERF "};\n" );
65 print ( GPERF "%%\n" );
66
67 print ( HXX "#ifndef __ABWXMLTOKENS_HXX__\n" );
68 print ( HXX "#define __ABWXMLTOKENS_HXX__\n" );
69 print ( HXX "\n" );
70
71 $i = 0;
72 foreach( sort(keys(%tokens)) )
73 {
74 $i = $i + 1;
75 print( HXX "const int $tokens{$_} = $i;\n" );
76 print( GPERF "$_,$tokens{$_}\n" );
77 }
78 print ( GPERF "%%\n" );
79 print ( HXX "\n" );
80 print ( HXX "const int XML_TOKEN_COUNT = $i;\n" );
81 print ( HXX "\n" );
82 print ( HXX "const int XML_TOKEN_INVALID = -1;\n" );
83 print ( HXX "\n" );
84 print ( HXX "#endif\n" );
85 close ( HXX );
86 close ( GPERF );