xref: /trunk/main/oox/source/token/tokens.pl (revision b63233d8)
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# operation mode (1 = identifiers, 2 = names, 3 = gperf)
25$op = shift @ARGV;
26die "Error: invalid operation" unless( $op >= 1 && $op <= 3);
27
28if( $op == 3 ) {
29    print( "%language=C++\n" );
30    print( "%define slot-name mpcName\n" );
31    print( "%define initializer-suffix ,0\n" );
32    print( "%define lookup-function-name getTokenInfo\n" );
33    print( "%compare-strncmp\n" );
34    print( "%readonly-tables\n" );
35    print( "%enum\n" );
36    print( "%null-strings\n" );
37    print( "%struct-type\n" );
38    print( "struct XMLTokenInfo {\n" );
39    print( "    const sal_Char* mpcName;\n" );
40    print( "    sal_Int32       mnToken;\n" );
41    print( "};\n" );
42    print( "%%\n" );
43}
44
45$i = 0;
46while( <> )
47{
48    # trim newline
49    chomp( $_ );
50    # trim leading/trailing whitespace
51    $_ =~ s/^\s*//g;
52    $_ =~ s/\s*$//g;
53    # skip empty lines
54    if( $_ ) {
55        # check for valid characters
56        $_ =~ /^[a-zA-Z0-9-_]+$/ or die "Error: invalid entry: '$_'";
57        # generate output
58        $id = "XML_$_";
59        $id =~ s/-/_/g;
60        if( $op == 1 ) {
61            print( "const sal_Int32 $id = $i;\n" );
62        } elsif( $op == 2 ) {
63            print( "\"$_\",\n" );
64        } elsif( $op == 3 ) {
65            print( "$_,$id\n" );
66        }
67        ++$i;
68    }
69}
70
71if( $op == 1 ) {
72    print( "const sal_Int32 XML_TOKEN_COUNT = $i;\n" );
73} elsif( $op == 3 ) {
74    print( "%%\n" );
75}
76