From d9fade08f4faf1f70671bdf02f124af7c5b236bc Mon Sep 17 00:00:00 2001 From: Haru Date: Fri, 1 Jan 2016 05:52:36 +0100 Subject: Correctly escaped special characters in the generated_translations.pot Signed-off-by: Haru --- src/map/script.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'src/map/script.c') diff --git a/src/map/script.c b/src/map/script.c index 46116f75a..753306f91 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -1296,7 +1296,7 @@ const char* parse_simpleexpr(const char *p) ) || script->syntax.lang_macro_active ) ) { const char *line_start = start_point; const char *line_end = start_point; - int line_length, cursor; + int line_length; while( line_start > script->parser_current_src ) { if( *line_start != '\n' ) @@ -1317,16 +1317,12 @@ const char* parse_simpleexpr(const char *p) normalize_name(VECTOR_DATA(script->lang_export_line_buf), "\r\n\t "); // [!] Note: VECTOR_LENGTH() will lie. } - for (cursor = 0; cursor < VECTOR_LENGTH(script->parse_simpleexpr_str); cursor++) { - if (VECTOR_INDEX(script->parse_simpleexpr_str, cursor) == '"') { - VECTOR_ENSURE(script->lang_export_unescaped_buf, 1, 512); - VECTOR_PUSH(script->lang_export_unescaped_buf, '\\'); - } - VECTOR_ENSURE(script->lang_export_unescaped_buf, 1, 512); - VECTOR_PUSH(script->lang_export_unescaped_buf, VECTOR_INDEX(script->parse_simpleexpr_str, cursor)); - } - VECTOR_ENSURE(script->lang_export_unescaped_buf, 1, 512); - VECTOR_PUSH(script->lang_export_unescaped_buf, '\0'); + VECTOR_ENSURE(script->lang_export_escaped_buf, 4*VECTOR_LENGTH(script->parse_simpleexpr_str)+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_PUSH(script->lang_export_escaped_buf, '\0'); fprintf(script->lang_export_fp, "#: %s\n" "# %s\n" @@ -1336,10 +1332,10 @@ const char* parse_simpleexpr(const char *p) script->parser_current_file ? script->parser_current_file : "Unknown File", VECTOR_DATA(script->lang_export_line_buf), script->parser_current_npc_name ? script->parser_current_npc_name : "Unknown NPC", - VECTOR_DATA(script->lang_export_unescaped_buf) + VECTOR_DATA(script->lang_export_escaped_buf) ); VECTOR_TRUNCATE(script->lang_export_line_buf); - VECTOR_TRUNCATE(script->lang_export_unescaped_buf); + VECTOR_TRUNCATE(script->lang_export_escaped_buf); } VECTOR_TRUNCATE(script->parse_simpleexpr_str); } else { @@ -5169,7 +5165,7 @@ void script_parser_clean_leftovers(void) VECTOR_CLEAR(script->parse_simpleexpr_str); VECTOR_CLEAR(script->lang_export_line_buf); - VECTOR_CLEAR(script->lang_export_unescaped_buf); + VECTOR_CLEAR(script->lang_export_escaped_buf); } /** @@ -5189,7 +5185,7 @@ int script_parse_cleanup_timer(int tid, int64 tick, int id, intptr_t data) { 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_unescaped_buf); + VECTOR_INIT(script->lang_export_escaped_buf); VECTOR_INIT(script->parse_simpleexpr_str); script->st_db = idb_alloc(DB_OPT_BASE); -- cgit v1.2.3-60-g2f50