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