mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-11 13:10:45 +00:00
(svn r25818) -Fix [FS#5750]: [GS] Language file scanner considered filenames starting with '.' as valid translations, resulting in languages with empty name, which causes trouble.
This commit is contained in:
parent
4912e3170e
commit
bf0f5345ea
@ -60,18 +60,11 @@ void NORETURN CDECL strgen_fatal(const char *s, ...)
|
|||||||
/**
|
/**
|
||||||
* Create a new container for language strings.
|
* Create a new container for language strings.
|
||||||
* @param language The language name.
|
* @param language The language name.
|
||||||
|
* @param end If not NULL, terminate \a language at this position.
|
||||||
*/
|
*/
|
||||||
LanguageStrings::LanguageStrings(const char *language)
|
LanguageStrings::LanguageStrings(const char *language, const char *end)
|
||||||
{
|
{
|
||||||
const char *p = strrchr(language, PATHSEPCHAR);
|
this->language = end == NULL ? strdup(language) : strndup(language, end - language);
|
||||||
if (p == NULL) {
|
|
||||||
p = language;
|
|
||||||
} else {
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *e = strchr(p, '.');
|
|
||||||
this->language = e == NULL ? strdup(p) : strndup(p, e - p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Free everything. */
|
/** Free everything. */
|
||||||
@ -95,7 +88,17 @@ LanguageStrings *ReadRawLanguageStrings(const char *file)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = new LanguageStrings(file);
|
const char *langname = strrchr(file, PATHSEPCHAR);
|
||||||
|
if (langname == NULL) {
|
||||||
|
langname = file;
|
||||||
|
} else {
|
||||||
|
langname++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check for invalid empty filename */
|
||||||
|
if (*langname == '.' || *langname == 0) return NULL;
|
||||||
|
|
||||||
|
ret = new LanguageStrings(langname, strchr(langname, '.'));
|
||||||
|
|
||||||
char buffer[2048];
|
char buffer[2048];
|
||||||
while (to_read != 0 && fgets(buffer, sizeof(buffer), fh) != NULL) {
|
while (to_read != 0 && fgets(buffer, sizeof(buffer), fh) != NULL) {
|
||||||
|
@ -26,7 +26,7 @@ struct LanguageStrings {
|
|||||||
const char *language; ///< Name of the language (base filename).
|
const char *language; ///< Name of the language (base filename).
|
||||||
StringList lines; ///< The lines of the file to pass into the parser/encoder.
|
StringList lines; ///< The lines of the file to pass into the parser/encoder.
|
||||||
|
|
||||||
LanguageStrings(const char *language);
|
LanguageStrings(const char *language, const char *end = NULL);
|
||||||
~LanguageStrings();
|
~LanguageStrings();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user