OpenTTD Source  12.0-beta2
strgen.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * 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.
4  * 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.
5  * 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/>.
6  */
7 
10 #include "../stdafx.h"
11 #include "../core/endian_func.hpp"
12 #include "../string_func.h"
13 #include "../strings_type.h"
14 #include "../misc/getoptdata.h"
15 #include "../table/control_codes.h"
16 
17 #include "strgen.h"
18 
19 #include <stdarg.h>
20 #include <exception>
21 
22 #if !defined(_WIN32) || defined(__CYGWIN__)
23 #include <unistd.h>
24 #include <sys/stat.h>
25 #endif
26 
27 #if defined(_WIN32) || defined(__WATCOMC__)
28 #include <direct.h>
29 #endif /* _WIN32 || __WATCOMC__ */
30 
31 #include "../table/strgen_tables.h"
32 
33 #include "../safeguards.h"
34 
35 
36 #ifdef _MSC_VER
37 # define LINE_NUM_FMT(s) "%s (%d): warning: %s (" s ")\n"
38 #else
39 # define LINE_NUM_FMT(s) "%s:%d: " s ": %s\n"
40 #endif
41 
42 void CDECL strgen_warning(const char *s, ...)
43 {
44  char buf[1024];
45  va_list va;
46  va_start(va, s);
47  vseprintf(buf, lastof(buf), s, va);
48  va_end(va);
49  if (_show_todo > 0) {
50  fprintf(stderr, LINE_NUM_FMT("warning"), _file, _cur_line, buf);
51  } else {
52  fprintf(stderr, LINE_NUM_FMT("info"), _file, _cur_line, buf);
53  }
54  _warnings++;
55 }
56 
57 void CDECL strgen_error(const char *s, ...)
58 {
59  char buf[1024];
60  va_list va;
61  va_start(va, s);
62  vseprintf(buf, lastof(buf), s, va);
63  va_end(va);
64  fprintf(stderr, LINE_NUM_FMT("error"), _file, _cur_line, buf);
65  _errors++;
66 }
67 
68 void NORETURN CDECL strgen_fatal(const char *s, ...)
69 {
70  char buf[1024];
71  va_list va;
72  va_start(va, s);
73  vseprintf(buf, lastof(buf), s, va);
74  va_end(va);
75  fprintf(stderr, LINE_NUM_FMT("FATAL"), _file, _cur_line, buf);
76 #ifdef _MSC_VER
77  fprintf(stderr, LINE_NUM_FMT("warning"), _file, _cur_line, "language is not compiled");
78 #endif
79  throw std::exception();
80 }
81 
82 void NORETURN CDECL error(const char *s, ...)
83 {
84  char buf[1024];
85  va_list va;
86  va_start(va, s);
87  vseprintf(buf, lastof(buf), s, va);
88  va_end(va);
89  fprintf(stderr, LINE_NUM_FMT("FATAL"), _file, _cur_line, buf);
90 #ifdef _MSC_VER
91  fprintf(stderr, LINE_NUM_FMT("warning"), _file, _cur_line, "language is not compiled");
92 #endif
93  exit(2);
94 }
95 
98  FILE *fh;
99 
107  FileStringReader(StringData &data, const char *file, bool master, bool translation) :
109  {
110  this->fh = fopen(file, "rb");
111  if (this->fh == nullptr) error("Could not open %s", file);
112  }
113 
116  {
117  fclose(this->fh);
118  }
119 
120  char *ReadLine(char *buffer, const char *last) override
121  {
122  return fgets(buffer, ClampToU16(last - buffer + 1), this->fh);
123  }
124 
125  void HandlePragma(char *str) override;
126 
127  void ParseFile() override
128  {
129  this->StringReader::ParseFile();
130 
132  error("Language must include ##name, ##ownname and ##isocode");
133  }
134  }
135 };
136 
138 {
139  if (!memcmp(str, "id ", 3)) {
140  this->data.next_string_id = strtoul(str + 3, nullptr, 0);
141  } else if (!memcmp(str, "name ", 5)) {
142  strecpy(_lang.name, str + 5, lastof(_lang.name));
143  } else if (!memcmp(str, "ownname ", 8)) {
145  } else if (!memcmp(str, "isocode ", 8)) {
146  strecpy(_lang.isocode, str + 8, lastof(_lang.isocode));
147  } else if (!memcmp(str, "textdir ", 8)) {
148  if (!memcmp(str + 8, "ltr", 3)) {
150  } else if (!memcmp(str + 8, "rtl", 3)) {
152  } else {
153  error("Invalid textdir %s", str + 8);
154  }
155  } else if (!memcmp(str, "digitsep ", 9)) {
156  str += 9;
157  strecpy(_lang.digit_group_separator, strcmp(str, "{NBSP}") == 0 ? NBSP : str, lastof(_lang.digit_group_separator));
158  } else if (!memcmp(str, "digitsepcur ", 12)) {
159  str += 12;
161  } else if (!memcmp(str, "decimalsep ", 11)) {
162  str += 11;
163  strecpy(_lang.digit_decimal_separator, strcmp(str, "{NBSP}") == 0 ? NBSP : str, lastof(_lang.digit_decimal_separator));
164  } else if (!memcmp(str, "winlangid ", 10)) {
165  const char *buf = str + 10;
166  long langid = strtol(buf, nullptr, 16);
167  if (langid > (long)UINT16_MAX || langid < 0) {
168  error("Invalid winlangid %s", buf);
169  }
170  _lang.winlangid = (uint16)langid;
171  } else if (!memcmp(str, "grflangid ", 10)) {
172  const char *buf = str + 10;
173  long langid = strtol(buf, nullptr, 16);
174  if (langid >= 0x7F || langid < 0) {
175  error("Invalid grflangid %s", buf);
176  }
177  _lang.newgrflangid = (uint8)langid;
178  } else if (!memcmp(str, "gender ", 7)) {
179  if (this->master) error("Genders are not allowed in the base translation.");
180  char *buf = str + 7;
181 
182  for (;;) {
183  const char *s = ParseWord(&buf);
184 
185  if (s == nullptr) break;
186  if (_lang.num_genders >= MAX_NUM_GENDERS) error("Too many genders, max %d", MAX_NUM_GENDERS);
188  _lang.num_genders++;
189  }
190  } else if (!memcmp(str, "case ", 5)) {
191  if (this->master) error("Cases are not allowed in the base translation.");
192  char *buf = str + 5;
193 
194  for (;;) {
195  const char *s = ParseWord(&buf);
196 
197  if (s == nullptr) break;
198  if (_lang.num_cases >= MAX_NUM_CASES) error("Too many cases, max %d", MAX_NUM_CASES);
200  _lang.num_cases++;
201  }
202  } else {
204  }
205 }
206 
207 bool CompareFiles(const char *n1, const char *n2)
208 {
209  FILE *f2 = fopen(n2, "rb");
210  if (f2 == nullptr) return false;
211 
212  FILE *f1 = fopen(n1, "rb");
213  if (f1 == nullptr) {
214  fclose(f2);
215  error("can't open %s", n1);
216  }
217 
218  size_t l1, l2;
219  do {
220  char b1[4096];
221  char b2[4096];
222  l1 = fread(b1, 1, sizeof(b1), f1);
223  l2 = fread(b2, 1, sizeof(b2), f2);
224 
225  if (l1 != l2 || memcmp(b1, b2, l1)) {
226  fclose(f2);
227  fclose(f1);
228  return false;
229  }
230  } while (l1 != 0);
231 
232  fclose(f2);
233  fclose(f1);
234  return true;
235 }
236 
238 struct FileWriter {
239  FILE *fh;
240  const char *filename;
241 
246  FileWriter(const char *filename)
247  {
248  this->filename = stredup(filename);
249  this->fh = fopen(this->filename, "wb");
250 
251  if (this->fh == nullptr) {
252  error("Could not open %s", this->filename);
253  }
254  }
255 
257  void Finalise()
258  {
259  fclose(this->fh);
260  this->fh = nullptr;
261  }
262 
264  virtual ~FileWriter()
265  {
266  /* If we weren't closed an exception was thrown, so remove the temporary file. */
267  if (fh != nullptr) {
268  fclose(this->fh);
269  unlink(this->filename);
270  }
271  free(this->filename);
272  }
273 };
274 
277  const char *real_filename;
279  int prev;
280  uint total_strings;
281 
286  HeaderFileWriter(const char *filename) : FileWriter("tmp.xxx"),
287  real_filename(stredup(filename)), prev(0), total_strings(0)
288  {
289  fprintf(this->fh, "/* This file is automatically generated. Do not modify */\n\n");
290  fprintf(this->fh, "#ifndef TABLE_STRINGS_H\n");
291  fprintf(this->fh, "#define TABLE_STRINGS_H\n");
292  }
293 
296  {
297  free(real_filename);
298  }
299 
300  void WriteStringID(const char *name, int stringid)
301  {
302  if (prev + 1 != stringid) fprintf(this->fh, "\n");
303  fprintf(this->fh, "static const StringID %s = 0x%X;\n", name, stringid);
304  prev = stringid;
305  total_strings++;
306  }
307 
308  void Finalise(const StringData &data)
309  {
310  /* Find the plural form with the most amount of cases. */
311  int max_plural_forms = 0;
312  for (uint i = 0; i < lengthof(_plural_forms); i++) {
313  max_plural_forms = std::max(max_plural_forms, _plural_forms[i].plural_count);
314  }
315 
316  fprintf(this->fh,
317  "\n"
318  "static const uint LANGUAGE_PACK_VERSION = 0x%X;\n"
319  "static const uint LANGUAGE_MAX_PLURAL = %u;\n"
320  "static const uint LANGUAGE_MAX_PLURAL_FORMS = %d;\n"
321  "static const uint LANGUAGE_TOTAL_STRINGS = %u;\n"
322  "\n",
323  (uint)data.Version(), (uint)lengthof(_plural_forms), max_plural_forms, total_strings
324  );
325 
326  fprintf(this->fh, "#endif /* TABLE_STRINGS_H */\n");
327 
328  this->FileWriter::Finalise();
329 
330  if (CompareFiles(this->filename, this->real_filename)) {
331  /* files are equal. tmp.xxx is not needed */
332  unlink(this->filename);
333  } else {
334  /* else rename tmp.xxx into filename */
335 # if defined(_WIN32)
336  unlink(this->real_filename);
337 # endif
338  if (rename(this->filename, this->real_filename) == -1) error("rename() failed");
339  }
340  }
341 };
342 
350  {
351  }
352 
353  void WriteHeader(const LanguagePackHeader *header)
354  {
355  this->Write((const byte *)header, sizeof(*header));
356  }
357 
358  void Finalise()
359  {
360  if (fputc(0, this->fh) == EOF) {
361  error("Could not write to %s", this->filename);
362  }
363  this->FileWriter::Finalise();
364  }
365 
366  void Write(const byte *buffer, size_t length)
367  {
368  if (fwrite(buffer, sizeof(*buffer), length, this->fh) != length) {
369  error("Could not write to %s", this->filename);
370  }
371  }
372 };
373 
375 static inline void ottd_mkdir(const char *directory)
376 {
377  /* Ignore directory creation errors; they'll surface later on, and most
378  * of the time they are 'directory already exists' errors anyhow. */
379 #if defined(_WIN32) || defined(__WATCOMC__)
380  mkdir(directory);
381 #else
382  mkdir(directory, 0755);
383 #endif
384 }
385 
391 static inline char *mkpath(char *buf, const char *last, const char *path, const char *file)
392 {
393  strecpy(buf, path, last); // copy directory into buffer
394 
395  char *p = strchr(buf, '\0'); // add path separator if necessary
396  if (p[-1] != PATHSEPCHAR && p != last) *p++ = PATHSEPCHAR;
397  strecpy(p, file, last); // concatenate filename at end of buffer
398  return buf;
399 }
400 
401 #if defined(_WIN32)
402 
409 static inline char *replace_pathsep(char *s)
410 {
411  for (char *c = s; *c != '\0'; c++) if (*c == '/') *c = '\\';
412  return s;
413 }
414 #else
415 static inline char *replace_pathsep(char *s) { return s; }
416 #endif
417 
419 static const OptionData _opts[] = {
420  GETOPT_NOVAL( 'v', "--version"),
421  GETOPT_GENERAL('C', '\0', "-export-commands", ODF_NO_VALUE),
422  GETOPT_GENERAL('L', '\0', "-export-plurals", ODF_NO_VALUE),
423  GETOPT_GENERAL('P', '\0', "-export-pragmas", ODF_NO_VALUE),
424  GETOPT_NOVAL( 't', "--todo"),
425  GETOPT_NOVAL( 'w', "--warning"),
426  GETOPT_NOVAL( 'h', "--help"),
427  GETOPT_GENERAL('h', '?', nullptr, ODF_NO_VALUE),
428  GETOPT_VALUE( 's', "--source_dir"),
429  GETOPT_VALUE( 'd', "--dest_dir"),
430  GETOPT_END(),
431 };
432 
433 int CDECL main(int argc, char *argv[])
434 {
435  char pathbuf[MAX_PATH];
436  const char *src_dir = ".";
437  const char *dest_dir = nullptr;
438 
439  GetOptData mgo(argc - 1, argv + 1, _opts);
440  for (;;) {
441  int i = mgo.GetOpt();
442  if (i == -1) break;
443 
444  switch (i) {
445  case 'v':
446  puts("$Revision$");
447  return 0;
448 
449  case 'C':
450  printf("args\tflags\tcommand\treplacement\n");
451  for (const CmdStruct *cs = _cmd_structs; cs < endof(_cmd_structs); cs++) {
452  char flags;
453  if (cs->proc == EmitGender) {
454  flags = 'g'; // Command needs number of parameters defined by number of genders
455  } else if (cs->proc == EmitPlural) {
456  flags = 'p'; // Command needs number of parameters defined by plural value
457  } else if (cs->flags & C_DONTCOUNT) {
458  flags = 'i'; // Command may be in the translation when it is not in base
459  } else {
460  flags = '0'; // Command needs no parameters
461  }
462  printf("%i\t%c\t\"%s\"\t\"%s\"\n", cs->consumes, flags, cs->cmd, strstr(cs->cmd, "STRING") ? "STRING" : cs->cmd);
463  }
464  return 0;
465 
466  case 'L':
467  printf("count\tdescription\tnames\n");
468  for (const PluralForm *pf = _plural_forms; pf < endof(_plural_forms); pf++) {
469  printf("%i\t\"%s\"\t%s\n", pf->plural_count, pf->description, pf->names);
470  }
471  return 0;
472 
473  case 'P':
474  printf("name\tflags\tdefault\tdescription\n");
475  for (size_t i = 0; i < lengthof(_pragmas); i++) {
476  printf("\"%s\"\t%s\t\"%s\"\t\"%s\"\n",
477  _pragmas[i][0], _pragmas[i][1], _pragmas[i][2], _pragmas[i][3]);
478  }
479  return 0;
480 
481  case 't':
482  _show_todo |= 1;
483  break;
484 
485  case 'w':
486  _show_todo |= 2;
487  break;
488 
489  case 'h':
490  puts(
491  "strgen - $Revision$\n"
492  " -v | --version print version information and exit\n"
493  " -t | --todo replace any untranslated strings with '<TODO>'\n"
494  " -w | --warning print a warning for any untranslated strings\n"
495  " -h | -? | --help print this help message and exit\n"
496  " -s | --source_dir search for english.txt in the specified directory\n"
497  " -d | --dest_dir put output file in the specified directory, create if needed\n"
498  " -export-commands export all commands and exit\n"
499  " -export-plurals export all plural forms and exit\n"
500  " -export-pragmas export all pragmas and exit\n"
501  " Run without parameters and strgen will search for english.txt and parse it,\n"
502  " creating strings.h. Passing an argument, strgen will translate that language\n"
503  " file using english.txt as a reference and output <language>.lng."
504  );
505  return 0;
506 
507  case 's':
508  src_dir = replace_pathsep(mgo.opt);
509  break;
510 
511  case 'd':
512  dest_dir = replace_pathsep(mgo.opt);
513  break;
514 
515  case -2:
516  fprintf(stderr, "Invalid arguments\n");
517  return 0;
518  }
519  }
520 
521  if (dest_dir == nullptr) dest_dir = src_dir; // if dest_dir is not specified, it equals src_dir
522 
523  try {
524  /* strgen has two modes of operation. If no (free) arguments are passed
525  * strgen generates strings.h to the destination directory. If it is supplied
526  * with a (free) parameter the program will translate that language to destination
527  * directory. As input english.txt is parsed from the source directory */
528  if (mgo.numleft == 0) {
529  mkpath(pathbuf, lastof(pathbuf), src_dir, "english.txt");
530 
531  /* parse master file */
532  StringData data(TEXT_TAB_END);
533  FileStringReader master_reader(data, pathbuf, true, false);
534  master_reader.ParseFile();
535  if (_errors != 0) return 1;
536 
537  /* write strings.h */
538  ottd_mkdir(dest_dir);
539  mkpath(pathbuf, lastof(pathbuf), dest_dir, "strings.h");
540 
541  HeaderFileWriter writer(pathbuf);
542  writer.WriteHeader(data);
543  writer.Finalise(data);
544  if (_errors != 0) return 1;
545  } else if (mgo.numleft >= 1) {
546  char *r;
547 
548  mkpath(pathbuf, lastof(pathbuf), src_dir, "english.txt");
549 
550  StringData data(TEXT_TAB_END);
551  /* parse master file and check if target file is correct */
552  FileStringReader master_reader(data, pathbuf, true, false);
553  master_reader.ParseFile();
554 
555  for (int i = 0; i < mgo.numleft; i++) {
556  data.FreeTranslation();
557 
558  const char *translation = replace_pathsep(mgo.argv[i]);
559  const char *file = strrchr(translation, PATHSEPCHAR);
560  FileStringReader translation_reader(data, translation, false, file == nullptr || strcmp(file + 1, "english.txt") != 0);
561  translation_reader.ParseFile(); // target file
562  if (_errors != 0) return 1;
563 
564  /* get the targetfile, strip any directories and append to destination path */
565  r = strrchr(mgo.argv[i], PATHSEPCHAR);
566  mkpath(pathbuf, lastof(pathbuf), dest_dir, (r != nullptr) ? &r[1] : mgo.argv[i]);
567 
568  /* rename the .txt (input-extension) to .lng */
569  r = strrchr(pathbuf, '.');
570  if (r == nullptr || strcmp(r, ".txt") != 0) r = strchr(pathbuf, '\0');
571  strecpy(r, ".lng", lastof(pathbuf));
572 
573  LanguageFileWriter writer(pathbuf);
574  writer.WriteLang(data);
575  writer.Finalise();
576 
577  /* if showing warnings, print a summary of the language */
578  if ((_show_todo & 2) != 0) {
579  fprintf(stdout, "%d warnings and %d errors for %s\n", _warnings, _errors, pathbuf);
580  }
581  }
582  }
583  } catch (...) {
584  return 2;
585  }
586 
587  return 0;
588 }
_file
const char * _file
The filename of the input, so we can refer to it in errors/warnings.
Definition: strgen_base.cpp:26
LanguagePackHeader::text_dir
byte text_dir
default direction of the text
Definition: language.h:42
StringReader::HandlePragma
virtual void HandlePragma(char *str)
Handle the pragma of the file.
Definition: strgen_base.cpp:797
MAX_NUM_GENDERS
static const uint8 MAX_NUM_GENDERS
Maximum number of supported genders.
Definition: language.h:20
HeaderFileWriter::Finalise
void Finalise(const StringData &data)
Finalise writing the file.
Definition: strgen.cpp:308
CompareFiles
static bool CompareFiles(const char *n1, const char *n2)
Compare two files for identity.
Definition: settingsgen.cpp:380
TEXT_TAB_END
@ TEXT_TAB_END
End of language files.
Definition: strings_type.h:38
_opts
static const OptionData _opts[]
Options of strgen.
Definition: strgen.cpp:419
TD_LTR
@ TD_LTR
Text is written left-to-right by default.
Definition: strings_type.h:23
LanguageFileWriter::WriteHeader
void WriteHeader(const LanguagePackHeader *header)
Write the header metadata.
Definition: strgen.cpp:353
LanguageFileWriter
Class for writing a language to disk.
Definition: strgen.cpp:344
PluralForm
Description of a plural form.
Definition: strgen_tables.h:154
GETOPT_VALUE
#define GETOPT_VALUE(shortname, longname)
Short option with value.
Definition: getoptdata.h:76
HeaderWriter
Base class for writing the header, i.e.
Definition: strgen.h:91
LanguagePackHeader::genders
char genders[MAX_NUM_GENDERS][CASE_GENDER_LEN]
the genders used by this translation
Definition: language.h:57
_lang
LanguagePackHeader _lang
Header information about a language.
Definition: strgen_base.cpp:29
C_DONTCOUNT
@ C_DONTCOUNT
These commands aren't counted for comparison.
Definition: strgen_tables.h:14
LanguagePackHeader::num_cases
uint8 num_cases
the number of cases of this language
Definition: language.h:54
_cur_line
int _cur_line
The current line we're parsing in the input file.
Definition: strgen_base.cpp:27
FileStringReader::HandlePragma
void HandlePragma(char *str) override
Handle the pragma of the file.
Definition: strgen.cpp:137
LanguageFileWriter::Write
void Write(const byte *buffer, size_t length)
Write a number of bytes.
Definition: strgen.cpp:366
HeaderFileWriter::prev
int prev
The previous string ID that was printed.
Definition: strgen.cpp:279
StringReader::master
bool master
Are we reading the master file?
Definition: strgen.h:63
FileStringReader::FileStringReader
FileStringReader(StringData &data, const char *file, bool master, bool translation)
Create the reader.
Definition: strgen.cpp:107
StringData::next_string_id
size_t next_string_id
The next string ID to allocate.
Definition: strgen.h:46
NBSP
#define NBSP
A non-breaking space.
Definition: string_type.h:18
FileWriter::filename
const char * filename
The file name we're writing to.
Definition: strgen.cpp:240
LanguagePackHeader::cases
char cases[MAX_NUM_CASES][CASE_GENDER_LEN]
the cases used by this translation
Definition: language.h:58
StringData::Version
uint Version() const
Make a hash of the file to get a unique "version number".
Definition: strgen_base.cpp:175
FileStringReader::~FileStringReader
virtual ~FileStringReader()
Free/close the file.
Definition: strgen.cpp:115
HeaderFileWriter
Definition: strgen.cpp:275
LanguagePackHeader::newgrflangid
uint8 newgrflangid
newgrf language id
Definition: language.h:52
mkpath
static char * mkpath(char *buf, const char *last, const char *path, const char *file)
Create a path consisting of an already existing path, a possible path separator and the filename.
Definition: strgen.cpp:391
StringData
Information about the currently known strings.
Definition: strgen.h:41
HeaderFileWriter::real_filename
const char * real_filename
The real file name we eventually want to write to.
Definition: strgen.cpp:277
GETOPT_NOVAL
#define GETOPT_NOVAL(shortname, longname)
Short option without value.
Definition: getoptdata.h:69
GETOPT_END
#define GETOPT_END()
Option terminator.
Definition: getoptdata.h:107
strgen.h
GETOPT_GENERAL
#define GETOPT_GENERAL(id, shortname, longname, flags)
General macro for creating an option.
Definition: getoptdata.h:62
LanguagePackHeader::name
char name[32]
the international name of this language
Definition: language.h:29
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:64
ottd_mkdir
static void ottd_mkdir(const char *directory)
Multi-OS mkdirectory function.
Definition: strgen.cpp:375
vseprintf
int CDECL vseprintf(char *str, const char *last, const char *format, va_list ap)
Safer implementation of vsnprintf; same as vsnprintf except:
Definition: string.cpp:61
CmdStruct
Definition: strgen_tables.h:23
FileStringReader
A reader that simply reads using fopen.
Definition: strgen.cpp:97
FileWriter::FileWriter
FileWriter(const char *filename)
Open a file to write to.
Definition: strgen.cpp:246
OptionData
Data of an option.
Definition: getoptdata.h:22
LanguagePackHeader::digit_decimal_separator
char digit_decimal_separator[8]
Decimal separator.
Definition: language.h:39
LanguagePackHeader::own_name
char own_name[32]
the localized name of this language
Definition: language.h:30
GetOptData
Data storage for parsing command line options.
Definition: getoptdata.h:30
LanguagePackHeader::isocode
char isocode[16]
the ISO code for the language (not country code)
Definition: language.h:31
main
int CDECL main(int argc, char *argv[])
And the main program (what else?)
Definition: settingsgen.cpp:455
FileStringReader::ParseFile
void ParseFile() override
Start parsing the file.
Definition: strgen.cpp:127
_pragmas
static const char *const _pragmas[][4]
All pragmas used.
Definition: strgen_tables.h:195
endof
#define endof(x)
Get the end element of an fixed size array.
Definition: stdafx.h:386
FileStringReader::ReadLine
char * ReadLine(char *buffer, const char *last) override
Read a single line from the source of strings.
Definition: strgen.cpp:120
StringReader::data
StringData & data
The data to fill during reading.
Definition: strgen.h:61
LanguagePackHeader::digit_group_separator_currency
char digit_group_separator_currency[8]
Thousand separator used for currencies.
Definition: language.h:37
LanguagePackHeader::winlangid
uint16 winlangid
Windows language ID: Windows cannot and will not convert isocodes to something it can use to determin...
Definition: language.h:51
LanguageFileWriter::LanguageFileWriter
LanguageFileWriter(const char *filename)
Open a file to write to.
Definition: strgen.cpp:349
FileStringReader::fh
FILE * fh
The file we are reading.
Definition: strgen.cpp:98
StringReader::translation
bool translation
Are we reading a translation, implies !master. However, the base translation will have this false.
Definition: strgen.h:64
HeaderFileWriter::WriteStringID
void WriteStringID(const char *name, int stringid)
Write the string ID.
Definition: strgen.cpp:300
StringReader::ParseFile
virtual void ParseFile()
Start parsing the file.
Definition: strgen_base.cpp:816
stredup
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Definition: string.cpp:137
LanguagePackHeader::num_genders
uint8 num_genders
the number of genders of this language
Definition: language.h:53
error
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
Definition: openttd.cpp:132
HeaderFileWriter::~HeaderFileWriter
~HeaderFileWriter()
Free the filename.
Definition: strgen.cpp:295
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:378
LanguageWriter
Base class for all language writers.
Definition: strgen.h:112
LanguageFileWriter::Finalise
void Finalise()
Finalise writing the file.
Definition: strgen.cpp:358
LanguagePackHeader::digit_group_separator
char digit_group_separator[8]
Thousand separator used for anything not currencies.
Definition: language.h:35
ClampToU16
static uint16 ClampToU16(const uint64 a)
Reduce an unsigned 64-bit int to an unsigned 16-bit one.
Definition: math_func.hpp:153
StringReader::file
const char * file
The file we are reading.
Definition: strgen.h:62
strecpy
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Definition: string.cpp:112
FileWriter::~FileWriter
virtual ~FileWriter()
Make sure the file is closed.
Definition: strgen.cpp:264
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:460
FileWriter::Finalise
void Finalise()
Finalise the writing.
Definition: strgen.cpp:257
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:394
MAX_NUM_CASES
static const uint8 MAX_NUM_CASES
Maximum number of supported cases.
Definition: language.h:21
_plural_forms
static const PluralForm _plural_forms[]
All plural forms used.
Definition: strgen_tables.h:164
ODF_NO_VALUE
@ ODF_NO_VALUE
A plain option (no value attached to it).
Definition: getoptdata.h:15
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
StringReader
Helper for reading strings.
Definition: strgen.h:60
FileWriter::fh
FILE * fh
The file handle we're writing to.
Definition: strgen.cpp:239
HeaderFileWriter::HeaderFileWriter
HeaderFileWriter(const char *filename)
Open a file to write to.
Definition: strgen.cpp:286
LanguagePackHeader
Header of a language file.
Definition: language.h:24
FileWriter
Yes, simply writing to a file.
Definition: saveload.cpp:2380