From eaeab8c226ea0a3658353121d1a7d20dd359d5ad Mon Sep 17 00:00:00 2001 From: "tg(x)" <*@tg-x.net> Date: Tue, 31 Jan 2012 19:34:11 +0100 Subject: [PATCH] psyc_is_var_routing() -> psyc_var_routing() --- include/psyc/method.h | 4 ++-- include/psyc/variable.h | 32 +++++++++++++++++++------- pike/psyc.cmod | 2 +- src/variable.c | 50 ++++++++++++++++++++--------------------- test/Makefile | 4 ++-- test/var_is_routing.c | 37 ------------------------------ test/var_routing.c | 23 +++++++++++++++++++ 7 files changed, 76 insertions(+), 76 deletions(-) delete mode 100644 test/var_is_routing.c create mode 100644 test/var_routing.c diff --git a/include/psyc/method.h b/include/psyc/method.h index d2fdcf1..bf445f9 100644 --- a/include/psyc/method.h +++ b/include/psyc/method.h @@ -1,7 +1,7 @@ #ifndef PSYC_METHOD_H #define PSYC_METHOD_H -typedef enum PsycMethodFlag { +typedef enum { PSYC_METHOD_TEMPLATE = 1 << 0, PSYC_METHOD_REPLY = 1 << 1, PSYC_METHOD_VISIBLE = 1 << 2, @@ -9,7 +9,7 @@ typedef enum PsycMethodFlag { PSYC_METHOD_MANUAL = 1 << 4, } PsycMethodFlag; -typedef enum PsycMethod { +typedef enum { PSYC_MC_UNKNOWN, PSYC_MC_DATA, diff --git a/include/psyc/variable.h b/include/psyc/variable.h index 6c8db7c..a17f56d 100644 --- a/include/psyc/variable.h +++ b/include/psyc/variable.h @@ -8,8 +8,7 @@ #include "packet.h" /// Routing variables in alphabetical order. -//extern const PsycString psyc_routing_vars[]; -extern const PsycDictInt psyc_routing_vars[]; +extern const PsycDictInt psyc_rvars[]; // Variable types in alphabetical order. extern const PsycDictInt psyc_var_types[]; @@ -17,18 +16,35 @@ extern const PsycDictInt psyc_var_types[]; /// Method names in alphabetical order. extern const PsycDictInt psyc_methods[]; -extern const size_t psyc_routing_vars_num; +extern const size_t psyc_rvars_num; extern const size_t psyc_var_types_num; extern const size_t psyc_methods_num; +typedef enum { + PSYC_RVAR_UNKNOWN, + + PSYC_RVAR_AMOUNT_FRAGMENTS, + PSYC_RVAR_CONTEXT, + PSYC_RVAR_COUNTER, + PSYC_RVAR_FRAGMENT, + PSYC_RVAR_SOURCE, + PSYC_RVAR_SOURCE_RELAY, + PSYC_RVAR_TAG, + PSYC_RVAR_TAG_RELAY, + PSYC_RVAR_TARGET, + PSYC_RVAR_TARGET_RELAY, + + PSYC_RVARS_NUM, +} PsycRoutingVar; + /** - * Is this a routing variable name? + * Look up routing variable. */ -static inline PsycBool -psyc_var_is_routing (const char *name, size_t len) +static inline PsycRoutingVar +psyc_var_routing (const char *name, size_t len) { - return (PsycBool) psyc_dict_lookup((PsycDict *)psyc_routing_vars, - psyc_routing_vars_num, name, len, PSYC_NO); + return (PsycRoutingVar) psyc_dict_lookup((PsycDict *)psyc_rvars, + psyc_rvars_num, name, len, PSYC_NO); } /** diff --git a/pike/psyc.cmod b/pike/psyc.cmod index 2cb1d44..31d6cf9 100644 --- a/pike/psyc.cmod +++ b/pike/psyc.cmod @@ -99,7 +99,7 @@ PIKEFUN string psyc_text(string template, mapping vars) { *! 0 otherwise */ PIKEFUN int is_routingvar(string name) { - RETURN psyc_var_is_routing((char *) STR0(name), name->len); + RETURN psyc_var_routing((char *) STR0(name), name->len); } /*! @decl string render(mapping rvars, mapping evars, string method, string|void body) diff --git a/src/variable.c b/src/variable.c index fa2f842..23c5e10 100644 --- a/src/variable.c +++ b/src/variable.c @@ -3,31 +3,31 @@ #include - /// Routing variables in alphabetical order. -//const PsycString psyc_routing_vars[] = { -const PsycDictInt psyc_routing_vars[] = { - { PSYC_C2STRI("_amount_fragments"), 1 }, - { PSYC_C2STRI("_context"), 1 }, - //{ PSYC_C2STRI("_count"), 1 }, // older PSYC - { PSYC_C2STRI("_counter"), 1 }, - { PSYC_C2STRI("_fragment"), 1 }, - //{ PSYC_C2STRI("_length"), 1 }, // older PSYC - { PSYC_C2STRI("_source"), 1 }, - //{ PSYC_C2STRI("_source_identification"), 1 }, // older PSYC - { PSYC_C2STRI("_source_identity"), 1 }, - { PSYC_C2STRI("_source_relay"), 1 }, - // until you have a better idea.. is this really in use? - { PSYC_C2STRI("_source_relay_relay"), 1 }, - { PSYC_C2STRI("_tag"), 1 }, - { PSYC_C2STRI("_tag_relay"), 1 }, - //{ PSYC_C2STRI("_tag_reply"), 1 }, // older PSYC - { PSYC_C2STRI("_target"), 1 }, - { PSYC_C2STRI("_target_forward"), 1 }, - { PSYC_C2STRI("_target_relay"), 1 }, - //{ PSYC_C2STRI("_understand_modules"), 1 }, // older PSYC - //{ PSYC_C2STRI("_using_modules"), 1 }, // older PSYC +const PsycDictInt psyc_rvars[] = { + { PSYC_C2STRI("_amount_fragments"), PSYC_RVAR_AMOUNT_FRAGMENTS }, + { PSYC_C2STRI("_context"), PSYC_RVAR_CONTEXT }, + { PSYC_C2STRI("_counter"), PSYC_RVAR_COUNTER }, + { PSYC_C2STRI("_fragment"), PSYC_RVAR_FRAGMENT }, + { PSYC_C2STRI("_source"), PSYC_RVAR_SOURCE }, + { PSYC_C2STRI("_source_relay"), PSYC_RVAR_SOURCE_RELAY }, + { PSYC_C2STRI("_tag"), PSYC_RVAR_TAG }, + { PSYC_C2STRI("_tag_relay"), PSYC_RVAR_TAG_RELAY }, + { PSYC_C2STRI("_target"), PSYC_RVAR_TARGET }, + { PSYC_C2STRI("_target_relay"), PSYC_RVAR_TARGET_RELAY }, + +/* old psyc: + { PSYC_C2STRI("_length"), PSYC_RVAR_LENGTH }, + { PSYC_C2STRI("_source_identification"), PSYC_RVAR_SOURCE_IDENTIFICATION }, + { PSYC_C2STRI("_source_identity"), PSYC_RVAR_SOURCE_IDENTITY }, + { PSYC_C2STRI("_source_relay_relay"), PSYC_RVAR_RELAY_RELAY }, + { PSYC_C2STRI("_tag_reply"), PSYC_RVAR_TAG_REPLY }, + { PSYC_C2STRI("_target_forward"), PSYC_RVAR_TARGET_FORWARD }, + { PSYC_C2STRI("_understand_modules"), PSYC_RVAR_UNDERSTAND_MODULES }, + { PSYC_C2STRI("_using_modules"), PSYC_RVAR_USING_MODULES }, +*/ }; +const size_t psyc_rvars_num = PSYC_NUM_ELEM(psyc_rvars); // Variable types in alphabetical order. const PsycDictInt psyc_var_types[] = { @@ -46,6 +46,7 @@ const PsycDictInt psyc_var_types[] = { { PSYC_C2STRI("_time"), PSYC_TYPE_TIME }, { PSYC_C2STRI("_uniform"), PSYC_TYPE_UNIFORM }, }; +const size_t psyc_var_types_num = PSYC_NUM_ELEM(psyc_var_types); /// Method names in alphabetical order. const PsycDictInt psyc_methods[] = { @@ -79,9 +80,6 @@ const PsycDictInt psyc_methods[] = { { PSYC_C2STRI("_status"), PSYC_MC_STATUS }, { PSYC_C2STRI("_warning"), PSYC_MC_WARNING }, }; - -const size_t psyc_routing_vars_num = PSYC_NUM_ELEM(psyc_routing_vars); -const size_t psyc_var_types_num = PSYC_NUM_ELEM(psyc_var_types); const size_t psyc_methods_num = PSYC_NUM_ELEM(psyc_methods); /** diff --git a/test/Makefile b/test/Makefile index 75f15c0..662f2a2 100644 --- a/test/Makefile +++ b/test/Makefile @@ -3,7 +3,7 @@ DEBUG = 2 CFLAGS = -I../include -I../src -Wall -std=c99 ${OPT} LDFLAGS = -L../lib LOADLIBES = -lpsyc -lm -TARGETS = test_psyc test_psyc_speed test_parser test_match test_render test_text var_is_routing var_type uniform_parse test_list test_table test_packet_id method +TARGETS = test_psyc test_psyc_speed test_parser test_match test_render test_text var_routing var_type uniform_parse test_list test_table test_packet_id method O = test.o WRAPPER = DIET = diet @@ -45,7 +45,7 @@ test: ${TARGETS} ./test_render ./test_match ./test_text - ./var_is_routing + ./var_routing ./var_type ./uniform_parse ./test_list diff --git a/test/var_is_routing.c b/test/var_is_routing.c deleted file mode 100644 index caba355..0000000 --- a/test/var_is_routing.c +++ /dev/null @@ -1,37 +0,0 @@ -#include -#include -#include -#include -#include - -int main() { -#if 0 - const char* vars[] = { - "_source", - "_source_relay", - "_source_foo", - "_sourcherry", - "_foo", - "bar", - "_", - }; - - int i; - for (i = 0; i < sizeof(vars) / sizeof(*vars); i++) { - printf(">> %s: %d %d\n", vars[i], sizeof(vars[i]), sizeof(*vars[i])); - printf("%s: %d\n", vars[i], psyc_var_is_routing(vars[i], strlen(vars[i]))); - } -#else - unless (psyc_var_is_routing(PSYC_C2ARG("_source"))) return 1; - unless (psyc_var_is_routing(PSYC_C2ARG("_source_relay"))) return 2; - if (psyc_var_is_routing(PSYC_C2ARG("_source_foo"))) return 3; - if (psyc_var_is_routing(PSYC_C2ARG("_sourcherry"))) return 4; - if (psyc_var_is_routing(PSYC_C2ARG("_sour"))) return 5; - if (psyc_var_is_routing(PSYC_C2ARG("_foo"))) return 6; - if (psyc_var_is_routing(PSYC_C2ARG("bar"))) return 7; - if (psyc_var_is_routing(PSYC_C2ARG("_"))) return 8; - - puts("psyc_var_is_routing passed all tests."); -#endif - return 0; // passed all tests -} diff --git a/test/var_routing.c b/test/var_routing.c new file mode 100644 index 0000000..c6b131d --- /dev/null +++ b/test/var_routing.c @@ -0,0 +1,23 @@ +#include +#include +#include +#include +#include + +int main() { + int i; + + for (i = 0; i < psyc_rvars_num; i++) + if (psyc_var_routing(PSYC_S2ARG(psyc_rvars[i].key)) != psyc_rvars[i].value) + return i + 1; + + if (psyc_var_routing(PSYC_C2ARG("_source_foo"))) return 3; + if (psyc_var_routing(PSYC_C2ARG("_sourcherry"))) return 4; + if (psyc_var_routing(PSYC_C2ARG("_sour"))) return 5; + if (psyc_var_routing(PSYC_C2ARG("_foo"))) return 6; + if (psyc_var_routing(PSYC_C2ARG("bar"))) return 7; + if (psyc_var_routing(PSYC_C2ARG("_"))) return 8; + + puts("psyc_var_routing passed all tests."); + return 0; +}