File: xml2cpp.pl

package info (click to toggle)
coin3 4.0.3%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 54,428 kB
  • sloc: cpp: 256,086; ansic: 21,309; makefile: 8,661; sh: 3,141; perl: 1,504; lex: 1,372; lisp: 1,247; pascal: 961; xml: 604; yacc: 387; sed: 68
file content (43 lines) | stat: -rwxr-xr-x 1,017 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/perl

if (scalar(@ARGV) != 3) {
    print STDOUT "Usage: $0 <input.xml> <output.cpp> <buffername>\n";
    exit -1;
}

open(XML, "+<", "$ARGV[0]") || die "$0: error opening xml input: $_\n";
open(OUT, "> $ARGV[1]") || die "$0: error opening output for writing: $_\n";

$perline = 12;

$counter = 0;
printf(OUT "static const unsigned char " . $ARGV[2] . "[] = {\n");
$text = "";

while ( !eof(XML) ) {
    $char = getc(XML);
    if (($counter % $perline) == 0) {
        printf(OUT "  ");
    }
    printf(OUT "0x%02x,", ord($char));
    if ($char =~ m/\p{IsPrint}/ && $char !~ m/[\n\r]/) {
      $text = $text . $char;
    } else {
      $text = $text . "?";
    }
    if ((($counter % $perline) == ($perline - 1)) || ($char =~ m/[\n]/)) {
        printf(OUT " // '" . $text . "'\n");
        $text = "";
        $counter = $perline - 1;
    }
    $counter++;
}
if (($counter % $perline) == 0) {
    printf(OUT "  ");
}
printf(OUT "0x00 // '" . $text . "'\n");
printf(OUT "};\n");


close(OUT);
close(XML);