2 # Copyright (c) 1994 James Clark, 2000 Matthias Clasen
3 # Copyright (c) 2000 Peter Nilsson
4 # See the file COPYING for copying permission.
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]+)?)|(\[[0-9]+(\.[0-9]*)?\]))( (ISO(\/IEC)? [0-9]+:[0-9]+ )?(([A-Z]?[0-9]+(\.[0-9]+)*(p[0-9]+)?)|(\[[0-9]+(\.[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
134 #include <OpenSP/Message.h>
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
184 #include "stylelib.h"
188 namespace SP_NAMESPACE {
194 if (defined($opt_l)) {
195 print "extern MessageModule $module;\n\n";
198 foreach $i (0 .. $#message) {
199 if (defined($message[$i])) {
200 if ($type[$i] eq "") {
201 print "const MessageFragment ${class}::$tag[$i](\n";
204 print "const MessageType$nargs[$i]$auxloc[$i] ${class}::$tag[$i](\n";
205 print "MessageType::";
206 if ($type[$i] eq 'I') {
209 elsif ($type[$i] eq 'W') {
212 elsif ($type[$i] eq 'Q') {
213 print 'quantityError';
215 elsif ($type[$i] eq 'X') {
223 if (defined($opt_l)) {
229 print "#ifndef SP_NO_MESSAGE_TEXT\n";
233 printf ",\"%s\"", $str;
238 printf "\n,\"%s\"", $str;
241 if ($clauses[$i] eq "") {
244 $str = $message2[$i + 1];
247 printf "\n,\"%s\"", $str;
261 # this is needed on Windows NT
262 chmod 0666, "$file_base.rc";
263 unlink("$file_base.rc");
264 open(OUT, ">$file_base.rc");
265 chmod 0444, "$file_base.rc";
268 print "STRINGTABLE\nBEGIN\n";
270 foreach $i (0 .. $#message) {
271 if (defined($message[$i])) {
273 if ($translation{$str}) {
274 $str = $translation{$str};
277 printf " %d, \"%s\"\n", $i, $str;
279 elsif (defined($message2[$i])) {
280 $str = $message2[$i];
282 printf " %d, \"%s\"\n", $i, $str;
293 if (defined($opt_p)) {
295 # this is needed for GNU gettext
296 chmod 0666, "$pot_file";
298 open(OUT, ">$pot_file");
299 chmod 0444, "$pot_file";
302 $crdate = POSIX::strftime "%Y-%m-%d %H:%M+0000", gmtime;
304 # SOME DESCRIPTIVE TITLE.
305 # Copyright (C) YEAR HOLDER
306 # FIRST AUTHOR <EMAIL\@ADDRESS>, YEAR.
311 "Project-Id-Version: PACKAGE VERSION\\n"
312 "POT-Creation-Date: $crdate\\n"
313 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n"
314 "Last-Translator: FULL NAME <EMAIL\@ADDRESS>\\n"
315 "Language-Team: LANGUAGE <LL\@li.org>\\n"
316 "MIME-Version:: 1.0\\n"
317 "Content-Type: text/plain; charset=CHARSET\\n"
318 "Content-Transfer-Encoding: ENCODING\\n"
322 foreach $i (0 .. $#message) {
323 if (defined($message[$i]) && !defined($written{$message[$i]})) {
324 next if $message[$i] eq "";
325 $written{$message[$i]} = 1;
328 printf "msgid \"%s\"\nmsgstr \"\"\n\n", $str;
330 elsif (defined($message2[$i]) && ! defined($written{$message2[$i]})) {
331 $written{$message2[$i]} = 1;
332 $str = $message2[$i];
334 printf "msgid \"%s\"\nmsgstr \"\"\n\n", $str;
342 die "$def_file:$.: $_[0]\n";
345 # Read a PO file with message translations.
346 # This doesn't accept every valid PO file, but it seems to work reasonably.
347 sub read_po_translations {
349 open(PO_IN, "<$po_in") || die "Can't open file $po_in.";
352 my $catching_string = 0;
356 if ($catching_string) {
357 &po_flush($id, $str);
362 $catching_string = 1;
364 elsif (/^\s*msgstr/) {
365 die "No msgid." if !$catching_string or $id;
371 if ($catching_string) {
376 $in_string = !$in_string;
382 elsif (s/^\\([ntbrf\\\"])//) {
383 $str .= "\n" if $1 eq "n";
384 $str .= "\t" if $1 eq "t";
385 $str .= "\b" if $1 eq "b";
386 $str .= "\r" if $1 eq "r";
387 $str .= "\f" if $1 eq "f";
388 $str .= "\\" if $1 eq "\\";
389 $str .= "\"" if $1 eq "\"";
391 elsif (s/\\([0-9]+)//) {
392 $str .= chr(oct($1));
394 elsif (s/\\[xX]([0-9a-fA-F]+)//) {
395 $str .= chr(hex($1));
398 die "Invalid control sequence." if /^\\/;
408 if ($catching_string) {
409 &po_flush($id, $str);
417 # We use a translation only if $id is non-empty (we don't include the
418 # PO file header) and if $str is non-empty (the message is translated).
420 $translation{$id} = $str;