summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgumi <git@gumi.ca>2018-02-15 13:16:04 -0500
committergumi <git@gumi.ca>2018-02-26 23:31:48 -0500
commit60bc3c265d6633a6f8e98160184d97d362c89a96 (patch)
treef6840fcfb7d1a7da7599776c3ace6934cccf5556
parentf698153e70c0e0159254cdc96c66192fe702db22 (diff)
downloadevol-hercules-60bc3c265d6633a6f8e98160184d97d362c89a96.tar.gz
evol-hercules-60bc3c265d6633a6f8e98160184d97d362c89a96.tar.bz2
evol-hercules-60bc3c265d6633a6f8e98160184d97d362c89a96.tar.xz
evol-hercules-60bc3c265d6633a6f8e98160184d97d362c89a96.zip
re-add the sprintf translation, and fix it
-rw-r--r--src/emap/utils/formatutils.c65
1 files changed, 48 insertions, 17 deletions
diff --git a/src/emap/utils/formatutils.c b/src/emap/utils/formatutils.c
index 00ea637..83236c1 100644
--- a/src/emap/utils/formatutils.c
+++ b/src/emap/utils/formatutils.c
@@ -97,25 +97,56 @@ int format_sub(struct script_state* st, int translate)
}
char *ptr = line;
- int sz = (int)strlen(line);
- while (script_hasdata(st, idx))
+
+ if (strstr(ptr, "@@"))
{
- char *tmp = strstr(ptr, "@@");
- if (!tmp)
- break;
- const char *item = script_getstr(st, idx);
- int len = (int)strlen(item);
- if (len > 50)
- break;
- sz += len - 2;
- if (sz > 490)
- break;
- memmove(tmp + len, tmp + 2, strlen(tmp + 2) + 1);
- memcpy(tmp, item, len);
- ptr = tmp + len;
- idx ++;
+ int sz = (int)strlen(line);
+
+ while (script_hasdata(st, idx))
+ {
+ char *tmp = strstr(ptr, "@@");
+ if (!tmp)
+ break;
+ const char *item = script_getstr(st, idx);
+ int len = (int)strlen(item);
+ if (len > 50)
+ break;
+ sz += len - 2;
+ if (sz > 490)
+ break;
+ memmove(tmp + len, tmp + 2, strlen(tmp + 2) + 1);
+ memcpy(tmp, item, len);
+ ptr = tmp + len;
+ idx ++;
+ }
+
+ script_pushstr(st, line);
+ }
+ else
+ {
+ char start = (translate == 2 ? 3 : 2);
+
+ if (script_hasdata(st, start + 1))
+ {
+ struct StringBuf pfbuf;
+ StrBuf->Init(&pfbuf);
+
+ // modify the string directly in the stack, for use by script_sprintf
+ st->stack->stack_data[st->start + start].u.str = line;
+
+ if (!script->sprintf(st, start, &pfbuf))
+ {
+ StrBuf->Destroy(&pfbuf);
+ script_pushstr(st, line);
+ return false;
+ }
+
+ strcpy(line, StrBuf->Value(&pfbuf));
+ StrBuf->Destroy(&pfbuf);
+ }
+
+ script_pushstr(st, line);
}
- script_pushstr(st, line);
return 0;
}