diff --git a/include/psyc/parser.h b/include/psyc/parser.h index 23e5018..6b69cb1 100644 --- a/include/psyc/parser.h +++ b/include/psyc/parser.h @@ -1,15 +1,11 @@ #include #include -enum -{ - -} typedef struct { unsigned int length; - const uint8_t *ptr; + const uint8_t * ptr; } PSYC_Array; typedef struct @@ -23,7 +19,7 @@ typedef struct } PSYC_State; -inline PSYC_Array (const uint8_t memory, unsigned int length) +inline PSYC_Array PSYC_CreateArray (uint8_t* const memory, unsigned int length) { PSYC_Array arr = {length, memory}; @@ -41,11 +37,9 @@ inline void PSYC_nextBuffer (PSYC_State* state, PSYC_Array newBuf) } -int PSYC_parse(PSYC_State* state, - PSYC_ConstArray name, - PSYC_ConstArray value, - uint8_t modifier, - unsigned long *expectedBytes); +inline int PSYC_parse(PSYC_State* state, + PSYC_Array* name, PSYC_Array* value, + uint8_t* modifier, unsigned long *expectedBytes); inline unsigned int PSYC_getBodyLength (PSYC_State* state) diff --git a/src/Makefile b/src/Makefile index 238510d..9337223 100644 --- a/src/Makefile +++ b/src/Makefile @@ -9,5 +9,5 @@ diet: /opt/diet/bin/diet ar rcs libpsyc.a libpsyc.o lib: - ${CC} -static -c -Os parser.c -lc -o libpsyc.o -DDEBUG + ${CC} -static -c -Os parser.c -lc -o libpsyc.o -DDEBUG -I../include ar rcs libpsyc.a libpsyc.o diff --git a/src/parser.c b/src/parser.c index 4091f80..cadfe43 100644 --- a/src/parser.c +++ b/src/parser.c @@ -5,7 +5,7 @@ #include #endif - +#include /** @brief isGlyph * @@ -44,22 +44,10 @@ inline char isAlphaNumeric(uint8_t c) -int PSYC_parse(PSYC_State* state, - PSYC_ConstArray name, - PSYC_ConstArray value, - uint8_t modifier, - unsigned long *expectedBytes) -{ - -} - - - - /** @brief generalized linebased parser */ inline int PSYC_parse( PSYC_State* state, - PSYC_Array* name, PSYC_Array* value + PSYC_Array* name, PSYC_Array* value, uint8_t* modifier, unsigned long* expectedBytes) { /* first we test if we can access the first char */ @@ -101,7 +89,16 @@ inline int PSYC_parse( return -6; // report error }else // it is a glyph, so a variable name starts here { - *modifier = *state->buffer.ptr+state->cursor; + *modifier = *(state->buffer.ptr+state->cursor); + + if (state->buffer.length <= ++(state->cursor)) + { + state->cursor = startc; // rewind to start of line + return 1; // return insufficient + } + + name->ptr = state->buffer.ptr + state->cursor; + name->length = 0; } } @@ -140,6 +137,14 @@ inline int PSYC_parse( } else { + *modifier = *(state->buffer.ptr+state->cursor); + + if (state->buffer.length <= ++(state->cursor)) + { + state->cursor = startc; // rewind + return 1; // return insufficient + } + name->ptr = state->buffer.ptr+state->cursor; name->length=1; } @@ -177,7 +182,6 @@ inline int PSYC_parse( break; // not valid? then stop the loop right here ++(name->length); // was a valid char, increase length - } /* we now parsed the variable name successfully