summaryrefslogtreecommitdiff
path: root/src/script.cpp
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2020-02-03 15:53:56 +0300
committerAleksey Veresov <aleksey@veresov.pro>2020-02-03 15:53:56 +0300
commit8d4981fcc1c545396df3eac87a3c1a67f3d30038 (patch)
tree0e4f373313f7b251847fecd1186786574e8d450c /src/script.cpp
parent3032869b86efa52f20ad9840381a37017980f587 (diff)
downloadtexo-8d4981fcc1c545396df3eac87a3c1a67f3d30038.tar
texo-8d4981fcc1c545396df3eac87a3c1a67f3d30038.tar.xz
texo-8d4981fcc1c545396df3eac87a3c1a67f3d30038.zip
[texo] Abolished dependency on ScriptPP.
Diffstat (limited to 'src/script.cpp')
-rw-r--r--src/script.cpp38
1 files changed, 32 insertions, 6 deletions
diff --git a/src/script.cpp b/src/script.cpp
index 2892723..cf87bc2 100644
--- a/src/script.cpp
+++ b/src/script.cpp
@@ -1,21 +1,47 @@
#include "script.hpp"
+#include <stdlib.h>
+#include <string.h>
+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Texo String Exporter
*/
-TexoExporterString::TexoExporterString(ScriptVariable & str): str(str)
-{}
+TexoString::TexoString(char *&str): str(str)
+{
+ str = (char *)malloc(1);
+ *str = 0;
+ len = 0;
+ size = 1;
+}
-bool TexoExporterString::Put(char c)
+bool TexoString::Put(char c)
{
- str += c;
+ if (len + 1 == size) {
+ size *= 2;
+ str = (char *)realloc(str, size);
+ }
+ if (!str) {
+ return false;
+ }
+ str[len] = c;
+ ++len;
+ str[len] = 0;
return true;
}
-bool TexoExporterString::Put(const ScriptVariable & addon)
+bool TexoString::Put(const char *addon)
{
- str += addon;
+ int alen = strlen(addon);
+ if (len + alen >= size) {
+ size = len + alen + 1;
+ str = (char *)realloc(str, size);
+ }
+ if (!str) {
+ return false;
+ }
+ memcpy(str + len, addon, alen + 1);
+ len += alen;
return true;
}