-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathu_prblst.cc
322 lines (317 loc) · 10 KB
/
u_prblst.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/*$Id: u_prblst.cc,v 26.137 2010/04/10 02:37:33 al Exp $ -*- C++ -*-
* Copyright (C) 2001 Albert Davis
* Author: Albert Davis <[email protected]>
*
* 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 3, 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.
*------------------------------------------------------------------
* probe list functions
*/
//testing=script,sparse 2006.07.14
#include "u_prblst.h"
#include "e_cardlist.h"
#include "e_node.h"
#include "e_card.h"
#include "u_nodemap.h"
#include "ap.h"
/*--------------------------------------------------------------------------*/
void PROBE_LISTS::purge(CARD* brh)
{ untested();
for (int i = 0; i < sCOUNT; ++i) { untested();
alarm[i].remove_one(brh);
plot[i] .remove_one(brh);
print[i].remove_one(brh);
store[i].remove_one(brh);
}
}
/*--------------------------------------------------------------------------*/
void PROBELIST::listing(const std::string& label)const
{ untested();
IO::mstdout.form("%-7s", label.c_str());
for (const_iterator p = begin(); p != end(); ++p) { untested();
IO::mstdout << ' ' << p->label();
if (p->range() != 0.) {untested();
IO::mstdout.setfloatwidth(5)
<< '(' << p->lo() << ',' << p->hi() << ')';
}else{ untested();
}
}
IO::mstdout << '\n';
}
/*--------------------------------------------------------------------------*/
void PROBELIST::clear(void)
{ untested();
erase(begin(), end());
}
/*--------------------------------------------------------------------------*/
/* check for match
* called by STL remove, below
* both are needed to support different versions of STL
*/
bool operator==(const PROBE& prb, const std::string& par)
{ untested();
return wmatch(prb.label(), par);
}
bool operator!=(const PROBE& prb, const std::string& par)
{untested();
//return !wmatch(prb.label(), par);
return !(prb == par);
}
/*--------------------------------------------------------------------------*/
/* remove a complete probe, extract from CS
* wild card match ex: vds(m*)
*/
void PROBELIST::remove_list(CS& cmd)
{
size_t mark = cmd.cursor();
std::string parameter(cmd.ctos(TOKENTERM) + '(');
int paren = cmd.skip1b('(');
parameter += cmd.ctos(TOKENTERM) + ')';
paren -= cmd.skip1b(')');
if (paren != 0) {untested();
cmd.warn(bWARNING, "need )");
}else if (parameter.empty()) {untested();
cmd.warn(bWARNING, "what's this?");
}else{ untested();
}
iterator x = remove(begin(), end(), parameter);
if (x != end()) { untested();
erase(x, end());
}else{itested();
cmd.warn(bWARNING, mark, "probe isn't set -- can't remove");
}
}
/*--------------------------------------------------------------------------*/
/* check for match
* called by STL remove, below
* both are needed to support different versions of stl
*/
bool operator==(const PROBE& prb, const CKT_BASE* brh)
{ untested();
return (prb.object() == brh);
}
bool operator!=(const PROBE& prb, const CKT_BASE* brh)
{untested();
return (prb.object() != brh);
}
/*--------------------------------------------------------------------------*/
/* remove a brh from a PROBELIST
* removes all probes on brh
*/
void PROBELIST::remove_one(CARD *brh)
{ untested();
assert(brh);
erase(remove(begin(), end(), brh), end());
// remove .. removes all that match and compacts the list, leaving blanks at the end
// erase .. shortens, throw away the blanks at the end
}
/*--------------------------------------------------------------------------*/
/* add_list: add a "list" of probes, usually only one
* This means possibly several probes with a single parameter
* like "v(r*)" meaning all resistors
* but not "v(r4) v(r5)" which has two parameters.
* It also takes care of setting the range for plot or alarm.
*/
void PROBELIST::add_list(CS& cmd, CARD_LIST* scope)
{ untested();
assert(scope);
if(scope==&CARD_LIST::card_list){ untested();
}else{ untested();
}
int oldcount = size();
std::string what(cmd.ctos(TOKENTERM));/* parameter */
if (what.empty()) {untested();
cmd.warn(bWARNING, "need a probe");
}else{ untested();
}
int paren = cmd.skip1b('('); /* device, node, etc. */
if (cmd.umatch("nodes ")) { untested();
// all nodes
add_all_nodes(what, scope);
}else if (cmd.umatch("0")) { untested();
// node 0 means system stuff
push_new_probe(what, 0);
}else if (cmd.is_alnum() || cmd.match1("*?")) { untested();
// branches or named nodes
size_t here1 = cmd.cursor();
bool found_something = add_branches(cmd.ctos(), what, scope);
if (!found_something) { untested();
cmd.warn(bWARNING, here1, "no match");
}else{ untested();
}
for (;;) { untested();
// a list, as in v(r1,r2,r3) or v(1,2,3)
if (!(cmd.is_alnum() || cmd.match1("*?"))) { untested();
break;
}else{ untested();
}
size_t here2 = cmd.cursor();
found_something = add_branches(cmd.ctos(), what, scope);
if (!found_something) {itested();
cmd.reset(here2);
break;
}else{ untested();
}
}
}else{itested();
cmd.warn(bDANGER, "need device or node");
}
paren -= cmd.skip1b(')');
if (paren != 0) {itested();
cmd.warn(bWARNING, "need )");
}else{ untested();
}
if (cmd.skip1b('(')) { /* range for plotting and alarm */
double lo = cmd.ctof();
double hi = cmd.ctof();
for (iterator p = begin() + oldcount; p != end(); ++p) { untested();
p->set_limit(lo,hi);
}
if (!cmd.skip1b(')')) {untested();
cmd.check(bWARNING, "need )");
}else{ untested();
}
}else{ untested();
}
}
/*--------------------------------------------------------------------------*/
void PROBELIST::push_new_probe(const std::string& param,const CARD* object)
{ untested();
bag.push_back(PROBE(param, object));
}
/*--------------------------------------------------------------------------*/
void PROBELIST::add_all_nodes(const std::string& what, CARD_LIST* scope)
{ untested();
assert(scope);
if(scope==&CARD_LIST::card_list){ untested();
}else{ untested();
}
for (NODE_MAP::const_iterator
i = scope->nodes()->begin();
i != scope->nodes()->end();
++i) { untested();
trace1("node probe", i->first);
if ((i->first != "0") && (i->first.find('.') == std::string::npos)) { untested();
NODE* node = i->second;
assert (node);
push_new_probe(what, node);
}else{ untested();
}
}
}
/*--------------------------------------------------------------------------*/
/* add_branches: add net elements to probe list
* all matching a label with wildcards
*/
bool PROBELIST::add_branches(const std::string&device,
const std::string¶m,
const CARD_LIST* scope)
{ untested();
assert(scope);
if(scope==&CARD_LIST::card_list){untested();
}else{ untested();
}
bool found_something = false;
std::string::size_type dotplace = device.find_first_of(".");
if (dotplace != std::string::npos) { untested();
// has a dot, look deeper
{ // forward (Verilog style)
std::string dev = device.substr(dotplace+1, std::string::npos);
std::string container = device.substr(0, dotplace);
for (CARD_LIST::const_iterator
i = scope->begin(); i != scope->end(); ++i) { untested();
CARD* card = *i;
if (card->is_device()
&& card->subckt()
&& wmatch(card->short_label(), container)) { untested();
found_something |= add_branches(dev, param, card->subckt());
}else{ untested();
}
}
}
{ // reverse (ACS style)
dotplace = device.find_last_of(".");
std::string container = device.substr(dotplace+1, std::string::npos);
std::string dev = device.substr(0, dotplace);
for (CARD_LIST::const_iterator
i = scope->begin(); i != scope->end(); ++i) { untested();
CARD* card = *i;
if (card->is_device()
&& card->subckt()
&& wmatch(card->short_label(), container)) { untested();
found_something |= add_branches(dev, param, card->subckt());
}else{ untested();
}
}
}
}else{ untested();
// no dots, look here
if (device.find_first_of("*?") != std::string::npos) { untested();
// there's a wild card. do linear search for all
{ // nodes
for (NODE_MAP::const_iterator
i = scope->nodes()->begin();
i != scope->nodes()->end();
++i) { untested();
if (i->first != "0") { untested();
NODE* node = i->second;
assert (node);
if (wmatch(node->short_label(), device)) { untested();
push_new_probe(param, node);
found_something = true;
}else{ untested();
}
}else{ untested();
}
}
}
{// components
for (CARD_LIST::const_iterator
i = scope->begin(); i != scope->end(); ++i) { untested();
CARD* card = *i;
if (wmatch(card->short_label(), device)) { untested();
push_new_probe(param, card);
found_something = true;
}else{ untested();
}
}
}
}else{ untested();
// no wild card. do fast search for one
{ // nodes
NODE* node = (*scope->nodes())[device];
if (node) { untested();
push_new_probe(param, node);
found_something = true;
}else{ untested();
}
}
{ //components
CARD_LIST::const_iterator i = scope->find_(device);
if (i != scope->end()) { untested();
push_new_probe(param, *i);
found_something = true;
}else{ untested();
}
}
}
}
return found_something;
}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// vim:ts=8:sw=2:noet: