1
0
Fork 0
mirror of git://git.psyc.eu/libpsyc synced 2024-08-15 03:19:02 +00:00

updated testparser to work with the new api. Debugging time now

This commit is contained in:
Marenz 2011-04-17 13:25:06 +02:00
parent 69ca100ed0
commit b6ef420efa
5 changed files with 46 additions and 67 deletions

View file

@ -9,12 +9,12 @@ enum PSYC_Flags
enum PSYC_ReturnCodes enum PSYC_ReturnCodes
{ {
PSYC_SUCCESS = 0, PSYC_METHOD = 1,
PSYC_INSUFFICIENT = 1, PSYC_INSUFFICIENT,
PSYC_ROUTING = 2, PSYC_ROUTING,
PSYC_ENTITY = 3, PSYC_ENTITY,
PSYC_COMPLETE = 4, PSYC_COMPLETE,
PSYC_HEADER_COMPLETE = 5, PSYC_HEADER_COMPLETE,
}; };
@ -35,7 +35,7 @@ typedef struct
unsigned int contentLength; unsigned int contentLength;
} PSYC_State; } PSYC_State;
#ifndef PSYC_COMPILE_LIBRARY
inline PSYC_Array PSYC_CreateArray (uint8_t* const memory, unsigned int length) inline PSYC_Array PSYC_CreateArray (uint8_t* const memory, unsigned int length)
{ {
PSYC_Array arr = {length, memory}; 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) inline unsigned int PSYC_getBodyLength (PSYC_State* state)
{ {
return state->length; return state->length;
} }
#endif
int PSYC_parse(PSYC_State* state,
PSYC_Array* name, PSYC_Array* value,
uint8_t* modifier, unsigned long *expectedBytes);

View file

@ -12,7 +12,7 @@ diet:
/opt/diet/bin/diet ar rcs libpsyc.a $O /opt/diet/bin/diet ar rcs libpsyc.a $O
lib: $S lib: $S
${CC} -static -c -Os $S -lc -DDEBUG ${CC} -static -c -Os $S -lc -DDEBUG -DPSYC_COMPILE_LIBRARY
ar rcs libpsyc.a $O ar rcs libpsyc.a $O
match: match.c match: match.c

View file

@ -87,7 +87,7 @@ start:
// a NL follows the length // a NL follows the length
if (state->buffer.ptr[state->cursor] != '\n') if (state->buffer.ptr[state->cursor] != '\n')
{ {
return -10;
} }
} }

View file

@ -2,7 +2,7 @@ CFLAGS=-I.. -DDEBUG
LDFLAGS=-L.. -lpsyc LDFLAGS=-L.. -lpsyc
works: works:
cc -I.. -DDEBUG -L.. testParser.c -o testParser -lpsyc cc -I../../include -DDEBUG -L.. parser/testParser.c -o testParser -lpsyc
it: testParser it: testParser

View file

@ -1,11 +1,11 @@
#include <parser.h> #include <psyc/parser.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <fcntl.h> #include <fcntl.h>
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
const uint8_t buffer[2048]; uint8_t buffer[2048];
int index; int index;
int file = open(argv[1],O_RDONLY); int file = open(argv[1],O_RDONLY);
@ -13,61 +13,40 @@ int main(int argc, char** argv)
return -1; return -1;
index = read(file,(void*)buffer,sizeof(buffer)); index = read(file,(void*)buffer,sizeof(buffer));
PSYC_State state;
PSYC_initState(&state);
unsigned int cursor=0,tmp=0; 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; switch (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)
{ {
write(0,varname,nl); case PSYC_ROUTING:
write(0," = ",3); case PSYC_ENTITY:
write(0,varvalue,vl); case PSYC_METHOD:
write(0,"\n",1); write(0,&modifier,1);
} write(0,name.ptr, name.length);
printf("ret0: %d\ncursor0: %d\n", write(0," = ", 3);
ret,cursor); write(0,value.ptr, value.length);
write(0,"\n", 1);
if(ret == 3 || ret == 2) break;
{ case PSYC_COMPLETE:
write(0,varname,nl); write(0, "Done parsing.\n", 15);
write(0," = ",3); continue;
write(0,varvalue,vl); default:
write(0,"\n",1); printf("Error while parsing: %i\n", ret);
} return;
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);
} }
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; return 0;