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