2011-04-17 11:25:06 +00:00
|
|
|
#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)
|
|
|
|
{
|
2011-04-17 11:25:06 +00:00
|
|
|
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));
|
|
|
|
|
2011-04-17 11:25:06 +00:00
|
|
|
|
|
|
|
PSYC_State state;
|
|
|
|
PSYC_initState(&state);
|
|
|
|
|
2010-02-20 16:41:16 +00:00
|
|
|
unsigned int cursor=0,tmp=0;
|
2011-04-17 11:25:06 +00:00
|
|
|
unsigned long expectedBytes=0;
|
|
|
|
uint8_t modifier;
|
|
|
|
int ret;
|
|
|
|
PSYC_Array name, value;
|
2010-02-20 16:41:16 +00:00
|
|
|
|
2011-04-17 11:25:06 +00:00
|
|
|
PSYC_nextBuffer(&state, PSYC_CreateArray(buffer, index));
|
2010-02-20 16:41:16 +00:00
|
|
|
|
2011-04-17 11:25:06 +00:00
|
|
|
// try parsing that now
|
|
|
|
while(ret=PSYC_parse(&state, &name, &value, &modifier, &expectedBytes))
|
|
|
|
{
|
|
|
|
switch (ret)
|
2010-02-20 21:29:09 +00:00
|
|
|
{
|
2011-04-17 11:25:06 +00:00
|
|
|
case PSYC_ROUTING:
|
|
|
|
case PSYC_ENTITY:
|
|
|
|
write(0,&modifier,1);
|
2011-04-17 12:22:01 +00:00
|
|
|
case PSYC_METHOD:
|
2011-04-17 11:25:06 +00:00
|
|
|
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 21:29:09 +00:00
|
|
|
}
|
|
|
|
|
2010-02-20 16:41:16 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|