From c2ad0f0bd704d45db8b5659e3c0db24c0b622906 Mon Sep 17 00:00:00 2001 From: Gabor Adam Toth Date: Fri, 22 Apr 2011 23:16:50 +0200 Subject: [PATCH] more PSYC_Packet fields; s/Var/Modifier/ --- include/psyc.h | 19 +++++++++++++++++-- include/psyc/render.h | 2 +- src/parser.c | 6 +++--- src/render.c | 2 +- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/include/psyc.h b/include/psyc.h index ef166db..53c1cf3 100644 --- a/include/psyc.h +++ b/include/psyc.h @@ -79,18 +79,31 @@ typedef enum PSYC_LIST_BINARY = 2, } PSYC_ListType; +typedef enum { + PSYC_MODIFIER_CHECK_LENGTH = 0, + PSYC_MODIFIER_NEED_LENGTH = 1, + PSYC_MODIFIER_NO_LENGTH = 2, + PSYC_MODIFIER_ROUTING = 3, +} PSYC_ModifierType; + +typedef enum { + PSYC_CONTENT_CHECK_LENGTH = 0, + PSYC_CONTENT_NEED_LENGTH = 1, + PSYC_CONTENT_NO_LENGTH = 2, +} PSYC_ContentType; + typedef struct { size_t length; const char* ptr; } PSYC_Array; - /* intermediate struct for a PSYC variable modification */ typedef struct { char oper; // not call it 'operator' as C++ may not like that..? PSYC_Array name; - PSYC_Array parameter; + PSYC_Array value; + PSYC_ModifierType type; } PSYC_Modifier; /* intermediate struct for a PSYC packet */ @@ -99,6 +112,8 @@ typedef struct { PSYC_Modifier **entity; // Header PSYC_Array method; PSYC_Array data; + PSYC_ContentType contentType; + size_t contentLength; } PSYC_Packet; diff --git a/include/psyc/render.h b/include/psyc/render.h index 5e814fb..34c0969 100644 --- a/include/psyc/render.h +++ b/include/psyc/render.h @@ -39,7 +39,7 @@ typedef struct */ inline void PSYC_initRenderState (PSYC_RenderState* state); -int PSYC_renderVar(PSYC_RenderState* render, +int PSYC_renderModifier(PSYC_RenderState* render, const char* name, size_t nlength, const char* value, size_t vlength, PSYC_RenderFlag flags, char oper); diff --git a/src/parser.c b/src/parser.c index bf87986..3638023 100644 --- a/src/parser.c +++ b/src/parser.c @@ -154,7 +154,7 @@ inline PSYC_ParseRC PSYC_parseBinaryValue(PSYC_ParseState* state, PSYC_Array* va * Parse simple or binary variable. * @return PSYC_PARSE_ERROR or PSYC_PARSE_SUCCESS */ -inline PSYC_ParseRC PSYC_parseVar(PSYC_ParseState* state, char* oper, PSYC_Array* name, PSYC_Array* value) +inline PSYC_ParseRC PSYC_parseModifier(PSYC_ParseState* state, char* oper, PSYC_Array* name, PSYC_Array* value) { *oper = *(state->buffer.ptr + state->cursor); ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT); @@ -248,7 +248,7 @@ PSYC_ParseRC PSYC_parse(PSYC_ParseState* state, char* oper, PSYC_Array* name, PS // so just test if the first char is a glyph. if (isGlyph(state->buffer.ptr[state->cursor])) // is the first char a glyph? { // it is a glyph, so a variable starts here - ret = PSYC_parseVar(state, oper, name, value); + ret = PSYC_parseModifier(state, oper, name, value); return ret == PSYC_PARSE_SUCCESS ? PSYC_PARSE_ROUTING : ret; } else // not a glyph @@ -310,7 +310,7 @@ PSYC_ParseRC PSYC_parse(PSYC_ParseState* state, char* oper, PSYC_Array* name, PS if (isGlyph(state->buffer.ptr[state->cursor])) { pos = state->cursor; - ret = PSYC_parseVar(state, oper, name, value); + ret = PSYC_parseModifier(state, oper, name, value); state->contentParsed += state->cursor - pos; return ret == PSYC_PARSE_SUCCESS ? PSYC_PARSE_ENTITY : ret; } diff --git a/src/render.c b/src/render.c index b83c9fb..7052f79 100644 --- a/src/render.c +++ b/src/render.c @@ -6,7 +6,7 @@ inline void PSYC_initRenderState (PSYC_RenderState* state) memset(state, 0, sizeof(PSYC_RenderState)); } -PSYC_RenderRC PSYC_renderVar(PSYC_RenderState* state, +PSYC_RenderRC PSYC_renderModifier(PSYC_RenderState* state, const char* name, size_t nlength, const char* value, size_t vlength, const PSYC_RenderFlag flags, char oper)