merge the formfield patch from ooo-build
[ooovba.git] / oox / source / token / gentoken.pl
blob196ac37ebb5ca73d2390a2ec34908764e9e24fe6
1 $ARGV0 = shift @ARGV;
2 $ARGV1 = shift @ARGV;
3 $ARGV2 = shift @ARGV;
4 $ARGV3 = shift @ARGV;
6 open ( TOKENS, $ARGV0 ) || die "can't open $ARGV0 file: $!";
7 my %tokens;
9 while ( <TOKENS> )
11 chomp( $_ );
12 $_ =~ s/\s*//g;
13 $_ =~ /^[a-zA-Z0-9-_]+$/ or die "invalid character in token '$_'";
14 $id = "XML_$_";
15 $id =~ s/-/_/g;
16 $tokens{$_} = $id;
18 close ( TOKENS );
20 open ( HXX, ">$ARGV1" ) or die "can't open $ARGV1 file: $!";
21 open ( WORDS, ">$ARGV2" ) or die "can't open $ARGV2 file: $!";
22 open ( GPERF, ">$ARGV3" ) or die "can't open $ARGV3 file: $!";
24 print ( HXX "#ifndef OOX_TOKENS_HXX\n" );
25 print ( HXX "#define OOX_TOKENS_HXX\n\n" );
26 print ( HXX "#include <com/sun/star/xml/sax/FastToken.hpp>\n" );
28 print ( WORDS "static const sal_Char* xmltokenwordlist[] = {\n" );
30 print ( GPERF "%language=C++\n" );
31 print ( GPERF "%global-table\n" );
32 print ( GPERF "%null-strings\n" );
33 print ( GPERF "%struct-type\n" );
34 print ( GPERF "struct xmltoken {\n" );
35 print ( GPERF " const sal_Char *name;\n" );
36 print ( GPERF " sal_Int32 nToken;\n" );
37 print ( GPERF "};\n" );
38 print ( GPERF "%%\n" );
40 $i = 0;
41 foreach( sort( keys( %tokens ) ) )
43 print ( HXX "const sal_Int32 $tokens{$_} = $i;\n" );
44 print ( WORDS " \"$_\",\n" );
45 print ( GPERF "$_,$tokens{$_}\n" );
46 ++$i;
49 print ( HXX "const sal_Int32 XML_TOKEN_COUNT = $i;\n" );
50 print ( HXX "const sal_Int32 XML_TOKEN_INVALID = ::com::sun::star::xml::sax::FastToken::DONTKNOW;\n\n" );
51 print ( HXX "const sal_Int32 XML_ROOT_CONTEXT = SAL_MAX_INT32;\n\n" );
52 print ( HXX "#endif\n" );
54 print ( WORDS " \"\"\n" );
55 print ( WORDS "};\n" );
57 print ( GPERF "%%\n" );
59 close ( HXX );
60 close ( WORDS );
61 close ( GPERF );