|
|
@ -105,6 +105,16 @@ struct LangString {
|
|
|
|
free(this->translated);
|
|
|
|
free(this->translated);
|
|
|
|
delete this->translated_case;
|
|
|
|
delete this->translated_case;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Free all data related to the translation. */
|
|
|
|
|
|
|
|
void FreeTranslation()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
free(this->translated);
|
|
|
|
|
|
|
|
this->translated = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
delete this->translated_case;
|
|
|
|
|
|
|
|
this->translated_case = NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** Information about the currently known strings. */
|
|
|
|
/** Information about the currently known strings. */
|
|
|
@ -136,6 +146,15 @@ struct StringData {
|
|
|
|
free(this->hash_heads);
|
|
|
|
free(this->hash_heads);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Free all data related to the translation. */
|
|
|
|
|
|
|
|
void FreeTranslation()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for (size_t i = 0; i < this->max_strings; i++) {
|
|
|
|
|
|
|
|
LangString *ls = this->strings[i];
|
|
|
|
|
|
|
|
if (ls != NULL) ls->FreeTranslation();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Create a hash of the string for finding them back quickly.
|
|
|
|
* Create a hash of the string for finding them back quickly.
|
|
|
|
* @param s The string to hash.
|
|
|
|
* @param s The string to hash.
|
|
|
@ -1017,6 +1036,7 @@ static void rstrip(char *buf)
|
|
|
|
void StringReader::ParseFile()
|
|
|
|
void StringReader::ParseFile()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
char buf[2048];
|
|
|
|
char buf[2048];
|
|
|
|
|
|
|
|
_warnings = _errors = 0;
|
|
|
|
|
|
|
|
|
|
|
|
_translation = this->master || this->translation;
|
|
|
|
_translation = this->master || this->translation;
|
|
|
|
_file = this->file;
|
|
|
|
_file = this->file;
|
|
|
@ -1621,7 +1641,7 @@ int CDECL main(int argc, char *argv[])
|
|
|
|
HeaderFileWriter writer(pathbuf);
|
|
|
|
HeaderFileWriter writer(pathbuf);
|
|
|
|
writer.WriteHeader(data);
|
|
|
|
writer.WriteHeader(data);
|
|
|
|
writer.Finalise(data);
|
|
|
|
writer.Finalise(data);
|
|
|
|
} else if (mgo.numleft == 1) {
|
|
|
|
} else if (mgo.numleft >= 1) {
|
|
|
|
char *r;
|
|
|
|
char *r;
|
|
|
|
|
|
|
|
|
|
|
|
mkpath(pathbuf, lengthof(pathbuf), src_dir, "english.txt");
|
|
|
|
mkpath(pathbuf, lengthof(pathbuf), src_dir, "english.txt");
|
|
|
@ -1631,31 +1651,33 @@ int CDECL main(int argc, char *argv[])
|
|
|
|
FileStringReader master_reader(data, pathbuf, true, false);
|
|
|
|
FileStringReader master_reader(data, pathbuf, true, false);
|
|
|
|
master_reader.ParseFile();
|
|
|
|
master_reader.ParseFile();
|
|
|
|
|
|
|
|
|
|
|
|
const char *translation = replace_pathsep(mgo.argv[0]);
|
|
|
|
for (int i = 0; i < mgo.numleft; i++) {
|
|
|
|
const char *file = strrchr(translation, PATHSEPCHAR);
|
|
|
|
data.FreeTranslation();
|
|
|
|
FileStringReader translation_reader(data, translation, false, file == NULL || strcmp(file + 1, "english.txt") != 0);
|
|
|
|
|
|
|
|
translation_reader.ParseFile(); // target file
|
|
|
|
|
|
|
|
if (_errors != 0) return 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* get the targetfile, strip any directories and append to destination path */
|
|
|
|
const char *translation = replace_pathsep(mgo.argv[i]);
|
|
|
|
r = strrchr(mgo.argv[0], PATHSEPCHAR);
|
|
|
|
const char *file = strrchr(translation, PATHSEPCHAR);
|
|
|
|
mkpath(pathbuf, lengthof(pathbuf), dest_dir, (r != NULL) ? &r[1] : mgo.argv[0]);
|
|
|
|
FileStringReader translation_reader(data, translation, false, file == NULL || strcmp(file + 1, "english.txt") != 0);
|
|
|
|
|
|
|
|
translation_reader.ParseFile(); // target file
|
|
|
|
|
|
|
|
if (_errors != 0) return 1;
|
|
|
|
|
|
|
|
|
|
|
|
/* rename the .txt (input-extension) to .lng */
|
|
|
|
/* get the targetfile, strip any directories and append to destination path */
|
|
|
|
r = strrchr(pathbuf, '.');
|
|
|
|
r = strrchr(mgo.argv[i], PATHSEPCHAR);
|
|
|
|
if (r == NULL || strcmp(r, ".txt") != 0) r = strchr(pathbuf, '\0');
|
|
|
|
mkpath(pathbuf, lengthof(pathbuf), dest_dir, (r != NULL) ? &r[1] : mgo.argv[i]);
|
|
|
|
ttd_strlcpy(r, ".lng", (size_t)(r - pathbuf));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LanguageFileWriter writer(pathbuf);
|
|
|
|
/* rename the .txt (input-extension) to .lng */
|
|
|
|
writer.WriteLang(data);
|
|
|
|
r = strrchr(pathbuf, '.');
|
|
|
|
writer.Finalise();
|
|
|
|
if (r == NULL || strcmp(r, ".txt") != 0) r = strchr(pathbuf, '\0');
|
|
|
|
|
|
|
|
ttd_strlcpy(r, ".lng", (size_t)(r - pathbuf));
|
|
|
|
|
|
|
|
|
|
|
|
/* if showing warnings, print a summary of the language */
|
|
|
|
LanguageFileWriter writer(pathbuf);
|
|
|
|
if ((_show_todo & 2) != 0) {
|
|
|
|
writer.WriteLang(data);
|
|
|
|
fprintf(stdout, "%d warnings and %d errors for %s\n", _warnings, _errors, pathbuf);
|
|
|
|
writer.Finalise();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* if showing warnings, print a summary of the language */
|
|
|
|
|
|
|
|
if ((_show_todo & 2) != 0) {
|
|
|
|
|
|
|
|
fprintf(stdout, "%d warnings and %d errors for %s\n", _warnings, _errors, pathbuf);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
fprintf(stderr, "Invalid arguments\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (...) {
|
|
|
|
} catch (...) {
|
|
|
|
return 2;
|
|
|
|
return 2;
|
|
|
|