Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / filter / source / svg / gentoken.pl
blob1c7736d7745103547c71561c613bb3a805d30432
1 #!/usr/bin/env perl
4 # This file is part of the LibreOffice project.
6 # This Source Code Form is subject to the terms of the Mozilla Public
7 # License, v. 2.0. If a copy of the MPL was not distributed with this
8 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 $ARGV0 = shift @ARGV;
13 $ARGV1 = shift @ARGV;
14 $ARGV2 = shift @ARGV;
16 open ( TOKENS, $ARGV0 ) || die "can't open token file: $!";
17 my %tokens;
19 while ( defined ($line = <TOKENS>) )
21 if( !($line =~ /^#/) )
23 chomp($line);
24 @token = split(/\s+/,$line);
25 if ( not defined ($token[1]) )
27 $token[1] = "XML_".$token[0];
28 $token[1] =~ tr/\-\.\:/___/;
29 $token[1] =~ s/\+/PLUS/g;
30 $token[1] =~ s/\-/MINUS/g;
33 $tokens{$token[0]} = uc($token[1]);
36 close ( TOKENS );
38 open ( HXX, ">$ARGV1" ) || die "can't open tokens.hxx file: $!";
39 open ( GPERF, ">$ARGV2" ) || die "can't open tokens.gperf file: $!";
41 print ( GPERF "%language=C++\n" );
42 print ( GPERF "%global-table\n" );
43 print ( GPERF "%null-strings\n" );
44 print ( GPERF "%struct-type\n" );
45 print ( GPERF "struct xmltoken\n" );
46 print ( GPERF "{\n" );
47 print ( GPERF " const sal_Char *name; sal_Int32 nToken; \n" );
48 print ( GPERF "};\n" );
49 print ( GPERF "%%\n" );
51 print ( HXX "#ifndef INCLUDED_AUTOGEN_TOKEN_HXX\n" );
52 print ( HXX "#define INCLUDED_AUTOGEN_TOKEN_HXX\n\n" );
53 print ( HXX "#include <sal/types.h>\n\n" );
55 $i = 0;
56 foreach( sort(keys(%tokens)) )
58 $i = $i + 1;
59 print( HXX "const sal_Int32 $tokens{$_} = $i;\n" );
60 print( GPERF "$_,$tokens{$_}\n" );
62 print ( GPERF "%%\n" );
63 print ( HXX "const sal_Int32 XML_TOKEN_COUNT = $i;\n" );
64 print ( HXX "const sal_Int32 XML_TOKEN_INVALID = -1;\n\n" );
65 print ( HXX "#endif\n" );
66 close ( HXX );
67 close ( GPERF );