bool cp_oddcomm(char *s, wordlist *wl) { FILE *fp; if ((fp = inp_pathopen(s, "r")) != NULL) { char buf[BSIZE_SP]; wordlist *setarg; (void) fclose(fp); (void) sprintf(buf, "argc = %d argv = ( ", wl_length(wl)); while (wl) { (void) strcat(buf, wl->wl_word); (void) strcat(buf, " "); wl = wl->wl_next; } (void) strcat(buf, ")"); setarg = cp_lexer(buf); com_set(setarg); wl_free(setarg); inp_source(s); cp_remvar("argc"); cp_remvar("argv"); return (TRUE); } if (wl && eq(wl->wl_word, "=")) { wordlist *ww = wl_cons(copy(s), wl); com_let(ww); wl_delete_slice(ww, ww->wl_next); return (TRUE); } return (FALSE); }
bool cp_oddcomm(char *s, wordlist *wl) { FILE *fp; char buf[BSIZE_SP]; wordlist ww; if ((fp = inp_pathopen(s, "r"))) { (void) fclose(fp); (void) sprintf(buf, "argc = %d argv = ( ", wl_length(wl)); while (wl) { (void) strcat(buf, wl->wl_word); (void) strcat(buf, " "); wl = wl->wl_next; } (void) strcat(buf, ")"); com_set(cp_lexer(buf)); inp_source(s); cp_remvar("argc"); cp_remvar("argv"); return (TRUE); } else if (wl && eq(wl->wl_word, "=")) { ww.wl_next = wl; wl->wl_prev = &ww; ww.wl_prev = NULL; ww.wl_word = s; com_let(&ww); return (TRUE); } else return (FALSE); }
LRESULT HcpyPlotBW( HWND hwnd) { int bgcolor; if (cp_getvar("hcopypscolor", CP_NUM, &bgcolor)) cp_remvar("hcopypscolor"); com_hardcopy(NULL); return 0; }
//bool //do_measure( // char *what, /*in: analysis type*/ // bool chk_only /*in: TRUE if checking for "autostop", FALSE otherwise*/ //) int do_measure( char *what, /*in: analysis type*/ int chk_only /*in: TRUE if checking for "autostop", FALSE otherwise*/ ) { struct line *meas_card, *meas_results = NULL, *end = NULL, *newcard; char *line, *an_name, *an_type, *resname, *meastype, *str_ptr, out_line[1000]; int ok = 0; int fail; int num_failed = 0; double result = 0; // bool first_time = TRUE; // bool measures_passed; int first_time = TRUE; int measures_passed; wordlist *measure_word_list; int precision = measure_get_precision(); #ifdef HAS_PROGREP if (!chk_only) SetAnalyse("meas", 0); #endif an_name = strdup(what); /* analysis type, e.g. "tran" */ strtolower(an_name); measure_word_list = NULL; measures_passed = TRUE; /* don't allow .meas if batchmode is set by -b and -r rawfile given */ if (ft_batchmode && rflag) { fprintf(cp_err, "\nNo .measure possible in batch mode (-b) with -r rawfile set!\n"); fprintf(cp_err, "Remove rawfile and use .print or .plot or\n"); fprintf(cp_err, "select interactive mode (optionally with .control section) instead.\n\n"); return (measures_passed); } /* don't allow autostop if no .meas commands are given in the input file */ if ((cp_getvar("autostop", CP_BOOL, NULL)) && (ft_curckt->ci_meas == NULL)) { fprintf(cp_err, "\nWarning: No .meas commands found!\n"); fprintf(cp_err, " Option autostop is not available, ignored!\n\n"); cp_remvar("autostop"); return (FALSE); } /* Evaluating the linked list of .meas cards, assembled from the input deck by fcn inp_spsource() in inp.c:575. A typical .meas card will contain: parameter value nameof card .meas(ure) analysis type tran only tran available currently result name myout defined by user measurement type trig|delay|param|expr|avg|mean|max|min|rms|integ(ral)|when The measurement type determines how to continue the .meas card. param|expr are skipped in first pass through .meas cards and are treated in second pass, all others are treated in fcn get_measure2() (com_measure2.c). */ /* first pass through .meas cards: evaluate everything except param|expr */ for (meas_card = ft_curckt->ci_meas; meas_card != NULL; meas_card = meas_card->li_next) { line = meas_card->li_line; txfree(gettok(&line)); /* discard .meas */ an_type = gettok(&line); resname = gettok(&line); meastype = gettok(&line); if (chkAnalysisType(an_type) != TRUE) { if (!chk_only) { fprintf(cp_err, "Error: unrecognized analysis type '%s' for the following .meas statement on line %d:\n", an_type, meas_card->li_linenum); fprintf(cp_err, " %s\n", meas_card->li_line); } txfree(an_type); txfree(resname); txfree(meastype); continue; } /* print header before evaluating first .meas line */ else if (first_time) { first_time = FALSE; if (!chk_only && strcmp(an_type, "tran") == 0) { fprintf(stdout, "\n Measurements for Transient Analysis\n\n"); } } /* skip param|expr measurement types for now -- will be done after other measurements */ if (strncmp(meastype, "param", 5) == 0 || strncmp(meastype, "expr", 4) == 0) continue; /* skip .meas line, if analysis type from line and name of analysis performed differ */ if (strcmp(an_name, an_type) != 0) { txfree(an_type); txfree(resname); txfree(meastype); continue; } /* New way of processing measure statements using common code in fcn get_measure2() (com_measure2.c)*/ out_line[0] = '\0'; measure_word_list = measure_parse_line(meas_card->li_line); if (measure_word_list) { fail = get_measure2(measure_word_list, &result, out_line, chk_only); if (fail) { measures_passed = FALSE; if (!chk_only) fprintf(stderr, " %s failed!\n\n", meas_card->li_line); num_failed++; if (chk_only) { /* added for speed - cleanup last parse and break */ txfree(an_type); txfree(resname); txfree(meastype); wl_free(measure_word_list); break; } } else { if (!chk_only) nupa_add_param(resname, result); } wl_free(measure_word_list); } else { measures_passed = FALSE; num_failed++; } if (!chk_only) { newcard = alloc(struct line); newcard->li_line = strdup(out_line); newcard->li_next = NULL; if (meas_results == NULL) { meas_results = end = newcard; } else { end->li_next = newcard; end = newcard; } } txfree(an_type); txfree(resname); txfree(meastype); } /* end of for loop (first pass through .meas lines) */
/* Set a variable. */ void cp_vset(char *varname, enum cp_types type, void *value) { struct variable *v, *u, *w; 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)) { alreadythere = TRUE; break; } 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 = var_alloc(copy(copyvarname), NULL); v_free = TRUE; } switch (type) { case CP_BOOL: if (* ((bool *) value) == FALSE) { cp_remvar(copyvarname); if (v_free) { tfree(v->va_name); tfree(v); } tfree(copyvarname); return; } else { var_set_bool(v, TRUE); } break; case CP_NUM: var_set_num(v, * (int *) value); break; case CP_REAL: var_set_real(v, * (double *) value); break; case CP_STRING: var_set_string(v, copy((char*) value)); break; case CP_LIST: var_set_vlist(v, (struct variable *) value); break; default: fprintf(cp_err, "cp_vset: Internal Error: bad variable type %d.\n", type); tfree(copyvarname); return; } /* Now, see if there is anything interesting going on. We * recognise these special variables: noglob, nonomatch, history, * echo, noclobber, prompt, and verbose. cp_remvar looks for these * variables too. The host program will get any others. */ if (eq(copyvarname, "noglob")) cp_noglob = TRUE; else if (eq(copyvarname, "nonomatch")) cp_nonomatch = TRUE; else if (eq(copyvarname, "history") && (type == CP_NUM)) cp_maxhistlength = v->va_num; else if (eq(copyvarname, "history") && (type == CP_REAL)) cp_maxhistlength = (int)floor(v->va_real + 0.5); else if (eq(copyvarname, "noclobber")) cp_noclobber = TRUE; else if (eq(varname, "echo")) /*CDHW*/ cp_echo = TRUE; /*CDHW*/ else if (eq(copyvarname, "prompt") && (type == CP_STRING)) cp_promptstring = v->va_string; else if (eq(copyvarname, "ignoreeof")) cp_ignoreeof = TRUE; else if (eq(copyvarname, "cpdebug")) { cp_debug = TRUE; #ifndef CPDEBUG fprintf(cp_err, "Warning: program not compiled with cshpar debug messages\n"); #endif } switch (i = cp_usrset(v, TRUE)) { case US_OK: /* Normal case. */ if (!alreadythere) { v->va_next = variables; variables = v; } else if (v_free) free_struct_variable(v); break; case US_DONTRECORD: /* 'curplot' 'curplotname' 'curplottitle' 'curplotdate' */ /* Do nothing... */ if (alreadythere) { fprintf(cp_err, "cp_vset: Internal Error: " "%s already there, but 'dont record'\n", v->va_name); } if (v_free) free_struct_variable(v); break; case US_READONLY: /* 'plots' and any var in plot_cur->pl_env */ 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: /* variables processed by if_option(ft_curckt->ci_ckt, ...) */ if (alreadythere) { /* somehow it got into the front-end list of variables */ if (w) { w->va_next = v->va_next; } else { variables = v->va_next; } } alreadythere = FALSE; if (ft_curckt) { for (u = ft_curckt->ci_vars; u; u = u->va_next) if (eq(copyvarname, u->va_name)) { alreadythere = TRUE; break; } if (!alreadythere) { v->va_next = ft_curckt->ci_vars; ft_curckt->ci_vars = v; } else { if (u->va_type == CP_STRING) tfree(u->va_string); else if (u->va_type == CP_LIST) tfree(u->va_vlist); u->va_V = v->va_V; u->va_type = v->va_type; /* va_name is the same string */ tfree(u->va_name); u->va_name = v->va_name; /* va_next left unchanged */ tfree(v); } } break; case US_NOSIMVAR: /* variables processed by if_option(NULL, ...) */ /* What do you do? */ free_struct_variable(v); break; default: fprintf(cp_err, "cp_vset: Internal Error: bad US val %d\n", i); break; } tfree(copyvarname); }
void com_quit(wordlist *wl) { int exitcode = EXIT_NORMAL; bool noask = (wl && wl->wl_word && 1 == sscanf(wl->wl_word, "%d", &exitcode)) || (wl && wl->wl_word && cieq(wl->wl_word, "noask")) || cp_getvar("noaskquit", CP_BOOL, NULL); /* update screen and reset terminal */ gr_clean(); cp_ccon(FALSE); /* Make sure the guy really wants to quit. */ if (!ft_nutmeg) if (!noask && !confirm_quit()) return; /* start to clean up the mess */ #ifdef SHARED_MODULE { wordlist all = { "all", NULL, NULL }; wordlist star = { "*", NULL, NULL }; // com_remcirc(NULL); com_destroy(&all); com_unalias(&star); com_undefine(&star); cp_remvar("history"); cp_remvar("noglob"); cp_remvar("brief"); cp_remvar("sourcepath"); cp_remvar("program"); cp_remvar("prompt"); } #endif #ifdef EXPERIMENTAL_CODE /* Destroy CKT when quit. Add by Gong Ding, [email protected] */ if (!ft_nutmeg) { struct circ *cc; for (cc = ft_circuits; cc; cc = cc->ci_next) if (SIMinfo.deleteCircuit) SIMinfo.deleteCircuit(cc->ci_ckt); } #endif #ifdef SHARED_MODULE /* Destroy CKT when quit. */ if (!ft_nutmeg) { while(ft_curckt) com_remcirc(NULL); } #endif DevSwitch(NULL); DevSwitch(NULL); /* then go away */ #ifdef SHARED_MODULE cp_destroy_keywords(); destroy_ivars(); #endif byemesg(); #ifdef SHARED_MODULE destroy_const_plot(); spice_destroy_devices(); #endif #ifdef SHARED_MODULE /* add 1000 to notify that we exit from 'quit' */ controlled_exit(1000 + exitcode); #else exit(exitcode); #endif }