#!/usr/bin/perl ############################################################################ # # Quote all of the lines of a text file, so that it can be loaded # into C/C++ # ############################################################################ # # main - top level code # if ( $#ARGV != 1 ) { # parse command line args print "usage: perl quotefile.pl infile outfile\n\n"; exit 1; } $inName = $ARGV[0]; $outName = $ARGV[1]; print "#######################################################\n"; print "## Quoting $inName to $outName\n"; print "#######################################################\n"; &doQuoteFile(); #Do your magic! print "#######################################################\n"; print "## DONE\n"; print "#######################################################\n"; exit 0; ############################################################################ # # # # ############################################################################ sub doQuoteFile { my $line; #current line from input file my $datestr; #Current date local(*INFILE); local(*OUTFILE); $datestr = gmtime(); if ( -r $inName ) { open INFILE, $inName or die "$inName: $!"; open OUTFILE, ">$outName" or die "$outName: $!"; print OUTFILE "\n"; print OUTFILE "/* ###################################################\n"; print OUTFILE "## This file generated by quotefile.pl from\n"; print OUTFILE "## $inName on $datestr\n"; print OUTFILE "## DO NOT EDIT\n"; print OUTFILE "################################################### */\n"; print OUTFILE "\n"; print OUTFILE "static char *inkscape_module_script =\n"; while () { $line = $_; #Escape existing quotes $line =~ s/\"/\\"/g; #Add outer quotes $line =~ s/^/\"/; $line =~ s/$/\\n\"/; print OUTFILE $line } close INFILE; print OUTFILE "\"\";\n"; close OUTFILE; } }