diff --git a/include/psyc/parser.h b/include/psyc/parser.h index 009563a..58ea653 100644 --- a/include/psyc/parser.h +++ b/include/psyc/parser.h @@ -9,12 +9,12 @@ enum PSYC_Flags enum PSYC_ReturnCodes { - PSYC_SUCCESS = 0, - PSYC_INSUFFICIENT = 1, - PSYC_ROUTING = 2, - PSYC_ENTITY = 3, - PSYC_COMPLETE = 4, - PSYC_HEADER_COMPLETE = 5, + PSYC_METHOD = 1, + PSYC_INSUFFICIENT, + PSYC_ROUTING, + PSYC_ENTITY, + PSYC_COMPLETE, + PSYC_HEADER_COMPLETE, }; @@ -35,7 +35,7 @@ typedef struct unsigned int contentLength; } PSYC_State; - +#ifndef PSYC_COMPILE_LIBRARY inline PSYC_Array PSYC_CreateArray (uint8_t* const memory, unsigned int length) { PSYC_Array arr = {length, memory}; @@ -60,15 +60,15 @@ inline void PSYC_nextBuffer (PSYC_State* state, PSYC_Array newBuf) } -inline int PSYC_parse(PSYC_State* state, - PSYC_Array* name, PSYC_Array* value, - uint8_t* modifier, unsigned long *expectedBytes); - inline unsigned int PSYC_getBodyLength (PSYC_State* state) { return state->length; } - +#endif + +int PSYC_parse(PSYC_State* state, + PSYC_Array* name, PSYC_Array* value, + uint8_t* modifier, unsigned long *expectedBytes); diff --git a/src/Makefile b/src/Makefile index 10a5e93..1bfc194 100644 --- a/src/Makefile +++ b/src/Makefile @@ -12,7 +12,7 @@ diet: /opt/diet/bin/diet ar rcs libpsyc.a $O lib: $S - ${CC} -static -c -Os $S -lc -DDEBUG + ${CC} -static -c -Os $S -lc -DDEBUG -DPSYC_COMPILE_LIBRARY ar rcs libpsyc.a $O match: match.c diff --git a/src/parser.c b/src/parser.c index 31814d8..4b4628d 100644 --- a/src/parser.c +++ b/src/parser.c @@ -87,7 +87,7 @@ start: // a NL follows the length if (state->buffer.ptr[state->cursor] != '\n') { - + return -10; } } diff --git a/src/tests/Makefile b/src/tests/Makefile index 554c76e..e36efe4 100644 --- a/src/tests/Makefile +++ b/src/tests/Makefile @@ -2,7 +2,7 @@ CFLAGS=-I.. -DDEBUG LDFLAGS=-L.. -lpsyc works: - cc -I.. -DDEBUG -L.. testParser.c -o testParser -lpsyc + cc -I../../include -DDEBUG -L.. parser/testParser.c -o testParser -lpsyc it: testParser diff --git a/src/tests/parser/testParser.c b/src/tests/parser/testParser.c index 8c40ab4..2939f64 100644 --- a/src/tests/parser/testParser.c +++ b/src/tests/parser/testParser.c @@ -1,11 +1,11 @@ -#include +#include #include #include #include int main(int argc, char** argv) { - const uint8_t buffer[2048]; + uint8_t buffer[2048]; int index; int file = open(argv[1],O_RDONLY); @@ -13,61 +13,40 @@ int main(int argc, char** argv) return -1; index = read(file,(void*)buffer,sizeof(buffer)); + + PSYC_State state; + PSYC_initState(&state); + unsigned int cursor=0,tmp=0; - while(cursor < index) + unsigned long expectedBytes=0; + uint8_t modifier; + int ret; + PSYC_Array name, value; + + PSYC_nextBuffer(&state, PSYC_CreateArray(buffer, index)); + + // try parsing that now + while(ret=PSYC_parse(&state, &name, &value, &modifier, &expectedBytes)) { - int ret; - const uint8_t *varname,*varvalue; - unsigned int nl,vl; - // try parsing that now - while((ret=PSYC_parseHeader( - &cursor, - buffer,index, - &varname,&nl, - &varvalue,&vl)) == 0) + switch (ret) { - write(0,varname,nl); - write(0," = ",3); - write(0,varvalue,vl); - write(0,"\n",1); - } - printf("ret0: %d\ncursor0: %d\n", - ret,cursor); - - if(ret == 3 || ret == 2) - { - write(0,varname,nl); - write(0," = ",3); - write(0,varvalue,vl); - write(0,"\n",1); - } - if(ret ==2) // header finished - while((ret=PSYC_parseOpenBody( - &cursor, - buffer,index, - &varname,&nl, - &varvalue,&vl)) == 0) - { - write(0,varname,nl); - write(0," = ",3); - write(0,varvalue,vl); - write(0,"\n",1); + case PSYC_ROUTING: + case PSYC_ENTITY: + case PSYC_METHOD: + write(0,&modifier,1); + write(0,name.ptr, name.length); + write(0," = ", 3); + write(0,value.ptr, value.length); + write(0,"\n", 1); + break; + case PSYC_COMPLETE: + write(0, "Done parsing.\n", 15); + continue; + default: + printf("Error while parsing: %i\n", ret); + return; } - if(ret == 3 || ret == 2) - { - write(0,varname,nl); - write(0," = ",3); - write(0,varvalue,vl); - write(0,"\n",1); - } - - if(tmp != cursor) - tmp=cursor; - else - return 1; - printf("ret: %d\ncursor: %d\n--------\n", - ret,cursor); } return 0;