2 * Copyright (C) 2001 Albert Davis
3 * Author: Albert Davis <aldavis@gnu.org>
5 * This file is part of "Gnucap", the Gnu Circuit Analysis Package
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 *------------------------------------------------------------------
22 * command interpreter and dispatcher
26 #include "declare.h" /* plclose */
29 /*--------------------------------------------------------------------------*/
30 /* cmdproc: process a command
31 * parse, and act on, a command string
33 void CMD::cmdproc(CS
& cmd
, CARD_LIST
* scope
)
35 bool get_timer_was_running
= ::status
.get
.is_running();
38 static TIMER timecheck
;
39 bool didsomething
= true;
41 error(bTRACE
, ">>>>>" + cmd
.fullstring() + "\n");
43 timecheck
.stop().reset().start();
45 cmd
.umatch(ANTI_COMMENT
);
46 while (cmd
.umatch(I_PROMPT
)) { itested();
47 /* skip any number of these */
50 unsigned here
= cmd
.cursor();
53 // Map possible short names to full ones.
54 // If this if/else block is removed, the only loss is the short names.
55 // Although it looks like it can be used to make aliases, don't.
56 if (cmd
.umatch("'|*|#|//|\"")) { s
= "xxxxcomment";}
57 else if (cmd
.umatch("b{uild} ")) {itested(); s
= "build";}
58 else if (cmd
.umatch("del{ete} ")) { s
= "delete";}
59 else if (cmd
.umatch("fo{urier} ")) { s
= "fourier";}
60 else if (cmd
.umatch("gen{erator} ")) { s
= "generator";}
61 else if (cmd
.umatch("inc{lude} ")) {itested(); s
= "include";}
62 else if (cmd
.umatch("l{ist} ")) { s
= "list";}
63 else if (cmd
.umatch("m{odify} ")) { s
= "modify";}
64 else if (cmd
.umatch("opt{ions} ")) { s
= "options";}
65 else if (cmd
.umatch("par{ameter} ")) { s
= "param";}
66 else if (cmd
.umatch("pr{int} ")) { s
= "print";}
67 else if (cmd
.umatch("q{uit} ")) { s
= "quit";}
68 else if (cmd
.umatch("st{atus} ")) { s
= "status";}
69 else if (cmd
.umatch("te{mperature} ")){itested(); s
= "temperature";}
70 else if (cmd
.umatch("tr{ansient} ")) { s
= "transient";}
71 else if (cmd
.umatch("tw{otimetran} ")){ s
= "twotimetran";}
72 else if (cmd
.umatch("!")) { s
= "system";}
73 else if (cmd
.umatch("<")) {untested(); s
= "<";}
74 else if (cmd
.umatch(">")) { itested(); s
= ">";}
75 else{ /* no shortcut available */
80 if (s
== "xxxxcomment") {
83 CMD
* c
= command_dispatcher
[s
];
88 cmd
.warn(bWARNING
, here
, "cmd: what's this?");
90 }else if (!didsomething
) {
91 cmd
.check(bWARNING
, "bad command");
96 if (OPT::acct
&& didsomething
) {
97 IO::mstdout
.form("time=%8.2f\n", timecheck
.check().elapsed());
101 IO::mstdout
.outreset();
103 if (get_timer_was_running
) {
104 ::status
.get
.start();
108 /*--------------------------------------------------------------------------*/
109 void CMD::command(const std::string
& cs
, CARD_LIST
* scope
)
111 CS
cmd(CS::_STRING
, cs
); // from string, full command
115 //std::cerr << "CMD::command " << s << " " <<cs << "\n";
117 CMD
* c
= command_dispatcher
[s
];
119 c
->do_it(cmd
, scope
);
121 throw Exception("bad internal command: " + s
);
124 /*--------------------------------------------------------------------------*/
125 /*--------------------------------------------------------------------------*/
126 // vim:ts=8:sw=2:noet: