From: ian Date: Fri, 23 May 2008 21:50:31 +0000 (+0000) Subject: better unknown-command handling X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=5f7cea67d6f073483e1cdb922d23c1db6da4d92c;p=trains.git better unknown-command handling --- diff --git a/hostside/README.commands b/hostside/README.commands index 8dd2be7..4ca65b7 100644 --- a/hostside/README.commands +++ b/hostside/README.commands @@ -81,6 +81,7 @@ COMMANDS AND RESPONSES P> [...] results in: + R< ?nak unknown-command|permission-denied|invalid-syntax [: ] R< ?executing [...] consequential messages including picio, signalling problems etc. then one of these @@ -110,7 +111,7 @@ MULTIPLEXER FACILITIES or M< =denied and later perhaps - M< =failing : + M< =failed : otherwise there is no need to quit - just send eof M< select [~]... @@ -129,8 +130,7 @@ MULTIPLEXER FACILITIES MULTIPLEXER-IMPLEMENTED FUNCTIONALITY AFFECTING WHOLE SYSTEM P> [!] ... - R< ?executing [!] - R< ?ack [!] ok + R< ?nak|executing...ack... as above C> !realtime kill|finish|start|start-manual C> !save diff --git a/hostside/commands.c b/hostside/commands.c index b3b8bb2..f590ce4 100644 --- a/hostside/commands.c +++ b/hostside/commands.c @@ -307,8 +307,14 @@ void command_doline(ParseState *ps, CommandInput *cmdi_arg) { simlog("command-in %s\n",ps->remain); simlog_flush(); current_cmd= 0; - current_cmd= some_needword_lookup(ps, toplevel_cmds, "command"); - if (!current_cmd) return; + + if (!ps->remain[0]) return; + r= ps_word(ps); assert(!r); + current_cmd= some_lookup(ps,toplevel_cmds); + if (!current_cmd) { + oprintf(UPO,"nack unknown-command\n"); + return; + } oprintf(UPO, "executing %s\n",current_cmd->name); if (sta_state < Sta_Run && !(current_cmd->xarg & CIXF_ANYSTA)) { oprintf(UPO,"ack %s InvalidState : layout not ready\n",current_cmd->name); diff --git a/hostside/common.h b/hostside/common.h index 6983e1f..e0cccd9 100644 --- a/hostside/common.h +++ b/hostside/common.h @@ -71,7 +71,7 @@ int ps_neednoargs(ParseState *ps); #define some_lookup(ps, infos) \ ((const typeof(infos[0])*) \ - any_lookup((ps),(infos),sizeof((infos)[0]))) + any_lookup((ps),(infos),INT_MAX,sizeof((infos)[0]))) #define some_needword_lookup_counted(ps, infos, ninfos, what) \ ((const typeof(infos[0])*) \ diff --git a/hostside/realtime.c b/hostside/realtime.c index 1dd2f41..f001b1d 100644 --- a/hostside/realtime.c +++ b/hostside/realtime.c @@ -334,6 +334,7 @@ int main(int argc, const char **argv) { default: badusage("unknown -R suboption"); } } + arg= 0; break; default: badusage("unknown option"); }