1 /*
2    Copyright (C) 1999 T. Scott Dattalo
3 
4 This file is part of gpsim.
5 
6 gpsim is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10 
11 gpsim is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with gpsim; see the file COPYING.  If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.  */
20 
21 #include <ctype.h>
22 #include <stdio.h>
23 
24 #include <string>
25 
26 #include "command.h"
27 #include "cmd_shell.h"
28 #include "misc.h"
29 #include "../src/cmd_manager.h"
30 #include "../src/gpsim_interface.h"
31 
32 cmd_shell c_shell;
33 
34 static cmd_options cmd_shell_options[] =
35 {
36   {0, 0, 0}
37 };
38 
cmd_shell()39 cmd_shell::cmd_shell()
40   : command("!", 0)
41 {
42   brief_doc = "Shell out to another program or module's command line interface";
43 
44   long_doc = "!cmd.exe copy a.c b.c\n"
45     "!picxx args\n"
46     "\n";
47 
48   op = cmd_shell_options;
49 }
50 
shell(String * cmd)51 void cmd_shell::shell(String *cmd)
52 {
53   const std::string sTarget = cmd->getVal();
54   const char *pArguments = sTarget.c_str();
55 
56   if (*pArguments == '\0') {
57      CCommandManager::GetManager().ListToConsole();
58   } else {
59     while (*pArguments != '\0' && !isspace(*pArguments))
60       pArguments++;
61 
62     std::string name = sTarget.substr(0, pArguments - sTarget.c_str());
63     pArguments++;
64 
65     int iResult = CCommandManager::GetManager().Execute(name, pArguments);
66     if (iResult == CMD_ERR_PROCESSORNOTDEFINED)
67       printf("%s module command processor not found\n", name.c_str());
68   }
69 }
70