diff --git a/DtsodC/src/Autoarr/Autoarr2.h b/DtsodC/src/Autoarr/Autoarr2.h index c5b96c5..74b89f2 100644 --- a/DtsodC/src/Autoarr/Autoarr2.h +++ b/DtsodC/src/Autoarr/Autoarr2.h @@ -15,3 +15,4 @@ declare_Autoarr2(float) declare_Autoarr2(double) declare_Autoarr2(Unitype) + diff --git a/DtsodC/src/Autoarr/StringBuilder.c b/DtsodC/src/Autoarr/StringBuilder.c new file mode 100644 index 0000000..2a3c3ee --- /dev/null +++ b/DtsodC/src/Autoarr/StringBuilder.c @@ -0,0 +1,24 @@ +#include "StringBuilder.h" + +StringBuilder StringBuilder_create(uint16 max_blocks_count, uint16 max_block_length){ + return Autoarr2_create(int8,max_blocks_count,max_block_length); +} + +void StringBuilder_append(StringBuilder* b, char c){ + Autoarr2_add(b,c); +} + +void StringBuilder_append_str(StringBuilder* b, char* s){ + char c; + while((c=*s++)) + Autoarr2_add(b,c); +} + +char* StringBuilder_build(StringBuilder* b){ + uint32 len=Autoarr2_length(b); + char* str=malloc(len+1); + str[len]=0; + for(uint32 i=0;i0) throw(ERR_ENDOFSTR); + return NULL; }; Unitype ReadValue(){ + Unitype value=UniNull; - }; - - void SkipComment(){ - + return value; }; - while ((c=*text)){ - char* n=ReadName(); - Unitype v=ReadValue(); - Hashtable_add(dict,n,v); - text++; - } */ + while((c=*text++)){ + char* name=ReadName(); + if(!name){ + free(name); + return dict; + } + Unitype value=ReadValue(); + if(partOfDollarList){ + Autoarr2(Unitype)* list; + Unitype _lu; + if(Hashtable_try_get(dict,name, &_lu)) + list=(Autoarr2(Unitype)*)_lu.VoidPtr; + else { + list=malloc(sizeof(Autoarr2(Unitype))); + *list=Autoarr2_create(Unitype,ARR_BC,ARR_BL); + Hashtable_add(dict,name,UniF(AutoarrUnitypePtr,VoidPtr,list)); + } + Autoarr2_add(list,value); + } + else Hashtable_add(dict,name,value); + } return dict; } diff --git a/DtsodC/src/Hashtable/Hashtable.c b/DtsodC/src/Hashtable/Hashtable.c index 8d9a5ec..58f848c 100644 --- a/DtsodC/src/Hashtable/Hashtable.c +++ b/DtsodC/src/Hashtable/Hashtable.c @@ -88,7 +88,7 @@ Unitype Hashtable_get(Hashtable* ht, char* key){ KeyValuePair p=Autoarr2_get(ar,i); if(mystrcmp(key,p.key)) return p.value; } - return (Unitype){.type=Null,.VoidPtr=NULL}; + return UniNull; } KeyValuePair Hashtable_get_pair(Hashtable* ht, char* key){ return cpair(key,Hashtable_get(ht,key)); diff --git a/DtsodC/src/SearchTree/SearchTree.c b/DtsodC/src/SearchTree/SearchTree.c index e19757b..9a09800 100644 --- a/DtsodC/src/SearchTree/SearchTree.c +++ b/DtsodC/src/SearchTree/SearchTree.c @@ -89,20 +89,18 @@ void ST_push(STNode* node_first, const char* key, Unitype value){ node_last->value=value; } -const Unitype UnitypeNull={.type=Null,.VoidPtr=NULL}; - Unitype ST_pull(STNode* node_first, const char* key){ if (!node_first) throw(ERR_NULLPTR); STNode* node_last=node_first; while (*key){ indexes3 i3=splitindex((uint8)*key); - if(!node_last->branches) return UnitypeNull; + if(!node_last->branches) return UniNull; STNode*** ptrn32=(STNode***)node_last->branches[i3.n32]; - if(!ptrn32) return UnitypeNull; + if(!ptrn32) return UniNull; STNode** ptrn4=ptrn32[i3.n4]; - if(!ptrn4) return UnitypeNull; + if(!ptrn4) return UniNull; node_last=ptrn4[i3.rem]; - if(!node_last) return UnitypeNull; + if(!node_last) return UniNull; key++; } return node_last->value; diff --git a/DtsodC/src/base/errors.c b/DtsodC/src/base/errors.c index ec9c252..fa21f0d 100644 --- a/DtsodC/src/base/errors.c +++ b/DtsodC/src/base/errors.c @@ -9,6 +9,7 @@ const char* errname(err_t err){ case ERR_WRONGINDEX: return "ERR_WRONGINDEX"; case ERR_NOTIMPLEMENTED: return "ERR_NOTIMPLEMENTED"; case ERR_NULLPTR: return "ERR_NULLPTR"; + case ERR_ENDOFSTR: return "ERR_ENDOFSTR"; default: return "UNKNOWN_ERROR"; } } diff --git a/DtsodC/src/base/errors.h b/DtsodC/src/base/errors.h index 2ca7919..07fd140 100644 --- a/DtsodC/src/base/errors.h +++ b/DtsodC/src/base/errors.h @@ -2,12 +2,12 @@ typedef enum err_t { SUCCESS, //not an error - ERR_MAXLENGTH, ERR_WRONGTYPE, ERR_WRONGINDEX, ERR_NOTIMPLEMENTED, ERR_NULLPTR + ERR_MAXLENGTH, ERR_WRONGTYPE, ERR_WRONGINDEX, ERR_NOTIMPLEMENTED, ERR_NULLPTR, ERR_ENDOFSTR } err_t; const char* errname(err_t err); -void _throwint(int err, const char* srcfile, int line, const char* funcname); +void _throwint(int err, const char* srcfile, int line, const char* funcname) ; void _throwstr(const char* errmesg, const char* srcfile, int line, const char* funcname); #pragma GCC diagnostic ignored "-Wint-conversion" #define throw(E) \ diff --git a/DtsodC/src/base/types.h b/DtsodC/src/base/types.h index 30cba80..a487b47 100644 --- a/DtsodC/src/base/types.h +++ b/DtsodC/src/base/types.h @@ -14,7 +14,10 @@ typedef enum my_type{ Null, Float, Double, Char, Bool, UInt8, Int8, UInt16, Int16, UInt32, Int32, UInt64, Int64, UInt8Ptr, Int8Ptr, UInt16Ptr, Int16Ptr, UInt32Ptr, Int32Ptr, UInt64Ptr, Int64Ptr, - UniversalType, STNodePtr + UniversalType, STNodePtr, + AutoarrInt8Ptr, AutoarrUInt8Ptr, AutoarrInt16Ptr, AutoarrUInt16Ptr, + AutoarrInt32Ptr, AutoarrUInt32Ptr, AutoarrInt64Ptr, AutoarrUInt64Ptr, + AutoarrUnitypePtr, AutoarrKVPairPtr } __attribute__ ((__packed__)) my_type; //returns type name @@ -42,3 +45,5 @@ typedef struct Unitype{ } Unitype; #define Uni(TYPE,VAL) (Unitype){.type=TYPE,.TYPE=VAL} +#define UniF(TYPE,FIELD,VAL) (Unitype){.type=TYPE,.FIELD=VAL} +#define UniNull (Unitype){Null,.VoidPtr=NULL}