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

parser: fix for empty data, testParser: verbose mode

This commit is contained in:
tg(x) 2011-04-26 03:43:49 +02:00
parent 6058b8b58c
commit 1a0b28003d
5 changed files with 32 additions and 26 deletions

View file

@ -354,18 +354,20 @@ psycParseRC psyc_parse(psycParseState* state, char* oper, psycString* name, psyc
{
while (1)
{
if (state->buffer.ptr[state->cursor] == '\n')
uint8_t nl = state->buffer.ptr[state->cursor] == '\n';
// check for |\n if we're at the start of data or we have found a \n
if (state->cursor == state->startc || nl)
{
if (state->cursor+2 >= state->buffer.length) // incremented cursor inside length?
if (state->cursor+1+nl >= state->buffer.length) // incremented cursor inside length?
{
state->cursor = state->startc;
return PSYC_PARSE_INSUFFICIENT;
}
if (state->buffer.ptr[state->cursor+1] == '|' &&
state->buffer.ptr[state->cursor+2] == '\n') // packet ends here
if (state->buffer.ptr[state->cursor+nl] == '|' &&
state->buffer.ptr[state->cursor+1+nl] == '\n') // packet ends here
{
state->cursor++;
state->cursor += nl;
state->part = PSYC_PART_END;
return PSYC_PARSE_BODY;
}

View file

@ -9,7 +9,7 @@ all: $(TARGETS)
./isRoutingVar
test: $(TARGETS)
for f in packets/*; do echo "\n>> $$f"; ./testParser $$f; done
for f in packets/*; do echo ">> $$f"; ./testParser $$f; done
clean:
rm -f $(TARGETS)

View file

@ -1,4 +1,4 @@
:_list_understand_modules _state|_fragments|_context
:_list_understand_modules |_state|_fragments|_context
_request_features
|

View file

@ -1,4 +0,0 @@
:_list_understand_modules _state|_fragments|_context
_request_features
|

View file

@ -6,7 +6,7 @@
int main(int argc, char** argv)
{
int indx, ret;
int indx, ret, verbose = argc > 2;
char buffer[2048], oper;
psycString name, value, elem;
psycParseState state;
@ -17,10 +17,11 @@ int main(int argc, char** argv)
return -1;
indx = read(file,(void*)buffer,sizeof(buffer));
// write(1, ">> INPUT\n", 9);
// write(1, buffer, indx);
// write(1, ">> PARSE\n", 9);
if (verbose) {
write(1, ">> INPUT\n", 9);
write(1, buffer, indx);
write(1, ">> PARSE\n", 9);
}
psyc_initParseState(&state);
psyc_nextParseBuffer(&state, psyc_newString(buffer, indx));
@ -33,16 +34,20 @@ int main(int argc, char** argv)
{
case PSYC_PARSE_ROUTING:
case PSYC_PARSE_ENTITY:
write(1, &oper, 1);
if (verbose)
write(1, &oper, 1);
case PSYC_PARSE_BODY:
// printf("the string is '%.*s'\n", name);
write(1, name.ptr, name.length);
write(1, " = ", 3);
write(1, value.ptr, value.length);
write(1, "\n", 1);
if (verbose) {
write(1, name.ptr, name.length);
write(1, " = ", 3);
write(1, value.ptr, value.length);
write(1, "\n", 1);
}
if (memcmp(name.ptr, "_list", 5) == 0)
{
write(1, ">>> LIST START\n", 15);
if (verbose)
write(1, ">>> LIST START\n", 15);
psyc_initParseListState(&listState);
psyc_nextParseListBuffer(&listState, value);
while ((ret = psyc_parseList(&listState, &name, &value, &elem)))
@ -51,9 +56,11 @@ int main(int argc, char** argv)
{
case PSYC_PARSE_LIST_END:
case PSYC_PARSE_LIST_ELEM:
write(1, "|", 1);
write(1, elem.ptr, elem.length);
write(1, "\n", 1);
if (verbose) {
write(1, "|", 1);
write(1, elem.ptr, elem.length);
write(1, "\n", 1);
}
break;
default:
printf("Error while parsing list: %i\n", ret);
@ -62,7 +69,8 @@ int main(int argc, char** argv)
if (ret == PSYC_PARSE_LIST_END)
{
write(1, ">>> LIST END\n", 13);
if (verbose)
write(1, ">>> LIST END\n", 13);
break;
}
}