Jspice3
runcoms.c File Reference
#include "spice.h"
#include "ftedefs.h"
#include "fteinp.h"
#include "spfteext.h"
#include "scedio.h"
Include dependency graph for runcoms.c:

Go to the source code of this file.

Functions

void com_scirc (wordlist *wl)
 
void com_pz (wordlist *wl)
 
void com_op (wordlist *wl)
 
void com_dc (wordlist *wl)
 
void com_ac (wordlist *wl)
 
void com_tf (wordlist *wl)
 
void com_tran (wordlist *wl)
 
void com_sens (wordlist *wl)
 
void com_disto (wordlist *wl)
 
void com_noise (wordlist *wl)
 
void ft_dosim (char *what, wordlist *wl)
 
void com_resume (wordlist *wl)
 
void com_run (wordlist *wl)
 
void ft_dorun (char *file)
 
void com_rset (wordlist *wl)
 
bool ft_getOutReq (FILE **fpp, struct plot **plotp, bool *binp, char *name, char *title)
 
void com_free (wordlist *wl)
 

Variables

static FILE * rawfileFp
 
static bool rawfileBinary
 

Function Documentation

void com_ac ( wordlist wl)

Definition at line 112 of file runcoms.c.

115 {
116  ft_dosim("ac", wl);
117  return;
118 }
void ft_dosim(char *what, wordlist *wl)
Definition: runcoms.c:172
void com_dc ( wordlist wl)

Definition at line 102 of file runcoms.c.

105 {
106  ft_dosim("dc", wl);
107  return;
108 }
void ft_dosim(char *what, wordlist *wl)
Definition: runcoms.c:172
void com_disto ( wordlist wl)

Definition at line 152 of file runcoms.c.

155 {
156  ft_dosim("disto", wl);
157  return;
158 }
void ft_dosim(char *what, wordlist *wl)
Definition: runcoms.c:172
void com_free ( wordlist wl)

Definition at line 406 of file runcoms.c.

410 {
411  char s[8];
412  char *xx1 = "Delete all plots (no) ? ";
413  char *xx2 = "Delete current plot (yes) ? ";
414  char *xx3 = "Delete all circuits (no) ? ";
415  char *xx4 = "Delete current circuit (yes) ? ";
416  bool yes = false;
417  bool plots = false;
418  bool circuits = false;
419  bool all = false;
420  wordlist *ww;
421 
422 
423  for (ww = wl; ww; ww = ww->wl_next) {
424  if (ciprefix("p",ww->wl_word)) {
425  plots = true;
426  continue;
427  }
428  if (ciprefix("c",ww->wl_word)) {
429  circuits = true;
430  continue;
431  }
432  if (ciprefix("y",ww->wl_word)) {
433  yes = true;
434  continue;
435  }
436  if (ciprefix("a",ww->wl_word)) {
437  all = true;
438  continue;
439  }
440  }
441  if (!plots && !circuits) {
442  plots = true;
443  circuits = true;
444  }
445  vec_gc();
446 
447  if (plots) {
448  if (!plot_cur || eq(plot_cur->pl_name,"constants"))
449  (void) fprintf(cp_err,"No plot to delete.\n");
450  else {
451  if (all) {
452  if (!yes)
453  (void) SCEDfgets(s,8,cp_in,xx1);
454  if (yes || *s == 'y' || *s == 'Y')
455  while (plot_cur && !eq(plot_cur->pl_name,"constants"))
457  }
458  else {
459  if (!yes)
460  (void) SCEDfgets(s,8,cp_in,xx2);
461  if (yes || *s == 'y' || *s == 'Y' || *s == '\n')
463  }
464  }
465  }
466 
467  if (circuits) {
468  if (!ft_curckt) {
469  (void) fprintf(cp_err,"No circuit to delete.\n");
470  return;
471  }
472  else {
473  if (all) {
474  if (!yes)
475  (void) SCEDfgets(s,8,cp_in,xx3);
476  if (yes || *s == 'y' || *s == 'Y')
477  while (ft_curckt)
478  if_cktclear();
479  }
480  else {
481  if (!yes)
482  (void) SCEDfgets(s,8,cp_in,xx4);
483  if (yes || *s == 'y' || *s == 'Y' || *s == '\n')
484  if_cktclear();
485  }
486  }
487  }
488 }
#define xx1
#define eq(a, b)
Definition: misc.h:29
int ciprefix()
char * pl_name
Definition: ftedata.h:64
Definition: cddefs.h:119
struct plot * plot_cur
Definition: vectors.c:43
void vec_gc()
Definition: vectors.c:681
#define xx4
FILE * cp_err
Definition: help.c:101
void if_cktclear()
Definition: spiceif.c:476
#define NULL
Definition: spdefs.h:121
struct circ * ft_curckt
Definition: main.c:184
char * SCEDfgets(char *s, int n, FILE *fp, char *prompt)
Definition: scedstub.c:41
Definition: cpstd.h:21
#define xx3
Definition: netlist.c:477
struct wordlist * wl_next
Definition: cpstd.h:23
#define xx2
char * wl_word
Definition: cpstd.h:22
FILE * cp_in
Definition: help.c:101
void com_destroy()
void com_noise ( wordlist wl)

Definition at line 162 of file runcoms.c.

165 {
166  ft_dosim("noise", wl);
167  return;
168 }
void ft_dosim(char *what, wordlist *wl)
Definition: runcoms.c:172
void com_op ( wordlist wl)

Definition at line 92 of file runcoms.c.

95 {
96  ft_dosim("op", wl);
97  return;
98 }
void ft_dosim(char *what, wordlist *wl)
Definition: runcoms.c:172
void com_pz ( wordlist wl)

Definition at line 82 of file runcoms.c.

85 {
86  ft_dosim("pz", wl);
87  return;
88 }
void ft_dosim(char *what, wordlist *wl)
Definition: runcoms.c:172
void com_resume ( wordlist wl)

Definition at line 279 of file runcoms.c.

282 {
283  int err;
284 
285  if (!ft_curckt) return;
286  if (ft_curckt->ci_inprogress == false) {
287  fprintf(cp_err, "Note: run starting\n");
288  com_run((wordlist *) NULL);
289  return;
290  }
291  ft_curckt->ci_inprogress = true;
292 
293  err = if_run("resume", (wordlist *) NULL);
294  if (err == 1) {
295  /* The circuit was interrupted somewhere. */
296  DevGrHalt();
297  fprintf(cp_err, "simulation interrupted\n");
298  }
299  else if (err == 2) {
300  DevGrHalt();
301  ft_curckt->ci_inprogress = false;
302  fprintf(cp_err, "simulation aborted\n");
303  }
304  else
305  ft_curckt->ci_inprogress = false;
306 
307  if (rawfileFp && rawfileFp != cp_out) {
308  (void) fclose(rawfileFp);
309  rawfileFp = NULL;
310  }
311  ft_curckt->ci_runonce = true;
312 }
int if_run()
bool ci_inprogress
Definition: ftedefs.h:34
FILE * cp_err
Definition: help.c:101
#define NULL
Definition: spdefs.h:121
struct circ * ft_curckt
Definition: main.c:184
FILE * cp_out
Definition: help.c:101
bool ci_runonce
Definition: ftedefs.h:35
static FILE * rawfileFp
Definition: runcoms.c:26
Definition: cpstd.h:21
void DevGrHalt()
Definition: display.c:151
Definition: mfb.h:383
void com_run(wordlist *wl)
Definition: runcoms.c:316
void com_rset ( wordlist wl)

Definition at line 345 of file runcoms.c.

351 {
352  struct line *deck, *dd;
353  char *filename, *cblock;
354 
355  if (ft_curckt == NULL) {
356  fprintf(cp_err, "Error: there is no circuit loaded.\n");
357  return;
358  }
359 
360  /*
361  (*(ft_sim->deleteTask))(ft_curckt->ci_ckt,ft_curckt->ci_defTask);
362  if_cktfree(ft_curckt->ci_ckt, (char*)ft_curckt->ci_symtab);
363  inp_dodeck(ft_curckt->ci_deck, ft_curckt->ci_name, (wordlist *) NULL,
364  true, ft_curckt->ci_options, ft_curckt->ci_filename);
365  ft_curckt->ci_runonce = false;
366  */
367 
368  dd = ft_curckt->ci_deck;
369  deck = dd->li_actual;
370  dd->li_actual = NULL;
372  filename = ft_curckt->ci_filename;
374  cblock = ft_curckt->ci_contblk;
376  if_cktclear();
377  inp_spdeck(deck,filename);
378  ft_curckt->ci_contblk = cblock;
379  txfree(filename);
380 }
struct line * li_actual
Definition: fteinp.h:19
struct line * ci_origdeck
Definition: ftedefs.h:31
struct line * ci_deck
Definition: ftedefs.h:30
bool inp_spdeck(struct line *deck, char *filename)
Definition: inp.c:463
char * ci_filename
Definition: ftedefs.h:40
char * ci_contblk
Definition: ftedefs.h:29
FILE * cp_err
Definition: help.c:101
Definition: fteinp.h:14
void if_cktclear()
Definition: spiceif.c:476
void txfree()
#define NULL
Definition: spdefs.h:121
struct circ * ft_curckt
Definition: main.c:184
void com_run ( wordlist wl)

Definition at line 316 of file runcoms.c.

321 {
322  ft_dosim("run", wl);
323  return;
324 }
void ft_dosim(char *what, wordlist *wl)
Definition: runcoms.c:172
void com_scirc ( wordlist wl)

Definition at line 31 of file runcoms.c.

34 {
35  struct circ *p;
36  int i, j = 0;
37  char buf[BSIZE_SP];
38  char *xx = "Type the number of the desired circuit: ";
39 
40  if (ft_circuits == NULL) {
41  fprintf(cp_err, "Error: there aren't any circuits loaded.\n");
42  return;
43  }
44  if (wl == NULL) {
45  for (p = ft_circuits; p; p = p->ci_next) {
46  if (ft_curckt == p)
47  out_printf("Current %-4d%s\n", ++j, p->ci_name);
48  else
49  out_printf(" %-4d%s\n", ++j, p->ci_name);
50  }
51  out_printf("\n");
52  (void) SCEDfgets(buf,BSIZE_SP,cp_in,xx);
53 
54  clearerr(cp_in);
55  if ((sscanf(buf, " %d ", &i) != 1) || (i < 0) || (i > j))
56  return;
57  for (p = ft_circuits; --i > 0; p = p->ci_next);
58  }
59  else {
60  for (p = ft_circuits; p; p = p->ci_next)
61  if (ciprefix(wl->wl_word, p->ci_name))
62  break;
63  if (p == NULL) {
64  fprintf(cp_err, "Warning: no such circuit \"%s\"\n",
65  wl->wl_word);
66  return;
67  }
68  out_printf("%s\n", p->ci_name);
69  }
70  if (ft_curckt) {
71  /* Actually this can't be false */
75  }
76  ft_curckt = p;
77  return;
78 }
static char buf[MAXPROMPT]
Definition: arg.c:18
#define BSIZE_SP
Definition: misc.h:19
int ciprefix()
struct circ * ci_next
Definition: ftedefs.h:37
void out_printf()
Definition: ftedefs.h:25
char * ci_devices
Definition: ftedefs.h:39
FILE * p
Definition: proc2mod.c:48
char * ci_nodes
Definition: ftedefs.h:38
FILE * cp_err
Definition: help.c:101
#define CT_DEVNAMES
Definition: fteconst.h:87
struct circ * ft_circuits
Definition: main.c:185
#define NULL
Definition: spdefs.h:121
struct circ * ft_curckt
Definition: main.c:184
char * SCEDfgets(char *s, int n, FILE *fp, char *prompt)
Definition: scedstub.c:41
#define CT_NODENAMES
Definition: fteconst.h:89
char * ci_name
Definition: ftedefs.h:26
char * wl_word
Definition: cpstd.h:22
FILE * cp_in
Definition: help.c:101
void clearerr(FILE *fp)
Definition: libfuncs.c:116
char * cp_kwswitch()
void com_sens ( wordlist wl)

Definition at line 142 of file runcoms.c.

145 {
146  ft_dosim("sens", wl);
147  return;
148 }
void ft_dosim(char *what, wordlist *wl)
Definition: runcoms.c:172
void com_tf ( wordlist wl)

Definition at line 122 of file runcoms.c.

125 {
126  ft_dosim("tf", wl);
127  return;
128 }
void ft_dosim(char *what, wordlist *wl)
Definition: runcoms.c:172
void com_tran ( wordlist wl)

Definition at line 132 of file runcoms.c.

135 {
136  ft_dosim("tran", wl);
137  return;
138 }
void ft_dosim(char *what, wordlist *wl)
Definition: runcoms.c:172
void ft_dorun ( char *  file)

Definition at line 328 of file runcoms.c.

331 {
332  static wordlist wl = { NULL, NULL, NULL } ;
333 
334  wl.wl_word = file;
335  if (file)
336  ft_dosim("run", &wl);
337  else
338  ft_dosim("run", (wordlist *) NULL);
339  return;
340 }
void ft_dosim(char *what, wordlist *wl)
Definition: runcoms.c:172
Definition: library.c:18
#define NULL
Definition: spdefs.h:121
Definition: cpstd.h:21
char * wl_word
Definition: cpstd.h:22
void ft_dosim ( char *  what,
wordlist wl 
)

Definition at line 172 of file runcoms.c.

176 {
177  bool dofile = false;
178  char buf[BSIZE_SP];
179  struct circ *ct;
180  int err = 0;
181  bool ascii = true;
182  extern char *kw_filetype;
183 
184  /* give sced access to loop command */
185  if (eq(what,"loop")) {
186  com_loop(wl);
187  return;
188  }
189 
190  if (ft_servermode || (eq(what, "run") && wl))
191  dofile = true;
192 
193  if (cp_getvar(kw_filetype, VT_STRING, buf)) {
194  if (eq(buf, "binary"))
195  ascii = false;
196 #ifdef notdef
197  else if (eq(buf, "oct"))
198  oct = true;
199 #endif
200  else if (!eq(buf, "ascii"))
201  fprintf(cp_err, "Warning: strange file type %s\n", buf);
202  }
203 
204  if (!ft_curckt) {
205  fprintf(cp_err, "Error: there aren't any circuits loaded.\n");
206  return;
207  }
208  else if (ft_curckt->ci_ckt == NULL) { /* Set noparse? */
209  fprintf(cp_err, "Error: circuit not parsed.\n");
210  return;
211  }
212  for (ct = ft_circuits; ct; ct = ct->ci_next)
213  if (ct->ci_inprogress && (ct != ft_curckt)) {
214  fprintf(cp_err,
215  "Warning: losing old state for circuit '%s'\n", ct->ci_name);
216  ct->ci_inprogress = false;
217  }
218  if (ft_curckt->ci_inprogress && !eq(what, "resume")) {
219  ft_setflag = true;
220  fprintf(cp_err, "Resuming run in progress.\n");
221  com_resume((wordlist *) NULL);
222  return;
223  }
224  if (ft_curckt->ci_runonce)
225  com_rset((wordlist *) NULL);
226 
227  ft_intrpt = false;
228  if (dofile) {
229  if (ft_servermode)
230  rawfileFp = cp_out;
231  else if (!wl || !wl->wl_word || !*wl->wl_word) {
232  if (ft_rawfile)
233  if (!(rawfileFp = fopen(ft_rawfile, "w"))) {
234  perror(wl->wl_word);
235  return;
236  }
237  else
238  rawfileFp = cp_out;
239  }
240  else if (!(rawfileFp = fopen(wl->wl_word, "w"))) {
241  perror(wl->wl_word);
242  return;
243  }
244  rawfileBinary = !ascii;
245  }
246  else {
247  rawfileFp = NULL;
248  }
249 
250  ft_curckt->ci_inprogress = true;
251  err = if_run(what, wl);
252  if (err == 1) {
253  /* The circuit was interrupted somewhere. */
254  DevGrHalt();
255  fprintf(cp_err, "%s: simulation interrupted\n", what);
256  }
257  else if (err == 2) {
258  DevGrHalt();
259  ft_curckt->ci_inprogress = false;
260  fprintf(cp_err, "%s: simulation aborted\n", what);
261  }
262  else
263  ft_curckt->ci_inprogress = false;
264 
265  if (rawfileFp && rawfileFp != cp_out) {
266  (void) fclose(rawfileFp);
267  rawfileFp = NULL;
268  }
269  ft_curckt->ci_runonce = true;
270 }
bool ft_intrpt
Definition: main.c:47
static char buf[MAXPROMPT]
Definition: arg.c:18
#define BSIZE_SP
Definition: misc.h:19
#define eq(a, b)
Definition: misc.h:29
struct circ * ci_next
Definition: ftedefs.h:37
bool cp_getvar(char *n, int t, char *r)
Definition: help.c:184
int if_run()
Definition: ftedefs.h:25
bool ci_inprogress
Definition: ftedefs.h:34
char * ci_ckt
Definition: ftedefs.h:27
bool ft_setflag
Definition: main.c:48
char * kw_filetype
Definition: options.c:355
void com_rset(wordlist *wl)
Definition: runcoms.c:345
char * ft_rawfile
Definition: main.c:39
FILE * cp_err
Definition: help.c:101
struct circ * ft_circuits
Definition: main.c:185
#define NULL
Definition: spdefs.h:121
struct circ * ft_curckt
Definition: main.c:184
FILE * cp_out
Definition: help.c:101
bool ft_servermode
Definition: main.c:46
#define VT_STRING
Definition: cpstd.h:63
void perror()
bool ci_runonce
Definition: ftedefs.h:35
static FILE * rawfileFp
Definition: runcoms.c:26
Definition: cpstd.h:21
void DevGrHalt()
Definition: display.c:151
char * ci_name
Definition: ftedefs.h:26
Definition: mfb.h:383
char * wl_word
Definition: cpstd.h:22
void com_resume(wordlist *wl)
Definition: runcoms.c:279
void com_loop()
static bool rawfileBinary
Definition: runcoms.c:27
bool ft_getOutReq ( FILE **  fpp,
struct plot **  plotp,
bool binp,
char *  name,
char *  title 
)

Definition at line 385 of file runcoms.c.

391 {
392  /*struct plot *pl;*/
393 
394  if (rawfileFp) {
395  *fpp = rawfileFp;
396  *binp = rawfileBinary;
397  return (true);
398  }
399  else {
400  return (false);
401  }
402 }
static FILE * rawfileFp
Definition: runcoms.c:26
static bool rawfileBinary
Definition: runcoms.c:27

Variable Documentation

bool rawfileBinary
static

Definition at line 27 of file runcoms.c.

FILE* rawfileFp
static

Definition at line 26 of file runcoms.c.