From 3cb878c75fd69a44d4911cc39e70bceed633f363 Mon Sep 17 00:00:00 2001 From: Timerix22 Date: Tue, 8 Mar 2022 01:18:53 +0300 Subject: [PATCH] deserialize() fixed and tested on windows --- DtsodC/DtsodParser/DtsodV24_deserialize.c | 39 ++++++++++------------- DtsodC/base/base.h | 10 +++--- DtsodC/base/errors.c | 6 ++-- DtsodC/base/fsleep.c | 8 ----- DtsodC/base/std.h | 2 -- DtsodC/base/types.c | 11 ++++--- DtsodC/tests/main.c | 8 ++--- DtsodC/tests/test_dtsod.c | 12 +++---- 8 files changed, 40 insertions(+), 56 deletions(-) delete mode 100644 DtsodC/base/fsleep.c diff --git a/DtsodC/DtsodParser/DtsodV24_deserialize.c b/DtsodC/DtsodParser/DtsodV24_deserialize.c index c3d0197..fc1c81d 100644 --- a/DtsodC/DtsodParser/DtsodV24_deserialize.c +++ b/DtsodC/DtsodParser/DtsodV24_deserialize.c @@ -11,14 +11,13 @@ Hashtable* __deserialize(char** _text, bool calledRecursively){ bool readingList=false; void __throw_wrongchar(char* file, int line, char* fname,char _c){ - char errBuf[]="unexpected at:\n \"" - "00000000000000000000000000000000" - "\""; - errBuf[12]=_c; - for(uint8 i=0;i<32;i++) - errBuf[i+22]=*(text-16+i); - printf("\n\e[31m[%s:%d/%s]\n",file,line,fname); - throw(errBuf); + char errBuf[]="unexpected at:\n \"" + "00000000000000000000000000000000\""; + errBuf[12]=_c; + for(uint8 i=0;i<32;i++) + errBuf[i+22]=*(text-16+i); + printf("\n\e[91m[%s:%d %s] throwed error: %s\n",file,line,fname,errBuf); + exit(128); }; #define throw_wrongchar(C) __throw_wrongchar(__FILE__,__LINE__,__func__,C) @@ -54,14 +53,14 @@ Hashtable* __deserialize(char** _text, bool calledRecursively){ if(!calledRecursively) throw_wrongchar(c); if((*++text)!=';') throw_wrongchar(c); + case ':': + return nameStr; case '$': if(nameStr.length!=0) throw_wrongchar(c); nameStr.ptr++; partOfDollarList=true; break; - case ':': - return nameStr; default: nameStr.length++; break; @@ -72,7 +71,6 @@ Hashtable* __deserialize(char** _text, bool calledRecursively){ }; Unitype ReadValue(){ - //returns part of without quotes string ReadString(){ bool prevIsBackslash=false; @@ -97,16 +95,12 @@ Hashtable* __deserialize(char** _text, bool calledRecursively){ }; Hashtable* ReadDtsod(){ - if(*++text) //skips { - return __deserialize(&text,true); - else { - throw(ERR_ENDOFSTR); - return NULL; - } - }; + ++text; //skips '{' + return __deserialize(&text,true); + } Unitype ParseValue(string str){ - printf("\e[94m<\e[96m%s\e[94m>\n",string_cpToCharPtr(str)); + //printf("\e[94m<\e[96m%s\e[94m>\n",string_cpToCharPtr(str)); const string nullStr={"null",4}; const string trueStr={"true",4}; const string falseStr={"false",5}; @@ -175,10 +169,11 @@ Hashtable* __deserialize(char** _text, bool calledRecursively){ case '}': case '$': throw_wrongchar(c); break; - case '#': + case '#':; + char _c=c; SkipComment(); if(valueStr.length!=0) - throw_wrongchar(c); + throw_wrongchar(_c); valueStr.ptr=text; break; case '"': @@ -187,7 +182,6 @@ Hashtable* __deserialize(char** _text, bool calledRecursively){ break; case '\'': if(valueStr.length!=0) throw_wrongchar(c); - text++; char valueChar=*++text; if (*++text != '\'') throw("after <'> should be char"); value=Uni(Char,valueChar); @@ -201,6 +195,7 @@ Hashtable* __deserialize(char** _text, bool calledRecursively){ case '{': if(valueStr.length!=0) throw_wrongchar(c); value=UniPtr(HashtablePtr,ReadDtsod()); + return value; case ';': case ',': if(valueStr.length!=0) diff --git a/DtsodC/base/base.h b/DtsodC/base/base.h index 808d662..499c6ef 100644 --- a/DtsodC/base/base.h +++ b/DtsodC/base/base.h @@ -5,15 +5,13 @@ #include "errors.h" #include "mystr.h" -// sleep function based on std nanosleep() -void fsleep(float sec); - // executes codeblock and prints execution time #define optime(opname,repeats,codeblock) ({\ - clock_t start=clock();\ + struct timespec start, stop;\ + clock_gettime(CLOCK_REALTIME, &start);\ for(uint64 ___OPREP=0;___OPREP #include #include -#include -#include #include #define CHOOSE(B, Y, N) __builtin_choose_expr(B, Y, N) diff --git a/DtsodC/base/types.c b/DtsodC/base/types.c index eab3e33..8ccb309 100644 --- a/DtsodC/base/types.c +++ b/DtsodC/base/types.c @@ -119,11 +119,12 @@ void Unitype_free(Unitype u){ void printuni(Unitype v){ switch (v.type) { case Null: printf("{Null}");break; - case Double: printf("{%s:%lf}",typename(v.type),v.Double);break; - case Char: printf("{%s:%c}",typename(v.type),v.Char);break; + case Double: printf("{%s : %lf}",typename(v.type),v.Double);break; + case Char: printf("{%s : '%c'}",typename(v.type),v.Char);break; case Bool: - case UInt64: printf("{%s:%lu}",typename(v.type),v.UInt64);break; - case Int64: printf("{%s:%ld}",typename(v.type),v.Int64);break; - default: printf("{%s:%p}",typename(v.type),v.VoidPtr);break; + case UInt64: printf("{%s : %lu}",typename(v.type),v.UInt64);break; + case Int64: printf("{%s : %ld}",typename(v.type),v.Int64);break; + case CharPtr: printf("{%s : \"%s\"}",typename(v.type),(char*)v.VoidPtr);break; + default: printf("{%s : %p}",typename(v.type),v.VoidPtr);break; } } diff --git a/DtsodC/tests/main.c b/DtsodC/tests/main.c index 9a5d8f3..9ccfdc2 100644 --- a/DtsodC/tests/main.c +++ b/DtsodC/tests/main.c @@ -2,10 +2,10 @@ #include "tests.h" void test_all(){ - //test_searchtree(); - //test_autoarr(); - //test_hashtable(); - //test_string(); + test_searchtree(); + test_autoarr(); + test_hashtable(); + test_string(); test_dtsod(); printf("\e[96m---------------------------------------\e[0m\n"); } diff --git a/DtsodC/tests/test_dtsod.c b/DtsodC/tests/test_dtsod.c index 35bdb01..9007db2 100644 --- a/DtsodC/tests/test_dtsod.c +++ b/DtsodC/tests/test_dtsod.c @@ -4,16 +4,16 @@ const char text[]= "message: {\n" " bool: false;" -//" char: 'v';" +" char: 'v';" " int: -2515;" -" uint: 0u;" -" double: 965.557f;" +" uint:#comment!\n 0u;" +" double: 965.557f;#another comment!\n" " text: \"_$\\\"\\\\'''\n\ta ыыы000;2;=:%d;```\";\n" -"}; \n"; +"}; "; void test_dtsod(){ printf("\e[96m-------------[test_dtsod]-------------\n"); - //optime(__func__,1,({ + optime(__func__,1,({ Hashtable* dtsod; optime("deserialize",1,(dtsod=DtsodV24_deserialize(text))); Hashtable_foreach(dtsod, p,({ @@ -31,5 +31,5 @@ void test_dtsod(){ printf("\n"); })); Hashtable_free(dtsod); - //})); + })); } \ No newline at end of file