summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/strlib.c1
-rw-r--r--src/map/script.c26
-rw-r--r--src/map/script.h2
3 files changed, 13 insertions, 16 deletions
diff --git a/src/common/strlib.c b/src/common/strlib.c
index 9690151b4..b67adb63c 100644
--- a/src/common/strlib.c
+++ b/src/common/strlib.c
@@ -772,6 +772,7 @@ size_t sv_escape_c(char* out_dest, const char* src, size_t len, const char* esca
case '\v': out_dest[j++] = 'v'; break;
case '\f': out_dest[j++] = 'f'; break;
case '\?': out_dest[j++] = '?'; break;
+ case '\"': out_dest[j++] = '"'; break;
default:// to octal
out_dest[j++] = '0'+((char)(((unsigned char)src[i]&0700)>>6));
out_dest[j++] = '0'+((char)(((unsigned char)src[i]&0070)>>3));
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);
diff --git a/src/map/script.h b/src/map/script.h
index 845d52280..35a6a1bbf 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -637,7 +637,7 @@ struct script_interface {
/* */
struct script_string_buf parse_simpleexpr_str;
struct script_string_buf lang_export_line_buf;
- struct script_string_buf lang_export_unescaped_buf;
+ struct script_string_buf lang_export_escaped_buf;
/* */
int parse_cleanup_timer_id;
/* */