some fixes
This commit is contained in:
parent
354e6abaea
commit
1d7beebf6c
@ -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);
|
||||
}
|
||||
|
||||
@ -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 '$':
|
||||
@ -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;
|
||||
@ -299,6 +314,7 @@ Maybe __deserialize(char** _text, bool _calledRecursively) {
|
||||
}
|
||||
else Hashtable_add(dict,nameCPtr,val.value);
|
||||
}
|
||||
}
|
||||
|
||||
END:
|
||||
*_text=text;
|
||||
|
||||
4
Makefile
4
Makefile
@ -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)\
|
||||
|
||||
@ -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);
|
||||
}
|
||||
@ -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);
|
||||
}));
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user