From: Ian Jackson Date: Tue, 4 Jan 2011 02:28:38 +0000 (+0000) Subject: gui: listen to "movpos * position" as those are in terms of abstract features, which... X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=f03cfc63c4a78b2617547d6f64a4e84e33cf6e37;p=trains.git gui: listen to "movpos * position" as those are in terms of abstract features, which is what we get from layout/ --- diff --git a/hostside/gui-plan.c b/hostside/gui-plan.c index ca83af0..67e08a1 100644 --- a/hostside/gui-plan.c +++ b/hostside/gui-plan.c @@ -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 },