diff --git a/src/autoconf/configure.in b/src/autoconf/configure.in index f340a50..3f075de 100644 --- a/src/autoconf/configure.in +++ b/src/autoconf/configure.in @@ -1226,7 +1226,7 @@ if test $lp_cv_has_psyc_lib = yes; then #include int main(void) { - (void) PSYC_version(); + (void) psyc_version(); return 0; } ], diff --git a/src/pkg-psyc.c b/src/pkg-psyc.c index e2797f7..a4bc06f 100644 --- a/src/pkg-psyc.c +++ b/src/pkg-psyc.c @@ -18,8 +18,10 @@ #include "array.h" #include "interpret.h" +#include "mapping.h" #include "mstrings.h" #include "simulate.h" +#include "xalloc.h" #include #include @@ -59,14 +61,18 @@ f_psyc_render(svalue_t *sp) { svalue_t * f_psyc_parse (svalue_t *sp) { + string_t *str = NULL; + vector_t *v; + mapping_t *map; + svalue_t *sv; mp_int i; - PSYC_String name, value, elem; - PSYC_ParseState state; - PSYC_ParseListState listState; + psycString name, value, elem; + psycParseState state; + psycParseListState listState; char oper; int ret; - PSYC_initParseState(&state); + psyc_initParseState(&state); i = 0; if (sp->type == T_POINTER) { if ((i = (mp_int)VEC_SIZE(sp->u.vec)) > 32) { @@ -75,33 +81,54 @@ f_psyc_parse (svalue_t *sp) { /* NOTREACHED */ return sp; } - printf("\nparsing %ld bytes... not yet\n", i); + printf("\npsyc_parse got %ld int* bytes... not supported yet\n", i); } else if (sp->type == T_STRING) { - printf("\nparsing '%s'...\n", get_txt(sp->u.str)); - PSYC_nextParseBuffer(&state, PSYC_newString(get_txt(sp->u.str), + printf("\npsyc_parse got a %d bytes long string...\n", mstrsize(sp->u.str)); + psyc_nextParseBuffer(&state, psyc_newString(get_txt(sp->u.str), mstrsize(sp->u.str))); } + v = allocate_array(4); + if (!v) errorf("Out of memory for psyc_parse array.\n"); + map = allocate_mapping( 0, 1 ); // empty mapping + if (!map) errorf("Out of memory for psyc_parse routing header.\n"); + put_mapping(&v->item[0], map); + map = allocate_mapping( 0, 1 ); // empty mapping + if (!map) errorf("Out of memory for psyc_parse entity header.\n"); + put_mapping(&v->item[1], map); + do { - ret = PSYC_parse(&state, &oper, &name, &value); + ret = psyc_parse(&state, &oper, &name, &value); switch (ret) { case PSYC_PARSE_ROUTING: + if (oper != ':') { + puts("_failure_unsupported_state"); + continue; + } + // not sure if the following code is good.. TODO + sv = pxalloc( sizeof( svalue_t ) ); + put_string(sv, new_n_mstring(name.ptr, name.length)); + sv = get_map_lvalue(v->item[0].u.map, sv); + put_string(sv, new_n_mstring(value.ptr, value.length)); + break; case PSYC_PARSE_ENTITY: - write(1, "\t", 1); - write(1, &oper, 1); - case PSYC_PARSE_BODY: - // printf("the string is '%.*s'\n", name); - write(1, name.ptr, name.length); - write(1, " = ", 3); - write(1, value.ptr, value.length); - write(1, "\n", 1); + if (oper != ':') { + puts("_failure_unsupported_state"); + continue; + } + // not sure if the following code is good.. TODO + sv = pxalloc( sizeof( svalue_t ) ); + put_string(sv, new_n_mstring(name.ptr, name.length)); + sv = get_map_lvalue(v->item[1].u.map, sv); + put_string(sv, new_n_mstring(value.ptr, value.length)); + if (memcmp(name.ptr, "_list", 5) == 0) { write(1, ">>> LIST START\n", 15); - PSYC_initParseListState(&listState); - PSYC_nextParseListBuffer(&listState, value); - while ((ret = PSYC_parseList(&listState, &name, &value, &elem))) + psyc_initParseListState(&listState); + psyc_nextParseListBuffer(&listState, value); + while ((ret = psyc_parseList(&listState, &name, &value, &elem))) { switch (ret) { @@ -124,9 +151,20 @@ f_psyc_parse (svalue_t *sp) { } } } + break; + case PSYC_PARSE_BODY: + if (str) errorf("Got two PSYC methods in the same packet!?\n"); + // not sure if new_n_mstring is the right thing here.. TODO + str = new_n_mstring(name.ptr, name.length); + // make_tabled gets the shared string for the method + put_string(&v->item[2], make_tabled(str)); + + // not sure if new_n_mstring is the right thing here.. TODO + str = new_n_mstring(value.ptr, value.length); + put_string(&v->item[3], str); + break; case PSYC_PARSE_COMPLETE: - printf("Done parsing.\n"); ret = 0; break; case PSYC_PARSE_INSUFFICIENT: @@ -141,7 +179,9 @@ f_psyc_parse (svalue_t *sp) { } while (ret); free_svalue(sp); - put_number(sp, 4404); // push a test rc +// push_string(sp, str); +// put_number(sp, 4404); // push a test rc + put_array(sp, v); return sp; } /* f_psyc_parse */ diff --git a/src/version.sh b/src/version.sh index a851c08..e68a739 100644 --- a/src/version.sh +++ b/src/version.sh @@ -17,7 +17,7 @@ version_longtype="stable" # A timestamp, to be used by bumpversion and other scripts. # It can be used, for example, to 'touch' this file on every build, thus # forcing revision control systems to add it on every checkin automatically. -version_stamp="Mon Apr 25 22:51:12 CEST 2011" +version_stamp="Tue Apr 26 02:40:40 CEST 2011" # Okay, LDMUD is using 3.x.x so to avoid conflicts let's just use 4.x.x version_major=4