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

54 lines
999 B
C
Raw Normal View History

#include <psyc/parser.h>
2010-02-20 16:41:16 +00:00
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
int main(int argc, char** argv)
{
uint8_t buffer[2048];
2010-02-20 16:41:16 +00:00
int index;
int file = open(argv[1],O_RDONLY);
if(file < 0)
return -1;
index = read(file,(void*)buffer,sizeof(buffer));
PSYC_State state;
PSYC_initState(&state);
2010-02-20 16:41:16 +00:00
unsigned int cursor=0,tmp=0;
unsigned long expectedBytes=0;
uint8_t modifier;
int ret;
PSYC_Array name, value;
2010-02-20 16:41:16 +00:00
PSYC_nextBuffer(&state, PSYC_CreateArray(buffer, index));
2010-02-20 16:41:16 +00:00
// try parsing that now
while(ret=PSYC_parse(&state, &name, &value, &modifier, &expectedBytes))
{
switch (ret)
{
case PSYC_ROUTING:
case PSYC_ENTITY:
write(0,&modifier,1);
2011-04-17 12:22:01 +00:00
case PSYC_METHOD:
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;
}
2010-02-20 16:41:16 +00:00
}
return 0;
}