xref: /aoo42x/main/oox/source/token/tokens.pl (revision b63233d8)
17e90fac2SAndrew Rist#**************************************************************
27e90fac2SAndrew Rist#
37e90fac2SAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
47e90fac2SAndrew Rist#  or more contributor license agreements.  See the NOTICE file
57e90fac2SAndrew Rist#  distributed with this work for additional information
67e90fac2SAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
77e90fac2SAndrew Rist#  to you under the Apache License, Version 2.0 (the
87e90fac2SAndrew Rist#  "License"); you may not use this file except in compliance
97e90fac2SAndrew Rist#  with the License.  You may obtain a copy of the License at
107e90fac2SAndrew Rist#
117e90fac2SAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
127e90fac2SAndrew Rist#
137e90fac2SAndrew Rist#  Unless required by applicable law or agreed to in writing,
147e90fac2SAndrew Rist#  software distributed under the License is distributed on an
157e90fac2SAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
167e90fac2SAndrew Rist#  KIND, either express or implied.  See the License for the
177e90fac2SAndrew Rist#  specific language governing permissions and limitations
187e90fac2SAndrew Rist#  under the License.
197e90fac2SAndrew Rist#
207e90fac2SAndrew Rist#**************************************************************
217e90fac2SAndrew Rist
227e90fac2SAndrew Rist
23cdf0e10cSrcweir
24*b63233d8Sdamjan# operation mode (1 = identifiers, 2 = names, 3 = gperf)
25*b63233d8Sdamjan$op = shift @ARGV;
26*b63233d8Sdamjandie "Error: invalid operation" unless( $op >= 1 && $op <= 3);
27cdf0e10cSrcweir
28*b63233d8Sdamjanif( $op == 3 ) {
29*b63233d8Sdamjan    print( "%language=C++\n" );
30*b63233d8Sdamjan    print( "%define slot-name mpcName\n" );
31*b63233d8Sdamjan    print( "%define initializer-suffix ,0\n" );
32*b63233d8Sdamjan    print( "%define lookup-function-name getTokenInfo\n" );
33*b63233d8Sdamjan    print( "%compare-strncmp\n" );
34*b63233d8Sdamjan    print( "%readonly-tables\n" );
35*b63233d8Sdamjan    print( "%enum\n" );
36*b63233d8Sdamjan    print( "%null-strings\n" );
37*b63233d8Sdamjan    print( "%struct-type\n" );
38*b63233d8Sdamjan    print( "struct XMLTokenInfo {\n" );
39*b63233d8Sdamjan    print( "    const sal_Char* mpcName;\n" );
40*b63233d8Sdamjan    print( "    sal_Int32       mnToken;\n" );
41*b63233d8Sdamjan    print( "};\n" );
42*b63233d8Sdamjan    print( "%%\n" );
43*b63233d8Sdamjan}
44*b63233d8Sdamjan
45*b63233d8Sdamjan$i = 0;
46*b63233d8Sdamjanwhile( <> )
47cdf0e10cSrcweir{
48cdf0e10cSrcweir    # trim newline
49cdf0e10cSrcweir    chomp( $_ );
50cdf0e10cSrcweir    # trim leading/trailing whitespace
51cdf0e10cSrcweir    $_ =~ s/^\s*//g;
52cdf0e10cSrcweir    $_ =~ s/\s*$//g;
53*b63233d8Sdamjan    # skip empty lines
54*b63233d8Sdamjan    if( $_ ) {
55*b63233d8Sdamjan        # check for valid characters
56*b63233d8Sdamjan        $_ =~ /^[a-zA-Z0-9-_]+$/ or die "Error: invalid entry: '$_'";
57*b63233d8Sdamjan        # generate output
58*b63233d8Sdamjan        $id = "XML_$_";
59*b63233d8Sdamjan        $id =~ s/-/_/g;
60*b63233d8Sdamjan        if( $op == 1 ) {
61*b63233d8Sdamjan            print( "const sal_Int32 $id = $i;\n" );
62*b63233d8Sdamjan        } elsif( $op == 2 ) {
63*b63233d8Sdamjan            print( "\"$_\",\n" );
64*b63233d8Sdamjan        } elsif( $op == 3 ) {
65*b63233d8Sdamjan            print( "$_,$id\n" );
66*b63233d8Sdamjan        }
67*b63233d8Sdamjan        ++$i;
68*b63233d8Sdamjan    }
69cdf0e10cSrcweir}
70cdf0e10cSrcweir
71*b63233d8Sdamjanif( $op == 1 ) {
72*b63233d8Sdamjan    print( "const sal_Int32 XML_TOKEN_COUNT = $i;\n" );
73*b63233d8Sdamjan} elsif( $op == 3 ) {
74*b63233d8Sdamjan    print( "%%\n" );
75cdf0e10cSrcweir}
76