2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2005-04-24 15:41:01 +00:00
|
|
|
#define STRGEN
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "../stdafx.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#if !defined(WIN32) || defined(__CYGWIN__)
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2004-09-08 15:01:12 +00:00
|
|
|
#ifdef __MORPHOS__
|
|
|
|
#ifdef stderr
|
|
|
|
#undef stderr
|
|
|
|
#endif
|
|
|
|
#define stderr stdout
|
|
|
|
#endif // __MORPHOS__
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
/* Compiles a list of strings into a compiled string list */
|
|
|
|
|
|
|
|
typedef void (*ParseCmdProc)(char *buf, int value);
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint32 ident;
|
|
|
|
uint32 version; // 32-bits of auto generated version info which is basically a hash of strings.h
|
|
|
|
char name[32]; // the international name of this language
|
|
|
|
char own_name[32]; // the localized name of this language
|
2005-02-17 07:49:31 +00:00
|
|
|
char isocode[16]; // the ISO code for the language (not country code)
|
2004-08-09 17:04:08 +00:00
|
|
|
uint16 offsets[32]; // the offsets
|
2005-07-16 17:12:32 +00:00
|
|
|
byte plural_form; // plural form index
|
|
|
|
byte pad[3]; // pad header to be a multiple of 4
|
2004-08-09 17:04:08 +00:00
|
|
|
} LanguagePackHeader;
|
|
|
|
|
|
|
|
typedef struct CmdStruct {
|
|
|
|
const char *cmd;
|
|
|
|
ParseCmdProc proc;
|
|
|
|
long value;
|
2005-07-15 14:53:44 +00:00
|
|
|
int8 consumes;
|
2005-07-17 10:18:23 +00:00
|
|
|
byte flags;
|
2004-08-09 17:04:08 +00:00
|
|
|
} CmdStruct;
|
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
enum {
|
|
|
|
C_DONTCOUNT = 1,
|
|
|
|
C_CASE = 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct Case {
|
|
|
|
int caseidx;
|
|
|
|
char *string;
|
|
|
|
struct Case *next;
|
|
|
|
} Case;
|
|
|
|
|
2005-07-15 07:48:17 +00:00
|
|
|
static int _cur_line;
|
2005-07-15 14:53:44 +00:00
|
|
|
static int _errors, _warnings;
|
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
typedef struct LangString {
|
|
|
|
char *name; // Name of the string
|
|
|
|
char *english; // English text
|
|
|
|
char *translated; // Translated text
|
|
|
|
uint16 hash_next; // next hash entry
|
|
|
|
uint16 index;
|
|
|
|
Case *english_case; // cases for english
|
|
|
|
Case *translated_case; // cases for foreign
|
|
|
|
} LangString;
|
|
|
|
|
|
|
|
static LangString *_strings[65536];
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
|
|
|
|
#define HASH_SIZE 32767
|
|
|
|
static uint16 _hash_head[HASH_SIZE];
|
|
|
|
|
|
|
|
static byte _put_buf[4096];
|
|
|
|
static int _put_pos;
|
|
|
|
static int _next_string_id;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-15 07:48:17 +00:00
|
|
|
static uint32 _hash;
|
2005-07-15 14:53:44 +00:00
|
|
|
static char _lang_name[32], _lang_ownname[32], _lang_isocode[16];
|
2005-07-16 17:12:32 +00:00
|
|
|
static byte _lang_pluralform;
|
2005-07-17 10:18:23 +00:00
|
|
|
#define MAX_NUM_GENDER 8
|
|
|
|
static char _genders[MAX_NUM_GENDER][8];
|
2005-07-16 20:58:04 +00:00
|
|
|
static int _numgenders;
|
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
// contains the name of all cases.
|
|
|
|
#define MAX_NUM_CASES 50
|
|
|
|
static char _cases[MAX_NUM_CASES][16];
|
|
|
|
static int _numcases;
|
|
|
|
|
2005-07-16 17:12:32 +00:00
|
|
|
// for each plural value, this is the number of plural forms.
|
|
|
|
static const byte _plural_form_counts[] = { 2,1,2,3,3,3,3,3,4 };
|
|
|
|
|
|
|
|
static const char *_cur_ident;
|
2005-07-15 07:48:17 +00:00
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
typedef struct CmdPair {
|
|
|
|
const CmdStruct *a;
|
|
|
|
char *v;
|
|
|
|
} CmdPair;
|
|
|
|
|
|
|
|
typedef struct ParsedCommandStruct {
|
|
|
|
int np;
|
|
|
|
CmdPair pairs[32];
|
|
|
|
const CmdStruct *cmd[32]; // ordered by param #
|
|
|
|
} ParsedCommandStruct;
|
|
|
|
|
|
|
|
// Used when generating some advanced commands.
|
|
|
|
static ParsedCommandStruct _cur_pcs;
|
|
|
|
static int _cur_argidx;
|
|
|
|
|
2005-07-15 07:48:17 +00:00
|
|
|
static uint HashStr(const char *s)
|
|
|
|
{
|
|
|
|
uint hash = 0;
|
2005-07-15 14:53:44 +00:00
|
|
|
for(; *s; s++)
|
|
|
|
hash = ((hash << 3) | (hash >> 29)) ^ *s;
|
2004-08-09 17:04:08 +00:00
|
|
|
return hash % HASH_SIZE;
|
|
|
|
}
|
2005-07-15 07:48:17 +00:00
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
static void HashAdd(const char *s, LangString *ls)
|
2005-07-15 07:48:17 +00:00
|
|
|
{
|
|
|
|
uint hash = HashStr(s);
|
2005-07-17 10:18:23 +00:00
|
|
|
ls->hash_next = _hash_head[hash];
|
|
|
|
_hash_head[hash] = ls->index + 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
static LangString *HashFind(const char *s)
|
2005-07-15 07:48:17 +00:00
|
|
|
{
|
2005-07-15 14:53:44 +00:00
|
|
|
int idx = _hash_head[HashStr(s)];
|
|
|
|
while (--idx >= 0) {
|
2005-07-17 10:18:23 +00:00
|
|
|
LangString *ls = _strings[idx];
|
|
|
|
if (!strcmp(ls->name, s)) return ls;
|
|
|
|
idx = ls->hash_next;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-07-17 10:18:23 +00:00
|
|
|
return NULL;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
|
|
|
|
static void CDECL Warning(const char *s, ...)
|
2005-07-15 07:48:17 +00:00
|
|
|
{
|
2004-08-09 17:04:08 +00:00
|
|
|
char buf[1024];
|
|
|
|
va_list va;
|
|
|
|
va_start(va, s);
|
|
|
|
vsprintf(buf, s, va);
|
|
|
|
va_end(va);
|
2005-07-15 17:59:55 +00:00
|
|
|
fprintf(stderr, "Warning:(%d): %s\n", _cur_line, buf);
|
2005-07-15 14:53:44 +00:00
|
|
|
_warnings++;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
|
|
|
|
static void CDECL Error(const char *s, ...)
|
|
|
|
{
|
|
|
|
char buf[1024];
|
|
|
|
va_list va;
|
|
|
|
va_start(va, s);
|
|
|
|
vsprintf(buf, s, va);
|
|
|
|
va_end(va);
|
2005-07-15 17:59:55 +00:00
|
|
|
fprintf(stderr, "Error:(%d): %s\n", _cur_line, buf);
|
2005-07-15 14:53:44 +00:00
|
|
|
_errors++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void NORETURN CDECL Fatal(const char *s, ...)
|
2005-07-15 07:48:17 +00:00
|
|
|
{
|
2004-08-09 17:04:08 +00:00
|
|
|
char buf[1024];
|
|
|
|
va_list va;
|
|
|
|
va_start(va, s);
|
|
|
|
vsprintf(buf, s, va);
|
|
|
|
va_end(va);
|
|
|
|
fprintf(stderr, "%d: FATAL: %s\n", _cur_line, buf);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
|
2005-07-15 07:48:17 +00:00
|
|
|
static void ttd_strlcpy(char *dst, const char *src, size_t len)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
assert(len > 0);
|
|
|
|
while (--len && *src)
|
|
|
|
*dst++=*src++;
|
|
|
|
*dst = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
static void PutByte(byte c)
|
2005-07-15 07:48:17 +00:00
|
|
|
{
|
2004-08-09 17:04:08 +00:00
|
|
|
if (_put_pos == lengthof(_put_buf))
|
2005-07-15 14:53:44 +00:00
|
|
|
Fatal("Put buffer too small");
|
2004-08-09 17:04:08 +00:00
|
|
|
_put_buf[_put_pos++] = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-15 07:48:17 +00:00
|
|
|
static void EmitSingleByte(char *buf, int value)
|
|
|
|
{
|
2005-07-15 14:53:44 +00:00
|
|
|
if (*buf != '\0')
|
|
|
|
Warning("Ignoring trailing letters in command");
|
|
|
|
PutByte((byte)value);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
|
2005-07-15 07:48:17 +00:00
|
|
|
static void EmitEscapedByte(char *buf, int value)
|
|
|
|
{
|
2005-07-15 14:53:44 +00:00
|
|
|
if (*buf != '\0')
|
|
|
|
Warning("Ignoring trailing letters in command");
|
|
|
|
PutByte((byte)0x85);
|
|
|
|
PutByte((byte)value);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-07-15 07:48:17 +00:00
|
|
|
static void EmitSetX(char *buf, int value)
|
|
|
|
{
|
2004-08-09 17:04:08 +00:00
|
|
|
char *err;
|
|
|
|
int x = strtol(buf, &err, 0);
|
2005-07-15 14:53:44 +00:00
|
|
|
if (*err != 0)
|
|
|
|
Fatal("SetX param invalid");
|
|
|
|
PutByte(1);
|
|
|
|
PutByte((byte)x);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
|
2005-07-15 07:48:17 +00:00
|
|
|
static void EmitSetXY(char *buf, int value)
|
|
|
|
{
|
2004-08-09 17:04:08 +00:00
|
|
|
char *err;
|
2005-07-15 14:53:44 +00:00
|
|
|
int x,y;
|
2005-07-15 07:48:17 +00:00
|
|
|
|
|
|
|
x = strtol(buf, &err, 0);
|
2005-07-16 17:12:32 +00:00
|
|
|
if (*err != ' ') Fatal("SetXY param invalid");
|
2005-07-15 14:53:44 +00:00
|
|
|
y = strtol(err+1, &err, 0);
|
|
|
|
if (*err != 0) Fatal("SetXY param invalid");
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
PutByte(2);
|
2005-07-15 14:53:44 +00:00
|
|
|
PutByte((byte)x);
|
|
|
|
PutByte((byte)y);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-07-16 17:12:32 +00:00
|
|
|
// The plural specifier looks like
|
|
|
|
// {NUM} {PLURAL -1 passenger passengers} then it picks either passenger/passengers depending on the count in NUM
|
|
|
|
|
|
|
|
// This is encoded like
|
|
|
|
// CommandByte <ARG#> <NUM> {Length of each string} {each string}
|
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
bool ParseRelNum(char **buf, int *value)
|
2005-07-16 17:12:32 +00:00
|
|
|
{
|
|
|
|
char *s = *buf, *end;
|
|
|
|
bool rel = false;
|
2005-07-17 10:18:23 +00:00
|
|
|
int v;
|
|
|
|
|
2005-07-16 17:12:32 +00:00
|
|
|
while (*s == ' ' || *s == '\t') s++;
|
|
|
|
if (*s == '+') { rel = true; s++; }
|
2005-07-17 10:18:23 +00:00
|
|
|
v = strtol(s, &end, 0);
|
2005-07-16 17:12:32 +00:00
|
|
|
if (end == s) return false;
|
2005-07-17 10:18:23 +00:00
|
|
|
if (rel || (v < 0))
|
|
|
|
*value += v;
|
|
|
|
else
|
|
|
|
*value = v;
|
2005-07-16 17:12:32 +00:00
|
|
|
*buf = end;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse out the next word, or NULL
|
|
|
|
char *ParseWord(char **buf)
|
|
|
|
{
|
|
|
|
char *s = *buf, *r;
|
|
|
|
while (*s == ' ' || *s == '\t') s++;
|
|
|
|
if (*s == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (*s == '"') {
|
|
|
|
r = ++s;
|
|
|
|
// parse until next " or NUL
|
|
|
|
for(;;) {
|
|
|
|
if (*s == 0)
|
|
|
|
break;
|
|
|
|
if (*s == '"') {
|
|
|
|
*s++ = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// proceed until whitespace or NUL
|
|
|
|
r = s;
|
|
|
|
for(;;) {
|
|
|
|
if (*s == 0)
|
|
|
|
break;
|
|
|
|
if (*s == ' ' || *s == '\t') {
|
|
|
|
*s++ = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*buf = s;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Forward declaration
|
2005-07-17 10:18:23 +00:00
|
|
|
static int TranslateArgumentIdx(int arg);
|
2005-07-16 17:12:32 +00:00
|
|
|
|
2005-07-16 20:58:04 +00:00
|
|
|
static void EmitWordList(char **words, int nw)
|
|
|
|
{
|
|
|
|
int i,j;
|
|
|
|
|
|
|
|
PutByte(nw);
|
|
|
|
for(i=0; i<nw; i++)
|
|
|
|
PutByte(strlen(words[i]));
|
|
|
|
for(i=0; i<nw; i++) {
|
|
|
|
for(j=0; words[i][j]; j++)
|
|
|
|
PutByte(words[i][j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-16 17:12:32 +00:00
|
|
|
static void EmitPlural(char *buf, int value)
|
|
|
|
{
|
2005-07-17 10:18:23 +00:00
|
|
|
int argidx = _cur_argidx;
|
2005-07-16 17:12:32 +00:00
|
|
|
char *words[5];
|
|
|
|
int nw = 0;
|
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
// Parse out the number, if one exists. Otherwise default to prev arg.
|
|
|
|
if (!ParseRelNum(&buf, &argidx))
|
|
|
|
argidx--;
|
2005-07-16 17:12:32 +00:00
|
|
|
|
|
|
|
// Parse each string
|
|
|
|
for(nw=0; nw<5; nw++) {
|
|
|
|
words[nw] = ParseWord(&buf);
|
|
|
|
if (!words[nw])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nw == 0)
|
|
|
|
Fatal("No plural words");
|
|
|
|
|
|
|
|
if (_plural_form_counts[_lang_pluralform] != nw)
|
|
|
|
Fatal("%s: Invalid number of plural forms. Expecting %d, found %d.", _cur_ident,
|
|
|
|
_plural_form_counts[_lang_pluralform], nw);
|
|
|
|
|
2005-09-10 15:14:35 +00:00
|
|
|
PutByte(0x8D);
|
2005-07-17 10:18:23 +00:00
|
|
|
PutByte(TranslateArgumentIdx(argidx));
|
2005-07-16 20:58:04 +00:00
|
|
|
EmitWordList(words, nw);
|
2005-07-16 17:12:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-16 20:58:04 +00:00
|
|
|
static void EmitGender(char *buf, int value)
|
|
|
|
{
|
2005-07-17 10:18:23 +00:00
|
|
|
int argidx = _cur_argidx;
|
2005-07-16 20:58:04 +00:00
|
|
|
char *words[8];
|
|
|
|
int nw;
|
|
|
|
|
|
|
|
if (buf[0] == '=') {
|
|
|
|
buf++;
|
|
|
|
|
|
|
|
// This is a {G=DER} command
|
|
|
|
for(nw=0; ;nw++) {
|
|
|
|
if (nw >= 8)
|
|
|
|
Fatal("G argument '%s' invalid", buf);
|
|
|
|
if (!strcmp(buf, _genders[nw]))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// now nw contains the gender index
|
|
|
|
PutByte(0x87);
|
|
|
|
PutByte(nw);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// This is a {G 0 foo bar two} command.
|
2005-07-17 10:18:23 +00:00
|
|
|
// If no relative number exists, default to +0
|
|
|
|
if (!ParseRelNum(&buf, &argidx)) {}
|
2005-07-16 20:58:04 +00:00
|
|
|
|
|
|
|
for(nw=0; nw<8; nw++) {
|
|
|
|
words[nw] = ParseWord(&buf);
|
|
|
|
if (!words[nw])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (nw != _numgenders) Fatal("Bad # of arguments for gender command");
|
|
|
|
PutByte(0x85);
|
|
|
|
PutByte(13);
|
2005-07-17 10:18:23 +00:00
|
|
|
PutByte(TranslateArgumentIdx(argidx));
|
2005-07-16 20:58:04 +00:00
|
|
|
EmitWordList(words, nw);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static const CmdStruct _cmd_structs[] = {
|
|
|
|
// Update position
|
2005-07-15 14:53:44 +00:00
|
|
|
{"SETX", EmitSetX, 1, 0},
|
|
|
|
{"SETXY", EmitSetXY, 2, 0},
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// Font size
|
2005-07-15 14:53:44 +00:00
|
|
|
{"TINYFONT", EmitSingleByte, 8, 0},
|
|
|
|
{"BIGFONT", EmitSingleByte, 9, 0},
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// New line
|
2005-07-17 10:18:23 +00:00
|
|
|
{"", EmitSingleByte, 10, 0, C_DONTCOUNT},
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-09-10 15:52:19 +00:00
|
|
|
{"{", EmitSingleByte, '{', 0, C_DONTCOUNT},
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// Colors
|
2005-07-15 14:53:44 +00:00
|
|
|
{"BLUE", EmitSingleByte, 15, 0},
|
|
|
|
{"SILVER", EmitSingleByte, 16, 0},
|
|
|
|
{"GOLD", EmitSingleByte, 17, 0},
|
|
|
|
{"RED", EmitSingleByte, 18, 0},
|
|
|
|
{"PURPLE", EmitSingleByte, 19, 0},
|
|
|
|
{"LTBROWN", EmitSingleByte, 20, 0},
|
|
|
|
{"ORANGE", EmitSingleByte, 21, 0},
|
|
|
|
{"GREEN", EmitSingleByte, 22, 0},
|
|
|
|
{"YELLOW", EmitSingleByte, 23, 0},
|
|
|
|
{"DKGREEN", EmitSingleByte, 24, 0},
|
|
|
|
{"CREAM", EmitSingleByte, 25, 0},
|
|
|
|
{"BROWN", EmitSingleByte, 26, 0},
|
|
|
|
{"WHITE", EmitSingleByte, 27, 0},
|
|
|
|
{"LTBLUE", EmitSingleByte, 28, 0},
|
|
|
|
{"GRAY", EmitSingleByte, 29, 0},
|
|
|
|
{"DKBLUE", EmitSingleByte, 30, 0},
|
|
|
|
{"BLACK", EmitSingleByte, 31, 0},
|
2004-09-12 21:49:38 +00:00
|
|
|
|
2004-09-13 20:38:36 +00:00
|
|
|
// 0x85
|
2005-07-15 14:53:44 +00:00
|
|
|
{"CURRCOMPACT", EmitEscapedByte, 0, 1}, // compact currency (32 bits)
|
|
|
|
{"REV", EmitEscapedByte, 2, 0}, // openttd revision string
|
|
|
|
{"SHORTCARGO", EmitEscapedByte, 3, 2}, // short cargo description, only ### tons, or ### litres
|
|
|
|
{"CURRCOMPACT64", EmitEscapedByte, 4, 2}, // compact currency 64 bits
|
|
|
|
|
|
|
|
{"COMPANY", EmitEscapedByte, 5, 1}, // company string. This is actually a {STRING1}
|
|
|
|
// The first string includes the second string.
|
|
|
|
|
|
|
|
{"PLAYERNAME", EmitEscapedByte, 5, 1}, // playername string. This is actually a {STRING1}
|
|
|
|
// The first string includes the second string.
|
|
|
|
|
|
|
|
{"VEHICLE", EmitEscapedByte, 5, 1}, // playername string. This is actually a {STRING1}
|
|
|
|
// The first string includes the second string.
|
|
|
|
|
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
{"STRING1", EmitEscapedByte, 5, 1, C_CASE}, // included string that consumes ONE argument
|
|
|
|
{"STRING2", EmitEscapedByte, 6, 2, C_CASE}, // included string that consumes TWO arguments
|
|
|
|
{"STRING3", EmitEscapedByte, 7, 3, C_CASE}, // included string that consumes THREE arguments
|
|
|
|
{"STRING4", EmitEscapedByte, 8, 4, C_CASE}, // included string that consumes FOUR arguments
|
|
|
|
{"STRING5", EmitEscapedByte, 9, 5, C_CASE}, // included string that consumes FIVE arguments
|
2005-07-15 14:53:44 +00:00
|
|
|
|
|
|
|
{"STATIONFEATURES", EmitEscapedByte, 10, 1}, // station features string, icons of the features
|
2005-07-15 17:59:55 +00:00
|
|
|
{"INDUSTRY", EmitEscapedByte, 11, 1}, // industry, takes an industry #
|
2005-07-16 20:58:04 +00:00
|
|
|
{"VOLUME", EmitEscapedByte, 12, 1},
|
2005-07-17 10:18:23 +00:00
|
|
|
{"DATE_TINY", EmitEscapedByte, 14, 1},
|
|
|
|
{"CARGO", EmitEscapedByte, 15, 2},
|
2004-09-12 21:49:38 +00:00
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
{"P", EmitPlural, 0, 0, C_DONTCOUNT}, // plural specifier
|
|
|
|
{"G", EmitGender, 0, 0, C_DONTCOUNT}, // gender specifier
|
2005-07-16 17:12:32 +00:00
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
{"DATE_LONG", EmitSingleByte, 0x82, 1},
|
|
|
|
{"DATE_SHORT", EmitSingleByte, 0x83, 1},
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
{"VELOCITY", EmitSingleByte, 0x84, 1},
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
{"SKIP", EmitSingleByte, 0x86, 1},
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
{"STRING", EmitSingleByte, 0x88, 1, C_CASE},
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-09-10 15:14:35 +00:00
|
|
|
// Numbers
|
|
|
|
{"COMMA", EmitSingleByte, 0x8B, 1}, // Number with comma
|
|
|
|
{"NUM", EmitSingleByte, 0x8E, 1}, // Signed number
|
|
|
|
|
|
|
|
{"CURRENCY", EmitSingleByte, 0x8F, 1},
|
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
{"WAYPOINT", EmitSingleByte, 0x99, 1}, // waypoint name
|
2005-07-15 14:53:44 +00:00
|
|
|
{"STATION", EmitSingleByte, 0x9A, 1},
|
|
|
|
{"TOWN", EmitSingleByte, 0x9B, 1},
|
|
|
|
{"CURRENCY64", EmitSingleByte, 0x9C, 2},
|
2005-07-17 10:18:23 +00:00
|
|
|
// 0x9D is used for the pseudo command SETCASE
|
|
|
|
// 0x9E is used for case switching
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// 0x9E=158 is the LAST special character we may use.
|
|
|
|
|
2005-09-10 08:17:30 +00:00
|
|
|
{"UPARROW", EmitSingleByte, 0x80, 0},
|
|
|
|
|
|
|
|
{"NBSP", EmitSingleByte, 0xA0, 0, C_DONTCOUNT},
|
2005-07-15 14:53:44 +00:00
|
|
|
{"POUNDSIGN", EmitSingleByte, 0xA3, 0},
|
|
|
|
{"YENSIGN", EmitSingleByte, 0xA5, 0},
|
|
|
|
{"COPYRIGHT", EmitSingleByte, 0xA9, 0},
|
|
|
|
{"DOWNARROW", EmitSingleByte, 0xAA, 0},
|
|
|
|
{"CHECKMARK", EmitSingleByte, 0xAC, 0},
|
|
|
|
{"CROSS", EmitSingleByte, 0xAD, 0},
|
|
|
|
{"RIGHTARROW", EmitSingleByte, 0xAF, 0},
|
|
|
|
|
2005-08-20 18:14:32 +00:00
|
|
|
{"TRAIN", EmitSingleByte, 0x94, 0},
|
|
|
|
{"LORRY", EmitSingleByte, 0x95, 0},
|
|
|
|
{"BUS", EmitSingleByte, 0x96, 0},
|
|
|
|
{"PLANE", EmitSingleByte, 0x97, 0},
|
|
|
|
{"SHIP", EmitSingleByte, 0x98, 0},
|
|
|
|
|
|
|
|
{"SMALLUPARROW", EmitSingleByte, 0x90, 0},
|
|
|
|
{"SMALLDOWNARROW", EmitSingleByte, 0x91, 0},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
|
2005-07-15 07:48:17 +00:00
|
|
|
static const CmdStruct *FindCmd(const char *s, int len)
|
|
|
|
{
|
2005-07-15 14:53:44 +00:00
|
|
|
int i;
|
|
|
|
const CmdStruct *cs = _cmd_structs;
|
|
|
|
for(i=0; i != lengthof(_cmd_structs); i++, cs++) {
|
|
|
|
if (!strncmp(cs->cmd, s, len) && cs->cmd[len] == '\0')
|
|
|
|
return cs;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
static int ResolveCaseName(const char *str, int len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i=0; i<MAX_NUM_CASES; i++)
|
|
|
|
if (!memcmp(_cases[i], str, len) && _cases[i][len] == 0)
|
|
|
|
return i + 1;
|
|
|
|
Fatal("Invalid case-name '%s'", str);
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
// returns NULL on eof
|
|
|
|
// else returns command struct
|
2005-07-17 10:18:23 +00:00
|
|
|
static const CmdStruct *ParseCommandString(const char **str, char *param, int *argno, int *casei)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-07-17 10:18:23 +00:00
|
|
|
const char *s = *str, *start;
|
2004-08-09 17:04:08 +00:00
|
|
|
const CmdStruct *cmd;
|
2005-07-15 14:53:44 +00:00
|
|
|
int plen = 0;
|
|
|
|
byte c;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
*argno = -1;
|
2005-07-17 10:18:23 +00:00
|
|
|
*casei = -1;
|
2005-07-15 14:53:44 +00:00
|
|
|
|
|
|
|
// Scan to the next command, exit if there's no next command.
|
|
|
|
for(; *s != '{'; s++) {
|
|
|
|
if (*s == '\0')
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
s++; // Skip past the {
|
|
|
|
|
|
|
|
if (*s >= '0' && *s <= '9') {
|
|
|
|
char *end;
|
|
|
|
*argno = strtoul(s, &end, 0);
|
|
|
|
if (*end != ':') {
|
|
|
|
Fatal("missing arg #");
|
|
|
|
}
|
|
|
|
s = end + 1;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// parse command name
|
|
|
|
start = s;
|
2005-07-17 10:18:23 +00:00
|
|
|
do {
|
2004-08-09 17:04:08 +00:00
|
|
|
c = *s++;
|
2005-07-17 10:18:23 +00:00
|
|
|
} while (c != '}' && c != ' ' && c != '=' && c != '.' && c != 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-15 07:48:17 +00:00
|
|
|
cmd = FindCmd(start, s - start - 1);
|
2004-08-09 17:04:08 +00:00
|
|
|
if (cmd == NULL) {
|
2005-07-15 14:53:44 +00:00
|
|
|
Error("Undefined command '%.*s'", s - start - 1, start);
|
2004-08-09 17:04:08 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
if (c == '.') {
|
|
|
|
const char *casep = s;
|
|
|
|
|
|
|
|
if (!(cmd->flags & C_CASE))
|
|
|
|
Fatal("Command '%s' can't have a case", cmd->cmd);
|
|
|
|
|
|
|
|
do c = *s++; while (c != '}' && c != ' ' && c != '\0');
|
|
|
|
*casei = ResolveCaseName(casep, s-casep-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == '\0') {
|
|
|
|
Error("Missing } from command '%s'", start);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-16 20:58:04 +00:00
|
|
|
if (c != '}') {
|
|
|
|
if (c == '=') s--;
|
2004-08-09 17:04:08 +00:00
|
|
|
// copy params
|
|
|
|
start = s;
|
|
|
|
for(;;) {
|
|
|
|
c = *s++;
|
|
|
|
if (c == '}') break;
|
2005-07-15 14:53:44 +00:00
|
|
|
if (c == '\0') {
|
|
|
|
Error("Missing } from command '%s'", start);
|
2004-08-09 17:04:08 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2005-07-16 17:12:32 +00:00
|
|
|
if ( s - start == 250)
|
2005-07-15 14:53:44 +00:00
|
|
|
Fatal("param command too long");
|
2004-08-09 17:04:08 +00:00
|
|
|
*param++ = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*param = 0;
|
|
|
|
|
|
|
|
*str = s;
|
|
|
|
|
|
|
|
return cmd;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
static void HandlePragma(char *str)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-07-15 14:53:44 +00:00
|
|
|
if (!memcmp(str, "id ", 3)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
_next_string_id = strtoul(str + 3, NULL, 0);
|
2005-07-15 14:53:44 +00:00
|
|
|
} else if (!memcmp(str, "name ", 5)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
ttd_strlcpy(_lang_name, str + 5, sizeof(_lang_name));
|
2005-07-15 14:53:44 +00:00
|
|
|
} else if (!memcmp(str, "ownname ", 8)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
ttd_strlcpy(_lang_ownname, str + 8, sizeof(_lang_ownname));
|
2005-07-15 14:53:44 +00:00
|
|
|
} else if (!memcmp(str, "isocode ", 8)) {
|
2005-02-17 07:49:31 +00:00
|
|
|
ttd_strlcpy(_lang_isocode, str + 8, sizeof(_lang_isocode));
|
2005-07-16 17:12:32 +00:00
|
|
|
} else if (!memcmp(str, "plural ", 7)) {
|
|
|
|
_lang_pluralform = atoi(str + 7);
|
|
|
|
if (_lang_pluralform >= lengthof(_plural_form_counts))
|
|
|
|
Fatal("Invalid pluralform %d", _lang_pluralform);
|
2005-07-16 20:58:04 +00:00
|
|
|
} else if (!memcmp(str, "gender ", 7)) {
|
|
|
|
char *buf = str + 7, *s;
|
2005-07-17 10:18:23 +00:00
|
|
|
for(;;) {
|
2005-07-16 20:58:04 +00:00
|
|
|
s = ParseWord(&buf);
|
|
|
|
if (!s) break;
|
2005-07-17 10:18:23 +00:00
|
|
|
if (_numgenders >= MAX_NUM_GENDER) Fatal("Too many genders, max %d", MAX_NUM_GENDER);
|
|
|
|
ttd_strlcpy(_genders[_numgenders], s, sizeof(_genders[_numgenders]));
|
2005-07-16 20:58:04 +00:00
|
|
|
_numgenders++;
|
|
|
|
}
|
2005-07-17 10:18:23 +00:00
|
|
|
} else if (!memcmp(str, "case ", 5)) {
|
|
|
|
char *buf = str + 5, *s;
|
|
|
|
for(;;) {
|
|
|
|
s = ParseWord(&buf);
|
|
|
|
if (!s) break;
|
|
|
|
if (_numcases >= MAX_NUM_CASES) Fatal("Too many cases, max %d", MAX_NUM_CASES);
|
|
|
|
ttd_strlcpy(_cases[_numcases], s, sizeof(_cases[_numcases]));
|
|
|
|
_numcases++;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2005-07-15 14:53:44 +00:00
|
|
|
Fatal("unknown pragma '%s'", str);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
static void ExtractCommandString(ParsedCommandStruct *p, char *s, bool warnings)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-07-15 07:48:17 +00:00
|
|
|
const CmdStruct *ar;
|
2004-08-09 17:04:08 +00:00
|
|
|
char param[100];
|
2005-07-15 14:53:44 +00:00
|
|
|
int argno;
|
|
|
|
int argidx = 0;
|
2005-07-17 10:18:23 +00:00
|
|
|
int casei;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
memset(p, 0, sizeof(*p));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
for(;;) {
|
|
|
|
// read until next command from a.
|
2005-07-17 18:11:17 +00:00
|
|
|
ar = ParseCommandString((const char **)&s, param, &argno, &casei);
|
2005-07-15 14:53:44 +00:00
|
|
|
if (ar == NULL)
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
// Sanity checking
|
|
|
|
if (argno != -1 && !ar->consumes) Fatal("Non consumer param can't have a paramindex");
|
|
|
|
|
|
|
|
if (ar->consumes) {
|
|
|
|
if (argno != -1)
|
|
|
|
argidx = argno;
|
|
|
|
if (argidx < 0 || argidx >= lengthof(p->cmd)) Fatal("invalid param idx %d", argidx);
|
|
|
|
if (p->cmd[argidx] != NULL && p->cmd[argidx] != ar) Fatal("duplicate param idx %d", argidx);
|
|
|
|
|
|
|
|
p->cmd[argidx++] = ar;
|
2005-07-17 10:18:23 +00:00
|
|
|
} else if (!(ar->flags & C_DONTCOUNT)) { // Ignore some of them
|
2005-07-15 14:53:44 +00:00
|
|
|
if (p->np >= lengthof(p->pairs)) Fatal("too many commands in string, max %d", lengthof(p->pairs));
|
|
|
|
p->pairs[p->np].a = ar;
|
|
|
|
p->pairs[p->np].v = param[0]?strdup(param):"";
|
|
|
|
p->np++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const CmdStruct *TranslateCmdForCompare(const CmdStruct *a)
|
|
|
|
{
|
|
|
|
if (!a) return NULL;
|
|
|
|
|
|
|
|
if (!strcmp(a->cmd, "STRING1") ||
|
|
|
|
!strcmp(a->cmd, "STRING2") ||
|
|
|
|
!strcmp(a->cmd, "STRING3") ||
|
|
|
|
!strcmp(a->cmd, "STRING4") ||
|
|
|
|
!strcmp(a->cmd, "STRING5"))
|
|
|
|
return FindCmd("STRING", 6);
|
|
|
|
|
|
|
|
if (!strcmp(a->cmd, "SKIP"))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return a;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
|
2005-07-15 17:59:55 +00:00
|
|
|
static bool CheckCommandsMatch(char *a, char *b, const char *name)
|
2005-07-15 07:48:17 +00:00
|
|
|
{
|
2005-07-15 14:53:44 +00:00
|
|
|
ParsedCommandStruct templ;
|
|
|
|
ParsedCommandStruct lang;
|
|
|
|
int i,j;
|
|
|
|
bool result = true;
|
|
|
|
|
|
|
|
ExtractCommandString(&templ, b, true);
|
|
|
|
ExtractCommandString(&lang, a, true);
|
|
|
|
|
|
|
|
// For each string in templ, see if we find it in lang
|
|
|
|
if (templ.np != lang.np) {
|
2005-07-15 17:59:55 +00:00
|
|
|
Warning("%s: template string and language string have a different # of commands", name);
|
2005-07-15 14:53:44 +00:00
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < templ.np; i++) {
|
|
|
|
// see if we find it in lang, and zero it out
|
|
|
|
bool found = false;
|
|
|
|
for(j = 0; j < lang.np; j++) {
|
|
|
|
if (templ.pairs[i].a == lang.pairs[j].a &&
|
|
|
|
!strcmp(templ.pairs[i].v, lang.pairs[j].v)) {
|
|
|
|
// it was found in both. zero it out from lang so we don't find it again
|
|
|
|
lang.pairs[j].a = NULL;
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
2005-07-15 17:59:55 +00:00
|
|
|
Warning("%s: command '%s' exists in template file but not in language file", name, templ.pairs[i].a->cmd);
|
2005-07-15 14:53:44 +00:00
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we reach here, all non consumer commands match up.
|
|
|
|
// Check if the non consumer commands match up also.
|
|
|
|
for(i = 0; i < lengthof(templ.cmd); i++) {
|
|
|
|
if (TranslateCmdForCompare(templ.cmd[i]) != TranslateCmdForCompare(lang.cmd[i])) {
|
2005-07-15 17:59:55 +00:00
|
|
|
Warning("%s: Param idx #%d '%s' doesn't match with template command '%s'", name, i,
|
2005-07-15 14:53:44 +00:00
|
|
|
!lang.cmd[i] ? "<empty>" : lang.cmd[i]->cmd,
|
|
|
|
!templ.cmd[i] ? "<empty>" : templ.cmd[i]->cmd);
|
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void HandleString(char *str, bool master)
|
|
|
|
{
|
|
|
|
char *s,*t;
|
2005-07-17 10:18:23 +00:00
|
|
|
LangString *ent;
|
|
|
|
char *casep;
|
2004-09-12 21:49:38 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (*str == '#') {
|
|
|
|
if (str[1] == '#' && str[2] != '#')
|
2005-07-15 14:53:44 +00:00
|
|
|
HandlePragma(str + 2);
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore comments & blank lines
|
2005-07-15 07:48:17 +00:00
|
|
|
if (*str == ';' || *str == ' ' || *str == '\0')
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
s = strchr(str, ':');
|
|
|
|
if (s == NULL) {
|
2005-07-15 14:53:44 +00:00
|
|
|
Error("Line has no ':' delimiter");
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
// Trim spaces.
|
|
|
|
// After this str points to the command name, and s points to the command contents
|
|
|
|
for(t = s; t > str && (t[-1]==' ' || t[-1]=='\t'); t--);
|
|
|
|
*t = 0;
|
|
|
|
s++;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
// Check if the string has a case..
|
|
|
|
// The syntax for cases is IDENTNAME.case
|
|
|
|
casep = strchr(str, '.');
|
|
|
|
if (casep) *casep++ = 0;
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
// Check if this string already exists..
|
2005-07-15 07:48:17 +00:00
|
|
|
ent = HashFind(str);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (master) {
|
2005-07-17 10:18:23 +00:00
|
|
|
if (ent != NULL && !casep) {
|
2005-07-15 14:53:44 +00:00
|
|
|
Error("String name '%s' is used multiple times", str);
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
if (ent == NULL && casep) {
|
|
|
|
Error("Base string name '%s' doesn't exist yet. Define it before defining a case.", str);
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
if (ent == NULL) {
|
|
|
|
if (_strings[_next_string_id]) {
|
|
|
|
Error("String ID 0x%X for '%s' already in use by '%s'", ent, str, _strings[_next_string_id]->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate a new LangString
|
|
|
|
ent = calloc(sizeof(LangString), 1);
|
|
|
|
_strings[_next_string_id] = ent;
|
|
|
|
ent->index = _next_string_id++;
|
|
|
|
ent->name = strdup(str);
|
|
|
|
|
|
|
|
HashAdd(str, ent);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (casep) {
|
|
|
|
Case *c = malloc(sizeof(Case));
|
|
|
|
c->caseidx = ResolveCaseName(casep, strlen(casep));
|
|
|
|
c->string = strdup(s);
|
|
|
|
c->next = ent->english_case;
|
|
|
|
ent->english_case = c;
|
|
|
|
} else {
|
|
|
|
ent->english = strdup(s);
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2005-07-17 10:18:23 +00:00
|
|
|
if (ent == NULL) {
|
2005-07-15 17:59:55 +00:00
|
|
|
Warning("String name '%s' does not exist in master file", str);
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
if (ent->translated && !casep) {
|
2005-07-15 14:53:44 +00:00
|
|
|
Error("String name '%s' is used multiple times", str);
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
if (s[0] == ':' && s[1] == '\0' && casep == NULL) {
|
2005-07-15 14:53:44 +00:00
|
|
|
// Special syntax :: means we should just inherit the master string
|
2005-07-17 10:18:23 +00:00
|
|
|
ent->translated = strdup(ent->english);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2005-07-17 10:18:23 +00:00
|
|
|
// make sure that the commands match
|
|
|
|
if (!CheckCommandsMatch(s, ent->english, str))
|
2005-07-15 14:53:44 +00:00
|
|
|
return;
|
2005-07-17 10:18:23 +00:00
|
|
|
|
|
|
|
if (casep) {
|
|
|
|
Case *c = malloc(sizeof(Case));
|
|
|
|
c->caseidx = ResolveCaseName(casep, strlen(casep));
|
|
|
|
c->string = strdup(s);
|
|
|
|
c->next = ent->translated_case;
|
|
|
|
ent->translated_case = c;
|
|
|
|
} else {
|
|
|
|
ent->translated = strdup(s);
|
2005-07-15 14:53:44 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-12 21:49:38 +00:00
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
static void rstrip(char *buf)
|
|
|
|
{
|
|
|
|
int i = strlen(buf);
|
|
|
|
while (i>0 && (buf[i-1]=='\r' || buf[i-1]=='\n' || buf[i-1] == ' ')) i--;
|
|
|
|
buf[i] = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
|
|
|
|
static void ParseFile(const char *file, bool english)
|
2005-07-15 07:48:17 +00:00
|
|
|
{
|
2004-08-09 17:04:08 +00:00
|
|
|
FILE *in;
|
2005-07-15 14:53:44 +00:00
|
|
|
char buf[2048];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
// For each new file we parse, reset the genders.
|
|
|
|
_numgenders = 0;
|
|
|
|
// TODO:!! We can't reset the cases. In case the translated strings
|
|
|
|
// derive some strings from english....
|
|
|
|
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
in = fopen(file, "r");
|
2005-07-15 14:53:44 +00:00
|
|
|
if (in == NULL) { Fatal("Cannot open file '%s'", file); }
|
2004-08-09 17:04:08 +00:00
|
|
|
_cur_line = 1;
|
|
|
|
while (fgets(buf, sizeof(buf),in) != NULL) {
|
2005-07-15 14:53:44 +00:00
|
|
|
rstrip(buf);
|
|
|
|
HandleString(buf, english);
|
2004-08-09 17:04:08 +00:00
|
|
|
_cur_line++;
|
|
|
|
}
|
|
|
|
fclose(in);
|
2005-07-15 14:53:44 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-15 07:48:17 +00:00
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
static uint32 MyHashStr(uint32 hash, const char *s)
|
|
|
|
{
|
|
|
|
for(; *s; s++) {
|
|
|
|
hash = ((hash << 3) | (hash >> 29)) ^ *s;
|
|
|
|
if (hash & 1) hash = (hash>>1) ^ 0xDEADBEEF; else hash >>= 1;
|
|
|
|
}
|
|
|
|
return hash;
|
|
|
|
}
|
2005-07-15 07:48:17 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
// make a hash of the file to get a unique "version number"
|
|
|
|
static void MakeHashOfStrings()
|
|
|
|
{
|
|
|
|
uint32 hash = 0;
|
2005-07-17 10:18:23 +00:00
|
|
|
LangString *ls;
|
2005-07-15 14:53:44 +00:00
|
|
|
char *s;
|
|
|
|
const CmdStruct *cs;
|
2005-07-16 17:12:32 +00:00
|
|
|
char buf[256];
|
2005-07-15 14:53:44 +00:00
|
|
|
int i;
|
|
|
|
int argno;
|
2005-07-17 10:18:23 +00:00
|
|
|
int casei;
|
2005-07-15 14:53:44 +00:00
|
|
|
|
|
|
|
for(i = 0; i != 65536; i++) {
|
2005-07-17 10:18:23 +00:00
|
|
|
if ((ls=_strings[i]) != NULL) {
|
|
|
|
s = ls->name;
|
2005-07-15 14:53:44 +00:00
|
|
|
hash ^= i * 0x717239;
|
|
|
|
if (hash & 1) hash = (hash>>1) ^ 0xDEADBEEF; else hash >>= 1;
|
|
|
|
hash = MyHashStr(hash, s + 1);
|
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
s = ls->english;
|
2005-07-17 18:11:17 +00:00
|
|
|
while ((cs = ParseCommandString((const char **)&s, buf, &argno, &casei)) != NULL) {
|
2005-07-17 10:18:23 +00:00
|
|
|
if (cs->flags & C_DONTCOUNT)
|
|
|
|
continue;
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
hash ^= (cs - _cmd_structs) * 0x1234567;
|
|
|
|
if (hash & 1) hash = (hash>>1) ^ 0xF00BAA4; else hash >>= 1;
|
2004-09-12 21:49:38 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2005-07-15 14:53:44 +00:00
|
|
|
_hash = hash;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
|
|
|
|
static int CountInUse(int grp)
|
2005-07-15 07:48:17 +00:00
|
|
|
{
|
2004-08-09 17:04:08 +00:00
|
|
|
int i;
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
for(i = 0x800; --i >= 0;) {
|
2005-07-17 10:18:23 +00:00
|
|
|
if (_strings[(grp<<11)+i] != NULL)
|
2005-07-15 14:53:44 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
return i + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
bool CompareFiles(const char *n1, const char *n2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
FILE *f1, *f2;
|
|
|
|
char b1[4096];
|
|
|
|
char b2[4096];
|
|
|
|
size_t l1, l2;
|
|
|
|
|
|
|
|
f2 = fopen(n2, "rb");
|
|
|
|
if (f2 == NULL) return false;
|
|
|
|
|
|
|
|
f1 = fopen(n1, "rb");
|
2005-07-15 14:53:44 +00:00
|
|
|
if (f1 == NULL) Fatal("can't open %s", n1);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
l1 = fread(b1, 1, sizeof(b1), f1);
|
|
|
|
l2 = fread(b2, 1, sizeof(b2), f2);
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
if (l1 != l2 || memcmp(b1, b2, l1)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
fclose(f2);
|
|
|
|
fclose(f1);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} while (l1);
|
|
|
|
|
|
|
|
fclose(f2);
|
|
|
|
fclose(f1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
|
|
|
|
static void WriteStringsH(const char *filename)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
FILE *out;
|
|
|
|
int i;
|
|
|
|
int next = -1;
|
|
|
|
int lastgrp;
|
|
|
|
|
|
|
|
out = fopen("tmp.xxx", "w");
|
2005-07-15 14:53:44 +00:00
|
|
|
if (out == NULL) { Fatal("can't open tmp.xxx"); }
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
fprintf(out, "enum {");
|
|
|
|
|
|
|
|
lastgrp = 0;
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
for(i = 0; i != 65536; i++) {
|
2005-07-17 10:18:23 +00:00
|
|
|
if (_strings[i]) {
|
2004-08-09 17:04:08 +00:00
|
|
|
if (lastgrp != (i >> 11)) {
|
|
|
|
lastgrp = (i >> 11);
|
|
|
|
fprintf(out, "};\n\nenum {");
|
|
|
|
}
|
2004-09-12 21:49:38 +00:00
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
fprintf(out, next == i ? "%s,\n" : "\n%s = 0x%X,\n", _strings[i]->name, i);
|
2004-08-09 17:04:08 +00:00
|
|
|
next = i + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(out, "};\n");
|
|
|
|
|
2004-09-12 21:49:38 +00:00
|
|
|
fprintf(out,
|
2004-08-09 17:04:08 +00:00
|
|
|
"\nenum {\n"
|
2004-09-08 15:01:12 +00:00
|
|
|
"\tLANGUAGE_PACK_IDENT = 0x474E414C, // Big Endian value for 'LANG' (LE is 0x 4C 41 4E 47)\n"
|
2004-08-09 17:04:08 +00:00
|
|
|
"\tLANGUAGE_PACK_VERSION = 0x%X,\n"
|
2005-07-15 07:48:17 +00:00
|
|
|
"};\n", (uint)_hash);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
fclose(out);
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
if (CompareFiles("tmp.xxx", filename)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
// files are equal. tmp.xxx is not needed
|
|
|
|
unlink("tmp.xxx");
|
|
|
|
} else {
|
|
|
|
// else rename tmp.xxx into filename
|
|
|
|
#if defined(WIN32)
|
|
|
|
unlink(filename);
|
|
|
|
#endif
|
2005-07-15 14:53:44 +00:00
|
|
|
if (rename("tmp.xxx", filename) == -1) Fatal("rename() failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
static int TranslateArgumentIdx(int argidx)
|
2005-07-15 14:53:44 +00:00
|
|
|
{
|
|
|
|
int i, sum;
|
|
|
|
|
2005-07-16 17:12:32 +00:00
|
|
|
if (argidx < 0 || argidx >= lengthof(_cur_pcs.cmd))
|
2005-07-15 14:53:44 +00:00
|
|
|
Fatal("invalid argidx %d", argidx);
|
|
|
|
|
|
|
|
for(i = sum = 0; i < argidx; i++) {
|
2005-08-28 14:45:44 +00:00
|
|
|
const CmdStruct *cs = _cur_pcs.cmd[i];
|
2005-07-15 14:53:44 +00:00
|
|
|
sum += cs ? cs->consumes : 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-07-15 14:53:44 +00:00
|
|
|
|
2005-07-16 17:12:32 +00:00
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PutArgidxCommand(void)
|
|
|
|
{
|
2005-09-10 15:14:35 +00:00
|
|
|
PutByte(0x8C);
|
2005-07-17 10:18:23 +00:00
|
|
|
PutByte(TranslateArgumentIdx(_cur_argidx));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void PutCommandString(const char *str)
|
|
|
|
{
|
|
|
|
const CmdStruct *cs;
|
|
|
|
char param[256];
|
|
|
|
int argno;
|
|
|
|
int casei;
|
|
|
|
|
|
|
|
_cur_argidx = 0;
|
|
|
|
|
|
|
|
while (*str != '\0') {
|
|
|
|
// Process characters as they are until we encounter a {
|
|
|
|
if (*str != '{') {
|
|
|
|
PutByte(*str++);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
cs = ParseCommandString(&str, param, &argno, &casei);
|
|
|
|
if (cs == NULL) break;
|
|
|
|
|
|
|
|
if (casei != -1) {
|
|
|
|
PutByte(0x9D); // {SETCASE}
|
|
|
|
PutByte(casei);
|
|
|
|
}
|
|
|
|
|
|
|
|
// For params that consume values, we need to handle the argindex properly
|
|
|
|
if (cs->consumes) {
|
|
|
|
// Check if we need to output a move-param command
|
|
|
|
if (argno!=-1 && argno != _cur_argidx) {
|
|
|
|
_cur_argidx = argno;
|
|
|
|
PutArgidxCommand();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Output the one from the master string... it's always accurate.
|
|
|
|
cs = _cur_pcs.cmd[_cur_argidx++];
|
|
|
|
if (!cs)
|
|
|
|
Fatal("%s: No argument exists at posision %d", _cur_ident, _cur_argidx-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
cs->proc(param, cs->value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WriteLength(FILE *f, uint length)
|
|
|
|
{
|
|
|
|
if (length < 0xC0) {
|
|
|
|
fputc(length, f);
|
|
|
|
} else if (length < 0x4000) {
|
|
|
|
fputc((length >> 8) | 0xC0, f);
|
|
|
|
fputc(length & 0xFF, f);
|
|
|
|
} else {
|
|
|
|
Fatal("string too long");
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
|
|
|
|
static void WriteLangfile(const char *filename, int show_todo)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
int in_use[32];
|
|
|
|
LanguagePackHeader hdr;
|
2005-07-15 14:53:44 +00:00
|
|
|
int i,j;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
f = fopen(filename, "wb");
|
2005-07-15 14:53:44 +00:00
|
|
|
if (f == NULL) Fatal("can't open %s", filename);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
memset(&hdr, 0, sizeof(hdr));
|
2005-07-15 14:53:44 +00:00
|
|
|
for(i = 0; i != 32; i++) {
|
|
|
|
int n = CountInUse(i);
|
2004-08-09 17:04:08 +00:00
|
|
|
in_use[i] = n;
|
|
|
|
hdr.offsets[i] = TO_LE16(n);
|
|
|
|
}
|
|
|
|
|
2004-09-12 21:49:38 +00:00
|
|
|
// see line 655: fprintf(..."\tLANGUAGE_PACK_IDENT = 0x474E414C,...)
|
2004-09-08 15:01:12 +00:00
|
|
|
hdr.ident = TO_LE32(0x474E414C); // Big Endian value for 'LANG'
|
2004-08-09 17:04:08 +00:00
|
|
|
hdr.version = TO_LE32(_hash);
|
2005-07-16 17:12:32 +00:00
|
|
|
hdr.plural_form = _lang_pluralform;
|
2004-08-09 17:04:08 +00:00
|
|
|
strcpy(hdr.name, _lang_name);
|
|
|
|
strcpy(hdr.own_name, _lang_ownname);
|
2005-02-17 07:49:31 +00:00
|
|
|
strcpy(hdr.isocode, _lang_isocode);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
fwrite(&hdr, sizeof(hdr), 1, f);
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
for(i = 0; i != 32; i++) {
|
|
|
|
for(j = 0; j != in_use[i]; j++) {
|
2005-07-17 10:18:23 +00:00
|
|
|
LangString *ls = _strings[(i<<11)+j];
|
|
|
|
|
|
|
|
Case *casep;
|
|
|
|
char *cmdp;
|
2005-07-15 14:53:44 +00:00
|
|
|
|
|
|
|
// For undefined strings, just set that it's an empty string
|
2005-07-17 10:18:23 +00:00
|
|
|
if (ls == NULL) {
|
2005-07-15 14:53:44 +00:00
|
|
|
WriteLength(f, 0);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
_cur_ident = ls->name;
|
2005-07-16 17:12:32 +00:00
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
// Produce a message if a string doesn't have a translation.
|
2005-07-17 10:18:23 +00:00
|
|
|
if (show_todo && ls->translated == NULL) {
|
2005-07-15 14:53:44 +00:00
|
|
|
if (show_todo == 2) {
|
2005-07-17 10:18:23 +00:00
|
|
|
Warning("'%s' is untranslated", ls->name);
|
2005-07-15 14:53:44 +00:00
|
|
|
} else {
|
|
|
|
const char *s = "<TODO> ";
|
|
|
|
while(*s) PutByte(*s++);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-07-15 14:53:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Extract the strings and stuff from the english command string
|
2005-07-17 10:18:23 +00:00
|
|
|
ExtractCommandString(&_cur_pcs, ls->english, false);
|
|
|
|
|
|
|
|
if (ls->translated_case || ls->translated) {
|
|
|
|
casep = ls->translated_case;
|
|
|
|
cmdp = ls->translated;
|
|
|
|
} else {
|
|
|
|
casep = ls->english_case;
|
|
|
|
cmdp = ls->english;
|
|
|
|
}
|
2005-07-15 14:53:44 +00:00
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
if (casep) {
|
|
|
|
Case *c;
|
|
|
|
int num;
|
|
|
|
// Need to output a case-switch.
|
|
|
|
// It has this format
|
|
|
|
// <0x9E> <NUM CASES> <CASE1> <LEN1> <STRING1> <CASE2> <LEN2> <STRING2> <CASE3> <LEN3> <STRING3> <STRINGDEFAULT>
|
|
|
|
// Each LEN is printed using 2 bytes in big endian order.
|
|
|
|
PutByte(0x9E);
|
|
|
|
// Count the number of cases
|
|
|
|
for(num=0,c=casep; c; c=c->next) num++;
|
|
|
|
PutByte(num);
|
|
|
|
|
|
|
|
// Write each case
|
|
|
|
for(c=casep; c; c=c->next) {
|
|
|
|
int pos;
|
|
|
|
PutByte(c->caseidx);
|
|
|
|
// Make some space for the 16-bit length
|
|
|
|
pos = _put_pos;
|
|
|
|
PutByte(0);
|
|
|
|
PutByte(0);
|
|
|
|
// Write string
|
|
|
|
PutCommandString(c->string);
|
|
|
|
PutByte(0); // terminate with a zero
|
|
|
|
// Fill in the length
|
|
|
|
_put_buf[pos] = (_put_pos - (pos + 2)) >> 8;
|
|
|
|
_put_buf[pos+1] = (_put_pos - (pos + 2)) & 0xFF;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2005-07-15 14:53:44 +00:00
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
if (cmdp)
|
|
|
|
PutCommandString(cmdp);
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
WriteLength(f, _put_pos);
|
|
|
|
fwrite(_put_buf, 1, _put_pos, f);
|
|
|
|
_put_pos = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fputc(0, f);
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
|
2004-09-14 18:19:29 +00:00
|
|
|
int CDECL main(int argc, char* argv[])
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-07-15 14:53:44 +00:00
|
|
|
char *r;
|
|
|
|
char buf[256];
|
2004-08-09 17:04:08 +00:00
|
|
|
int show_todo = 0;
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
if (argc > 1 && (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version"))) {
|
2005-09-11 18:20:32 +00:00
|
|
|
puts("$Revision$");
|
2004-08-09 17:04:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
if (argc > 1 && !strcmp(argv[1], "-t")) {
|
2004-08-09 17:04:08 +00:00
|
|
|
show_todo = 1;
|
2005-07-15 14:53:44 +00:00
|
|
|
argc--, argv++;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
if (argc > 1 && !strcmp(argv[1], "-w")) {
|
2004-08-09 17:04:08 +00:00
|
|
|
show_todo = 2;
|
2005-07-15 14:53:44 +00:00
|
|
|
argc--, argv++;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (argc == 1) {
|
|
|
|
// parse master file
|
2005-07-15 14:53:44 +00:00
|
|
|
ParseFile("lang/english.txt", true);
|
|
|
|
MakeHashOfStrings();
|
|
|
|
if (_errors) return 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// write english.lng and strings.h
|
2004-09-12 21:49:38 +00:00
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
WriteLangfile("lang/english.lng", 0);
|
|
|
|
WriteStringsH("table/strings.h");
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
} else if (argc == 2) {
|
2005-07-15 14:53:44 +00:00
|
|
|
ParseFile("lang/english.txt", true);
|
|
|
|
MakeHashOfStrings();
|
|
|
|
ParseFile(argv[1], false);
|
|
|
|
|
|
|
|
if (_errors) return 1;
|
2005-07-15 07:48:17 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
strcpy(buf, argv[1]);
|
|
|
|
r = strrchr(buf, '.');
|
2005-07-15 14:53:44 +00:00
|
|
|
if (!r || strcmp(r, ".txt")) r = strchr(buf, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
strcpy(r, ".lng");
|
2005-07-15 14:53:44 +00:00
|
|
|
WriteLangfile(buf, show_todo);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, "invalid arguments\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2005-07-15 14:53:44 +00:00
|
|
|
|