/*$Id: c__cmd.cc,v 26.21 2007/03/27 08:33:15 al Exp $ -*- C++ -*- * Copyright (C) 2001 Albert Davis * Author: Albert Davis * * This file is part of "Gnucap", the Gnu Circuit Analysis Package * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. *------------------------------------------------------------------ * command interpreter and dispatcher */ //testing=obsolete #include "l_dispatcher.h" #include "u_status.h" #include "declare.h" /* plclose */ #include "u_opt.h" #include "ap.h" #include "c_comand.h" /*--------------------------------------------------------------------------*/ /* cmdproc: process a command * parse, and act on, a command string */ void CMD::cmdproc(const std::string& cs) { bool get_timer_was_running = ::status.get.is_running(); ::status.get.stop(); CS cmd(cs); static TIMER timecheck; bool didsomething = true; error(bTRACE, "%s\n", cmd.fullstring()); timecheck.stop().reset().start(); cmd.ematch(ANTI_COMMENT); while (cmd.ematch(I_PROMPT)) {itested(); /* skip any number of these */ } int here = cmd.cursor(); std::string s; // Map possible short names to full ones. // If this if/else block is removed, the only loss is the short names. // Although it looks like it can be used to make aliases, don't. /* */if (cmd.pmatch("Build")) {itested(); s = "build";} else if (cmd.pmatch("DELete")) { s = "delete";} else if (cmd.pmatch("FOurier")) { s = "fourier";} else if (cmd.pmatch("GENerator")) { s = "generator";} else if (cmd.pmatch("INClude")) {itested(); s = "include";} else if (cmd.pmatch("List")) { s = "list";} else if (cmd.pmatch("Modify")) { s = "modify";} else if (cmd.pmatch("OPTions")) { s = "options";} else if (cmd.pmatch("PARameter")) { s = "param";} else if (cmd.pmatch("PRint")) { s = "print";} else if (cmd.pmatch("Quit")) { s = "quit";} else if (cmd.pmatch("RM")) {untested(); s = "delete";} else if (cmd.pmatch("STatus")) { s = "status";} else if (cmd.pmatch("TEmperature")){untested(); s = "temperature";} else if (cmd.pmatch("TRansient")) { s = "transient";} else if (cmd.pmatch("!$$")) {itested(); s = "system";} else if (cmd.pmatch("<$$")) { s = "<";} else if (cmd.pmatch(">$$")) {itested(); s = ">";} else{ /* no shortcut available */ cmd >> s; notstd::to_lower(&s); didsomething = false; } if (s != "") { extern DISPATCHER command_dispatcher; CMD* c = command_dispatcher[s]; if (c) { c->do_it(cmd); didsomething = true; }else{ cmd.warn(bWARNING, here, "bad command"); } }else if (!didsomething) {itested(); cmd.check(bWARNING, "bad command"); didsomething = false; }else{itested(); } if (OPT::acct && didsomething) {itested(); IO::mstdout.form("time=%8.2f\n", timecheck.check().elapsed()); }else{ } plclose(); IO::suppresserrors = false; outreset(); if (get_timer_was_running) { ::status.get.start(); }else{ } } /*--------------------------------------------------------------------------*/ void CMD::command(const std::string& cs) { CS cmd(cs); std::string s; cmd >> s; notstd::to_lower(&s); if (s != "") { extern DISPATCHER command_dispatcher; CMD* c = command_dispatcher[s]; if (c) { c->do_it(cmd); }else{itested(); cmd.warn(bWARNING, 0, "bad internal command"); } }else{untested(); cmd.warn(bWARNING, 0, "empty internal command"); } } /*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/