src/strings.h
branchNewGRF_ports
changeset 6872 1c4a4a609f85
parent 6871 5a9dc001e1ad
child 6873 86bf4ccb580d
equal deleted inserted replaced
6871:5a9dc001e1ad 6872:1c4a4a609f85
     1 /* $Id$ */
       
     2 
       
     3 /** @file strings.h */
       
     4 
       
     5 #ifndef STRINGS_H
       
     6 #define STRINGS_H
       
     7 
       
     8 char *InlineString(char *buf, StringID string);
       
     9 char *GetString(char *buffr, StringID string, const char *last);
       
    10 
       
    11 extern char _userstring[128];
       
    12 
       
    13 void InjectDParam(int amount);
       
    14 
       
    15 static inline void SetDParamX(uint64 *s, uint n, uint64 v)
       
    16 {
       
    17 	s[n] = v;
       
    18 }
       
    19 
       
    20 static inline void SetDParam(uint n, uint64 v)
       
    21 {
       
    22 	extern uint64 _decode_parameters[20];
       
    23 
       
    24 	assert(n < lengthof(_decode_parameters));
       
    25 	_decode_parameters[n] = v;
       
    26 }
       
    27 
       
    28 /* Used to bind a C string name to a dparam number.
       
    29  * NOTE: This has a short lifetime. You can't
       
    30  *       use this string much later or it will be gone. */
       
    31 void SetDParamStr(uint n, const char *str);
       
    32 
       
    33 /** This function takes a C-string and allocates a temporary string ID.
       
    34  * The duration of the bound string is valid only until the next call to GetString,
       
    35  * so be careful. */
       
    36 StringID BindCString(const char *str);
       
    37 
       
    38 static inline uint64 GetDParamX(const uint64 *s, uint n)
       
    39 {
       
    40 	return s[n];
       
    41 }
       
    42 
       
    43 static inline uint64 GetDParam(uint n)
       
    44 {
       
    45 	extern uint64 _decode_parameters[20];
       
    46 
       
    47 	assert(n < lengthof(_decode_parameters));
       
    48 	return _decode_parameters[n];
       
    49 }
       
    50 
       
    51 static inline void CopyInDParam(int offs, const uint64 *src, int num)
       
    52 {
       
    53 	extern uint64 _decode_parameters[20];
       
    54 	memcpy(_decode_parameters + offs, src, sizeof(uint64) * (num));
       
    55 }
       
    56 
       
    57 static inline void CopyOutDParam(uint64 *dst, int offs, int num)
       
    58 {
       
    59 	extern uint64 _decode_parameters[20];
       
    60 	memcpy(dst, _decode_parameters + offs, sizeof(uint64) * (num));
       
    61 }
       
    62 
       
    63 
       
    64 /** Information about a language */
       
    65 struct Language {
       
    66 	char *name; ///< The internal name of the language
       
    67 	char *file; ///< The name of the language as it appears on disk
       
    68 };
       
    69 
       
    70 /** Used for dynamic language support */
       
    71 struct DynamicLanguages {
       
    72 	int num;                         ///< Number of languages
       
    73 	int curr;                        ///< Currently selected language index
       
    74 	char curr_file[MAX_PATH];        ///< Currently selected language file name without path (needed for saving the filename of the loaded language).
       
    75 	StringID dropdown[MAX_LANG + 1]; ///< List of languages in the settings gui
       
    76 	Language ent[MAX_LANG];          ///< Information about the languages
       
    77 };
       
    78 
       
    79 extern DynamicLanguages _dynlang; // defined in strings.cpp
       
    80 
       
    81 bool ReadLanguagePack(int index);
       
    82 void InitializeLanguagePacks();
       
    83 
       
    84 int CDECL StringIDSorter(const void *a, const void *b);
       
    85 
       
    86 #endif /* STRINGS_H */