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)
|
2011-04-19 07:21:00 +00:00
|
|
|
return -1;
|
2010-02-20 16:41:16 +00:00
|
|
|
index = read(file,(void*)buffer,sizeof(buffer));
|
|
|
|
|
2011-04-19 07:21:00 +00:00
|
|
|
write(1, ">> INPUT:\n", 10);
|
|
|
|
write(1, buffer, index);
|
|
|
|
write(1, ">> PARSE:\n", 10);
|
2011-04-17 11:25:06 +00:00
|
|
|
|
|
|
|
PSYC_State state;
|
|
|
|
PSYC_initState(&state);
|
|
|
|
|
2011-04-19 07:21:00 +00:00
|
|
|
//unsigned int cursor=0,tmp=0;
|
|
|
|
//unsigned long expectedBytes=0;
|
2011-04-17 11:25:06 +00:00
|
|
|
uint8_t modifier;
|
|
|
|
int ret;
|
|
|
|
PSYC_Array name, value;
|
2010-02-20 16:41:16 +00:00
|
|
|
|
2011-04-18 08:09:35 +00:00
|
|
|
PSYC_nextBuffer(&state, PSYC_createArray(buffer, index));
|
2010-02-20 16:41:16 +00:00
|
|
|
|
2011-04-19 07:21:00 +00:00
|
|
|
// try parsing that now
|
|
|
|
while((ret=PSYC_parse(&state, &modifier, &name, &value)))
|
2011-04-17 11:25:06 +00:00
|
|
|
{
|
|
|
|
switch (ret)
|
2010-02-20 21:29:09 +00:00
|
|
|
{
|
2011-04-17 11:25:06 +00:00
|
|
|
case PSYC_ROUTING:
|
|
|
|
case PSYC_ENTITY:
|
2011-04-19 07:21:00 +00:00
|
|
|
write(1, &modifier, 1);
|
|
|
|
case PSYC_BODY:
|
|
|
|
write(1, name.ptr, name.length);
|
|
|
|
write(1, " = ", 3);
|
|
|
|
write(1, value.ptr, value.length);
|
|
|
|
write(1, "\n", 1);
|
2011-04-17 11:25:06 +00:00
|
|
|
break;
|
|
|
|
case PSYC_COMPLETE:
|
2011-04-19 07:21:00 +00:00
|
|
|
printf("Done parsing.\n");
|
2011-04-17 11:25:06 +00:00
|
|
|
continue;
|
2011-04-19 07:21:00 +00:00
|
|
|
case PSYC_INSUFFICIENT:
|
|
|
|
printf("Insufficient data.\n");
|
|
|
|
return 0;
|
2011-04-17 11:25:06 +00:00
|
|
|
default:
|
|
|
|
printf("Error while parsing: %i\n", ret);
|
2011-04-19 07:21:00 +00:00
|
|
|
return 1;
|
2010-02-20 21:29:09 +00:00
|
|
|
}
|
2010-02-20 16:41:16 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|