From eef27a7566da57ad1a3a491777a46ad0b2a7456b Mon Sep 17 00:00:00 2001 From: ian Date: Tue, 27 May 2008 21:44:14 +0000 Subject: [PATCH] saner parsing --- hostside/gui-plan.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/hostside/gui-plan.c b/hostside/gui-plan.c index 0d7ee81..6306bb6 100644 --- a/hostside/gui-plan.c +++ b/hostside/gui-plan.c @@ -58,6 +58,7 @@ typedef struct { unsigned inverted:1, updated:1; } SegState; +static FILE *debug; static SegState *state; static SegmovfeatState *states_head; static Display *d; @@ -471,6 +472,10 @@ static void si_on(ParseState *ps) { static void si_off(ParseState *ps) { } +static void si_train(ParseState *ps) { + +} + typedef struct MuxEventInfo MuxEventInfo; typedef void MuxEventFn(ParseState *ps); @@ -518,6 +523,7 @@ static const MuxEventInfo muxeventinfos[]= { { "?movpos", "_*_feat", si_movpos }, { "?picio out on", "", si_on }, { "?picio out off", "", si_off }, + { "?train", "_*_has", si_train }, { "=connected", "", si_connected }, { "=permission", "", 0 }, @@ -533,25 +539,25 @@ static const MuxEventInfo muxeventinfos[]= { static void sock_input_line(ParseState *ps) { const MuxEventInfo *mxi; const char *got, *expected; - int l; + int l, c; if (!ps->remain || !ps->remain[0]) return; + ps->thisword= ps->remain; for (mxi=muxeventinfos; mxi->prefix; mxi++) { got= ps->remain; expected= mxi->prefix; - if (*expected=='?') { got++; expected++; } - l= strlen(expected); + l= ps->lthisword= strlen(expected); + if (*expected=='?') { got++; expected++; l--; } if (memcmp(got, expected, l)) continue; if (!got[l] || got[l]==' ') goto found; } return; found: if (!mxi->fn) return; - ps->thisword= ps->remain; - ps->lthisword= l; - ps->remain += l; -fprintf(stderr,"calling <%s> with <%.*s|%s>\n", - mxi->prefix, ps->lthisword,ps->thisword, ps->remain); + ps->remain= got + l; + if ((c= *ps->remain)) { assert(c==' '); ps->remain++; } + if (debug) fprintf(debug,"calling <%s> with <%.*s|%s>\n", + mxi->prefix, ps->lthisword,ps->thisword, ps->remain); mxi->fn(ps); } @@ -585,6 +591,8 @@ int main(int argc, const char *const *argv) { printf("%d\n%d\n", ui_plan_data.xsz, ui_plan_data.ysz); if (ferror(stdout) || fflush(stdout)) diee("print stdout"); exit(0); + } else if (!strcmp(arg,"--debug")) { + debug= stderr; } else if (arg[0]=='@') { char *node, *comma; const char *service; -- 2.30.2