]> gitweb.ps.run Git - iftint/commitdiff
edit in place :D
authorPatrick <patrick.schoenberger@posteo.de>
Fri, 4 Aug 2023 09:42:10 +0000 (10:42 +0100)
committerPatrick <patrick.schoenberger@posteo.de>
Fri, 4 Aug 2023 09:42:10 +0000 (10:42 +0100)
main2.c

diff --git a/main2.c b/main2.c
index 104c2a47a021ad8b347aea2f563e184ac29f5804..96aba10d0a905313a361756b37abaf1ef117aa39 100644 (file)
--- 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();