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$ARGV0 = shift @ARGV; 25$ARGV1 = shift @ARGV; 26$ARGV2 = shift @ARGV; 27$ARGV3 = shift @ARGV; 28 29# parse input file 30 31open( INFILE, $ARGV0 ) or die "cannot open input file: $!"; 32my %namespaces; 33while( <INFILE> ) 34{ 35 # trim newline 36 chomp( $_ ); 37 # trim leading/trailing whitespace 38 $_ =~ s/^\s*//g; 39 $_ =~ s/\s*$//g; 40 # trim comments 41 $_ =~ s/^#.*//; 42 # skip empty lines 43 if( $_ ) 44 { 45 # check for valid characters 46 $_ =~ /^([a-zA-Z]+)\s+([a-zA-Z0-9-.:\/]+)\s*$/ or die "Error: invalid character in input data"; 47 $namespaces{$1} = $2; 48 } 49} 50close( INFILE ); 51 52# generate output files 53 54open( IDFILE, ">$ARGV1" ) or die "Error: cannot open output file: $!"; 55open( NAMEFILE, ">$ARGV2" ) or die "Error: cannot open output file: $!"; 56open( TXTFILE, ">$ARGV3" ) or die "Error: cannot open output file: $!"; 57 58# number of bits to shift the namespace identifier 59$shift = 16; 60 61print ( IDFILE "const size_t NMSP_SHIFT = $shift;\n" ); 62 63$i = 1; 64foreach( keys( %namespaces ) ) 65{ 66 print( IDFILE "const sal_Int32 NMSP_$_ = $i << NMSP_SHIFT;\n" ); 67 $id = $i << $shift; 68 print( NAMEFILE "{ $id, \"$namespaces{$_}\" },\n" ); 69 print( TXTFILE "$id $_ $namespaces{$_}\n" ); 70 ++$i; 71} 72 73close( IDFILE ); 74close( nameFILE ); 75close( TXTFILE ); 76