blob: 39f1696e8c893f9d28c5074a4940ee9c82bc3488 [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
Daniel Stenberg8b06a012002-09-17 07:17:25 +00005Usage: lang.pl [-p=<prefix>] <language file>
6
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
25/* This file was automaticly 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
33/* this is the array with all the strings */
34extern unsigned char *language_strings[];
35
Daniel Stenberg20963dd2002-09-20 06:37:25 +000036/* The enum below contains all available strings */
Daniel Stenberg8b06a012002-09-17 07:17:25 +000037enum {
Daniel Stenberge19f7632002-09-16 15:01:38 +000038MOO
39 ;
40
Daniel Stenberg8b06a012002-09-17 07:17:25 +000041print CFILE <<MOO
42/* This file was automaticly generated using genlang, the strings come
43 from "$input" */
44
45unsigned char *language_strings[]={
46MOO
47 ;
48
49open(LANG, "<$input");
Daniel Stenberge19f7632002-09-16 15:01:38 +000050while(<LANG>) {
Daniel Stenberg1017e252002-10-11 22:01:24 +000051 $line++;
Daniel Stenberge19f7632002-09-16 15:01:38 +000052 if($_ =~ / *\#/) {
53 # comment
54 next;
55 }
Daniel Stenberg1b2db9e2002-09-20 07:06:15 +000056 # get rid of DOS newlines
57 $_ =~ s/\r//g;
Daniel Stenberge19f7632002-09-16 15:01:38 +000058 if($_ =~ / *([a-z]+): *(.*)/) {
59 ($var, $value) = ($1, $2);
Daniel Stenberg1017e252002-10-11 22:01:24 +000060 # print "$var => $value\n";
Daniel Stenberge19f7632002-09-16 15:01:38 +000061
62 $set{$var} = $value;
63
Daniel Stenberg9e8a1c72002-10-13 09:28:46 +000064 if( (($var eq "new") && $value && ($value !~ /^\"(.*)\" *$/)) ||
65 (($var eq "eng") && ($value !~ /^\"(.*)\" *$/)) ) {
Daniel Stenberg17cf4482002-10-14 08:49:25 +000066 print "$input:$line:missing quotes for ".$set{'id'}."\n";
67 $errors++;
Daniel Stenberg1017e252002-10-11 22:01:24 +000068 next;
69 }
70
Daniel Stenberge19f7632002-09-16 15:01:38 +000071 if($var eq "new") {
72 # the last one for a single phrase
73
Daniel Stenberg1d7c1042002-10-14 09:11:48 +000074 if(!$value || ($value eq "\"\"") ) {
Daniel Stenberge19f7632002-09-16 15:01:38 +000075 # if not set, get the english version
76 $value = $set{'eng'};
77 }
78
Daniel Stenbergdade5712002-10-14 12:19:47 +000079 print HFILE " ".$set{'id'}.",\n";
80 print CFILE " $value,\n";
Daniel Stenberg8b06a012002-09-17 07:17:25 +000081
Daniel Stenberge19f7632002-09-16 15:01:38 +000082 undef %set;
83 }
84
85 }
86
87}
88close(LANG);
Daniel Stenberg8b06a012002-09-17 07:17:25 +000089
90
91print HFILE <<MOO
Daniel Stenbergdade5712002-10-14 12:19:47 +000092 LANG_LAST_INDEX_IN_ARRAY /* this is not a string, this is a marker */
Daniel Stenberg8b06a012002-09-17 07:17:25 +000093};
94/* end of generated enum list */
95MOO
96 ;
97
98print CFILE <<MOO
99};
100/* end of generated string list */
101MOO
102 ;
103
104close(CFILE);
105close(HFILE);
Daniel Stenberg17cf4482002-10-14 08:49:25 +0000106
107exit $errors;