From 0cd53743e20f2c7cea9a2888d23aa9dc3aac9d24 Mon Sep 17 00:00:00 2001 From: Gabor Adam Toth Date: Tue, 1 Nov 2011 12:06:58 +0100 Subject: [PATCH] refactoring - more renames --- d/include/psyc/common.d | 2 +- d/include/psyc/packet.d | 4 +-- d/include/psyc/parse.d | 4 +-- include/psyc.h | 62 +++++++++++++++++++++++---------- include/psyc/packet.h | 2 +- include/psyc/parse.h | 12 +++---- include/psyc/text.h | 2 +- include/psyc/uniform.h | 1 + include/psyc/variable.h | 2 +- pike/psyc.cmod | 52 ++++++++++++++-------------- src/match.c | 41 ++++++++-------------- src/packet.c | 8 ++--- src/parse.c | 76 ++++++++++++++++++++--------------------- src/render.c | 14 ++++---- src/text.c | 30 ++++++++-------- src/uniform.c | 34 +++++++++--------- src/variable.c | 10 +++--- test/test_list.c | 16 ++++----- test/test_parser.c | 6 ++-- test/test_psyc.c | 24 ++++++------- test/test_text.c | 12 +++---- 21 files changed, 215 insertions(+), 199 deletions(-) diff --git a/d/include/psyc/common.d b/d/include/psyc/common.d index 21938f9..2f41a6b 100644 --- a/d/include/psyc/common.d +++ b/d/include/psyc/common.d @@ -101,7 +101,7 @@ Bool psyc_var_is_routing (char* name, size_t len); bool isRoutingVar (char[] name) { - return psyc_var_is_routing(name.ptr, name.length); //FIXME + return psyc_var_is_routing(name.data, name.length); //FIXME } /** diff --git a/d/include/psyc/packet.d b/d/include/psyc/packet.d index da544e0..a2e5648 100644 --- a/d/include/psyc/packet.d +++ b/d/include/psyc/packet.d @@ -105,7 +105,7 @@ struct Modifier if (value.length > PSYC_MODIFIER_SIZE_THRESHOLD) flag = ModifierFlag.NEED_LENGTH; - else if (memchr(value.ptr, cast(int)'\n', value.length)) + else if (memchr(value.data, cast(int)'\n', value.length)) flag = ModifierFlag.NEED_LENGTH; else flag = ModifierFlag.NO_LENGTH; @@ -162,7 +162,7 @@ struct Packet psyc_packet_length_set(this); with (RenderRC) - switch (psyc_render(this, buffer.ptr, buffer.length)) + switch (psyc_render(this, buffer.data, buffer.length)) { case ERROR_METHOD_MISSING: throw new Exception("Method missing"); diff --git a/d/include/psyc/parse.d b/d/include/psyc/parse.d index 7d21714..4f4dfe7 100644 --- a/d/include/psyc/parse.d +++ b/d/include/psyc/parse.d @@ -247,13 +247,13 @@ struct ParseState ubyte* getRemainingBuffer ( ) { - return cast(ubyte*)this.buffer.ptr + this.cursor; + return cast(ubyte*)this.buffer.data + this.cursor; } void getRemainingBuffer ( ref ubyte[] buf ) { - buf = cast(ubyte[])this.buffer.ptr[cursor .. cursor + getRemainingLength()]; + buf = cast(ubyte[])this.buffer.data[cursor .. cursor + getRemainingLength()]; } } diff --git a/include/psyc.h b/include/psyc.h index 395f645..b980a3d 100644 --- a/include/psyc.h +++ b/include/psyc.h @@ -24,8 +24,8 @@ #define PSYC_C2STR(str) {sizeof(str)-1, str} #define PSYC_C2ARG(str) str, sizeof(str)-1 -#define PSYC_S2ARG(str) (str).ptr, (str).length -#define PSYC_S2ARG2(str) (str).length, (str).ptr +#define PSYC_S2ARG(str) (str).data, (str).length +#define PSYC_S2ARG2(str) (str).length, (str).data #define PSYC_NUM_ELEM(a) (sizeof(a) / sizeof(*(a))) @@ -37,6 +37,12 @@ typedef enum PSYC_YES = 1, } PsycBool; +typedef enum +{ + PSYC_OK = 1, + PSYC_ERROR = -1, +} PsycRC; + /** * PSYC packet parts. */ @@ -96,14 +102,20 @@ typedef struct /// Length of the data pointed to by ptr size_t length; /// pointer to the data - char *ptr; + char *data; } PsycString; typedef struct { PsycString key; - int value; -} PsycMatchVar; + void *value; +} PsycDict; + +typedef struct +{ + PsycString key; + intptr_t value; +} PsycDictInt; /** * Shortcut for creating a PsycString. @@ -140,23 +152,37 @@ int psyc_matches (char *sho, size_t slen, char *lon, size_t llen); /** - * Check if keyword is in array. + * Look up value associated with a key in a dictionary. * - * @param array The array to search, should be ordered alphabetically. - * @param size Size of array. - * @param kw Keyword to look for. - * @param kwlen Length of keyword. - * @param inherit If true, also look for anything inheriting from kw, - otherwise only exact matches are returned. - * @param matching A temporary array used for keeping track of results. - * Should be the same size as the array we're searching. + * @param dict The dictionary to search, should be ordered alphabetically. + * @param size Size of dict. + * @param key Key to look for. + * @param keylen Length of key. + * @param inherit If true, also look for anything inheriting from key, + otherwise only exact matches are returned. + * @param tmp A temporary array used for keeping track of results. + * Should be the same size as dict. * - * @return The value of the matched variable in the array. + * @return The value of the entry if found, or NULL if not found. */ -int psyc_in_array (const PsycMatchVar *array, size_t size, - const char *kw, size_t kwlen, - PsycBool inherit, int8_t *matching); +void * psyc_dict_lookup (const PsycDict *dict, size_t size, + const char *key, size_t keylen, + PsycBool inherit, int8_t *tmp); + +/** + * Look up value associated with a key in a dictionary of integers. + * @see psyc_dict_lookup + */ +static inline +intptr_t psyc_dict_lookup_int (const PsycDictInt *dict, size_t size, + const char *key, size_t keylen, + PsycBool inherit, int8_t *tmp) +{ + return (intptr_t) psyc_dict_lookup((PsycDict *)dict, size, key, keylen, inherit, tmp); +} + + #include "psyc/variable.h" diff --git a/include/psyc/packet.h b/include/psyc/packet.h index c0fddaa..9608c2c 100644 --- a/include/psyc/packet.h +++ b/include/psyc/packet.h @@ -113,7 +113,7 @@ PsycModifierFlag psyc_modifier_length_check (PsycModifier *m) if (m->value.length > PSYC_MODIFIER_SIZE_THRESHOLD) flag = PSYC_MODIFIER_NEED_LENGTH; - else if (memchr(m->value.ptr, (int)'\n', m->value.length)) + else if (memchr(m->value.data, (int)'\n', m->value.length)) flag = PSYC_MODIFIER_NEED_LENGTH; else flag = PSYC_MODIFIER_NO_LENGTH; diff --git a/include/psyc/parse.h b/include/psyc/parse.h index c1ba421..0b9c737 100644 --- a/include/psyc/parse.h +++ b/include/psyc/parse.h @@ -77,17 +77,17 @@ * // Name, value and operator of the variable can now be found in the * // respective variables: * printf("Variable: %.*s Value: %.*s Operator: %c\n", - * name.length, name.ptr, - * value.length, value.ptr, + * name.length, name.data, + * value.length, value.data, * oper); - * // Note that the .ptr member still points at your original buffer. If + * // Note that the .data member still points at your original buffer. If * // you want to reuse that buffer for the next packet, you better copy it * // before passing it to the parser or you copy each variable now. * break; * case PSYC_PARSE_BODY: // it is the method and the body of the packet. * printf("Method Name: %.*s Body: %.*s\n", - * name.length, name.ptr, // name of the method - * value.length, value.ptr); // value of the body + * name.length, name.data, // name of the method + * value.length, value.data); // value of the body * break; * case PSYC_PARSE_COMPLETE: // parsing of this packet is complete * // You can simply continue parsing till you get the @@ -345,7 +345,7 @@ size_t psyc_parse_remaining_length (PsycParseState *state) static inline const char * psyc_parse_remaining_buffer (PsycParseState *state) { - return state->buffer.ptr + state->cursor; + return state->buffer.data + state->cursor; } /** diff --git a/include/psyc/text.h b/include/psyc/text.h index f3e1bc8..83b0232 100644 --- a/include/psyc/text.h +++ b/include/psyc/text.h @@ -58,7 +58,7 @@ typedef struct * Callback for psyc_text() that produces a value for a match. * * The application looks up a match such as _fruit from [_fruit] and - * if found sets value->ptr & value->length to point to the found value, + * if found sets value->data & value->length to point to the found value, * "Apple" for example. 0 is a legal value for the length. * The callbacks returns either PSYC_TEXT_VALUE_FOUND or * PSYC_TEXT_VALUE_NOT_FOUND if no match found in which case psyc_text diff --git a/include/psyc/uniform.h b/include/psyc/uniform.h index cd0abdb..bf1d84c 100644 --- a/include/psyc/uniform.h +++ b/include/psyc/uniform.h @@ -68,6 +68,7 @@ typedef enum { } PsycTransport; typedef enum { + PSYC_ENTITY_ROOT = 0, PSYC_ENTITY_PERSON = '~', PSYC_ENTITY_PLACE = '@', PSYC_ENTITY_SERVICE = '$', diff --git a/include/psyc/variable.h b/include/psyc/variable.h index 1e42f7e..0c3d9b9 100644 --- a/include/psyc/variable.h +++ b/include/psyc/variable.h @@ -8,7 +8,7 @@ extern const PsycString psyc_routing_vars[]; // Variable types in alphabetical order. -extern const PsycMatchVar psyc_var_types[]; +extern const PsycDictInt psyc_var_types[]; extern const size_t psyc_routing_vars_num; extern const size_t psyc_var_types_num; diff --git a/pike/psyc.cmod b/pike/psyc.cmod index 3aca2dd..211ab81 100644 --- a/pike/psyc.cmod +++ b/pike/psyc.cmod @@ -47,13 +47,13 @@ PsycTextValueRC lookup_value_mapping(const char *name, size_t len, PsycString *v switch(s->type) { case PIKE_T_STRING: //printf("lookup returned %.*s\n", (int) s->u.string->len, STR0(s->u.string)); - value->ptr = (char *) STR0(s->u.string); + value->data = (char *) STR0(s->u.string); value->length = s->u.string->len; break; default: printf("lookup did return !string\n"); // FIXME: we need the automagic value conversion - value->ptr = ""; + value->data = ""; value->length = 0; } return PSYC_TEXT_VALUE_FOUND; @@ -302,29 +302,29 @@ PIKECLASS Parser { ret = psyc_parse(&THIS->parser, &oper, &name, &value); switch(ret) { case PSYC_PARSE_ROUTING: - // printf("R %.*s -> %.*s\n", (int)name.length, name.ptr, (int)value.length, value.ptr); + // printf("R %.*s -> %.*s\n", (int)name.length, name.data, (int)value.length, value.data); mapping_string_insert_string(THIS->rvars, - make_shared_binary_string(name.ptr, name.length), - make_shared_binary_string(value.ptr, value.length)); + make_shared_binary_string(name.data, name.length), + make_shared_binary_string(value.data, value.length)); break; case PSYC_PARSE_ENTITY_START: // entity var with length init_string_builder_alloc(&THIS->incomplete, psyc_parse_value_length(&THIS->parser), 0); // fall thru case PSYC_PARSE_ENTITY_CONT: - string_builder_append(&THIS->incomplete, MKPCHARP(value.ptr, 0), value.length); + string_builder_append(&THIS->incomplete, MKPCHARP(value.data, 0), value.length); break; case PSYC_PARSE_ENTITY_END: - string_builder_append(&THIS->incomplete, MKPCHARP(value.ptr, 0), value.length); + string_builder_append(&THIS->incomplete, MKPCHARP(value.data, 0), value.length); do { struct pike_string *tmp = finish_string_builder(&THIS->incomplete); value.length = tmp->len; - value.ptr = (char *) STR0(tmp); + value.data = (char *) STR0(tmp); // FIXME: not sure if this is really safe free_string(tmp); } while (0); // fall thru case PSYC_PARSE_ENTITY: - //printf("E %.*s -> %.*s\n", (int)name.length, name.ptr, (int)value.length, value.ptr); + //printf("E %.*s -> %.*s\n", (int)name.length, name.data, (int)value.length, value.data); do { err = 0; int type = psyc_var_type(PSYC_S2ARG(&name)); @@ -335,7 +335,7 @@ PIKECLASS Parser { if (psyc_parse_date(&value, &timmy)) { sv.type = PIKE_T_INT; sv.u.integer = timmy; mapping_string_insert(THIS->evars, - make_shared_binary_string(name.ptr, name.length), + make_shared_binary_string(name.data, name.length), &sv); } else { err = 1; @@ -345,7 +345,7 @@ PIKECLASS Parser { if (psyc_parse_time(&value, &timmy)) { sv.type = PIKE_T_INT; sv.u.integer = timmy; mapping_string_insert(THIS->evars, - make_shared_binary_string(name.ptr, name.length), + make_shared_binary_string(name.data, name.length), &sv); } else { err = 2; @@ -354,20 +354,20 @@ PIKECLASS Parser { case PSYC_TYPE_AMOUNT: break; case PSYC_TYPE_DEGREE: - if (value.length && value.ptr[0] >= '0' && value.ptr[0] <= '9') { - sv.type = PIKE_T_FLOAT; sv.u.float_number = (float) (value.ptr[0] - '0') / 10.0; + if (value.length && value.data[0] >= '0' && value.data[0] <= '9') { + sv.type = PIKE_T_FLOAT; sv.u.float_number = (float) (value.data[0] - '0') / 10.0; mapping_string_insert(THIS->evars, - make_shared_binary_string(name.ptr, name.length), + make_shared_binary_string(name.data, name.length), &sv); } else { err = 3; } break; case PSYC_TYPE_FLAG: - if (value.length && value.ptr[0] >= '0' && value.ptr[0] <= '1') { - sv.type = PIKE_T_INT; sv.u.integer = value.ptr[0] - '0'; + if (value.length && value.data[0] >= '0' && value.data[0] <= '1') { + sv.type = PIKE_T_INT; sv.u.integer = value.data[0] - '0'; mapping_string_insert(THIS->evars, - make_shared_binary_string(name.ptr, name.length), + make_shared_binary_string(name.data, name.length), &sv); } else { err = 4; @@ -390,7 +390,7 @@ PIKECLASS Parser { case PSYC_PARSE_LIST_END: // last element retl = 0; case PSYC_PARSE_LIST_ELEM: - sv.type = PIKE_T_STRING; sv.u.string = make_shared_binary_string(elem.ptr, elem.length); + sv.type = PIKE_T_STRING; sv.u.string = make_shared_binary_string(elem.data, elem.length); elems = array_insert(elems, &sv, count++); break; default: @@ -403,7 +403,7 @@ PIKECLASS Parser { sv.type = PIKE_T_ARRAY; sv.u.array = elems; mapping_string_insert(THIS->evars, - make_shared_binary_string(name.ptr, name.length), + make_shared_binary_string(name.data, name.length), &sv); } free_array(elems); @@ -411,8 +411,8 @@ PIKECLASS Parser { break; default: // string mapping_string_insert_string(THIS->evars, - make_shared_binary_string(name.ptr, name.length), - make_shared_binary_string(value.ptr, value.length)); + make_shared_binary_string(name.data, name.length), + make_shared_binary_string(value.data, value.length)); } } while (0); if (err) { // there was an error while @@ -423,21 +423,21 @@ PIKECLASS Parser { case PSYC_PARSE_BODY_START: // if length was given this is used for body init_string_builder_alloc(&THIS->incomplete, psyc_parse_value_length(&THIS->parser), 0); case PSYC_PARSE_BODY_CONT: - string_builder_append(&THIS->incomplete, MKPCHARP(value.ptr, 0), value.length); + string_builder_append(&THIS->incomplete, MKPCHARP(value.data, 0), value.length); break; case PSYC_PARSE_BODY_END: - string_builder_append(&THIS->incomplete, MKPCHARP(value.ptr, 0), value.length); + string_builder_append(&THIS->incomplete, MKPCHARP(value.data, 0), value.length); do { struct pike_string *tmp = finish_string_builder(&THIS->incomplete); value.length = tmp->len; - value.ptr = (char *) STR0(tmp); + value.data = (char *) STR0(tmp); // FIXME: not sure if this is really safe free_string(tmp); } while (0); // fall thru case PSYC_PARSE_BODY: - THIS->method = make_shared_binary_string(name.ptr, name.length); - THIS->body = make_shared_binary_string(value.ptr, value.length); + THIS->method = make_shared_binary_string(name.data, name.length); + THIS->body = make_shared_binary_string(value.data, value.length); break; case PSYC_PARSE_COMPLETE: // apply the callback push_mapping(THIS->rvars); diff --git a/src/match.c b/src/match.c index cc06dc6..de34c1f 100644 --- a/src/match.c +++ b/src/match.c @@ -101,49 +101,38 @@ failed: } /** - * Check if keyword is in array. - * - * @param array The array to search, should be ordered alphabetically. - * @param size Size of array. - * @param kw Keyword to look for. - * @param kwlen Length of keyword. - * @param inherit If true, look for any keyword inheriting from name, - otherwise only exact matches are returned. - * @param matching A temporary array used for keeping track of results. - * Should be the same size as the array we're searching. - * - * @return The value of the matched variable in the array. + * Look up value associated with a key in a dictionary. */ -int psyc_in_array (const PsycMatchVar *array, size_t size, - const char *kw, size_t kwlen, - PsycBool inherit, int8_t *matching) +void * psyc_dict_lookup (const PsycDict *dict, size_t size, + const char *key, size_t keylen, + PsycBool inherit, int8_t *matching) { size_t cursor = 1; uint8_t i, m = 0; //memset(&matching, -1, sizeof matching); - if (kwlen < 2 || kw[0] != '_') + if (keylen < 2 || key[0] != '_') return 0; // first find the keywords with matching length for (i=0; i array[i].key.length && kw[array[i].key.length] == '_')) + if (keylen == dict[i].key.length || + (inherit && keylen > dict[i].key.length && key[dict[i].key.length] == '_')) matching[m++] = i; matching[m] = -1; // mark the end of matching indexes - while (cursor < kwlen && matching[0] >= 0) { + while (cursor < keylen && matching[0] >= 0) { for (i = m = 0; i < size; i++) { if (matching[i] < 0) break; // reached the end of possible matches - if (cursor < array[matching[i]].key.length && - array[matching[i]].key.ptr[cursor] == kw[cursor]) + if (cursor < dict[matching[i]].key.length && + dict[matching[i]].key.data[cursor] == key[cursor]) matching[m++] = matching[i]; // found a match, update matching indexes - else if (cursor == array[matching[i]].key.length && kw[cursor] == '_') - return array[matching[0]].value; // _ after the end of a matching prefix - else if (array[matching[i]].key.ptr[cursor] > kw[cursor]) - break; // passed the possible matches in alphabetical order in the array + else if (cursor == dict[matching[i]].key.length && key[cursor] == '_') + return dict[matching[0]].value; // _ after the end of a matching prefix + else if (dict[matching[i]].key.data[cursor] > key[cursor]) + break; // passed the possible matches in alphabetical order in the dict } if (m < size) @@ -153,7 +142,7 @@ int psyc_in_array (const PsycMatchVar *array, size_t size, } // return first match if found - return matching[0] >= 0 ? array[matching[0]].value : 0; + return matching[0] >= 0 ? dict[matching[0]].value : 0; } #ifdef CMDTOOL diff --git a/src/packet.c b/src/packet.c index dc7f10a..b4444e7 100644 --- a/src/packet.c +++ b/src/packet.c @@ -13,8 +13,8 @@ PsycListFlag psyc_list_length_check (PsycList *list) PsycString *elem = &list->elems[i]; length += 1 + elem->length; // |elem if (length > PSYC_MODIFIER_SIZE_THRESHOLD || - memchr(elem->ptr, (int)'|', elem->length) || - memchr(elem->ptr, (int)'\n', elem->length)) + memchr(elem->data, (int)'|', elem->length) || + memchr(elem->data, (int)'\n', elem->length)) { flag = PSYC_LIST_NEED_LENGTH; break; @@ -76,7 +76,7 @@ size_t psyc_modifier_length (PsycModifier *m) inline PsycPacketFlag psyc_packet_length_check (PsycPacket *p) { - if (p->data.length == 1 && p->data.ptr[0] == C_GLYPH_PACKET_DELIMITER) + if (p->data.length == 1 && p->data.data[0] == C_GLYPH_PACKET_DELIMITER) return PSYC_PACKET_NEED_LENGTH; if (p->data.length > PSYC_CONTENT_SIZE_THRESHOLD) @@ -89,7 +89,7 @@ PsycPacketFlag psyc_packet_length_check (PsycPacket *p) if (p->entity.modifiers[i].flag == PSYC_MODIFIER_NEED_LENGTH) return PSYC_PACKET_NEED_LENGTH; - if (memmem(p->data.ptr, p->data.length, PSYC_C2ARG(PSYC_PACKET_DELIMITER))) + if (memmem(p->data.data, p->data.length, PSYC_C2ARG(PSYC_PACKET_DELIMITER))) return PSYC_PACKET_NEED_LENGTH; return PSYC_PACKET_NO_LENGTH; diff --git a/src/parse.c b/src/parse.c index 8c8e763..42459e3 100644 --- a/src/parse.c +++ b/src/parse.c @@ -31,10 +31,10 @@ typedef enum { static inline parseRC psyc_parse_keyword (PsycParseState *state, PsycString *name) { - name->ptr = state->buffer.ptr + state->cursor; + name->data = state->buffer.data + state->cursor; name->length = 0; - while (psyc_is_kw_char(state->buffer.ptr[state->cursor])) + while (psyc_is_kw_char(state->buffer.data[state->cursor])) { name->length++; // was a valid char, increase length ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT); @@ -58,7 +58,7 @@ parseRC psyc_parse_binary_value (PsycParseState *state, PsycString *value, size_t *length, size_t *parsed) { size_t remaining = *length - *parsed; - value->ptr = state->buffer.ptr + state->cursor; + value->data = state->buffer.data + state->cursor; if (state->cursor + remaining > state->buffer.length) { // value doesn't fit in the buffer completely @@ -84,7 +84,7 @@ static inline parseRC psyc_parse_modifier (PsycParseState *state, char *oper, PsycString *name, PsycString *value) { - *oper = *(state->buffer.ptr + state->cursor); + *oper = *(state->buffer.data + state->cursor); ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT); parseRC ret = psyc_parse_keyword(state, name); @@ -101,26 +101,26 @@ parseRC psyc_parse_modifier (PsycParseState *state, char *oper, // Parse the value. // If we're in the content part check if it's a binary var. - if (state->part == PSYC_PART_CONTENT && state->buffer.ptr[state->cursor] == ' ') // binary arg + if (state->part == PSYC_PART_CONTENT && state->buffer.data[state->cursor] == ' ') // binary arg { // After SP the length follows. ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT); - if (psyc_is_numeric(state->buffer.ptr[state->cursor])) + if (psyc_is_numeric(state->buffer.data[state->cursor])) { state->valueLengthFound = 1; do { - length = 10 * length + state->buffer.ptr[state->cursor] - '0'; + length = 10 * length + state->buffer.data[state->cursor] - '0'; ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT); } - while (psyc_is_numeric(state->buffer.ptr[state->cursor])); + while (psyc_is_numeric(state->buffer.data[state->cursor])); state->valueLength = length; } else return PSYC_PARSE_ERROR_MOD_LEN; // After the length a TAB follows. - if (state->buffer.ptr[state->cursor] != '\t') + if (state->buffer.data[state->cursor] != '\t') return PSYC_PARSE_ERROR_MOD_TAB; if (++(state->cursor) >= state->buffer.length) @@ -132,12 +132,12 @@ parseRC psyc_parse_modifier (PsycParseState *state, char *oper, return PARSE_SUCCESS; } - else if (state->buffer.ptr[state->cursor] == '\t') // simple arg + else if (state->buffer.data[state->cursor] == '\t') // simple arg { ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT); - value->ptr = state->buffer.ptr + state->cursor; + value->data = state->buffer.data + state->cursor; - while (state->buffer.ptr[state->cursor] != '\n') + while (state->buffer.data[state->cursor] != '\n') { value->length++; ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT); @@ -189,7 +189,7 @@ PsycParseRC psyc_parse (PsycParseState *state, char *oper, case PSYC_PART_ROUTING: if (state->routingLength > 0) { - if (state->buffer.ptr[state->cursor] != '\n') + if (state->buffer.data[state->cursor] != '\n') return PSYC_PARSE_ERROR_MOD_NL; ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT); } @@ -197,7 +197,7 @@ PsycParseRC psyc_parse (PsycParseState *state, char *oper, // Each line of the header starts with a glyph, // i.e. :_name, -_name +_name etc, // so just test if the first char is a glyph. - if (psyc_is_glyph(state->buffer.ptr[state->cursor])) // is the first char a glyph? + if (psyc_is_glyph(state->buffer.data[state->cursor])) // is the first char a glyph? { // it is a glyph, so a variable starts here ret = psyc_parse_modifier(state, oper, name, value); state->routingLength += state->cursor - pos; @@ -212,20 +212,20 @@ PsycParseRC psyc_parse (PsycParseState *state, char *oper, case PSYC_PART_LENGTH: // End of header, content starts with an optional length then a NL - if (psyc_is_numeric(state->buffer.ptr[state->cursor])) + if (psyc_is_numeric(state->buffer.data[state->cursor])) { state->contentLengthFound = 1; state->contentLength = 0; do { - state->contentLength = 10 * state->contentLength + state->buffer.ptr[state->cursor] - '0'; + state->contentLength = 10 * state->contentLength + state->buffer.data[state->cursor] - '0'; ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT); } - while (psyc_is_numeric(state->buffer.ptr[state->cursor])); + while (psyc_is_numeric(state->buffer.data[state->cursor])); } - if (state->buffer.ptr[state->cursor] == '\n') // start of content + if (state->buffer.data[state->cursor] == '\n') // start of content { // If we need to parse the header only and we know the content length, // then skip content parsing. @@ -270,7 +270,7 @@ PsycParseRC psyc_parse (PsycParseState *state, char *oper, if (state->contentParsed > 0) { - if (state->buffer.ptr[state->cursor] != '\n') + if (state->buffer.data[state->cursor] != '\n') return PSYC_PARSE_ERROR_MOD_NL; ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_INSUFFICIENT); } @@ -280,7 +280,7 @@ PsycParseRC psyc_parse (PsycParseState *state, char *oper, // So just test if the first char is a glyph. // In the body, the same applies, only that the // method does not start with a glyph. - if (psyc_is_glyph(state->buffer.ptr[state->cursor])) + if (psyc_is_glyph(state->buffer.data[state->cursor])) { ret = psyc_parse_modifier(state, oper, name, value); state->contentParsed += state->cursor - pos; @@ -308,7 +308,7 @@ PsycParseRC psyc_parse (PsycParseState *state, char *oper, return ret; else if (ret == PARSE_SUCCESS) { // the method ends with a \n then the data follows - if (state->buffer.ptr[state->cursor] != '\n') + if (state->buffer.data[state->cursor] != '\n') return PSYC_PARSE_ERROR_METHOD; state->valueLengthFound = 0; @@ -338,7 +338,7 @@ PsycParseRC psyc_parse (PsycParseState *state, char *oper, case PSYC_PART_DATA: PSYC_PART_DATA: - value->ptr = state->buffer.ptr + state->cursor; + value->data = state->buffer.data + state->cursor; value->length = 0; if (state->contentLengthFound) // We know the length of the packet. @@ -370,7 +370,7 @@ PsycParseRC psyc_parse (PsycParseState *state, char *oper, while (1) { - uint8_t nl = state->buffer.ptr[state->cursor] == '\n'; + uint8_t nl = state->buffer.data[state->cursor] == '\n'; // check for |\n if we're at the start of data or we have found a \n if (state->cursor == datac || nl) { @@ -380,8 +380,8 @@ PsycParseRC psyc_parse (PsycParseState *state, char *oper, return PSYC_PARSE_INSUFFICIENT; } - if (state->buffer.ptr[state->cursor+nl] == '|' && - state->buffer.ptr[state->cursor+1+nl] == '\n') // packet ends here + if (state->buffer.data[state->cursor+nl] == '|' && + state->buffer.data[state->cursor+1+nl] == '\n') // packet ends here { if (state->flags & PSYC_PARSE_ROUTING_ONLY) value->length++; @@ -405,7 +405,7 @@ PsycParseRC psyc_parse (PsycParseState *state, char *oper, state->valueLength = 0; state->valueLengthFound = 0; - if (state->buffer.ptr[state->cursor] != '\n') + if (state->buffer.data[state->cursor] != '\n') return PSYC_PARSE_ERROR_END; state->contentParsed++; @@ -417,8 +417,8 @@ PsycParseRC psyc_parse (PsycParseState *state, char *oper, if (state->cursor+1 >= state->buffer.length) // incremented cursor inside length? return PSYC_PARSE_INSUFFICIENT; - if (state->buffer.ptr[state->cursor] == '|' && - state->buffer.ptr[state->cursor+1] == '\n') // packet ends here + if (state->buffer.data[state->cursor] == '|' && + state->buffer.data[state->cursor+1] == '\n') // packet ends here { state->cursor += 2; state->part = PSYC_PART_RESET; @@ -447,12 +447,12 @@ PsycParseListRC psyc_parse_list (PsycParseListState *state, PsycString *elem) if (!state->type) // If type is not set we're at the start { // First character is either | for text lists, or a number for binary lists - if (state->buffer.ptr[state->cursor] == '|') + if (state->buffer.data[state->cursor] == '|') { state->type = PSYC_LIST_TEXT; state->cursor++; } - else if (psyc_is_numeric(state->buffer.ptr[state->cursor])) + else if (psyc_is_numeric(state->buffer.data[state->cursor])) state->type = PSYC_LIST_BINARY; else return PSYC_PARSE_LIST_ERROR_TYPE; @@ -460,13 +460,13 @@ PsycParseListRC psyc_parse_list (PsycParseListState *state, PsycString *elem) if (state->type == PSYC_LIST_TEXT) { - elem->ptr = state->buffer.ptr + state->cursor; + elem->data = state->buffer.data + state->cursor; elem->length = 0; if (state->cursor >= state->buffer.length) return PSYC_PARSE_LIST_END; - while (state->buffer.ptr[state->cursor] != '|') + while (state->buffer.data[state->cursor] != '|') { elem->length++; if (++(state->cursor) >= state->buffer.length) @@ -480,23 +480,23 @@ PsycParseListRC psyc_parse_list (PsycParseListState *state, PsycString *elem) if (!(state->elemParsed < state->elemLength)) { // Element starts with a number. - if (psyc_is_numeric(state->buffer.ptr[state->cursor])) + if (psyc_is_numeric(state->buffer.data[state->cursor])) { do { - state->elemLength = 10 * state->elemLength + state->buffer.ptr[state->cursor] - '0'; + state->elemLength = 10 * state->elemLength + state->buffer.data[state->cursor] - '0'; ADVANCE_CURSOR_OR_RETURN(PSYC_PARSE_LIST_INCOMPLETE); } - while (psyc_is_numeric(state->buffer.ptr[state->cursor])); + while (psyc_is_numeric(state->buffer.data[state->cursor])); } else return PSYC_PARSE_LIST_ERROR_LEN; - if (state->buffer.ptr[state->cursor] != ' ') + if (state->buffer.data[state->cursor] != ' ') return PSYC_PARSE_LIST_ERROR_LEN; state->cursor++; - elem->ptr = state->buffer.ptr + state->cursor; + elem->data = state->buffer.data + state->cursor; elem->length = 0; state->elemParsed = 0; } @@ -513,7 +513,7 @@ PsycParseListRC psyc_parse_list (PsycParseListState *state, PsycString *elem) if (state->cursor >= state->buffer.length) return PSYC_PARSE_LIST_END; - if (state->buffer.ptr[state->cursor] != '|') + if (state->buffer.data[state->cursor] != '|') return PSYC_PARSE_LIST_ERROR_DELIM; state->cursor++; diff --git a/src/render.c b/src/render.c index e310419..68f2fd9 100644 --- a/src/render.c +++ b/src/render.c @@ -22,7 +22,7 @@ PsycRenderListRC psyc_render_list (PsycList *list, char *buffer, size_t buflen) buffer[cur++] = '|'; cur += itoa(elem->length, buffer + cur, 10); buffer[cur++] = ' '; - memcpy(buffer + cur, elem->ptr, elem->length); + memcpy(buffer + cur, elem->data, elem->length); cur += elem->length; } } @@ -32,7 +32,7 @@ PsycRenderListRC psyc_render_list (PsycList *list, char *buffer, size_t buflen) { elem = &list->elems[i]; buffer[cur++] = '|'; - memcpy(buffer + cur, elem->ptr, elem->length); + memcpy(buffer + cur, elem->data, elem->length); cur += elem->length; } } @@ -48,7 +48,7 @@ size_t psyc_render_modifier (PsycModifier *mod, char *buffer) size_t cur = 0; buffer[cur++] = mod->oper; - memcpy(buffer + cur, mod->name.ptr, mod->name.length); + memcpy(buffer + cur, mod->name.data, mod->name.length); cur += mod->name.length; if (cur <= 1) return cur; // error, name can't be empty @@ -60,7 +60,7 @@ size_t psyc_render_modifier (PsycModifier *mod, char *buffer) } buffer[cur++] = '\t'; - memcpy(buffer + cur, mod->value.ptr, mod->value.length); + memcpy(buffer + cur, mod->value.data, mod->value.length); cur += mod->value.length; buffer[cur++] = '\n'; @@ -96,7 +96,7 @@ PsycRenderRC psyc_render (PsycPacket *packet, char *buffer, size_t buflen) if (packet->content.length) // render raw content if present { - memcpy(buffer + cur, packet->content.ptr, packet->content.length); + memcpy(buffer + cur, packet->content.data, packet->content.length); cur += packet->content.length; } else @@ -107,13 +107,13 @@ PsycRenderRC psyc_render (PsycPacket *packet, char *buffer, size_t buflen) if (packet->method.length) // add method\n { - memcpy(buffer + cur, packet->method.ptr, packet->method.length); + memcpy(buffer + cur, packet->method.data, packet->method.length); cur += packet->method.length; buffer[cur++] = '\n'; if (packet->data.length) // add data\n { - memcpy(buffer + cur, packet->data.ptr, packet->data.length); + memcpy(buffer + cur, packet->data.data, packet->data.length); cur += packet->data.length; buffer[cur++] = '\n'; } diff --git a/src/text.c b/src/text.c index 943daff..1c48010 100644 --- a/src/text.c +++ b/src/text.c @@ -3,8 +3,8 @@ PsycTextRC psyc_text (PsycTextState *state, PsycTextCB getValue, void* extra) { - const char *start = state->tmpl.ptr, *end; // start & end of variable name - const char *prev = state->tmpl.ptr + state->cursor; + const char *start = state->tmpl.data, *end; // start & end of variable name + const char *prev = state->tmpl.data + state->cursor; PsycString value; int ret; size_t len; @@ -12,20 +12,20 @@ PsycTextRC psyc_text (PsycTextState *state, PsycTextCB getValue, void* extra) while (state->cursor < state->tmpl.length) { - start = memmem(state->tmpl.ptr + state->cursor, + start = memmem(state->tmpl.data + state->cursor, state->tmpl.length - state->cursor, - state->open.ptr, state->open.length); + state->open.data, state->open.length); if (!start) break; - state->cursor = (start - state->tmpl.ptr) + state->open.length; + state->cursor = (start - state->tmpl.data) + state->open.length; if (state->cursor >= state->tmpl.length) break; // [ at the end - end = memmem(state->tmpl.ptr + state->cursor, + end = memmem(state->tmpl.data + state->cursor, state->tmpl.length - state->cursor, - state->close.ptr, state->close.length); - state->cursor = (end - state->tmpl.ptr) + state->close.length; + state->close.data, state->close.length); + state->cursor = (end - state->tmpl.data) + state->close.length; if (!end) break; // ] not found @@ -45,25 +45,25 @@ PsycTextRC psyc_text (PsycTextState *state, PsycTextCB getValue, void* extra) len = start - prev; if (state->written + len > state->buffer.length) { - state->cursor = prev - state->tmpl.ptr; + state->cursor = prev - state->tmpl.data; return PSYC_TEXT_INCOMPLETE; } - memcpy((void *)(state->buffer.ptr + state->written), prev, len); + memcpy((void *)(state->buffer.data + state->written), prev, len); state->written += len; // now substitute the value if there's enough buffer space if (state->written + value.length > state->buffer.length) { - state->cursor = start - state->tmpl.ptr; + state->cursor = start - state->tmpl.data; return PSYC_TEXT_INCOMPLETE; } - memcpy((void *)(state->buffer.ptr + state->written), value.ptr, value.length); + memcpy((void *)(state->buffer.data + state->written), value.data, value.length); state->written += value.length; // mark the start of the next chunk of text in the template - prev = state->tmpl.ptr + state->cursor; + prev = state->tmpl.data + state->cursor; no_subst = 0; } @@ -71,11 +71,11 @@ PsycTextRC psyc_text (PsycTextState *state, PsycTextCB getValue, void* extra) return PSYC_TEXT_NO_SUBST; // copy the rest of the template after the last var - len = state->tmpl.length - (prev - state->tmpl.ptr); + len = state->tmpl.length - (prev - state->tmpl.data); if (state->written + len > state->buffer.length) return PSYC_TEXT_INCOMPLETE; - memcpy((void *)(state->buffer.ptr + state->written), prev, len); + memcpy((void *)(state->buffer.data + state->written), prev, len); state->written += len; return PSYC_TEXT_COMPLETE; diff --git a/src/uniform.c b/src/uniform.c index 6dab7b7..26b83bf 100644 --- a/src/uniform.c +++ b/src/uniform.c @@ -10,13 +10,13 @@ int psyc_uniform_parse (PsycUniform *uni, char *str, size_t length) size_t pos = 0, part = PSYC_UNIFORM_SCHEME; uni->valid = 0; - uni->full.ptr = str; + uni->full.data = str; uni->full.length = length; while (pos < length) { c = str[pos]; if (c == ':') { - uni->scheme.ptr = str; + uni->scheme.data = str; uni->scheme.length = pos++; break; } else if (!psyc_is_host_char(c)) @@ -26,14 +26,14 @@ int psyc_uniform_parse (PsycUniform *uni, char *str, size_t length) p = &uni->scheme; if (p->length == 4 && - tolower(p->ptr[0]) == 'p' && - tolower(p->ptr[1]) == 's' && - tolower(p->ptr[2]) == 'y' && - tolower(p->ptr[3]) == 'c') { + tolower(p->data[0]) == 'p' && + tolower(p->data[1]) == 's' && + tolower(p->data[2]) == 'y' && + tolower(p->data[3]) == 'c') { uni->type = PSYC_SCHEME_PSYC; part = PSYC_UNIFORM_SLASHES; - uni->slashes.ptr = str + pos; + uni->slashes.data = str + pos; uni->slashes.length = 0; while (pos < length) { @@ -46,7 +46,7 @@ int psyc_uniform_parse (PsycUniform *uni, char *str, size_t length) if (uni->slashes.length == 2) { part = PSYC_UNIFORM_HOST; - uni->host.ptr = str + pos + 1; + uni->host.data = str + pos + 1; uni->host.length = 0; } break; @@ -69,7 +69,7 @@ int psyc_uniform_parse (PsycUniform *uni, char *str, size_t length) } else return PSYC_PARSE_UNIFORM_INVALID_HOST; - p->ptr = str + pos + 1; + p->data = str + pos + 1; p->length = 0; break; @@ -84,13 +84,13 @@ int psyc_uniform_parse (PsycUniform *uni, char *str, size_t length) if (c == '/') { part = PSYC_UNIFORM_RESOURCE; - uni->resource.ptr = str + pos + 1; + uni->resource.data = str + pos + 1; uni->resource.length = 0; break; } else { part = PSYC_UNIFORM_TRANSPORT; - uni->transport.ptr = str + pos; + uni->transport.data = str + pos; uni->transport.length = 0; } // fall thru @@ -109,7 +109,7 @@ int psyc_uniform_parse (PsycUniform *uni, char *str, size_t length) break; case '/': part = PSYC_UNIFORM_RESOURCE; - uni->resource.ptr = str + pos + 1; + uni->resource.data = str + pos + 1; uni->resource.length = 0; break; default: @@ -123,7 +123,7 @@ int psyc_uniform_parse (PsycUniform *uni, char *str, size_t length) break; } else if (c == '#') { part = PSYC_UNIFORM_CHANNEL; - uni->channel.ptr = str + pos + 1; + uni->channel.data = str + pos + 1; uni->channel.length = 0; break; } else return PSYC_PARSE_UNIFORM_INVALID_RESOURCE; @@ -140,20 +140,20 @@ int psyc_uniform_parse (PsycUniform *uni, char *str, size_t length) if (uni->host.length == 0) return PSYC_PARSE_UNIFORM_INVALID_HOST; - uni->host_port.ptr = uni->host.ptr; + uni->host_port.data = uni->host.data; uni->host_port.length = uni->host.length + uni->port.length + uni->transport.length; if (uni->port.length > 0 || uni->transport.length > 0) uni->host_port.length++; - uni->root.ptr = str; + uni->root.data = str; uni->root.length = uni->scheme.length + 1 + uni->slashes.length + uni->host_port.length; - uni->body.ptr = uni->host.ptr; + uni->body.data = uni->host.data; uni->body.length = length - uni->scheme.length - 1 - uni->slashes.length; if (uni->resource.length) { - uni->nick.ptr = uni->resource.ptr + 1; + uni->nick.data = uni->resource.data + 1; uni->nick.length = uni->resource.length; } diff --git a/src/variable.c b/src/variable.c index a55b37c..72cc839 100644 --- a/src/variable.c +++ b/src/variable.c @@ -27,7 +27,7 @@ const PsycString psyc_routing_vars[] = }; // Variable types in alphabetical order. -const PsycMatchVar psyc_var_types[] = +const PsycDictInt psyc_var_types[] = { {PSYC_C2STR("_amount"), PSYC_TYPE_AMOUNT}, {PSYC_C2STR("_color"), PSYC_TYPE_COLOR}, @@ -72,9 +72,9 @@ PsycBool psyc_var_is_routing (const char *name, size_t len) { if (matching[i] < 0) break; // reached the end of possible matches - if (psyc_routing_vars[matching[i]].ptr[cursor] == name[cursor]) + if (psyc_routing_vars[matching[i]].data[cursor] == name[cursor]) matching[m++] = matching[i]; // found a match, update matching indexes - else if (psyc_routing_vars[matching[i]].ptr[cursor] > name[cursor]) + else if (psyc_routing_vars[matching[i]].data[cursor] > name[cursor]) break; // passed the possible matches in alphabetical order in the array } @@ -94,6 +94,6 @@ inline PsycType psyc_var_type (const char *name, size_t len) { int8_t m[psyc_var_types_num]; - return psyc_in_array(psyc_var_types, psyc_var_types_num, - name, len, PSYC_YES, (int8_t*)&m); + return (PsycType) psyc_dict_lookup((PsycDict*)psyc_var_types, psyc_var_types_num, + name, len, PSYC_YES, (int8_t*)&m); } diff --git a/test/test_list.c b/test/test_list.c index dd0be16..e4ebb39 100644 --- a/test/test_list.c +++ b/test/test_list.c @@ -48,9 +48,9 @@ int main (int argc, char **argv) { case PSYC_PARSE_LIST_END: ret = 0; case PSYC_PARSE_LIST_ELEM: - if (verbose) printf("|%d: %.*s... (%ld)\n", i, 10, elem.ptr, elem.length); + if (verbose) printf("|%d: %.*s... (%ld)\n", i, 10, elem.data, elem.length); //elems[i] = malloc(elem.length); - //memcpy(&elems[i++], elem.ptr, elem.length); + //memcpy(&elems[i++], elem.data, elem.length); break; default: printf("# Error while parsing list: %i\n", ret); @@ -76,10 +76,10 @@ int main (int argc, char **argv) { case PSYC_PARSE_LIST_END: ret = 0; case PSYC_PARSE_LIST_ELEM: - //if (verbose) printf("|%.*s\n", (int)elem.length, elem.ptr); - if (verbose) printf("|%d: %.*s... (%ld)\n", i, 10, elem.ptr, elem.length); + //if (verbose) printf("|%.*s\n", (int)elem.length, elem.data); + if (verbose) printf("|%d: %.*s... (%ld)\n", i, 10, elem.data, elem.length); elems[i] = malloc(elem.length); - memcpy(elems[i++], elem.ptr, elem.length); + memcpy(elems[i++], elem.data, elem.length); break; default: printf("# Error while parsing list: %i\n", ret); @@ -111,7 +111,7 @@ int main (int argc, char **argv) { elems2 = malloc((i+1) * sizeof(char*)); elems2[i] = malloc(elem.length); - memcpy(elems2[i++], elem.ptr, elem.length); + memcpy(elems2[i++], elem.data, elem.length); break; default: printf("# Error while parsing list: %i\n", ret); @@ -145,7 +145,7 @@ int main (int argc, char **argv) { */ elems2 = malloc(sizeof(char*)); elems2[i] = malloc(elem.length); - memcpy(elems2[i], elem.ptr, elem.length); + memcpy(elems2[i], elem.data, elem.length); break; default: printf("# Error while parsing list: %i\n", ret); @@ -191,7 +191,7 @@ int main (int argc, char **argv) { ret = 0; case PSYC_PARSE_LIST_ELEM: elems2[i] = malloc(elem.length); - memcpy(elems2[i++], elem.ptr, elem.length); + memcpy(elems2[i++], elem.data, elem.length); break; default: printf("# Error while parsing list: %i\n", ret); diff --git a/test/test_parser.c b/test/test_parser.c index 43d5ed9..4d2c4e4 100644 --- a/test/test_parser.c +++ b/test/test_parser.c @@ -53,8 +53,8 @@ int main (int argc, char **argv) // printf("the string is '%.*s'\n", name); if (verbose) printf("%.*s = %.*s\n", - (int)name.length, name.ptr, - (int)value.length, value.ptr); + (int)name.length, name.data, + (int)value.length, value.data); if (psyc_var_is_list(PSYC_S2ARG(name))) { @@ -71,7 +71,7 @@ int main (int argc, char **argv) case PSYC_PARSE_LIST_END: case PSYC_PARSE_LIST_ELEM: if (verbose) - printf("|%.*s\n", (int)elem.length, elem.ptr); + printf("|%.*s\n", (int)elem.length, elem.data); break; default: printf("Error while parsing list: %i\n", ret); diff --git a/test/test_psyc.c b/test/test_psyc.c index 43bbbd6..d18bc7a 100644 --- a/test/test_psyc.c +++ b/test/test_psyc.c @@ -82,7 +82,7 @@ int test_input (int i, char *recvbuf, size_t nbytes) { do { if (verbose >= 3) - printf("\n# buffer = [%.*s]\n# part = %d\n", (int)parser->buffer.length, parser->buffer.ptr, parser->part); + printf("\n# buffer = [%.*s]\n# part = %d\n", (int)parser->buffer.length, parser->buffer.data, parser->part); // Parse the next part of the packet (a routing/entity modifier or the body) ret = exit_code = psyc_parse(parser, &oper, &name, &value); if (verbose >= 2) @@ -222,15 +222,15 @@ int test_input (int i, char *recvbuf, size_t nbytes) { } if (name.length) { - pname->ptr = malloc(name.length); + pname->data = malloc(name.length); pname->length = name.length; - assert(pname->ptr != NULL); - memcpy((void*)pname->ptr, name.ptr, name.length); + assert(pname->data != NULL); + memcpy((void*)pname->data, name.data, name.length); name.length = 0; if (verbose >= 2) - printf("%.*s = ", (int)pname->length, pname->ptr); + printf("%.*s = ", (int)pname->length, pname->data); } if (value.length) { @@ -239,15 +239,15 @@ int test_input (int i, char *recvbuf, size_t nbytes) { len = psyc_parse_value_length(parser); else len = value.length; - pvalue->ptr = malloc(len); + pvalue->data = malloc(len); } - assert(pvalue->ptr != NULL); - memcpy((void*)pvalue->ptr + pvalue->length, value.ptr, value.length); + assert(pvalue->data != NULL); + memcpy((void*)pvalue->data + pvalue->length, value.data, value.length); pvalue->length += value.length; value.length = 0; if (verbose >= 2) { - printf("[%.*s]", (int)pvalue->length, pvalue->ptr); + printf("[%.*s]", (int)pvalue->length, pvalue->data); if (parser->valueLength > pvalue->length) printf("..."); printf("\n"); @@ -284,7 +284,7 @@ int test_input (int i, char *recvbuf, size_t nbytes) { retl = 0; case PSYC_PARSE_LIST_ELEM: if (verbose >= 2) { - printf("|%.*s\n", (int)elem.length, elem.ptr); + printf("|%.*s\n", (int)elem.length, elem.data); if (ret == PSYC_PARSE_LIST_END) printf("## LIST END"); } @@ -311,9 +311,9 @@ static inline void resetString (PsycString *s, uint8_t freeptr) { if (freeptr && s->length) - free((void*)s->ptr); + free((void*)s->data); - s->ptr = NULL; + s->data = NULL; s->length = 0; } diff --git a/test/test_text.c b/test/test_text.c index cd1552d..d776e3b 100644 --- a/test/test_text.c +++ b/test/test_text.c @@ -11,7 +11,7 @@ PsycTextValueRC getValueFooBar (const char *name, size_t len, PsycString *value, { if (verbose) printf("> getValue: %.*s\n", (int)len, name); - value->ptr = "Foo Bar"; + value->data = "Foo Bar"; value->length = 7; return PSYC_TEXT_VALUE_FOUND; } @@ -20,7 +20,7 @@ PsycTextValueRC getValueEmpty (const char *name, size_t len, PsycString *value, { if (verbose) printf("> getValue: %.*s\n", (int)len, name); - value->ptr = ""; + value->data = ""; value->length = 0; return PSYC_TEXT_VALUE_FOUND; } @@ -54,7 +54,7 @@ int testText (char *template, size_t tmplen, char *buffer, size_t buflen, PsycSt if (verbose) printf("%.*s\n", (int)length, buffer); result->length = length; - result->ptr = buffer; + result->data = buffer; return ret; case PSYC_TEXT_NO_SUBST: if (verbose) @@ -78,11 +78,11 @@ int main(int argc, char **argv) int i; testText(str, len, buffer, BUFSIZE, &result, &getValueFooBar); - if (memcmp(result.ptr, PSYC_C2ARG("Hello Foo Bar & Foo Bar!"))) + if (memcmp(result.data, PSYC_C2ARG("Hello Foo Bar & Foo Bar!"))) return 1; testText(str, len, buffer, BUFSIZE, &result, &getValueEmpty); - if (memcmp(result.ptr, PSYC_C2ARG("Hello & !"))) + if (memcmp(result.data, PSYC_C2ARG("Hello & !"))) return 2; if (testText(str, len, buffer, BUFSIZE, &result, &getValueNotFound) != PSYC_TEXT_NO_SUBST) @@ -91,7 +91,7 @@ int main(int argc, char **argv) for (i = 1; i < 22; i++) { testText(str, len, buffer, i, &result, &getValueFooBar); - if (memcmp(result.ptr, PSYC_C2ARG("Hello Foo Bar & Foo Bar!"))) + if (memcmp(result.data, PSYC_C2ARG("Hello Foo Bar & Foo Bar!"))) return 10 + i; }