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