ngspice/src/frontend/mw_coms.c

131 lines
3.5 KiB
C
Raw Normal View History

2012-07-19 20:26:13 +02:00
/* Michael Widlok 2 Jun 1999 */
2000-04-27 22:03:57 +02:00
/* New commands for unloading circuits */
#include "ngspice/ngspice.h"
#include "ngspice/cpdefs.h"
#include "ngspice/ftedefs.h"
#include "ngspice/ftedev.h"
#include "ngspice/ftedebug.h"
#include "ngspice/dvec.h"
2000-04-27 22:03:57 +02:00
src/Makefile.am src/help.c src/main.c src/circuit/Makefile.am src/circuit/ifnewuid.c src/frontend/Makefile.am src/frontend/aspice.c src/frontend/circuits.h src/frontend/com_display.c src/frontend/com_hardcopy.c src/frontend/commands.c src/frontend/commands.h src/frontend/cpitf.c src/frontend/debugcom.c src/frontend/device.c src/frontend/diff.c src/frontend/display.c src/frontend/dotcards.c src/frontend/fourier.c src/frontend/inp.c src/frontend/inpcom.c src/frontend/linear.c src/frontend/misccoms.c src/frontend/mw_coms.c src/frontend/nutinp.c src/frontend/options.c src/frontend/outitf.c src/frontend/parse.c src/frontend/postcoms.c src/frontend/postsc.c src/frontend/rawfile.c src/frontend/resource.c src/frontend/runcoms.c src/frontend/runcoms2.c src/frontend/shyu.c src/frontend/spec.c src/frontend/spiceif.c src/frontend/subckt.c src/frontend/vectors.c src/frontend/where.c src/frontend/plotting/Makefile.am src/frontend/plotting/agraf.c src/frontend/plotting/graf.c src/frontend/plotting/plotcurv.c src/frontend/plotting/plotit.c src/frontend/plotting/x11.c src/frontend/plotting/xgraph.c src/include/Makefile.am src/maths/cmaths/cmath4.c src/misc/terminal.c src/misc/terminal.h src/parser/cshpar.c src/parser/front.c src/parser/front.h src/parser/history.c src/parser/history.h src/parser/modify.c src/parser/var2.c src/parser/var2.h src/parser/variable.c: Refactoring of frontend code. * src/include/ftehelp.h src/include/variable.h: Moved into frontend directory. * src/include/cpdefs.h src/include/cpextern.h src/include/ftedefs.h src/include/plot.h: Updates.
2000-06-27 18:09:02 +02:00
#include "circuits.h"
#include "mw_coms.h"
#include "variable.h"
#include "runcoms.h"
#include "spiceif.h"
2000-04-27 22:03:57 +02:00
/* Clears ckt and removes current circ. form database */
2000-04-27 22:03:57 +02:00
void
2010-06-23 19:40:56 +02:00
com_removecirc(wordlist *wl)
2000-04-27 22:03:57 +02:00
{
struct variable *v, *next;
struct circ *ct;
struct circ *caux = NULL;
struct plot *p;
struct plot *paux;
int auxCir = 1, i, auxPlot;
char* namecircuit;
char buf[80];
2010-11-16 21:38:24 +01:00
NG_IGNORE(wl);
2010-11-16 20:11:32 +01:00
if (!ft_curckt) {
2000-04-27 22:03:57 +02:00
fprintf(cp_err, "Error: there is no circuit loaded.\n");
return;
}
ct = ft_curckt;
2000-04-27 22:03:57 +02:00
if_cktfree(ct->ci_ckt, ct->ci_symtab);
2000-04-27 22:03:57 +02:00
for (v = ct->ci_vars; v; v = next) {
2012-07-19 20:26:13 +02:00
next = v->va_next;
tfree(v);
2000-04-27 22:03:57 +02:00
}
/* PN FTESTATS*/
tfree(ct->FTEstats);
2000-04-27 22:03:57 +02:00
ct->ci_vars = NULL;
caux = ft_circuits;
namecircuit = strdup(ft_curckt->ci_name);
2000-04-27 22:03:57 +02:00
/* The circuit being removed is the first loaded and you have more circuits */
if (ft_curckt == ft_circuits && ft_circuits->ci_next)
2012-07-19 20:26:13 +02:00
ft_circuits = ft_circuits->ci_next;
2000-04-27 22:03:57 +02:00
/* The circuit being removed id the first loaded and there are no more circuits */
else if (ft_circuits->ci_next == NULL)
ft_circuits = NULL;
else {
/* Run over the circuit list to find how many of them are
* in front of the one to be removed
*/
for (; ft_curckt != caux && caux; caux = caux->ci_next)
auxCir++;
caux = ft_circuits;
/* Remove the circuit and move pointer to the next one */
for (i = 1; i < auxCir-1; i++)
caux = caux->ci_next;
caux->ci_next = caux->ci_next->ci_next;
/* ft_curckt = ft_circuits; */
}
/* If the plot is the first one and there are no other plots */
if (!plot_list->pl_next && strcmp(plot_list->pl_title, namecircuit) == 0)
plot_list = NULL;
else if (plot_list && plot_list->pl_next) {
2012-07-19 20:26:13 +02:00
p = plot_list;
while (p) {
auxPlot = 1;
/* If the plot is in the first position */
if (plot_list->pl_next && strcmp(plot_list->pl_title, namecircuit) == 0)
plot_list = plot_list->pl_next;
2012-07-19 20:26:13 +02:00
/* otherwise we run over the list of plots */
else {
for (; strcmp(p->pl_title, namecircuit) != 0 && p->pl_next; p = p->pl_next)
auxPlot++;
if (strcmp(p->pl_title, namecircuit) == 0) {
paux = plot_list;
2012-07-19 20:26:13 +02:00
for (i = 1; i < auxPlot-1; i++)
paux = paux->pl_next;
2012-07-19 20:26:13 +02:00
paux->pl_next = paux->pl_next->pl_next;
}
}
p = p->pl_next;
}
}
/* if (ft_curckt) {
ft_curckt->ci_devices = cp_kwswitch(CT_DEVNAMES, ft_circuits->ci_devices);
ft_curckt->ci_nodes = cp_kwswitch(CT_NODENAMES, ft_circuits->ci_nodes);
} */
if (ft_circuits && caux->ci_next) {
struct wordlist *wlist;
2012-07-19 20:26:13 +02:00
sprintf(buf, "%d", auxCir);
wlist = wl_cons(copy(buf), NULL);
2012-07-19 20:26:13 +02:00
com_scirc(wlist);
wl_free(wlist);
}
else if (ft_circuits) {
struct wordlist *wlist;
sprintf(buf, "%d", auxCir-1);
wlist = wl_cons(copy(buf), NULL);
2012-07-19 20:26:13 +02:00
com_scirc(wlist);
wl_free(wlist);
}
else
2012-07-19 20:26:13 +02:00
ft_curckt = NULL;
2000-04-27 22:03:57 +02:00
}