From 1ada4d353049c34d5df7364ad54b80e3d18db6c6 Mon Sep 17 00:00:00 2001 From: pnenzi Date: Fri, 16 Jan 2009 15:35:00 +0000 Subject: [PATCH] Finish first batch of imports from espice. --- ChangeLog | 22 ++++++++++ src/frontend/commands.c | 16 ++++++-- src/frontend/misccoms.c | 9 +++- src/frontend/mw_coms.c | 91 ++++++++++++++++++++++++++++++++++++++++- src/frontend/runcoms.c | 20 ++++++--- src/include/fteext.h | 3 ++ 6 files changed, 150 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2e9d7b249..8bbc88f3d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2009-01-16 Paolo Nenzi + * src/frontend/mw_coms.c, src/frontend/commands.c, + * src/frontend/runcoms.c, src/include/fteext.h: + 34, + 36, + 38: Added the removecirc command. This command removes the current + circuit and its associated plots. This comes from an old function + written by M. Widlok and updated by A. Roldan for espice. + Note: I have changed the code to eliminate GTK functions and tested. + Things work but in ngspice there is a problem due to model redefinitions, + as it seems that in ngspice models are globals. Need further + investigation. P. Nenzi + + * src/frontend/commands.c, src/frontend/misccomms.c: + 24: Added the parameter "noask" to quit command to avoid the question + before exiting ngspice. A. Roldan - Espice + + * src/frontend/evaluate.c, src/frontend/typedefs.c, src/include/sim.h: + Added some vector types from Espice (impedance, admittance, power etc.) + The original implementation by A. Roldan did not fit immediatly. I had + to comment two definitions. I could not test "plotab". + 2009-01-16 Paolo Nenzi * src/frontend/evaluate.c, src/frontend/typedefs.c, src/include/sim.h: Added some vector types from Espice (impedance, admittance, power etc.) diff --git a/src/frontend/commands.c b/src/frontend/commands.c index 158eef858..7c4159799 100644 --- a/src/frontend/commands.c +++ b/src/frontend/commands.c @@ -375,8 +375,13 @@ struct comm spcp_coms[] = { { 010, 010, 010, 010 }, E_DEFHMASK, 0, LOTS, (void (*)()) NULL, "[command name] ... : Print help." } , + /* to remove circuits loaded */ + { "removecirc", com_removecirc, FALSE, TRUE, FALSE, + { 04, 0, 0, 0 }, E_DEFHMASK, 0, 1, + (void (*)()) NULL, + "[circuit name] : Remove the current circuit from memory." } , { "quit", com_quit, FALSE, FALSE, TRUE, - { 0, 0, 0, 0 }, E_BEGINNING, 0, 0, + { 0, 0, 0, 0 }, E_BEGINNING, 0, 1, (void (*)()) NULL, ": Quit %s." } , { "source", com_source, FALSE, FALSE, TRUE, @@ -544,7 +549,7 @@ struct comm nutcp_coms[] = { { 0400, 0, 0, 0 }, E_DEFHMASK, 0, 1, (void (*)()) NULL, "[plotname] : Change the current working plot." } , - { "setcirc", NULL, FALSE, TRUE, FALSE, + { "setcirc", com_scirc, FALSE, TRUE, FALSE, { 04, 0, 0, 0 }, E_DEFHMASK, 0, 1, (void (*)()) NULL, "[circuit name] : Change the current circuit." } , @@ -725,9 +730,14 @@ struct comm nutcp_coms[] = { (void (*)()) NULL, "[command name] ... : Print help." } , { "quit", com_quit, FALSE, FALSE, TRUE, - { 0, 0, 0, 0 }, E_BEGINNING, 0, 0, + { 0, 0, 0, 0 }, E_BEGINNING, 0, 1, (void (*)()) NULL, ": Quit %s." } , + /* to remove circuits loaded */ + { "removecirc", com_removecirc, FALSE, TRUE, FALSE, + { 04, 0, 0, 0 }, E_DEFHMASK, 0, 1, + (void (*)()) NULL, + "[circuit name] : Remove the current circuit from memory." } , { "source", nutcom_source, FALSE, FALSE, TRUE, { 1, 1, 1, 1 }, E_DEFHMASK, 1, LOTS, (void (*)()) NULL, diff --git a/src/frontend/misccoms.c b/src/frontend/misccoms.c index 8126f3605..ad7b47ed9 100644 --- a/src/frontend/misccoms.c +++ b/src/frontend/misccoms.c @@ -38,7 +38,14 @@ com_quit(wordlist *wl) (void) cp_getvar("noaskquit", VT_BOOL, (char *) &noask); gr_clean(); cp_ccon(FALSE); - + if(wl) + if(wl->wl_word) + if(cieq(wl->wl_word,"noask")) + { + byemesg(); + exit(EXIT_NORMAL); + } + /* Make sure the guy really wants to quit. */ if (!ft_nutmeg && !noask) { for (cc = ft_circuits; cc; cc = cc->ci_next) diff --git a/src/frontend/mw_coms.c b/src/frontend/mw_coms.c index 23e1c6f95..a2f1f5daf 100644 --- a/src/frontend/mw_coms.c +++ b/src/frontend/mw_coms.c @@ -21,7 +21,16 @@ com_removecirc(wordlist *wl) { struct variable *v, *next; struct circ *ct; - + struct circ *caux=NULL; + struct plot *p; + struct plot *paux; + struct wordlist *wlist; + int auxCir=1,i,auxPlot; + + /* Allocation of a temp wordlist */ + wlist = (struct wordlist *)malloc(sizeof(struct wordlist)); + char buf[80]; + if (ft_curckt == NULL) { fprintf(cp_err, "Error: there is no circuit loaded.\n"); return; @@ -36,8 +45,88 @@ com_removecirc(wordlist *wl) } ct->ci_vars = NULL; + caux=ft_circuits; + char* namecircuit = strdup(ft_curckt->ci_name); + /* The circuit being removed is the first loaded and you have more circuits */ + if(ft_curckt==ft_circuits&&ft_circuits->ci_next!=NULL) + ft_circuits=ft_circuits->ci_next; + /* 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;ici_next; + caux->ci_next=caux->ci_next->ci_next; + /* ft_curckt=ft_circuits; */ + + } + + /* If the plot is ther first one and there are no other plots */ + if(plot_list->pl_next==NULL&&strcmp(plot_list->pl_title,namecircuit)==0) + plot_list=NULL; + + + else if(plot_list&&plot_list->pl_next!=NULL){ + 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; + /* otherwise we run over the list of plots */ + else { + for (; strcmp(p->pl_title,namecircuit)!=0&&p->pl_next!=NULL; p = p->pl_next) + auxPlot++; + if(strcmp(p->pl_title,namecircuit)==0){ + paux = plot_list; + for(i=1;ipl_next; + 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){ + sprintf(buf,"%d",auxCir); + wlist->wl_next = NULL; + wlist->wl_prev = NULL; + wlist->wl_word = buf; + + com_scirc(wlist); + free(wlist); +} +else if(ft_circuits){ + sprintf(buf,"%d",(auxCir-1)); + wlist->wl_next = NULL; + wlist->wl_prev = NULL; + wlist->wl_word = buf; + + com_scirc(wlist); + free(wlist); + +} +else + ft_curckt=NULL; return; } diff --git a/src/frontend/runcoms.c b/src/frontend/runcoms.c index 4ac8bd7c9..49b5febf7 100644 --- a/src/frontend/runcoms.c +++ b/src/frontend/runcoms.c @@ -73,12 +73,20 @@ com_scirc(wordlist *wl) return; for (p = ft_circuits; --i > 0; p = p->ci_next); } else { - for (p = ft_circuits; p; p = p->ci_next) - if (ciprefix(wl->wl_word, p->ci_name)) - break; - if (p == NULL) { - fprintf(cp_err, "Warning: no such circuit \"%s\"\n", - wl->wl_word); + for (p = ft_circuits; p; p = p->ci_next) + j++; + + p=NULL; + if ((sscanf(wl->wl_word, " %d ", &i) != 1) || (i < 0) || (i > j)); + else + for (p = ft_circuits; --i > 0; p = p->ci_next); + /* for (p = ft_circuits; p; p = p->ci_next) + * if (ciprefix(wl->wl_word, p->ci_name)) + * break; + */ + if (p == NULL) + { + fprintf(cp_err, "Warning: no such circuit \"%s\"\n",wl->wl_word); return; } fprintf(cp_out, "\t%s\n", p->ci_name); diff --git a/src/include/fteext.h b/src/include/fteext.h index 228b0f2fc..91ac8746d 100644 --- a/src/include/fteext.h +++ b/src/include/fteext.h @@ -329,6 +329,9 @@ extern void com_version(); extern int hcomp(); extern void com_where(); +/* mw_coms.c */ +extern void com_removecirc(); + /* numparse.c */ extern bool ft_strictnumparse;