File: par_pl2c.pl

package info (click to toggle)
libpar-packer-perl 1.063-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,380 kB
  • sloc: perl: 12,859; ansic: 1,486; makefile: 30; sh: 5
file content (28 lines) | stat: -rw-r--r-- 832 bytes parent folder | download | duplicates (4)
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
#!perl

use strict;
use warnings;

use blib;               # PAR::Filter::Podstrip might not be installed yet
use PAR::Filter::PodStrip;

my ($var) = @ARGV;

my $slurp = do { local $/ = undef; <STDIN> };

PAR::Filter::PodStrip->apply(\$slurp, '');

print "const char *$var =\n";
foreach (split(/\n/, $slurp))
{
    # Note: We've already podstripped stdin (i.e. par.pl), but
    # the generated C string will be passed through argc to our
    # custom Perl interpreter. Some legacy OS platforms have really
    # small _POSIX_ARG_MAX values, hence squeeze some more bytes from it. 
    s/^\s*|\s*$//g;             # strip leading and trailing whitespace
    next if /^#|^$/;            # skip comment (nad #line) and empty lines

    s/(["\\])/\\$1/g;           # escape quotes and backslashes
    print qq["$_\\n"\n];
}
print ";\n"