From f03a32287fd7be3cc185e9fda23db9ef5826976e Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sat, 25 Jul 2020 22:14:18 +0200 Subject: [PATCH] If 'set ngbehavior=ki' in .spiceinit or flag 'kicad' on the plot line: Add " around vector names containing character / Numerical ivision in plot line then requires spaces around / --- src/frontend/plotting/plotit.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/frontend/plotting/plotit.c b/src/frontend/plotting/plotit.c index e5073fa56..e0ebe12fa 100644 --- a/src/frontend/plotting/plotit.c +++ b/src/frontend/plotting/plotit.c @@ -7,6 +7,7 @@ #include "ngspice/pnode.h" #include "ngspice/sim.h" #include "ngspice/fteext.h" +#include "ngspice/compatmode.h" #include @@ -281,6 +282,7 @@ bool plotit(wordlist *wl, const char *hcopy, const char *devname) int prevgraph = 0; static bool nointerp = FALSE; + static bool kicad = FALSE; static GRIDTYPE gtype = GRID_LIN; static PLOTTYPE ptype = PLOT_LIN; @@ -693,11 +695,43 @@ bool plotit(wordlist *wl, const char *hcopy, const char *devname) nointerp = TRUE; } + if (!sameflag) { + kicad = getflag(wl, "kicad"); + } + else if (getflag(wl, "kicad")) { + kicad = TRUE; + } + if (!wl->wl_next) { fprintf(cp_err, "Error: no vectors given\n"); goto quit1; } + /* kicad will generate vector names containing '/'. If compatibilty flag + 'ki' is set in .spiceinit or plot line flag 'kicad' is set, + we will place " around this vector name. Division in the plot command + will then work only if spaces are around ' / '.*/ + if (kicad || newcompat.ki) { + wordlist* wlk; + for (wlk = wl->wl_next; wlk; wlk = wlk->wl_next) { + char* wlkword = strchr(wlk->wl_word, '/'); + if (wlkword) { + /* already " around token */ + if (*(wlk->wl_word) == '"') + continue; + /* just '/' */ + if (*(wlkword + 1) == '\0') + continue; + else { + char* newword = tprintf("\"%s\"", wlk->wl_word); + tfree(wlk->wl_word); + wlk->wl_word = newword; + } + } + } + } + + /* Now parse the vectors. We have a list of the form * "a b vs c d e vs f g h". Since it's a bit of a hassle for * us to parse the vector boundaries here, we do this -- call