ngspice/src/frontend/breakp2.c

191 lines
4.2 KiB
C
Raw Normal View History

2000-04-27 22:03:57 +02:00
/**********
Copyright 1990 Regents of the University of California. All rights reserved.
Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group
**********/
/*
* Code to deal with breakpoints and tracing.
*/
#include "ngspice/ngspice.h"
#include "ngspice/cpdefs.h"
#include "ngspice/ftedefs.h"
#include "ngspice/dvec.h"
#include "ngspice/ftedebug.h"
2000-04-27 22:03:57 +02:00
#include "breakp2.h"
2009-12-19 17:04:22 +01:00
/* global linked list to store .save data and breakpoint data */
2000-04-27 22:03:57 +02:00
struct dbcomm *dbs = NULL; /* export for iplot */
2009-12-19 17:04:22 +01:00
/* used in breakp.c and breakp2.c */
2000-04-27 22:03:57 +02:00
int debugnumber = 1;
static char *copynode(char* s);
2009-12-19 17:04:22 +01:00
/* Analyse the data given by the .save card or 'save' command.
Store the data in the global dbs struct.
*/
2000-04-27 22:03:57 +02:00
/* Save a vector. */
void
com_save(wordlist *wl)
{
settrace(wl, VF_ACCUM, NULL);
}
2009-12-19 17:04:22 +01:00
/* Save a vector with the analysis type given (name). */
2000-04-27 22:03:57 +02:00
void
com_save2(wordlist *wl, char *name)
{
settrace(wl, VF_ACCUM, name);
}
2000-04-27 22:03:57 +02:00
void
settrace(wordlist *wl, int what, char *name)
{
struct dbcomm *d, *last, *dbcheck;
2000-04-27 22:03:57 +02:00
if (!ft_curckt) {
fprintf(cp_err, "Error: no circuit loaded\n");
return;
}
if (dbs)
for (last = dbs; last->db_next; last = last->db_next)
;
else
last = NULL;
2016-10-30 20:25:26 +01:00
for (;wl ;wl = wl->wl_next) {
char *s = cp_unquote(wl->wl_word);
char *db_nodename1 = NULL;
char db_type = 0;
if (eq(s, "all") || eq(s, "nosub")) {
2000-04-27 22:03:57 +02:00
switch (what) {
case VF_PRINT:
2016-10-30 20:25:26 +01:00
db_type = DB_TRACEALL;
break;
case VF_ACCUM:
2016-10-30 20:25:26 +01:00
db_nodename1 = copy(s);
db_type = DB_SAVE;
break;
2000-04-27 22:03:57 +02:00
}
tfree(s);
2000-04-27 22:03:57 +02:00
} else {
switch (what) {
case VF_PRINT:
2016-10-30 20:25:26 +01:00
db_type = DB_TRACENODE;
break;
case VF_ACCUM:
2016-10-30 20:25:26 +01:00
db_type = DB_SAVE;
break;
2000-04-27 22:03:57 +02:00
}
/* v(2) --> 2, i(vds) --> vds#branch */
2016-10-30 20:25:26 +01:00
db_nodename1 = copynode(s);
tfree(s);
if (!db_nodename1) /* skip on error */
continue;
2000-04-27 22:03:57 +02:00
}
/* Don't save a nodename more than once, except for token 'all' */
if (db_type == DB_SAVE) {
for (dbcheck = dbs; dbcheck; dbcheck = dbcheck->db_next) {
if (dbcheck->db_type == DB_SAVE && eq(dbcheck->db_nodename1, db_nodename1) &&
!eq("all", db_nodename1)) {
2021-12-23 14:37:57 +01:00
tfree(db_nodename1);
goto loopend;
}
}
}
2016-10-30 20:25:26 +01:00
d = TMALLOC(struct dbcomm, 1);
d->db_analysis = name;
d->db_type = db_type;
d->db_nodename1 = db_nodename1;
d->db_number = debugnumber++;
if (last)
last->db_next = d;
else
ft_curckt->ci_dbs = dbs = d;
last = d;
loopend:;
2000-04-27 22:03:57 +02:00
}
}
2009-12-19 17:04:22 +01:00
/* retrieve the save nodes from dbs into an array */
2000-04-27 22:03:57 +02:00
int
ft_getSaves(struct save_info **savesp)
2009-12-19 17:04:22 +01:00
/* global variable: dbs */
2000-04-27 22:03:57 +02:00
{
struct dbcomm *d;
int count = 0, i = 0;
struct save_info *array;
for (d = dbs; d; d = d->db_next)
if (d->db_type == DB_SAVE)
count++;
2009-12-19 17:04:22 +01:00
2000-04-27 22:03:57 +02:00
if (!count)
return (0);
*savesp = array = TMALLOC(struct save_info, count);
2000-04-27 22:03:57 +02:00
for (d = dbs; d; d = d->db_next)
if (d->db_type == DB_SAVE) {
array[i].used = 0;
if (d->db_analysis)
array[i].analysis = copy(d->db_analysis);
else
array[i].analysis = NULL;
2000-04-27 22:03:57 +02:00
array[i++].name = copy(d->db_nodename1);
}
2000-04-27 22:03:57 +02:00
return (count);
}
/* v(2) --> 2, i(vds) --> vds#branch, 3 --> 3, @mn1[vth0] --> @mn1[vth0]
* derived from wordlist *gettoks(char *s)
*/
static char*
copynode(char *s)
{
char *l, *r;
char *ret = NULL;
if (strchr(s, '('))
s = stripWhiteSpacesInsideParens(s);
2013-08-20 19:47:10 +02:00
else
s = copy(s);
l = strrchr(s, '(');
2013-08-20 19:47:10 +02:00
if (!l)
return s;
r = strchr(s, ')');
if (!r) {
fprintf(cp_err, "Warning: Missing ')' in %s\n Not saved!\n", s);
tfree(s);
return NULL;
}
*r = '\0';
2015-03-28 20:10:29 +01:00
if (*(l - 1) == 'i' || *(l - 1) == 'I')
ret = tprintf("%s#branch", l + 1);
else
ret = copy(l + 1);
2013-08-20 19:47:10 +02:00
tfree(s);
return ret;
}