summaryrefslogtreecommitdiff
path: root/src/map/script.c
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2016-06-25 17:28:21 +0200
committerHaru <haru@dotalux.com>2016-06-25 17:29:52 +0200
commita8590a0b235ce48320d428a184181c1e93267cd6 (patch)
tree1b766d21645ff064e57e366d807497f58d4f0a2d /src/map/script.c
parent98c11df06659aac8fff6f04915043c6eebaf2c6f (diff)
downloadhercules-a8590a0b235ce48320d428a184181c1e93267cd6.tar.gz
hercules-a8590a0b235ce48320d428a184181c1e93267cd6.tar.bz2
hercules-a8590a0b235ce48320d428a184181c1e93267cd6.tar.xz
hercules-a8590a0b235ce48320d428a184181c1e93267cd6.zip
Corrected an issue that prevented changing default languages
The script->get_translation_file_name() is more robust (and actually works) now. Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/map/script.c')
-rw-r--r--src/map/script.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/src/map/script.c b/src/map/script.c
index a6a9a9cf9..64966f987 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -4910,28 +4910,42 @@ void script_load_translations(void) {
}
/**
+ * Generates a language name from a translation filename.
*
- **/
+ * @param file The filename.
+ * @return The corresponding translation name.
+ */
const char *script_get_translation_file_name(const char *file)
{
- int i, len = (int)strlen(file), last_bar = -1, last_dot = -1;
+ const char *basename = NULL, *last_dot = NULL;
+
+ nullpo_retr("Unknown", file);
- for(i = 0; i < len; i++) {
- if( file[i] == '/' || file[i] == '\\' )
- last_bar = i;
- else if ( file[i] == '.' )
- last_dot = i;
+ basename = strrchr(file, '/');;
+#ifdef WIN32
+ {
+ const char *basename_windows = strrchr(file, '\\');
+ if (basename_windows > basename)
+ basename = basename_windows;
}
+#endif // WIN32
+ if (basename == NULL)
+ basename = file;
+ else
+ basename++; // Skip slash
+ Assert_retr("Unknown", *basename != '\0');
- if( last_bar != -1 || last_dot != -1 ) {
+ last_dot = strrchr(basename, '.');
+ if (last_dot != NULL) {
static char file_name[200];
- if( last_bar != -1 && last_dot < last_bar )
- last_dot = -1;
- safestrncpy(file_name, file+(last_bar >= 0 ? last_bar+1 : 0), ( last_dot >= 0 ? ( last_bar >= 0 ? last_dot - last_bar : last_dot ) : sizeof(file_name) ));
+ if (last_dot == basename)
+ return basename + 1;
+
+ safestrncpy(file_name, basename, last_dot - basename + 1);
return file_name;
}
- return file;
+ return basename;
}
/**