mirror of
git://git.psyced.org/git/psyclpc
synced 2024-08-15 03:20:16 +00:00
pkg-psyc: callback for psyc_parse
This commit is contained in:
parent
79c479b563
commit
1d35e854e3
3 changed files with 58 additions and 50 deletions
|
@ -604,7 +604,7 @@ int send_erq(int, int*|string, null|closure default: F_CONST0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_PSYC
|
#ifdef USE_PSYC
|
||||||
mixed* psyc_parse(int* | string);
|
void psyc_parse(int* | string);
|
||||||
string psyc_render(mixed*);
|
string psyc_render(mixed*);
|
||||||
#endif /* USE_PSYC */
|
#endif /* USE_PSYC */
|
||||||
|
|
||||||
|
|
|
@ -3,37 +3,47 @@
|
||||||
*------------------------------------------------------------------
|
*------------------------------------------------------------------
|
||||||
* test LPC code:
|
* test LPC code:
|
||||||
*
|
*
|
||||||
// doesn't work with (int *) yet
|
|
||||||
string s = ":_context\ttest\n\n:_topic\ttesting\n_notice_test_libpsyc\nJust [_topic] libpsyc.\n|\n";
|
string s, s2;
|
||||||
mixed *f = psyc_parse(s);
|
|
||||||
mixed fr = psyc_render(f);
|
create() {
|
||||||
mixed r = ({ ([ "_context": "test" ]), ([ "_topic": "testing" ]),
|
mixed p, r;
|
||||||
|
s = ":_context\ttest\n\n:_topic\ttesting\n_notice_test_libpsyc\nJust [_topic] libpsyc.\n|\n";
|
||||||
|
psyc_parse(s+s+s);
|
||||||
|
|
||||||
|
psyc_parse(":_context\ttest\n\n:_topic\ttest");
|
||||||
|
psyc_parse("ing\n_notice_test_libpsyc\nJust [_topic] libpsyc.\n|\n");
|
||||||
|
|
||||||
|
p = ({ ([ "_context": "test" ]), ([ "_topic": "testing" ]),
|
||||||
"_notice_test_libpsyc", "Just [_topic] libpsyc." });
|
"_notice_test_libpsyc", "Just [_topic] libpsyc." });
|
||||||
mixed rr = psyc_render(r);
|
r = psyc_render(p);
|
||||||
|
|
||||||
debug_message(sprintf("libpsyc returned %O,\n%O\nand\n%O\n(%s)\n", f, fr, rr,
|
debug_message(sprintf("rendering test:\n%s\n", r));
|
||||||
fr == s && rr == s ? "SUCCESS": "FAIL!"));
|
if (r != s) raise_error("FAIL\n");
|
||||||
mixed *p1 = psyc_parse(":_context\ttest\n\n:_topic\ttest");
|
|
||||||
debug_message(sprintf("p1: libpsyc returned %O\n", p1));
|
|
||||||
mixed *p2 = psyc_parse("ing\n_notice_test_libpsyc\nJust [_topic] libpsyc.\n|\n");
|
|
||||||
debug_message(sprintf("p2: libpsyc returned %O\n", p2));
|
|
||||||
|
|
||||||
mixed pr = psyc_render(p2);
|
s = ":_context\ttest\n\n:_list_foo\t|foo|bar|baz\n:_list_bar\t\n_notice_test_libpsyc\nJust [_topic] libpsyc.\n|\n";
|
||||||
debug_message(sprintf("libpsyc returned %O (%s)\n", p2,
|
s2 = ":_context\ttest\n\n:_list_bar\t\n:_list_foo\t|foo|bar|baz\n_notice_test_libpsyc\nJust [_topic] libpsyc.\n|\n";
|
||||||
pr == s ? "SUCCESS": "FAIL!"));
|
psyc_parse(s);
|
||||||
|
|
||||||
string ls = ":_context\ttest\n\n:_list_foo\t|foo|bar|baz\n:_list_bar\t\n_notice_test_libpsyc\nJust [_topic] libpsyc.\n|\n";
|
p = ({ ([ "_context": "test" ]),
|
||||||
string ls2 = ":_context\ttest\n\n:_list_bar\t\n:_list_foo\t|foo|bar|baz\n_notice_test_libpsyc\nJust [_topic] libpsyc.\n|\n";
|
|
||||||
mixed *lf = psyc_parse(ls);
|
|
||||||
mixed *lfr = psyc_render(lf);
|
|
||||||
mixed lr = ({ ([ "_context": "test" ]),
|
|
||||||
([ "_list_foo": ({ "foo", "bar", "baz" }), "_list_bar": ({}) ]),
|
([ "_list_foo": ({ "foo", "bar", "baz" }), "_list_bar": ({}) ]),
|
||||||
"_notice_test_libpsyc",
|
"_notice_test_libpsyc", "Just [_topic] libpsyc." });
|
||||||
"Just [_topic] libpsyc." });
|
r = psyc_render(p);
|
||||||
mixed lrr = psyc_render(lr);
|
|
||||||
|
debug_message(sprintf("list rendering test:\n%s\n", r));
|
||||||
|
if (r != s) raise_error("FAIL\n");
|
||||||
|
|
||||||
|
debug_message(sprintf(">> SUCCESS\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
psyc_dispatch(mixed p) {
|
||||||
|
debug_message(sprintf(">> psyc_parse returned:\n%O\n", p));
|
||||||
|
|
||||||
|
mixed r = psyc_render(p);
|
||||||
|
debug_message(sprintf(">> psyc_render returned:\n%s", r));
|
||||||
|
if (r != s && r != s2) raise_error("FAIL\n");
|
||||||
|
}
|
||||||
|
|
||||||
debug_message(sprintf("libpsyc returned %O,\n%O\nand\n%O\n(%s)\n", lf, lfr, lrr,
|
|
||||||
(lfr == ls || lfr == ls2) && (lrr == ls || lrr == ls2) ? "SUCCESS": "FAIL!"));
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "array.h"
|
#include "array.h"
|
||||||
|
@ -188,7 +198,7 @@ f_psyc_render(svalue_t *sp) {
|
||||||
} /* f_psyc_render */
|
} /* f_psyc_render */
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
// mixed psyc_parse(int* | string);
|
// void psyc_parse(int* | string);
|
||||||
|
|
||||||
svalue_t *
|
svalue_t *
|
||||||
f_psyc_parse (svalue_t *sp) {
|
f_psyc_parse (svalue_t *sp) {
|
||||||
|
@ -201,6 +211,7 @@ f_psyc_parse (svalue_t *sp) {
|
||||||
psycParseListState listState;
|
psycParseListState listState;
|
||||||
int ret, retl;
|
int ret, retl;
|
||||||
size_t size, i;
|
size_t size, i;
|
||||||
|
string_t *callback = mstring_new_string("psyc_dispatch");
|
||||||
|
|
||||||
assert_shadow_sent(current_object);
|
assert_shadow_sent(current_object);
|
||||||
psyc_state_t *state = O_GET_PSYC_STATE(current_object);
|
psyc_state_t *state = O_GET_PSYC_STATE(current_object);
|
||||||
|
@ -214,6 +225,7 @@ f_psyc_parse (svalue_t *sp) {
|
||||||
if (!state->parser) errorf("Out of memory for psyc parse state struct.\n");
|
if (!state->parser) errorf("Out of memory for psyc parse state struct.\n");
|
||||||
psyc_initParseState(state->parser);
|
psyc_initParseState(state->parser);
|
||||||
}
|
}
|
||||||
|
v = state->packet;
|
||||||
|
|
||||||
if (sp->type == T_POINTER) {
|
if (sp->type == T_POINTER) {
|
||||||
errorf("\npsyc_parse got %ld int* bytes... not supported yet\n", VEC_SIZE(sp->u.vec));
|
errorf("\npsyc_parse got %ld int* bytes... not supported yet\n", VEC_SIZE(sp->u.vec));
|
||||||
|
@ -238,7 +250,10 @@ f_psyc_parse (svalue_t *sp) {
|
||||||
errorf("\npsyc_parse got type %d, not supported\n", sp->type);
|
errorf("\npsyc_parse got type %d, not supported\n", sp->type);
|
||||||
}
|
}
|
||||||
|
|
||||||
free_svalue(sp);
|
do {
|
||||||
|
ret = psyc_parse(state->parser, &oper, &name, &value);
|
||||||
|
|
||||||
|
printf("#%2d %c%.*s = %.*s\n", ret, oper ? oper : ' ', (int)name.length, name.ptr, (int)value.length, value.ptr);
|
||||||
|
|
||||||
if (!state->packet) {
|
if (!state->packet) {
|
||||||
state->packet = allocate_array(4);
|
state->packet = allocate_array(4);
|
||||||
|
@ -251,13 +266,7 @@ f_psyc_parse (svalue_t *sp) {
|
||||||
map = allocate_mapping(0, 1); // empty mapping
|
map = allocate_mapping(0, 1); // empty mapping
|
||||||
if (!map) errorf("Out of memory for psyc_parse entity header.\n");
|
if (!map) errorf("Out of memory for psyc_parse entity header.\n");
|
||||||
put_mapping(&v->item[PACKET_ENTITY], map);
|
put_mapping(&v->item[PACKET_ENTITY], map);
|
||||||
} else
|
}
|
||||||
v = state->packet;
|
|
||||||
|
|
||||||
do {
|
|
||||||
ret = psyc_parse(state->parser, &oper, &name, &value);
|
|
||||||
|
|
||||||
printf("#%2d %c%.*s = %.*s\n", ret, oper ? oper : ' ', (int)name.length, name.ptr, (int)value.length, value.ptr);
|
|
||||||
|
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case PSYC_PARSE_ENTITY_START: case PSYC_PARSE_BODY_START:
|
case PSYC_PARSE_ENTITY_START: case PSYC_PARSE_BODY_START:
|
||||||
|
@ -360,9 +369,9 @@ f_psyc_parse (svalue_t *sp) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PSYC_PARSE_COMPLETE:
|
case PSYC_PARSE_COMPLETE:
|
||||||
|
put_array(inter_sp, v);
|
||||||
|
sapply(callback, current_object, 1);
|
||||||
state->packet = NULL;
|
state->packet = NULL;
|
||||||
put_array(sp, v);
|
|
||||||
ret = 0;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PSYC_PARSE_INSUFFICIENT:
|
case PSYC_PARSE_INSUFFICIENT:
|
||||||
|
@ -376,7 +385,6 @@ f_psyc_parse (svalue_t *sp) {
|
||||||
} else
|
} else
|
||||||
state->remaining = NULL;
|
state->remaining = NULL;
|
||||||
|
|
||||||
put_number(sp, 0);
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -435,7 +443,7 @@ f_psyc_parse (svalue_t *sp) {
|
||||||
if (buffer)
|
if (buffer)
|
||||||
pfree(buffer);
|
pfree(buffer);
|
||||||
|
|
||||||
return sp;
|
return --sp;
|
||||||
} /* f_psyc_parse */
|
} /* f_psyc_parse */
|
||||||
|
|
||||||
#endif /* USE_PSYC */
|
#endif /* USE_PSYC */
|
||||||
|
|
|
@ -17,7 +17,7 @@ version_longtype="stable"
|
||||||
# A timestamp, to be used by bumpversion and other scripts.
|
# A timestamp, to be used by bumpversion and other scripts.
|
||||||
# It can be used, for example, to 'touch' this file on every build, thus
|
# 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.
|
# forcing revision control systems to add it on every checkin automatically.
|
||||||
version_stamp="Thu May 19 18:45:43 CEST 2011"
|
version_stamp="Thu May 19 21:24:11 CEST 2011"
|
||||||
|
|
||||||
# Okay, LDMUD is using 3.x.x so to avoid conflicts let's just use 4.x.x
|
# Okay, LDMUD is using 3.x.x so to avoid conflicts let's just use 4.x.x
|
||||||
version_major=4
|
version_major=4
|
||||||
|
|
Loading…
Reference in a new issue