chiark / gitweb /
gui: listen to "movpos * position" as those are in terms of abstract features, which...
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Tue, 4 Jan 2011 02:28:38 +0000 (02:28 +0000)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Tue, 4 Jan 2011 02:28:38 +0000 (02:28 +0000)
hostside/gui-plan.c

index ca83af08828cba09f96326edc6229c58deee2f2c..67e08a140bc68e048903a156c8e1e4f34046ce89 100644 (file)
@@ -609,26 +609,47 @@ static void si_polarity(ParseState *ps) {
 }
 
 static void si_movpos(ParseState *ps) {
-  long pl;
-  int r,s,f, n_posns;
+  int r,s,f;
   s= ps_needsegment(ps);                                 if (s<0) return;
   r= ps_needword(ps);                                    if (r) return;
-  if (thiswordstrcmp(ps,"feat")) { badcmd(ps,"weird movpos"); return; }
+  if (thiswordstrcmp(ps,"position")) { badcmd(ps,"weird movpos"); return; }
 
   r= ps_needword(ps);                                    if (r) return;
-  f= lstrpdbsearch_movfeat(ps->thisword, ps->lthisword,
-                          &ui_plan_data.segments[s]);   if (f<0) return;
-  
-  n_posns= ui_plan_data.segments[s].movfeats[f].n_posns;
-  if (ps->remain[0]=='?') goto unknown;
-  r= ps_neednumber(ps,&pl,0,n_posns-1,"movfeat posn");   if (r) goto unknown;
-  state[s].mfs[f].posn= pl;
-  mx_redraw_seg(s);
-  return;
+  if (!thiswordstrcmp(ps,"?")) {
+    int f;
+    for (f=0; f < ui_plan_data.segments[s].n_movfeats; f++)
+      state[s].mfs[f].posn= ui_plan_data.segments[s].movfeats[f].n_posns;
+    mx_redraw_seg(s);
+    return;
+  }
 
-unknown:
-  state[s].mfs[f].posn= n_posns;
-  mx_redraw_seg(s);
+  const char *feat= ps->thisword;
+  const char *endword= ps->thisword + ps->lthisword;
+  while (feat < endword) {
+    int featl;
+    for (featl=0;
+        featl < ps->lthisword && CTYPE(isalpha, feat[featl]);
+        featl++);
+
+    char *ep;
+    errno=0; unsigned long pos= strtoul(feat+featl,&ep,10);
+
+    if (!featl || errno || ep==feat+featl || ep > endword) {
+      badcmd(ps,"bad movfeatpos `%.*s'", (int)(endword - feat), feat);
+      return;
+    }
+
+    f= lstrpdbsearch_movfeat(feat, featl, &ui_plan_data.segments[s]);
+    if (f<0) continue;
+
+    if (pos >= ui_plan_data.segments[s].movfeats[f].n_posns)
+      { badcmd(ps,"out of range movfeat %.*s%lu", featl,feat, pos); }
+
+    state[s].mfs[f].posn= pos;
+    mx_redraw_seg(s);
+
+    feat= ep;
+  }
 }
 
 static void si_on(ParseState *ps) {
@@ -798,7 +819,7 @@ static void si_ack(ParseState *ps) {
 static const MuxEventInfo muxeventinfos[]= {
   { "?detect", "",                          si_detect                     },
   { "?picio out polarity", "",              si_polarity                   },
-  { "?movpos", "_*_feat",                   si_movpos                     },
+  { "?movpos", "_*_position",               si_movpos                     },
   { "?picio out on", "",                    si_on                         },
   { "?picio out off", "",                   si_off                        },
   { "?train", "_*_has",                     si_train                      },