diff options
author | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2011-06-20 14:45:33 +0200 |
---|---|---|
committer | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2011-06-20 14:45:33 +0200 |
commit | 68ef83dbd75b7f25466e007140aedb9ed3694e50 (patch) | |
tree | 733a32c244371eef74cb522aa279a5108e4dec22 /oox/source/token | |
parent | b788274180d19329ac0d0f13ac24d23e50bfcf57 (diff) |
fix buildbreakers in oox, revert token changes for now
Diffstat (limited to 'oox/source/token')
-rw-r--r-- | oox/source/token/namespacemap.cxx | 2 | ||||
-rw-r--r-- | oox/source/token/namespaces.pl | 79 | ||||
-rw-r--r-- | oox/source/token/properties.pl | 52 | ||||
-rw-r--r-- | oox/source/token/propertynames.cxx | 3 | ||||
-rw-r--r-- | oox/source/token/tokenmap.cxx | 22 | ||||
-rw-r--r-- | oox/source/token/tokens.pl | 85 |
6 files changed, 166 insertions, 77 deletions
diff --git a/oox/source/token/namespacemap.cxx b/oox/source/token/namespacemap.cxx index 915cbe9855b8..b64b4e179627 100644 --- a/oox/source/token/namespacemap.cxx +++ b/oox/source/token/namespacemap.cxx @@ -37,7 +37,7 @@ NamespaceMap::NamespaceMap() static const struct NamespaceUrl { sal_Int32 mnId; const sal_Char* mpcUrl; } spNamespaceUrls[] = { // include auto-generated C array with namespace URLs as C strings -#include <token/namespacenames.inc> +#include "namespacenames.inc" { -1, "" } }; diff --git a/oox/source/token/namespaces.pl b/oox/source/token/namespaces.pl new file mode 100644 index 000000000000..3c741fa7b2af --- /dev/null +++ b/oox/source/token/namespaces.pl @@ -0,0 +1,79 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +$ARGV0 = shift @ARGV; +$ARGV1 = shift @ARGV; +$ARGV2 = shift @ARGV; +$ARGV3 = shift @ARGV; + +# parse input file + +open( INFILE, $ARGV0 ) or die "cannot open input file: $!"; +my %namespaces; +while( <INFILE> ) +{ + # trim newline + chomp( $_ ); + # trim leading/trailing whitespace + $_ =~ s/^\s*//g; + $_ =~ s/\s*$//g; + # trim comments + $_ =~ s/^#.*//; + # skip empty lines + if( $_ ) + { + # check for valid characters + $_ =~ /^([a-zA-Z]+)\s+([a-zA-Z0-9-.:\/]+)\s*$/ or die "Error: invalid character in input data"; + $namespaces{$1} = $2; + } +} +close( INFILE ); + +# generate output files + +open( IDFILE, ">$ARGV1" ) or die "Error: cannot open output file: $!"; +open( NAMEFILE, ">$ARGV2" ) or die "Error: cannot open output file: $!"; +open( TXTFILE, ">$ARGV3" ) or die "Error: cannot open output file: $!"; + +# number of bits to shift the namespace identifier +$shift = 16; + +print ( IDFILE "const size_t NMSP_SHIFT = $shift;\n" ); + +$i = 1; +foreach( keys( %namespaces ) ) +{ + print( IDFILE "const sal_Int32 NMSP_$_ = $i << NMSP_SHIFT;\n" ); + $id = $i << $shift; + print( NAMEFILE "{ $id, \"$namespaces{$_}\" },\n" ); + print( TXTFILE "$id $_ $namespaces{$_}\n" ); + ++$i; +} + +close( IDFILE ); +close( nameFILE ); +close( TXTFILE ); diff --git a/oox/source/token/properties.pl b/oox/source/token/properties.pl index 9f1262b02df5..f341924bbb90 100644 --- a/oox/source/token/properties.pl +++ b/oox/source/token/properties.pl @@ -25,33 +25,43 @@ # #************************************************************************* -# operation mode (1 = identifiers, 2 = names) -$op = shift @ARGV; -die "Error: invalid operation" unless( $op >= 1 && $op <= 2); +$ARGV0 = shift @ARGV; +$ARGV1 = shift @ARGV; +$ARGV2 = shift @ARGV; -$i = 0; -while( <> ) { +# parse input file + +open( INFILE, $ARGV0 ) or die "Error: cannot open input file: $!"; +my %props; +while( <INFILE> ) +{ # trim newline chomp( $_ ); # trim leading/trailing whitespace $_ =~ s/^\s*//g; $_ =~ s/\s*$//g; - # skip empty lines - if( $_ ) { - # check for valid characters - $_ =~ /^[A-Z][a-zA-Z0-9]+$/ or die "Error: invalid entry: '$_'"; - # generate output - if( $op == 1 ) { - print( "const sal_Int32 PROP_$_ = $i;\n" ); - } elsif( $op == 2 ) { - print( "/* $i */ \"$_\",\n" ); - } - ++$i; - } + # check for valid characters + $_ =~ /^[A-Z][a-zA-Z0-9]*$/ or die "Error: invalid character in property '$_'"; + $id = "PROP_$_"; + $props{$_} = $id; } +close( INFILE ); + +# generate output files + +open( IDFILE, ">$ARGV1" ) or die "Error: cannot open output file: $!"; +open( NAMEFILE, ">$ARGV2" ) or die "Error: cannot open output file: $!"; -if( $op == 1 ) { - print( "const sal_Int32 PROP_COUNT = $i;\nconst sal_Int32 PROP_INVALID = -1;\n" ); -} elsif( $op == 2 ) { - print( " \"\"\n" ); +$i = 0; +foreach( sort( keys( %props ) ) ) +{ + print( IDFILE "const sal_Int32 $props{$_} = $i;\n" ); + print( NAMEFILE "/* $i */ \"$_\",\n" ); + ++$i; } + +print( IDFILE "const sal_Int32 PROP_COUNT = $i;\n" ); +print( IDFILE "const sal_Int32 PROP_INVALID = -1;\n" ); + +close( IDFILE ); +close( NAMEFILE ); diff --git a/oox/source/token/propertynames.cxx b/oox/source/token/propertynames.cxx index 4a6d54cd6e63..a7c9b87e4982 100644 --- a/oox/source/token/propertynames.cxx +++ b/oox/source/token/propertynames.cxx @@ -37,7 +37,8 @@ PropertyNameVector::PropertyNameVector() static const sal_Char* sppcPropertyNames[] = { // include auto-generated C array with property names as C strings -#include <token/propertynames.inc> +#include "propertynames.inc" + "" }; size_t nArraySize = (sizeof( sppcPropertyNames ) / sizeof( *sppcPropertyNames )) - 1; diff --git a/oox/source/token/tokenmap.cxx b/oox/source/token/tokenmap.cxx index 9d106731dc53..424336b164c9 100644 --- a/oox/source/token/tokenmap.cxx +++ b/oox/source/token/tokenmap.cxx @@ -43,10 +43,8 @@ using ::rtl::OUString; // ============================================================================ namespace { - -// include auto-generated Perfect_Hash class -#include <token/tokenhash.inc> - +// include auto-generated Perfect_Hash +#include "tokenhash.inc" } // namespace // ============================================================================ @@ -57,7 +55,7 @@ TokenMap::TokenMap() : static const sal_Char* sppcTokenNames[] = { // include auto-generated C array with token names as C strings -#include <token/tokennames.inc> +#include "tokennames.inc" "" }; @@ -70,14 +68,14 @@ TokenMap::TokenMap() : } #if OSL_DEBUG_LEVEL > 0 - // check that the Perfect_Hash is in sync with the token name list + // check that the perfect_hash is in sync with the token name list bool bOk = true; for( sal_Int32 nToken = 0; bOk && (nToken < XML_TOKEN_COUNT); ++nToken ) { // check that the getIdentifier <-> getToken roundtrip works OString aUtf8Name = OUStringToOString( maTokenNames[ nToken ].maUniName, RTL_TEXTENCODING_UTF8 ); - const XMLTokenInfo* pTokenInfo = Perfect_Hash::getTokenInfo( aUtf8Name.getStr(), aUtf8Name.getLength() ); - bOk = pTokenInfo && (pTokenInfo->mnToken == nToken); + struct xmltoken* pToken = Perfect_Hash::in_word_set( aUtf8Name.getStr(), aUtf8Name.getLength() ); + bOk = pToken && (pToken->nToken == nToken); OSL_ENSURE( bOk, ::rtl::OStringBuffer( "TokenMap::TokenMap - token list broken, #" ). append( nToken ).append( ", '" ).append( aUtf8Name ).append( '\'' ).getStr() ); } @@ -98,8 +96,8 @@ OUString TokenMap::getUnicodeTokenName( sal_Int32 nToken ) const sal_Int32 TokenMap::getTokenFromUnicode( const OUString& rUnicodeName ) const { OString aUtf8Name = OUStringToOString( rUnicodeName, RTL_TEXTENCODING_UTF8 ); - const XMLTokenInfo* pTokenInfo = Perfect_Hash::getTokenInfo( aUtf8Name.getStr(), aUtf8Name.getLength() ); - return pTokenInfo ? pTokenInfo->mnToken : XML_TOKEN_INVALID; + struct xmltoken* pToken = Perfect_Hash::in_word_set( aUtf8Name.getStr(), aUtf8Name.getLength() ); + return pToken ? pToken->nToken : XML_TOKEN_INVALID; } Sequence< sal_Int8 > TokenMap::getUtf8TokenName( sal_Int32 nToken ) const @@ -111,9 +109,9 @@ Sequence< sal_Int8 > TokenMap::getUtf8TokenName( sal_Int32 nToken ) const sal_Int32 TokenMap::getTokenFromUtf8( const Sequence< sal_Int8 >& rUtf8Name ) const { - const XMLTokenInfo* pTokenInfo = Perfect_Hash::getTokenInfo( + struct xmltoken* pToken = Perfect_Hash::in_word_set( reinterpret_cast< const char* >( rUtf8Name.getConstArray() ), rUtf8Name.getLength() ); - return pTokenInfo ? pTokenInfo->mnToken : XML_TOKEN_INVALID; + return pToken ? pToken->nToken : XML_TOKEN_INVALID; } // ============================================================================ diff --git a/oox/source/token/tokens.pl b/oox/source/token/tokens.pl index ba7f39f2be39..a951cee80db2 100644 --- a/oox/source/token/tokens.pl +++ b/oox/source/token/tokens.pl @@ -25,55 +25,56 @@ # #************************************************************************* -# operation mode (1 = identifiers, 2 = names, 3 = gperf) -$op = shift @ARGV; -die "Error: invalid operation" unless( $op >= 1 && $op <= 3); +$ARGV0 = shift @ARGV; +$ARGV1 = shift @ARGV; +$ARGV2 = shift @ARGV; +$ARGV3 = shift @ARGV; -if( $op == 3 ) { - print( "%language=C++\n" ); - print( "%define slot-name mpcName\n" ); - print( "%define initializer-suffix ,0\n" ); - print( "%define lookup-function-name getTokenInfo\n" ); - print( "%compare-strncmp\n" ); - print( "%readonly-tables\n" ); - print( "%enum\n" ); - print( "%null-strings\n" ); - print( "%struct-type\n" ); - print( "struct XMLTokenInfo {\n" ); - print( " const sal_Char* mpcName;\n" ); - print( " sal_Int32 mnToken;\n" ); - print( "};\n" ); - print( "%%\n" ); -} - -$i = 0; -while( <> ) +open( INFILE, $ARGV0 ) or die "Error: cannot open input file: $!"; +my %tokens; +while ( <INFILE> ) { # trim newline chomp( $_ ); # trim leading/trailing whitespace $_ =~ s/^\s*//g; $_ =~ s/\s*$//g; - # skip empty lines - if( $_ ) { - # check for valid characters - $_ =~ /^[a-zA-Z0-9-_]+$/ or die "Error: invalid entry: '$_'"; - # generate output - $id = "XML_$_"; - $id =~ s/-/_/g; - if( $op == 1 ) { - print( "const sal_Int32 $id = $i;\n" ); - } elsif( $op == 2 ) { - print( "\"$_\",\n" ); - } elsif( $op == 3 ) { - print( "$_,$id\n" ); - } - ++$i; - } + # check for valid characters + $_ =~ /^[a-zA-Z0-9-_]+$/ or die "Error: invalid character in token '$_'"; + $id = "XML_$_"; + $id =~ s/-/_/g; + $tokens{$_} = $id; } +close ( INFILE ); + +# generate output files + +open ( IDFILE, ">$ARGV1" ) or die "Error: cannot open output file: $!"; +open ( NAMEFILE, ">$ARGV2" ) or die "Error: cannot open output file: $!"; +open ( GPERFFILE, ">$ARGV3" ) or die "Error: cannot open output file: $!"; -if( $op == 1 ) { - print( "const sal_Int32 XML_TOKEN_COUNT = $i;\n" ); -} elsif( $op == 3 ) { - print( "%%\n" ); +print( GPERFFILE "%language=C++\n" ); +print( GPERFFILE "%global-table\n" ); +print( GPERFFILE "%null-strings\n" ); +print( GPERFFILE "%struct-type\n" ); +print( GPERFFILE "struct xmltoken {\n" ); +print( GPERFFILE " const sal_Char *name;\n" ); +print( GPERFFILE " sal_Int32 nToken;\n" ); +print( GPERFFILE "};\n" ); +print( GPERFFILE "%%\n" ); + +$i = 0; +foreach( sort( keys( %tokens ) ) ) +{ + print( IDFILE "const sal_Int32 $tokens{$_} = $i;\n" ); + print( NAMEFILE "\"$_\",\n" ); + print( GPERFFILE "$_,$tokens{$_}\n" ); + ++$i; } + +print( IDFILE "const sal_Int32 XML_TOKEN_COUNT = $i;\n" ); +print( GPERFFILE "%%\n" ); + +close( IDFILE ); +close( NAMEFILE ); +close( GPERFFILE ); |