From: ian Date: Sun, 27 Apr 2008 23:31:06 +0000 (+0000) Subject: parsing and other bugfixes X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=5a411c38ac4dae2013a2d277cbba5e79500f5584;p=trains.git parsing and other bugfixes --- diff --git a/hostside/parseutils.c b/hostside/parseutils.c index dc21275..3a40926 100644 --- a/hostside/parseutils.c +++ b/hostside/parseutils.c @@ -21,7 +21,7 @@ int badcmd(ParseState *ps, const char *fmt, ...) { int ps_word(ParseState *ps) { const char *space; - if (!ps->remain) return -1; + if (!ps->remain) { ps->lthisword=0; return -1; } space= strchr(ps->remain, ' '); ps->thisword= ps->remain; if (space) { @@ -107,8 +107,10 @@ const void *any_lookup(ParseState *ps, const void *inf, int ninfsmax, const void *any_needword_lookup(ParseState *ps, const void *infs, int ninfsmax, size_t sz, const char *what) { + int ec; const void *r; - if (!ps_needword(ps)) return 0; + + ec= ps_needword(ps); if (ec) return 0; r= any_lookup(ps,infs,ninfsmax,sz); if (!r) { badcmd(ps,"unknown %s %.*s",what, ps->lthisword,ps->thisword); diff --git a/hostside/realtime.c b/hostside/realtime.c index 72e7c8e..8fc791b 100644 --- a/hostside/realtime.c +++ b/hostside/realtime.c @@ -191,15 +191,19 @@ static void oprint_nmradata(const PicInsn *pi) { static const CmdInfo *ci; int vbadcmd(ParseState *ps, const char *fmt, va_list al) { - oprintf(UPO,"ack %s BadCmd : ", ci->name); + oprintf(UPO,"ack %s BadCmd : ", ci?ci->name:"?"); ovprintf(UPO,fmt,al); + oprintf(UPO,"\n"); return EC_BadCmd; } static void command_doline(ParseState *ps, CommandInput *cmdi_arg) { int r; - + + ci= 0; ci= some_needword_lookup(ps, toplevel_cmds, "command"); + if (!ci) return; + oprintf(UPO, "executing %s\n", ci->name); r= ci->fn(ps,ci); switch (r) { case 0: oprintf(UPO, "ack %s ok\n", ci->name); break; diff --git a/hostside/safety.c b/hostside/safety.c index 4d23487..aa5f782 100644 --- a/hostside/safety.c +++ b/hostside/safety.c @@ -636,11 +636,16 @@ ErrorCode predict_confirm(Train *tra, int accelerate, u.usecurrentposn= 1; u.fdetc.getmovpos= pred_getmovpos; - u.tailc.getmovpos= pred_getmovpos; + u.fdetc.u= &u; trackloc_set_exactinto(&u.fdet, &u.fdetc, foredet, foredet->tr_backwards, tra->maxinto); + u.tail= u.fdet; + + u.tailc.getmovpos= pred_getmovpos; + u.tailc.u= &u; + ec= trackloc_reverse_exact(&u.tail, &u.tailc); assert(!ec); /* find the train's tail and mark it present */ @@ -649,7 +654,6 @@ ErrorCode predict_confirm(Train *tra, int accelerate, + tra->uncertainty + MARGIN_TAIL; u.tailc.nextseg= initpresent_nextseg; u.tailc.trackend= pred_trackend_panic; - u.tailc.u= &u; ec= initpresent_nextseg(&u.tail,&u.tailc,0,0); assert(!ec); ec= trackloc_advance(&u.tail,&u.tailc); assert(!ec); @@ -674,7 +678,6 @@ ErrorCode predict_confirm(Train *tra, int accelerate, u.fdetc.nextseg= fdet_nextseg; u.fdetc.getmovpos= pred_getmovpos; u.fdetc.trackend= pred_trackend; - u.fdetc.u= &u; u.tailc.nextseg= tail_nextseg; diff --git a/hostside/trackloc.c b/hostside/trackloc.c index 58384b6..19ee95c 100644 --- a/hostside/trackloc.c +++ b/hostside/trackloc.c @@ -18,12 +18,14 @@ int trackloc_set_exactinto(TrackLocation *t, TrackAdvanceContext *c, const SegPosCombInfo *pci; int r; + t->seg= seg; + t->backwards= backwards; + t->remain= 0; + r= trackloc_getlink(t,c,&pci,0,-1); if (r) return r; assert(pci); - t->seg= seg; - t->backwards= backwards; t->remain= pci->dist - into; return 0; }