src/strgen/strgen.cpp
author KUDr
Sat, 21 Apr 2007 08:23:57 +0000
branchcpp_gui
changeset 6308 646711c5feaa
parent 6298 c30fe89622df
child 9911 0b8b245a2391
permissions -rw-r--r--
(svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2107
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2107
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "../stdafx.h"
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
     4
#include "../macros.h"
4370
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
     5
#include "../string.h"
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
     6
#include "../table/control_codes.h"
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
     7
#include "../helpers.hpp"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
#include <stdio.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     9
#include <string.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
#include <stdlib.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include <stdarg.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
2482
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2459
diff changeset
    13
#if (!defined(WIN32) && !defined(WIN64)) || defined(__CYGWIN__)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include <unistd.h>
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
    15
#include <sys/types.h>
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
    16
#include <sys/stat.h>
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
4370
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
    19
#if defined WIN32 || defined __WATCOMC__
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
    20
#include <direct.h>
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
    21
#endif /* WIN32 || __WATCOMC__ */
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
    22
181
0b95567f2d0f (svn r182) -Fix: [1024380] strgen diff (Warning fix + MorphOS fix). Removes the longest standing warning on compilation of strgen (tokai)
darkvater
parents: 0
diff changeset
    23
#ifdef __MORPHOS__
0b95567f2d0f (svn r182) -Fix: [1024380] strgen diff (Warning fix + MorphOS fix). Removes the longest standing warning on compilation of strgen (tokai)
darkvater
parents: 0
diff changeset
    24
#ifdef stderr
0b95567f2d0f (svn r182) -Fix: [1024380] strgen diff (Warning fix + MorphOS fix). Removes the longest standing warning on compilation of strgen (tokai)
darkvater
parents: 0
diff changeset
    25
#undef stderr
0b95567f2d0f (svn r182) -Fix: [1024380] strgen diff (Warning fix + MorphOS fix). Removes the longest standing warning on compilation of strgen (tokai)
darkvater
parents: 0
diff changeset
    26
#endif
0b95567f2d0f (svn r182) -Fix: [1024380] strgen diff (Warning fix + MorphOS fix). Removes the longest standing warning on compilation of strgen (tokai)
darkvater
parents: 0
diff changeset
    27
#define stderr stdout
4370
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
    28
#endif /* __MORPHOS__ */
181
0b95567f2d0f (svn r182) -Fix: [1024380] strgen diff (Warning fix + MorphOS fix). Removes the longest standing warning on compilation of strgen (tokai)
darkvater
parents: 0
diff changeset
    29
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
/* Compiles a list of strings into a compiled string list */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
typedef void (*ParseCmdProc)(char *buf, int value);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6083
diff changeset
    34
struct LanguagePackHeader {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
	uint32 ident;
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4077
diff changeset
    36
	uint32 version;     // 32-bits of auto generated version info which is basically a hash of strings.h
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4077
diff changeset
    37
	char name[32];      // the international name of this language
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4379
diff changeset
    38
	char own_name[32];  // the localized name of this language
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4077
diff changeset
    39
	char isocode[16];   // the ISO code for the language (not country code)
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4077
diff changeset
    40
	uint16 offsets[32]; // the offsets
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4077
diff changeset
    41
	byte plural_form;   // plural form index
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4077
diff changeset
    42
	byte pad[3];        // pad header to be a multiple of 4
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6083
diff changeset
    43
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6083
diff changeset
    45
struct CmdStruct {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
	const char *cmd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
	ParseCmdProc proc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
	long value;
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
    49
	int8 consumes;
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    50
	byte flags;
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6083
diff changeset
    51
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    53
enum {
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    54
	C_DONTCOUNT = 1,
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4077
diff changeset
    55
	C_CASE      = 2,
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    56
};
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    57
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    58
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6083
diff changeset
    59
struct Case {
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    60
	int caseidx;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    61
	char *string;
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6083
diff changeset
    62
	Case *next;
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6083
diff changeset
    63
};
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    64
2586
c0ec490c5150 (svn r3123) eh, don't press enter after typing text, previous patch wasn't finished. Now strgen really behaves correctly. Thanks again glx
Darkvater
parents: 2585
diff changeset
    65
static bool _masterlang;
2585
b4b7a65ca209 (svn r3122) - Fix (regression): recent change to strgen which 'fixed' all strings with wrong plural forms. Thanks for glx for pointing this out (after I changed his original patch which was correct..whohoo braindeadness; here I come)
Darkvater
parents: 2566
diff changeset
    66
static bool _translated;
2459
4b65354b7586 (svn r2985) Print warnings and errors in the canonical file:line: form to make life for IDEs easier (ln-)
tron
parents: 2418
diff changeset
    67
static const char* _file = "(unknown file)";
2059
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
    68
static int _cur_line;
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
    69
static int _errors, _warnings;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
    70
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6083
diff changeset
    71
struct LangString {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4077
diff changeset
    72
	char *name;            // Name of the string
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4077
diff changeset
    73
	char *english;         // English text
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4077
diff changeset
    74
	char *translated;      // Translated text
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4077
diff changeset
    75
	uint16 hash_next;      // next hash entry
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    76
	uint16 index;
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4077
diff changeset
    77
	int line;              // line of string in source-file
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4077
diff changeset
    78
	Case *english_case;    // cases for english
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4077
diff changeset
    79
	Case *translated_case; // cases for foreign
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6083
diff changeset
    80
};
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    81
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    82
static LangString *_strings[65536];
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    83
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
    84
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
    85
#define HASH_SIZE 32767
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
    86
static uint16 _hash_head[HASH_SIZE];
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
    87
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
    88
static byte _put_buf[4096];
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
    89
static int _put_pos;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
    90
static int _next_string_id;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
2059
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
    92
static uint32 _hash;
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
    93
static char _lang_name[32], _lang_ownname[32], _lang_isocode[16];
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
    94
static byte _lang_pluralform;
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    95
#define MAX_NUM_GENDER 8
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    96
static char _genders[MAX_NUM_GENDER][8];
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    97
static int _numgenders;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    98
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    99
// contains the name of all cases.
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   100
#define MAX_NUM_CASES 50
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   101
static char _cases[MAX_NUM_CASES][16];
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   102
static int _numcases;
2084
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   103
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   104
// for each plural value, this is the number of plural forms.
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4077
diff changeset
   105
static const byte _plural_form_counts[] = { 2, 1, 2, 3, 3, 3, 3, 3, 4 };
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   106
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   107
static const char *_cur_ident;
2059
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   108
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6083
diff changeset
   109
struct CmdPair {
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   110
	const CmdStruct *a;
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   111
	const char *v;
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6083
diff changeset
   112
};
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   113
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6083
diff changeset
   114
struct ParsedCommandStruct {
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   115
	int np;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   116
	CmdPair pairs[32];
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   117
	const CmdStruct *cmd[32]; // ordered by param #
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6083
diff changeset
   118
};
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   119
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   120
// Used when generating some advanced commands.
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   121
static ParsedCommandStruct _cur_pcs;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   122
static int _cur_argidx;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   123
2059
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   124
static uint HashStr(const char *s)
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   125
{
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   126
	uint hash = 0;
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   127
	for (; *s != '\0'; s++) hash = ROL(hash, 3) ^ *s;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
	return hash % HASH_SIZE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
}
2059
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   130
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   131
static void HashAdd(const char *s, LangString *ls)
2059
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   132
{
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   133
	uint hash = HashStr(s);
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   134
	ls->hash_next = _hash_head[hash];
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   135
	_hash_head[hash] = ls->index + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   137
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   138
static LangString *HashFind(const char *s)
2059
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   139
{
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   140
	int idx = _hash_head[HashStr(s)];
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   141
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   142
	while (--idx >= 0) {
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   143
		LangString* ls = _strings[idx];
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   144
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   145
		if (strcmp(ls->name, s) == 0) return ls;
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   146
		idx = ls->hash_next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
	}
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   148
	return NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3718
diff changeset
   151
#ifdef _MSC_VER
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3718
diff changeset
   152
# define LINE_NUM_FMT "(%d)"
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3718
diff changeset
   153
#else
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3718
diff changeset
   154
# define LINE_NUM_FMT ":%d"
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3718
diff changeset
   155
#endif
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   156
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   157
static void CDECL warning(const char *s, ...)
2059
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   158
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
	char buf[1024];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
	va_list va;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
	va_start(va, s);
4370
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
   162
	vsnprintf(buf, lengthof(buf), s, va);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
	va_end(va);
4447
d196eec23f9f (svn r6225) -Codechange: change the warning/error format of strgen to show up
Darkvater
parents: 4434
diff changeset
   164
	fprintf(stderr, "%s" LINE_NUM_FMT ": warning: %s\n", _file, _cur_line, buf);
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   165
	_warnings++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   168
void CDECL error(const char *s, ...)
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   169
{
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   170
	char buf[1024];
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   171
	va_list va;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   172
	va_start(va, s);
4370
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
   173
	vsnprintf(buf, lengthof(buf), s, va);
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   174
	va_end(va);
4447
d196eec23f9f (svn r6225) -Codechange: change the warning/error format of strgen to show up
Darkvater
parents: 4434
diff changeset
   175
	fprintf(stderr, "%s" LINE_NUM_FMT ": error: %s\n", _file, _cur_line, buf);
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   176
	_errors++;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   177
}
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   178
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   179
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   180
static void NORETURN CDECL fatal(const char *s, ...)
2059
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   181
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
	char buf[1024];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
	va_list va;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
	va_start(va, s);
4370
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
   185
	vsnprintf(buf, lengthof(buf), s, va);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
	va_end(va);
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3718
diff changeset
   187
	fprintf(stderr, "%s" LINE_NUM_FMT ": FATAL: %s\n", _file, _cur_line, buf);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
	exit(1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   191
static void PutByte(byte c)
2059
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   192
{
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   193
	if (_put_pos == lengthof(_put_buf)) fatal("Put buffer too small");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
	_put_buf[_put_pos++] = c;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   198
static void PutUtf8(uint32 value)
2059
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   199
{
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   200
	if (value < 0x80) {
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   201
		PutByte(value);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   202
	} else if (value < 0x800) {
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   203
		PutByte(0xC0 + GB(value,  6, 5));
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   204
		PutByte(0x80 + GB(value,  0, 6));
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   205
	} else if (value < 0x10000) {
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   206
		PutByte(0xE0 + GB(value, 12, 4));
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   207
		PutByte(0x80 + GB(value,  6, 6));
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   208
		PutByte(0x80 + GB(value,  0, 6));
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   209
	} else if (value < 0x110000) {
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   210
		PutByte(0xF0 + GB(value, 18, 3));
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   211
		PutByte(0x80 + GB(value, 12, 6));
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   212
		PutByte(0x80 + GB(value,  6, 6));
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   213
		PutByte(0x80 + GB(value,  0, 6));
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   214
	} else {
5548
209971b79b9a (svn r7540) -Codechange: Print a summary of the number of errors/warnings of a language when strgen is run with the -w flag.
Darkvater
parents: 5111
diff changeset
   215
		warning("Invalid unicode value U+0x%X", value);
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   216
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
5111
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   220
size_t Utf8Validate(const char *s)
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   221
{
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   222
	uint32 c;
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   223
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   224
	if (!HASBIT(s[0], 7)) {
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   225
		/* 1 byte */
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   226
		return 1;
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   227
	} else if (GB(s[0], 5, 3) == 6 && IsUtf8Part(s[1])) {
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   228
		/* 2 bytes */
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   229
		c = GB(s[0], 0, 5) << 6 | GB(s[1], 0, 6);
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   230
		if (c >= 0x80) return 2;
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   231
	} else if (GB(s[0], 4, 4) == 14 && IsUtf8Part(s[1]) && IsUtf8Part(s[2])) {
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   232
		/* 3 bytes */
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   233
		c = GB(s[0], 0, 4) << 12 | GB(s[1], 0, 6) << 6 | GB(s[2], 0, 6);
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   234
		if (c >= 0x800) return 3;
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   235
	} else if (GB(s[0], 3, 5) == 30 && IsUtf8Part(s[1]) && IsUtf8Part(s[2]) && IsUtf8Part(s[3])) {
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   236
		/* 4 bytes */
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   237
		c = GB(s[0], 0, 3) << 18 | GB(s[1], 0, 6) << 12 | GB(s[2], 0, 6) << 6 | GB(s[3], 0, 6);
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   238
		if (c >= 0x10000 && c <= 0x10FFFF) return 4;
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   239
	}
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   240
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   241
	return 0;
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   242
}
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   243
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   244
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   245
static void EmitSingleChar(char *buf, int value)
2059
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   246
{
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   247
	if (*buf != '\0') warning("Ignoring trailing letters in command");
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   248
	PutUtf8(value);
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   249
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   251
2059
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   252
static void EmitSetX(char *buf, int value)
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   253
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
	char *err;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
	int x = strtol(buf, &err, 0);
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   256
	if (*err != 0) fatal("SetX param invalid");
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   257
	PutUtf8(SCC_SETX);
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   258
	PutByte((byte)x);
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   259
}
2059
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   260
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
2059
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   262
static void EmitSetXY(char *buf, int value)
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   263
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
	char *err;
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   265
	int x;
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   266
	int y;
2059
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   267
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   268
	x = strtol(buf, &err, 0);
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   269
	if (*err != ' ') fatal("SetXY param invalid");
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   270
	y = strtol(err + 1, &err, 0);
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   271
	if (*err != 0) fatal("SetXY param invalid");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   273
	PutUtf8(SCC_SETXY);
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   274
	PutByte((byte)x);
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   275
	PutByte((byte)y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   278
// The plural specifier looks like
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   279
// {NUM} {PLURAL -1 passenger passengers} then it picks either passenger/passengers depending on the count in NUM
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   280
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   281
// This is encoded like
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   282
//  CommandByte <ARG#> <NUM> {Length of each string} {each string}
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   283
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   284
bool ParseRelNum(char **buf, int *value)
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   285
{
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   286
	const char* s = *buf;
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   287
	char* end;
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   288
	bool rel = false;
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   289
	int v;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   290
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   291
	while (*s == ' ' || *s == '\t') s++;
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   292
	if (*s == '+') {
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   293
		rel = true;
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   294
		s++;
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   295
	}
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   296
	v = strtol(s, &end, 0);
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   297
	if (end == s) return false;
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   298
	if (rel || v < 0) {
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   299
		*value += v;
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   300
	} else {
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   301
		*value = v;
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   302
	}
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   303
	*buf = end;
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   304
	return true;
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   305
}
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   306
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   307
// Parse out the next word, or NULL
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   308
char *ParseWord(char **buf)
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   309
{
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   310
	char *s = *buf, *r;
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   311
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   312
	while (*s == ' ' || *s == '\t') s++;
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   313
	if (*s == '\0') return NULL;
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   314
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   315
	if (*s == '"') {
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   316
		r = ++s;
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   317
		// parse until next " or NUL
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   318
		for (;;) {
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   319
			if (*s == '\0') break;
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   320
			if (*s == '"') {
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   321
				*s++ = '\0';
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   322
				break;
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   323
			}
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   324
			s++;
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   325
		}
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   326
	} else {
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   327
		// proceed until whitespace or NUL
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   328
		r = s;
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   329
		for (;;) {
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   330
			if (*s == '\0') break;
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   331
			if (*s == ' ' || *s == '\t') {
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   332
				*s++ = '\0';
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   333
				break;
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   334
			}
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   335
			s++;
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   336
		}
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   337
	}
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   338
	*buf = s;
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   339
	return r;
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   340
}
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   341
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   342
// Forward declaration
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   343
static int TranslateArgumentIdx(int arg);
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   344
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   345
static void EmitWordList(const char* const* words, uint nw)
2084
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   346
{
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   347
	uint i;
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   348
	uint j;
2084
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   349
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   350
	PutByte(nw);
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   351
	for (i = 0; i < nw; i++) PutByte(strlen(words[i]));
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   352
	for (i = 0; i < nw; i++) {
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   353
		for (j = 0; words[i][j] != '\0'; j++) PutByte(words[i][j]);
2084
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   354
	}
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   355
}
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   356
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   357
static void EmitPlural(char *buf, int value)
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   358
{
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   359
	int argidx = _cur_argidx;
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   360
	const char* words[5];
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   361
	int nw = 0;
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   362
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   363
	// Parse out the number, if one exists. Otherwise default to prev arg.
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   364
	if (!ParseRelNum(&buf, &argidx)) argidx--;
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   365
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   366
	// Parse each string
2566
da24c0f2d2d8 (svn r3103) - Fix: [ 1339000 ] Fix: strgen and plural forms fatal error for untranslated strings. (glx). Also output the correct lines for these warnings, for missing strings the lines correspond with the ones in english.txt
Darkvater
parents: 2482
diff changeset
   367
	for (nw = 0; nw < 5; nw++) {
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   368
		words[nw] = ParseWord(&buf);
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   369
		if (words[nw] == NULL) break;
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   370
	}
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   371
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   372
	if (nw == 0)
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   373
		fatal("%s: No plural words", _cur_ident);
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   374
2765
b00f2d3d7964 (svn r3310) Fix a couple of warnings: Initialise all struct members, disambiguate cascaded if/else, remove an unused variable, use (void) for empty parameter lists
tron
parents: 2586
diff changeset
   375
	if (_plural_form_counts[_lang_pluralform] != nw) {
2585
b4b7a65ca209 (svn r3122) - Fix (regression): recent change to strgen which 'fixed' all strings with wrong plural forms. Thanks for glx for pointing this out (after I changed his original patch which was correct..whohoo braindeadness; here I come)
Darkvater
parents: 2566
diff changeset
   376
		if (_translated) {
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   377
			fatal("%s: Invalid number of plural forms. Expecting %d, found %d.", _cur_ident,
2566
da24c0f2d2d8 (svn r3103) - Fix: [ 1339000 ] Fix: strgen and plural forms fatal error for untranslated strings. (glx). Also output the correct lines for these warnings, for missing strings the lines correspond with the ones in english.txt
Darkvater
parents: 2482
diff changeset
   378
				_plural_form_counts[_lang_pluralform], nw);
da24c0f2d2d8 (svn r3103) - Fix: [ 1339000 ] Fix: strgen and plural forms fatal error for untranslated strings. (glx). Also output the correct lines for these warnings, for missing strings the lines correspond with the ones in english.txt
Darkvater
parents: 2482
diff changeset
   379
		} else {
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   380
			warning("'%s' is untranslated. Tweaking english string to allow compilation for plural forms", _cur_ident);
2566
da24c0f2d2d8 (svn r3103) - Fix: [ 1339000 ] Fix: strgen and plural forms fatal error for untranslated strings. (glx). Also output the correct lines for these warnings, for missing strings the lines correspond with the ones in english.txt
Darkvater
parents: 2482
diff changeset
   381
			if (nw > _plural_form_counts[_lang_pluralform]) {
da24c0f2d2d8 (svn r3103) - Fix: [ 1339000 ] Fix: strgen and plural forms fatal error for untranslated strings. (glx). Also output the correct lines for these warnings, for missing strings the lines correspond with the ones in english.txt
Darkvater
parents: 2482
diff changeset
   382
				nw = _plural_form_counts[_lang_pluralform];
da24c0f2d2d8 (svn r3103) - Fix: [ 1339000 ] Fix: strgen and plural forms fatal error for untranslated strings. (glx). Also output the correct lines for these warnings, for missing strings the lines correspond with the ones in english.txt
Darkvater
parents: 2482
diff changeset
   383
			} else {
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   384
				for (; nw < _plural_form_counts[_lang_pluralform]; nw++) {
2566
da24c0f2d2d8 (svn r3103) - Fix: [ 1339000 ] Fix: strgen and plural forms fatal error for untranslated strings. (glx). Also output the correct lines for these warnings, for missing strings the lines correspond with the ones in english.txt
Darkvater
parents: 2482
diff changeset
   385
					words[nw] = words[nw - 1];
da24c0f2d2d8 (svn r3103) - Fix: [ 1339000 ] Fix: strgen and plural forms fatal error for untranslated strings. (glx). Also output the correct lines for these warnings, for missing strings the lines correspond with the ones in english.txt
Darkvater
parents: 2482
diff changeset
   386
				}
da24c0f2d2d8 (svn r3103) - Fix: [ 1339000 ] Fix: strgen and plural forms fatal error for untranslated strings. (glx). Also output the correct lines for these warnings, for missing strings the lines correspond with the ones in english.txt
Darkvater
parents: 2482
diff changeset
   387
			}
da24c0f2d2d8 (svn r3103) - Fix: [ 1339000 ] Fix: strgen and plural forms fatal error for untranslated strings. (glx). Also output the correct lines for these warnings, for missing strings the lines correspond with the ones in english.txt
Darkvater
parents: 2482
diff changeset
   388
		}
2765
b00f2d3d7964 (svn r3310) Fix a couple of warnings: Initialise all struct members, disambiguate cascaded if/else, remove an unused variable, use (void) for empty parameter lists
tron
parents: 2586
diff changeset
   389
	}
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   390
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   391
	PutUtf8(SCC_PLURAL_LIST);
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   392
	PutByte(TranslateArgumentIdx(argidx));
2084
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   393
	EmitWordList(words, nw);
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   394
}
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   395
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   396
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   397
static void EmitGender(char *buf, int value)
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   398
{
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   399
	int argidx = _cur_argidx;
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   400
	uint nw;
2084
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   401
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   402
	if (buf[0] == '=') {
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   403
		buf++;
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   404
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   405
		// This is a {G=DER} command
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   406
		for (nw = 0; ; nw++) {
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   407
			if (nw >= 8) fatal("G argument '%s' invalid", buf);
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   408
			if (strcmp(buf, _genders[nw]) == 0) break;
2084
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   409
		}
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   410
		// now nw contains the gender index
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   411
		PutUtf8(SCC_GENDER_INDEX);
2084
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   412
		PutByte(nw);
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   413
	} else {
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   414
		const char* words[8];
2084
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   415
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   416
		// This is a {G 0 foo bar two} command.
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   417
		// If no relative number exists, default to +0
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   418
		if (!ParseRelNum(&buf, &argidx)) {}
2084
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   419
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   420
		for (nw = 0; nw < 8; nw++) {
2084
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   421
			words[nw] = ParseWord(&buf);
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   422
			if (words[nw] == NULL) break;
2084
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   423
		}
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   424
		if (nw != _numgenders) fatal("Bad # of arguments for gender command");
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   425
		PutUtf8(SCC_GENDER_LIST);
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   426
		PutByte(TranslateArgumentIdx(argidx));
2084
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   427
		EmitWordList(words, nw);
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   428
	}
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   429
}
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   430
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   431
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   432
static const CmdStruct _cmd_structs[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
	// Update position
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   434
	{"SETX",  EmitSetX,  SCC_SETX,  0, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   435
	{"SETXY", EmitSetXY, SCC_SETXY, 0, 0},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
	// Font size
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   438
	{"TINYFONT", EmitSingleChar, SCC_TINYFONT, 0, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   439
	{"BIGFONT",  EmitSingleChar, SCC_BIGFONT,  0, 0},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
	// Colors
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   442
	{"BLUE",    EmitSingleChar, SCC_BLUE,    0, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   443
	{"SILVER",  EmitSingleChar, SCC_SILVER,  0, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   444
	{"GOLD",    EmitSingleChar, SCC_GOLD,    0, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   445
	{"RED",     EmitSingleChar, SCC_RED,     0, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   446
	{"PURPLE",  EmitSingleChar, SCC_PURPLE,  0, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   447
	{"LTBROWN", EmitSingleChar, SCC_LTBROWN, 0, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   448
	{"ORANGE",  EmitSingleChar, SCC_ORANGE,  0, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   449
	{"GREEN",   EmitSingleChar, SCC_GREEN,   0, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   450
	{"YELLOW",  EmitSingleChar, SCC_YELLOW,  0, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   451
	{"DKGREEN", EmitSingleChar, SCC_DKGREEN, 0, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   452
	{"CREAM",   EmitSingleChar, SCC_CREAM,   0, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   453
	{"BROWN",   EmitSingleChar, SCC_BROWN,   0, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   454
	{"WHITE",   EmitSingleChar, SCC_WHITE,   0, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   455
	{"LTBLUE",  EmitSingleChar, SCC_LTBLUE,  0, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   456
	{"GRAY",    EmitSingleChar, SCC_GRAY,    0, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   457
	{"DKBLUE",  EmitSingleChar, SCC_DKBLUE,  0, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   458
	{"BLACK",   EmitSingleChar, SCC_BLACK,   0, 0},
222
b88456001397 (svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents: 181
diff changeset
   459
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   460
	{"CURRCOMPACT",   EmitSingleChar, SCC_CURRENCY_COMPACT,    1, 0}, // compact currency (32 bits)
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   461
	{"REV",           EmitSingleChar, SCC_REVISION,            0, 0}, // openttd revision string
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   462
	{"SHORTCARGO",    EmitSingleChar, SCC_CARGO_SHORT,         2, 0}, // short cargo description, only ### tons, or ### litres
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   463
	{"CURRCOMPACT64", EmitSingleChar, SCC_CURRENCY_COMPACT_64, 2, 0}, // compact currency 64 bits
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   465
	// These are special versions of {STRING1}
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   466
	// The first string includes the second string.
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   467
	{"COMPANY",    EmitSingleChar, SCC_STRING1, 1, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   468
	{"PLAYERNAME", EmitSingleChar, SCC_STRING1, 1, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   469
	{"VEHICLE",    EmitSingleChar, SCC_STRING1, 1, 0},
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   470
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   471
	{"STRING1", EmitSingleChar, SCC_STRING1, 1, C_CASE}, // included string that consumes ONE argument
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   472
	{"STRING2", EmitSingleChar, SCC_STRING2, 2, C_CASE}, // included string that consumes TWO arguments
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   473
	{"STRING3", EmitSingleChar, SCC_STRING3, 3, C_CASE}, // included string that consumes THREE arguments
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   474
	{"STRING4", EmitSingleChar, SCC_STRING4, 4, C_CASE}, // included string that consumes FOUR arguments
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   475
	{"STRING5", EmitSingleChar, SCC_STRING5, 5, C_CASE}, // included string that consumes FIVE arguments
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   476
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   477
	{"STATIONFEATURES", EmitSingleChar, SCC_STATION_FEATURES, 1, 0}, // station features string, icons of the features
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   478
	{"INDUSTRY",        EmitSingleChar, SCC_INDUSTRY_NAME,    1, 0}, // industry, takes an industry #
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   479
	{"CARGO",           EmitSingleChar, SCC_CARGO,            2, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   480
	{"POWER",           EmitSingleChar, SCC_POWER,            1, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   481
	{"VOLUME",          EmitSingleChar, SCC_VOLUME,           1, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   482
	{"VOLUME_S",        EmitSingleChar, SCC_VOLUME_SHORT,     1, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   483
	{"WEIGHT",          EmitSingleChar, SCC_WEIGHT,           1, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   484
	{"WEIGHT_S",        EmitSingleChar, SCC_WEIGHT_SHORT,     1, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   485
	{"FORCE",           EmitSingleChar, SCC_FORCE,            1, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   486
	{"VELOCITY",        EmitSingleChar, SCC_VELOCITY,         1, 0},
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   487
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4379
diff changeset
   488
	{"P", EmitPlural, 0, 0, C_DONTCOUNT}, // plural specifier
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4379
diff changeset
   489
	{"G", EmitGender, 0, 0, C_DONTCOUNT}, // gender specifier
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   490
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   491
	{"DATE_TINY",  EmitSingleChar, SCC_DATE_TINY, 1, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   492
	{"DATE_SHORT", EmitSingleChar, SCC_DATE_SHORT, 1, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   493
	{"DATE_LONG",  EmitSingleChar, SCC_DATE_LONG, 1, 0},
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   494
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   495
	{"SKIP", EmitSingleChar, SCC_SKIP, 1, 0},
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   496
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   497
	{"STRING", EmitSingleChar, SCC_STRING, 1, C_CASE},
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   498
2410
d1fae093e768 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2407
diff changeset
   499
	// Numbers
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   500
	{"COMMA", EmitSingleChar, SCC_COMMA, 1, 0}, // Number with comma
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   501
	{"NUM",   EmitSingleChar, SCC_NUM,   1, 0}, // Signed number
2410
d1fae093e768 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2407
diff changeset
   502
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   503
	{"CURRENCY",   EmitSingleChar, SCC_CURRENCY,    1, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   504
	{"CURRENCY64", EmitSingleChar, SCC_CURRENCY_64, 2, 0},
2410
d1fae093e768 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2407
diff changeset
   505
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   506
	{"WAYPOINT", EmitSingleChar, SCC_WAYPOINT_NAME, 1, 0}, // waypoint name
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   507
	{"STATION",  EmitSingleChar, SCC_STATION_NAME,  1, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   508
	{"TOWN",     EmitSingleChar, SCC_TOWN_NAME,     1, 0},
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   509
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   510
	// 0x9D is used for the pseudo command SETCASE
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   511
	// 0x9E is used for case switching
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   512
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   513
	{"",               EmitSingleChar, '\n',               0, C_DONTCOUNT},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   514
	{"{",              EmitSingleChar, '{',                0, C_DONTCOUNT},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   515
	{"UPARROW",        EmitSingleChar, SCC_UPARROW,        0, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   516
	{"SMALLUPARROW",   EmitSingleChar, SCC_SMALLUPARROW,   0, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   517
	{"SMALLDOWNARROW", EmitSingleChar, SCC_SMALLDOWNARROW, 0, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   518
	{"TRAIN",          EmitSingleChar, SCC_TRAIN,          0, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   519
	{"LORRY",          EmitSingleChar, SCC_LORRY,          0, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   520
	{"BUS",            EmitSingleChar, SCC_BUS,            0, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   521
	{"PLANE",          EmitSingleChar, SCC_PLANE,          0, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   522
	{"SHIP",           EmitSingleChar, SCC_SHIP,           0, 0},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   523
	{"NBSP",           EmitSingleChar, 0xA0,               0, C_DONTCOUNT},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   524
	{"CENT",           EmitSingleChar, 0xA2,               0, C_DONTCOUNT},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   525
	{"POUNDSIGN",      EmitSingleChar, 0xA3,               0, C_DONTCOUNT},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   526
	{"EURO",           EmitSingleChar, 0x20AC,             0, C_DONTCOUNT},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   527
	{"YENSIGN",        EmitSingleChar, 0xA5,               0, C_DONTCOUNT},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   528
	{"COPYRIGHT",      EmitSingleChar, 0xA9,               0, C_DONTCOUNT},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   529
	{"DOWNARROW",      EmitSingleChar, SCC_DOWNARROW,      0, C_DONTCOUNT},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   530
	{"CHECKMARK",      EmitSingleChar, SCC_CHECKMARK,      0, C_DONTCOUNT},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   531
	{"CROSS",          EmitSingleChar, SCC_CROSS,          0, C_DONTCOUNT},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   532
	{"REGISTERED",     EmitSingleChar, 0xAE,               0, C_DONTCOUNT},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   533
	{"RIGHTARROW",     EmitSingleChar, SCC_RIGHTARROW,     0, C_DONTCOUNT},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   534
	{"SMALLLEFTARROW", EmitSingleChar, SCC_LESSTHAN,       0, C_DONTCOUNT},
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
   535
	{"SMALLRIGHTARROW",EmitSingleChar, SCC_GREATERTHAN,    0, C_DONTCOUNT},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   536
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   537
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   538
2059
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   539
static const CmdStruct *FindCmd(const char *s, int len)
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   540
{
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   541
	const CmdStruct* cs;
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   542
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   543
	for (cs = _cmd_structs; cs != endof(_cmd_structs); cs++) {
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   544
		if (strncmp(cs->cmd, s, len) == 0 && cs->cmd[len] == '\0') return cs;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   548
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   549
static uint ResolveCaseName(const char *str, uint len)
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   550
{
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   551
	uint i;
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   552
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   553
	for (i = 0; i < MAX_NUM_CASES; i++) {
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   554
		if (memcmp(_cases[i], str, len) == 0 && _cases[i][len] == 0) return i + 1;
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   555
	}
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   556
	fatal("Invalid case-name '%s'", str);
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   557
}
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   558
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   559
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   560
// returns NULL on eof
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   561
// else returns command struct
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   562
static const CmdStruct *ParseCommandString(const char **str, char *param, int *argno, int *casei)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   563
{
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   564
	const char *s = *str, *start;
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   565
	const CmdStruct *cmd;
2060
b414856d85af (svn r2569) Get rid of some dubious casts and thus warnings on 64bit machines
tron
parents: 2059
diff changeset
   566
	byte c;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   567
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   568
	*argno = -1;
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   569
	*casei = -1;
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   570
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   571
	// Scan to the next command, exit if there's no next command.
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   572
	for (; *s != '{'; s++) {
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   573
		if (*s == '\0') return NULL;
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   574
	}
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   575
	s++; // Skip past the {
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   576
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   577
	if (*s >= '0' && *s <= '9') {
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   578
		char *end;
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   579
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   580
		*argno = strtoul(s, &end, 0);
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   581
		if (*end != ':') fatal("missing arg #");
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   582
		s = end + 1;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   583
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
	// parse command name
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   586
	start = s;
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   587
	do {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
		c = *s++;
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   589
	} while (c != '}' && c != ' ' && c != '=' && c != '.' && c != 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
2059
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   591
	cmd = FindCmd(start, s - start - 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
	if (cmd == NULL) {
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   593
		error("Undefined command '%.*s'", s - start - 1, start);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   594
		return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   597
	if (c == '.') {
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   598
		const char *casep = s;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   599
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   600
		if (!(cmd->flags & C_CASE))
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   601
			fatal("Command '%s' can't have a case", cmd->cmd);
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   602
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   603
		do c = *s++; while (c != '}' && c != ' ' && c != '\0');
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   604
		*casei = ResolveCaseName(casep, s - casep - 1);
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   605
	}
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   606
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   607
	if (c == '\0') {
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   608
		error("Missing } from command '%s'", start);
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   609
		return NULL;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   610
	}
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   611
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   612
2084
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   613
	if (c != '}') {
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   614
		if (c == '=') s--;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   615
		// copy params
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   616
		start = s;
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   617
		for (;;) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
			c = *s++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
			if (c == '}') break;
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   620
			if (c == '\0') {
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   621
				error("Missing } from command '%s'", start);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
				return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
			}
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   624
			if (s - start == 250) fatal("param command too long");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   625
			*param++ = c;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   626
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   627
	}
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   628
	*param = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   629
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   630
	*str = s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   632
	return cmd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   633
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   634
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   635
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   636
static void HandlePragma(char *str)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   637
{
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   638
	if (!memcmp(str, "id ", 3)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   639
		_next_string_id = strtoul(str + 3, NULL, 0);
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   640
	} else if (!memcmp(str, "name ", 5)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
		ttd_strlcpy(_lang_name, str + 5, sizeof(_lang_name));
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   642
	} else if (!memcmp(str, "ownname ", 8)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
		ttd_strlcpy(_lang_ownname, str + 8, sizeof(_lang_ownname));
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   644
	} else if (!memcmp(str, "isocode ", 8)) {
1376
425781645fba (svn r1880) [Codechange] Added isocodes to langfiles and support code to strgen (Lauri Nurmi)
miham
parents: 1097
diff changeset
   645
		ttd_strlcpy(_lang_isocode, str + 8, sizeof(_lang_isocode));
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   646
	} else if (!memcmp(str, "plural ", 7)) {
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   647
		_lang_pluralform = atoi(str + 7);
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   648
		if (_lang_pluralform >= lengthof(_plural_form_counts))
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   649
			fatal("Invalid pluralform %d", _lang_pluralform);
2084
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   650
	} else if (!memcmp(str, "gender ", 7)) {
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   651
		char* buf = str + 7;
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   652
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   653
		for (;;) {
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   654
			const char* s = ParseWord(&buf);
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   655
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   656
			if (s == NULL) break;
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   657
			if (_numgenders >= MAX_NUM_GENDER) fatal("Too many genders, max %d", MAX_NUM_GENDER);
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   658
			ttd_strlcpy(_genders[_numgenders], s, sizeof(_genders[_numgenders]));
2084
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   659
			_numgenders++;
d67790a49f78 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   660
		}
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   661
	} else if (!memcmp(str, "case ", 5)) {
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   662
		char* buf = str + 5;
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   663
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   664
		for (;;) {
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   665
			const char* s = ParseWord(&buf);
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   666
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   667
			if (s == NULL) break;
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   668
			if (_numcases >= MAX_NUM_CASES) fatal("Too many cases, max %d", MAX_NUM_CASES);
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   669
			ttd_strlcpy(_cases[_numcases], s, sizeof(_cases[_numcases]));
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   670
			_numcases++;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   671
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   672
	} else {
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   673
		fatal("unknown pragma '%s'", str);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   674
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   675
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   676
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   677
static void ExtractCommandString(ParsedCommandStruct* p, const char* s, bool warnings)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   678
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   679
	char param[100];
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   680
	int argno;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   681
	int argidx = 0;
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   682
	int casei;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   683
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   684
	memset(p, 0, sizeof(*p));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   685
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   686
	for (;;) {
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   687
		// read until next command from a.
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   688
		const CmdStruct* ar = ParseCommandString(&s, param, &argno, &casei);
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   689
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   690
		if (ar == NULL) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   691
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   692
		// Sanity checking
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   693
		if (argno != -1 && ar->consumes == 0) fatal("Non consumer param can't have a paramindex");
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   694
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   695
		if (ar->consumes) {
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   696
			if (argno != -1) argidx = argno;
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   697
			if (argidx < 0 || argidx >= lengthof(p->cmd)) fatal("invalid param idx %d", argidx);
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   698
			if (p->cmd[argidx] != NULL && p->cmd[argidx] != ar) fatal("duplicate param idx %d", argidx);
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   699
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   700
			p->cmd[argidx++] = ar;
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   701
		} else if (!(ar->flags & C_DONTCOUNT)) { // Ignore some of them
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   702
			if (p->np >= lengthof(p->pairs)) fatal("too many commands in string, max %d", lengthof(p->pairs));
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   703
			p->pairs[p->np].a = ar;
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   704
			p->pairs[p->np].v = param[0] != '\0' ? strdup(param) : "";
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   705
			p->np++;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   706
		}
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   707
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   708
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   709
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   710
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   711
static const CmdStruct *TranslateCmdForCompare(const CmdStruct *a)
2059
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   712
{
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   713
	if (a == NULL) return NULL;
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   714
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   715
	if (strcmp(a->cmd, "STRING1") == 0 ||
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   716
			strcmp(a->cmd, "STRING2") == 0 ||
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   717
			strcmp(a->cmd, "STRING3") == 0 ||
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   718
			strcmp(a->cmd, "STRING4") == 0 ||
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   719
			strcmp(a->cmd, "STRING5") == 0) {
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   720
		return FindCmd("STRING", 6);
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   721
	}
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   722
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   723
	if (strcmp(a->cmd, "SKIP") == 0) return NULL;
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   724
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   725
	return a;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   726
}
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   727
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   728
2069
929b43e70be9 (svn r2579) Change some strgen errors into warnings to prevent build from stopping.
ludde
parents: 2063
diff changeset
   729
static bool CheckCommandsMatch(char *a, char *b, const char *name)
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   730
{
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   731
	ParsedCommandStruct templ;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   732
	ParsedCommandStruct lang;
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6298
diff changeset
   733
	int i, j;
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   734
	bool result = true;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   735
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   736
	ExtractCommandString(&templ, b, true);
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   737
	ExtractCommandString(&lang, a, true);
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   738
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   739
	// For each string in templ, see if we find it in lang
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   740
	if (templ.np != lang.np) {
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   741
		warning("%s: template string and language string have a different # of commands", name);
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   742
		result = false;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   743
	}
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   744
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   745
	for (i = 0; i < templ.np; i++) {
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   746
		// see if we find it in lang, and zero it out
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   747
		bool found = false;
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   748
		for (j = 0; j < lang.np; j++) {
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   749
			if (templ.pairs[i].a == lang.pairs[j].a &&
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   750
					strcmp(templ.pairs[i].v, lang.pairs[j].v) == 0) {
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   751
				// it was found in both. zero it out from lang so we don't find it again
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   752
				lang.pairs[j].a = NULL;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   753
				found = true;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   754
				break;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   755
			}
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   756
		}
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   757
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   758
		if (!found) {
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   759
			warning("%s: command '%s' exists in template file but not in language file", name, templ.pairs[i].a->cmd);
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   760
			result = false;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   761
		}
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   762
	}
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   763
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   764
	// if we reach here, all non consumer commands match up.
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   765
	// Check if the non consumer commands match up also.
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   766
	for (i = 0; i < lengthof(templ.cmd); i++) {
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   767
		if (TranslateCmdForCompare(templ.cmd[i]) != TranslateCmdForCompare(lang.cmd[i])) {
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   768
			warning("%s: Param idx #%d '%s' doesn't match with template command '%s'", name, i,
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   769
				lang.cmd[i]  == NULL ? "<empty>" : lang.cmd[i]->cmd,
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   770
				templ.cmd[i] == NULL ? "<empty>" : templ.cmd[i]->cmd);
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   771
			result = false;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   772
		}
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   773
	}
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   774
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   775
	return result;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   776
}
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   777
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   778
static void HandleString(char *str, bool master)
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   779
{
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   780
	char *s,*t;
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   781
	LangString *ent;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   782
	char *casep;
222
b88456001397 (svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents: 181
diff changeset
   783
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   784
	if (*str == '#') {
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   785
		if (str[1] == '#' && str[2] != '#') HandlePragma(str + 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   787
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   788
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   789
	// Ignore comments & blank lines
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   790
	if (*str == ';' || *str == ' ' || *str == '\0') return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   791
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   792
	s = strchr(str, ':');
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   793
	if (s == NULL) {
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   794
		error("Line has no ':' delimiter");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   795
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   796
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   797
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   798
	// Trim spaces.
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   799
	// After this str points to the command name, and s points to the command contents
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   800
	for (t = s; t > str && (t[-1] == ' ' || t[-1] == '\t'); t--);
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   801
	*t = 0;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   802
	s++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   803
5111
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   804
	/* Check string is valid UTF-8 */
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   805
	{
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   806
		const char *tmp;
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   807
		for (tmp = s; *tmp != '\0';) {
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   808
			size_t len = Utf8Validate(tmp);
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   809
			if (len == 0) fatal("Invalid UTF-8 sequence in '%s'", s);
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   810
			tmp += len;
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   811
		}
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   812
	}
05bb05c1e9b5 (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   813
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   814
	// Check if the string has a case..
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   815
	// The syntax for cases is IDENTNAME.case
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   816
	casep = strchr(str, '.');
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   817
	if (casep) *casep++ = 0;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   818
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   819
	// Check if this string already exists..
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   820
	ent = HashFind(str);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   821
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   822
	if (master) {
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   823
		if (ent != NULL && casep == NULL) {
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   824
			error("String name '%s' is used multiple times", str);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   825
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   826
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   827
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   828
		if (ent == NULL && casep != NULL) {
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   829
			error("Base string name '%s' doesn't exist yet. Define it before defining a case.", str);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   830
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   831
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   833
		if (ent == NULL) {
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   834
			if (_strings[_next_string_id]) {
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   835
				error("String ID 0x%X for '%s' already in use by '%s'", ent, str, _strings[_next_string_id]->name);
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   836
				return;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   837
			}
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   838
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   839
			// Allocate a new LangString
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5838
diff changeset
   840
			ent = CallocT<LangString>(1);
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   841
			_strings[_next_string_id] = ent;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   842
			ent->index = _next_string_id++;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   843
			ent->name = strdup(str);
2566
da24c0f2d2d8 (svn r3103) - Fix: [ 1339000 ] Fix: strgen and plural forms fatal error for untranslated strings. (glx). Also output the correct lines for these warnings, for missing strings the lines correspond with the ones in english.txt
Darkvater
parents: 2482
diff changeset
   844
			ent->line = _cur_line;
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   845
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   846
			HashAdd(str, ent);
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   847
		}
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   848
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   849
		if (casep != NULL) {
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5838
diff changeset
   850
			Case* c = MallocT<Case>(1);
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   851
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   852
			c->caseidx = ResolveCaseName(casep, strlen(casep));
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   853
			c->string = strdup(s);
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   854
			c->next = ent->english_case;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   855
			ent->english_case = c;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   856
		} else {
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   857
			ent->english = strdup(s);
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   858
		}
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   859
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   860
	} else {
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   861
		if (ent == NULL) {
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   862
			warning("String name '%s' does not exist in master file", str);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   866
		if (ent->translated && casep == NULL) {
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   867
			error("String name '%s' is used multiple times", str);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   868
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   869
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   870
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   871
		if (s[0] == ':' && s[1] == '\0' && casep == NULL) {
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   872
			// Special syntax :: means we should just inherit the master string
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   873
			ent->translated = strdup(ent->english);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   874
		} else {
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   875
			// make sure that the commands match
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   876
			if (!CheckCommandsMatch(s, ent->english, str)) return;
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   877
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   878
			if (casep != NULL) {
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5838
diff changeset
   879
				Case* c = MallocT<Case>(1);
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   880
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   881
				c->caseidx = ResolveCaseName(casep, strlen(casep));
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   882
				c->string = strdup(s);
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   883
				c->next = ent->translated_case;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   884
				ent->translated_case = c;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   885
			} else {
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   886
				ent->translated = strdup(s);
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   887
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   888
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   889
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   890
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   891
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   892
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   893
static void rstrip(char *buf)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   894
{
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   895
	int i = strlen(buf);
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   896
	while (i > 0 && (buf[i - 1] == '\r' || buf[i - 1] == '\n' || buf[i - 1] == ' ')) i--;
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   897
	buf[i] = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   898
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   899
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   900
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   901
static void ParseFile(const char *file, bool english)
2059
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   902
{
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   903
	FILE *in;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   904
	char buf[2048];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   905
2459
4b65354b7586 (svn r2985) Print warnings and errors in the canonical file:line: form to make life for IDEs easier (ln-)
tron
parents: 2418
diff changeset
   906
	_file = file;
4b65354b7586 (svn r2985) Print warnings and errors in the canonical file:line: form to make life for IDEs easier (ln-)
tron
parents: 2418
diff changeset
   907
5976
2aabd1d72d31 (svn r8253) -Codechange: Be more strict about language generation and fail any languages not having the mandatory ##name, ##ownname and ##isocode pragma's.
Darkvater
parents: 5860
diff changeset
   908
	/* For each new file we parse, reset the genders, and language codes */
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   909
	_numgenders = 0;
5976
2aabd1d72d31 (svn r8253) -Codechange: Be more strict about language generation and fail any languages not having the mandatory ##name, ##ownname and ##isocode pragma's.
Darkvater
parents: 5860
diff changeset
   910
	_lang_name[0] = _lang_ownname[0] = _lang_isocode[0] = '\0';
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   911
	// TODO:!! We can't reset the cases. In case the translated strings
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   912
	// derive some strings from english....
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   913
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   914
	in = fopen(file, "r");
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   915
	if (in == NULL) fatal("Cannot open file");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   916
	_cur_line = 1;
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6298
diff changeset
   917
	while (fgets(buf, sizeof(buf), in) != NULL) {
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   918
		rstrip(buf);
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   919
		HandleString(buf, english);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   920
		_cur_line++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   921
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
	fclose(in);
5976
2aabd1d72d31 (svn r8253) -Codechange: Be more strict about language generation and fail any languages not having the mandatory ##name, ##ownname and ##isocode pragma's.
Darkvater
parents: 5860
diff changeset
   923
2aabd1d72d31 (svn r8253) -Codechange: Be more strict about language generation and fail any languages not having the mandatory ##name, ##ownname and ##isocode pragma's.
Darkvater
parents: 5860
diff changeset
   924
	if (StrEmpty(_lang_name) || StrEmpty(_lang_ownname) || StrEmpty(_lang_isocode)) {
2aabd1d72d31 (svn r8253) -Codechange: Be more strict about language generation and fail any languages not having the mandatory ##name, ##ownname and ##isocode pragma's.
Darkvater
parents: 5860
diff changeset
   925
		fatal("Language must include ##name, ##ownname and ##isocode");
2aabd1d72d31 (svn r8253) -Codechange: Be more strict about language generation and fail any languages not having the mandatory ##name, ##ownname and ##isocode pragma's.
Darkvater
parents: 5860
diff changeset
   926
	}
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   927
}
2059
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   928
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   929
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   930
static uint32 MyHashStr(uint32 hash, const char *s)
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   931
{
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   932
	for (; *s != '\0'; s++) {
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   933
		hash = ROL(hash, 3) ^ *s;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3900
diff changeset
   934
		hash = (hash & 1 ? hash >> 1 ^ 0xDEADBEEF : hash >> 1);
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   935
	}
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   936
	return hash;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   937
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   938
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   939
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   940
// make a hash of the file to get a unique "version number"
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6083
diff changeset
   941
static void MakeHashOfStrings()
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   942
{
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   943
	uint32 hash = 0;
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   944
	uint i;
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   945
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   946
	for (i = 0; i != lengthof(_strings); i++) {
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   947
		const LangString* ls = _strings[i];
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   948
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   949
		if (ls != NULL) {
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   950
			const CmdStruct* cs;
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   951
			const char* s;
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   952
			char buf[256];
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   953
			int argno;
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   954
			int casei;
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   955
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   956
			s = ls->name;
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   957
			hash ^= i * 0x717239;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3900
diff changeset
   958
			hash = (hash & 1 ? hash >> 1 ^ 0xDEADBEEF : hash >> 1);
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   959
			hash = MyHashStr(hash, s + 1);
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   960
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   961
			s = ls->english;
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   962
			while ((cs = ParseCommandString(&s, buf, &argno, &casei)) != NULL) {
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   963
				if (cs->flags & C_DONTCOUNT) continue;
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   964
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   965
				hash ^= (cs - _cmd_structs) * 0x1234567;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3900
diff changeset
   966
				hash = (hash & 1 ? hash >> 1 ^ 0xF00BAA4 : hash >> 1);
222
b88456001397 (svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents: 181
diff changeset
   967
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   968
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   969
	}
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   970
	_hash = hash;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   971
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   972
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   973
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   974
static uint CountInUse(uint grp)
2059
35037679fcfb (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   975
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   976
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   977
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   978
	for (i = 0x800; --i >= 0;) if (_strings[(grp << 11) + i] != NULL) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   979
	return i + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   981
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   982
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   983
bool CompareFiles(const char *n1, const char *n2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   984
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   985
	FILE *f1, *f2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   986
	char b1[4096];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   987
	char b2[4096];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   988
	size_t l1, l2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   989
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   990
	f2 = fopen(n2, "rb");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   991
	if (f2 == NULL) return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   992
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   993
	f1 = fopen(n1, "rb");
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
   994
	if (f1 == NULL) fatal("can't open %s", n1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   995
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   996
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   997
		l1 = fread(b1, 1, sizeof(b1), f1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   998
		l2 = fread(b2, 1, sizeof(b2), f2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   999
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1000
		if (l1 != l2 || memcmp(b1, b2, l1)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1001
			fclose(f2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1002
			fclose(f1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1003
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1004
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1005
	} while (l1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1006
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1007
	fclose(f2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1008
	fclose(f1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1009
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1010
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1011
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1012
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1013
static void WriteStringsH(const char *filename)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1014
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1015
	FILE *out;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1016
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1017
	int next = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1018
	int lastgrp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1019
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1020
	out = fopen("tmp.xxx", "w");
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
  1021
	if (out == NULL) fatal("can't open tmp.xxx");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1022
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1023
	fprintf(out, "enum StringIdEnum {");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1024
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1025
	lastgrp = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1026
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1027
	for (i = 0; i != lengthof(_strings); i++) {
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1028
		if (_strings[i] != NULL) {
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1029
			fprintf(out, next == i ? "\t%s,\n" : "\n\t%s = 0x%X,\n", _strings[i]->name, i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1030
			next = i + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1031
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1032
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1033
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1034
	fprintf(out, "};\n");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1035
222
b88456001397 (svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents: 181
diff changeset
  1036
	fprintf(out,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1037
		"\nenum {\n"
181
0b95567f2d0f (svn r182) -Fix: [1024380] strgen diff (Warning fix + MorphOS fix). Removes the longest standing warning on compilation of strgen (tokai)
darkvater
parents: 0
diff changeset
  1038
		"\tLANGUAGE_PACK_IDENT = 0x474E414C, // Big Endian value for 'LANG' (LE is 0x 4C 41 4E 47)\n"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1039
		"\tLANGUAGE_PACK_VERSION = 0x%X,\n"
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1040
		"};\n", (uint)_hash
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1041
	);
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1042
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1043
	fclose(out);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1044
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1045
	if (CompareFiles("tmp.xxx", filename)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1046
		// files are equal. tmp.xxx is not needed
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1047
		unlink("tmp.xxx");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1048
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1049
		// else rename tmp.xxx into filename
2482
dffcca243dbc (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2459
diff changeset
  1050
#if defined(WIN32) || defined(WIN64)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1051
		unlink(filename);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1052
#endif
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
  1053
		if (rename("tmp.xxx", filename) == -1) fatal("rename() failed");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1054
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1055
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1056
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1057
static int TranslateArgumentIdx(int argidx)
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1058
{
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1059
	int i, sum;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1060
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1061
	if (argidx < 0 || argidx >= lengthof(_cur_pcs.cmd))
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
  1062
		fatal("invalid argidx %d", argidx);
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1063
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
  1064
	for (i = sum = 0; i < argidx; i++) {
2374
74afdc193f78 (svn r2900) Fix a bug, which incremented the counter of a loop twice and therefore calculated wrong argument indices
tron
parents: 2353
diff changeset
  1065
		const CmdStruct *cs = _cur_pcs.cmd[i];
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1066
		sum += (cs != NULL) ? cs->consumes : 1;
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1067
	}
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1068
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1069
	return sum;
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1070
}
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1071
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6083
diff changeset
  1072
static void PutArgidxCommand()
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1073
{
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
  1074
	PutUtf8(SCC_ARG_INDEX);
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1075
	PutByte(TranslateArgumentIdx(_cur_argidx));
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1076
}
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1077
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1078
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1079
static void PutCommandString(const char *str)
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1080
{
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1081
	const CmdStruct *cs;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1082
	char param[256];
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1083
	int argno;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1084
	int casei;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1085
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1086
	_cur_argidx = 0;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1088
	while (*str != '\0') {
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1089
		// Process characters as they are until we encounter a {
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1090
		if (*str != '{') {
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1091
			PutByte(*str++);
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1092
			continue;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1093
		}
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1094
		cs = ParseCommandString(&str, param, &argno, &casei);
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1095
		if (cs == NULL) break;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1096
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1097
		if (casei != -1) {
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
  1098
			PutUtf8(SCC_SETCASE); // {SETCASE}
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1099
			PutByte(casei);
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1100
		}
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1101
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1102
		// For params that consume values, we need to handle the argindex properly
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1103
		if (cs->consumes > 0) {
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1104
			// Check if we need to output a move-param command
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1105
			if (argno != -1 && argno != _cur_argidx) {
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1106
				_cur_argidx = argno;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1107
				PutArgidxCommand();
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1108
			}
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1109
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1110
			// Output the one from the master string... it's always accurate.
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1111
			cs = _cur_pcs.cmd[_cur_argidx++];
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1112
			if (cs == NULL) {
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
  1113
				fatal("%s: No argument exists at position %d", _cur_ident, _cur_argidx - 1);
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1114
			}
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1115
		}
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1116
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1117
		cs->proc(param, cs->value);
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1118
	}
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1119
}
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1120
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1121
static void WriteLength(FILE *f, uint length)
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1122
{
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1123
	if (length < 0xC0) {
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1124
		fputc(length, f);
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1125
	} else if (length < 0x4000) {
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1126
		fputc((length >> 8) | 0xC0, f);
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1127
		fputc(length & 0xFF, f);
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1128
	} else {
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
  1129
		fatal("string too long");
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1130
	}
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1131
}
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1132
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1133
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1134
static void WriteLangfile(const char *filename, int show_todo)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1135
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1136
	FILE *f;
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1137
	uint in_use[32];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1138
	LanguagePackHeader hdr;
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1139
	uint i;
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1140
	uint j;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1141
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1142
	f = fopen(filename, "wb");
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
  1143
	if (f == NULL) fatal("can't open %s", filename);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1144
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1145
	memset(&hdr, 0, sizeof(hdr));
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
  1146
	for (i = 0; i != 32; i++) {
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1147
		uint n = CountInUse(i);
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1148
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
		in_use[i] = n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
		hdr.offsets[i] = TO_LE16(n);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1151
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1152
222
b88456001397 (svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents: 181
diff changeset
  1153
	// see line 655: fprintf(..."\tLANGUAGE_PACK_IDENT = 0x474E414C,...)
181
0b95567f2d0f (svn r182) -Fix: [1024380] strgen diff (Warning fix + MorphOS fix). Removes the longest standing warning on compilation of strgen (tokai)
darkvater
parents: 0
diff changeset
  1154
	hdr.ident = TO_LE32(0x474E414C); // Big Endian value for 'LANG'
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1155
	hdr.version = TO_LE32(_hash);
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1156
	hdr.plural_form = _lang_pluralform;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1157
	strcpy(hdr.name, _lang_name);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1158
	strcpy(hdr.own_name, _lang_ownname);
1376
425781645fba (svn r1880) [Codechange] Added isocodes to langfiles and support code to strgen (Lauri Nurmi)
miham
parents: 1097
diff changeset
  1159
	strcpy(hdr.isocode, _lang_isocode);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1160
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1161
	fwrite(&hdr, sizeof(hdr), 1, f);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1162
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
  1163
	for (i = 0; i != 32; i++) {
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
  1164
		for (j = 0; j != in_use[i]; j++) {
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1165
			const LangString* ls = _strings[(i << 11) + j];
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1166
			const Case* casep;
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1167
			const char* cmdp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1168
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1169
			// For undefined strings, just set that it's an empty string
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1170
			if (ls == NULL) {
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1171
				WriteLength(f, 0);
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1172
				continue;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1173
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1174
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1175
			_cur_ident = ls->name;
2566
da24c0f2d2d8 (svn r3103) - Fix: [ 1339000 ] Fix: strgen and plural forms fatal error for untranslated strings. (glx). Also output the correct lines for these warnings, for missing strings the lines correspond with the ones in english.txt
Darkvater
parents: 2482
diff changeset
  1176
			_cur_line = ls->line;
2082
52fa58482eeb (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1177
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1178
			// Produce a message if a string doesn't have a translation.
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1179
			if (show_todo > 0 && ls->translated == NULL) {
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1180
				if (show_todo == 2) {
4922
58a40fcc1b72 (svn r6898) -Fix: lowercase Error/Warning/Fatal for strgen and remove static on error() so strgen
Darkvater
parents: 4464
diff changeset
  1181
					warning("'%s' is untranslated", ls->name);
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1182
				} else {
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1183
					const char *s = "<TODO> ";
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1184
					while (*s != '\0') PutByte(*s++);
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1185
				}
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1186
			}
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1187
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1188
			// Extract the strings and stuff from the english command string
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1189
			ExtractCommandString(&_cur_pcs, ls->english, false);
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1190
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1191
			if (ls->translated_case != NULL || ls->translated != NULL) {
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1192
				casep = ls->translated_case;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1193
				cmdp = ls->translated;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1194
			} else {
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1195
				casep = ls->english_case;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1196
				cmdp = ls->english;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1197
			}
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1198
2586
c0ec490c5150 (svn r3123) eh, don't press enter after typing text, previous patch wasn't finished. Now strgen really behaves correctly. Thanks again glx
Darkvater
parents: 2585
diff changeset
  1199
			_translated = _masterlang || (cmdp != ls->english);
2585
b4b7a65ca209 (svn r3122) - Fix (regression): recent change to strgen which 'fixed' all strings with wrong plural forms. Thanks for glx for pointing this out (after I changed his original patch which was correct..whohoo braindeadness; here I come)
Darkvater
parents: 2566
diff changeset
  1200
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1201
			if (casep != NULL) {
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1202
				const Case* c;
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1203
				uint num;
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1204
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1205
				// Need to output a case-switch.
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1206
				// It has this format
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1207
				// <0x9E> <NUM CASES> <CASE1> <LEN1> <STRING1> <CASE2> <LEN2> <STRING2> <CASE3> <LEN3> <STRING3> <STRINGDEFAULT>
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1208
				// Each LEN is printed using 2 bytes in big endian order.
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4922
diff changeset
  1209
				PutUtf8(SCC_SWITCH_CASE);
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1210
				// Count the number of cases
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
  1211
				for (num = 0, c = casep; c; c = c->next) num++;
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1212
				PutByte(num);
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1213
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1214
				// Write each case
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1215
				for (c = casep; c != NULL; c = c->next) {
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1216
					int pos;
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1217
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1218
					PutByte(c->caseidx);
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1219
					// Make some space for the 16-bit length
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1220
					pos = _put_pos;
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1221
					PutByte(0);
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1222
					PutByte(0);
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1223
					// Write string
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1224
					PutCommandString(c->string);
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1225
					PutByte(0); // terminate with a zero
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1226
					// Fill in the length
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1227
					_put_buf[pos + 0] = GB(_put_pos - (pos + 2), 8, 8);
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1228
					_put_buf[pos + 1] = GB(_put_pos - (pos + 2), 0, 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1229
				}
2087
bedb167de57b (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1230
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1231
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1232
			if (cmdp != NULL) PutCommandString(cmdp);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1233
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1234
			WriteLength(f, _put_pos);
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1235
			fwrite(_put_buf, 1, _put_pos, f);
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1236
			_put_pos = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1237
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1238
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1239
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1240
	fputc(0, f);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1241
	fclose(f);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1242
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1243
4370
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1244
/** Multi-OS mkdirectory function */
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1245
static inline void ottd_mkdir(const char *directory)
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1246
{
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1247
#if defined(WIN32) || defined(__WATCOMC__)
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1248
		mkdir(directory);
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1249
#else
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1250
		mkdir(directory, 0755);
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1251
#endif
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1252
}
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1253
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1254
/** Create a path consisting of an already existing path, a possible
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1255
 * path seperator and the filename. The seperator is only appended if the path
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1256
 * does not already end with a seperator */
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1257
static inline char *mkpath(char *buf, size_t buflen, const char *path, const char *file)
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1258
{
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1259
	char *p;
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1260
	ttd_strlcpy(buf, path, buflen); // copy directory into buffer
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1261
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1262
	p = strchr(buf, '\0'); // add path seperator if necessary
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1263
	if (p[-1] != PATHSEPCHAR && (size_t)(p - buf) + 1 < buflen) *p++ = PATHSEPCHAR;
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1264
	ttd_strlcpy(p, file, buflen - (size_t)(p - buf)); // catenate filename at end of buffer
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1265
	return buf;
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1266
}
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1267
5754
5ecc9be438f0 (svn r7796) -Fix (r7759): cygwin does not need to rewrite the paths for strgen.
rubidium
parents: 5726
diff changeset
  1268
#if defined(__MINGW32__)
4379
2866185c1377 (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1269
/**
2866185c1377 (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1270
 * On MingW, it is common that both / as \ are accepted in the
2866185c1377 (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1271
 * params. To go with those flow, we rewrite all incoming /
2866185c1377 (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1272
 * simply to \, so internally we can safely assume \.
2866185c1377 (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1273
 */
2866185c1377 (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1274
static inline char *replace_pathsep(char *s)
2866185c1377 (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1275
{
2866185c1377 (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1276
	char *c;
2866185c1377 (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1277
2866185c1377 (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1278
	for (c = s; *c != '\0'; c++) if (*c == '/') *c = '\\';
2866185c1377 (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1279
	return s;
2866185c1377 (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1280
}
2866185c1377 (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1281
#else
2866185c1377 (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1282
static inline char *replace_pathsep(char *s) { return s; }
2866185c1377 (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1283
#endif
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1284
250
733e18ca6e93 (svn r251) -Project ready for 0.3.4 release. Updated installer, readme and fileinformation
darkvater
parents: 236
diff changeset
  1285
int CDECL main(int argc, char* argv[])
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1286
{
4370
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1287
	char pathbuf[256];
4461
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1288
	const char *src_dir = ".";
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1289
	const char *dest_dir = NULL;
4370
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1290
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1291
	int show_todo = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1292
4461
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1293
	while (argc > 1 && *argv[1] == '-') {
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1294
		if (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0) {
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1295
			puts("$Revision$");
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1296
			return 0;
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1297
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1298
4461
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1299
		if (strcmp(argv[1], "-t") == 0 || strcmp(argv[1], "--todo") == 0) {
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1300
			show_todo = 1;
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1301
			argc--, argv++;
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1302
			continue;
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1303
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1304
4461
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1305
		if (strcmp(argv[1], "-w") == 0 || strcmp(argv[1], "--warning") == 0) {
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1306
			show_todo = 2;
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1307
			argc--, argv++;
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1308
			continue;
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1309
		}
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1310
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1311
		if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0) {
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1312
			puts(
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1313
				"strgen - $Revision$\n"
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1314
				" -v | --version    print version information and exit\n"
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1315
				" -t | --todo       replace any untranslated strings with '<TODO>'\n"
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1316
				" -w | --warning    print a warning for any untranslated strings\n"
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1317
				" -h | -? | --help  print this help message and exit\n"
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1318
				" -s | --source_dir search for english.txt in the specified directory\n"
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1319
				" -d | --dest_dir   put output file in the specified directory, create if needed\n"
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1320
				" Run without parameters and strgen will search for english.txt and parse it,\n"
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1321
				" creating strings.h. Passing an argument, strgen will translate that language\n"
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1322
				" file using english.txt as a reference and output <language>.lng."
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1323
			);
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1324
			return 0;
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1325
		}
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1326
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1327
		if (argc > 2 && (strcmp(argv[1], "-s") == 0 || strcmp(argv[1], "--source_dir") == 0)) {
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1328
			src_dir = replace_pathsep(argv[2]);
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1329
			argc -= 2, argv += 2;
4464
281a2984a0c9 (svn r6247) -Fix(r6244): invalid arguments caused infinite loop
glx
parents: 4461
diff changeset
  1330
			continue;
4461
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1331
		}
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1332
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1333
		if (argc > 2 && (strcmp(argv[1], "-d") == 0 || strcmp(argv[1], "--dest_dir") == 0)) {
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1334
			dest_dir = replace_pathsep(argv[2]);
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1335
			argc -= 2, argv += 2;
4464
281a2984a0c9 (svn r6247) -Fix(r6244): invalid arguments caused infinite loop
glx
parents: 4461
diff changeset
  1336
			continue;
4461
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1337
		}
4464
281a2984a0c9 (svn r6247) -Fix(r6244): invalid arguments caused infinite loop
glx
parents: 4461
diff changeset
  1338
281a2984a0c9 (svn r6247) -Fix(r6244): invalid arguments caused infinite loop
glx
parents: 4461
diff changeset
  1339
		fprintf(stderr, "Invalid arguments\n");
281a2984a0c9 (svn r6247) -Fix(r6244): invalid arguments caused infinite loop
glx
parents: 4461
diff changeset
  1340
		return 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1341
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1342
4461
e46bbe947a06 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1343
	if (dest_dir == NULL) dest_dir = src_dir; // if dest_dir is not specified, it equals src_dir
4370
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1344
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1345
	/* strgen has two modes of operation. If no (free) arguments are passed
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1346
	 * strgen generates strings.h to the destination directory. If it is supplied
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1347
	 * with a (free) parameter the program will translate that language to destination
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1348
	 * directory. As input english.txt is parsed from the source directory */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1349
	if (argc == 1) {
4370
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1350
		mkpath(pathbuf, lengthof(pathbuf), src_dir, "english.txt");
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1351
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1352
		/* parse master file */
2586
c0ec490c5150 (svn r3123) eh, don't press enter after typing text, previous patch wasn't finished. Now strgen really behaves correctly. Thanks again glx
Darkvater
parents: 2585
diff changeset
  1353
		_masterlang = true;
4370
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1354
		ParseFile(pathbuf, true);
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1355
		MakeHashOfStrings();
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1356
		if (_errors) return 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1357
4370
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1358
		/* write strings.h */
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1359
		ottd_mkdir(dest_dir);
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1360
		mkpath(pathbuf, lengthof(pathbuf), dest_dir, "strings.h");
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1361
		WriteStringsH(pathbuf);
3015
76371a33e6c4 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1362
	} else if (argc == 2) {
4370
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1363
		char *r;
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1364
4370
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1365
		mkpath(pathbuf, lengthof(pathbuf), src_dir, "english.txt");
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1366
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1367
		/* parse master file and check if target file is correct */
2586
c0ec490c5150 (svn r3123) eh, don't press enter after typing text, previous patch wasn't finished. Now strgen really behaves correctly. Thanks again glx
Darkvater
parents: 2585
diff changeset
  1368
		_masterlang = false;
4370
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1369
		ParseFile(pathbuf, true);
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1370
		MakeHashOfStrings();
4379
2866185c1377 (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1371
		ParseFile(replace_pathsep(argv[1]), false); // target file
2063
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1372
		if (_errors) return 1;
95259a31ceb5 (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1373
4370
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1374
		/* get the targetfile, strip any directories and append to destination path */
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1375
		r = strrchr(argv[1], PATHSEPCHAR);
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1376
		mkpath(pathbuf, lengthof(pathbuf), dest_dir, (r != NULL) ? &r[1] : argv[1]);
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1377
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1378
		/* rename the .txt (input-extension) to .lng */
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1379
		r = strrchr(pathbuf, '.');
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1380
		if (r == NULL || strcmp(r, ".txt") != 0) r = strchr(pathbuf, '\0');
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1381
		ttd_strlcpy(r, ".lng", (size_t)(r - pathbuf));
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1382
		WriteLangfile(pathbuf, show_todo);
5548
209971b79b9a (svn r7540) -Codechange: Print a summary of the number of errors/warnings of a language when strgen is run with the -w flag.
Darkvater
parents: 5111
diff changeset
  1383
209971b79b9a (svn r7540) -Codechange: Print a summary of the number of errors/warnings of a language when strgen is run with the -w flag.
Darkvater
parents: 5111
diff changeset
  1384
		/* if showing warnings, print a summary of the language */
209971b79b9a (svn r7540) -Codechange: Print a summary of the number of errors/warnings of a language when strgen is run with the -w flag.
Darkvater
parents: 5111
diff changeset
  1385
		if (show_todo == 2) {
5693
2112a00325ed (svn r7693) -Codechange (r7540): print a newline after the summary (strgen).
Darkvater
parents: 5548
diff changeset
  1386
			fprintf(stdout, "%d warnings and %d errors for %s\n", _warnings, _errors, pathbuf);
5548
209971b79b9a (svn r7540) -Codechange: Print a summary of the number of errors/warnings of a language when strgen is run with the -w flag.
Darkvater
parents: 5111
diff changeset
  1387
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1388
	} else {
4370
c7bd128b1670 (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1389
		fprintf(stderr, "Invalid arguments\n");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1390
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1391
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1392
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1393
}