| 121 | } |
| 122 | |
| 123 | static void String_Load(const char *filename, bool compressed, int start, int end) |
| 124 | { |
| 125 | uint8 *buf; |
| 126 | uint16 count; |
| 127 | uint16 i; |
| 128 | char decomp_buffer[1024]; |
| 129 | |
| 130 | buf = File_ReadWholeFile(String_GenerateFilename(filename)); |
| 131 | count = READ_LE_UINT16(buf) / 2; |
| 132 | |
| 133 | if (end < 0) end = start + count - 1; |
| 134 | |
| 135 | s_strings = (char **)realloc(s_strings, (end + 1) * sizeof(char *)); |
| 136 | s_strings[s_stringsCount] = NULL; |
| 137 | |
| 138 | for (i = 0; i < count && s_stringsCount <= end; i++) { |
| 139 | char *src = (char *)buf + READ_LE_UINT16(buf + i * 2); |
| 140 | char *dst; |
| 141 | |
| 142 | if (compressed) { |
| 143 | uint16 len; |
| 144 | len = String_Decompress(src, decomp_buffer, (uint16)sizeof(decomp_buffer)); |
| 145 | String_TranslateSpecial(decomp_buffer); |
| 146 | String_Trim(decomp_buffer); |
| 147 | dst = strdup(decomp_buffer); |
| 148 | } else { |
| 149 | dst = strdup(src); |
| 150 | String_Trim(dst); |
| 151 | } |
| 152 | |
| 153 | if (strlen(dst) == 0 && s_strings[0] != NULL) { |
| 154 | free(dst); |
| 155 | } else { |
| 156 | s_strings[s_stringsCount++] = dst; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | /* EU version has one more string in DUNE langfile. */ |
| 161 | if (s_stringsCount == STR_LOAD_GAME) s_strings[s_stringsCount++] = strdup(s_strings[STR_LOAD_A_GAME]); |
| 162 | |
| 163 | while (s_stringsCount <= end) { |
| 164 | s_strings[s_stringsCount++] = NULL; |
| 165 | } |
| 166 | |
| 167 | free(buf); |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Loads the language files in the memory, which is used after that with String_GetXXX_ByIndex(). |
no test coverage detected