From 51fea526ace77e88a1806a2984c34e07131456e5 Mon Sep 17 00:00:00 2001 From: "psyc://psyced.org/~lynX" <@> Date: Fri, 6 May 2011 22:15:37 +0200 Subject: [PATCH] glue to enable optional psyc parsers for each lpc object --- src/Makefile.in | 2 +- src/pkg-psyc.c | 5 ++--- src/pkg-psyc.h | 18 ++++++++++++++---- src/sent.h | 8 ++++++++ src/simulate.c | 14 ++++++++++++++ src/version.sh | 2 +- 6 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/Makefile.in b/src/Makefile.in index 45add09..fe72c77 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -522,7 +522,7 @@ simulate.o : ../mudlib/sys/rtlimits.h ../mudlib/sys/regexp.h \ mapping.h main.h lex.h heartbeat.h gcollect.h filestat.h ed.h comm.h \ closure.h call_out.h backend.h array.h actions.h simulate.h my-alloca.h \ typedefs.h driver.h interpret.h hash.h exec.h ptrtable.h bytecode.h \ - port.h config.h hosts/unix.h hosts/be/be.h machine.h + port.h config.h hosts/unix.h hosts/be/be.h machine.h pkg-psyc.o sprintf.o : xalloc.h swap.h svalue.h structs.h stdstrings.h simul_efun.h \ simulate.h sent.h random.h ptrtable.h object.h mstrings.h mapping.h \ diff --git a/src/pkg-psyc.c b/src/pkg-psyc.c index 8790dd4..c901c74 100644 --- a/src/pkg-psyc.c +++ b/src/pkg-psyc.c @@ -29,7 +29,6 @@ # include # include -# include # include /*-------------------------------------------------------------------------*/ @@ -127,7 +126,7 @@ f_psyc_parse (svalue_t *sp) { } else if (sp->type == T_STRING) { printf("\npsyc_parse got a %d bytes long string...\n", mstrsize(sp->u.str)); - psyc_nextParseBuffer(&state, psyc_newString(get_txt(sp->u.str), + psyc_setParseBuffer(&state, psyc_newString(get_txt(sp->u.str), mstrsize(sp->u.str))); } @@ -176,7 +175,7 @@ f_psyc_parse (svalue_t *sp) { { write(1, ">>> LIST START\n", 15); psyc_initParseListState(&listState); - psyc_nextParseListBuffer(&listState, value); + psyc_setParseListBuffer(&listState, value); while ((ret = psyc_parseList(&listState, &name, &value, &elem))) { switch (ret) diff --git a/src/pkg-psyc.h b/src/pkg-psyc.h index cc40aba..810ebd5 100644 --- a/src/pkg-psyc.h +++ b/src/pkg-psyc.h @@ -1,10 +1,20 @@ +#ifdef USE_PSYC + /* pkg-psyc takes and produces PSYC packets in form * of an array of mapping, mapping, string and string * or int* where necessary. */ -#define PSYC_ROUTING 0 -#define PSYC_ENTITY 1 -#define PSYC_METHOD 2 -#define PSYC_BODY 3 +# define PSYC_ROUTING 0 +# define PSYC_ENTITY 1 +# define PSYC_METHOD 2 +# define PSYC_BODY 3 +# include + +static inline void +psyc_free_parser (psycParseState *ps) { + /* if (ps) xfree((void *) ps); */ +} + +#endif diff --git a/src/sent.h b/src/sent.h index a921929..0db5fcc 100644 --- a/src/sent.h +++ b/src/sent.h @@ -43,6 +43,10 @@ #include "driver.h" #include "typedefs.h" +#ifdef USE_PSYC +# include +#endif + enum sent_type_e { SENT_PLAIN = 0 /* Normal action */ , SENT_SHORT_VERB /* Action with abbreviatable verb */ @@ -127,6 +131,9 @@ struct shadow_s ed_buffer_t *ed_buffer; /* the editor buffer, if needed */ #endif interactive_t *ip; /* the information for interactive objects */ +#ifdef USE_PSYC + psycParseState *psyc_parser; /* in case this objects parses PSYC data */ +#endif }; /* --- Macros --- */ @@ -134,6 +141,7 @@ struct shadow_s #define O_GET_SHADOW(ob) ((shadow_t *)(ob)->sent) #define O_GET_INTERACTIVE(ob) (O_GET_SHADOW(ob)->ip) #define O_GET_EDBUFFER(ob) (O_GET_SHADOW(ob)->ed_buffer) +#define O_GET_PSYC_PARSER(ob) (O_GET_SHADOW(ob)->psyc_parser) /* Expand to an expression suitable to query or set the * indicated attribute. No checks are performed. diff --git a/src/simulate.c b/src/simulate.c index 9da6f2c..0a50d26 100644 --- a/src/simulate.c +++ b/src/simulate.c @@ -58,6 +58,9 @@ #ifdef USE_SQLITE #include "pkg-sqlite.h" #endif +#ifdef USE_PSYC +#include "pkg-psyc.h" +#endif #include "prolang.h" #include "sent.h" #include "simul_efun.h" @@ -2698,6 +2701,11 @@ destruct (object_t *ob) } #endif +#ifdef USE_PSYC + if (shadow_sent->psyc_parser) + psyc_free_parser(shadow_sent->psyc_parser); +#endif + #ifdef USE_SHADOWING /* The chain of shadows is a double linked list. Take care to update * it correctly. @@ -3173,6 +3181,9 @@ new_shadow_sent(void) #endif #ifdef USE_BUILTIN_EDITOR p->ed_buffer = NULL; +#endif +#ifdef USE_PSYC + p->psyc_parser = NULL; #endif p->ip = NULL; return p; @@ -3215,6 +3226,9 @@ check_shadow_sent (object_t *ob) #ifdef USE_BUILTIN_EDITOR && !sh->ed_buffer #endif +#ifdef USE_PSYC + && !sh->psyc_parser +#endif #ifdef USE_SHADOWING && !sh->shadowing && !sh->shadowed_by diff --git a/src/version.sh b/src/version.sh index 5101c3a..ad19ddd 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="Fri May 6 21:14:39 CEST 2011" +version_stamp="Fri May 6 22:13:45 CEST 2011" # Okay, LDMUD is using 3.x.x so to avoid conflicts let's just use 4.x.x version_major=4