Data Structures | Defines | Functions | Variables

strgen.cpp File Reference

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

#include "../stdafx.h"
#include "../core/endian_func.hpp"
#include "../string_func.h"
#include "../strings_type.h"
#include "../language.h"
#include "../misc/getoptdata.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 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 LangStringHashFind (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 CmdStructFindCmd (const char *s, int len)
static uint ResolveCaseName (const char *str, uint len)
static const CmdStructParseCommandString (const char **str, char *param, int *argno, int *casei)
static void HandlePragma (char *str, bool master)
static void ExtractCommandString (ParsedCommandStruct *p, const char *s, bool warnings)
static const CmdStructTranslateCmdForCompare (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 const ptrdiff_t MAX_COMMAND_PARAM_SIZE = 100
 Maximum size of every command block, not counting the name of the command itself.
static LangString_strings [65536]
static LanguagePackHeader _lang
 Header information about a language.
static uint16 _hash_head [HASH_SIZE]
static byte _put_buf [4096]
static uint _put_pos
static int _next_string_id
static uint32 _hash
static const char * _cur_ident
static ParsedCommandStruct _cur_pcs
static int _cur_argidx
static const OptionData _opts []
 Options of strgen.

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 1172 of file strgen.cpp.

References ttd_strlcpy().


Variable Documentation

const OptionData _opts[] [static]
Initial value:
 {
    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(),
}

Options of strgen.

Definition at line 1198 of file strgen.cpp.