diff --git a/src/frontend/variable.c b/src/frontend/variable.c index 2be776f2e..5da56d446 100644 --- a/src/frontend/variable.c +++ b/src/frontend/variable.c @@ -1,6 +1,6 @@ /********** -Copyright 1990 Regents of the University of California. All rights reserved. -Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group + Copyright 1990 Regents of the University of California. All rights reserved. + Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group **********/ #include "ngspice/ngspice.h" @@ -12,14 +12,12 @@ Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group #include "ngspice/memory.h" #include "ngspice/inpdefs.h" #include "ngspice/fteext.h" - #include "circuits.h" #include "com_history.h" #include "quote.h" #include "ngspice/cpextern.h" #include "variable.h" - bool cp_noglob = TRUE; bool cp_nonomatch = FALSE; bool cp_noclobber = FALSE; @@ -28,14 +26,12 @@ bool cp_echo = FALSE; /* CDHW */ struct variable *variables = NULL; - wordlist * cp_varwl(struct variable *var) { wordlist *wl = NULL, *w, *wx = NULL; char buf[BSIZE_SP], *copystring; struct variable *vt; - switch (var->va_type) { case CP_BOOL: /* Can't ever be FALSE. */ @@ -72,12 +68,10 @@ cp_varwl(struct variable *var) var->va_type); return NULL; } - wl = wl_cons(copy(buf), NULL); return wl; } - /* Set a variable. */ void cp_vset(char *varname, enum cp_types type, void *value) @@ -86,11 +80,8 @@ cp_vset(char *varname, enum cp_types type, void *value) int i; bool alreadythere = FALSE, v_free = FALSE; char *copyvarname; - /* varname = cp_unquote(varname); DG: Memory leak old varname is lost*/ - copyvarname = cp_unquote(varname); - w = NULL; for (v = variables; v; v = v->va_next) { if (eq(copyvarname, v->va_name)) { @@ -99,21 +90,18 @@ cp_vset(char *varname, enum cp_types type, void *value) } w = v; } - if (alreadythere) { if (v->va_type == CP_LIST) free_struct_variable(v->va_vlist); if (v->va_type == CP_STRING) tfree(v->va_string); } - if (!v) { v = alloc(struct variable); v->va_name = copy(copyvarname); v->va_next = NULL; v_free = TRUE; } - switch (type) { case CP_BOOL: if (* ((bool *) value) == FALSE) { @@ -128,23 +116,18 @@ cp_vset(char *varname, enum cp_types type, void *value) v->va_bool = TRUE; } break; - case CP_NUM: v->va_num = * (int *) value; break; - case CP_REAL: v->va_real = * (double *) value; break; - case CP_STRING: v->va_string = copy((char*) value); break; - case CP_LIST: v->va_vlist = (struct variable *) value; break; - default: fprintf(cp_err, "cp_vset: INTERNAL ERROR: bad variable type %d.\n", @@ -152,9 +135,7 @@ cp_vset(char *varname, enum cp_types type, void *value) tfree(copyvarname); return; } - v->va_type = type; - /* Now, see if there is anything interesting going on. We * recognize these special variables: noglob, nonomatch, history, * echo, noclobber, prompt, and verbose. cp_remvar looks for these @@ -180,7 +161,6 @@ cp_vset(char *varname, enum cp_types type, void *value) } switch (i = cp_usrset(v, TRUE)) { - case US_OK: /* Normal case. */ if (!alreadythere) { @@ -188,7 +168,6 @@ cp_vset(char *varname, enum cp_types type, void *value) variables = v; } break; - case US_DONTRECORD: /* Do nothing... */ if (alreadythere) { @@ -196,19 +175,17 @@ cp_vset(char *varname, enum cp_types type, void *value) "%s already there, but `don't record'\n", v->va_name); } break; - case US_READONLY: fprintf(cp_err, "ERROR: %s is a read-only variable.\n", v->va_name); if (alreadythere) fprintf(cp_err, "cp_vset: INTERNAL ERROR: " "it was already there too!!\n"); break; - case US_SIMVAR: if (alreadythere) { /* somehow it got into the front-end list of variables */ if (w) { - w->va_next = v->va_next; + w->va_next = v->va_next; } else { variables = v->va_next; } @@ -235,13 +212,11 @@ cp_vset(char *varname, enum cp_types type, void *value) } } break; - case US_NOSIMVAR: /* What do you do? */ tfree(v->va_name); tfree(v); break; - default: fprintf(cp_err, "cp_vset: INTERNAL ERROR: bad US val %d\n", i); break; @@ -249,12 +224,11 @@ cp_vset(char *varname, enum cp_types type, void *value) tfree(copyvarname); } - /* CDHW This needs leak checking carefully CDHW */ -/* mhx: Uses ft_numparse, which interprets SPICE numbers. Therefore it worked incorrectly - for com_set: it prevented e.g. set ape="1MEG" (ape became CP_NUM 1e6 instead of CP_STRING '1meg'). - Therefore I changed the function to FIRST check if the rhs is a string (look for quotes), and only - if it is not, continue with ft_numparse. +/* mhx: Uses ft_numparse, which interprets SPICE numbers. Therefore it worked incorrectly + for com_set: it prevented e.g. set ape="1MEG" (ape became CP_NUM 1e6 instead of CP_STRING '1meg'). + Therefore I changed the function to FIRST check if the rhs is a string (look for quotes), and only + if it is not, continue with ft_numparse. Note: cp_setparse is used by com_set and com_option, where this new behavior should be ok. cp_setparse is used in inp.c (4) for .option scale=xxx. Assumed new behavior will be ok. cp_setparse is used in rawfile.c (2) to parse "option: xxx". Assumed new behavior will be ok. @@ -268,14 +242,10 @@ cp_setparse(wordlist *wl) struct variable *listv = NULL, *vv, *lv = NULL; struct variable *vars = NULL; int balance; - while (wl) { - if (name) tfree(name); - name = cp_unquote(wl->wl_word); - wl = wl->wl_next; if ((!wl || (*wl->wl_word != '=')) && !strchr(name, '=')) { /* 'name ccccc' */ vv = alloc(struct variable); @@ -287,8 +257,7 @@ cp_setparse(wordlist *wl) tfree(name); /*DG: cp_unquote Memory leak*/ continue; } - - if (wl && eq(wl->wl_word, "=")) { /* 'name =' */ + if (wl && eq(wl->wl_word, "=")) { /* 'name =' */ wl = wl->wl_next; if (wl == NULL) { fprintf(cp_err, "ERROR: bad set form.\n"); @@ -324,20 +293,18 @@ cp_setparse(wordlist *wl) controlled_exit(EXIT_BAD); return NULL; } - /* val = cp_unquote(val); DG: bad old val is lost*/ - isstring = (*val == '"'); /* mhx: is this sufficient? */ - copyval = cp_unquote(val); /*DG*/ + isstring = (*val == '"'); /* mhx: is this sufficient? */ + copyval = cp_unquote(val); /*DG*/ strcpy(val, copyval); tfree(copyval); - - if (eq(val, "(")) { + if (eq(val, "(")) { /* The beginning of a list... We have to walk down the * list until we find a close paren... If there are nested * ()'s, treat them as tokens... */ balance = 1; while (wl && wl->wl_word) { - bool isstringc; + bool isstringc; if (eq(wl->wl_word, "(")) { balance++; } else if (eq(wl->wl_word, ")")) { @@ -346,13 +313,13 @@ cp_setparse(wordlist *wl) } vv = alloc(struct variable); vv->va_next = NULL; - isstringc = (*wl->wl_word == '"'); /* mhx: is this sufficient? */ - copyval = ss = cp_unquote(wl->wl_word); + isstringc = (*wl->wl_word == '"'); /* mhx: is this sufficient? */ + copyval = ss = cp_unquote(wl->wl_word); if (isstringc) { vv->va_type = CP_STRING; vv->va_string = copy(ss); } else { - td = ft_numparse(&ss, FALSE); + td = ft_numparse(&ss, FALSE); if (td) { vv->va_type = CP_REAL; vv->va_real = *td; @@ -361,14 +328,14 @@ cp_setparse(wordlist *wl) vv->va_string = copy(ss); fprintf(cp_err, "cp_setparse() :: ft_numparse() didn't recognize `%s' for assignment to `%s' as CP_REAL, using CP_STRING.\n", ss, name); } - } + } tfree(copyval); /*DG: must free ss any way to avoid cp_unquote memory leak*/ if (listv) { lv->va_next = vv; lv = vv; } else { listv = lv = vv; - } + } wl = wl->wl_next; } if (balance && !wl) { @@ -378,31 +345,28 @@ cp_setparse(wordlist *wl) controlled_exit(EXIT_BAD); return NULL; } - vv = alloc(struct variable); vv->va_name = copy(name); vv->va_type = CP_LIST; vv->va_vlist = listv; vv->va_next = vars; vars = vv; - wl = wl->wl_next; continue; } - - /* there shouldn't be quotes around val at this point? */ + /* there shouldn't be quotes around val at this point? */ if (*val == '"') isstring |= TRUE; /* mhx: is this sufficient? */ - copyval = ss = cp_unquote(val); /* 'name = ccccc' */ - vv = alloc(struct variable); - vv->va_name = copy(name); - vv->va_next = vars; - vars = vv; + copyval = ss = cp_unquote(val); /* 'name = ccccc'*/ + vv = alloc(struct variable); + vv->va_name = copy(name); + vv->va_next = vars; + vars = vv; if (isstring) { vv->va_type = CP_STRING; vv->va_string = copy(val); } else { - td = ft_numparse(&ss, FALSE); /* FALSE: because set x=1umeter should work and 'meter' ignored */ + td = ft_numparse(&ss, FALSE); /* FALSE: because set x=1umeter should work and 'meter' ignored */ if (td) { vv->va_type = CP_REAL; vv->va_real = *td; @@ -410,17 +374,15 @@ cp_setparse(wordlist *wl) vv->va_type = CP_STRING; vv->va_string = copy(val); } - } - tfree(copyval); /*DG: must free ss any way to avoid cp_unquote memory leak */ - tfree(name); /* va: cp_unquote memory leak: free name for every loop */ + } + tfree(copyval); /*DG: must free ss any way to avoid cp_unquote memory leak */ + tfree(name); /* va: cp_unquote memory leak: free name for every loop */ } - if (name) tfree(name); return vars; } - /* free the struct variable. The type of the union is given by va_type */ void free_struct_variable(struct variable *v) @@ -436,7 +398,6 @@ free_struct_variable(struct variable *v) } } - void cp_remvar(char *varname) { @@ -444,9 +405,7 @@ cp_remvar(char *varname) struct variable *uv1, *uv2; bool found = TRUE; int i, var_index = 0; - cp_usrvars(&uv1, &uv2); - for (v = variables; v; v = v->va_next) { var_index = 0; if (eq(v->va_name, varname)) @@ -480,7 +439,6 @@ cp_remvar(char *varname) v->va_num = 0; found = FALSE; } - /* Note that 'unset history' doesn't do anything here... Causes * trouble... */ if (eq(varname, "noglob")) @@ -501,7 +459,6 @@ cp_remvar(char *varname) cp_program = ""; switch (i = cp_usrset(v, FALSE)) { - case US_OK: /* Normal case. */ if (found) { @@ -515,10 +472,8 @@ cp_remvar(char *varname) } else { ft_curckt->ci_vars = v->va_next; } - } break; - case US_DONTRECORD: /* Do nothing... */ if (found) @@ -527,7 +482,7 @@ cp_remvar(char *varname) case US_READONLY: /* Badness... */ - fprintf(cp_err, "ERROR: %s is read-only.\n", v->va_name); + fprintf(cp_err, "ERROR: %s is read-only.\n", v->va_name); if (found) fprintf(cp_err, "cp_remvar: INTERNAL ERROR: var %d\n", *varname); break; @@ -543,7 +498,7 @@ cp_remvar(char *varname) } if (u) { if (lv) - lv->va_next = u->va_next; + lv->va_next = u->va_next; else ft_curckt->ci_vars = u->va_next; tfree(u); @@ -555,26 +510,22 @@ cp_remvar(char *varname) fprintf(cp_err, "cp_remvar: INTERNAL ERROR: US val %d\n", i); break; } - v->va_next = NULL; tfree(v->va_name); free_struct_variable(v); free_struct_variable(uv1); } - -/* +/* * Determine the value of a variable. Fail if the variable is unset, - * and if the type doesn't match, try and make it work... + * and if the type doesn't match, try and make it work... */ bool cp_getvar(char *name, enum cp_types type, void *retval) { struct variable *v; struct variable *uv1, *uv2; - cp_usrvars(&uv1, &uv2); - for (v = variables; v && !eq(name, v->va_name); v = v->va_next) ; if (v == NULL) @@ -583,14 +534,12 @@ cp_getvar(char *name, enum cp_types type, void *retval) if (v == NULL) for (v = uv2; v && !eq(name, v->va_name); v = v->va_next) ; - if (v == NULL) { if (type == CP_BOOL && retval) * (bool *) retval = FALSE; free_struct_variable(uv1); return FALSE; } - if (v->va_type == type) { switch (type) { case CP_BOOL: @@ -630,9 +579,7 @@ cp_getvar(char *name, enum cp_types type, void *retval) } free_struct_variable(uv1); return TRUE; - } else { - /* Try to coerce it.. */ if ((type == CP_NUM) && (v->va_type == CP_REAL)) { int *i; @@ -660,7 +607,6 @@ cp_getvar(char *name, enum cp_types type, void *retval) } } - /* A variable substitution is indicated by a $, and the variable name * is the following string of non-special characters. All variable * values are inserted as a single word, except for lists, which are a @@ -685,8 +631,7 @@ span_var_expr(char *t) { int parenthesis = 0; int brackets = 0; - - while (*t && (isalphanum((int)*t) || strchr(VALIDCHARS, *t))) + while (*t && (isalphanum((int)*t) || strchr(VALIDCHARS, *t))) switch (*t++) { case '[': @@ -710,11 +655,9 @@ span_var_expr(char *t) default: break; } - return t; } - wordlist * cp_variablesubst(wordlist *wlist) { @@ -724,7 +667,6 @@ cp_variablesubst(wordlist *wlist) int i; for (wl = wlist; wl; wl = wl->wl_next) { - t = wl->wl_word; i = 0; while ((s = strchr(t, cp_dol)) != NULL) { @@ -744,9 +686,9 @@ cp_variablesubst(wordlist *wlist) if (i) { (void) strcpy(buf, wbuf); if (nwl) { - (void) strcat(buf, nwl->wl_word); - tfree(nwl->wl_word); - nwl->wl_word = copy(buf); + (void) strcat(buf, nwl->wl_word); + tfree(nwl->wl_word); + nwl->wl_word = copy(buf); } else { nwl = wl_cons(copy(buf), NULL); } @@ -770,11 +712,9 @@ cp_variablesubst(wordlist *wlist) wbuf[i++] = *s; } } - return wlist; } - /* Evaluate a variable. */ wordlist * vareval(char *string) @@ -785,21 +725,17 @@ vareval(char *string) char *oldstring = copy(string); char *range = NULL; int i, up, low; - cp_wstrip(string); if ((s = strchr(string, '[')) != NULL) { *s = '\0'; range = s + 1; } - switch (*string) { - case '$': (void) sprintf(buf, "%d", getpid()); wl = wl_cons(copy(buf), NULL); tfree(oldstring); return (wl); - case '<': (void) fflush(cp_out); if (!fgets(buf, BSIZE_SP, cp_in)) { @@ -815,7 +751,6 @@ vareval(char *string) wl->wl_word = copy(""); tfree(oldstring); return (wl); - case '?': string++; for (v = variables; v; v = v->va_next) @@ -826,7 +761,6 @@ vareval(char *string) wl = wl_cons(copy(v ? "1" : "0"), NULL); tfree(oldstring); return (wl); - case '#': string++; for (v = variables; v; v = v->va_next) @@ -848,13 +782,11 @@ vareval(char *string) wl = wl_cons(copy(buf), NULL); tfree(oldstring); return (wl); - case '\0': wl = wl_cons(copy("$"), NULL); tfree(oldstring); return (wl); } - /* The notation var[stuff] has two meanings... If this is a real * variable, then the [] denotes range, but if this is a strange * (e.g, device parameter) variable, it could be anything... @@ -884,7 +816,6 @@ vareval(char *string) return NULL; } wl = cp_varwl(v); - /* Now parse and deal with 'range' ... */ if (range) { /* rather crude fix when range itself is a $expression */ @@ -922,21 +853,18 @@ vareval(char *string) return wl; } - static int vcmp(const void *a, const void *b) { int i; struct xxx *v1 = (struct xxx *) a; struct xxx *v2 = (struct xxx *) b; - if ((i = strcmp(v1->x_v->va_name, v2->x_v->va_name)) != 0) return (i); else return (v1->x_char - v2->x_char); } - /* Print the values of currently defined variables. */ void cp_vprint(void) @@ -947,18 +875,14 @@ cp_vprint(void) int i, j; char *s; struct xxx *vars; - cp_usrvars(&uv1, &uv2); - for (v = uv1, i = 0; v; v = v->va_next) i++; for (v = uv2; v; v = v->va_next) i++; for (v = variables; v; v = v->va_next) i++; - vars = TMALLOC(struct xxx, i); - out_init(); for (v = variables, i = 0; v; v = v->va_next, i++) { vars[i].x_v = v; @@ -972,9 +896,7 @@ cp_vprint(void) vars[i].x_v = v; vars[i].x_char = '+'; } - qsort(vars, (size_t) i, sizeof(*vars), vcmp); - for (j = 0; j < i; j++) { if (j && eq(vars[j].x_v->va_name, vars[j-1].x_v->va_name)) continue; @@ -991,6 +913,5 @@ cp_vprint(void) out_printf("%s\n", s); } } - tfree(vars); } diff --git a/src/frontend/vectors.c b/src/frontend/vectors.c index 83f2e2a32..9b4bd1fd1 100644 --- a/src/frontend/vectors.c +++ b/src/frontend/vectors.c @@ -1,6 +1,6 @@ /********** -Copyright 1990 Regents of the University of California. All rights reserved. -Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group + Copyright 1990 Regents of the University of California. All rights reserved. + Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group **********/ /* @@ -24,7 +24,6 @@ Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group struct dvec *EVTfindvec(char *node); - static void vec_rebuild_lookup_table(struct plot *pl) { @@ -55,7 +54,6 @@ vec_rebuild_lookup_table(struct plot *pl) pl->pl_lookup_valid = TRUE; } - /* Find a named vector in a plot. We are careful to copy the vector if * v_link2 is set, because otherwise we will get screwed up. */ static struct dvec * @@ -77,7 +75,7 @@ findvec(char *word, struct plot *pl) vec_new(v); } else { v = d; - } + } if (end) end->v_link2 = v; else @@ -96,7 +94,7 @@ findvec(char *word, struct plot *pl) vec_new(v); } else { v = d; - } + } if (end) end->v_link2 = v; else @@ -111,11 +109,11 @@ findvec(char *word, struct plot *pl) for (d = pl->pl_dvecs; d; d = d->v_next) { if ((d->v_flags & VF_PERMANENT) && (d->v_type == SV_CURRENT)) { if (d->v_link2) { - v = vec_copy(d); - vec_new(v); + v = vec_copy(d); + vec_new(v); } else { v = d; - } + } if (end) end->v_link2 = v; else @@ -130,11 +128,11 @@ findvec(char *word, struct plot *pl) for (d = pl->pl_dvecs; d; d = d->v_next) { if ((d->v_flags & VF_PERMANENT) && (!cieq(d->v_name, pl->pl_scale->v_name))) { if (d->v_link2) { - v = vec_copy(d); - vec_new(v); + v = vec_copy(d); + vec_new(v); } else { v = d; - } + } if (end) end->v_link2 = v; else @@ -187,7 +185,6 @@ findvec(char *word, struct plot *pl) return d; } - /* If there are imbedded numeric strings, compare them numerically, not * alphabetically. */ @@ -219,7 +216,6 @@ namecmp(const void *a, const void *b) } } - static int veccmp(const void *a, const void *b) { @@ -233,7 +229,6 @@ veccmp(const void *a, const void *b) return namecmp((*d1)->v_name, (*d2)->v_name); } - /* Sort all the vectors in d, first by plot name and then by vector * name. Do the right thing with numbers. */ static struct dvec * @@ -261,7 +256,6 @@ sortvecs(struct dvec *d) return d; } - /* Load in a rawfile. */ void ft_loadfile(char *file) @@ -293,7 +287,6 @@ ft_loadfile(char *file) plotl_changed = TRUE; } - void plot_add(struct plot *pl) { @@ -303,7 +296,6 @@ plot_add(struct plot *pl) fprintf(cp_out, "Title: %s\nName: %s\nDate: %s\n\n", pl->pl_title, pl->pl_name, pl->pl_date); - if (plot_cur) plot_cur->pl_ccom = cp_kwswitch(CT_VECTOR, pl->pl_ccom); @@ -329,32 +321,24 @@ plot_add(struct plot *pl) plot_setcur(pl->pl_typename); } - /* Remove a vector from the database, if it is there. */ - void vec_remove(char *name) { struct dvec *ov; - for (ov = plot_cur->pl_dvecs; ov; ov = ov->v_next) if (cieq(name, ov->v_name) && (ov->v_flags & VF_PERMANENT)) break; - if (!ov) return; - ov->v_flags &= ~VF_PERMANENT; - /* Remove from the keyword list. */ cp_remkword(CT_VECTOR, name); } - /* Get a vector by name. This deals with v(1), etc. almost properly. Also, * it checks for pre-defined vectors. */ - struct dvec * vec_fromplot(char *word, struct plot *plot) { @@ -374,7 +358,7 @@ vec_fromplot(char *word, struct plot *plot) } /* scanf("%c(%s)" doesn't do what it should do. ) */ - if (!d && (sscanf(word, "%c(%s", /* ) */ &cc, buf) == 2) && + if (!d && (sscanf(word, "%c(%s", /* ) */ &cc, buf) == 2) && /* ( */ ((s = strrchr(buf, ')')) != NULL) && (s[1] == '\0')) { *s = '\0'; @@ -385,17 +369,15 @@ vec_fromplot(char *word, struct plot *plot) } d = findvec(buf, plot); } - return d; } - /* This is the main lookup routine for names. The possible types of names are: - * name An ordinary vector. - * plot.name A vector from a particular plot. + * name An ordinary vector. + * plot.name A vector from a particular plot. * @device[parm] A device parameter. * @model[parm] A model parameter. - * @param A circuit parameter. + * @param A circuit parameter. * For the @ cases, we construct a dvec with length 1 to hold the value. * In the other two cases, either the plot or the name can be "all", a * wildcard. @@ -413,12 +395,12 @@ vec_get(const char *vec_name) char buf[BSIZE_SP], *s, *wd, *word, *whole, *name = NULL, *param; int i = 0; struct variable *vv; - int indexvar; /* mhx */ - - wd = word = copy(vec_name); /* Gets mangled below... */ - - if (*word != SPECCHAR) { /* mhx: eventually replace atoi() by full evaluate */ - char *ps = strchr(wd, '['), *pe = strchr(wd, ']'); + int indexvar; /* mhx */ + + wd = word = copy(vec_name); /* Gets mangled below... */ + + if (*word != SPECCHAR) { /* mhx: eventually replace atoi() by full evaluate */ + char *ps = strchr(wd, '['), *pe = strchr(wd, ']'); if (ps && pe && pe > ps) { whole = copy(word); *ps = '\0'; @@ -448,11 +430,11 @@ vec_get(const char *vec_name) } else { /* This used to be an error... */ pl = plot_cur; - } + } } } else { pl = plot_cur; - } + } if (pl) { d = vec_fromplot(word, pl); @@ -473,29 +455,29 @@ vec_get(const char *vec_name) } } d = newv; - if (!d) { + if (!d) { fprintf(cp_err, "ERROR: plot wildcard (name %s) matches nothing\n", word); - tfree(wd); + tfree(wd); return NULL; } } - /* In case of data[ix] we must return a SINGLE value - (vector of length 1) instead of the vector. + /* In case of data[ix] we must return a SINGLE value + (vector of length 1) instead of the vector. Duplicates a lot of code that still follows :-( */ if (d && indexvar != -1) { - struct dvec *ad; - ad = alloc(struct dvec); - ZERO(ad, struct dvec); - ad->v_name = copy(whole); /* so the name could be data[2] or data[expression] :-) */ - ad->v_type = d->v_type; - ad->v_flags = d->v_flags; /* VF_REAL; or complex? */ - ad->v_length = 1; - ad->v_realdata = TMALLOC(double, 1); - *ad->v_realdata = *d->v_realdata; - tfree(whole); + struct dvec *ad; + ad = alloc(struct dvec); + ZERO(ad, struct dvec); + ad->v_name = copy(whole); /* so the name could be data[2] or data[expression] :-) */ + ad->v_type = d->v_type; + ad->v_flags = d->v_flags; /* VF_REAL; or complex? */ + ad->v_length = 1; + ad->v_realdata = TMALLOC(double, 1); + *ad->v_realdata = *d->v_realdata; + tfree(whole); } if (!d && (*word == SPECCHAR)) { @@ -519,16 +501,14 @@ vec_get(const char *vec_name) *s = '\0'; } else { param = NULL; - } - + } if (ft_curckt) { /* - * This is what is done in case of "alter r1 resistance = 1234" + * This is what is done in case of "alter r1 resistance = 1234" * r1 resistance, 0 * if_setparam(ft_curckt->ci_ckt, &dev, param, dv, do_model); */ - /* vv = if_getparam (ft_curckt->ci_ckt, &name, param, 0, 0); */ vv = if_getparam(ft_curckt->ci_ckt, &name, param, 0, 0); if (!vv) { @@ -563,7 +543,7 @@ vec_get(const char *vec_name) * print @pot[pos_node] * To fix this, it is necessary to define: * OPU( "pos_node", POT_QUEST_POS_NODE, IF_REAL,"Positive node of potentiometer"), - * int POTnegNode; // number of negative node of potentiometer (Node_3) + * int POTnegNode; // number of negative node of potentiometer (Node_3) * case POT_QUEST_POS_NODE: * value->rValue = (double)fast->POTposNode; * return OK; @@ -595,7 +575,6 @@ vec_get(const char *vec_name) * used with the parameters of isrc and vsrc */ struct variable *nv; - double *list; list = TMALLOC(double, 1); nv = alloc(struct variable); @@ -646,17 +625,15 @@ vec_get(const char *vec_name) case CP_NUM: fprintf(stdout, "%s=%d\n", nv->va_name, nv->va_num); break; - default: { + default: { fprintf(stderr, "ERROR: enumeration value `CP_BOOL' or `CP_LIST' not handled in vec_get\nAborting...\n"); controlled_exit(EXIT_FAILURE); - } + } } nv = nv->va_next; - if (!nv) break; } - /* To distinguish those does not take anything for print screen to * make a print or M1 @ @ M1 [all] leaving only the correct data * and not the last @@ -664,7 +641,6 @@ vec_get(const char *vec_name) d->v_rlength = 1; } } - tfree(vv->va_name); tfree(vv); /* va: tfree vv->va_name and vv (avoid memory leakages) */ tfree(wd); @@ -672,16 +648,13 @@ vec_get(const char *vec_name) tfree(whole); return d; } - tfree(wd); return sortvecs(d); } - /* Execute the commands for a plot. This is done whenever a plot becomes * the current plot. */ - void plot_docoms(wordlist *wl) { @@ -697,9 +670,7 @@ plot_docoms(wordlist *wl) cp_interactive = inter; } - /* Create a copy of a vector. */ - struct dvec * vec_copy(struct dvec *v) { @@ -743,9 +714,9 @@ vec_copy(struct dvec *v) */ nv->v_rlength = v->v_rlength; - nv->v_outindex = 0; /*XXX???*/ - nv->v_linestyle = 0; /*XXX???*/ - nv->v_color = 0; /*XXX???*/ + nv->v_outindex = 0; /*XXX???*/ + nv->v_linestyle = 0; /*XXX???*/ + nv->v_color = 0; /*XXX???*/ nv->v_defcolor = v->v_defcolor; nv->v_numdims = v->v_numdims; for (i = 0; i < v->v_numdims; i++) @@ -758,11 +729,9 @@ vec_copy(struct dvec *v) return nv; } - /* Create a new plot structure. This just fills in the typename and sets up * the ccom struct. */ - struct plot * plot_alloc(char *name) { @@ -792,16 +761,14 @@ plot_alloc(char *name) return pl; } - /* Stick a new vector in the proper place in the plot list. */ - void vec_new(struct dvec *d) { /* Note that this can't happen. */ if (plot_cur == NULL) { fprintf(cp_err, "vec_new: INTERNAL ERROR: no cur plot\n"); - controlled_exit(1); + controlled_exit(1); } plot_cur->pl_lookup_valid = FALSE; if ((d->v_flags & VF_PERMANENT) && (plot_cur->pl_scale == NULL)) @@ -816,7 +783,6 @@ vec_new(struct dvec *d) d->v_plot->pl_dvecs = d; } - /* Because of the way that all vectors, including temporary vectors, * are linked together under the current plot, they can often be * left lying around. This gets rid of all vectors that don't have @@ -841,13 +807,11 @@ vec_gc(void) vec_free(d); } } - for (pl = plot_list; pl; pl = pl->pl_next) for (d = pl->pl_dvecs; d; d = d->v_next) d->v_link2 = NULL; } - /* Free a dvector. This is sort of a pain because we also have to make sure * that it has been unlinked from its plot structure. If the name of the * vector is NULL, then we have already freed it so don't try again. (This @@ -885,14 +849,14 @@ vec_free_x(struct dvec *v) } if (pl->pl_scale == v) { if (pl->pl_dvecs) - pl->pl_scale = pl->pl_dvecs; /* Random one... */ + pl->pl_scale = pl->pl_dvecs; /* Random one... */ else pl->pl_scale = NULL; } } if (v->v_name) - tfree(v->v_name); + tfree(v->v_name); if (v->v_realdata) tfree(v->v_realdata); if (v->v_compdata) @@ -900,34 +864,29 @@ vec_free_x(struct dvec *v) tfree(v); } - /* * return TRUE if every vector element is zero */ - BOOL vec_iszero(struct dvec *v) { - int i; - - for (; v; v = v->v_link2) - if (isreal(v)) - for (i = 0; i < v->v_length; i++) { + int i; + for (; v; v = v->v_link2) + if (isreal(v)) + for (i = 0; i < v->v_length; i++) { if (v->v_realdata[i] != 0.0) return FALSE; - } + } else for (i = 0; i < v->v_length; i++) { if (realpart(v->v_compdata[i]) != 0.0) return FALSE; if (imagpart(v->v_compdata[i]) != 0.0) return FALSE; - } - - return TRUE; + } + return TRUE; } - /* This is something we do in a few places... Since vectors get copied a lot, * we can't just compare pointers to tell if two vectors are 'really' the same. */ @@ -945,7 +904,7 @@ vec_eq(struct dvec *v1, struct dvec *v2) s2 = vec_basename(v2); if (cieq(s1, s2)) - rtn = TRUE; + rtn = TRUE; else rtn = FALSE; @@ -966,7 +925,7 @@ vec_basename(struct dvec *v) if (strchr(v->v_name, '.')) { if (cieq(v->v_plot->pl_typename, v->v_name)) - (void) strcpy(buf, v->v_name + strlen(v->v_name) + 1); + (void) strcpy(buf, v->v_name + strlen(v->v_name) + 1); else (void) strcpy(buf, v->v_name); } else { @@ -984,7 +943,6 @@ vec_basename(struct dvec *v) return copy(s); } - /* Make a plot the current one. This gets called by cp_usrset() when one * does a 'set curplot = name'. * va: ATTENTION: has unlinked old keyword-class-tree from keywords[CT_VECTOR] @@ -1042,7 +1000,6 @@ plot_new(struct plot *pl) * The data array is replaced with a new one that has the elements * in the proper order. Otherwise the transposition is done in place. */ - void vec_transpose(struct dvec *v) { @@ -1064,7 +1021,6 @@ vec_transpose(struct dvec *v) */ blocksize = dim0*dim1; nummatrices = v->v_length / blocksize; - /* Note: * olda[i,j] is at data[i*dim0+j] * newa[j,i] is at data[j*dim1+i] @@ -1074,7 +1030,6 @@ vec_transpose(struct dvec *v) * though. The formulation below gathers scattered old data into * consecutive new data. */ - if (isreal(v)) { newreal = TMALLOC(double, v->v_length); oldreal = v->v_realdata; @@ -1119,7 +1074,6 @@ vec_transpose(struct dvec *v) * of 1-d vectors, linked together with v_link2. It is here so that plot * can do intelligent things. */ - struct dvec * vec_mkfamily(struct dvec *v) { @@ -1145,14 +1099,11 @@ vec_mkfamily(struct dvec *v) for (i = 0; i < MAXDIMS; i++) count[i] = 0; for (d = vecs, j = 0; d; j++, d = d->v_link2) { - indexstring(count, v->v_numdims - 1, buf2); - (void) sprintf(buf, "%s%s", v->v_name, buf2); d->v_name = copy(buf); d->v_type = v->v_type; d->v_flags = v->v_flags; - d->v_minsignal = v->v_minsignal; d->v_maxsignal = v->v_maxsignal; d->v_gridtype = v->v_gridtype; @@ -1177,13 +1128,10 @@ vec_mkfamily(struct dvec *v) for (d = vecs; d; d = d->v_link2) vec_new(d); - return vecs; } - /* This function will match "op" with "op1", but not "op1" with "op12". */ - bool plot_prefix(char *pre, char *str) { @@ -1198,7 +1146,7 @@ plot_prefix(char *pre, char *str) } if (*pre || (*str && isdigit((int)pre[-1]))) - return FALSE; + return FALSE; else return TRUE; }