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 
22 #include <iostream>
23 #include <iomanip>
24 #include <string>
25 
26 #include "command.h"
27 #include "cmd_node.h"
28 #include "../src/stimuli.h"
29 #include "../src/symbol.h"
30 
31 cmd_node c_node;
32 
33 
34 static cmd_options cmd_node_options[] =
35 {
36   {0,0,0}
37 };
38 
39 
cmd_node()40 cmd_node::cmd_node()
41   : command("node",0)
42 {
43   brief_doc = string("Add or display stimulus nodes");
44 
45   long_doc = string ("node [new_node1 new_node2 ...]\n"
46     "\t If no new_node is specified then all of the nodes that have been\n"
47     "\tdefined are displayed. If a new_node is specified then it will be\n"
48     "\tadded to the node list. See the \"attach\" and \"stimulus\" commands\n"
49     "\tto see how stimuli are added to the nodes.\n"
50     "\n"
51     "\texamples:\n"
52     "\n"
53     "\tnode              // display the node list\n"
54     "\tnode n1 n2 n3     // create and add 3 new nodes to the list\n");
55 
56   op = cmd_node_options;
57 }
58 
dumpOneNode(const SymbolEntry_t & sym)59 void dumpOneNode(const SymbolEntry_t &sym)
60 {
61   Stimulus_Node *psn = dynamic_cast<Stimulus_Node *>(sym.second);
62 
63   if (psn) {
64     cout << psn->name() << " voltage = " << psn->get_nodeVoltage() << "V\n";
65     if (psn->stimuli) {
66       stimulus *s = psn->stimuli;
67       while (s) {
68         cout << '\t' << s->name() << '\n';
69         s=s->next;
70       }
71     }
72   }
73 }
74 
dumpNodes(const SymbolTableEntry_t & st)75 void dumpNodes(const SymbolTableEntry_t &st)
76 {
77   cout << " Node Table: " << st.first << endl;
78   (st.second)->ForEachSymbolTable(dumpOneNode);
79 }
80 
81 
list_nodes()82 void cmd_node::list_nodes()
83 {
84   globalSymbolTable().ForEachModule(dumpNodes);
85 }
86 
add_nodes(list<string> * nodes)87 void cmd_node::add_nodes(list <string> * nodes)
88 {
89   if(nodes) {
90 
91     list <string> :: iterator si;
92 
93     for (si = nodes->begin();
94 	 si != nodes->end();
95 	 ++si) {
96 
97       string &s = *si;
98       Stimulus_Node::construct((char *)s.c_str());
99     }
100 
101   }
102 }
103