Skip to content

Commit

Permalink
txt2c.pl: replace language list with glob
Browse files Browse the repository at this point in the history
  • Loading branch information
snipsnipsnip committed Sep 25, 2012
1 parent a6d3d13 commit 15789fe
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions ldmicro/txt2c.pl
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
#!/usr/bin/perl

use strict;

print <<EOT;
// generated by txt2c.pl from $ARGV[0]
#include <stdlib.h>
EOT

for $manual (<manual*txt>) {
my %manuals = map { /manual-?([^.]*)/ or die; (lc($1) || 'en') => $_ } glob('manual*txt');
my @languages_without_manual = grep { !exists $manuals{$_} } map { /-([^.]*)/ or die; lc $1 } glob('lang-*.txt');

if($manual eq 'manual.txt') {
$name = "HelpText";
for my $lang (sort keys %manuals) {
my ($name, $ifdef);
my $manual = $manuals{$lang};

if ($lang eq 'en') {
# Some languages don't have translated manuals yet, so use English
$ifdef = "#if defined(LDLANG_EN) || defined(LDLANG_ES) || defined(LDLANG_IT) || " .
"defined(LDLANG_PT)";
} elsif($manual =~ /manual-(.)(.)\.txt/) {
$p = uc($1) . lc($2);
$ifdef = "#ifdef LDLANG_" . uc($1 . $2);
$name = "HelpText$p";
my @langs = sort('en', @languages_without_manual);
my $cond = join ' || ', map { "defined(LDLANG_$_)" } map { uc } @langs;

$name = "HelpText";
$ifdef = "#if $cond";
} else {
die;
$name = "HelpText" . ucfirst $lang;
$ifdef = "#ifdef LDLANG_" . uc $lang;
}

print <<EOT;
Expand All @@ -29,7 +35,7 @@
while(<IN>) {
chomp;
# avoid problem with Japanese encoding (cp932) which has 0x5c in a multibyte character
s/\\/\\\\/g if $p ne 'Ja';
s/\\/\\\\/g if $lang ne 'ja';
s/"/\\"/g;

print qq{ "$_",\n};
Expand Down

0 comments on commit 15789fe

Please sign in to comment.