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

Go to the source code of this file.

Functions

void nutcom_edit (wordlist *wl)
 
bool inp_edit (char *filename)
 
void inp_nutsource (FILE *fp, bool comfile, char *filename)
 
void nutcom_source (wordlist *wl)
 

Function Documentation

bool inp_edit ( char *  filename)

Definition at line 47 of file nutinp.c.

50 {
51  char buf[BSIZE_SP], buf2[BSIZE_SP], *editor;
52  extern char *kw_editor;
53 
54  if (cp_getvar(kw_editor, VT_STRING, buf2)) {
55  editor = buf2;
56  }
57  else {
58  if (!(editor = getenv("EDITOR"))) {
59  if (Def_Editor && *Def_Editor)
60  editor = Def_Editor;
61  else
62  editor = "/usr/ucb/vi";
63  }
64  }
65  (void) sprintf(buf, "%s %s", editor, filename);
66  /* Note: probably don't want this if editor creates its
67  * own window.
68  */
69  return (DevXterm(buf));
70 }
static char buf[MAXPROMPT]
Definition: arg.c:18
#define BSIZE_SP
Definition: misc.h:19
bool cp_getvar(char *n, int t, char *r)
Definition: help.c:184
int DevXterm()
char * getenv(char *c)
Definition: libfuncs.c:106
char * Def_Editor
#define VT_STRING
Definition: cpstd.h:63
char * kw_editor
Definition: options.c:354
void inp_nutsource ( FILE *  fp,
bool  comfile,
char *  filename 
)

Definition at line 138 of file nutinp.c.

143 {
144  struct line *deck, *dd;
145  bool commands = comfile;
146  FILE *lastin, *lastout, *lasterr;
147 
148  inp_readall(fp, &deck, NULL);
149 
150  if (!deck)
151  return;
152 
153  if (!deck->li_next)
154  fprintf(cp_err, "Warning: no cards in deck...\n");
155 
156  /* Now save the IO context and start a new control set... After
157  * we are done with the source we'll put the old file descriptors
158  * back. I guess we could use a FILE stack, but since this routine
159  * is recursive anyway...
160  */
161  lastin = cp_curin;
162  lastout = cp_curout;
163  lasterr = cp_curerr;
164  cp_curin = cp_in;
165  cp_curout = cp_out;
166  cp_curerr = cp_err;
167  cp_pushcontrol();
168 
169  for (dd = deck->li_next; dd; dd = dd->li_next) {
170  if ((dd->li_line[0] == '*') && (dd->li_line[1] != '#')) {
171  continue;
172  }
173  if (!*dd->li_line ||
174  (commands && (*dd->li_line == '#' ||
175  *dd->li_line == '*'))) {
176  /* So blank lines in com files don't get
177  * considered as circuits.
178  * Also kill comments in commands.
179  */
180  continue;
181  }
182  if (ciprefix(".control", dd->li_line)) {
183  if (!comfile) {
184  if (commands)
185  fprintf(cp_err,
186  "Warning: redundant .control card\n");
187  else
188  commands = true;
189  }
190  continue;
191  }
192  if (ciprefix(".endc", dd->li_line)) {
193  if (!comfile) {
194  if (commands)
195  commands = false;
196  else
197  fprintf(cp_err,
198  "Warning: misplaced .endc card\n");
199  }
200  continue;
201  }
202  if (commands || prefix("*#", dd->li_line)) {
203  if (prefix("*#", dd->li_line))
204  (void) cp_evloop(dd->li_line + 2);
205  else
206  (void) cp_evloop(dd->li_line);
207  }
208  }
209  inp_deckfree(deck);
210 
211  /* Now reset everything. Pop the control stack, and fix up the IO
212  * as it was before the source.
213  */
214  cp_popcontrol();
215  cp_curin = lastin;
216  cp_curout = lastout;
217  cp_curerr = lasterr;
218  return;
219 }
int ciprefix()
void inp_readall()
#define prefix(x, y)
Definition: readhelp.c:39
FILE * cp_curerr
Definition: cshpar.c:77
FILE * cp_curin
Definition: cshpar.c:75
FILE * cp_err
Definition: help.c:101
Definition: fteinp.h:14
#define NULL
Definition: spdefs.h:121
FILE * cp_out
Definition: help.c:101
char * li_line
Definition: fteinp.h:16
struct line * li_next
Definition: fteinp.h:18
void inp_deckfree()
static struct ccom * commands
Definition: complete.c:94
void cp_pushcontrol()
Definition: front.c:1066
void cp_popcontrol()
Definition: front.c:1051
int cp_evloop()
FILE * cp_curout
Definition: cshpar.c:76
FILE * cp_in
Definition: help.c:101
void nutcom_edit ( wordlist wl)

Definition at line 17 of file nutinp.c.

20 {
21  int inter;
22 
23  inter = cp_interactive;
24  cp_interactive = false;
25 
26  if (SCEDactive()) {
27  ShowPrompt("Exit sced to edit.");
28  return;
29  }
30  for ( ; wl; wl = wl->wl_next) {
31 
32  /* ignore -r, -n */
33  if (eq(wl->wl_word,"-n"))
34  continue;
35 
36  if (eq(wl->wl_word,"-r"))
37  continue;
38 
39  (void)inp_edit(wl->wl_word);
40  }
41  cp_interactive = inter;
42  return;
43 }
#define eq(a, b)
Definition: misc.h:29
bool cp_interactive
Definition: help.c:100
bool inp_edit(char *filename)
Definition: nutinp.c:47
struct wordlist * wl_next
Definition: cpstd.h:23
char * wl_word
Definition: cpstd.h:22
enum Active SCEDactive()
Definition: scedstub.c:63
void ShowPrompt(char *str)
Definition: scedstub.c:71
void nutcom_source ( wordlist wl)

Definition at line 223 of file nutinp.c.

227 {
228  FILE *fp, *tp;
229  char buf[BSIZE_SP];
230  bool inter;
231  char *tempfile = NULL, *fname;
232  wordlist *owl, *ww, *wn;
233  int i;
234 
235  owl = wl;
236  wl = wl_copy(wl);
237  ww = wl;
238  for (; wl; wl = wn) {
239  wn = wl->wl_next;
240  if (*wl->wl_word != '-')
241  continue;
242  if (!strchr(wl->wl_word,'n') &&
243  !strchr(wl->wl_word,'c') &&
244  !strchr(wl->wl_word,'r'))
245  continue;
246  if (wl->wl_prev)
247  wl->wl_prev->wl_next = wl->wl_next;
248  if (wl->wl_next)
249  wl->wl_next->wl_prev = wl->wl_prev;
250  txfree(wl->wl_word);
251  if (ww == wl)
252  ww = wl->wl_next;
253  txfree((char*)wl);
254  }
255  wl = ww;
256 
257  inter = cp_interactive;
258  cp_interactive = false;
259  if (wl && wl->wl_next) {
260  /* There are several files -- put them into a temp file */
261  tempfile = smktemp("sp");
262  if (!(fp = inp_pathopen(tempfile, "w+"))) {
263  perror(tempfile);
264  goto done;
265  }
266  while (wl) {
267  if (!(tp = inp_pathopen(wl->wl_word, "r"))) {
268  perror(wl->wl_word);
269  goto done;
270  }
271  while ((i = fread(buf, 1, BSIZE_SP, tp)) > 0)
272  (void) fwrite(buf, 1, i, fp);
273  (void) fclose(tp);
274  wl = wl->wl_next;
275  }
276  (void) fseek(fp, (long) 0, 0);
277  }
278  else {
279  if (wl) {
280  if (!(fp = inp_pathopen(wl->wl_word, "r"))) {
281  perror(wl->wl_word);
282  goto done;
283  }
284  }
285  else
286  fp = stdin;
287  }
288 
289  if (tempfile)
290  fname = NULL;
291  else {
292  if (wl)
293  fname = wl->wl_word;
294  else
295  fname = NULL;
296  }
297 
298  /* Don't print the title if this is a .spiceinit file. */
299  if (substring(".spiceinit", owl->wl_word) ||
300  substring("spice.rc", owl->wl_word))
301  inp_nutsource(fp, true, fname);
302  else
303  inp_nutsource(fp,false,fname);
304  if (fp != stdin)
305  (void) fclose(fp);
306 
307 done:
308  cp_interactive = inter;
309 
310  if (tempfile) {
311  (void) unlink(tempfile);
312  txfree(tempfile);
313  }
314  wl_free(ww);
315  return;
316 }
static char buf[MAXPROMPT]
Definition: arg.c:18
#define BSIZE_SP
Definition: misc.h:19
void inp_nutsource(FILE *fp, bool comfile, char *filename)
Definition: nutinp.c:138
void wl_free()
int substring()
struct wordlist * wl_prev
Definition: cpstd.h:24
bool cp_interactive
Definition: help.c:100
void txfree()
#define NULL
Definition: spdefs.h:121
FILE * inp_pathopen()
int unlink(char *fn)
Definition: libfuncs.c:96
char * smktemp()
void perror()
Definition: cpstd.h:21
Definition: netlist.c:477
struct wordlist * wl_next
Definition: cpstd.h:23
char * wl_word
Definition: cpstd.h:22
wordlist * wl_copy()