summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2016-05-17 00:44:14 +0200
committerHaru <haru@dotalux.com>2016-06-25 17:29:44 +0200
commit70a1facc30c2670d57744b67ec2e7842b8e0a840 (patch)
treefddb8fc651ce23fa7066fc70fdc2e4a84a9c333f /src
parent95d5ff6fde56fbd407ac5fe07ceae22f67fea1da (diff)
downloadhercules-70a1facc30c2670d57744b67ec2e7842b8e0a840.tar.gz
hercules-70a1facc30c2670d57744b67ec2e7842b8e0a840.tar.bz2
hercules-70a1facc30c2670d57744b67ec2e7842b8e0a840.tar.xz
hercules-70a1facc30c2670d57744b67ec2e7842b8e0a840.zip
Split translation handling out of parse_simpleexpr_string()
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src')
-rw-r--r--src/map/script.c154
-rw-r--r--src/map/script.h3
2 files changed, 83 insertions, 74 deletions
diff --git a/src/map/script.c b/src/map/script.c
index 7067c44b4..5b179dea1 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -1240,9 +1240,7 @@ const char *parse_simpleexpr_number(const char *p)
const char *parse_simpleexpr_string(const char *p)
{
- struct string_translation *st = NULL;
const char *start_point = p;
- bool duplicate = true;
do {
p++;
@@ -1254,15 +1252,15 @@ const char *parse_simpleexpr_string(const char *p)
if (n != 1)
ShowDebug("parse_simpleexpr: unexpected length %d after unescape (\"%.*s\" -> %.*s)\n", (int)n, (int)len, p, (int)n, buf);
p += len;
- VECTOR_ENSURE(script->parse_simpleexpr_str, 1, 512);
- VECTOR_PUSH(script->parse_simpleexpr_str, buf[0]);
+ VECTOR_ENSURE(script->parse_simpleexpr_strbuf, 1, 512);
+ VECTOR_PUSH(script->parse_simpleexpr_strbuf, buf[0]);
continue;
}
if (*p == '\n') {
disp_error_message("parse_simpleexpr: unexpected newline @ string", p);
}
- VECTOR_ENSURE(script->parse_simpleexpr_str, 1, 512);
- VECTOR_PUSH(script->parse_simpleexpr_str, *p++);
+ VECTOR_ENSURE(script->parse_simpleexpr_strbuf, 1, 512);
+ VECTOR_PUSH(script->parse_simpleexpr_strbuf, *p++);
}
if (*p == '\0')
disp_error_message("parse_simpleexpr: unexpected end of file @ string", p);
@@ -1270,16 +1268,78 @@ const char *parse_simpleexpr_string(const char *p)
p = script->skip_space(p);
} while (*p != '\0' && *p == '"');
- VECTOR_ENSURE(script->parse_simpleexpr_str, 1, 512);
- VECTOR_PUSH(script->parse_simpleexpr_str, '\0');
+ VECTOR_ENSURE(script->parse_simpleexpr_strbuf, 1, 512);
+ VECTOR_PUSH(script->parse_simpleexpr_strbuf, '\0');
+
+ script->add_translatable_string(&script->parse_simpleexpr_strbuf, start_point);
+
+ VECTOR_TRUNCATE(script->parse_simpleexpr_strbuf);
+
+ return p;
+}
+
+const char *parse_simpleexpr_name(const char *p)
+{
+ int l;
+ const char *pv = NULL;
+
+ // label , register , function etc
+ if (script->skip_word(p) == p)
+ disp_error_message("parse_simpleexpr: unexpected character", p);
+
+ l = script->add_word(p);
+ if (script->str_data[l].type == C_FUNC || script->str_data[l].type == C_USERFUNC || script->str_data[l].type == C_USERFUNC_POS) {
+ return script->parse_callfunc(p,1,0);
+#ifdef SCRIPT_CALLFUNC_CHECK
+ } else {
+ const char *name = script->get_str(l);
+ if (strdb_get(script->userfunc_db,name) != NULL) {
+ return script->parse_callfunc(p, 1, 1);
+ }
+#endif
+ }
+
+ if ((pv = script->parse_variable(p)) != NULL) {
+ // successfully processed a variable assignment
+ return pv;
+ }
+
+ if (script->str_data[l].type == C_INT && script->str_data[l].deprecated) {
+ disp_warning_message("This constant is deprecated and it will be removed in a future version. Please see the script documentation and constants.conf for an alternative.\n", p);
+ }
+
+ p = script->skip_word(p);
+ if (*p == '[') {
+ // array(name[i] => getelementofarray(name,i) )
+ script->addl(script->buildin_getelementofarray_ref);
+ script->addc(C_ARG);
+ script->addl(l);
+
+ p = script->parse_subexpr(p + 1, -1);
+ p = script->skip_space(p);
+ if (*p != ']')
+ disp_error_message("parse_simpleexpr: unmatched ']'", p);
+ ++p;
+ script->addc(C_FUNC);
+ } else {
+ script->addl(l);
+ }
+
+ return p;
+}
+
+void script_add_translatable_string(const struct script_string_buf *string, const char *start_point)
+{
+ struct string_translation *st = NULL;
+ bool duplicate = true;
if (script->syntax.translation_db == NULL
- || (st = strdb_get(script->syntax.translation_db, VECTOR_DATA(script->parse_simpleexpr_str))) == NULL) {
+ || (st = strdb_get(script->syntax.translation_db, VECTOR_DATA(*string))) == NULL) {
script->addc(C_STR);
- VECTOR_ENSURE(script->buf, VECTOR_LENGTH(script->parse_simpleexpr_str), SCRIPT_BLOCK_SIZE);
+ VECTOR_ENSURE(script->buf, VECTOR_LENGTH(*string), SCRIPT_BLOCK_SIZE);
- VECTOR_PUSHARRAY(script->buf, VECTOR_DATA(script->parse_simpleexpr_str), VECTOR_LENGTH(script->parse_simpleexpr_str));
+ VECTOR_PUSHARRAY(script->buf, VECTOR_DATA(*string), VECTOR_LENGTH(*string));
} else {
unsigned char u;
int st_cursor = 0;
@@ -1305,14 +1365,14 @@ const char *parse_simpleexpr_string(const char *p)
}
/* When exporting we don't know what is a translation and what isn't */
- if (script->lang_export_fp != NULL && VECTOR_LENGTH(script->parse_simpleexpr_str) > 1) {
- // The length of script->parse_simpleexpr_str will always be at least 1 because of the '\0'
+ if (script->lang_export_fp != NULL && VECTOR_LENGTH(*string) > 1) {
+ // The length of script->parse_simpleexpr_strbuf will always be at least 1 because of the '\0'
if (script->syntax.strings == NULL) {
script->syntax.strings = strdb_alloc(DB_OPT_DUP_KEY|DB_OPT_ALLOW_NULL_DATA, 0);
}
- if (!strdb_exists(script->syntax.strings, VECTOR_DATA(script->parse_simpleexpr_str))) {
- strdb_put(script->syntax.strings, VECTOR_DATA(script->parse_simpleexpr_str), NULL);
+ if (!strdb_exists(script->syntax.strings, VECTOR_DATA(*string))) {
+ strdb_put(script->syntax.strings, VECTOR_DATA(*string), NULL);
duplicate = false;
}
}
@@ -1344,10 +1404,10 @@ const char *parse_simpleexpr_string(const char *p)
normalize_name(VECTOR_DATA(script->lang_export_line_buf), "\r\n\t "); // [!] Note: VECTOR_LENGTH() will lie.
}
- VECTOR_ENSURE(script->lang_export_escaped_buf, 4*VECTOR_LENGTH(script->parse_simpleexpr_str)+1, 1);
+ VECTOR_ENSURE(script->lang_export_escaped_buf, 4*VECTOR_LENGTH(*string)+1, 1);
VECTOR_LENGTH(script->lang_export_escaped_buf) = (int)sv->escape_c(VECTOR_DATA(script->lang_export_escaped_buf),
- VECTOR_DATA(script->parse_simpleexpr_str),
- VECTOR_LENGTH(script->parse_simpleexpr_str)-1, /* exclude null terminator */
+ VECTOR_DATA(*string),
+ VECTOR_LENGTH(*string)-1, /* exclude null terminator */
"\"");
VECTOR_PUSH(script->lang_export_escaped_buf, '\0');
@@ -1364,59 +1424,6 @@ const char *parse_simpleexpr_string(const char *p)
VECTOR_TRUNCATE(script->lang_export_line_buf);
VECTOR_TRUNCATE(script->lang_export_escaped_buf);
}
- VECTOR_TRUNCATE(script->parse_simpleexpr_str);
-
- return p;
-}
-
-const char *parse_simpleexpr_name(const char *p)
-{
- int l;
- const char *pv = NULL;
-
- // label , register , function etc
- if (script->skip_word(p) == p)
- disp_error_message("parse_simpleexpr: unexpected character", p);
-
- l = script->add_word(p);
- if (script->str_data[l].type == C_FUNC || script->str_data[l].type == C_USERFUNC || script->str_data[l].type == C_USERFUNC_POS) {
- return script->parse_callfunc(p,1,0);
-#ifdef SCRIPT_CALLFUNC_CHECK
- } else {
- const char *name = script->get_str(l);
- if (strdb_get(script->userfunc_db,name) != NULL) {
- return script->parse_callfunc(p, 1, 1);
- }
-#endif
- }
-
- if ((pv = script->parse_variable(p)) != NULL) {
- // successfully processed a variable assignment
- return pv;
- }
-
- if (script->str_data[l].type == C_INT && script->str_data[l].deprecated) {
- disp_warning_message("This constant is deprecated and it will be removed in a future version. Please see the script documentation and constants.conf for an alternative.\n", p);
- }
-
- p = script->skip_word(p);
- if (*p == '[') {
- // array(name[i] => getelementofarray(name,i) )
- script->addl(script->buildin_getelementofarray_ref);
- script->addc(C_ARG);
- script->addl(l);
-
- p = script->parse_subexpr(p + 1, -1);
- p = script->skip_space(p);
- if (*p != ']')
- disp_error_message("parse_simpleexpr: unmatched ']'", p);
- ++p;
- script->addc(C_FUNC);
- } else {
- script->addl(l);
- }
-
- return p;
}
/*==========================================
@@ -5193,7 +5200,7 @@ void script_parser_clean_leftovers(void)
script->syntax.strings = NULL;
}
- VECTOR_CLEAR(script->parse_simpleexpr_str);
+ VECTOR_CLEAR(script->parse_simpleexpr_strbuf);
VECTOR_CLEAR(script->lang_export_line_buf);
VECTOR_CLEAR(script->lang_export_escaped_buf);
}
@@ -5216,7 +5223,7 @@ void do_init_script(bool minimal) {
script->parse_cleanup_timer_id = INVALID_TIMER;
VECTOR_INIT(script->lang_export_line_buf);
VECTOR_INIT(script->lang_export_escaped_buf);
- VECTOR_INIT(script->parse_simpleexpr_str);
+ VECTOR_INIT(script->parse_simpleexpr_strbuf);
script->st_db = idb_alloc(DB_OPT_BASE);
script->userfunc_db = strdb_alloc(DB_OPT_DUP_KEY,0);
@@ -21300,6 +21307,7 @@ void script_defaults(void) {
script->parse_simpleexpr_number = parse_simpleexpr_number;
script->parse_simpleexpr_string = parse_simpleexpr_string;
script->parse_simpleexpr_name = parse_simpleexpr_name;
+ script->add_translatable_string = script_add_translatable_string;
script->parse_expr = parse_expr;
script->parse_line = parse_line;
script->read_constdb = read_constdb;
diff --git a/src/map/script.h b/src/map/script.h
index a9a719099..30737e950 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -635,7 +635,7 @@ struct script_interface {
char **languages;
uint8 max_lang_id;
/* */
- struct script_string_buf parse_simpleexpr_str;
+ struct script_string_buf parse_simpleexpr_strbuf;
struct script_string_buf lang_export_line_buf;
struct script_string_buf lang_export_escaped_buf;
/* */
@@ -737,6 +737,7 @@ struct script_interface {
const char *(*parse_simpleexpr_number) (const char *p);
const char *(*parse_simpleexpr_string) (const char *p);
const char *(*parse_simpleexpr_name) (const char *p);
+ void (*add_translatable_string) (const struct script_string_buf *string, const char *start_point);
const char *(*parse_expr) (const char *p);
const char *(*parse_line) (const char *p);
void (*read_constdb) (void);