# strgen_tables.h

Go to the documentation of this file.

    00001 /* $Id$ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00012 #include "../core/enum_type.hpp"
    00013
    00014 enum CmdFlags {
    00015   C_NONE      = 0x0,
    00016   C_DONTCOUNT = 0x1,
    00017   C_CASE      = 0x2,
    00018   C_GENDER    = 0x4,
    00019 };
    00020 DECLARE_ENUM_AS_BIT_SET(CmdFlags)
    00021
    00022 typedef void (*ParseCmdProc)(char *buf, int value);
    00023
    00024 struct CmdStruct {
    00025   const char *cmd;
    00026   ParseCmdProc proc;
    00027   long value;
    00028   uint8 consumes;
    00029   CmdFlags flags;
    00030 };
    00031
    00032 static void EmitSingleChar(char *buf, int value);
    00033 static void EmitPlural(char *buf, int value);
    00034 static void EmitGender(char *buf, int value);
    00035
    00036 static const CmdStruct _cmd_structs[] = {
    00037   /* Font size */
    00038   {"TINYFONT",        EmitSingleChar, SCC_TINYFONT,           0, C_NONE},
    00039   {"BIGFONT",         EmitSingleChar, SCC_BIGFONT,            0, C_NONE},
    00040
    00041   /* Colors */
    00042   {"BLUE",            EmitSingleChar, SCC_BLUE,               0, C_NONE},
    00043   {"SILVER",          EmitSingleChar, SCC_SILVER,             0, C_NONE},
    00044   {"GOLD",            EmitSingleChar, SCC_GOLD,               0, C_NONE},
    00045   {"RED",             EmitSingleChar, SCC_RED,                0, C_NONE},
    00046   {"PURPLE",          EmitSingleChar, SCC_PURPLE,             0, C_NONE},
    00047   {"LTBROWN",         EmitSingleChar, SCC_LTBROWN,            0, C_NONE},
    00048   {"ORANGE",          EmitSingleChar, SCC_ORANGE,             0, C_NONE},
    00049   {"GREEN",           EmitSingleChar, SCC_GREEN,              0, C_NONE},
    00050   {"YELLOW",          EmitSingleChar, SCC_YELLOW,             0, C_NONE},
    00051   {"DKGREEN",         EmitSingleChar, SCC_DKGREEN,            0, C_NONE},
    00052   {"CREAM",           EmitSingleChar, SCC_CREAM,              0, C_NONE},
    00053   {"BROWN",           EmitSingleChar, SCC_BROWN,              0, C_NONE},
    00054   {"WHITE",           EmitSingleChar, SCC_WHITE,              0, C_NONE},
    00055   {"LTBLUE",          EmitSingleChar, SCC_LTBLUE,             0, C_NONE},
    00056   {"GRAY",            EmitSingleChar, SCC_GRAY,               0, C_NONE},
    00057   {"DKBLUE",          EmitSingleChar, SCC_DKBLUE,             0, C_NONE},
    00058   {"BLACK",           EmitSingleChar, SCC_BLACK,              0, C_NONE},
    00059
    00060   {"CURRCOMPACT",     EmitSingleChar, SCC_CURRENCY_COMPACT,   1, C_NONE}, // compact currency
    00061   {"REV",             EmitSingleChar, SCC_REVISION,           0, C_NONE}, // openttd revision string
    00062   {"SHORTCARGO",      EmitSingleChar, SCC_CARGO_SHORT,        2, C_NONE}, // short cargo description, only ### tons, or ### litres
    00063
    00064   {"STRING1",         EmitSingleChar, SCC_STRING1,            2, C_CASE | C_GENDER}, // included string that consumes the string id and ONE argument
    00065   {"STRING2",         EmitSingleChar, SCC_STRING2,            3, C_CASE | C_GENDER}, // included string that consumes the string id and TWO arguments
    00066   {"STRING3",         EmitSingleChar, SCC_STRING3,            4, C_CASE | C_GENDER}, // included string that consumes the string id and THREE arguments
    00067   {"STRING4",         EmitSingleChar, SCC_STRING4,            5, C_CASE | C_GENDER}, // included string that consumes the string id and FOUR arguments
    00068   {"STRING5",         EmitSingleChar, SCC_STRING5,            6, C_CASE | C_GENDER}, // included string that consumes the string id and FIVE arguments
    00069
    00070   {"STATIONFEATURES", EmitSingleChar, SCC_STATION_FEATURES,   1, C_NONE}, // station features string, icons of the features
    00071   {"INDUSTRY",        EmitSingleChar, SCC_INDUSTRY_NAME,      1, C_CASE | C_GENDER}, // industry, takes an industry #, can have cases
    00072   {"CARGO",           EmitSingleChar, SCC_CARGO,              2, C_NONE | C_GENDER},
    00073   {"POWER",           EmitSingleChar, SCC_POWER,              1, C_NONE},
    00074   {"VOLUME",          EmitSingleChar, SCC_VOLUME,             1, C_NONE},
    00075   {"VOLUME_S",        EmitSingleChar, SCC_VOLUME_SHORT,       1, C_NONE},
    00076   {"WEIGHT",          EmitSingleChar, SCC_WEIGHT,             1, C_NONE},
    00077   {"WEIGHT_S",        EmitSingleChar, SCC_WEIGHT_SHORT,       1, C_NONE},
    00078   {"FORCE",           EmitSingleChar, SCC_FORCE,              1, C_NONE},
    00079   {"VELOCITY",        EmitSingleChar, SCC_VELOCITY,           1, C_NONE},
    00080   {"HEIGHT",          EmitSingleChar, SCC_HEIGHT,             1, C_NONE},
    00081
    00082   {"P",               EmitPlural,     0,                      0, C_DONTCOUNT}, // plural specifier
    00083   {"G",               EmitGender,     0,                      0, C_DONTCOUNT}, // gender specifier
    00084
    00085   {"DATE_TINY",       EmitSingleChar, SCC_DATE_TINY,          1, C_NONE},
    00086   {"DATE_SHORT",      EmitSingleChar, SCC_DATE_SHORT,         1, C_CASE},
    00087   {"DATE_LONG",       EmitSingleChar, SCC_DATE_LONG,          1, C_CASE},
    00088   {"DATE_ISO",        EmitSingleChar, SCC_DATE_ISO,           1, C_NONE},
    00089
    00090   {"STRING",          EmitSingleChar, SCC_STRING,             1, C_CASE | C_GENDER},
    00091   {"RAW_STRING",      EmitSingleChar, SCC_RAW_STRING_POINTER, 1, C_NONE | C_GENDER},
    00092
    00093   /* Numbers */
    00094   {"COMMA",           EmitSingleChar, SCC_COMMA,              1, C_NONE}, // Number with comma
    00095   {"NUM",             EmitSingleChar, SCC_NUM,                1, C_NONE}, // Signed number
    00096   {"ZEROFILL_NUM",    EmitSingleChar, SCC_ZEROFILL_NUM,       2, C_NONE}, // Unsigned number with zero fill, e.g. "02". First parameter is number, second minimum length
    00097   {"BYTES",           EmitSingleChar, SCC_BYTES,              1, C_NONE}, // Unsigned number with "bytes", i.e. "1.02 MiB or 123 KiB"
    00098   {"HEX",             EmitSingleChar, SCC_HEX,                1, C_NONE}, // Hexadecimally printed number
    00099
    00100   {"CURRENCY",        EmitSingleChar, SCC_CURRENCY,           1, C_NONE},
    00101
    00102   {"WAYPOINT",        EmitSingleChar, SCC_WAYPOINT_NAME,      1, C_NONE | C_GENDER}, // waypoint name
    00103   {"STATION",         EmitSingleChar, SCC_STATION_NAME,       1, C_NONE | C_GENDER},
    00104   {"DEPOT",           EmitSingleChar, SCC_DEPOT_NAME,         2, C_NONE | C_GENDER},
    00105   {"TOWN",            EmitSingleChar, SCC_TOWN_NAME,          1, C_NONE | C_GENDER},
    00106   {"GROUP",           EmitSingleChar, SCC_GROUP_NAME,         1, C_NONE | C_GENDER},
    00107   {"SIGN",            EmitSingleChar, SCC_SIGN_NAME,          1, C_NONE | C_GENDER},
    00108   {"ENGINE",          EmitSingleChar, SCC_ENGINE_NAME,        1, C_NONE | C_GENDER},
    00109   {"VEHICLE",         EmitSingleChar, SCC_VEHICLE_NAME,       1, C_NONE | C_GENDER},
    00110   {"COMPANY",         EmitSingleChar, SCC_COMPANY_NAME,       1, C_NONE | C_GENDER},
    00111   {"COMPANYNUM",      EmitSingleChar, SCC_COMPANY_NUM,        1, C_NONE},
    00112   {"PRESIDENTNAME",   EmitSingleChar, SCC_PRESIDENT_NAME,     1, C_NONE | C_GENDER},
    00113
    00114   {"",                EmitSingleChar, '\n',                   0, C_DONTCOUNT},
    00115   {"{",               EmitSingleChar, '{',                    0, C_DONTCOUNT},
    00116   {"UPARROW",         EmitSingleChar, SCC_UPARROW,            0, C_DONTCOUNT},
    00117   {"SMALLUPARROW",    EmitSingleChar, SCC_SMALLUPARROW,       0, C_DONTCOUNT},
    00118   {"SMALLDOWNARROW",  EmitSingleChar, SCC_SMALLDOWNARROW,     0, C_DONTCOUNT},
    00119   {"TRAIN",           EmitSingleChar, SCC_TRAIN,              0, C_DONTCOUNT},
    00120   {"LORRY",           EmitSingleChar, SCC_LORRY,              0, C_DONTCOUNT},
    00121   {"BUS",             EmitSingleChar, SCC_BUS,                0, C_DONTCOUNT},
    00122   {"PLANE",           EmitSingleChar, SCC_PLANE,              0, C_DONTCOUNT},
    00123   {"SHIP",            EmitSingleChar, SCC_SHIP,               0, C_DONTCOUNT},
    00124   {"NBSP",            EmitSingleChar, 0xA0,                   0, C_DONTCOUNT},
    00125   {"CENT",            EmitSingleChar, 0xA2,                   0, C_DONTCOUNT},
    00126   {"POUNDSIGN",       EmitSingleChar, 0xA3,                   0, C_DONTCOUNT},
    00127   {"EURO",            EmitSingleChar, 0x20AC,                 0, C_DONTCOUNT},
    00128   {"YENSIGN",         EmitSingleChar, 0xA5,                   0, C_DONTCOUNT},
    00129   {"COPYRIGHT",       EmitSingleChar, 0xA9,                   0, C_DONTCOUNT},
    00130   {"DOWNARROW",       EmitSingleChar, SCC_DOWNARROW,          0, C_DONTCOUNT},
    00131   {"CHECKMARK",       EmitSingleChar, SCC_CHECKMARK,          0, C_DONTCOUNT},
    00132   {"CROSS",           EmitSingleChar, SCC_CROSS,              0, C_DONTCOUNT},
    00133   {"REGISTERED",      EmitSingleChar, 0xAE,                   0, C_DONTCOUNT},
    00134   {"RIGHTARROW",      EmitSingleChar, SCC_RIGHTARROW,         0, C_DONTCOUNT},
    00135   {"SMALLLEFTARROW",  EmitSingleChar, SCC_LESSTHAN,           0, C_DONTCOUNT},
    00136   {"SMALLRIGHTARROW", EmitSingleChar, SCC_GREATERTHAN,        0, C_DONTCOUNT},
    00137
    00138   /* The following are directional formatting codes used to get the RTL strings right:
    00139    * http://www.unicode.org/unicode/reports/tr9/#Directional_Formatting_Codes */
    00140   {"LRM",             EmitSingleChar, CHAR_TD_LRM,            0, C_DONTCOUNT},
    00141   {"RLM",             EmitSingleChar, CHAR_TD_RLM,            0, C_DONTCOUNT},
    00142   {"LRE",             EmitSingleChar, CHAR_TD_LRE,            0, C_DONTCOUNT},
    00143   {"RLE",             EmitSingleChar, CHAR_TD_RLE,            0, C_DONTCOUNT},
    00144   {"LRO",             EmitSingleChar, CHAR_TD_LRO,            0, C_DONTCOUNT},
    00145   {"RLO",             EmitSingleChar, CHAR_TD_RLO,            0, C_DONTCOUNT},
    00146   {"PDF",             EmitSingleChar, CHAR_TD_PDF,            0, C_DONTCOUNT},
    00147 };
    00148
    00150 struct PluralForm {
    00151   int plural_count;
    00152   const char *description;
    00153 };
    00154
    00156 static const PluralForm _plural_forms[] = {
    00157   { 2, "Two forms, singular used for 1 only" },
    00158   { 1, "Only one form" },
    00159   { 2, "Two forms, singular used for zero and 1" },
    00160   { 3, "Three forms, special case for 0 and ending in 1, except those ending in 11" },
    00161   { 5, "Five forms, special case for one, two, 3 to 6 and 7 to 10" },
    00162   { 3, "Three forms, special case for numbers ending in 1[2-9]" },
    00163   { 3, "Three forms, special cases for numbers ending in 1 and 2, 3, 4, except those ending in 1[1-4]" },
    00164   { 3, "Three forms, special case for 1 and some numbers ending in 2, 3, or 4" },
    00165   { 4, "Four forms, special case for 1 and all numbers ending in 02, 03, or 04" },
    00166   { 2, "Two forms, singular used for everything ending in 1 but not in 11" },
    00167   { 3, "Three forms, special case for 1 and 2, 3, or 4" },
    00168   { 2, "Two forms, cases for numbers ending with a consonant and with a vowel" },
    00169   { 4, "Four forms: one, 0 and everything ending in 02..10, everything ending in 11..19" },
    00170 };
    00171
    00172 /* Flags:
    00173  * 0 = nothing
    00174  * t = translator editable
    00175  * l = ltr/rtl choice
    00176  * p = plural choice
    00177  * d = separator char (replace spaces with {NBSP})
    00178  * x1 = hexadecimal number of 1 byte
    00179  * x2 = hexadecimal number of 2 bytes
    00180  * g = gender
    00181  * c = cases
    00182  * a = array, i.e. list of strings
    00183  */
    00185 static const char * const _pragmas[][4] = {
    00186   /*  name         flags  default   description */
    00187   { "name",        "0",   "",       "English name for the language" },
    00188   { "ownname",     "t",   "",       "Localised name for the language" },
    00189   { "isocode",     "0",   "",       "ISO code for the language" },
    00190   { "plural",      "tp",  "0",      "Plural form to use" },
    00191   { "textdir",     "tl",  "ltr",    "Text direction. Either ltr (left-to-right) or rtl (right-to-left)" },
    00192   { "digitsep",    "td",  ",",      "Digit grouping separator for non-currency numbers" },
    00193   { "digitsepcur", "td",  ",",      "Digit grouping seprarator for currency numbers" },
    00194   { "decimalsep",  "td",  ".",      "Decimal separator" },
    00195   { "winlangid",   "x2",  "0x0000", "Language ID for Windows" },
    00196   { "grflangid",   "x1",  "0x00",   "Language ID for NewGRFs" },
    00197   { "gender",      "tag", "",       "List of genders" },
    00198   { "case",        "tac", "",       "List of cases" },
    00199 };