# strgen.cpp File Reference

Tool to create computer readable (stand-alone) translation files. More...

`#include "../stdafx.h"`
`#include "../core/alloc_func.hpp"`
`#include "../core/endian_func.hpp"`
`#include "../string_func.h"`
`#include "../strings_type.h"`
`#include "strgen.h"`
`#include "../table/control_codes.h"`
`#include <stdarg.h>`
`#include <unistd.h>`
`#include <sys/stat.h>`
`#include "../table/strgen_tables.h"`

Go to the source code of this file.

## Data Structures

struct | Case
struct | LangString
struct | CmdPair
struct | ParsedCommandStruct

## Defines

#define | HASH_SIZE 32767
#define | MAX_NUM_GENDER 8
#define | MAX_NUM_CASES 50
#define | LINE_NUM_FMT(s) "%s: :%d: " s ": %s\n"

## Functions

static uint | HashStr (const char *s)
static void | HashAdd (const char *s, LangString *ls)
static LangString * | HashFind (const char *s)
static void CDECL | strgen_warning (const char *s,...) WARN_FORMAT(1
static void CDECL | strgen_error (const char *s,...) WARN_FORMAT(1
void NORETURN CDECL | error (const char *s,...)
static void | PutByte (byte c)
static void | PutUtf8 (uint32 value)
size_t | Utf8Validate (const char *s)
static void | EmitSingleChar (char *buf, int value)
bool | ParseRelNum (char **buf, int *value, int *offset)
char * | ParseWord (char **buf)
static int | TranslateArgumentIdx (int arg, int offset=0)
static void | EmitWordList (const char *const *words, uint nw)
static void | EmitPlural (char *buf, int value)
static void | EmitGender (char *buf, int value)
static const CmdStruct * | FindCmd (const char *s, int len)
static uint | ResolveCaseName (const char *str, uint len)
static const CmdStruct * | ParseCommandString (const char **str, char *param, int *argno, int *casei)
static void | HandlePragma (char *str)
static void | ExtractCommandString (ParsedCommandStruct *p, const char *s, bool warnings)
static const CmdStruct * | TranslateCmdForCompare (const CmdStruct *a)
static bool | CheckCommandsMatch (char *a, char *b, const char *name)
static void | HandleString (char *str, bool master)
static void | rstrip (char *buf)
static void | ParseFile (const char *file, bool english)
static uint32 | MyHashStr (uint32 hash, const char *s)
static void | MakeHashOfStrings ()
static uint | CountInUse (uint grp)
bool | CompareFiles (const char *n1, const char *n2)
static void | WriteStringsH (const char *filename)
static void | PutArgidxCommand ()
static void | PutCommandString (const char *str)
static void | WriteLength (FILE *f, uint length)
static void | WriteLangfile (const char *filename)
static void | ottd_mkdir (const char *directory)
| Multi-OS mkdirectory function.
static char * | mkpath (char *buf, size_t buflen, const char *path, const char *file)
| Create a path consisting of an already existing path, a possible path seperator and the filename.
static char * | replace_pathsep (char *s)
int CDECL | main (int argc, char *argv[])

## Variables

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.
static int | _errors
static int | _warnings
static int | _show_todo
static LangString * | _strings [65536]
static uint16 | _hash_head [HASH_SIZE]
static byte | _put_buf [4096]
static int | _put_pos
static int | _next_string_id
static uint32 | _hash
static char | _lang_name [32]
static char | _lang_ownname [32]
static char | _lang_isocode [16]
static char | _lang_digit_group_separator [8]
static char | _lang_digit_group_separator_currency [8]
static char | _lang_digit_decimal_separator [8]
static byte | _lang_pluralform
static byte | _lang_textdir
static uint16 | _lang_winlangid
static uint8 | _lang_newgrflangid
static char | _genders [MAX_NUM_GENDER][16]
static uint | _numgenders
static char | _cases [MAX_NUM_CASES][16]
static uint | _numcases
static const char * | _cur_ident
static ParsedCommandStruct | _cur_pcs
static int | _cur_argidx

## Detailed Description

Tool to create computer readable (stand-alone) translation files.

Definition in file strgen.cpp.

## Function Documentation

static char* mkpath | ( | char * | buf,
|  | size_t | buflen,
|  | const char * | path,
|  | const char * | file |
| ) |  |  | `[inline, static]`

Create a path consisting of an already existing path, a possible path seperator and the filename.

The seperator is only appended if the path does not already end with a seperator

Definition at line 1189 of file strgen.cpp.

References ttd_strlcpy().