chiark / gitweb /
saner parsing
authorian <ian>
Tue, 27 May 2008 21:44:14 +0000 (21:44 +0000)
committerian <ian>
Tue, 27 May 2008 21:44:14 +0000 (21:44 +0000)
hostside/gui-plan.c

index 0d7ee81cb3fddb2bafd4d3c19896e492517c22b5..6306bb6e5da5c76225e28beb0f13cd19a04c1bc0 100644 (file)
@@ -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;