1#!/usr/bin/env perl 2# 3# 4# This file is part of the LibreOffice project. 5# 6# This Source Code Form is subject to the terms of the Mozilla Public 7# License, v. 2.0. If a copy of the MPL was not distributed with this 8# file, You can obtain one at http://mozilla.org/MPL/2.0/. 9# 10 11 12$ARGV0 = shift @ARGV; 13$ARGV1 = shift @ARGV; 14$ARGV2 = shift @ARGV; 15 16open ( TOKENS, $ARGV0 ) || die "can't open token file: $!"; 17my %tokens; 18 19while ( defined ($line = <TOKENS>) ) 20{ 21 if( !($line =~ /^#/) ) 22 { 23 chomp($line); 24 @token = split(/\s+/,$line); 25 if ( not defined ($token[1]) ) 26 { 27 $token[1] = "XML_".$token[0]; 28 $token[1] =~ tr/\-\.\:/___/; 29 $token[1] =~ s/\+/PLUS/g; 30 $token[1] =~ s/\-/MINUS/g; 31 } 32 33 $tokens{$token[0]} = uc($token[1]); 34 } 35} 36close ( TOKENS ); 37 38open ( HXX, ">$ARGV1" ) || die "can't open tokens.hxx file: $!"; 39open ( GPERF, ">$ARGV2" ) || die "can't open tokens.gperf file: $!"; 40 41print ( GPERF "%language=C++\n" ); 42print ( GPERF "%global-table\n" ); 43print ( GPERF "%null-strings\n" ); 44print ( GPERF "%struct-type\n" ); 45print ( GPERF "struct xmltoken\n" ); 46print ( GPERF "{\n" ); 47print ( GPERF " const sal_Char *name; sal_Int32 nToken; \n" ); 48print ( GPERF "};\n" ); 49print ( GPERF "%%\n" ); 50 51print ( HXX "#ifndef INCLUDED_AUTOGEN_TOKEN_HXX\n" ); 52print ( HXX "#define INCLUDED_AUTOGEN_TOKEN_HXX\n\n" ); 53print ( HXX "#include <sal/types.h>\n\n" ); 54 55$i = 0; 56foreach( sort(keys(%tokens)) ) 57{ 58 $i = $i + 1; 59 print( HXX "const sal_Int32 $tokens{$_} = $i;\n" ); 60 print( GPERF "$_,$tokens{$_}\n" ); 61} 62print ( GPERF "%%\n" ); 63print ( HXX "const sal_Int32 XML_TOKEN_COUNT = $i;\n" ); 64print ( HXX "const sal_Int32 XML_TOKEN_INVALID = -1;\n\n" ); 65print ( HXX "#endif\n" ); 66close ( HXX ); 67close ( GPERF ); 68