Merge branch 'testing-uf' into master-uf
[gnucap-felix.git] / lib / c__cmd.cc
blob94a9823c412fada1abd4c8f2ff4af3f724ae81d5
1 /* -*- C++ -*-
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)
10 * any later version.
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
20 * 02110-1301, USA.
21 *------------------------------------------------------------------
22 * command interpreter and dispatcher
24 //testing=obsolete
25 #include "u_status.h"
26 #include "declare.h" /* plclose */
27 #include "c_comand.h"
28 #include "globals.h"
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();
36 ::status.get.stop();
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();
51 std::string s;
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 */
76 cmd >> s;
77 didsomething = false;
80 if (s == "xxxxcomment") {
81 // nothing
82 }else if (s != "") {
83 CMD* c = command_dispatcher[s];
84 if (c) {
85 c->do_it(cmd, scope);
86 didsomething = true;
87 }else{
88 cmd.warn(bWARNING, here, "cmd: what's this?");
90 }else if (!didsomething) {
91 cmd.check(bWARNING, "bad command");
92 didsomething = false;
93 }else{ itested();
96 if (OPT::acct && didsomething) {
97 IO::mstdout.form("time=%8.2f\n", timecheck.check().elapsed());
98 }else{
100 plclose();
101 IO::mstdout.outreset();
103 if (get_timer_was_running) {
104 ::status.get.start();
105 }else{
108 /*--------------------------------------------------------------------------*/
109 void CMD::command(const std::string& cs, CARD_LIST* scope)
111 CS cmd(CS::_STRING, cs); // from string, full command
112 std::string s;
113 cmd >> s;
115 //std::cerr << "CMD::command " << s << " " <<cs << "\n";
117 CMD* c = command_dispatcher[s];
118 if (c) {
119 c->do_it(cmd, scope);
120 }else{
121 throw Exception("bad internal command: " + s);
124 /*--------------------------------------------------------------------------*/
125 /*--------------------------------------------------------------------------*/
126 // vim:ts=8:sw=2:noet: