blob: cde23f85fa744b07447b006a54a04c58f97eeab6 [file] [log] [blame]
Daniel Stenberg8b06a012002-09-17 07:17:25 +00001#!/usr/bin/perl -s
Daniel Stenberge19f7632002-09-16 15:01:38 +00002
3if(!$ARGV[0]) {
4 print <<MOO
Linus Nielsen Feltzingf84e93e2004-06-03 08:23:05 +00005Usage: genlang [-p=<prefix>] <language file>
Daniel Stenberg8b06a012002-09-17 07:17:25 +00006
7When running this program. <prefix>.h and <prefix>.c will be created in the
8"current directory". <prefix> is "lang" by default.
Daniel Stenberge19f7632002-09-16 15:01:38 +00009MOO
10;
11 exit;
12}
13
Daniel Stenberg8b06a012002-09-17 07:17:25 +000014my $prefix = $p;
15if(!$prefix) {
16 $prefix="lang";
17}
18
19my $input = $ARGV[0];
20
21open(HFILE, ">$prefix.h");
22open(CFILE, ">$prefix.c");
23
24print HFILE <<MOO
Linus Nielsen Feltzingdfb5c6e2004-05-21 23:37:08 +000025/* This file was automatically generated using genlang */
Daniel Stenberge19f7632002-09-16 15:01:38 +000026/*
27 * The str() macro/functions is how to access strings that might be
Daniel Stenberg20963dd2002-09-20 06:37:25 +000028 * translated. Use it like str(MACRO) and expect a string to be
Daniel Stenberge19f7632002-09-16 15:01:38 +000029 * returned!
30 */
Daniel Stenberg8b06a012002-09-17 07:17:25 +000031#define str(x) language_strings[x]
32
Jens Arnold0f040292005-01-19 21:43:15 +000033/* this is the array for holding the string pointers.
34 It will be initialized at runtime. */
Daniel Stenberg8b06a012002-09-17 07:17:25 +000035extern unsigned char *language_strings[];
Daniel Stenberge7bd73f2005-07-31 21:58:49 +000036/* this contains the concatenation of all strings, separated by \\0 chars */
Jens Arnold0f040292005-01-19 21:43:15 +000037extern const unsigned char language_builtin[];
Daniel Stenberg8b06a012002-09-17 07:17:25 +000038
Daniel Stenberg20963dd2002-09-20 06:37:25 +000039/* The enum below contains all available strings */
Daniel Stenberg8b06a012002-09-17 07:17:25 +000040enum {
Daniel Stenberge19f7632002-09-16 15:01:38 +000041MOO
42 ;
43
Daniel Stenberg8b06a012002-09-17 07:17:25 +000044print CFILE <<MOO
45/* This file was automaticly generated using genlang, the strings come
46 from "$input" */
Jens Arnold0f040292005-01-19 21:43:15 +000047
48#include "$prefix.h"
Daniel Stenberg8b06a012002-09-17 07:17:25 +000049
Jens Arnold0f040292005-01-19 21:43:15 +000050unsigned char *language_strings[LANG_LAST_INDEX_IN_ARRAY];
51const unsigned char language_builtin[] =
Daniel Stenberg8b06a012002-09-17 07:17:25 +000052MOO
53 ;
54
55open(LANG, "<$input");
Daniel Stenberge19f7632002-09-16 15:01:38 +000056while(<LANG>) {
Daniel Stenberg1017e252002-10-11 22:01:24 +000057 $line++;
Daniel Stenberge19f7632002-09-16 15:01:38 +000058 if($_ =~ / *\#/) {
59 # comment
60 next;
61 }
Daniel Stenberg1b2db9e2002-09-20 07:06:15 +000062 # get rid of DOS newlines
63 $_ =~ s/\r//g;
Daniel Stenberge19f7632002-09-16 15:01:38 +000064 if($_ =~ / *([a-z]+): *(.*)/) {
65 ($var, $value) = ($1, $2);
Daniel Stenberg1017e252002-10-11 22:01:24 +000066 # print "$var => $value\n";
Daniel Stenberge19f7632002-09-16 15:01:38 +000067
68 $set{$var} = $value;
69
Daniel Stenberg8f72d9e2003-01-31 09:04:34 +000070 if( (($var eq "new") && $value && ($value !~ /^\"(.*)\"\W*$/)) ||
Jörg Hohensohnf9495cb2004-04-03 20:52:24 +000071 (($var eq "voice") && $value && ($value !~ /^\"(.*)\"\W*$/)) ||
Daniel Stenberg8f72d9e2003-01-31 09:04:34 +000072 (($var eq "eng") && ($value !~ /^\"(.*)\"\W*$/)) ) {
Daniel Stenberg17cf4482002-10-14 08:49:25 +000073 print "$input:$line:missing quotes for ".$set{'id'}."\n";
74 $errors++;
Daniel Stenberg1017e252002-10-11 22:01:24 +000075 next;
76 }
77
Daniel Stenberge19f7632002-09-16 15:01:38 +000078 if($var eq "new") {
79 # the last one for a single phrase
80
Daniel Stenberg1d7c1042002-10-14 09:11:48 +000081 if(!$value || ($value eq "\"\"") ) {
Daniel Stenberge19f7632002-09-16 15:01:38 +000082 # if not set, get the english version
83 $value = $set{'eng'};
84 }
Jörg Hohensohnf9495cb2004-04-03 20:52:24 +000085# print "VOICE: ".$set{'voice'}." VALUE: $value\n";
Linus Nielsen Feltzingf84e93e2004-06-03 08:23:05 +000086 # Note: if both entries are "", the string is deprecated,
87 # but must be included to maintain compatibility
Jens Arnold19afad82005-01-31 00:34:32 +000088 if($set{'id'} =~ /^VOICE_/) {
Jörg Hohensohnf9495cb2004-04-03 20:52:24 +000089 # voice-only
90 push @vfile, $set{'id'};
91 }
92 else {
93 push @hfile, $set{'id'};
Jens Arnoldabfd29a2005-02-01 01:23:58 +000094 $value =~ s/^\"(.*)\"\W*$/\"$1\\0\"/;
Jens Arnold0f040292005-01-19 21:43:15 +000095 print CFILE " $value\n";
Jörg Hohensohnf9495cb2004-04-03 20:52:24 +000096 }
Daniel Stenberg8b06a012002-09-17 07:17:25 +000097
Daniel Stenberge19f7632002-09-16 15:01:38 +000098 undef %set;
99 }
100
101 }
102
103}
104close(LANG);
Daniel Stenberg8b06a012002-09-17 07:17:25 +0000105
Jörg Hohensohnf9495cb2004-04-03 20:52:24 +0000106for(@hfile) {
107 print HFILE " $_,\n";
108}
109
Jens Arnold3c2fefd2005-01-19 21:12:38 +0000110print HFILE <<MOO
111 LANG_LAST_INDEX_IN_ARRAY, /* this is not a string, this is a marker */
112 /* --- below this follows voice-only strings --- */
113 VOICEONLY_DELIMITER = 0x8000,
114MOO
115 ;
Jörg Hohensohnf9495cb2004-04-03 20:52:24 +0000116
117for(@vfile) {
118 print HFILE " $_,\n";
119}
Daniel Stenberg8b06a012002-09-17 07:17:25 +0000120
121print HFILE <<MOO
122};
123/* end of generated enum list */
124MOO
125 ;
126
127print CFILE <<MOO
Jens Arnold0f040292005-01-19 21:43:15 +0000128;
Daniel Stenberg8b06a012002-09-17 07:17:25 +0000129/* end of generated string list */
130MOO
131 ;
132
133close(CFILE);
134close(HFILE);
Daniel Stenberg17cf4482002-10-14 08:49:25 +0000135
136exit $errors;