chiark / gitweb /
parsing and other bugfixes
authorian <ian>
Sun, 27 Apr 2008 23:31:06 +0000 (23:31 +0000)
committerian <ian>
Sun, 27 Apr 2008 23:31:06 +0000 (23:31 +0000)
hostside/parseutils.c
hostside/realtime.c
hostside/safety.c
hostside/trackloc.c

index dc21275e61cb3fa71737a9a4853cd5e7c9c1e8f4..3a409269c37652cc36ed06f893dce55150400907 100644 (file)
@@ -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);
index 72e7c8e8e3f524e45dbb9bd10813b0f60ed99dd4..8fc791bbf0aa3ead4e1ba296a0377ba88e9ce342 100644 (file)
@@ -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;
index 4d234870aeb67b1c3e5ebc263ec448a1d8e480be..aa5f78205a0a9e5b9109e3d84a62a958932a4271 100644 (file)
@@ -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;
 
index 58384b6c1ee35c3243db17e94af456e55dc515a6..19ee95c3c058ba0b0b4819ac23533c1d5dfc4655 100644 (file)
@@ -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;
 }