From 4de626227a2adfada8e30b042eedf82b68a87614 Mon Sep 17 00:00:00 2001 From: Gabor Adam Toth Date: Fri, 22 Apr 2011 20:50:59 +0200 Subject: [PATCH] s/modifier/operator/ --- include/psyc/parser.h | 12 ++++++------ include/psyc/render.h | 7 +------ include/psyc/syntax.h | 20 ++++++++++---------- src/parser.c | 10 +++++----- src/psyc_parser_cb.h | 18 +++++++++--------- src/render.c | 6 +++--- test/testParser.c | 6 +++--- test/testRender.c | 4 ++-- 8 files changed, 39 insertions(+), 44 deletions(-) diff --git a/include/psyc/parser.h b/include/psyc/parser.h index 6331d0d..22e3866 100644 --- a/include/psyc/parser.h +++ b/include/psyc/parser.h @@ -43,13 +43,13 @@ typedef enum /// from the cursor position to the end. PSYC_PARSE_INSUFFICIENT = 1, /// Routing variable parsing done. -/// Modifier, name & value contains the respective parts. +/// Operator, name & value contains the respective parts. PSYC_PARSE_ROUTING = 2, /// Entity variable parsing done. -/// Modifier, name & value contains the respective parts. +/// Operator, name & value contains the respective parts. PSYC_PARSE_ENTITY = 3, /// Entity variable parsing is incomplete. -/// Modifier & name are complete, value is incomplete. +/// Operator & name are complete, value is incomplete. PSYC_PARSE_ENTITY_INCOMPLETE = 4, /// Body parsing done, name contains method, value contains body. PSYC_PARSE_BODY = 5, @@ -156,14 +156,14 @@ inline size_t PSYC_getContentLength (PSYC_ParseState* s); * Generalized line-based packet parser. * * @param state An initialized PSYC_ParseState - * @param modifier A pointer to a character. In case of a variable, it will - * be set to the modifier of that variable + * @param operator A pointer to a character. In case of a variable, it will + * be set to the operator of that variable * @param name A pointer to a PSYC_Array. It will point to the name of * the variable or method and its length will be set accordingly * @param value A pointer to a PSYC_Array. It will point to the * value/body the variable/method and its length will be set accordingly */ -PSYC_ParseRC PSYC_parse(PSYC_ParseState* state, char* modifier, PSYC_Array* name, PSYC_Array* value); +PSYC_ParseRC PSYC_parse(PSYC_ParseState* state, char* operator, PSYC_Array* name, PSYC_Array* value); /** * List value parser. diff --git a/include/psyc/render.h b/include/psyc/render.h index 0620f2b..1a47149 100644 --- a/include/psyc/render.h +++ b/include/psyc/render.h @@ -3,11 +3,6 @@ #include "syntax.h" -#define PSYC_FLAG_UNDEFINED 0 -#define PSYC_FLAG_NOT_BINARY 1 -#define PSYC_FLAG_YES_BINARY 2 -#define PSYC_FLAG_CHECK_BINARY 3 - typedef enum { PSYC_RENDER_CHECK_LENGTH = 0, @@ -47,7 +42,7 @@ inline void PSYC_initRenderState (PSYC_RenderState* state); int PSYC_renderVar(PSYC_RenderState* render, const char* name, size_t nlength, const char* value, size_t vlength, - PSYC_RenderFlag flags, char modifier); + PSYC_RenderFlag flags, char operator); int PSYC_renderBody(PSYC_RenderState* render, const char* method, size_t mlength, diff --git a/include/psyc/syntax.h b/include/psyc/syntax.h index 004845e..ab4ff0d 100644 --- a/include/psyc/syntax.h +++ b/include/psyc/syntax.h @@ -17,20 +17,20 @@ #define C_GLYPH_SEPARATOR_KEYWORD '_' #define S_GLYPH_SEPARATOR_KEYWORD "_" -#define C_GLYPH_MODIFIER_SET ':' -#define S_GLYPH_MODIFIER_SET ":" +#define C_GLYPH_OPERATOR_SET ':' +#define S_GLYPH_OPERATOR_SET ":" -#define C_GLYPH_MODIFIER_ASSIGN '=' -#define S_GLYPH_MODIFIER_ASSIGN "=" +#define C_GLYPH_OPERATOR_ASSIGN '=' +#define S_GLYPH_OPERATOR_ASSIGN "=" -#define C_GLYPH_MODIFIER_AUGMENT '+' -#define S_GLYPH_MODIFIER_AUGMENT "+" +#define C_GLYPH_OPERATOR_AUGMENT '+' +#define S_GLYPH_OPERATOR_AUGMENT "+" -#define C_GLYPH_MODIFIER_DIMINISH '-' -#define S_GLYPH_MODIFIER_DIMINISH "-" +#define C_GLYPH_OPERATOR_DIMINISH '-' +#define S_GLYPH_OPERATOR_DIMINISH "-" -#define C_GLYPH_MODIFIER_QUERY '?' -#define S_GLYPH_MODIFIER_QUERY "?" +#define C_GLYPH_OPERATOR_QUERY '?' +#define S_GLYPH_OPERATOR_QUERY "?" /* might move into routing.h or something */ #define PSYC_ROUTING 1 diff --git a/src/parser.c b/src/parser.c index 02d9fd5..d1b7017 100644 --- a/src/parser.c +++ b/src/parser.c @@ -154,9 +154,9 @@ 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* modifier, PSYC_Array* name, PSYC_Array* value) +inline PSYC_ParseRC PSYC_parseVar(PSYC_ParseState* state, char* operator, PSYC_Array* name, PSYC_Array* value) { - *modifier = *(state->buffer.ptr + state->cursor); + *operator = *(state->buffer.ptr + state->cursor); ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT); if (PSYC_parseName(state, name) != PSYC_PARSE_SUCCESS) @@ -218,7 +218,7 @@ inline PSYC_ParseRC PSYC_parseVar(PSYC_ParseState* state, char* modifier, PSYC_A * Parse PSYC packets. * Generalized line-based parser. */ -PSYC_ParseRC PSYC_parse(PSYC_ParseState* state, char* modifier, PSYC_Array* name, PSYC_Array* value) +PSYC_ParseRC PSYC_parse(PSYC_ParseState* state, char* operator, PSYC_Array* name, PSYC_Array* value) { int ret; // a return value size_t pos; // a cursor position @@ -248,7 +248,7 @@ PSYC_ParseRC PSYC_parse(PSYC_ParseState* state, char* modifier, PSYC_Array* name // 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, modifier, name, value); + ret = PSYC_parseVar(state, operator, 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* modifier, PSYC_Array* name if (isGlyph(state->buffer.ptr[state->cursor])) { pos = state->cursor; - ret = PSYC_parseVar(state, modifier, name, value); + ret = PSYC_parseVar(state, operator, name, value); state->contentParsed += state->cursor - pos; return ret == PSYC_PARSE_SUCCESS ? PSYC_PARSE_ENTITY : ret; } diff --git a/src/psyc_parser_cb.h b/src/psyc_parser_cb.h index 25b212e..6216fca 100644 --- a/src/psyc_parser_cb.h +++ b/src/psyc_parser_cb.h @@ -46,14 +46,14 @@ void PSYC_parse(const uint8_t* data, unsigned int length, struct PSYC_Parser* pstate); /** @brief FlagMod */ -enum PSYC_Modifier +enum PSYC_Operator { - // variable modifers - ASSIGN=0x02, - AUGMENT=0x04, - DIMINISH=0x08, - SET=0x10, - QUERY=0x20 + // modifier operators + ASSIGN = 0x02, + AUGMENT = 0x04, + DIMINISH = 0x08, + SET = 0x10, + QUERY = 0x20, }; struct PSYC_Parser @@ -79,7 +79,7 @@ struct PSYC_Parser void (*stateCallback)(struct PSYC_Parser* pstate, const uint8_t *name, const unsigned int nlength, const uint8_t *value, const unsigned int vlength, - enum PSYC_Modifier modifiers, char inEntity); + enum PSYC_Operator operators, char inEntity); /** @brief gets called after the routing-header was parsed * @@ -135,7 +135,7 @@ struct PSYC_Parser void (*errorStateCallback)(struct PSYC_Parser* pstate, const uint8_t *name, const unsigned int nlength, const uint8_t *value, const unsigned int vlength, - enum PSYC_Modifier modifiers); + enum PSYC_Operator operators); /******************************************* diff --git a/src/render.c b/src/render.c index 2268aa7..a596124 100644 --- a/src/render.c +++ b/src/render.c @@ -9,15 +9,15 @@ inline void PSYC_initRenderState (PSYC_RenderState* state) PSYC_RenderRC PSYC_renderVar(PSYC_RenderState* state, const char* name, size_t nlength, const char* value, size_t vlength, - const PSYC_RenderFlag flags, char modifier) + const PSYC_RenderFlag flags, char operator) { size_t startc = state->cursor; unless (nlength) nlength = strlen(name); // vlength 0 means an empty variable.. no cheating there - unless (modifier) modifier = C_GLYPH_MODIFIER_SET; + unless (operator) operator = C_GLYPH_OPERATOR_SET; - state->buffer[state->cursor++] = modifier; + state->buffer[state->cursor++] = operator; strncpy(&state->buffer[state->cursor], name, nlength); state->cursor += nlength; diff --git a/test/testParser.c b/test/testParser.c index 7b1f8e8..bdab7e7 100644 --- a/test/testParser.c +++ b/test/testParser.c @@ -7,7 +7,7 @@ int main(int argc, char** argv) { int index, ret; - char buffer[2048], modifier; + char buffer[2048], operator; PSYC_Array name, value, elem; PSYC_ParseState state; PSYC_ParseListState listState; @@ -25,13 +25,13 @@ int main(int argc, char** argv) PSYC_nextParseBuffer(&state, PSYC_createArray(buffer, index)); // try parsing that now - while ((ret = PSYC_parse(&state, &modifier, &name, &value))) + while ((ret = PSYC_parse(&state, &operator, &name, &value))) { switch (ret) { case PSYC_PARSE_ROUTING: case PSYC_PARSE_ENTITY: - write(1, &modifier, 1); + write(1, &operator, 1); case PSYC_PARSE_BODY: // printf("the string is '%.*s'\n", name); write(1, name.ptr, name.length); diff --git a/test/testRender.c b/test/testRender.c index d2f856e..e3900ae 100644 --- a/test/testRender.c +++ b/test/testRender.c @@ -24,8 +24,8 @@ int writePresence(const char *avail, int availlen, const char *desc, int desclen // 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); + (void) PSYC_renderVar(pb, "_degree_availability", 0, avail, availlen, 0, C_GLYPH_OPERATOR_ASSIGN); + (void) PSYC_renderVar(pb, "_description_presence", 0, desc, desclen, 0, C_GLYPH_OPERATOR_ASSIGN); // presence is to be assigned permanently in distributed state (void) PSYC_renderBody(pb, "_notice_presence", 0,