Code

r11676@tres: ted | 2006-05-05 21:45:20 -0700
[inkscape.git] / src / extension / script / quotefile.pl
1 #!/usr/bin/perl
2 ############################################################################
3 #
4 # Quote all of the lines of a text file, so that it can be loaded
5 # into C/C++
6 #
7 ############################################################################
9 #
10 # main - top level code
11 #
14 if ( $#ARGV != 1 ) {                # parse command line args
15     print "usage: perl quotefile.pl infile outfile\n\n";
16     exit 1;
17 }
19 $inName  = $ARGV[0];
20 $outName = $ARGV[1];
22 print "#######################################################\n";
23 print "## Quoting $inName to $outName\n";
24 print "#######################################################\n";
26 &doQuoteFile();  #Do your magic!
28 print "#######################################################\n";
29 print "## DONE\n";
30 print "#######################################################\n";
32 exit 0;
36 ############################################################################
37 #
38 #
39 #
40 #
41 ############################################################################
42 sub doQuoteFile
43 {
44     my $line;       #current line from input file
45     my $datestr;    #Current date
46     local(*INFILE);
47     local(*OUTFILE);
49     $datestr = gmtime();
51     if ( -r $inName )
52         {
53         open INFILE, $inName or
54             die "$inName: $!";
55         open OUTFILE, ">$outName" or
56             die "$outName: $!";
57         print OUTFILE "\n";
58         print OUTFILE "/* ###################################################\n";
59         print OUTFILE "## This file generated by quotefile.pl from\n";
60         print OUTFILE "## $inName on $datestr\n";
61         print OUTFILE "## DO NOT EDIT\n";
62         print OUTFILE "################################################### */\n";
63         print OUTFILE "\n";
64         print OUTFILE "static char *inkscape_module_script =\n";
65         while (<INFILE>)
66             {
67             $line = $_;
68             #Escape existing quotes
69             $line =~ s/\"/\\"/g;
70             #Add outer quotes
71             $line =~ s/^/\"/;
72             $line =~ s/$/\\n\"/;
73             
74             print OUTFILE $line
75             }
76         close INFILE;
77         print OUTFILE "\"\";\n";
78         close OUTFILE;
79         }
80     
81 }