treesummaryrefslogcommitdiff
path: root/main2.c
diff options
context:
space:
mode:
authorPatrick2023-08-04 10:42:10 +0100
committerPatrick2023-08-04 10:42:10 +0100
commit7915eed596265bb03d9fc01eec6dd39015b01188 (patch)
tree59471ed47b7eee57a132da9554841babd070e427 /main2.c
parent4732c7322c4af189232d5faee94e43fe71b175d2 (diff)
downloadiftint-7915eed596265bb03d9fc01eec6dd39015b01188.tar.gz
iftint-7915eed596265bb03d9fc01eec6dd39015b01188.zip
edit in place :D
Diffstat (limited to 'main2.c')
-rw-r--r--main2.c66
1 files changed, 39 insertions, 27 deletions
diff --git a/main2.c b/main2.c
index 104c2a4..96aba10 100644
--- a/main2.c
+++ b/main2.c
@@ -284,35 +284,38 @@ PeekChar() {
return c;
}
-int
-GetInt() {
- static char intStr[16];
- intStr[0] = '\0';
+void
+GetInt(JSONNode * node) {
+ char intStr[16] = "";
int intStrLen = 0;
- int result = 0;
+
+ size_t * i = &node->data;
+
int c;
g_DrawStr = intStr;
while ((c = GetChar()), (c != '\r') && (c != '\n')) {
if ((c == 8 || c == 127) && intStrLen > 0) {
intStrLen--;
intStr[intStrLen] = '\0';
- result /= 10;
+ *i /= 10;
}
else if (intStrLen < 16 - 1 && (c >= '0' && c <= '9')) {
intStr[intStrLen++] = c;
intStr[intStrLen] = '\0';
- result *= 10;
- result += c - '0';
+ *i *= 10;
+ *i += c - '0';
}
}
g_DrawStr = "";
- return result;
}
-char *
-GetStr() {
- char * str = NEWARR(char, 16);
+void
+GetStr(JSONNode * node) {
+ node->data = (size_t)NEWARR(char, 16);
int strLen = 0;
+
+ char * str = (char *)node->data;
+
int c;
g_DrawStr = str;
while ((c = GetChar()), (c != '\r') && (c != '\n')) {
@@ -326,15 +329,14 @@ GetStr() {
}
}
g_DrawStr = "";
- return str;
}
-JSONNode *
-GetNode(JSONNode * parent) {
+void
+GetNode(JSONNode * parent, JSONNode * node) {
int c = GetChar();
- JSONNode * result = JSONNodeNewNul();
-
+ JSONNode * result = node;
+
if (parent == NULL)
g_DrawNode = result;
@@ -344,20 +346,26 @@ GetNode(JSONNode * parent) {
switch (c) {
case 'i': {
result->kind = JSONNodeKind_Int;
- result->data = (size_t)GetInt();
+ GetInt(result);
break;
}
case 's': {
result->kind = JSONNodeKind_Str;
- result->data = (size_t)GetStr();
+ GetStr(result);
break;
}
case 'o': {
result->kind = JSONNodeKind_Obj;
while ((c = PeekChar()), (c != '\r') && (c != '\n')) {
- JSONNodePush(result, JSONNodeNewStr(GetStr()));
-
- JSONNodePush(result, GetNode(result));
+ JSONNode * newNode;
+
+ newNode = JSONNodeNewStr("");
+ JSONNodePush(result, newNode);
+ GetStr(newNode);
+
+ newNode = JSONNodeNewNul();
+ JSONNodePush(result, newNode);
+ GetNode(result, newNode);
}
GetChar();
break;
@@ -365,23 +373,26 @@ GetNode(JSONNode * parent) {
case 'a': {
result->kind = JSONNodeKind_Arr;
while ((c = PeekChar()), (c != '\r') && (c != '\n')) {
- JSONNodePush(result, GetNode(result));
+ JSONNode * newNode = JSONNodeNewNul();
+ JSONNodePush(result, newNode);
+ GetNode(result, newNode);
}
GetChar();
break;
}
+ /*
case 8:
case 127:
JSONNodePop(parent);
- result = GetNode(parent);
+ JSONNode * newNode = JSONNodeNewNul();
+ GetNode(parent, newNode);
break;
+ */
case 't':
result->kind = JSONNodeKind_Int;
result->data = (size_t)GetChar();
break;
}
-
- return result;
}
@@ -390,7 +401,8 @@ GetNode(JSONNode * parent) {
int main() {
Draw();
- JSONNode * n = GetNode(NULL);
+ JSONNode * n = JSONNodeNewNul();
+ GetNode(NULL, n);
//JSONNode * n = TestNode();
vt100ClearScreen();