summaryrefslogtreecommitdiff
path: root/tools/genlang
diff options
context:
space:
mode:
Diffstat (limited to 'tools/genlang')
-rwxr-xr-xtools/genlang58
1 files changed, 51 insertions, 7 deletions
diff --git a/tools/genlang b/tools/genlang
index 827ceb3949..2e3f212023 100755
--- a/tools/genlang
+++ b/tools/genlang
@@ -1,25 +1,51 @@
1#!/usr/bin/perl 1#!/usr/bin/perl -s
2 2
3if(!$ARGV[0]) { 3if(!$ARGV[0]) {
4 print <<MOO 4 print <<MOO
5Usage: lang.pl <file> 5Usage: 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.
6MOO 9MOO
7; 10;
8 exit; 11 exit;
9} 12}
10 13
11print <<MOO 14my $prefix = $p;
12/* This file was automaticly generated using genlan */ 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 */
13/* 26/*
14 * The str() macro/functions is how to access strings that might be 27 * The str() macro/functions is how to access strings that might be
15 * translated. Use it like str(MACRO) and except a string to be 28 * translated. Use it like str(MACRO) and except a string to be
16 * returned! 29 * returned!
17 */ 30 */
18#define str(x) x 31#define str(x) language_strings[x]
32
33/* this is the array with all the strings */
34extern unsigned char *language_strings[];
35
36enum {
37MOO
38 ;
39
40print CFILE <<MOO
41/* This file was automaticly generated using genlang, the strings come
42 from "$input" */
43
44unsigned char *language_strings[]={
19MOO 45MOO
20 ; 46 ;
21 47
22open(LANG, "<$ARGV[0]"); 48open(LANG, "<$input");
23while(<LANG>) { 49while(<LANG>) {
24 if($_ =~ / *\#/) { 50 if($_ =~ / *\#/) {
25 # comment 51 # comment
@@ -39,7 +65,9 @@ while(<LANG>) {
39 $value = $set{'eng'}; 65 $value = $set{'eng'};
40 } 66 }
41 67
42 print "#define ".$set{'id'}." $value\n"; 68 print HFILE " ".$set{'id'}.",\n";
69 print CFILE " $value,\n";
70
43 undef %set; 71 undef %set;
44 } 72 }
45 73
@@ -47,3 +75,19 @@ while(<LANG>) {
47 75
48} 76}
49close(LANG); 77close(LANG);
78
79
80print HFILE <<MOO
81};
82/* end of generated enum list */
83MOO
84 ;
85
86print CFILE <<MOO
87};
88/* end of generated string list */
89MOO
90 ;
91
92close(CFILE);
93close(HFILE);