#!/usr/local/bin/perl -w # # file: cpp2xsl # purpose: generate .xsl file from .xsl.cpp by stripping xsl comments, running preprocessor # and doing additional substitutions with which preprocessor cannot cope # created: pasha aug 29 2002 # modified: pasha dec 29 2004 # modification: get rid of gmdb::Utilities # usage: cpp2xsl input.xsl.cpp > output.xsl # use strict; use IPC::Open2; use Sys::Hostname; use FindBin qw($Bin $Script); my $OPEN = ''; ########################## process command line ############# for (scalar @ARGV) { /^0$/ && do { print (STDERR "input file required as argument\n"); exit (-1); last; }; /^1$/ && do { last; }; print (STDERR "wrong number of arguments\n"); exit (-1); } ########################## wipe out XML comments ############ # XML comments may confuse cpp, that is why wiping them open (FILE, '< ' . $ARGV[0]) || die ('error opening ' . $ARGV[0]); my $input; { local $/ = undef; # slurp-slurp $input = ; } close (FILE); $input =~ s/$OPEN(.*?)$CLOSE//msgo; ########################## print header ##################### my $hostname = hostname(); my $localtime = localtime(); print < EOF ; ########################## run cpp ########################## open2 (*CPPOUT, *CPPIN, 'cpp -P') || die ('error launching cpp'); print (CPPIN $input); close (CPPIN) || die ('error executing cpp'); my $output = ; close (CPPOUT) || die ('error closing cpp output'); ########################## replace QUOT by "" ############### # we do this ugly substitutions which cannot be done via #define's # due to cpp quoting rules $output =~ s/QUOT/"/g; print $output; exit (0); __END__