src/strgen/strgen.cpp
author frosch
Sat, 29 Nov 2008 21:27:15 +0000
changeset 10392 306d24c840f4
parent 10367 0098392a5560
permissions -rw-r--r--
(svn r14643) -Fix: Invalidate autoreplace window when toggling 'replace protection'.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2107
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2107
diff changeset
     2
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 8983
diff changeset
     3
/** @file strgen.cpp Tool to create computer readable (stand-alone) translation files. */
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 8983
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "../stdafx.h"
8130
d2eb7d04f6e1 (svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents: 8114
diff changeset
     6
#include "../core/alloc_func.hpp"
8135
2373c1e0e9bc (svn r11697) -Fix [FS#1585]: strgen did not (always) compile properly.
rubidium
parents: 8130
diff changeset
     7
#include "../core/endian_func.hpp"
8214
971f861d5543 (svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents: 8135
diff changeset
     8
#include "../string_func.h"
10249
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
     9
#include "../strings_type.h"
10366
74b3472edfa4 (svn r14617) -Change: unduplicate the languagepack(header).
rubidium
parents: 10310
diff changeset
    10
#include "strgen.h"
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8214
diff changeset
    11
#include "../table/control_codes.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8214
diff changeset
    12
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include <stdio.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include <string.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include <stdlib.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include <stdarg.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
2482
374f6395847d (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2459
diff changeset
    18
#if (!defined(WIN32) && !defined(WIN64)) || defined(__CYGWIN__)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
#include <unistd.h>
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
    20
#include <sys/types.h>
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
    21
#include <sys/stat.h>
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
    24
#if defined WIN32 || defined __WATCOMC__
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
    25
#include <direct.h>
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
    26
#endif /* WIN32 || __WATCOMC__ */
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
    27
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
    28
#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
    29
#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
    30
#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
    31
#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
    32
#define stderr stdout
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
    33
#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
    34
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
/* 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
    36
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
typedef void (*ParseCmdProc)(char *buf, int value);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    39
struct CmdStruct {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
	const char *cmd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
	ParseCmdProc proc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
	long value;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
    43
	int8 consumes;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    44
	byte flags;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    45
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    47
enum {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    48
	C_DONTCOUNT = 1,
4344
7e123fec5b0b (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
    49
	C_CASE      = 2,
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    50
};
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    51
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    52
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    53
struct Case {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    54
	int caseidx;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    55
	char *string;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    56
	Case *next;
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    57
};
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    58
2586
1c0f0b67a70d (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
    59
static bool _masterlang;
2585
fa2f94aa9de2 (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
    60
static bool _translated;
2459
a2f63b331830 (svn r2985) Print warnings and errors in the canonical file:line: form to make life for IDEs easier (ln-)
tron
parents: 2418
diff changeset
    61
static const char* _file = "(unknown file)";
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
    62
static int _cur_line;
7110
bda0a45e30e5 (svn r10382) -Fix (strgen): it was not possible to use --warning and --todo at the same time.
rubidium
parents: 7059
diff changeset
    63
static int _errors, _warnings, _show_todo;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
    64
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    65
struct LangString {
4344
7e123fec5b0b (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
    66
	char *name;            // Name of the string
7e123fec5b0b (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
    67
	char *english;         // English text
7e123fec5b0b (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
    68
	char *translated;      // Translated text
7e123fec5b0b (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
    69
	uint16 hash_next;      // next hash entry
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    70
	uint16 index;
4344
7e123fec5b0b (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
    71
	int line;              // line of string in source-file
7e123fec5b0b (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
	Case *english_case;    // cases for english
7e123fec5b0b (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
	Case *translated_case; // cases for foreign
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    74
};
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    75
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    76
static LangString *_strings[65536];
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    77
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
    78
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
    79
#define HASH_SIZE 32767
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
    80
static uint16 _hash_head[HASH_SIZE];
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
    81
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
    82
static byte _put_buf[4096];
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
    83
static int _put_pos;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
    84
static int _next_string_id;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
    86
static uint32 _hash;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
    87
static char _lang_name[32], _lang_ownname[32], _lang_isocode[16];
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
    88
static byte _lang_pluralform;
10249
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
    89
static byte _lang_textdir;
10367
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
    90
static uint16 _lang_winlangid;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    91
#define MAX_NUM_GENDER 8
10309
a3519caf1001 (svn r14554) -Fix: languages using longer gender names than strgen supports.
rubidium
parents: 10249
diff changeset
    92
static char _genders[MAX_NUM_GENDER][16];
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    93
static int _numgenders;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    95
// contains the name of all cases.
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    96
#define MAX_NUM_CASES 50
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    97
static char _cases[MAX_NUM_CASES][16];
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
    98
static int _numcases;
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
    99
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   100
// for each plural value, this is the number of plural forms.
8733
e60ce9c3ae47 (svn r12417) -Fix: Add a new plural rule for Icelandic.
maedhros
parents: 8264
diff changeset
   101
static const byte _plural_form_counts[] = { 2, 1, 2, 3, 3, 3, 3, 3, 4, 2 };
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   102
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   103
static const char *_cur_ident;
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   104
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   105
struct CmdPair {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   106
	const CmdStruct *a;
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   107
	const char *v;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   108
};
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   109
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   110
struct ParsedCommandStruct {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   111
	int np;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   112
	CmdPair pairs[32];
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   113
	const CmdStruct *cmd[32]; // ordered by param #
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   114
};
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   115
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   116
// Used when generating some advanced commands.
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   117
static ParsedCommandStruct _cur_pcs;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   118
static int _cur_argidx;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   119
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   120
static uint HashStr(const char *s)
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   121
{
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   122
	uint hash = 0;
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   123
	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
   124
	return hash % HASH_SIZE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
}
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   126
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   127
static void HashAdd(const char *s, LangString *ls)
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   128
{
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   129
	uint hash = HashStr(s);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   130
	ls->hash_next = _hash_head[hash];
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   131
	_hash_head[hash] = ls->index + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   134
static LangString *HashFind(const char *s)
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   135
{
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   136
	int idx = _hash_head[HashStr(s)];
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   137
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   138
	while (--idx >= 0) {
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   139
		LangString* ls = _strings[idx];
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   140
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   141
		if (strcmp(ls->name, s) == 0) return ls;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   142
		idx = ls->hash_next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
	}
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   144
	return NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3718
diff changeset
   147
#ifdef _MSC_VER
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3718
diff changeset
   148
# define LINE_NUM_FMT "(%d)"
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3718
diff changeset
   149
#else
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3718
diff changeset
   150
# define LINE_NUM_FMT ":%d"
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3718
diff changeset
   151
#endif
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   152
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   153
static void CDECL strgen_warning(const char *s, ...)
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   154
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
	char buf[1024];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
	va_list va;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
	va_start(va, s);
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
   158
	vsnprintf(buf, lengthof(buf), s, va);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
	va_end(va);
4447
486395ec1e06 (svn r6225) -Codechange: change the warning/error format of strgen to show up
Darkvater
parents: 4434
diff changeset
   160
	fprintf(stderr, "%s" LINE_NUM_FMT ": warning: %s\n", _file, _cur_line, buf);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   161
	_warnings++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   164
static void CDECL strgen_error(const char *s, ...)
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   165
{
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   166
	char buf[1024];
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   167
	va_list va;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   168
	va_start(va, s);
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
   169
	vsnprintf(buf, lengthof(buf), s, va);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   170
	va_end(va);
4447
486395ec1e06 (svn r6225) -Codechange: change the warning/error format of strgen to show up
Darkvater
parents: 4434
diff changeset
   171
	fprintf(stderr, "%s" LINE_NUM_FMT ": error: %s\n", _file, _cur_line, buf);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   172
	_errors++;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   173
}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   174
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   175
void NORETURN CDECL error(const char *s, ...)
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   176
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
	char buf[1024];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
	va_list va;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
	va_start(va, s);
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
   180
	vsnprintf(buf, lengthof(buf), s, va);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
	va_end(va);
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3718
diff changeset
   182
	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
   183
	exit(1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   186
static void PutByte(byte c)
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   187
{
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   188
	if (_put_pos == lengthof(_put_buf)) error("Put buffer too small");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
	_put_buf[_put_pos++] = c;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
5108
aeaef6fe53b7 (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
   193
static void PutUtf8(uint32 value)
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   194
{
5108
aeaef6fe53b7 (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
   195
	if (value < 0x80) {
aeaef6fe53b7 (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
   196
		PutByte(value);
aeaef6fe53b7 (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
   197
	} else if (value < 0x800) {
aeaef6fe53b7 (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
		PutByte(0xC0 + GB(value,  6, 5));
aeaef6fe53b7 (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
   199
		PutByte(0x80 + GB(value,  0, 6));
aeaef6fe53b7 (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
	} else if (value < 0x10000) {
aeaef6fe53b7 (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(0xE0 + GB(value, 12, 4));
aeaef6fe53b7 (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
		PutByte(0x80 + GB(value,  6, 6));
aeaef6fe53b7 (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(0x80 + GB(value,  0, 6));
aeaef6fe53b7 (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
	} else if (value < 0x110000) {
aeaef6fe53b7 (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
		PutByte(0xF0 + GB(value, 18, 3));
aeaef6fe53b7 (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(0x80 + GB(value, 12, 6));
aeaef6fe53b7 (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));
aeaef6fe53b7 (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));
aeaef6fe53b7 (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 {
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   210
		strgen_warning("Invalid unicode value U+0x%X", value);
5108
aeaef6fe53b7 (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
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
5111
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   215
size_t Utf8Validate(const char *s)
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   216
{
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   217
	uint32 c;
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   218
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7755
diff changeset
   219
	if (!HasBit(s[0], 7)) {
5111
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   220
		/* 1 byte */
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   221
		return 1;
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   222
	} else if (GB(s[0], 5, 3) == 6 && IsUtf8Part(s[1])) {
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   223
		/* 2 bytes */
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   224
		c = GB(s[0], 0, 5) << 6 | GB(s[1], 0, 6);
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   225
		if (c >= 0x80) return 2;
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   226
	} else if (GB(s[0], 4, 4) == 14 && IsUtf8Part(s[1]) && IsUtf8Part(s[2])) {
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   227
		/* 3 bytes */
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   228
		c = GB(s[0], 0, 4) << 12 | GB(s[1], 0, 6) << 6 | GB(s[2], 0, 6);
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   229
		if (c >= 0x800) return 3;
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   230
	} else if (GB(s[0], 3, 5) == 30 && IsUtf8Part(s[1]) && IsUtf8Part(s[2]) && IsUtf8Part(s[3])) {
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   231
		/* 4 bytes */
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   232
		c = GB(s[0], 0, 3) << 18 | GB(s[1], 0, 6) << 12 | GB(s[2], 0, 6) << 6 | GB(s[3], 0, 6);
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   233
		if (c >= 0x10000 && c <= 0x10FFFF) return 4;
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   234
	}
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   235
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   236
	return 0;
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   237
}
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   238
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   239
5108
aeaef6fe53b7 (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
   240
static void EmitSingleChar(char *buf, int value)
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   241
{
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   242
	if (*buf != '\0') strgen_warning("Ignoring trailing letters in command");
5108
aeaef6fe53b7 (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
   243
	PutUtf8(value);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   244
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
5108
aeaef6fe53b7 (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
   246
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   247
static void EmitSetX(char *buf, int value)
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   248
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
	char *err;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
	int x = strtol(buf, &err, 0);
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   251
	if (*err != 0) error("SetX param invalid");
5108
aeaef6fe53b7 (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
   252
	PutUtf8(SCC_SETX);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   253
	PutByte((byte)x);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   254
}
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   255
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   257
static void EmitSetXY(char *buf, int value)
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   258
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
	char *err;
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   260
	int x;
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   261
	int y;
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   262
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   263
	x = strtol(buf, &err, 0);
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   264
	if (*err != ' ') error("SetXY param invalid");
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   265
	y = strtol(err + 1, &err, 0);
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   266
	if (*err != 0) error("SetXY param invalid");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
5108
aeaef6fe53b7 (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
   268
	PutUtf8(SCC_SETXY);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   269
	PutByte((byte)x);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   270
	PutByte((byte)y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   273
// The plural specifier looks like
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   274
// {NUM} {PLURAL -1 passenger passengers} then it picks either passenger/passengers depending on the count in NUM
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   275
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   276
// This is encoded like
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   277
//  CommandByte <ARG#> <NUM> {Length of each string} {each string}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   278
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   279
bool ParseRelNum(char **buf, int *value)
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   280
{
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   281
	const char* s = *buf;
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   282
	char* end;
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   283
	bool rel = false;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   284
	int v;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   285
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   286
	while (*s == ' ' || *s == '\t') s++;
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   287
	if (*s == '+') {
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   288
		rel = true;
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   289
		s++;
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   290
	}
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   291
	v = strtol(s, &end, 0);
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   292
	if (end == s) return false;
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   293
	if (rel || v < 0) {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   294
		*value += v;
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   295
	} else {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   296
		*value = v;
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   297
	}
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   298
	*buf = end;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   299
	return true;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   300
}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   301
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   302
// Parse out the next word, or NULL
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   303
char *ParseWord(char **buf)
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   304
{
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   305
	char *s = *buf, *r;
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   306
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   307
	while (*s == ' ' || *s == '\t') s++;
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   308
	if (*s == '\0') return NULL;
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   309
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   310
	if (*s == '"') {
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   311
		r = ++s;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   312
		// parse until next " or NUL
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   313
		for (;;) {
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   314
			if (*s == '\0') break;
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   315
			if (*s == '"') {
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   316
				*s++ = '\0';
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   317
				break;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   318
			}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   319
			s++;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   320
		}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   321
	} else {
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   322
		// proceed until whitespace or NUL
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   323
		r = s;
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   324
		for (;;) {
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   325
			if (*s == '\0') break;
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   326
			if (*s == ' ' || *s == '\t') {
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   327
				*s++ = '\0';
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   328
				break;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   329
			}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   330
			s++;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   331
		}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   332
	}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   333
	*buf = s;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   334
	return r;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   335
}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   336
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   337
// Forward declaration
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   338
static int TranslateArgumentIdx(int arg);
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   339
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   340
static void EmitWordList(const char* const* words, uint nw)
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   341
{
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   342
	uint i;
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   343
	uint j;
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   344
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   345
	PutByte(nw);
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   346
	for (i = 0; i < nw; i++) PutByte(strlen(words[i]));
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   347
	for (i = 0; i < nw; i++) {
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   348
		for (j = 0; words[i][j] != '\0'; j++) PutByte(words[i][j]);
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   349
	}
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   350
}
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   351
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   352
static void EmitPlural(char *buf, int value)
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   353
{
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   354
	int argidx = _cur_argidx;
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   355
	const char* words[5];
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   356
	int nw = 0;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   357
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   358
	// Parse out the number, if one exists. Otherwise default to prev arg.
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   359
	if (!ParseRelNum(&buf, &argidx)) argidx--;
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   360
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   361
	// Parse each string
2566
75ae28a03460 (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
   362
	for (nw = 0; nw < 5; nw++) {
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   363
		words[nw] = ParseWord(&buf);
3015
f91a1b8fba79 (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 (words[nw] == NULL) break;
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   365
	}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   366
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   367
	if (nw == 0)
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   368
		error("%s: No plural words", _cur_ident);
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   369
2765
8fa792b6e525 (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
   370
	if (_plural_form_counts[_lang_pluralform] != nw) {
2585
fa2f94aa9de2 (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
   371
		if (_translated) {
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   372
			error("%s: Invalid number of plural forms. Expecting %d, found %d.", _cur_ident,
2566
75ae28a03460 (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
   373
				_plural_form_counts[_lang_pluralform], nw);
75ae28a03460 (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
   374
		} else {
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   375
			if ((_show_todo & 2) != 0) strgen_warning("'%s' is untranslated. Tweaking english string to allow compilation for plural forms", _cur_ident);
2566
75ae28a03460 (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
   376
			if (nw > _plural_form_counts[_lang_pluralform]) {
75ae28a03460 (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
   377
				nw = _plural_form_counts[_lang_pluralform];
75ae28a03460 (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
			} else {
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   379
				for (; nw < _plural_form_counts[_lang_pluralform]; nw++) {
2566
75ae28a03460 (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
   380
					words[nw] = words[nw - 1];
75ae28a03460 (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
				}
75ae28a03460 (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
			}
75ae28a03460 (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
		}
2765
8fa792b6e525 (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
   384
	}
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   385
5108
aeaef6fe53b7 (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
   386
	PutUtf8(SCC_PLURAL_LIST);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   387
	PutByte(TranslateArgumentIdx(argidx));
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   388
	EmitWordList(words, nw);
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   389
}
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   390
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   391
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   392
static void EmitGender(char *buf, int value)
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   393
{
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   394
	int argidx = _cur_argidx;
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   395
	uint nw;
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   396
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   397
	if (buf[0] == '=') {
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   398
		buf++;
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   399
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   400
		// This is a {G=DER} command
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   401
		for (nw = 0; ; nw++) {
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   402
			if (nw >= 8) error("G argument '%s' invalid", buf);
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   403
			if (strcmp(buf, _genders[nw]) == 0) break;
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   404
		}
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   405
		// now nw contains the gender index
5108
aeaef6fe53b7 (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
   406
		PutUtf8(SCC_GENDER_INDEX);
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   407
		PutByte(nw);
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   408
	} else {
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   409
		const char* words[8];
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   410
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   411
		// This is a {G 0 foo bar two} command.
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   412
		// If no relative number exists, default to +0
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   413
		if (!ParseRelNum(&buf, &argidx)) {}
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   414
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   415
		for (nw = 0; nw < 8; nw++) {
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   416
			words[nw] = ParseWord(&buf);
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   417
			if (words[nw] == NULL) break;
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   418
		}
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   419
		if (nw != _numgenders) error("Bad # of arguments for gender command");
5108
aeaef6fe53b7 (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
   420
		PutUtf8(SCC_GENDER_LIST);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   421
		PutByte(TranslateArgumentIdx(argidx));
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   422
		EmitWordList(words, nw);
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   423
	}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   424
}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   425
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   426
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
static const CmdStruct _cmd_structs[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
	// Update position
5108
aeaef6fe53b7 (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
   429
	{"SETX",  EmitSetX,  SCC_SETX,  0, 0},
aeaef6fe53b7 (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
   430
	{"SETXY", EmitSetXY, SCC_SETXY, 0, 0},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   432
	// Font size
5108
aeaef6fe53b7 (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
   433
	{"TINYFONT", EmitSingleChar, SCC_TINYFONT, 0, 0},
aeaef6fe53b7 (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
	{"BIGFONT",  EmitSingleChar, SCC_BIGFONT,  0, 0},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
	// Colors
5108
aeaef6fe53b7 (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
   437
	{"BLUE",    EmitSingleChar, SCC_BLUE,    0, 0},
aeaef6fe53b7 (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
	{"SILVER",  EmitSingleChar, SCC_SILVER,  0, 0},
aeaef6fe53b7 (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
	{"GOLD",    EmitSingleChar, SCC_GOLD,    0, 0},
aeaef6fe53b7 (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
   440
	{"RED",     EmitSingleChar, SCC_RED,     0, 0},
aeaef6fe53b7 (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
   441
	{"PURPLE",  EmitSingleChar, SCC_PURPLE,  0, 0},
aeaef6fe53b7 (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
	{"LTBROWN", EmitSingleChar, SCC_LTBROWN, 0, 0},
aeaef6fe53b7 (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
	{"ORANGE",  EmitSingleChar, SCC_ORANGE,  0, 0},
aeaef6fe53b7 (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
	{"GREEN",   EmitSingleChar, SCC_GREEN,   0, 0},
aeaef6fe53b7 (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
	{"YELLOW",  EmitSingleChar, SCC_YELLOW,  0, 0},
aeaef6fe53b7 (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
	{"DKGREEN", EmitSingleChar, SCC_DKGREEN, 0, 0},
aeaef6fe53b7 (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
	{"CREAM",   EmitSingleChar, SCC_CREAM,   0, 0},
aeaef6fe53b7 (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
	{"BROWN",   EmitSingleChar, SCC_BROWN,   0, 0},
aeaef6fe53b7 (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
	{"WHITE",   EmitSingleChar, SCC_WHITE,   0, 0},
aeaef6fe53b7 (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
	{"LTBLUE",  EmitSingleChar, SCC_LTBLUE,  0, 0},
aeaef6fe53b7 (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
	{"GRAY",    EmitSingleChar, SCC_GRAY,    0, 0},
aeaef6fe53b7 (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
	{"DKBLUE",  EmitSingleChar, SCC_DKBLUE,  0, 0},
aeaef6fe53b7 (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
	{"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
   454
7005
7273ae18a911 (svn r10261) -Cleanup: we do not need CURRENCY64 and CURRCOMPACT64 anymore, because everything is already 64 bits by default.
rubidium
parents: 6643
diff changeset
   455
	{"CURRCOMPACT",   EmitSingleChar, SCC_CURRENCY_COMPACT,    1, 0}, // compact currency
5108
aeaef6fe53b7 (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
	{"REV",           EmitSingleChar, SCC_REVISION,            0, 0}, // openttd revision string
aeaef6fe53b7 (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
	{"SHORTCARGO",    EmitSingleChar, SCC_CARGO_SHORT,         2, 0}, // short cargo description, only ### tons, or ### litres
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
9956
094d932dec8a (svn r14111) -Fix (r2572): [strgen] Changing order of parameters {X:...} did not work for strings including some {StringY}.
frosch
parents: 9648
diff changeset
   459
	{"STRING1", EmitSingleChar, SCC_STRING1, 2, C_CASE}, // included string that consumes the string id and ONE argument
094d932dec8a (svn r14111) -Fix (r2572): [strgen] Changing order of parameters {X:...} did not work for strings including some {StringY}.
frosch
parents: 9648
diff changeset
   460
	{"STRING2", EmitSingleChar, SCC_STRING2, 3, C_CASE}, // included string that consumes the string id and TWO arguments
094d932dec8a (svn r14111) -Fix (r2572): [strgen] Changing order of parameters {X:...} did not work for strings including some {StringY}.
frosch
parents: 9648
diff changeset
   461
	{"STRING3", EmitSingleChar, SCC_STRING3, 4, C_CASE}, // included string that consumes the string id and THREE arguments
094d932dec8a (svn r14111) -Fix (r2572): [strgen] Changing order of parameters {X:...} did not work for strings including some {StringY}.
frosch
parents: 9648
diff changeset
   462
	{"STRING4", EmitSingleChar, SCC_STRING4, 5, C_CASE}, // included string that consumes the string id and FOUR arguments
094d932dec8a (svn r14111) -Fix (r2572): [strgen] Changing order of parameters {X:...} did not work for strings including some {StringY}.
frosch
parents: 9648
diff changeset
   463
	{"STRING5", EmitSingleChar, SCC_STRING5, 6, C_CASE}, // included string that consumes the string id and FIVE arguments
5108
aeaef6fe53b7 (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
   464
aeaef6fe53b7 (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
   465
	{"STATIONFEATURES", EmitSingleChar, SCC_STATION_FEATURES, 1, 0}, // station features string, icons of the features
aeaef6fe53b7 (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
   466
	{"INDUSTRY",        EmitSingleChar, SCC_INDUSTRY_NAME,    1, 0}, // industry, takes an industry #
aeaef6fe53b7 (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
	{"CARGO",           EmitSingleChar, SCC_CARGO,            2, 0},
aeaef6fe53b7 (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
	{"POWER",           EmitSingleChar, SCC_POWER,            1, 0},
aeaef6fe53b7 (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
	{"VOLUME",          EmitSingleChar, SCC_VOLUME,           1, 0},
aeaef6fe53b7 (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
   470
	{"VOLUME_S",        EmitSingleChar, SCC_VOLUME_SHORT,     1, 0},
aeaef6fe53b7 (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
	{"WEIGHT",          EmitSingleChar, SCC_WEIGHT,           1, 0},
aeaef6fe53b7 (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
	{"WEIGHT_S",        EmitSingleChar, SCC_WEIGHT_SHORT,     1, 0},
aeaef6fe53b7 (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
	{"FORCE",           EmitSingleChar, SCC_FORCE,            1, 0},
aeaef6fe53b7 (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
	{"VELOCITY",        EmitSingleChar, SCC_VELOCITY,         1, 0},
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   475
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4379
diff changeset
   476
	{"P", EmitPlural, 0, 0, C_DONTCOUNT}, // plural specifier
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4379
diff changeset
   477
	{"G", EmitGender, 0, 0, C_DONTCOUNT}, // gender specifier
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   478
5108
aeaef6fe53b7 (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
	{"DATE_TINY",  EmitSingleChar, SCC_DATE_TINY, 1, 0},
aeaef6fe53b7 (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
	{"DATE_SHORT", EmitSingleChar, SCC_DATE_SHORT, 1, 0},
aeaef6fe53b7 (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
	{"DATE_LONG",  EmitSingleChar, SCC_DATE_LONG, 1, 0},
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   482
5108
aeaef6fe53b7 (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
	{"SKIP", EmitSingleChar, SCC_SKIP, 1, 0},
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   484
5108
aeaef6fe53b7 (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
	{"STRING", EmitSingleChar, SCC_STRING, 1, C_CASE},
9648
c79160082c0f (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium
parents: 9111
diff changeset
   486
	{"RAW_STRING", EmitSingleChar, SCC_RAW_STRING_POINTER, 1, 0},
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   487
2410
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2407
diff changeset
   488
	// Numbers
5108
aeaef6fe53b7 (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
   489
	{"COMMA", EmitSingleChar, SCC_COMMA, 1, 0}, // Number with comma
aeaef6fe53b7 (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
   490
	{"NUM",   EmitSingleChar, SCC_NUM,   1, 0}, // Signed number
2410
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2407
diff changeset
   491
5108
aeaef6fe53b7 (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
	{"CURRENCY",   EmitSingleChar, SCC_CURRENCY,    1, 0},
2410
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2407
diff changeset
   493
5108
aeaef6fe53b7 (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
   494
	{"WAYPOINT", EmitSingleChar, SCC_WAYPOINT_NAME, 1, 0}, // waypoint name
aeaef6fe53b7 (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
	{"STATION",  EmitSingleChar, SCC_STATION_NAME,  1, 0},
aeaef6fe53b7 (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
   496
	{"TOWN",     EmitSingleChar, SCC_TOWN_NAME,     1, 0},
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6491
diff changeset
   497
	{"GROUP",    EmitSingleChar, SCC_GROUP_NAME,    1, 0},
7056
6daddeaa79df (svn r10321) -Codechange: refer to sign text by index
peter1138
parents: 7049
diff changeset
   498
	{"SIGN",     EmitSingleChar, SCC_SIGN_NAME,     1, 0},
7059
c6d12e3de0dc (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7058
diff changeset
   499
	{"ENGINE",   EmitSingleChar, SCC_ENGINE_NAME,   1, 0},
7049
0ebe47348074 (svn r10314) -Codechange: Refer to vehicle names by index
peter1138
parents: 7025
diff changeset
   500
	{"VEHICLE",  EmitSingleChar, SCC_VEHICLE_NAME,  1, 0},
7058
8105bb13ce3d (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7056
diff changeset
   501
	{"COMPANY",  EmitSingleChar, SCC_COMPANY_NAME,  1, 0},
8105bb13ce3d (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7056
diff changeset
   502
	{"COMPANYNUM", EmitSingleChar, SCC_COMPANY_NUM, 1, 0},
10209
a1e7417bf1b7 (svn r14423) -Codechange: also do r14221 for the strings.
rubidium
parents: 9956
diff changeset
   503
	{"PRESIDENTNAME", EmitSingleChar, SCC_PRESIDENT_NAME, 1, 0},
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   504
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   505
	// 0x9D is used for the pseudo command SETCASE
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   506
	// 0x9E is used for case switching
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   507
5108
aeaef6fe53b7 (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
	{"",               EmitSingleChar, '\n',               0, C_DONTCOUNT},
aeaef6fe53b7 (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
   509
	{"{",              EmitSingleChar, '{',                0, C_DONTCOUNT},
aeaef6fe53b7 (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
   510
	{"UPARROW",        EmitSingleChar, SCC_UPARROW,        0, 0},
aeaef6fe53b7 (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
   511
	{"SMALLUPARROW",   EmitSingleChar, SCC_SMALLUPARROW,   0, 0},
aeaef6fe53b7 (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
   512
	{"SMALLDOWNARROW", EmitSingleChar, SCC_SMALLDOWNARROW, 0, 0},
aeaef6fe53b7 (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
	{"TRAIN",          EmitSingleChar, SCC_TRAIN,          0, 0},
aeaef6fe53b7 (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
	{"LORRY",          EmitSingleChar, SCC_LORRY,          0, 0},
aeaef6fe53b7 (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
	{"BUS",            EmitSingleChar, SCC_BUS,            0, 0},
aeaef6fe53b7 (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
	{"PLANE",          EmitSingleChar, SCC_PLANE,          0, 0},
aeaef6fe53b7 (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
	{"SHIP",           EmitSingleChar, SCC_SHIP,           0, 0},
aeaef6fe53b7 (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
	{"NBSP",           EmitSingleChar, 0xA0,               0, C_DONTCOUNT},
aeaef6fe53b7 (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
	{"CENT",           EmitSingleChar, 0xA2,               0, C_DONTCOUNT},
aeaef6fe53b7 (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
	{"POUNDSIGN",      EmitSingleChar, 0xA3,               0, C_DONTCOUNT},
aeaef6fe53b7 (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
	{"EURO",           EmitSingleChar, 0x20AC,             0, C_DONTCOUNT},
aeaef6fe53b7 (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
	{"YENSIGN",        EmitSingleChar, 0xA5,               0, C_DONTCOUNT},
aeaef6fe53b7 (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
	{"COPYRIGHT",      EmitSingleChar, 0xA9,               0, C_DONTCOUNT},
aeaef6fe53b7 (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
	{"DOWNARROW",      EmitSingleChar, SCC_DOWNARROW,      0, C_DONTCOUNT},
aeaef6fe53b7 (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
	{"CHECKMARK",      EmitSingleChar, SCC_CHECKMARK,      0, C_DONTCOUNT},
aeaef6fe53b7 (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
	{"CROSS",          EmitSingleChar, SCC_CROSS,          0, C_DONTCOUNT},
aeaef6fe53b7 (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
	{"REGISTERED",     EmitSingleChar, 0xAE,               0, C_DONTCOUNT},
aeaef6fe53b7 (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
	{"RIGHTARROW",     EmitSingleChar, SCC_RIGHTARROW,     0, C_DONTCOUNT},
aeaef6fe53b7 (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
	{"SMALLLEFTARROW", EmitSingleChar, SCC_LESSTHAN,       0, C_DONTCOUNT},
aeaef6fe53b7 (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
	{"SMALLRIGHTARROW",EmitSingleChar, SCC_GREATERTHAN,    0, C_DONTCOUNT},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   531
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   532
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   533
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   534
static const CmdStruct *FindCmd(const char *s, int len)
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   535
{
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   536
	const CmdStruct* cs;
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   537
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   538
	for (cs = _cmd_structs; cs != endof(_cmd_structs); cs++) {
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   539
		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
   540
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   541
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   543
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   544
static uint ResolveCaseName(const char *str, uint len)
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   545
{
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   546
	uint i;
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   547
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   548
	for (i = 0; i < MAX_NUM_CASES; i++) {
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   549
		if (memcmp(_cases[i], str, len) == 0 && _cases[i][len] == 0) return i + 1;
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   550
	}
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   551
	error("Invalid case-name '%s'", str);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   552
}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   553
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   554
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   555
// returns NULL on eof
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   556
// else returns command struct
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   557
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
   558
{
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   559
	const char *s = *str, *start;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   560
	const CmdStruct *cmd;
2060
9f3855e81f4b (svn r2569) Get rid of some dubious casts and thus warnings on 64bit machines
tron
parents: 2059
diff changeset
   561
	byte c;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   563
	*argno = -1;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   564
	*casei = -1;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   565
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   566
	// Scan to the next command, exit if there's no next command.
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   567
	for (; *s != '{'; s++) {
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   568
		if (*s == '\0') return NULL;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   569
	}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   570
	s++; // Skip past the {
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   571
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   572
	if (*s >= '0' && *s <= '9') {
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   573
		char *end;
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   574
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   575
		*argno = strtoul(s, &end, 0);
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   576
		if (*end != ':') error("missing arg #");
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   577
		s = end + 1;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   578
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   579
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   580
	// parse command name
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
	start = s;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   582
	do {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   583
		c = *s++;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   584
	} while (c != '}' && c != ' ' && c != '=' && c != '.' && c != 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   586
	cmd = FindCmd(start, s - start - 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   587
	if (cmd == NULL) {
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   588
		strgen_error("Undefined command '%.*s'", s - start - 1, start);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
		return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   592
	if (c == '.') {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   593
		const char *casep = s;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   594
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   595
		if (!(cmd->flags & C_CASE))
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   596
			error("Command '%s' can't have a case", cmd->cmd);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   597
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   598
		do c = *s++; while (c != '}' && c != ' ' && c != '\0');
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   599
		*casei = ResolveCaseName(casep, s - casep - 1);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   600
	}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   601
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   602
	if (c == '\0') {
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   603
		strgen_error("Missing } from command '%s'", start);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   604
		return NULL;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   605
	}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   606
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   607
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   608
	if (c != '}') {
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   609
		if (c == '=') s--;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   610
		// copy params
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
		start = s;
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   612
		for (;;) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   613
			c = *s++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   614
			if (c == '}') break;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   615
			if (c == '\0') {
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   616
				strgen_error("Missing } from command '%s'", start);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
				return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
			}
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   619
			if (s - start == 250) error("param command too long");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
			*param++ = c;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
	}
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   623
	*param = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   624
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   625
	*str = s;
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
	return cmd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   628
}
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
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   631
static void HandlePragma(char *str)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   632
{
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   633
	if (!memcmp(str, "id ", 3)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   634
		_next_string_id = strtoul(str + 3, NULL, 0);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   635
	} else if (!memcmp(str, "name ", 5)) {
10310
ca2eb5811a07 (svn r14555) -Codechange: replace ttd_strlcat and ttd_strlcpy with strecat and strecpy where direct conversion is possible
skidd13
parents: 10309
diff changeset
   636
		strecpy(_lang_name, str + 5, lastof(_lang_name));
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   637
	} else if (!memcmp(str, "ownname ", 8)) {
10310
ca2eb5811a07 (svn r14555) -Codechange: replace ttd_strlcat and ttd_strlcpy with strecat and strecpy where direct conversion is possible
skidd13
parents: 10309
diff changeset
   638
		strecpy(_lang_ownname, str + 8, lastof(_lang_ownname));
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   639
	} else if (!memcmp(str, "isocode ", 8)) {
10310
ca2eb5811a07 (svn r14555) -Codechange: replace ttd_strlcat and ttd_strlcpy with strecat and strecpy where direct conversion is possible
skidd13
parents: 10309
diff changeset
   640
		strecpy(_lang_isocode, str + 8, lastof(_lang_isocode));
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   641
	} else if (!memcmp(str, "plural ", 7)) {
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   642
		_lang_pluralform = atoi(str + 7);
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
   643
		if (_lang_pluralform >= lengthof(_plural_form_counts))
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   644
			error("Invalid pluralform %d", _lang_pluralform);
10249
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
   645
	} else if (!memcmp(str, "textdir ", 8)) {
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
   646
		if (!memcmp(str + 8, "ltr", 3)) {
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
   647
			_lang_textdir = TD_LTR;
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
   648
		} else if (!memcmp(str + 8, "rtl", 3)) {
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
   649
			_lang_textdir = TD_RTL;
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
   650
		} else {
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
   651
			error("Invalid textdir %s", str + 8);
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
   652
		}
10367
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
   653
	} else if (!memcmp(str, "winlangid ", 10)) {
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
   654
		char *buf = str + 10;
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
   655
		long langid = strtol(buf, NULL, 16);
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
   656
		if (langid > UINT16_MAX || langid < 0) {
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
   657
			error("Invalid winlangid %s", buf);
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
   658
		}
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
   659
		_lang_winlangid = (uint16)langid;
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   660
	} else if (!memcmp(str, "gender ", 7)) {
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   661
		char* buf = str + 7;
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   662
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   663
		for (;;) {
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   664
			const char* s = ParseWord(&buf);
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   665
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   666
			if (s == NULL) break;
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   667
			if (_numgenders >= MAX_NUM_GENDER) error("Too many genders, max %d", MAX_NUM_GENDER);
10310
ca2eb5811a07 (svn r14555) -Codechange: replace ttd_strlcat and ttd_strlcpy with strecat and strecpy where direct conversion is possible
skidd13
parents: 10309
diff changeset
   668
			strecpy(_genders[_numgenders], s, lastof(_genders[_numgenders]));
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   669
			_numgenders++;
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   670
		}
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   671
	} else if (!memcmp(str, "case ", 5)) {
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   672
		char* buf = str + 5;
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   673
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   674
		for (;;) {
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   675
			const char* s = ParseWord(&buf);
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   676
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   677
			if (s == NULL) break;
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   678
			if (_numcases >= MAX_NUM_CASES) error("Too many cases, max %d", MAX_NUM_CASES);
10310
ca2eb5811a07 (svn r14555) -Codechange: replace ttd_strlcat and ttd_strlcpy with strecat and strecpy where direct conversion is possible
skidd13
parents: 10309
diff changeset
   679
			strecpy(_cases[_numcases], s, lastof(_cases[_numcases]));
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   680
			_numcases++;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   681
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   682
	} else {
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   683
		error("unknown pragma '%s'", str);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   684
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   685
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   686
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   687
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
   688
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   689
	char param[100];
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   690
	int argno;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   691
	int argidx = 0;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   692
	int casei;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   693
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   694
	memset(p, 0, sizeof(*p));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   695
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   696
	for (;;) {
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   697
		// read until next command from a.
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   698
		const CmdStruct* ar = ParseCommandString(&s, param, &argno, &casei);
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   699
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   700
		if (ar == NULL) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   701
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   702
		// Sanity checking
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   703
		if (argno != -1 && ar->consumes == 0) error("Non consumer param can't have a paramindex");
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   704
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   705
		if (ar->consumes) {
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   706
			if (argno != -1) argidx = argno;
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   707
			if (argidx < 0 || argidx >= lengthof(p->cmd)) error("invalid param idx %d", argidx);
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   708
			if (p->cmd[argidx] != NULL && p->cmd[argidx] != ar) error("duplicate param idx %d", argidx);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   709
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   710
			p->cmd[argidx++] = ar;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   711
		} else if (!(ar->flags & C_DONTCOUNT)) { // Ignore some of them
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   712
			if (p->np >= lengthof(p->pairs)) error("too many commands in string, max %d", lengthof(p->pairs));
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   713
			p->pairs[p->np].a = ar;
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   714
			p->pairs[p->np].v = param[0] != '\0' ? strdup(param) : "";
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   715
			p->np++;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   716
		}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   717
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   718
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   720
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   721
static const CmdStruct *TranslateCmdForCompare(const CmdStruct *a)
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   722
{
3015
f91a1b8fba79 (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 (a == NULL) return NULL;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   724
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   725
	if (strcmp(a->cmd, "STRING1") == 0 ||
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   726
			strcmp(a->cmd, "STRING2") == 0 ||
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   727
			strcmp(a->cmd, "STRING3") == 0 ||
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   728
			strcmp(a->cmd, "STRING4") == 0 ||
9648
c79160082c0f (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium
parents: 9111
diff changeset
   729
			strcmp(a->cmd, "STRING5") == 0 ||
c79160082c0f (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium
parents: 9111
diff changeset
   730
			strcmp(a->cmd, "RAW_STRING") == 0){
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   731
		return FindCmd("STRING", 6);
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   732
	}
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   733
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   734
	if (strcmp(a->cmd, "SKIP") == 0) return NULL;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   735
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   736
	return a;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   737
}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   738
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   739
2069
30294fb11fc1 (svn r2579) Change some strgen errors into warnings to prevent build from stopping.
ludde
parents: 2063
diff changeset
   740
static bool CheckCommandsMatch(char *a, char *b, const char *name)
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   741
{
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   742
	ParsedCommandStruct templ;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   743
	ParsedCommandStruct lang;
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6248
diff changeset
   744
	int i, j;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   745
	bool result = true;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   746
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   747
	ExtractCommandString(&templ, b, true);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   748
	ExtractCommandString(&lang, a, true);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   749
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   750
	// For each string in templ, see if we find it in lang
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   751
	if (templ.np != lang.np) {
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   752
		strgen_warning("%s: template string and language string have a different # of commands", name);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   753
		result = false;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   754
	}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   755
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   756
	for (i = 0; i < templ.np; i++) {
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   757
		// see if we find it in lang, and zero it out
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   758
		bool found = false;
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   759
		for (j = 0; j < lang.np; j++) {
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   760
			if (templ.pairs[i].a == lang.pairs[j].a &&
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   761
					strcmp(templ.pairs[i].v, lang.pairs[j].v) == 0) {
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   762
				// it was found in both. zero it out from lang so we don't find it again
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   763
				lang.pairs[j].a = NULL;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   764
				found = true;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   765
				break;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   766
			}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   767
		}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   768
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   769
		if (!found) {
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   770
			strgen_warning("%s: command '%s' exists in template file but not in language file", name, templ.pairs[i].a->cmd);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   771
			result = false;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   772
		}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   773
	}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   774
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   775
	// if we reach here, all non consumer commands match up.
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   776
	// Check if the non consumer commands match up also.
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
   777
	for (i = 0; i < lengthof(templ.cmd); i++) {
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   778
		if (TranslateCmdForCompare(templ.cmd[i]) != TranslateCmdForCompare(lang.cmd[i])) {
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   779
			strgen_warning("%s: Param idx #%d '%s' doesn't match with template command '%s'", name, i,
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   780
				lang.cmd[i]  == NULL ? "<empty>" : lang.cmd[i]->cmd,
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   781
				templ.cmd[i] == NULL ? "<empty>" : templ.cmd[i]->cmd);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   782
			result = false;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   783
		}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   784
	}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   785
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   786
	return result;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   787
}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   788
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   789
static void HandleString(char *str, bool master)
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   790
{
8969
6d1c74e0e2cd (svn r12761) -Codechange: lots of minor whitespace coding style fixes around operators.
rubidium
parents: 8812
diff changeset
   791
	char *s, *t;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   792
	LangString *ent;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   793
	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
   794
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   795
	if (*str == '#') {
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   796
		if (str[1] == '#' && str[2] != '#') HandlePragma(str + 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   797
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   798
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   800
	// Ignore comments & blank lines
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   801
	if (*str == ';' || *str == ' ' || *str == '\0') return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   802
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   803
	s = strchr(str, ':');
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   804
	if (s == NULL) {
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   805
		strgen_error("Line has no ':' delimiter");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   806
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   807
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   808
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   809
	// Trim spaces.
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   810
	// After this str points to the command name, and s points to the command contents
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   811
	for (t = s; t > str && (t[-1] == ' ' || t[-1] == '\t'); t--);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   812
	*t = 0;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   813
	s++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   814
5111
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   815
	/* Check string is valid UTF-8 */
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   816
	{
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   817
		const char *tmp;
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   818
		for (tmp = s; *tmp != '\0';) {
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   819
			size_t len = Utf8Validate(tmp);
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   820
			if (len == 0) error("Invalid UTF-8 sequence in '%s'", s);
5111
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   821
			tmp += len;
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   822
		}
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   823
	}
ee7472776a4d (svn r7185) -Codechange: Make strgen validate strings for UTF-8 well-formed-ness-ness
peter1138
parents: 5108
diff changeset
   824
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   825
	// Check if the string has a case..
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   826
	// The syntax for cases is IDENTNAME.case
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   827
	casep = strchr(str, '.');
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   828
	if (casep) *casep++ = 0;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   829
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   830
	// Check if this string already exists..
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   831
	ent = HashFind(str);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   833
	if (master) {
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   834
		if (ent != NULL && casep == NULL) {
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   835
			strgen_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
   836
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   837
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   838
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   839
		if (ent == NULL && casep != NULL) {
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   840
			strgen_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
   841
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   843
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   844
		if (ent == NULL) {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   845
			if (_strings[_next_string_id]) {
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   846
				strgen_error("String ID 0x%X for '%s' already in use by '%s'", ent, str, _strings[_next_string_id]->name);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   847
				return;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   848
			}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   849
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   850
			// Allocate a new LangString
5609
dc6a58930ba4 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5587
diff changeset
   851
			ent = CallocT<LangString>(1);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   852
			_strings[_next_string_id] = ent;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   853
			ent->index = _next_string_id++;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   854
			ent->name = strdup(str);
2566
75ae28a03460 (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
   855
			ent->line = _cur_line;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   856
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   857
			HashAdd(str, ent);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   858
		}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   859
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   860
		if (casep != NULL) {
5609
dc6a58930ba4 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5587
diff changeset
   861
			Case* c = MallocT<Case>(1);
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   862
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   863
			c->caseidx = ResolveCaseName(casep, strlen(casep));
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   864
			c->string = strdup(s);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   865
			c->next = ent->english_case;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   866
			ent->english_case = c;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   867
		} else {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   868
			ent->english = strdup(s);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   869
		}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   870
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
	} else {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   872
		if (ent == NULL) {
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   873
			strgen_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
   874
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   875
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   877
		if (ent->translated && casep == NULL) {
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   878
			strgen_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
   879
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   880
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   881
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   882
		if (s[0] == ':' && s[1] == '\0' && casep == NULL) {
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   883
			// Special syntax :: means we should just inherit the master string
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   884
			ent->translated = strdup(ent->english);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   885
		} else {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   886
			// make sure that the commands match
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   887
			if (!CheckCommandsMatch(s, ent->english, str)) return;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   888
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   889
			if (casep != NULL) {
5609
dc6a58930ba4 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5587
diff changeset
   890
				Case* c = MallocT<Case>(1);
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   891
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   892
				c->caseidx = ResolveCaseName(casep, strlen(casep));
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   893
				c->string = strdup(s);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   894
				c->next = ent->translated_case;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   895
				ent->translated_case = c;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   896
			} else {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   897
				ent->translated = strdup(s);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   898
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   899
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   900
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   901
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   902
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   903
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   904
static void rstrip(char *buf)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   905
{
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   906
	int i = strlen(buf);
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   907
	while (i > 0 && (buf[i - 1] == '\r' || buf[i - 1] == '\n' || buf[i - 1] == ' ')) i--;
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   908
	buf[i] = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   909
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   910
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   911
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   912
static void ParseFile(const char *file, bool english)
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   913
{
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   914
	FILE *in;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   915
	char buf[2048];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   916
2459
a2f63b331830 (svn r2985) Print warnings and errors in the canonical file:line: form to make life for IDEs easier (ln-)
tron
parents: 2418
diff changeset
   917
	_file = file;
a2f63b331830 (svn r2985) Print warnings and errors in the canonical file:line: form to make life for IDEs easier (ln-)
tron
parents: 2418
diff changeset
   918
5725
0ec667093bc1 (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: 5609
diff changeset
   919
	/* For each new file we parse, reset the genders, and language codes */
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   920
	_numgenders = 0;
5725
0ec667093bc1 (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: 5609
diff changeset
   921
	_lang_name[0] = _lang_ownname[0] = _lang_isocode[0] = '\0';
10249
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
   922
	_lang_textdir = TD_LTR;
10367
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
   923
	_lang_winlangid = 0x0000; // neutral language code
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   924
	// TODO:!! We can't reset the cases. In case the translated strings
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   925
	// derive some strings from english....
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   926
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   927
	in = fopen(file, "r");
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   928
	if (in == NULL) error("Cannot open file");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
	_cur_line = 1;
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6248
diff changeset
   930
	while (fgets(buf, sizeof(buf), in) != NULL) {
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   931
		rstrip(buf);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   932
		HandleString(buf, english);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   933
		_cur_line++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   934
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   935
	fclose(in);
5725
0ec667093bc1 (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: 5609
diff changeset
   936
0ec667093bc1 (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: 5609
diff changeset
   937
	if (StrEmpty(_lang_name) || StrEmpty(_lang_ownname) || StrEmpty(_lang_isocode)) {
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
   938
		error("Language must include ##name, ##ownname and ##isocode");
5725
0ec667093bc1 (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: 5609
diff changeset
   939
	}
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   940
}
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   941
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   942
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   943
static uint32 MyHashStr(uint32 hash, const char *s)
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   944
{
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   945
	for (; *s != '\0'; s++) {
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   946
		hash = ROL(hash, 3) ^ *s;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3900
diff changeset
   947
		hash = (hash & 1 ? hash >> 1 ^ 0xDEADBEEF : hash >> 1);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   948
	}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   949
	return hash;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   950
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   951
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   952
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   953
// make a hash of the file to get a unique "version number"
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5832
diff changeset
   954
static void MakeHashOfStrings()
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   955
{
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   956
	uint32 hash = 0;
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   957
	uint i;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   958
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   959
	for (i = 0; i != lengthof(_strings); i++) {
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   960
		const LangString* ls = _strings[i];
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   961
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   962
		if (ls != NULL) {
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   963
			const CmdStruct* cs;
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   964
			const char* s;
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   965
			char buf[256];
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   966
			int argno;
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   967
			int casei;
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   968
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   969
			s = ls->name;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   970
			hash ^= i * 0x717239;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3900
diff changeset
   971
			hash = (hash & 1 ? hash >> 1 ^ 0xDEADBEEF : hash >> 1);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   972
			hash = MyHashStr(hash, s + 1);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   973
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   974
			s = ls->english;
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   975
			while ((cs = ParseCommandString(&s, buf, &argno, &casei)) != NULL) {
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   976
				if (cs->flags & C_DONTCOUNT) continue;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   977
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   978
				hash ^= (cs - _cmd_structs) * 0x1234567;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3900
diff changeset
   979
				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
   980
			}
0
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
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   983
	_hash = hash;
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
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   986
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   987
static uint CountInUse(uint grp)
2059
6446d0b23ddc (svn r2568) Small cleanup in strgen: static, bracing, ...
tron
parents: 2057
diff changeset
   988
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   989
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   990
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
   991
	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
   992
	return i + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   993
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   994
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   995
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
   996
bool CompareFiles(const char *n1, const char *n2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   997
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   998
	FILE *f1, *f2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   999
	char b1[4096];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1000
	char b2[4096];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1001
	size_t l1, l2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1002
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1003
	f2 = fopen(n2, "rb");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1004
	if (f2 == NULL) return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1005
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1006
	f1 = fopen(n1, "rb");
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
  1007
	if (f1 == NULL) error("can't open %s", n1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1008
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1009
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1010
		l1 = fread(b1, 1, sizeof(b1), f1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1011
		l2 = fread(b2, 1, sizeof(b2), f2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1012
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1013
		if (l1 != l2 || memcmp(b1, b2, l1)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1014
			fclose(f2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1015
			fclose(f1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1016
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1017
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1018
	} while (l1);
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
	fclose(f2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1021
	fclose(f1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1022
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1023
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1024
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1025
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1026
static void WriteStringsH(const char *filename)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1027
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1028
	FILE *out;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1029
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1030
	int next = -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
	out = fopen("tmp.xxx", "w");
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
  1033
	if (out == NULL) error("can't open tmp.xxx");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1034
7393
f3d27c82fec3 (svn r10762) -Codechange: Change enum StringIDEnum { to static const StringID = for
peter1138
parents: 7110
diff changeset
  1035
	fprintf(out, "/* This file is automatically generated. Do not modify */\n\n");
f3d27c82fec3 (svn r10762) -Codechange: Change enum StringIDEnum { to static const StringID = for
peter1138
parents: 7110
diff changeset
  1036
	fprintf(out, "#ifndef TABLE_STRINGS_H\n");
f3d27c82fec3 (svn r10762) -Codechange: Change enum StringIDEnum { to static const StringID = for
peter1138
parents: 7110
diff changeset
  1037
	fprintf(out, "#define TABLE_STRINGS_H\n");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1038
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1039
	for (i = 0; i != lengthof(_strings); i++) {
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1040
		if (_strings[i] != NULL) {
7393
f3d27c82fec3 (svn r10762) -Codechange: Change enum StringIDEnum { to static const StringID = for
peter1138
parents: 7110
diff changeset
  1041
			if (next != i) fprintf(out, "\n");
f3d27c82fec3 (svn r10762) -Codechange: Change enum StringIDEnum { to static const StringID = for
peter1138
parents: 7110
diff changeset
  1042
			fprintf(out, "static const StringID %s = 0x%X;\n", _strings[i]->name, i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1043
			next = i + 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1044
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1045
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1046
7755
7038d5001e0a (svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents: 7393
diff changeset
  1047
	fprintf(out, "\nstatic const StringID STR_LAST_STRINGID = 0x%X;\n", next - 1);
7038d5001e0a (svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents: 7393
diff changeset
  1048
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
  1049
	fprintf(out,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1050
		"\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
  1051
		"\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
  1052
		"\tLANGUAGE_PACK_VERSION = 0x%X,\n"
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1053
		"};\n", (uint)_hash
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1054
	);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1055
7393
f3d27c82fec3 (svn r10762) -Codechange: Change enum StringIDEnum { to static const StringID = for
peter1138
parents: 7110
diff changeset
  1056
	fprintf(out, "\n#endif /* TABLE_STRINGS_H */\n");
f3d27c82fec3 (svn r10762) -Codechange: Change enum StringIDEnum { to static const StringID = for
peter1138
parents: 7110
diff changeset
  1057
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1058
	fclose(out);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1059
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1060
	if (CompareFiles("tmp.xxx", filename)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1061
		// files are equal. tmp.xxx is not needed
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1062
		unlink("tmp.xxx");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1063
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1064
		// else rename tmp.xxx into filename
2482
374f6395847d (svn r3008) [ 1247535 ] Native Support for Win64 (compile&run only) (michi_cc)
Darkvater
parents: 2459
diff changeset
  1065
#if defined(WIN32) || defined(WIN64)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1066
		unlink(filename);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1067
#endif
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
  1068
		if (rename("tmp.xxx", filename) == -1) error("rename() failed");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1069
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1070
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1071
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1072
static int TranslateArgumentIdx(int argidx)
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1073
{
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1074
	int i, sum;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1075
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1076
	if (argidx < 0 || argidx >= lengthof(_cur_pcs.cmd))
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
  1077
		error("invalid argidx %d", argidx);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1078
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
  1079
	for (i = sum = 0; i < argidx; i++) {
2374
e4443eab6293 (svn r2900) Fix a bug, which incremented the counter of a loop twice and therefore calculated wrong argument indices
tron
parents: 2353
diff changeset
  1080
		const CmdStruct *cs = _cur_pcs.cmd[i];
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1081
		sum += (cs != NULL) ? cs->consumes : 1;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1082
	}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1083
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1084
	return sum;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1085
}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1086
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5832
diff changeset
  1087
static void PutArgidxCommand()
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1088
{
5108
aeaef6fe53b7 (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
  1089
	PutUtf8(SCC_ARG_INDEX);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1090
	PutByte(TranslateArgumentIdx(_cur_argidx));
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1091
}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1092
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1093
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1094
static void PutCommandString(const char *str)
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1095
{
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1096
	const CmdStruct *cs;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1097
	char param[256];
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1098
	int argno;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1099
	int casei;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1100
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1101
	_cur_argidx = 0;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1102
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1103
	while (*str != '\0') {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1104
		// Process characters as they are until we encounter a {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1105
		if (*str != '{') {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1106
			PutByte(*str++);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1107
			continue;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1108
		}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1109
		cs = ParseCommandString(&str, param, &argno, &casei);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1110
		if (cs == NULL) break;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1111
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1112
		if (casei != -1) {
5108
aeaef6fe53b7 (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
  1113
			PutUtf8(SCC_SETCASE); // {SETCASE}
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1114
			PutByte(casei);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1115
		}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1116
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1117
		// For params that consume values, we need to handle the argindex properly
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1118
		if (cs->consumes > 0) {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1119
			// Check if we need to output a move-param command
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1120
			if (argno != -1 && argno != _cur_argidx) {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1121
				_cur_argidx = argno;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1122
				PutArgidxCommand();
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1123
			}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1124
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1125
			// Output the one from the master string... it's always accurate.
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1126
			cs = _cur_pcs.cmd[_cur_argidx++];
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1127
			if (cs == NULL) {
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
  1128
				error("%s: No argument exists at position %d", _cur_ident, _cur_argidx - 1);
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1129
			}
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1130
		}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1131
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1132
		cs->proc(param, cs->value);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1133
	}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1134
}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1135
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1136
static void WriteLength(FILE *f, uint length)
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1137
{
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1138
	if (length < 0xC0) {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1139
		fputc(length, f);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1140
	} else if (length < 0x4000) {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1141
		fputc((length >> 8) | 0xC0, f);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1142
		fputc(length & 0xFF, f);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1143
	} else {
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
  1144
		error("string too long");
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1145
	}
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1146
}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1147
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1148
7110
bda0a45e30e5 (svn r10382) -Fix (strgen): it was not possible to use --warning and --todo at the same time.
rubidium
parents: 7059
diff changeset
  1149
static void WriteLangfile(const char *filename)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1151
	FILE *f;
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1152
	uint in_use[32];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1153
	LanguagePackHeader hdr;
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1154
	uint i;
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1155
	uint j;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1156
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1157
	f = fopen(filename, "wb");
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
  1158
	if (f == NULL) error("can't open %s", filename);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1159
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1160
	memset(&hdr, 0, sizeof(hdr));
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
  1161
	for (i = 0; i != 32; i++) {
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1162
		uint n = CountInUse(i);
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1163
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1164
		in_use[i] = n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1165
		hdr.offsets[i] = TO_LE16(n);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1166
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1167
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
  1168
	// 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
  1169
	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
  1170
	hdr.version = TO_LE32(_hash);
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1171
	hdr.plural_form = _lang_pluralform;
10249
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
  1172
	hdr.text_dir = _lang_textdir;
10367
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1173
	hdr.winlangid = TO_LE16(_lang_winlangid);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1174
	strcpy(hdr.name, _lang_name);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1175
	strcpy(hdr.own_name, _lang_ownname);
1376
d4e1dd8eb7e5 (svn r1880) [Codechange] Added isocodes to langfiles and support code to strgen (Lauri Nurmi)
miham
parents: 1097
diff changeset
  1176
	strcpy(hdr.isocode, _lang_isocode);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1177
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1178
	fwrite(&hdr, sizeof(hdr), 1, f);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1179
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
  1180
	for (i = 0; i != 32; i++) {
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
  1181
		for (j = 0; j != in_use[i]; j++) {
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1182
			const LangString* ls = _strings[(i << 11) + j];
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1183
			const Case* casep;
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1184
			const char* cmdp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1185
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1186
			// For undefined strings, just set that it's an empty string
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1187
			if (ls == NULL) {
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1188
				WriteLength(f, 0);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1189
				continue;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1190
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1191
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1192
			_cur_ident = ls->name;
2566
75ae28a03460 (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
  1193
			_cur_line = ls->line;
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2069
diff changeset
  1194
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1195
			// Produce a message if a string doesn't have a translation.
7110
bda0a45e30e5 (svn r10382) -Fix (strgen): it was not possible to use --warning and --todo at the same time.
rubidium
parents: 7059
diff changeset
  1196
			if (_show_todo > 0 && ls->translated == NULL) {
bda0a45e30e5 (svn r10382) -Fix (strgen): it was not possible to use --warning and --todo at the same time.
rubidium
parents: 7059
diff changeset
  1197
				if ((_show_todo & 2) != 0) {
8983
ea20f3cd2165 (svn r12777) -Codechange: rename fatal() and error() in strgen, so it can always have the NORETURN attribute
smatz
parents: 8969
diff changeset
  1198
					strgen_warning("'%s' is untranslated", ls->name);
7110
bda0a45e30e5 (svn r10382) -Fix (strgen): it was not possible to use --warning and --todo at the same time.
rubidium
parents: 7059
diff changeset
  1199
				}
bda0a45e30e5 (svn r10382) -Fix (strgen): it was not possible to use --warning and --todo at the same time.
rubidium
parents: 7059
diff changeset
  1200
				if ((_show_todo & 1) != 0) {
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1201
					const char *s = "<TODO> ";
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1202
					while (*s != '\0') PutByte(*s++);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1203
				}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1204
			}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1205
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1206
			// Extract the strings and stuff from the english command string
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1207
			ExtractCommandString(&_cur_pcs, ls->english, false);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1208
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1209
			if (ls->translated_case != NULL || ls->translated != NULL) {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1210
				casep = ls->translated_case;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1211
				cmdp = ls->translated;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1212
			} else {
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1213
				casep = ls->english_case;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1214
				cmdp = ls->english;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1215
			}
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1216
2586
1c0f0b67a70d (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
  1217
			_translated = _masterlang || (cmdp != ls->english);
2585
fa2f94aa9de2 (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
  1218
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1219
			if (casep != NULL) {
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1220
				const Case* c;
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1221
				uint num;
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1222
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1223
				// Need to output a case-switch.
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1224
				// It has this format
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1225
				// <0x9E> <NUM CASES> <CASE1> <LEN1> <STRING1> <CASE2> <LEN2> <STRING2> <CASE3> <LEN3> <STRING3> <STRINGDEFAULT>
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1226
				// Each LEN is printed using 2 bytes in big endian order.
5108
aeaef6fe53b7 (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
  1227
				PutUtf8(SCC_SWITCH_CASE);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1228
				// Count the number of cases
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2904
diff changeset
  1229
				for (num = 0, c = casep; c; c = c->next) num++;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1230
				PutByte(num);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1231
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1232
				// Write each case
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1233
				for (c = casep; c != NULL; c = c->next) {
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1234
					int pos;
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1235
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1236
					PutByte(c->caseidx);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1237
					// Make some space for the 16-bit length
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1238
					pos = _put_pos;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1239
					PutByte(0);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1240
					PutByte(0);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1241
					// Write string
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1242
					PutCommandString(c->string);
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1243
					PutByte(0); // terminate with a zero
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1244
					// Fill in the length
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1245
					_put_buf[pos + 0] = GB(_put_pos - (pos + 2), 8, 8);
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1246
					_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
  1247
				}
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
  1248
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1249
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1250
			if (cmdp != NULL) PutCommandString(cmdp);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1251
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1252
			WriteLength(f, _put_pos);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1253
			fwrite(_put_buf, 1, _put_pos, f);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1254
			_put_pos = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1255
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1256
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1257
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1258
	fputc(0, f);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1259
	fclose(f);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1260
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1261
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1262
/** Multi-OS mkdirectory function */
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1263
static inline void ottd_mkdir(const char *directory)
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1264
{
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1265
#if defined(WIN32) || defined(__WATCOMC__)
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1266
		mkdir(directory);
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1267
#else
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1268
		mkdir(directory, 0755);
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1269
#endif
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1270
}
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1271
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1272
/** Create a path consisting of an already existing path, a possible
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1273
 * path seperator and the filename. The seperator is only appended if the path
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1274
 * does not already end with a seperator */
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1275
static inline char *mkpath(char *buf, size_t buflen, const char *path, const char *file)
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1276
{
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1277
	char *p;
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1278
	ttd_strlcpy(buf, path, buflen); // copy directory into buffer
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1279
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1280
	p = strchr(buf, '\0'); // add path seperator if necessary
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1281
	if (p[-1] != PATHSEPCHAR && (size_t)(p - buf) + 1 < buflen) *p++ = PATHSEPCHAR;
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1282
	ttd_strlcpy(p, file, buflen - (size_t)(p - buf)); // catenate filename at end of buffer
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1283
	return buf;
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1284
}
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1285
5503
036e83e9083a (svn r7796) -Fix (r7759): cygwin does not need to rewrite the paths for strgen.
rubidium
parents: 5475
diff changeset
  1286
#if defined(__MINGW32__)
4379
96eb926dcc1d (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1287
/**
96eb926dcc1d (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1288
 * On MingW, it is common that both / as \ are accepted in the
96eb926dcc1d (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1289
 * params. To go with those flow, we rewrite all incoming /
96eb926dcc1d (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1290
 * simply to \, so internally we can safely assume \.
96eb926dcc1d (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1291
 */
96eb926dcc1d (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1292
static inline char *replace_pathsep(char *s)
96eb926dcc1d (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1293
{
96eb926dcc1d (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1294
	char *c;
96eb926dcc1d (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1295
96eb926dcc1d (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1296
	for (c = s; *c != '\0'; c++) if (*c == '/') *c = '\\';
96eb926dcc1d (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1297
	return s;
96eb926dcc1d (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1298
}
96eb926dcc1d (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1299
#else
96eb926dcc1d (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1300
static inline char *replace_pathsep(char *s) { return s; }
96eb926dcc1d (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1301
#endif
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1302
250
733e18ca6e93 (svn r251) -Project ready for 0.3.4 release. Updated installer, readme and fileinformation
darkvater
parents: 236
diff changeset
  1303
int CDECL main(int argc, char* argv[])
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1304
{
8812
4fd6de597c6e (svn r12557) -Cleanup: use MAX_PATH at two more places
smatz
parents: 8733
diff changeset
  1305
	char pathbuf[MAX_PATH];
4461
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1306
	const char *src_dir = ".";
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1307
	const char *dest_dir = NULL;
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1308
4461
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1309
	while (argc > 1 && *argv[1] == '-') {
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1310
		if (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0) {
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1311
			puts("$Revision$");
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1312
			return 0;
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1313
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1314
4461
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1315
		if (strcmp(argv[1], "-t") == 0 || strcmp(argv[1], "--todo") == 0) {
7110
bda0a45e30e5 (svn r10382) -Fix (strgen): it was not possible to use --warning and --todo at the same time.
rubidium
parents: 7059
diff changeset
  1316
			_show_todo |= 1;
4461
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1317
			argc--, argv++;
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1318
			continue;
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1319
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1320
4461
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1321
		if (strcmp(argv[1], "-w") == 0 || strcmp(argv[1], "--warning") == 0) {
7110
bda0a45e30e5 (svn r10382) -Fix (strgen): it was not possible to use --warning and --todo at the same time.
rubidium
parents: 7059
diff changeset
  1322
			_show_todo |= 2;
4461
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1323
			argc--, argv++;
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1324
			continue;
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1325
		}
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1326
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1327
		if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0) {
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1328
			puts(
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1329
				"strgen - $Revision$\n"
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1330
				" -v | --version    print version information and exit\n"
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1331
				" -t | --todo       replace any untranslated strings with '<TODO>'\n"
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1332
				" -w | --warning    print a warning for any untranslated strings\n"
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1333
				" -h | -? | --help  print this help message and exit\n"
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1334
				" -s | --source_dir search for english.txt in the specified directory\n"
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1335
				" -d | --dest_dir   put output file in the specified directory, create if needed\n"
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1336
				" Run without parameters and strgen will search for english.txt and parse it,\n"
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1337
				" creating strings.h. Passing an argument, strgen will translate that language\n"
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1338
				" file using english.txt as a reference and output <language>.lng."
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1339
			);
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1340
			return 0;
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1341
		}
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1342
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1343
		if (argc > 2 && (strcmp(argv[1], "-s") == 0 || strcmp(argv[1], "--source_dir") == 0)) {
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1344
			src_dir = replace_pathsep(argv[2]);
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1345
			argc -= 2, argv += 2;
4464
08e89a8faa09 (svn r6247) -Fix(r6244): invalid arguments caused infinite loop
glx
parents: 4461
diff changeset
  1346
			continue;
4461
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1347
		}
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1348
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1349
		if (argc > 2 && (strcmp(argv[1], "-d") == 0 || strcmp(argv[1], "--dest_dir") == 0)) {
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1350
			dest_dir = replace_pathsep(argv[2]);
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1351
			argc -= 2, argv += 2;
4464
08e89a8faa09 (svn r6247) -Fix(r6244): invalid arguments caused infinite loop
glx
parents: 4461
diff changeset
  1352
			continue;
4461
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1353
		}
4464
08e89a8faa09 (svn r6247) -Fix(r6244): invalid arguments caused infinite loop
glx
parents: 4461
diff changeset
  1354
08e89a8faa09 (svn r6247) -Fix(r6244): invalid arguments caused infinite loop
glx
parents: 4461
diff changeset
  1355
		fprintf(stderr, "Invalid arguments\n");
08e89a8faa09 (svn r6247) -Fix(r6244): invalid arguments caused infinite loop
glx
parents: 4461
diff changeset
  1356
		return 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1357
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1358
4461
905cb9ca6fe5 (svn r6244) -Fix: allow any order for strgen parameters
glx
parents: 4447
diff changeset
  1359
	if (dest_dir == NULL) dest_dir = src_dir; // if dest_dir is not specified, it equals src_dir
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1360
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1361
	/* strgen has two modes of operation. If no (free) arguments are passed
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1362
	 * strgen generates strings.h to the destination directory. If it is supplied
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1363
	 * with a (free) parameter the program will translate that language to destination
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1364
	 * 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
  1365
	if (argc == 1) {
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1366
		mkpath(pathbuf, lengthof(pathbuf), src_dir, "english.txt");
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1367
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1368
		/* parse master file */
2586
1c0f0b67a70d (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
  1369
		_masterlang = true;
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1370
		ParseFile(pathbuf, true);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1371
		MakeHashOfStrings();
ae866a12f2df (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;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1373
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1374
		/* write strings.h */
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1375
		ottd_mkdir(dest_dir);
5beb8896ae3d (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, "strings.h");
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1377
		WriteStringsH(pathbuf);
3015
f91a1b8fba79 (svn r3595) Several small cleanups, the only notable are some additional symbolic names for a few ISO8859 characters
tron
parents: 2952
diff changeset
  1378
	} else if (argc == 2) {
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1379
		char *r;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1380
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1381
		mkpath(pathbuf, lengthof(pathbuf), src_dir, "english.txt");
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1382
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1383
		/* parse master file and check if target file is correct */
2586
1c0f0b67a70d (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
  1384
		_masterlang = false;
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1385
		ParseFile(pathbuf, true);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1386
		MakeHashOfStrings();
4379
96eb926dcc1d (svn r6117) -Fix r6097: on mingw it is normal that both / as \ are accepted as input
truelight
parents: 4373
diff changeset
  1387
		ParseFile(replace_pathsep(argv[1]), false); // target file
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1388
		if (_errors) return 1;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2060
diff changeset
  1389
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1390
		/* get the targetfile, strip any directories and append to destination path */
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1391
		r = strrchr(argv[1], PATHSEPCHAR);
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1392
		mkpath(pathbuf, lengthof(pathbuf), dest_dir, (r != NULL) ? &r[1] : argv[1]);
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1393
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1394
		/* rename the .txt (input-extension) to .lng */
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1395
		r = strrchr(pathbuf, '.');
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1396
		if (r == NULL || strcmp(r, ".txt") != 0) r = strchr(pathbuf, '\0');
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1397
		ttd_strlcpy(r, ".lng", (size_t)(r - pathbuf));
7110
bda0a45e30e5 (svn r10382) -Fix (strgen): it was not possible to use --warning and --todo at the same time.
rubidium
parents: 7059
diff changeset
  1398
		WriteLangfile(pathbuf);
5360
d87dfdb62e5a (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
  1399
d87dfdb62e5a (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
  1400
		/* if showing warnings, print a summary of the language */
7110
bda0a45e30e5 (svn r10382) -Fix (strgen): it was not possible to use --warning and --todo at the same time.
rubidium
parents: 7059
diff changeset
  1401
		if ((_show_todo & 2) != 0) {
5442
577bf6b7da95 (svn r7693) -Codechange (r7540): print a newline after the summary (strgen).
Darkvater
parents: 5360
diff changeset
  1402
			fprintf(stdout, "%d warnings and %d errors for %s\n", _warnings, _errors, pathbuf);
5360
d87dfdb62e5a (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
  1403
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1404
	} else {
4370
5beb8896ae3d (svn r6089) -Backport r6088: added -s (source) and -d (destination) to strgen (Darkvater)
truelight
parents: 4344
diff changeset
  1405
		fprintf(stderr, "Invalid arguments\n");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1406
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1407
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1408
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1409
}