File: buildmsgstrings.pl

package info (click to toggle)
edbrowse 3.8.12-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,992 kB
  • sloc: ansic: 48,603; javascript: 16,211; perl: 6,825; sh: 120; makefile: 81; cpp: 56
file content (56 lines) | stat: -rwxr-xr-x 1,324 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
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/perl -w
# Build message strings for the languages that are supported.
# This is much simpler than buildsourcestring.pl.
# No interpretation or escaping, each line ia assumed to be a C string,
# put quotes around it and that's it!
# That means none of these lines can contain quotes, unless of course escaped,
# as in \"hello\"

use strict;
use warnings;

sub prt($) { print shift; }

my @files = glob "lang/msg-*";
my $infile;
my $outfile = "src/msg-strings.c";
my $outbase = $outfile;
$outbase =~ s,.*/,,;

    if (! open OUTF, ">$outfile") {
        prt("Error: Unable to create $outfile!\n");
        exit(1);
    }

    print OUTF "/* $outbase: this file is machine generated; */\n\n";

#  loop over input files
foreach $infile (@files) {
my $inbase = $infile;
$inbase =~ s,.*/,,;
my $stringname = $inbase;
$stringname =~ s/-/_/;

    if (!open  INF, "<$infile") {
        prt("Error: Unable to open $infile!\n");
        exit(1);
    }
    my @lines = <INF>;
my $line;
    close INF;
    print OUTF "/* source file $inbase */\n";
    print OUTF "const char *$stringname" . "[] = {\n";
    foreach $line (@lines) {
chomp $line;
#  in case \r is not removed on windows
$line =~ s/\r*$//;
if($line =~ /^[0,\s]*$/) {
print OUTF "\t0,\n";
} else {
print OUTF "\t\"$line\",\n";
}
}
print OUTF "};\n\n";
}

exit 0;