xref: /aoo4110/main/oox/source/token/tokens.pl (revision b1cdbd2c)
1#**************************************************************
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20#**************************************************************
21
22
23
24$ARGV0 = shift @ARGV;
25$ARGV1 = shift @ARGV;
26$ARGV2 = shift @ARGV;
27$ARGV3 = shift @ARGV;
28
29open( INFILE, $ARGV0 ) or die "Error: cannot open input file: $!";
30my %tokens;
31while ( <INFILE> )
32{
33    # trim newline
34    chomp( $_ );
35    # trim leading/trailing whitespace
36    $_ =~ s/^\s*//g;
37    $_ =~ s/\s*$//g;
38    # check for valid characters
39    $_ =~ /^[a-zA-Z0-9-_]+$/ or die "Error: invalid character in token '$_'";
40    $id = "XML_$_";
41    $id =~ s/-/_/g;
42    $tokens{$_} = $id;
43}
44close ( INFILE );
45
46# generate output files
47
48open ( IDFILE, ">$ARGV1" ) or die "Error: cannot open output file: $!";
49open ( NAMEFILE, ">$ARGV2" ) or die "Error: cannot open output file: $!";
50open ( GPERFFILE, ">$ARGV3" ) or die "Error: cannot open output file: $!";
51
52print( GPERFFILE "%language=C++\n" );
53print( GPERFFILE "%global-table\n" );
54print( GPERFFILE "%null-strings\n" );
55print( GPERFFILE "%struct-type\n" );
56print( GPERFFILE "struct xmltoken {\n" );
57print( GPERFFILE "    const sal_Char *name;\n" );
58print( GPERFFILE "    sal_Int32 nToken;\n" );
59print( GPERFFILE "};\n" );
60print( GPERFFILE "%%\n" );
61
62$i = 0;
63foreach( sort( keys( %tokens ) ) )
64{
65    print( IDFILE "const sal_Int32 $tokens{$_} = $i;\n" );
66    print( NAMEFILE "\"$_\",\n" );
67    print( GPERFFILE "$_,$tokens{$_}\n" );
68    ++$i;
69}
70
71print( IDFILE "const sal_Int32 XML_TOKEN_COUNT = $i;\n" );
72print( GPERFFILE "%%\n" );
73
74close( IDFILE );
75close( NAMEFILE );
76close( GPERFFILE );
77