|
@@ -94,56 +94,56 @@ void NORETURN CDECL error(const char *s,
|
|
|
/** A reader that simply reads using fopen. */
|
|
|
struct FileStringReader : StringReader {
|
|
|
FILE *fh; ///< The file we are reading.
|
|
|
|
|
|
/**
|
|
|
* Create the reader.
|
|
|
* @param data The data to fill during reading.
|
|
|
* @param file The file we are reading.
|
|
|
* @param master Are we reading the master file?
|
|
|
* @param translation Are we reading a translation?
|
|
|
*/
|
|
|
FileStringReader(StringData &data, const char *file, bool master, bool translation) :
|
|
|
StringReader(data, file, master, translation)
|
|
|
{
|
|
|
this->fh = fopen(file, "rb");
|
|
|
if (this->fh == NULL) error("Could not open %s", file);
|
|
|
}
|
|
|
|
|
|
/** Free/close the file. */
|
|
|
virtual ~FileStringReader()
|
|
|
{
|
|
|
fclose(this->fh);
|
|
|
}
|
|
|
|
|
|
/* virtual */ char *ReadLine(char *buffer, const char *last)
|
|
|
char *ReadLine(char *buffer, const char *last) override
|
|
|
{
|
|
|
return fgets(buffer, ClampToU16(last - buffer + 1), this->fh);
|
|
|
}
|
|
|
|
|
|
/* virtual */ void HandlePragma(char *str);
|
|
|
void HandlePragma(char *str) override;
|
|
|
|
|
|
/* virtual */ void ParseFile()
|
|
|
void ParseFile() override
|
|
|
{
|
|
|
this->StringReader::ParseFile();
|
|
|
|
|
|
if (StrEmpty(_lang.name) || StrEmpty(_lang.own_name) || StrEmpty(_lang.isocode)) {
|
|
|
error("Language must include ##name, ##ownname and ##isocode");
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
void FileStringReader::HandlePragma(char *str)
|
|
|
{
|
|
|
if (!memcmp(str, "id ", 3)) {
|
|
|
this->data.next_string_id = strtoul(str + 3, NULL, 0);
|
|
|
} else if (!memcmp(str, "name ", 5)) {
|
|
|
strecpy(_lang.name, str + 5, lastof(_lang.name));
|
|
|
} else if (!memcmp(str, "ownname ", 8)) {
|
|
|
strecpy(_lang.own_name, str + 8, lastof(_lang.own_name));
|
|
|
} else if (!memcmp(str, "isocode ", 8)) {
|
|
|
strecpy(_lang.isocode, str + 8, lastof(_lang.isocode));
|
|
|
} else if (!memcmp(str, "textdir ", 8)) {
|
|
|
if (!memcmp(str + 8, "ltr", 3)) {
|
|
|
_lang.text_dir = TD_LTR;
|
|
|
} else if (!memcmp(str + 8, "rtl", 3)) {
|
|
|
_lang.text_dir = TD_RTL;
|