2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file strgen.cpp Tool to create computer readable (stand-alone) translation files. */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "../stdafx.h"
|
2007-12-25 14:08:56 +00:00
|
|
|
#include "../core/endian_func.hpp"
|
2008-01-07 14:23:25 +00:00
|
|
|
#include "../string_func.h"
|
2008-10-17 17:42:51 +00:00
|
|
|
#include "../strings_type.h"
|
2010-11-13 11:11:02 +00:00
|
|
|
#include "../language.h"
|
2011-02-18 20:52:42 +00:00
|
|
|
#include "../misc/getoptdata.h"
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "../table/control_codes.h"
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2005-10-02 22:39:56 +00:00
|
|
|
#if (!defined(WIN32) && !defined(WIN64)) || defined(__CYGWIN__)
|
2004-08-09 17:04:08 +00:00
|
|
|
#include <unistd.h>
|
2007-01-10 18:56:51 +00:00
|
|
|
#include <sys/stat.h>
|
2004-08-09 17:04:08 +00:00
|
|
|
#endif
|
|
|
|
|
2006-08-24 12:08:25 +00:00
|
|
|
#if defined WIN32 || defined __WATCOMC__
|
|
|
|
#include <direct.h>
|
|
|
|
#endif /* WIN32 || __WATCOMC__ */
|
|
|
|
|
2004-09-08 15:01:12 +00:00
|
|
|
#ifdef __MORPHOS__
|
|
|
|
#ifdef stderr
|
|
|
|
#undef stderr
|
|
|
|
#endif
|
|
|
|
#define stderr stdout
|
2006-08-24 12:08:25 +00:00
|
|
|
#endif /* __MORPHOS__ */
|
2004-09-08 15:01:12 +00:00
|
|
|
|
2009-04-23 14:06:57 +00:00
|
|
|
#include "../table/strgen_tables.h"
|
2005-07-17 10:18:23 +00:00
|
|
|
|
2009-04-21 21:34:26 +00:00
|
|
|
/* Compiles a list of strings into a compiled string list */
|
2005-07-17 10:18:23 +00:00
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct Case {
|
2005-07-17 10:18:23 +00:00
|
|
|
int caseidx;
|
|
|
|
char *string;
|
2007-03-07 12:11:48 +00:00
|
|
|
Case *next;
|
|
|
|
};
|
2005-07-17 10:18:23 +00:00
|
|
|
|
2010-02-12 23:45:25 +00:00
|
|
|
static bool _masterlang; ///< Whether we are loading the master language
|
|
|
|
static bool _translated; ///< Whether the current language is not the master language
|
|
|
|
static bool _translation; ///< Is the current file actually a translation or not
|
|
|
|
static const char *_file = "(unknown file)"; ///< The filename of the input, so we can refer to it in errors/warnings
|
|
|
|
static FILE *_output_file = NULL; ///< The file we are currently writing output to
|
|
|
|
static const char *_output_filename = NULL; ///< The filename of the output, so we can delete it if compilation fails
|
|
|
|
static int _cur_line; ///< The current line we're parsing in the input file
|
2007-06-28 22:58:59 +00:00
|
|
|
static int _errors, _warnings, _show_todo;
|
2005-07-15 14:53:44 +00:00
|
|
|
|
2010-11-28 19:48:13 +00:00
|
|
|
static const ptrdiff_t MAX_COMMAND_PARAM_SIZE = 100; ///< Maximum size of every command block, not counting the name of the command itself
|
2010-11-28 19:39:04 +00:00
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct LangString {
|
2006-08-22 14:38:37 +00:00
|
|
|
char *name; // Name of the string
|
|
|
|
char *english; // English text
|
|
|
|
char *translated; // Translated text
|
|
|
|
uint16 hash_next; // next hash entry
|
2005-07-17 10:18:23 +00:00
|
|
|
uint16 index;
|
2006-08-22 14:38:37 +00:00
|
|
|
int line; // line of string in source-file
|
|
|
|
Case *translated_case; // cases for foreign
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2005-07-17 10:18:23 +00:00
|
|
|
|
|
|
|
static LangString *_strings[65536];
|
2010-11-07 18:20:18 +00:00
|
|
|
static LanguagePackHeader _lang; ///< Header information about a language.
|
2005-07-17 10:18:23 +00:00
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
|
|
|
|
#define HASH_SIZE 32767
|
|
|
|
static uint16 _hash_head[HASH_SIZE];
|
|
|
|
|
|
|
|
static byte _put_buf[4096];
|
2010-12-12 01:21:02 +00:00
|
|
|
static uint _put_pos;
|
2005-07-15 14:53:44 +00:00
|
|
|
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-17 10:18:23 +00:00
|
|
|
|
2005-07-16 17:12:32 +00:00
|
|
|
static const char *_cur_ident;
|
2005-07-15 07:48:17 +00:00
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct CmdPair {
|
2005-07-17 10:18:23 +00:00
|
|
|
const CmdStruct *a;
|
2007-01-10 18:56:51 +00:00
|
|
|
const char *v;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2005-07-17 10:18:23 +00:00
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct ParsedCommandStruct {
|
2008-12-19 23:24:42 +00:00
|
|
|
uint np;
|
2005-07-17 10:18:23 +00:00
|
|
|
CmdPair pairs[32];
|
|
|
|
const CmdStruct *cmd[32]; // ordered by param #
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2005-07-17 10:18:23 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* Used when generating some advanced commands. */
|
2005-07-17 10:18:23 +00:00
|
|
|
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;
|
2006-02-12 10:44:52 +00:00
|
|
|
for (; *s != '\0'; s++) hash = ROL(hash, 3) ^ *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)];
|
2006-02-12 10:44:52 +00:00
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
while (--idx >= 0) {
|
2009-01-10 00:31:47 +00:00
|
|
|
LangString *ls = _strings[idx];
|
2006-02-12 10:44:52 +00:00
|
|
|
|
|
|
|
if (strcmp(ls->name, s) == 0) return ls;
|
2005-07-17 10:18:23 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2006-05-27 16:12:16 +00:00
|
|
|
#ifdef _MSC_VER
|
2010-02-12 23:47:50 +00:00
|
|
|
# define LINE_NUM_FMT(s) "%s (%d): warning: %s (" s ")\n"
|
2006-05-27 16:12:16 +00:00
|
|
|
#else
|
2010-02-20 23:02:03 +00:00
|
|
|
# define LINE_NUM_FMT(s) "%s:%d: " s ": %s\n"
|
2006-05-27 16:12:16 +00:00
|
|
|
#endif
|
2005-07-15 14:53:44 +00:00
|
|
|
|
2009-05-10 17:27:25 +00:00
|
|
|
static void CDECL strgen_warning(const char *s, ...) WARN_FORMAT(1, 2);
|
|
|
|
|
2008-04-18 21:33:21 +00:00
|
|
|
static void CDECL strgen_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);
|
2006-08-24 12:08:25 +00:00
|
|
|
vsnprintf(buf, lengthof(buf), s, va);
|
2004-08-09 17:04:08 +00:00
|
|
|
va_end(va);
|
2010-02-12 23:47:50 +00:00
|
|
|
fprintf(stderr, LINE_NUM_FMT("warning"), _file, _cur_line, buf);
|
2005-07-15 14:53:44 +00:00
|
|
|
_warnings++;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2009-05-10 17:27:25 +00:00
|
|
|
static void CDECL strgen_error(const char *s, ...) WARN_FORMAT(1, 2);
|
|
|
|
|
2008-04-18 21:33:21 +00:00
|
|
|
static void CDECL strgen_error(const char *s, ...)
|
2005-07-15 14:53:44 +00:00
|
|
|
{
|
|
|
|
char buf[1024];
|
|
|
|
va_list va;
|
|
|
|
va_start(va, s);
|
2006-08-24 12:08:25 +00:00
|
|
|
vsnprintf(buf, lengthof(buf), s, va);
|
2005-07-15 14:53:44 +00:00
|
|
|
va_end(va);
|
2010-02-12 23:47:50 +00:00
|
|
|
fprintf(stderr, LINE_NUM_FMT("error"), _file, _cur_line, buf);
|
2005-07-15 14:53:44 +00:00
|
|
|
_errors++;
|
|
|
|
}
|
|
|
|
|
2008-04-18 21:33:21 +00:00
|
|
|
void NORETURN CDECL error(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);
|
2006-08-24 12:08:25 +00:00
|
|
|
vsnprintf(buf, lengthof(buf), s, va);
|
2004-08-09 17:04:08 +00:00
|
|
|
va_end(va);
|
2010-02-12 23:47:50 +00:00
|
|
|
fprintf(stderr, LINE_NUM_FMT("FATAL"), _file, _cur_line, buf);
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
fprintf(stderr, LINE_NUM_FMT("warning"), _file, _cur_line, "language is not compiled");
|
|
|
|
#endif
|
2010-02-12 23:45:25 +00:00
|
|
|
/* We were writing output to a file, remove it. */
|
|
|
|
if (_output_file != NULL) {
|
|
|
|
fclose(_output_file);
|
|
|
|
unlink(_output_filename);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
static void PutByte(byte c)
|
2005-07-15 07:48:17 +00:00
|
|
|
{
|
2010-12-12 01:21:02 +00:00
|
|
|
if (_put_pos >= lengthof(_put_buf)) error("Put buffer too small");
|
2004-08-09 17:04:08 +00:00
|
|
|
_put_buf[_put_pos++] = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-16 22:05:33 +00:00
|
|
|
static void PutUtf8(uint32 value)
|
2005-07-15 07:48:17 +00:00
|
|
|
{
|
2006-11-16 22:05:33 +00:00
|
|
|
if (value < 0x80) {
|
|
|
|
PutByte(value);
|
|
|
|
} else if (value < 0x800) {
|
|
|
|
PutByte(0xC0 + GB(value, 6, 5));
|
|
|
|
PutByte(0x80 + GB(value, 0, 6));
|
|
|
|
} else if (value < 0x10000) {
|
|
|
|
PutByte(0xE0 + GB(value, 12, 4));
|
|
|
|
PutByte(0x80 + GB(value, 6, 6));
|
|
|
|
PutByte(0x80 + GB(value, 0, 6));
|
|
|
|
} else if (value < 0x110000) {
|
|
|
|
PutByte(0xF0 + GB(value, 18, 3));
|
|
|
|
PutByte(0x80 + GB(value, 12, 6));
|
|
|
|
PutByte(0x80 + GB(value, 6, 6));
|
|
|
|
PutByte(0x80 + GB(value, 0, 6));
|
|
|
|
} else {
|
2008-04-18 21:33:21 +00:00
|
|
|
strgen_warning("Invalid unicode value U+0x%X", value);
|
2006-11-16 22:05:33 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
|
2006-11-17 07:46:02 +00:00
|
|
|
size_t Utf8Validate(const char *s)
|
|
|
|
{
|
|
|
|
uint32 c;
|
|
|
|
|
2007-11-19 21:02:30 +00:00
|
|
|
if (!HasBit(s[0], 7)) {
|
2006-11-17 07:46:02 +00:00
|
|
|
/* 1 byte */
|
|
|
|
return 1;
|
|
|
|
} else if (GB(s[0], 5, 3) == 6 && IsUtf8Part(s[1])) {
|
|
|
|
/* 2 bytes */
|
|
|
|
c = GB(s[0], 0, 5) << 6 | GB(s[1], 0, 6);
|
|
|
|
if (c >= 0x80) return 2;
|
|
|
|
} else if (GB(s[0], 4, 4) == 14 && IsUtf8Part(s[1]) && IsUtf8Part(s[2])) {
|
|
|
|
/* 3 bytes */
|
|
|
|
c = GB(s[0], 0, 4) << 12 | GB(s[1], 0, 6) << 6 | GB(s[2], 0, 6);
|
|
|
|
if (c >= 0x800) return 3;
|
|
|
|
} else if (GB(s[0], 3, 5) == 30 && IsUtf8Part(s[1]) && IsUtf8Part(s[2]) && IsUtf8Part(s[3])) {
|
|
|
|
/* 4 bytes */
|
|
|
|
c = GB(s[0], 0, 3) << 18 | GB(s[1], 0, 6) << 12 | GB(s[2], 0, 6) << 6 | GB(s[3], 0, 6);
|
|
|
|
if (c >= 0x10000 && c <= 0x10FFFF) return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-16 22:05:33 +00:00
|
|
|
static void EmitSingleChar(char *buf, int value)
|
2005-07-15 07:48:17 +00:00
|
|
|
{
|
2008-04-18 21:33:21 +00:00
|
|
|
if (*buf != '\0') strgen_warning("Ignoring trailing letters in command");
|
2006-11-16 22:05:33 +00:00
|
|
|
PutUtf8(value);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-11-16 22:05:33 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* The plural specifier looks like
|
|
|
|
* {NUM} {PLURAL -1 passenger passengers} then it picks either passenger/passengers depending on the count in NUM */
|
2005-07-16 17:12:32 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* This is encoded like
|
|
|
|
* CommandByte <ARG#> <NUM> {Length of each string} {each string} */
|
2005-07-16 17:12:32 +00:00
|
|
|
|
2009-12-09 11:41:27 +00:00
|
|
|
bool ParseRelNum(char **buf, int *value, int *offset)
|
2005-07-16 17:12:32 +00:00
|
|
|
{
|
2009-01-10 00:31:47 +00:00
|
|
|
const char *s = *buf;
|
|
|
|
char *end;
|
2005-07-16 17:12:32 +00:00
|
|
|
bool rel = false;
|
2005-07-17 10:18:23 +00:00
|
|
|
|
2005-07-16 17:12:32 +00:00
|
|
|
while (*s == ' ' || *s == '\t') s++;
|
2006-02-12 10:44:52 +00:00
|
|
|
if (*s == '+') {
|
|
|
|
rel = true;
|
|
|
|
s++;
|
|
|
|
}
|
2009-06-18 11:17:55 +00:00
|
|
|
int v = strtol(s, &end, 0);
|
2005-07-16 17:12:32 +00:00
|
|
|
if (end == s) return false;
|
2006-02-12 10:44:52 +00:00
|
|
|
if (rel || v < 0) {
|
2005-07-17 10:18:23 +00:00
|
|
|
*value += v;
|
2006-02-12 10:44:52 +00:00
|
|
|
} else {
|
2005-07-17 10:18:23 +00:00
|
|
|
*value = v;
|
2006-02-12 10:44:52 +00:00
|
|
|
}
|
2009-12-09 11:41:27 +00:00
|
|
|
if (offset != NULL && *end == ':') {
|
|
|
|
/* Take the Nth within */
|
|
|
|
s = end + 1;
|
|
|
|
*offset = strtol(s, &end, 0);
|
|
|
|
if (end == s) return false;
|
|
|
|
}
|
2005-07-16 17:12:32 +00:00
|
|
|
*buf = end;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* Parse out the next word, or NULL */
|
2005-07-16 17:12:32 +00:00
|
|
|
char *ParseWord(char **buf)
|
|
|
|
{
|
|
|
|
char *s = *buf, *r;
|
2006-02-12 10:44:52 +00:00
|
|
|
|
2005-07-16 17:12:32 +00:00
|
|
|
while (*s == ' ' || *s == '\t') s++;
|
2006-02-12 10:44:52 +00:00
|
|
|
if (*s == '\0') return NULL;
|
2005-07-16 17:12:32 +00:00
|
|
|
|
|
|
|
if (*s == '"') {
|
|
|
|
r = ++s;
|
2009-03-15 00:32:18 +00:00
|
|
|
/* parse until next " or NUL */
|
2006-02-01 07:36:15 +00:00
|
|
|
for (;;) {
|
2006-02-12 10:44:52 +00:00
|
|
|
if (*s == '\0') break;
|
2005-07-16 17:12:32 +00:00
|
|
|
if (*s == '"') {
|
2006-02-12 10:44:52 +00:00
|
|
|
*s++ = '\0';
|
2005-07-16 17:12:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
} else {
|
2009-03-15 00:32:18 +00:00
|
|
|
/* proceed until whitespace or NUL */
|
2005-07-16 17:12:32 +00:00
|
|
|
r = s;
|
2006-02-01 07:36:15 +00:00
|
|
|
for (;;) {
|
2006-02-12 10:44:52 +00:00
|
|
|
if (*s == '\0') break;
|
2005-07-16 17:12:32 +00:00
|
|
|
if (*s == ' ' || *s == '\t') {
|
2006-02-12 10:44:52 +00:00
|
|
|
*s++ = '\0';
|
2005-07-16 17:12:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*buf = s;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* Forward declaration */
|
2009-12-09 11:41:27 +00:00
|
|
|
static int TranslateArgumentIdx(int arg, int offset = 0);
|
2005-07-16 17:12:32 +00:00
|
|
|
|
2009-01-10 00:31:47 +00:00
|
|
|
static void EmitWordList(const char * const *words, uint nw)
|
2005-07-16 20:58:04 +00:00
|
|
|
{
|
|
|
|
PutByte(nw);
|
2009-08-06 20:21:53 +00:00
|
|
|
for (uint i = 0; i < nw; i++) PutByte(strlen(words[i]) + 1);
|
2009-06-18 11:17:55 +00:00
|
|
|
for (uint i = 0; i < nw; i++) {
|
|
|
|
for (uint j = 0; words[i][j] != '\0'; j++) PutByte(words[i][j]);
|
2009-08-06 20:21:53 +00:00
|
|
|
PutByte(0);
|
2005-07-16 20:58:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2009-12-09 11:41:27 +00:00
|
|
|
int offset = 0;
|
2009-01-10 00:31:47 +00:00
|
|
|
const char *words[5];
|
2005-07-16 17:12:32 +00:00
|
|
|
int nw = 0;
|
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* Parse out the number, if one exists. Otherwise default to prev arg. */
|
2009-12-09 11:41:27 +00:00
|
|
|
if (!ParseRelNum(&buf, &argidx, &offset)) argidx--;
|
2005-07-16 17:12:32 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* Parse each string */
|
2005-10-30 00:16:48 +00:00
|
|
|
for (nw = 0; nw < 5; nw++) {
|
2005-07-16 17:12:32 +00:00
|
|
|
words[nw] = ParseWord(&buf);
|
2006-02-12 10:44:52 +00:00
|
|
|
if (words[nw] == NULL) break;
|
2005-07-16 17:12:32 +00:00
|
|
|
}
|
|
|
|
|
2009-06-18 11:17:55 +00:00
|
|
|
if (nw == 0) {
|
2008-04-18 21:33:21 +00:00
|
|
|
error("%s: No plural words", _cur_ident);
|
2009-06-18 11:17:55 +00:00
|
|
|
}
|
2005-07-16 17:12:32 +00:00
|
|
|
|
2010-11-07 18:20:18 +00:00
|
|
|
if (_plural_forms[_lang.plural_form].plural_count != nw) {
|
2005-11-02 23:31:04 +00:00
|
|
|
if (_translated) {
|
2008-04-18 21:33:21 +00:00
|
|
|
error("%s: Invalid number of plural forms. Expecting %d, found %d.", _cur_ident,
|
2010-11-07 18:20:18 +00:00
|
|
|
_plural_forms[_lang.plural_form].plural_count, nw);
|
2005-10-30 00:16:48 +00:00
|
|
|
} else {
|
2008-04-18 21:33:21 +00:00
|
|
|
if ((_show_todo & 2) != 0) strgen_warning("'%s' is untranslated. Tweaking english string to allow compilation for plural forms", _cur_ident);
|
2010-11-07 18:20:18 +00:00
|
|
|
if (nw > _plural_forms[_lang.plural_form].plural_count) {
|
|
|
|
nw = _plural_forms[_lang.plural_form].plural_count;
|
2005-10-30 00:16:48 +00:00
|
|
|
} else {
|
2010-11-07 18:20:18 +00:00
|
|
|
for (; nw < _plural_forms[_lang.plural_form].plural_count; nw++) {
|
2005-10-30 00:16:48 +00:00
|
|
|
words[nw] = words[nw - 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-12-17 14:26:43 +00:00
|
|
|
}
|
2005-07-16 17:12:32 +00:00
|
|
|
|
2006-11-16 22:05:33 +00:00
|
|
|
PutUtf8(SCC_PLURAL_LIST);
|
2010-11-16 21:01:56 +00:00
|
|
|
PutByte(_lang.plural_form);
|
2009-12-09 11:41:27 +00:00
|
|
|
PutByte(TranslateArgumentIdx(argidx, offset));
|
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;
|
2009-12-09 11:41:27 +00:00
|
|
|
int offset = 0;
|
2006-02-12 10:44:52 +00:00
|
|
|
uint nw;
|
2005-07-16 20:58:04 +00:00
|
|
|
|
|
|
|
if (buf[0] == '=') {
|
|
|
|
buf++;
|
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* This is a {G=DER} command */
|
2010-11-13 14:36:43 +00:00
|
|
|
nw = _lang.GetGenderIndex(buf);
|
|
|
|
if (nw >= MAX_NUM_GENDERS) error("G argument '%s' invalid", buf);
|
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* now nw contains the gender index */
|
2006-11-16 22:05:33 +00:00
|
|
|
PutUtf8(SCC_GENDER_INDEX);
|
2005-07-16 20:58:04 +00:00
|
|
|
PutByte(nw);
|
|
|
|
} else {
|
2010-11-10 16:31:46 +00:00
|
|
|
const char *words[MAX_NUM_GENDERS];
|
2006-02-12 10:44:52 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* This is a {G 0 foo bar two} command.
|
|
|
|
* If no relative number exists, default to +0 */
|
2009-12-09 11:41:27 +00:00
|
|
|
if (!ParseRelNum(&buf, &argidx, &offset)) {}
|
2005-07-16 20:58:04 +00:00
|
|
|
|
2010-02-20 23:02:03 +00:00
|
|
|
const CmdStruct *cmd = _cur_pcs.cmd[argidx];
|
2010-02-26 10:03:33 +00:00
|
|
|
if (cmd == NULL || (cmd->flags & C_GENDER) == 0) {
|
|
|
|
error("Command '%s' can't have a gender", cmd == NULL ? "<empty>" : cmd->cmd);
|
2010-02-20 23:02:03 +00:00
|
|
|
}
|
|
|
|
|
2010-11-10 16:31:46 +00:00
|
|
|
for (nw = 0; nw < MAX_NUM_GENDERS; nw++) {
|
2005-07-16 20:58:04 +00:00
|
|
|
words[nw] = ParseWord(&buf);
|
2006-02-12 10:44:52 +00:00
|
|
|
if (words[nw] == NULL) break;
|
2005-07-16 20:58:04 +00:00
|
|
|
}
|
2010-11-13 14:36:43 +00:00
|
|
|
if (nw != _lang.num_genders) error("Bad # of arguments for gender command");
|
2010-02-20 23:42:11 +00:00
|
|
|
|
|
|
|
assert(IsInsideBS(cmd->value, SCC_CONTROL_START, UINT8_MAX));
|
2006-11-16 22:05:33 +00:00
|
|
|
PutUtf8(SCC_GENDER_LIST);
|
2009-12-09 11:41:27 +00:00
|
|
|
PutByte(TranslateArgumentIdx(argidx, offset));
|
2005-07-16 20:58:04 +00:00
|
|
|
EmitWordList(words, nw);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-15 07:48:17 +00:00
|
|
|
static const CmdStruct *FindCmd(const char *s, int len)
|
|
|
|
{
|
2009-06-18 11:17:55 +00:00
|
|
|
for (const CmdStruct *cs = _cmd_structs; cs != endof(_cmd_structs); cs++) {
|
2006-02-12 10:44:52 +00:00
|
|
|
if (strncmp(cs->cmd, s, len) == 0 && cs->cmd[len] == '\0') return cs;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-02-12 10:44:52 +00:00
|
|
|
static uint ResolveCaseName(const char *str, uint len)
|
2005-07-17 10:18:23 +00:00
|
|
|
{
|
2010-11-13 14:36:43 +00:00
|
|
|
/* First get a clean copy of only the case name, then resolve it. */
|
|
|
|
char case_str[CASE_GENDER_LEN];
|
2010-12-12 01:21:02 +00:00
|
|
|
len = min(lengthof(case_str) - 1, len);
|
2010-11-13 14:36:43 +00:00
|
|
|
memcpy(case_str, str, len);
|
|
|
|
case_str[len] = '\0';
|
|
|
|
|
|
|
|
uint8 case_idx = _lang.GetCaseIndex(case_str);
|
|
|
|
if (case_idx >= MAX_NUM_CASES) error("Invalid case-name '%s'", case_str);
|
|
|
|
return case_idx + 1;
|
2005-07-17 10:18:23 +00:00
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-03-15 00:32:18 +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;
|
2009-06-18 11:17:55 +00:00
|
|
|
char 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
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* Scan to the next command, exit if there's no next command. */
|
2006-02-01 07:36:15 +00:00
|
|
|
for (; *s != '{'; s++) {
|
2006-02-12 10:44:52 +00:00
|
|
|
if (*s == '\0') return NULL;
|
2005-07-15 14:53:44 +00:00
|
|
|
}
|
|
|
|
s++; // Skip past the {
|
|
|
|
|
|
|
|
if (*s >= '0' && *s <= '9') {
|
|
|
|
char *end;
|
2006-02-12 10:44:52 +00:00
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
*argno = strtoul(s, &end, 0);
|
2008-04-18 21:33:21 +00:00
|
|
|
if (*end != ':') error("missing arg #");
|
2005-07-15 14:53:44 +00:00
|
|
|
s = end + 1;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* parse command name */
|
2004-08-09 17:04:08 +00:00
|
|
|
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
|
|
|
|
2009-06-18 11:17:55 +00:00
|
|
|
const CmdStruct *cmd = FindCmd(start, s - start - 1);
|
2004-08-09 17:04:08 +00:00
|
|
|
if (cmd == NULL) {
|
2009-05-10 17:27:25 +00:00
|
|
|
strgen_error("Undefined command '%.*s'", (int)(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;
|
|
|
|
|
2009-06-18 11:17:55 +00:00
|
|
|
if (!(cmd->flags & C_CASE)) {
|
2008-04-18 21:33:21 +00:00
|
|
|
error("Command '%s' can't have a case", cmd->cmd);
|
2009-06-18 11:17:55 +00:00
|
|
|
}
|
2005-07-17 10:18:23 +00:00
|
|
|
|
2009-06-18 11:17:55 +00:00
|
|
|
do {
|
|
|
|
c = *s++;
|
|
|
|
} while (c != '}' && c != ' ' && c != '\0');
|
2006-02-12 10:44:52 +00:00
|
|
|
*casei = ResolveCaseName(casep, s - casep - 1);
|
2005-07-17 10:18:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (c == '\0') {
|
2008-04-18 21:33:21 +00:00
|
|
|
strgen_error("Missing } from command '%s'", start);
|
2005-07-17 10:18:23 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-16 20:58:04 +00:00
|
|
|
if (c != '}') {
|
|
|
|
if (c == '=') s--;
|
2009-03-15 00:32:18 +00:00
|
|
|
/* copy params */
|
2004-08-09 17:04:08 +00:00
|
|
|
start = s;
|
2006-02-01 07:36:15 +00:00
|
|
|
for (;;) {
|
2004-08-09 17:04:08 +00:00
|
|
|
c = *s++;
|
|
|
|
if (c == '}') break;
|
2005-07-15 14:53:44 +00:00
|
|
|
if (c == '\0') {
|
2008-04-18 21:33:21 +00:00
|
|
|
strgen_error("Missing } from command '%s'", start);
|
2004-08-09 17:04:08 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2010-11-28 19:39:04 +00:00
|
|
|
if (s - start == MAX_COMMAND_PARAM_SIZE) error("param command too long");
|
2004-08-09 17:04:08 +00:00
|
|
|
*param++ = c;
|
|
|
|
}
|
|
|
|
}
|
2006-02-12 10:44:52 +00:00
|
|
|
*param = '\0';
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
*str = s;
|
|
|
|
|
|
|
|
return cmd;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-07 20:57:41 +00:00
|
|
|
static void HandlePragma(char *str, bool master)
|
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)) {
|
2010-11-07 18:20:18 +00:00
|
|
|
strecpy(_lang.name, str + 5, lastof(_lang.name));
|
2005-07-15 14:53:44 +00:00
|
|
|
} else if (!memcmp(str, "ownname ", 8)) {
|
2010-11-07 18:20:18 +00:00
|
|
|
strecpy(_lang.own_name, str + 8, lastof(_lang.own_name));
|
2005-07-15 14:53:44 +00:00
|
|
|
} else if (!memcmp(str, "isocode ", 8)) {
|
2010-11-07 18:20:18 +00:00
|
|
|
strecpy(_lang.isocode, str + 8, lastof(_lang.isocode));
|
2005-07-16 17:12:32 +00:00
|
|
|
} else if (!memcmp(str, "plural ", 7)) {
|
2010-11-07 18:20:18 +00:00
|
|
|
_lang.plural_form = atoi(str + 7);
|
|
|
|
if (_lang.plural_form >= lengthof(_plural_forms)) {
|
|
|
|
error("Invalid pluralform %d", _lang.plural_form);
|
2010-07-24 10:14:39 +00:00
|
|
|
}
|
2008-10-17 17:42:51 +00:00
|
|
|
} else if (!memcmp(str, "textdir ", 8)) {
|
|
|
|
if (!memcmp(str + 8, "ltr", 3)) {
|
2010-11-07 18:20:18 +00:00
|
|
|
_lang.text_dir = TD_LTR;
|
2008-10-17 17:42:51 +00:00
|
|
|
} else if (!memcmp(str + 8, "rtl", 3)) {
|
2010-11-07 18:20:18 +00:00
|
|
|
_lang.text_dir = TD_RTL;
|
2008-10-17 17:42:51 +00:00
|
|
|
} else {
|
|
|
|
error("Invalid textdir %s", str + 8);
|
|
|
|
}
|
2009-04-23 21:05:00 +00:00
|
|
|
} else if (!memcmp(str, "digitsep ", 9)) {
|
|
|
|
str += 9;
|
2010-11-07 18:20:18 +00:00
|
|
|
strecpy(_lang.digit_group_separator, strcmp(str, "{NBSP}") == 0 ? NBSP : str, lastof(_lang.digit_group_separator));
|
2009-04-23 21:05:00 +00:00
|
|
|
} else if (!memcmp(str, "digitsepcur ", 12)) {
|
|
|
|
str += 12;
|
2010-11-07 18:20:18 +00:00
|
|
|
strecpy(_lang.digit_group_separator_currency, strcmp(str, "{NBSP}") == 0 ? NBSP : str, lastof(_lang.digit_group_separator_currency));
|
2009-08-12 01:28:11 +00:00
|
|
|
} else if (!memcmp(str, "decimalsep ", 11)) {
|
|
|
|
str += 11;
|
2010-11-07 18:20:18 +00:00
|
|
|
strecpy(_lang.digit_decimal_separator, strcmp(str, "{NBSP}") == 0 ? NBSP : str, lastof(_lang.digit_decimal_separator));
|
2008-11-24 18:53:17 +00:00
|
|
|
} else if (!memcmp(str, "winlangid ", 10)) {
|
2009-03-13 00:30:26 +00:00
|
|
|
const char *buf = str + 10;
|
2008-11-24 18:53:17 +00:00
|
|
|
long langid = strtol(buf, NULL, 16);
|
2009-06-22 22:04:48 +00:00
|
|
|
if (langid > (long)UINT16_MAX || langid < 0) {
|
2008-11-24 18:53:17 +00:00
|
|
|
error("Invalid winlangid %s", buf);
|
|
|
|
}
|
2010-11-07 18:20:18 +00:00
|
|
|
_lang.winlangid = (uint16)langid;
|
2009-03-13 00:30:26 +00:00
|
|
|
} else if (!memcmp(str, "grflangid ", 10)) {
|
|
|
|
const char *buf = str + 10;
|
|
|
|
long langid = strtol(buf, NULL, 16);
|
|
|
|
if (langid >= 0x7F || langid < 0) {
|
|
|
|
error("Invalid grflangid %s", buf);
|
|
|
|
}
|
2010-11-07 18:20:18 +00:00
|
|
|
_lang.newgrflangid = (uint8)langid;
|
2005-07-16 20:58:04 +00:00
|
|
|
} else if (!memcmp(str, "gender ", 7)) {
|
2010-11-07 20:57:41 +00:00
|
|
|
if (master) error("Genders are not allowed in the base translation.");
|
2009-01-10 00:31:47 +00:00
|
|
|
char *buf = str + 7;
|
2006-02-12 10:44:52 +00:00
|
|
|
|
2006-02-01 07:36:15 +00:00
|
|
|
for (;;) {
|
2009-01-10 00:31:47 +00:00
|
|
|
const char *s = ParseWord(&buf);
|
2006-02-12 10:44:52 +00:00
|
|
|
|
|
|
|
if (s == NULL) break;
|
2010-11-13 14:36:43 +00:00
|
|
|
if (_lang.num_genders >= MAX_NUM_GENDERS) error("Too many genders, max %d", MAX_NUM_GENDERS);
|
|
|
|
strecpy(_lang.genders[_lang.num_genders], s, lastof(_lang.genders[_lang.num_genders]));
|
|
|
|
_lang.num_genders++;
|
2005-07-16 20:58:04 +00:00
|
|
|
}
|
2005-07-17 10:18:23 +00:00
|
|
|
} else if (!memcmp(str, "case ", 5)) {
|
2010-11-07 20:57:41 +00:00
|
|
|
if (master) error("Cases are not allowed in the base translation.");
|
2009-01-10 00:31:47 +00:00
|
|
|
char *buf = str + 5;
|
2006-02-12 10:44:52 +00:00
|
|
|
|
2006-02-01 07:36:15 +00:00
|
|
|
for (;;) {
|
2009-01-10 00:31:47 +00:00
|
|
|
const char *s = ParseWord(&buf);
|
2006-02-12 10:44:52 +00:00
|
|
|
|
|
|
|
if (s == NULL) break;
|
2010-11-13 14:36:43 +00:00
|
|
|
if (_lang.num_cases >= MAX_NUM_CASES) error("Too many cases, max %d", MAX_NUM_CASES);
|
|
|
|
strecpy(_lang.cases[_lang.num_cases], s, lastof(_lang.cases[_lang.num_cases]));
|
|
|
|
_lang.num_cases++;
|
2005-07-17 10:18:23 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2008-04-18 21:33:21 +00:00
|
|
|
error("unknown pragma '%s'", str);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-10 00:31:47 +00:00
|
|
|
static void ExtractCommandString(ParsedCommandStruct *p, const char *s, bool warnings)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2010-11-28 19:39:04 +00:00
|
|
|
char param[MAX_COMMAND_PARAM_SIZE];
|
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
|
|
|
|
2006-02-01 07:36:15 +00:00
|
|
|
for (;;) {
|
2009-03-15 00:32:18 +00:00
|
|
|
/* read until next command from a. */
|
2009-01-10 00:31:47 +00:00
|
|
|
const CmdStruct *ar = ParseCommandString(&s, param, &argno, &casei);
|
2006-02-12 10:44:52 +00:00
|
|
|
|
|
|
|
if (ar == NULL) break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* Sanity checking */
|
2008-04-18 21:33:21 +00:00
|
|
|
if (argno != -1 && ar->consumes == 0) error("Non consumer param can't have a paramindex");
|
2005-07-15 14:53:44 +00:00
|
|
|
|
|
|
|
if (ar->consumes) {
|
2006-02-12 10:44:52 +00:00
|
|
|
if (argno != -1) argidx = argno;
|
2008-12-19 23:24:42 +00:00
|
|
|
if (argidx < 0 || (uint)argidx >= lengthof(p->cmd)) error("invalid param idx %d", argidx);
|
2008-04-18 21:33:21 +00:00
|
|
|
if (p->cmd[argidx] != NULL && p->cmd[argidx] != ar) error("duplicate param idx %d", argidx);
|
2005-07-15 14:53:44 +00:00
|
|
|
|
|
|
|
p->cmd[argidx++] = ar;
|
2005-07-17 10:18:23 +00:00
|
|
|
} else if (!(ar->flags & C_DONTCOUNT)) { // Ignore some of them
|
2009-05-10 17:27:25 +00:00
|
|
|
if (p->np >= lengthof(p->pairs)) error("too many commands in string, max " PRINTF_SIZE, lengthof(p->pairs));
|
2005-07-15 14:53:44 +00:00
|
|
|
p->pairs[p->np].a = ar;
|
2006-02-12 10:44:52 +00:00
|
|
|
p->pairs[p->np].v = param[0] != '\0' ? strdup(param) : "";
|
2005-07-15 14:53:44 +00:00
|
|
|
p->np++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const CmdStruct *TranslateCmdForCompare(const CmdStruct *a)
|
|
|
|
{
|
2006-02-12 10:44:52 +00:00
|
|
|
if (a == NULL) return NULL;
|
2005-07-15 14:53:44 +00:00
|
|
|
|
2006-02-12 10:44:52 +00:00
|
|
|
if (strcmp(a->cmd, "STRING1") == 0 ||
|
|
|
|
strcmp(a->cmd, "STRING2") == 0 ||
|
|
|
|
strcmp(a->cmd, "STRING3") == 0 ||
|
|
|
|
strcmp(a->cmd, "STRING4") == 0 ||
|
2008-07-17 13:47:04 +00:00
|
|
|
strcmp(a->cmd, "STRING5") == 0 ||
|
2009-08-14 17:11:59 +00:00
|
|
|
strcmp(a->cmd, "RAW_STRING") == 0) {
|
2005-07-15 14:53:44 +00:00
|
|
|
return FindCmd("STRING", 6);
|
2006-02-12 10:44:52 +00:00
|
|
|
}
|
2005-07-15 14:53:44 +00:00
|
|
|
|
|
|
|
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
|
|
|
{
|
2009-08-09 10:20:09 +00:00
|
|
|
/* If we're not translating, i.e. we're compiling the base language,
|
|
|
|
* it is pointless to do all these checks as it'll always be correct.
|
|
|
|
* After all, all checks are based on the base language.
|
|
|
|
*/
|
|
|
|
if (!_translation) return true;
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
ParsedCommandStruct templ;
|
|
|
|
ParsedCommandStruct lang;
|
|
|
|
bool result = true;
|
|
|
|
|
|
|
|
ExtractCommandString(&templ, b, true);
|
|
|
|
ExtractCommandString(&lang, a, true);
|
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* For each string in templ, see if we find it in lang */
|
2005-07-15 14:53:44 +00:00
|
|
|
if (templ.np != lang.np) {
|
2008-04-18 21:33:21 +00:00
|
|
|
strgen_warning("%s: template string and language string have a different # of commands", name);
|
2005-07-15 14:53:44 +00:00
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
|
2009-06-18 11:17:55 +00:00
|
|
|
for (uint i = 0; i < templ.np; i++) {
|
2009-03-15 00:32:18 +00:00
|
|
|
/* see if we find it in lang, and zero it out */
|
2005-07-15 14:53:44 +00:00
|
|
|
bool found = false;
|
2009-06-18 11:17:55 +00:00
|
|
|
for (uint j = 0; j < lang.np; j++) {
|
2005-07-15 14:53:44 +00:00
|
|
|
if (templ.pairs[i].a == lang.pairs[j].a &&
|
2006-02-12 10:44:52 +00:00
|
|
|
strcmp(templ.pairs[i].v, lang.pairs[j].v) == 0) {
|
2009-03-15 00:32:18 +00:00
|
|
|
/* it was found in both. zero it out from lang so we don't find it again */
|
2005-07-15 14:53:44 +00:00
|
|
|
lang.pairs[j].a = NULL;
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
2008-04-18 21:33:21 +00:00
|
|
|
strgen_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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* if we reach here, all non consumer commands match up.
|
|
|
|
* Check if the non consumer commands match up also. */
|
2009-06-18 11:17:55 +00:00
|
|
|
for (uint i = 0; i < lengthof(templ.cmd); i++) {
|
2009-08-09 10:20:09 +00:00
|
|
|
if (TranslateCmdForCompare(templ.cmd[i]) != lang.cmd[i]) {
|
2008-04-18 21:33:21 +00:00
|
|
|
strgen_warning("%s: Param idx #%d '%s' doesn't match with template command '%s'", name, i,
|
2009-08-09 10:20:09 +00:00
|
|
|
lang.cmd[i] == NULL ? "<empty>" : TranslateCmdForCompare(lang.cmd[i])->cmd,
|
2006-02-12 10:44:52 +00:00
|
|
|
templ.cmd[i] == NULL ? "<empty>" : templ.cmd[i]->cmd);
|
2005-07-15 14:53:44 +00:00
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void HandleString(char *str, bool master)
|
|
|
|
{
|
2004-08-09 17:04:08 +00:00
|
|
|
if (*str == '#') {
|
2010-11-07 20:57:41 +00:00
|
|
|
if (str[1] == '#' && str[2] != '#') HandlePragma(str + 2, master);
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* Ignore comments & blank lines */
|
2006-02-12 10:44:52 +00:00
|
|
|
if (*str == ';' || *str == ' ' || *str == '\0') return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-06-18 11:17:55 +00:00
|
|
|
char *s = strchr(str, ':');
|
2004-08-09 17:04:08 +00:00
|
|
|
if (s == NULL) {
|
2008-04-18 21:33:21 +00:00
|
|
|
strgen_error("Line has no ':' delimiter");
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-18 11:17:55 +00:00
|
|
|
char *t;
|
2009-03-15 00:32:18 +00:00
|
|
|
/* Trim spaces.
|
|
|
|
* After this str points to the command name, and s points to the command contents */
|
2009-06-18 11:17:55 +00:00
|
|
|
for (t = s; t > str && (t[-1] == ' ' || t[-1] == '\t'); t--) {}
|
2005-07-15 14:53:44 +00:00
|
|
|
*t = 0;
|
|
|
|
s++;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-11-17 07:46:02 +00:00
|
|
|
/* Check string is valid UTF-8 */
|
2009-06-18 11:17:55 +00:00
|
|
|
const char *tmp;
|
|
|
|
for (tmp = s; *tmp != '\0';) {
|
|
|
|
size_t len = Utf8Validate(tmp);
|
|
|
|
if (len == 0) error("Invalid UTF-8 sequence in '%s'", s);
|
2010-11-19 19:38:02 +00:00
|
|
|
|
|
|
|
WChar c;
|
|
|
|
Utf8Decode(&c, tmp);
|
|
|
|
if (c <= 0x001F || // ASCII control character range
|
|
|
|
(c >= 0xE000 && c <= 0xF8FF) || // Private range
|
|
|
|
(c >= 0xFFF0 && c <= 0xFFFF)) { // Specials range
|
|
|
|
error("Unwanted UTF-8 character U+%04X in sequence '%s'", c, s);
|
|
|
|
}
|
|
|
|
|
2009-06-18 11:17:55 +00:00
|
|
|
tmp += len;
|
2006-11-17 07:46:02 +00:00
|
|
|
}
|
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* Check if the string has a case..
|
|
|
|
* The syntax for cases is IDENTNAME.case */
|
2009-06-18 11:17:55 +00:00
|
|
|
char *casep = strchr(str, '.');
|
2011-02-25 22:04:38 +00:00
|
|
|
if (casep != NULL) *casep++ = '\0';
|
2005-07-17 10:18:23 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* Check if this string already exists.. */
|
2009-06-18 11:17:55 +00:00
|
|
|
LangString *ent = HashFind(str);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (master) {
|
2010-11-07 20:57:41 +00:00
|
|
|
if (casep != NULL) {
|
|
|
|
strgen_error("Cases in the base translation are not supported.");
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-07 20:57:41 +00:00
|
|
|
if (ent != NULL) {
|
|
|
|
strgen_error("String name '%s' is used multiple times", str);
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-28 19:40:35 +00:00
|
|
|
if (_strings[_next_string_id]) {
|
|
|
|
strgen_error("String ID 0x%X for '%s' already in use by '%s'", _next_string_id, str, _strings[_next_string_id]->name);
|
|
|
|
return;
|
|
|
|
}
|
2005-07-17 10:18:23 +00:00
|
|
|
|
2010-11-28 19:40:35 +00:00
|
|
|
/* Allocate a new LangString */
|
|
|
|
ent = CallocT<LangString>(1);
|
|
|
|
_strings[_next_string_id] = ent;
|
|
|
|
ent->index = _next_string_id++;
|
|
|
|
ent->name = strdup(str);
|
|
|
|
ent->line = _cur_line;
|
2005-07-17 10:18:23 +00:00
|
|
|
|
2010-11-28 19:40:35 +00:00
|
|
|
HashAdd(str, ent);
|
2005-07-17 10:18:23 +00:00
|
|
|
|
2010-11-07 20:57:41 +00:00
|
|
|
ent->english = strdup(s);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2005-07-17 10:18:23 +00:00
|
|
|
if (ent == NULL) {
|
2008-04-18 21:33:21 +00:00
|
|
|
strgen_warning("String name '%s' does not exist in master file", str);
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-02-12 10:44:52 +00:00
|
|
|
if (ent->translated && casep == NULL) {
|
2008-04-18 21:33:21 +00:00
|
|
|
strgen_error("String name '%s' is used multiple times", str);
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-28 19:40:35 +00:00
|
|
|
/* make sure that the commands match */
|
|
|
|
if (!CheckCommandsMatch(s, ent->english, str)) return;
|
2006-02-12 10:44:52 +00:00
|
|
|
|
2010-11-28 19:40:35 +00:00
|
|
|
if (casep != NULL) {
|
|
|
|
Case *c = MallocT<Case>(1);
|
2005-07-17 10:18:23 +00:00
|
|
|
|
2010-11-28 19:40:35 +00:00
|
|
|
c->caseidx = ResolveCaseName(casep, strlen(casep));
|
|
|
|
c->string = strdup(s);
|
|
|
|
c->next = ent->translated_case;
|
|
|
|
ent->translated_case = c;
|
|
|
|
} else {
|
|
|
|
ent->translated = strdup(s);
|
|
|
|
/* If the string was translated, use the line from the
|
|
|
|
* translated language so errors in the translated file
|
|
|
|
* are properly referenced to. */
|
|
|
|
ent->line = _cur_line;
|
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);
|
2006-02-12 10:44:52 +00:00
|
|
|
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
|
|
|
|
2010-04-12 14:12:47 +00:00
|
|
|
/* Only look at the final filename to determine whether it's the base language or not */
|
2009-08-09 19:06:05 +00:00
|
|
|
const char *cur_file = strrchr(_file, PATHSEPCHAR);
|
|
|
|
const char *next_file = strrchr(file, PATHSEPCHAR);
|
|
|
|
_translation = next_file != NULL && cur_file != NULL && strcmp(cur_file, next_file) != 0;
|
2005-09-25 09:15:09 +00:00
|
|
|
_file = file;
|
|
|
|
|
2007-01-18 15:27:57 +00:00
|
|
|
/* For each new file we parse, reset the genders, and language codes */
|
2010-11-07 18:20:18 +00:00
|
|
|
MemSetT(&_lang, 0);
|
|
|
|
strecpy(_lang.digit_group_separator, ",", lastof(_lang.digit_group_separator));
|
|
|
|
strecpy(_lang.digit_group_separator_currency, ",", lastof(_lang.digit_group_separator_currency));
|
|
|
|
strecpy(_lang.digit_decimal_separator, ".", lastof(_lang.digit_decimal_separator));
|
2005-07-17 10:18:23 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
in = fopen(file, "r");
|
2008-04-18 21:33:21 +00:00
|
|
|
if (in == NULL) error("Cannot open file");
|
2004-08-09 17:04:08 +00:00
|
|
|
_cur_line = 1;
|
2007-04-18 22:10:36 +00:00
|
|
|
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);
|
2007-01-18 15:27:57 +00:00
|
|
|
|
2010-11-07 18:20:18 +00:00
|
|
|
if (StrEmpty(_lang.name) || StrEmpty(_lang.own_name) || StrEmpty(_lang.isocode)) {
|
2008-04-18 21:33:21 +00:00
|
|
|
error("Language must include ##name, ##ownname and ##isocode");
|
2007-01-18 15:27:57 +00:00
|
|
|
}
|
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)
|
|
|
|
{
|
2006-02-12 10:44:52 +00:00
|
|
|
for (; *s != '\0'; s++) {
|
|
|
|
hash = ROL(hash, 3) ^ *s;
|
2006-06-27 21:25:53 +00:00
|
|
|
hash = (hash & 1 ? hash >> 1 ^ 0xDEADBEEF : hash >> 1);
|
2005-07-15 14:53:44 +00:00
|
|
|
}
|
|
|
|
return hash;
|
|
|
|
}
|
2005-07-15 07:48:17 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* make a hash of the file to get a unique "version number" */
|
2007-03-07 11:47:46 +00:00
|
|
|
static void MakeHashOfStrings()
|
2005-07-15 14:53:44 +00:00
|
|
|
{
|
|
|
|
uint32 hash = 0;
|
2006-02-12 10:44:52 +00:00
|
|
|
uint i;
|
|
|
|
|
|
|
|
for (i = 0; i != lengthof(_strings); i++) {
|
2009-01-10 00:31:47 +00:00
|
|
|
const LangString *ls = _strings[i];
|
2006-02-12 10:44:52 +00:00
|
|
|
|
|
|
|
if (ls != NULL) {
|
2009-01-10 00:31:47 +00:00
|
|
|
const CmdStruct *cs;
|
|
|
|
const char *s;
|
2010-11-28 19:39:04 +00:00
|
|
|
char buf[MAX_COMMAND_PARAM_SIZE];
|
2006-02-12 10:44:52 +00:00
|
|
|
int argno;
|
|
|
|
int casei;
|
2005-07-15 14:53:44 +00:00
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
s = ls->name;
|
2005-07-15 14:53:44 +00:00
|
|
|
hash ^= i * 0x717239;
|
2006-06-27 21:25:53 +00:00
|
|
|
hash = (hash & 1 ? hash >> 1 ^ 0xDEADBEEF : hash >> 1);
|
2005-07-15 14:53:44 +00:00
|
|
|
hash = MyHashStr(hash, s + 1);
|
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
s = ls->english;
|
2006-02-12 10:44:52 +00:00
|
|
|
while ((cs = ParseCommandString(&s, buf, &argno, &casei)) != NULL) {
|
|
|
|
if (cs->flags & C_DONTCOUNT) continue;
|
2005-07-17 10:18:23 +00:00
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
hash ^= (cs - _cmd_structs) * 0x1234567;
|
2006-06-27 21:25:53 +00:00
|
|
|
hash = (hash & 1 ? hash >> 1 ^ 0xF00BAA4 : 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
|
|
|
|
2006-02-12 10:44:52 +00:00
|
|
|
static uint CountInUse(uint grp)
|
2005-07-15 07:48:17 +00:00
|
|
|
{
|
2004-08-09 17:04:08 +00:00
|
|
|
int i;
|
|
|
|
|
2006-02-12 10:44:52 +00:00
|
|
|
for (i = 0x800; --i >= 0;) if (_strings[(grp << 11) + i] != NULL) 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
|
|
|
{
|
2009-06-18 11:17:55 +00:00
|
|
|
FILE *f2 = fopen(n2, "rb");
|
2004-08-09 17:04:08 +00:00
|
|
|
if (f2 == NULL) return false;
|
|
|
|
|
2009-06-18 11:17:55 +00:00
|
|
|
FILE *f1 = fopen(n1, "rb");
|
2008-04-18 21:33:21 +00:00
|
|
|
if (f1 == NULL) error("can't open %s", n1);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-06-18 11:17:55 +00:00
|
|
|
size_t l1, l2;
|
2004-08-09 17:04:08 +00:00
|
|
|
do {
|
2009-06-18 11:17:55 +00:00
|
|
|
char b1[4096];
|
|
|
|
char b2[4096];
|
2004-08-09 17:04:08 +00:00
|
|
|
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;
|
|
|
|
}
|
2011-02-25 22:04:38 +00:00
|
|
|
} while (l1 != 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
int next = -1;
|
|
|
|
|
2010-02-12 23:45:25 +00:00
|
|
|
_output_filename = "tmp.xxx";
|
|
|
|
_output_file = fopen(_output_filename, "w");
|
|
|
|
if (_output_file == NULL) error("can't open tmp.xxx");
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-02-12 23:45:25 +00:00
|
|
|
fprintf(_output_file, "/* This file is automatically generated. Do not modify */\n\n");
|
|
|
|
fprintf(_output_file, "#ifndef TABLE_STRINGS_H\n");
|
|
|
|
fprintf(_output_file, "#define TABLE_STRINGS_H\n");
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-06-18 11:17:55 +00:00
|
|
|
for (int i = 0; i != lengthof(_strings); i++) {
|
2006-02-12 10:44:52 +00:00
|
|
|
if (_strings[i] != NULL) {
|
2010-02-12 23:45:25 +00:00
|
|
|
if (next != i) fprintf(_output_file, "\n");
|
|
|
|
fprintf(_output_file, "static const StringID %s = 0x%X;\n", _strings[i]->name, i);
|
2004-08-09 17:04:08 +00:00
|
|
|
next = i + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-13 09:12:52 +00:00
|
|
|
fprintf(_output_file, "\nstatic const StringID STR_LAST_STRINGID = 0x%X;\n\n", next - 1);
|
2007-10-18 20:35:59 +00:00
|
|
|
|
2010-11-16 11:42:47 +00:00
|
|
|
/* Find the plural form with the most amount of cases. */
|
|
|
|
int max_plural_forms = 0;
|
|
|
|
for (uint i = 0; i < lengthof(_plural_forms); i++) {
|
|
|
|
max_plural_forms = max(max_plural_forms, _plural_forms[i].plural_count);
|
|
|
|
}
|
|
|
|
|
2010-02-12 23:45:25 +00:00
|
|
|
fprintf(_output_file,
|
2010-11-16 11:42:47 +00:00
|
|
|
"static const uint LANGUAGE_PACK_VERSION = 0x%X;\n"
|
|
|
|
"static const uint LANGUAGE_MAX_PLURAL = %d;\n"
|
|
|
|
"static const uint LANGUAGE_MAX_PLURAL_FORMS = %d;\n\n",
|
|
|
|
(uint)_hash, (uint)lengthof(_plural_forms), max_plural_forms
|
2006-02-12 10:44:52 +00:00
|
|
|
);
|
2005-07-15 14:53:44 +00:00
|
|
|
|
2010-05-13 09:12:52 +00:00
|
|
|
fprintf(_output_file, "#endif /* TABLE_STRINGS_H */\n");
|
2007-08-03 09:08:49 +00:00
|
|
|
|
2010-02-12 23:45:25 +00:00
|
|
|
fclose(_output_file);
|
|
|
|
_output_file = NULL;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-02-12 23:45:25 +00:00
|
|
|
if (CompareFiles(_output_filename, filename)) {
|
2009-03-15 00:32:18 +00:00
|
|
|
/* files are equal. tmp.xxx is not needed */
|
2010-02-12 23:45:25 +00:00
|
|
|
unlink(_output_filename);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2009-03-15 00:32:18 +00:00
|
|
|
/* else rename tmp.xxx into filename */
|
2005-10-02 22:39:56 +00:00
|
|
|
#if defined(WIN32) || defined(WIN64)
|
2004-08-09 17:04:08 +00:00
|
|
|
unlink(filename);
|
|
|
|
#endif
|
2010-02-12 23:45:25 +00:00
|
|
|
if (rename(_output_filename, filename) == -1) error("rename() failed");
|
2005-07-15 14:53:44 +00:00
|
|
|
}
|
2010-02-12 23:45:25 +00:00
|
|
|
_output_filename = NULL;
|
2005-07-15 14:53:44 +00:00
|
|
|
}
|
|
|
|
|
2009-12-09 11:41:27 +00:00
|
|
|
static int TranslateArgumentIdx(int argidx, int offset)
|
2005-07-15 14:53:44 +00:00
|
|
|
{
|
2009-06-18 11:17:55 +00:00
|
|
|
int sum;
|
2005-07-15 14:53:44 +00:00
|
|
|
|
2009-06-18 11:17:55 +00:00
|
|
|
if (argidx < 0 || (uint)argidx >= lengthof(_cur_pcs.cmd)) {
|
2008-04-18 21:33:21 +00:00
|
|
|
error("invalid argidx %d", argidx);
|
2009-06-18 11:17:55 +00:00
|
|
|
}
|
2009-12-09 11:41:27 +00:00
|
|
|
const CmdStruct *cs = _cur_pcs.cmd[argidx];
|
|
|
|
if (cs != NULL && cs->consumes <= offset) {
|
2010-01-04 21:58:47 +00:00
|
|
|
error("invalid argidx offset %d:%d", argidx, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_cur_pcs.cmd[argidx] == NULL) {
|
|
|
|
error("no command for this argidx %d", argidx);
|
2009-12-09 11:41:27 +00:00
|
|
|
}
|
2005-07-15 14:53:44 +00:00
|
|
|
|
2009-06-18 11:17:55 +00:00
|
|
|
for (int i = sum = 0; i < argidx; i++) {
|
2005-08-28 14:45:44 +00:00
|
|
|
const CmdStruct *cs = _cur_pcs.cmd[i];
|
2009-12-09 11:41:27 +00:00
|
|
|
|
2006-02-12 10:44:52 +00:00
|
|
|
sum += (cs != NULL) ? cs->consumes : 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-07-15 14:53:44 +00:00
|
|
|
|
2009-12-09 11:41:27 +00:00
|
|
|
return sum + offset;
|
2005-07-16 17:12:32 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void PutArgidxCommand()
|
2005-07-16 17:12:32 +00:00
|
|
|
{
|
2006-11-16 22:05:33 +00:00
|
|
|
PutUtf8(SCC_ARG_INDEX);
|
2005-07-17 10:18:23 +00:00
|
|
|
PutByte(TranslateArgumentIdx(_cur_argidx));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void PutCommandString(const char *str)
|
|
|
|
{
|
|
|
|
_cur_argidx = 0;
|
|
|
|
|
|
|
|
while (*str != '\0') {
|
2009-03-15 00:32:18 +00:00
|
|
|
/* Process characters as they are until we encounter a { */
|
2005-07-17 10:18:23 +00:00
|
|
|
if (*str != '{') {
|
|
|
|
PutByte(*str++);
|
|
|
|
continue;
|
|
|
|
}
|
2009-06-18 11:17:55 +00:00
|
|
|
|
2010-11-28 19:39:04 +00:00
|
|
|
char param[MAX_COMMAND_PARAM_SIZE];
|
2009-06-18 11:17:55 +00:00
|
|
|
int argno;
|
|
|
|
int casei;
|
|
|
|
const CmdStruct *cs = ParseCommandString(&str, param, &argno, &casei);
|
2005-07-17 10:18:23 +00:00
|
|
|
if (cs == NULL) break;
|
|
|
|
|
|
|
|
if (casei != -1) {
|
2006-11-16 22:05:33 +00:00
|
|
|
PutUtf8(SCC_SETCASE); // {SETCASE}
|
2005-07-17 10:18:23 +00:00
|
|
|
PutByte(casei);
|
|
|
|
}
|
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* For params that consume values, we need to handle the argindex properly */
|
2006-02-12 10:44:52 +00:00
|
|
|
if (cs->consumes > 0) {
|
2009-03-15 00:32:18 +00:00
|
|
|
/* Check if we need to output a move-param command */
|
2006-02-12 10:44:52 +00:00
|
|
|
if (argno != -1 && argno != _cur_argidx) {
|
2005-07-17 10:18:23 +00:00
|
|
|
_cur_argidx = argno;
|
|
|
|
PutArgidxCommand();
|
|
|
|
}
|
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* Output the one from the master string... it's always accurate. */
|
2005-07-17 10:18:23 +00:00
|
|
|
cs = _cur_pcs.cmd[_cur_argidx++];
|
2006-02-12 10:44:52 +00:00
|
|
|
if (cs == NULL) {
|
2008-04-18 21:33:21 +00:00
|
|
|
error("%s: No argument exists at position %d", _cur_ident, _cur_argidx - 1);
|
2006-02-12 10:44:52 +00:00
|
|
|
}
|
2005-07-17 10:18:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2008-04-18 21:33:21 +00:00
|
|
|
error("string too long");
|
2005-07-17 10:18:23 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-07-15 14:53:44 +00:00
|
|
|
|
2007-06-28 22:58:59 +00:00
|
|
|
static void WriteLangfile(const char *filename)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-02-12 10:44:52 +00:00
|
|
|
uint in_use[32];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2010-02-12 23:45:25 +00:00
|
|
|
_output_filename = filename;
|
|
|
|
_output_file = fopen(filename, "wb");
|
|
|
|
if (_output_file == NULL) error("can't open %s", filename);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-06-18 11:17:55 +00:00
|
|
|
for (int i = 0; i != 32; i++) {
|
2006-02-12 10:44:52 +00:00
|
|
|
uint n = CountInUse(i);
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
in_use[i] = n;
|
2010-11-07 18:20:18 +00:00
|
|
|
_lang.offsets[i] = TO_LE16(n);
|
2011-08-21 19:21:38 +00:00
|
|
|
|
|
|
|
for (uint j = 0; j != in_use[i]; j++) {
|
|
|
|
const LangString *ls = _strings[(i << 11) + j];
|
|
|
|
if (ls != NULL && ls->translated == NULL) _lang.missing++;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2010-11-07 18:35:59 +00:00
|
|
|
_lang.ident = TO_LE32(LanguagePackHeader::IDENT);
|
2010-11-07 18:20:18 +00:00
|
|
|
_lang.version = TO_LE32(_hash);
|
2011-08-21 19:21:38 +00:00
|
|
|
_lang.missing = TO_LE16(_lang.missing);
|
2010-11-07 18:20:18 +00:00
|
|
|
_lang.winlangid = TO_LE16(_lang.winlangid);
|
|
|
|
|
|
|
|
fwrite(&_lang, sizeof(_lang), 1, _output_file);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-06-18 11:17:55 +00:00
|
|
|
for (int i = 0; i != 32; i++) {
|
2009-06-22 20:35:14 +00:00
|
|
|
for (uint j = 0; j != in_use[i]; j++) {
|
2009-01-10 00:31:47 +00:00
|
|
|
const LangString *ls = _strings[(i << 11) + j];
|
|
|
|
const Case *casep;
|
|
|
|
const char *cmdp;
|
2005-07-15 14:53:44 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* For undefined strings, just set that it's an empty string */
|
2005-07-17 10:18:23 +00:00
|
|
|
if (ls == NULL) {
|
2010-02-12 23:45:25 +00:00
|
|
|
WriteLength(_output_file, 0);
|
2005-07-15 14:53:44 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
_cur_ident = ls->name;
|
2005-10-30 00:16:48 +00:00
|
|
|
_cur_line = ls->line;
|
2005-07-16 17:12:32 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* Produce a message if a string doesn't have a translation. */
|
2007-06-28 22:58:59 +00:00
|
|
|
if (_show_todo > 0 && ls->translated == NULL) {
|
|
|
|
if ((_show_todo & 2) != 0) {
|
2008-04-18 21:33:21 +00:00
|
|
|
strgen_warning("'%s' is untranslated", ls->name);
|
2007-06-28 22:58:59 +00:00
|
|
|
}
|
|
|
|
if ((_show_todo & 1) != 0) {
|
2005-07-15 14:53:44 +00:00
|
|
|
const char *s = "<TODO> ";
|
2006-02-12 10:44:52 +00:00
|
|
|
while (*s != '\0') PutByte(*s++);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-07-15 14:53:44 +00:00
|
|
|
}
|
|
|
|
|
2009-03-15 00:32:18 +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);
|
|
|
|
|
2006-02-12 10:44:52 +00:00
|
|
|
if (ls->translated_case != NULL || ls->translated != NULL) {
|
2005-07-17 10:18:23 +00:00
|
|
|
casep = ls->translated_case;
|
|
|
|
cmdp = ls->translated;
|
|
|
|
} else {
|
2010-11-07 20:57:41 +00:00
|
|
|
casep = NULL;
|
2005-07-17 10:18:23 +00:00
|
|
|
cmdp = ls->english;
|
|
|
|
}
|
2005-07-15 14:53:44 +00:00
|
|
|
|
2005-11-02 23:55:10 +00:00
|
|
|
_translated = _masterlang || (cmdp != ls->english);
|
2005-11-02 23:31:04 +00:00
|
|
|
|
2006-02-12 10:44:52 +00:00
|
|
|
if (casep != NULL) {
|
2009-01-10 00:31:47 +00:00
|
|
|
const Case *c;
|
2006-02-12 10:44:52 +00:00
|
|
|
uint num;
|
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* 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. */
|
2006-11-16 22:05:33 +00:00
|
|
|
PutUtf8(SCC_SWITCH_CASE);
|
2009-03-15 00:32:18 +00:00
|
|
|
/* Count the number of cases */
|
2006-02-01 07:36:15 +00:00
|
|
|
for (num = 0, c = casep; c; c = c->next) num++;
|
2005-07-17 10:18:23 +00:00
|
|
|
PutByte(num);
|
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
/* Write each case */
|
2006-02-12 10:44:52 +00:00
|
|
|
for (c = casep; c != NULL; c = c->next) {
|
2010-12-12 01:21:02 +00:00
|
|
|
uint pos;
|
2006-02-12 10:44:52 +00:00
|
|
|
|
2005-07-17 10:18:23 +00:00
|
|
|
PutByte(c->caseidx);
|
2009-03-15 00:32:18 +00:00
|
|
|
/* Make some space for the 16-bit length */
|
2005-07-17 10:18:23 +00:00
|
|
|
pos = _put_pos;
|
|
|
|
PutByte(0);
|
|
|
|
PutByte(0);
|
2009-03-15 00:32:18 +00:00
|
|
|
/* Write string */
|
2005-07-17 10:18:23 +00:00
|
|
|
PutCommandString(c->string);
|
|
|
|
PutByte(0); // terminate with a zero
|
2009-03-15 00:32:18 +00:00
|
|
|
/* Fill in the length */
|
2006-02-12 10:44:52 +00:00
|
|
|
_put_buf[pos + 0] = GB(_put_pos - (pos + 2), 8, 8);
|
|
|
|
_put_buf[pos + 1] = GB(_put_pos - (pos + 2), 0, 8);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2005-07-15 14:53:44 +00:00
|
|
|
|
2006-02-12 10:44:52 +00:00
|
|
|
if (cmdp != NULL) PutCommandString(cmdp);
|
2005-07-17 10:18:23 +00:00
|
|
|
|
2010-02-12 23:45:25 +00:00
|
|
|
WriteLength(_output_file, _put_pos);
|
|
|
|
fwrite(_put_buf, 1, _put_pos, _output_file);
|
2005-07-15 14:53:44 +00:00
|
|
|
_put_pos = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-12 23:45:25 +00:00
|
|
|
fputc(0, _output_file);
|
|
|
|
fclose(_output_file);
|
|
|
|
|
|
|
|
_output_file = NULL;
|
|
|
|
_output_filename = NULL;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-08-24 12:08:25 +00:00
|
|
|
/** Multi-OS mkdirectory function */
|
|
|
|
static inline void ottd_mkdir(const char *directory)
|
|
|
|
{
|
|
|
|
#if defined(WIN32) || defined(__WATCOMC__)
|
|
|
|
mkdir(directory);
|
|
|
|
#else
|
|
|
|
mkdir(directory, 0755);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Create a path consisting of an already existing path, a possible
|
2006-08-24 12:08:25 +00:00
|
|
|
* path seperator and the filename. The seperator is only appended if the path
|
2010-08-01 19:44:49 +00:00
|
|
|
* does not already end with a seperator
|
|
|
|
*/
|
2006-08-24 12:08:25 +00:00
|
|
|
static inline char *mkpath(char *buf, size_t buflen, const char *path, const char *file)
|
|
|
|
{
|
|
|
|
ttd_strlcpy(buf, path, buflen); // copy directory into buffer
|
|
|
|
|
2009-06-18 11:17:55 +00:00
|
|
|
char *p = strchr(buf, '\0'); // add path seperator if necessary
|
2006-08-24 12:08:25 +00:00
|
|
|
if (p[-1] != PATHSEPCHAR && (size_t)(p - buf) + 1 < buflen) *p++ = PATHSEPCHAR;
|
|
|
|
ttd_strlcpy(p, file, buflen - (size_t)(p - buf)); // catenate filename at end of buffer
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2007-01-03 13:55:25 +00:00
|
|
|
#if defined(__MINGW32__)
|
2006-08-25 12:26:34 +00:00
|
|
|
/**
|
|
|
|
* On MingW, it is common that both / as \ are accepted in the
|
|
|
|
* params. To go with those flow, we rewrite all incoming /
|
|
|
|
* simply to \, so internally we can safely assume \.
|
|
|
|
*/
|
|
|
|
static inline char *replace_pathsep(char *s)
|
|
|
|
{
|
2009-06-18 11:17:55 +00:00
|
|
|
for (char *c = s; *c != '\0'; c++) if (*c == '/') *c = '\\';
|
2006-08-25 12:26:34 +00:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline char *replace_pathsep(char *s) { return s; }
|
|
|
|
#endif
|
2005-07-15 14:53:44 +00:00
|
|
|
|
2011-02-18 20:52:42 +00:00
|
|
|
/** Options of strgen. */
|
|
|
|
static const OptionData _opts[] = {
|
|
|
|
GETOPT_NOVAL( 'v', "--version"),
|
|
|
|
GETOPT_GENERAL('C', '\0', "-export-commands", ODF_NO_VALUE),
|
|
|
|
GETOPT_GENERAL('L', '\0', "-export-plurals", ODF_NO_VALUE),
|
|
|
|
GETOPT_GENERAL('P', '\0', "-export-pragmas", ODF_NO_VALUE),
|
|
|
|
GETOPT_NOVAL( 't', "--todo"),
|
|
|
|
GETOPT_NOVAL( 'w', "--warning"),
|
|
|
|
GETOPT_NOVAL( 'h', "--help"),
|
|
|
|
GETOPT_GENERAL('h', '?', NULL, ODF_NO_VALUE),
|
|
|
|
GETOPT_VALUE( 's', "--source_dir"),
|
|
|
|
GETOPT_VALUE( 'd', "--dest_dir"),
|
|
|
|
GETOPT_END(),
|
|
|
|
};
|
|
|
|
|
2009-01-10 00:31:47 +00:00
|
|
|
int CDECL main(int argc, char *argv[])
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-04-04 00:06:51 +00:00
|
|
|
char pathbuf[MAX_PATH];
|
2006-08-30 20:08:58 +00:00
|
|
|
const char *src_dir = ".";
|
|
|
|
const char *dest_dir = NULL;
|
2006-08-24 12:08:25 +00:00
|
|
|
|
2011-02-18 20:52:42 +00:00
|
|
|
GetOptData mgo(argc - 1, argv + 1, _opts);
|
|
|
|
for (;;) {
|
|
|
|
int i = mgo.GetOpt();
|
|
|
|
if (i == -1) break;
|
|
|
|
|
|
|
|
switch (i) {
|
|
|
|
case 'v':
|
|
|
|
puts("$Revision$");
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case 'C':
|
|
|
|
printf("args\tflags\tcommand\treplacement\n");
|
|
|
|
for (const CmdStruct *cs = _cmd_structs; cs < endof(_cmd_structs); cs++) {
|
|
|
|
char flags;
|
|
|
|
switch (cs->value) {
|
|
|
|
case 0x200E: case 0x200F: // Implicit BIDI controls
|
|
|
|
case 0x202A: case 0x202B: case 0x202C: case 0x202D: case 0x202E: // Explicit BIDI controls
|
|
|
|
case 0xA0: // Non breaking space
|
|
|
|
case '\n': // Newlines may be added too
|
|
|
|
case '{': // This special
|
|
|
|
/* This command may be in the translation when it is not in base */
|
|
|
|
flags = 'i';
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (cs->proc == EmitGender) {
|
|
|
|
flags = 'g'; // Command needs number of parameters defined by number of genders
|
|
|
|
} else if (cs->proc == EmitPlural) {
|
|
|
|
flags = 'p'; // Command needs number of parameters defined by plural value
|
|
|
|
} else {
|
|
|
|
flags = '0'; // Command needs no parameters
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("%i\t%c\t\"%s\"\t\"%s\"\n", cs->consumes, flags, cs->cmd, strstr(cs->cmd, "STRING") ? "STRING" : cs->cmd);
|
2009-04-23 13:32:13 +00:00
|
|
|
}
|
2011-02-18 20:52:42 +00:00
|
|
|
return 0;
|
2009-04-21 21:34:26 +00:00
|
|
|
|
2011-02-18 20:52:42 +00:00
|
|
|
case 'L':
|
|
|
|
printf("count\tdescription\n");
|
|
|
|
for (const PluralForm *pf = _plural_forms; pf < endof(_plural_forms); pf++) {
|
|
|
|
printf("%i\t\"%s\"\n", pf->plural_count, pf->description);
|
|
|
|
}
|
|
|
|
return 0;
|
2009-04-21 21:34:26 +00:00
|
|
|
|
2011-02-18 20:52:42 +00:00
|
|
|
case 'P':
|
|
|
|
printf("name\tflags\tdefault\tdescription\n");
|
|
|
|
for (size_t i = 0; i < lengthof(_pragmas); i++) {
|
|
|
|
printf("\"%s\"\t%s\t\"%s\"\t\"%s\"\n",
|
|
|
|
_pragmas[i][0], _pragmas[i][1], _pragmas[i][2], _pragmas[i][3]);
|
|
|
|
}
|
|
|
|
return 0;
|
2009-04-25 21:09:42 +00:00
|
|
|
|
2011-02-18 20:52:42 +00:00
|
|
|
case 't':
|
|
|
|
_show_todo |= 1;
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2011-02-18 20:52:42 +00:00
|
|
|
case 'w':
|
|
|
|
_show_todo |= 2;
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2011-02-18 20:52:42 +00:00
|
|
|
case 'h':
|
|
|
|
puts(
|
|
|
|
"strgen - $Revision$\n"
|
|
|
|
" -v | --version print version information and exit\n"
|
|
|
|
" -t | --todo replace any untranslated strings with '<TODO>'\n"
|
|
|
|
" -w | --warning print a warning for any untranslated strings\n"
|
|
|
|
" -h | -? | --help print this help message and exit\n"
|
|
|
|
" -s | --source_dir search for english.txt in the specified directory\n"
|
|
|
|
" -d | --dest_dir put output file in the specified directory, create if needed\n"
|
|
|
|
" -export-commands export all commands and exit\n"
|
|
|
|
" -export-plurals export all plural forms and exit\n"
|
|
|
|
" -export-pragmas export all pragmas and exit\n"
|
|
|
|
" Run without parameters and strgen will search for english.txt and parse it,\n"
|
|
|
|
" creating strings.h. Passing an argument, strgen will translate that language\n"
|
|
|
|
" file using english.txt as a reference and output <language>.lng."
|
|
|
|
);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case 's':
|
|
|
|
src_dir = replace_pathsep(mgo.opt);
|
|
|
|
break;
|
2006-01-28 11:10:52 +00:00
|
|
|
|
2011-02-18 20:52:42 +00:00
|
|
|
case 'd':
|
|
|
|
dest_dir = replace_pathsep(mgo.opt);
|
|
|
|
break;
|
2006-08-24 12:08:25 +00:00
|
|
|
|
2011-02-18 20:52:42 +00:00
|
|
|
case -2:
|
|
|
|
fprintf(stderr, "Invalid arguments\n");
|
|
|
|
return 0;
|
2006-08-30 20:08:58 +00:00
|
|
|
}
|
2006-08-24 12:08:25 +00:00
|
|
|
}
|
|
|
|
|
2006-08-30 20:08:58 +00:00
|
|
|
if (dest_dir == NULL) dest_dir = src_dir; // if dest_dir is not specified, it equals src_dir
|
|
|
|
|
2006-08-24 12:08:25 +00:00
|
|
|
/* strgen has two modes of operation. If no (free) arguments are passed
|
|
|
|
* strgen generates strings.h to the destination directory. If it is supplied
|
|
|
|
* with a (free) parameter the program will translate that language to destination
|
|
|
|
* directory. As input english.txt is parsed from the source directory */
|
2011-02-18 20:52:42 +00:00
|
|
|
if (mgo.numleft == 0) {
|
2006-08-24 12:08:25 +00:00
|
|
|
mkpath(pathbuf, lengthof(pathbuf), src_dir, "english.txt");
|
|
|
|
|
|
|
|
/* parse master file */
|
2005-11-02 23:55:10 +00:00
|
|
|
_masterlang = true;
|
2006-08-24 12:08:25 +00:00
|
|
|
ParseFile(pathbuf, true);
|
2005-07-15 14:53:44 +00:00
|
|
|
MakeHashOfStrings();
|
2011-02-25 22:04:38 +00:00
|
|
|
if (_errors != 0) return 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-24 12:08:25 +00:00
|
|
|
/* write strings.h */
|
|
|
|
ottd_mkdir(dest_dir);
|
|
|
|
mkpath(pathbuf, lengthof(pathbuf), dest_dir, "strings.h");
|
|
|
|
WriteStringsH(pathbuf);
|
2011-02-18 20:52:42 +00:00
|
|
|
} else if (mgo.numleft == 1) {
|
2006-08-24 12:08:25 +00:00
|
|
|
char *r;
|
2006-02-12 10:44:52 +00:00
|
|
|
|
2006-08-24 12:08:25 +00:00
|
|
|
mkpath(pathbuf, lengthof(pathbuf), src_dir, "english.txt");
|
|
|
|
|
|
|
|
/* parse master file and check if target file is correct */
|
2005-11-02 23:55:10 +00:00
|
|
|
_masterlang = false;
|
2006-08-24 12:08:25 +00:00
|
|
|
ParseFile(pathbuf, true);
|
2005-07-15 14:53:44 +00:00
|
|
|
MakeHashOfStrings();
|
2011-02-18 20:52:42 +00:00
|
|
|
ParseFile(replace_pathsep(mgo.argv[0]), false); // target file
|
2011-02-25 22:04:38 +00:00
|
|
|
if (_errors != 0) return 1;
|
2005-07-15 07:48:17 +00:00
|
|
|
|
2006-08-24 12:08:25 +00:00
|
|
|
/* get the targetfile, strip any directories and append to destination path */
|
2011-02-18 20:52:42 +00:00
|
|
|
r = strrchr(mgo.argv[0], PATHSEPCHAR);
|
|
|
|
mkpath(pathbuf, lengthof(pathbuf), dest_dir, (r != NULL) ? &r[1] : mgo.argv[0]);
|
2006-08-24 12:08:25 +00:00
|
|
|
|
|
|
|
/* rename the .txt (input-extension) to .lng */
|
|
|
|
r = strrchr(pathbuf, '.');
|
|
|
|
if (r == NULL || strcmp(r, ".txt") != 0) r = strchr(pathbuf, '\0');
|
|
|
|
ttd_strlcpy(r, ".lng", (size_t)(r - pathbuf));
|
2007-06-28 22:58:59 +00:00
|
|
|
WriteLangfile(pathbuf);
|
2006-12-22 01:18:56 +00:00
|
|
|
|
|
|
|
/* if showing warnings, print a summary of the language */
|
2007-06-28 22:58:59 +00:00
|
|
|
if ((_show_todo & 2) != 0) {
|
2006-12-31 11:25:06 +00:00
|
|
|
fprintf(stdout, "%d warnings and %d errors for %s\n", _warnings, _errors, pathbuf);
|
2006-12-22 01:18:56 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2006-08-24 12:08:25 +00:00
|
|
|
fprintf(stderr, "Invalid arguments\n");
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|