blob: 9eb769a25207059ef3f1824b8440f0a969bb15b8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#!/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 (<INFILE>)
{
$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;
}
}
|