diff --git a/include/psyc/parser.h b/include/psyc/parser.h index b4b0d89..6331d0d 100644 --- a/include/psyc/parser.h +++ b/include/psyc/parser.h @@ -120,11 +120,14 @@ typedef struct * * @return An instance of the PSYC_Array struct. */ -inline PSYC_Array PSYC_createArray (const char* memory, size_t length) -{ - PSYC_Array arr = {length, memory}; - return arr; -} +inline PSYC_Array PSYC_createArray (const char* memory, size_t length); + +/** + * Initiates the state struct. + * + * @param state Pointer to the state struct that should be initiated. + */ +inline void PSYC_initParseState (PSYC_ParseState* state); /** * Initiates the state struct with flags. @@ -132,48 +135,20 @@ inline PSYC_Array PSYC_createArray (const char* memory, size_t length) * @param state Pointer to the state struct that should be initiated. * @param flags Flags to be set for the parser, see PSYC_ParseFlag. */ -inline void PSYC_initParseState2 (PSYC_ParseState* state, uint8_t flags) -{ - memset(state, 0, sizeof(PSYC_ParseState)); - state->flags = flags; -} - -/** - * Initiates the state struct. - * - * @param state Pointer to the state struct that should be initiated. - */ -inline void PSYC_initParseState (PSYC_ParseState* state) -{ - memset(state, 0, sizeof(PSYC_ParseState)); -} +inline void PSYC_initParseState2 (PSYC_ParseState* state, uint8_t flags); /** * Initiates the list state struct. * * @param state Pointer to the list state struct that should be initiated. */ -inline void PSYC_initParseListState (PSYC_ParseListState* state) -{ - memset(state, 0, sizeof(PSYC_ParseListState)); -} +inline void PSYC_initParseListState (PSYC_ParseListState* state); -inline void PSYC_nextParseBuffer (PSYC_ParseState* state, PSYC_Array newBuf) -{ - state->buffer = newBuf; - state->cursor = 0; -} +inline void PSYC_nextParseBuffer (PSYC_ParseState* state, PSYC_Array newBuf); -inline void PSYC_nextParseListBuffer (PSYC_ParseListState* state, PSYC_Array newBuf) -{ - state->buffer = newBuf; - state->cursor = 0; -} +inline void PSYC_nextParseListBuffer (PSYC_ParseListState* state, PSYC_Array newBuf); -inline size_t PSYC_getContentLength (PSYC_ParseState* s) -{ - return s->contentLength; -} +inline size_t PSYC_getContentLength (PSYC_ParseState* s); /** * Parse PSYC packets. diff --git a/include/psyc/render.h b/include/psyc/render.h index 0569d01..0620f2b 100644 --- a/include/psyc/render.h +++ b/include/psyc/render.h @@ -42,10 +42,7 @@ typedef struct * * @param state Pointer to the state struct that should be initiated. */ -inline void PSYC_initRenderState (PSYC_RenderState* state) -{ - memset(state, 0, sizeof(PSYC_RenderState)); -} +inline void PSYC_initRenderState (PSYC_RenderState* state); int PSYC_renderVar(PSYC_RenderState* render, const char* name, size_t nlength, diff --git a/src/parser.c b/src/parser.c index 6d18511..02d9fd5 100644 --- a/src/parser.c +++ b/src/parser.c @@ -15,6 +15,45 @@ return ret; \ } +inline PSYC_Array PSYC_createArray (const char* memory, size_t length) +{ + PSYC_Array arr = {length, memory}; + return arr; +} + +inline void PSYC_initParseState (PSYC_ParseState* state) +{ + memset(state, 0, sizeof(PSYC_ParseState)); +} + +inline void PSYC_initParseState2 (PSYC_ParseState* state, uint8_t flags) +{ + memset(state, 0, sizeof(PSYC_ParseState)); + state->flags = flags; +} + +inline void PSYC_initParseListState (PSYC_ParseListState* state) +{ + memset(state, 0, sizeof(PSYC_ParseListState)); +} + +inline void PSYC_nextParseBuffer (PSYC_ParseState* state, PSYC_Array newBuf) +{ + state->buffer = newBuf; + state->cursor = 0; +} + +inline void PSYC_nextParseListBuffer (PSYC_ParseListState* state, PSYC_Array newBuf) +{ + state->buffer = newBuf; + state->cursor = 0; +} + +inline size_t PSYC_getContentLength (PSYC_ParseState* s) +{ + return s->contentLength; +} + /** * Determines if the argument is a glyph. * Glyphs are: : = + - ? ! diff --git a/src/render.c b/src/render.c index 358458c..2268aa7 100644 --- a/src/render.c +++ b/src/render.c @@ -1,6 +1,11 @@ #include "psyc/lib.h" #include "psyc/render.h" +inline void PSYC_initRenderState (PSYC_RenderState* state) +{ + memset(state, 0, sizeof(PSYC_RenderState)); +} + PSYC_RenderRC PSYC_renderVar(PSYC_RenderState* state, const char* name, size_t nlength, const char* value, size_t vlength, diff --git a/src/variable.c b/src/variable.c index abd786a..d666047 100644 --- a/src/variable.c +++ b/src/variable.c @@ -1,7 +1,7 @@ #include #include -const PSYC_Array PSYC_routingVars[] = +const PSYC_Array PSYC_routingVars[] = /// Routing variables in alphabetical order. { {17, "_amount_fragments"}, { 8, "_context"}, diff --git a/test/testParser.c b/test/testParser.c index 6815441..7b1f8e8 100644 --- a/test/testParser.c +++ b/test/testParser.c @@ -7,7 +7,7 @@ int main(int argc, char** argv) { int index, ret; - uint8_t buffer[2048], modifier; + char buffer[2048], modifier; PSYC_Array name, value, elem; PSYC_ParseState state; PSYC_ParseListState listState; diff --git a/test/testRender.c b/test/testRender.c index c69b1c0..d2f856e 100644 --- a/test/testRender.c +++ b/test/testRender.c @@ -19,13 +19,13 @@ int writePresence(const char *avail, int availlen, const char *desc, int desclen } // if (PSYC_initBuffer(pb, WHATEVER)) die("PSYC_initBuffer hates me"); - (void) PSYC_renderHeader(pb, "_context", 0, - myUNI, sizeof(myUNI), PSYC_FLAG_ROUTING, 0); + (void) PSYC_renderVar(pb, "_context", 0, + myUNI, sizeof(myUNI), PSYC_RENDER_ROUTING, 0); - // the first call to PSYC_renderHeader() without PSYC_FLAG_ROUTING adds the - // extra newline to the buffer. later vars with PSYC_FLAG_ROUTING cause an error. - (void) PSYC_renderHeader(pb, "_degree_availability", 0, avail, availlen, 0, C_GLYPH_MODIFIER_ASSIGN); - (void) PSYC_renderHeader(pb, "_description_presence", 0, desc, desclen, 0, C_GLYPH_MODIFIER_ASSIGN); + // the first call to PSYC_renderHeader() without PSYC_RENDER_ROUTING adds the + // extra newline to the buffer. later vars with PSYC_RENDER_ROUTING cause an error. + (void) PSYC_renderVar(pb, "_degree_availability", 0, avail, availlen, 0, C_GLYPH_MODIFIER_ASSIGN); + (void) PSYC_renderVar(pb, "_description_presence", 0, desc, desclen, 0, C_GLYPH_MODIFIER_ASSIGN); // presence is to be assigned permanently in distributed state (void) PSYC_renderBody(pb, "_notice_presence", 0,