2 # Copyright (c) 1994 James Clark
3 # Copyright (c) 2000 Peter Nilsson
4 # See the file COPYING for copying permission.
9 $package = '@PACKAGE@';
10 $version = '@VERSION@';
11 $package = $package; $version = $version; # be quiet, -w
26 if (defined($opt_t)) {
27 # don't try to read translations for English
28 $opt_t =~ /.*en.*/ || &read_po_translations($opt_t);
33 foreach $def_file (@ARGV) {
37 open(DEF, $def_file) || die "can't open \`$def_file': $!\n";
46 if (!defined($opt_p)) {
48 &error("= directive must increase message num") if ($n < $num);
61 @field = split('\+', $_, 5);
62 &error("too few fields") if $#field < 3;
63 if ($#field == 4 && $field[4] =~ /^%J/) {
65 $field[3] .= substr($field[4], 2);
68 if ($field[0] eq "") {
73 $field[0] =~ /^[IWQXE][0-9]$/ || &error("invalid first field");;
74 $type[$num] = substr($field[0], 0, 1);
75 $argc = int(substr($field[0], 1, 1));
78 $field[1] =~ /^[a-zA-Z_][a-zA-Z0-9_]+$/ || &error("invalid tag");
79 $tag[$num] = $field[1];
80 &error("duplicate tag $field[1]")
81 if (!defined($opt_p) && defined($tag_used{$field[1]}));
82 $tag_used{$field[1]} = 1;
83 $field[2] =~ /^((ISO(\/IEC)? [0-9]+:[0-9]+ )?[A-Z]?[0-9]+(\.[0-9]+)*(p[0-9]+)?( (ISO(\/IEC)? [0-9]+:[0-9]+ )?[A-Z]?[0-9]+(\.[0-9]+)*(p[0-9]+)?)*)?$/
84 || &error("invalid clauses field");
85 # push @clauses, $field[2];
86 $clauses[$num] = $field[2];
88 if ($field[0] ne "") {
89 $field[3] =~ /^([^%]|%%)*$/ || &error("invalid character after %");
93 $field[3] =~ /^([^%]|%[%1-$argc])*$/ || &error("invalid character after %");
95 $auxloc[$num] = ($#field == 4 ? "L" : "");
96 $message[$num] = $field[3];
99 $message2[$num] = $field[4];
106 if (!defined($opt_p)) {
108 $file_base = $ARGV[0];
109 $file_base =~ s/\.[^.]*$//;
112 $class =~ s|.*[\\/]||;
114 # this is needed on Windows NT
115 chmod 0666, "$file_base.h";
116 unlink("$file_base.h");
117 open(OUT, ">$file_base.h");
118 chmod 0444, "$file_base.h";
122 // This file was automatically generated from $def_file by $prog.
124 print <<END if $gen_c;
125 #ifndef ${class}_INCLUDED
126 #define ${class}_INCLUDED 1
137 namespace SP_NAMESPACE {
143 foreach $i (0 .. $#message) {
144 if (defined($message[$i])) {
146 print " static const Message";
147 if ($type[$i] eq "") {
151 print "Type$nargs[$i]$auxloc[$i]";
153 print " $tag[$i];\n";
159 print <<END if $gen_c;
165 #endif /* not ${class}_INCLUDED */
170 # this is needed on Windows NT
171 chmod 0666, "$file_base.cxx";
172 unlink("$file_base.cxx");
173 open(OUT, ">$file_base.cxx");
174 chmod 0444, "$file_base.cxx";
178 // This file was automatically generated from $def_file by $prog.
181 #pragma implementation
188 namespace SP_NAMESPACE {
194 # The declaration is already included through Message.h
196 # if (defined($opt_l)) {
197 # print "extern MessageModule $module;\n\n";
200 foreach $i (0 .. $#message) {
201 if (defined($message[$i])) {
202 if ($type[$i] eq "") {
203 print "const MessageFragment ${class}::$tag[$i](\n";
206 print "const MessageType$nargs[$i]$auxloc[$i] ${class}::$tag[$i](\n";
207 print "MessageType::";
208 if ($type[$i] eq 'I') {
211 elsif ($type[$i] eq 'W') {
214 elsif ($type[$i] eq 'Q') {
215 print 'quantityError';
217 elsif ($type[$i] eq 'X') {
225 if (defined($opt_l)) {
231 print "#ifndef SP_NO_MESSAGE_TEXT\n";
235 printf ",\"%s\"", $str;
240 printf "\n,\"%s\"", $str;
243 if ($clauses[$i] eq "") {
246 $str = $message2[$i + 1];
249 printf "\n,\"%s\"", $str;
263 # this is needed on Windows NT
264 chmod 0666, "$file_base.rc";
265 unlink("$file_base.rc");
266 open(OUT, ">$file_base.rc");
267 chmod 0444, "$file_base.rc";
270 print "STRINGTABLE\nBEGIN\n";
272 foreach $i (0 .. $#message) {
273 if (defined($message[$i])) {
275 if ($translation{$str}) {
276 $str = $translation{$str};
279 printf " %d, \"%s\"\n", $i, $str;
281 elsif (defined($message2[$i])) {
282 $str = $message2[$i];
284 printf " %d, \"%s\"\n", $i, $str;
295 if (defined($opt_p)) {
297 # this is needed for GNU gettext
298 chmod 0666, "$pot_file";
300 open(OUT, ">$pot_file");
301 chmod 0444, "$pot_file";
304 $crdate = POSIX::strftime "%Y-%m-%d %H:%M+0000", gmtime;
306 # SOME DESCRIPTIVE TITLE.
307 # Copyright (C) YEAR HOLDER
308 # FIRST AUTHOR <EMAIL\@ADDRESS>, YEAR.
313 "Project-Id-Version: PACKAGE VERSION\\n"
314 "POT-Creation-Date: $crdate\\n"
315 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n"
316 "Last-Translator: FULL NAME <EMAIL\@ADDRESS>\\n"
317 "Language-Team: LANGUAGE <LL\@li.org>\\n"
318 "MIME-Version:: 1.0\\n"
319 "Content-Type: text/plain; charset=CHARSET\\n"
320 "Content-Transfer-Encoding: ENCODING\\n"
324 foreach $i (0 .. $#message) {
325 if (defined($message[$i]) && !defined($written{$message[$i]})) {
326 next if $message[$i] eq "";
327 $written{$message[$i]} = 1;
330 printf "msgid \"%s\"\nmsgstr \"\"\n\n", $str;
332 elsif (defined($message2[$i]) && ! defined($written{$message2[$i]})) {
333 $written{$message2[$i]} = 1;
334 $str = $message2[$i];
336 printf "msgid \"%s\"\nmsgstr \"\"\n\n", $str;
344 die "$def_file:$.: $_[0]\n";
347 # Read a PO file with message translations.
348 # This doesn't accept every valid PO file, but it seems to work reasonably.
349 sub read_po_translations {
351 open(PO_IN, "<$po_in") || die "Can't open file $po_in.";
354 my $catching_string = 0;
358 if ($catching_string) {
359 &po_flush($id, $str);
364 $catching_string = 1;
366 elsif (/^\s*msgstr/) {
367 die "No msgid." if !$catching_string or $id;
373 if ($catching_string) {
378 $in_string = !$in_string;
384 elsif (s/^\\([ntbrf\\\"])//) {
385 $str .= "\n" if $1 eq "n";
386 $str .= "\t" if $1 eq "t";
387 $str .= "\b" if $1 eq "b";
388 $str .= "\r" if $1 eq "r";
389 $str .= "\f" if $1 eq "f";
390 $str .= "\\" if $1 eq "\\";
391 $str .= "\"" if $1 eq "\"";
393 elsif (s/\\([0-9]+)//) {
394 $str .= chr(oct($1));
396 elsif (s/\\[xX]([0-9a-fA-F]+)//) {
397 $str .= chr(hex($1));
400 die "Invalid control sequence." if /^\\/;
410 if ($catching_string) {
411 &po_flush($id, $str);
419 # We use a translation only if $id is non-empty (we don't include the
420 # PO file header) and if $str is non-empty (the message is translated).
422 $translation{$id} = $str;