some fixes

This commit is contained in:
Timerix22 2022-04-18 13:50:33 +03:00
parent 354e6abaea
commit 1d7beebf6c
5 changed files with 62 additions and 23 deletions

View File

@ -53,7 +53,6 @@ void StringBuilder_append_uint64(StringBuilder* b, uint64 a){
a/=10;
}
string rev=string_reverse((string){buf,i});
printf("\e[95mrev:%s\n",string_cpToCptr(rev));
StringBuilder_append_string(b,rev);
free(rev.ptr);
}

View File

@ -9,19 +9,32 @@
// special func for throwing error messages about wrong characters in deserializing text
Maybe ERROR_WRONGCHAR(const char c, char* text, char* text_first, const char* srcfile, int line, const char* funcname){
char errBuf[33];
errBuf[32]='\0';
char* errText=text-16;
if(errText<text_first) errText=text_first;
for(uint8 i=0; i<32; i++){
// writes 16 chars before and 15 after the wrongchar
char _c=errText[i];
char errBuf[68];
errBuf[67]='\0';
char* errText=text-32;
uint8 cplace=32;
if(errText<text_first) {
cplace=errText-text_first;
errText=text_first;
}
uint8 i=0;
for(; i<cplace; i++){
// writes 32 chars before the wrongchar
errBuf[i]=errText[i];
}
//prints wrongchar in braces
errBuf[i++]='<';
errBuf[i++]=c;
errBuf[i++]='>';
for(; i<cplace+3+32; i++){
// writes 32 chars after the wrongchar
char _c=errText[i-2];
errBuf[i]=_c;
if(!_c) break;
}
char* errmsg=malloc(256);
char* errmsg=malloc(512);
IFWIN(
sprintf_s(errmsg,256, "unexpected <%c> at:\n"
sprintf_s(errmsg,512, "unexpected <%c> at:\n"
" \"%s\"\n"
"\\___[%s:%d] %s()",
c,errBuf, srcfile,line,funcname),
@ -83,9 +96,8 @@ Maybe __ReadName(DeserializeSharedData* shared){
nameStr.ptr=text+1; // skips '\n'
break;
case '}':
if(!calledRecursively) safethrow_wrongchar(c);
if((*++text)!=';')
safethrow_wrongchar(c);
if(!calledRecursively || nameStr.length!=0) safethrow_wrongchar(c);
return SUCCESS(UniPtr(CharPtr,NULL));
case ':':
return SUCCESS(UniPtr(CharPtr,string_cpToCptr(nameStr)));
case '$':
@ -211,7 +223,7 @@ Maybe __ReadValue(DeserializeSharedData* shared){
string valueStr={text+1,0};
Unitype value;
bool spaceAfterVal=false;
while ((c=*++text)) switch (c){
case ' ': case '\t':
case '\r': case '\n':
@ -232,7 +244,7 @@ Maybe __ReadValue(DeserializeSharedData* shared){
valueStr.ptr=text+1; // skips '\n'
break;
case '"':
if(valueStr.length!=0) safethrow_wrongchar(c);
if(valueStr.length!=0) { printf("length: %u valueStr: %s\n",valueStr.length, string_cpToCptr(valueStr)); safethrow_wrongchar(c);}
try(ReadString(),maybeString)
value=maybeString.value;
break;
@ -240,7 +252,8 @@ Maybe __ReadValue(DeserializeSharedData* shared){
if(valueStr.length!=0) safethrow_wrongchar(c);
++text; // skips '{'
try(__deserialize(&text,true), val)
return SUCCESS(val.value);
value=val.value;
break;
case '[':
if(valueStr.length!=0) safethrow_wrongchar(c);
try(ReadList(),maybeList)
@ -283,7 +296,9 @@ Maybe __deserialize(char** _text, bool _calledRecursively) {
if(!maybeName.value.VoidPtr) // end of file or '}' in recursive call
goto END;
char* nameCPtr=maybeName.value.VoidPtr;
try(ReadValue(), val)
printf("name: %s ", nameCPtr);
try(ReadValue(), val){
printuni(val.value);printf("\n");
if(partOfDollarList){
Autoarr(Unitype)* list;
Unitype lu;
@ -297,7 +312,8 @@ Maybe __deserialize(char** _text, bool _calledRecursively) {
}
Autoarr_add(list,val.value);
}
else Hashtable_add(dict,nameCPtr,val.value);
else Hashtable_add(dict,nameCPtr,val.value);
}
}
END:

View File

@ -31,12 +31,12 @@ build_test_dbg: clear_c clear_bin
test: build_test
@echo -e '\n\e[96m----------------[test]-----------------\e[0m'
$(TEST_FILE)
$(OUTDIR)/$(TEST_FILE)
valgrind: build_test_dbg
@echo -e '\n\e[96m--------------[valgrind]---------------\e[0m'
valgrind -s --read-var-info=yes --track-origins=yes --fullpath-after=kerep/ \
--leak-check=full --show-leak-kinds=all $(TEST_FILE).dbg
--leak-check=full --show-leak-kinds=all $(OUTDIR)/$(TEST_FILE).dbg
LIB_FILE=kerep.so
LIB_ARGS=$(OPT_ARGS) $(WARN_ARGS)\

View File

@ -115,7 +115,7 @@ void Unitype_free(Unitype u){
}
}
#define SPRINT_BUFSIZE 64
#define SPRINT_BUFSIZE 1024
void sprintuni(char* buf,Unitype v){
IFWIN(
switch (v.type) {
@ -140,8 +140,7 @@ void sprintuni(char* buf,Unitype v){
}
void printuni(Unitype v){
char* s=malloc(SPRINT_BUFSIZE);
char s[SPRINT_BUFSIZE];
sprintuni(s,v);
fputs(s, stdout);
free(s);
}

View File

@ -30,6 +30,10 @@ void print_dtsod(Hashtable* dtsod){
}));
}
#include <errno.h>
void test_dtsod(){
optime(__func__,1,({
printf("\e[96m-------------[test_dtsod]-------------\n");
@ -59,5 +63,26 @@ void test_dtsod(){
}));
free(s);
FILE* f=fopen("messages.dtsod", "r");
printf("f: %p\n", f);
if(f==NULL){
perror("error ");
throw("can't open file");
}
char fbuf[65535];
uint32 i=0;
char cc;
while((cc=fgetc(f))!=EOF){
fbuf[i++]=cc;
}
fbuf[i]='\0';
printf("read %u chars", i);
Maybe rrr=DtsodV24_deserialize(fbuf);
if(rrr.errmsg) {
throw(rrr.errmsg);
}
else dtsod=rrr.value.VoidPtr;
Hashtable_free(dtsod);
}));
}