diff --git a/include/psyc/parser.h b/include/psyc/parser.h index 6ea5fe8..009563a 100644 --- a/include/psyc/parser.h +++ b/include/psyc/parser.h @@ -1,13 +1,20 @@ #include #include -enum +enum PSYC_Flags +{ + PSYC_HEADER_ONLY = 1 +}; + + +enum PSYC_ReturnCodes { PSYC_SUCCESS = 0, PSYC_INSUFFICIENT = 1, PSYC_ROUTING = 2, PSYC_ENTITY = 3, PSYC_COMPLETE = 4, + PSYC_HEADER_COMPLETE = 5, }; @@ -36,6 +43,12 @@ inline PSYC_Array PSYC_CreateArray (uint8_t* const memory, unsigned int length) return arr; } +inline void PSYC_initState2 (PSYC_State* state, uint8_t flags ) +{ + memset(state, 0, sizeof(PSYC_State)); + state->flags = flags; +} + inline void PSYC_initState (PSYC_State* state) { memset(state, 0, sizeof(PSYC_State)); diff --git a/src/parser.c b/src/parser.c index 074bef8..31814d8 100644 --- a/src/parser.c +++ b/src/parser.c @@ -50,6 +50,7 @@ inline int PSYC_parse( PSYC_Array* name, PSYC_Array* value, uint8_t* modifier, unsigned long* expectedBytes) { +start: /* first we test if we can access the first char */ if(state->buffer.length<=state->cursor) // cursor is not inside the length return PSYC_INSUFFICIENT; // return insufficient data. @@ -95,7 +96,10 @@ inline int PSYC_parse( if(isAlphaNumeric(state->buffer.ptr[state->cursor])) { state->inHeader = 0; - return 2; // return header finished + if (state->flags & PSYC_HEADER_ONLY) + return PSYC_HEADER_COMPLETE; // return header finished + else + goto start; } if(state->buffer.ptr[state->cursor] == '|') @@ -109,7 +113,7 @@ inline int PSYC_parse( if(state->buffer.ptr[state->cursor]=='\n') { ++(state->cursor); - return 3; // return packet finished + return PSYC_COMPLETE; // return packet finished } } return -6; // report error @@ -150,7 +154,7 @@ inline int PSYC_parse( if(state->buffer.ptr[state->cursor]=='\n') { ++(state->cursor); - return 3; // return packet finished + return PSYC_COMPLETE; // return packet finished } } return -5; // report error @@ -289,7 +293,7 @@ inline int PSYC_parse( { /* packet finishes here */ state->cursor+=3; - return 3; + return PSYC_COMPLETE; } } @@ -385,6 +389,6 @@ inline int PSYC_parse( return -4; state->cursor+=1; - return 3; // packet is complete + return PSYC_COMPLETE; // packet is complete }