Jspice3
device.c
Go to the documentation of this file.
1 /***************************************************************************
2 JSPICE3 adaptation of Spice3e2 - Copyright (c) Stephen R. Whiteley 1992
3 Copyright 1990 Regents of the University of California. All rights reserved.
4 Authors: 1986 Wayne A. Christopher
5  1992 Stephen R. Whiteley
6 ****************************************************************************/
7 
8 /*
9  * Routines to query and alter devices.
10  */
11 
12 #include "spice.h"
13 #include "ftedefs.h"
14 #include "spfteext.h"
15 
16 #ifdef __STDC__
17 static wordlist *devexpand(char*);
18 static void parseline(wordlist*,wordlist**,wordlist**);
19 #else
20 static wordlist *devexpand();
21 static void parseline();
22 #endif
23 
24 
25 /* Display various device parameters. The syntax of this command is
26  * show [devicelist] [, parmlist]
27  * where devicelist can be "all", device names, or glob-matched subnames
28  * using wildcards *,?,[]. The parms are names of parameters that should
29  * be valid for all the named devices, or "all". Defaults to all, all.
30  */
31 
32 void
34 
35 wordlist *wl;
36 {
37  wordlist *devs, *parms, *keyword;
38  wordlist *tw, *pw, *kw, *ww, *w0;
39  struct variable *v, *vv;
40  int len;
41  char *neww;
42 
43  if (!ft_curckt) {
44  fprintf(cp_err, "Error: no circuit loaded\n");
45  return;
46  }
47  parseline(wl,&devs,&parms);
48 
49  if (parms == NULL) {
50  parms = alloc(wordlist);
51  parms->wl_word = copy("all");
52  }
53 
54  if (devs == NULL)
56 
57  wl_sort(devs);
58  out_init();
59 
60  for (tw = devs; tw; tw = tw->wl_next) {
61  out_printf("\n%s:\n", tw->wl_word);
62 
63  for (pw = parms; pw; pw = pw->wl_next) {
64 
65  keyword = NULL;
66  neww = copy(tw->wl_word); /* address put in symtab */
67  vv = if_getparam((char*)ft_curckt->ci_ckt, &neww,
68  pw->wl_word, 0, &keyword);
69 
70  for (v = vv, kw = keyword; v; v = v->va_next, kw = kw->wl_next) {
71  len = 14 + strlen(kw->wl_word);
72  out_printf(" %s =",kw->wl_word);
73  w0 = cp_varwl(v);
74  for (ww = w0; ww; ww = ww->wl_next) {
75  len += strlen(ww->wl_word) + 1;
76  out_printf(" %s", ww->wl_word);
77  }
78  wl_free(w0);
79 
80  for (; len < 40; len++)
81  out_send(" ");
82  out_printf(" %s\n",v->va_name);
83  }
84  wl_free(keyword);
85  va_free(vv);
86  }
87  }
88  out_send("\n");
89 
90  wl_free(devs);
91  wl_free(parms);
92 }
93 
94 
95 /* Alter a device parameter. The syntax here is
96  * alter devicelist : parmname value [parmname value] ...
97  * where devicelist is as above, parmname is the name of the desired parm
98  * and value is a string, numeric, or bool value.
99  */
100 
101 void
103 
104 wordlist *wl;
105 {
106  wordlist *devs, *parms, *tw;
107 
108  if (!ft_curckt) {
109  fprintf(cp_err, "Error: no circuit loaded\n");
110  return;
111  }
112 
113  parseline(wl,&devs,&parms);
114 
115  /*
116  for (tw = devs; tw; tw = tw->wl_next)
117  if_alter(tw->wl_word,parms);
118  */
119 
120  wl_free(devs);
121  wl_free(parms);
122 }
123 
124 
125 static void
127 wordlist *line,**dlist,**plist;
128 {
129  wordlist *tw, *tl, *t0;
130  char *c = NULL;
131 
132  *plist = NULL;
133  *dlist = NULL;
134  if (!line)
135  return;
136  tl = tw = wl_copy(line);
137 
138  while (tw) {
139  if ((c = strchr(tw->wl_word,',')) != NULL) break;
140  tw = tw->wl_next;
141  }
142  if (c) {
143  if (*(c+1) == '\0') {
144  *c = '\0';
145  *plist = tw->wl_next;
146  if (tw->wl_next)
147  tw->wl_next->wl_prev = NULL;
148  tw->wl_next = NULL;
149  if (*tw->wl_word == '\0') {
150  if (tw->wl_prev)
151  tw->wl_prev->wl_next = NULL;
152  if (tl == tw)
153  tl = NULL;
154  tfree(tw);
155  }
156  }
157  else if (c == tw->wl_word) {
158  tw->wl_word = copy(c+1);
159  tfree(c);
160  *plist = tw;
161  if (tw->wl_prev)
162  tw->wl_prev->wl_next = NULL;
163  tw->wl_prev = NULL;
164  }
165  else {
166  *plist = alloc(wordlist);
167  (*plist)->wl_word = copy(c+1);
168  (*plist)->wl_next = tw->wl_next;
169  if (tw->wl_next)
170  tw->wl_next->wl_prev = *plist;
171  *c = '\0';
172  tw->wl_next = NULL;
173  }
174  }
175 
176  /* Now expand the devicelist... */
177  t0 = tl;
178  for (tw = NULL; tl; tl = tl->wl_next) {
179  inp_casefix(tl->wl_word);
180  tw = wl_append(tw, devexpand(tl->wl_word));
181  }
182  wl_free(t0);
183  *dlist = tw;
184 }
185 
186 
187 /* Given a device name, possibly with wildcards, return the matches. */
188 
189 static wordlist *
191 
192 char *name;
193 {
194  wordlist *wl, *d, *devices, *tw;
195 
196  if (strchr(name, '*') || strchr(name, '[') || strchr(name, '?')) {
197  devices = cp_cctowl(ft_curckt->ci_devices);
198  d = devices;
199  for (wl = NULL; d; d = d->wl_next) {
200  if (cp_globmatch(name, d->wl_word)) {
201  tw = alloc(struct wordlist);
202  if (wl) {
203  wl->wl_prev = tw;
204  tw->wl_next = wl;
205  wl = tw;
206  }
207  else
208  wl = tw;
209  wl->wl_word = copy(d->wl_word);
210  }
211  }
212  wl_free(devices);
213  }
214  else if (eq(name, "all")) {
216  }
217  else {
218  wl = alloc(struct wordlist);
219  wl->wl_word = copy(name);
220  }
221  wl_sort(wl);
222  return (wl);
223 }
224 
#define eq(a, b)
Definition: misc.h:29
void inp_casefix()
void com_alter(wordlist *wl)
Definition: device.c:102
static void parseline()
void out_printf()
char * ci_devices
Definition: ftedefs.h:39
void com_show(wordlist *wl)
Definition: device.c:33
char * ci_ckt
Definition: ftedefs.h:27
Definition: library.c:18
struct variable *(* if_getparam)()
Definition: main.c:53
#define alloc(type)
Definition: cdmacs.h:21
void va_free()
char * copy()
void wl_free()
FILE * cp_err
Definition: help.c:101
Definition: fteinp.h:14
struct wordlist * wl_prev
Definition: cpstd.h:24
char * va_name
Definition: cpstd.h:43
bool cp_globmatch()
Definition: cddefs.h:237
#define tfree(x)
Definition: cdmacs.h:22
Definition: polyclip.c:32
#define NULL
Definition: spdefs.h:121
struct circ * ft_curckt
Definition: main.c:184
wordlist * wl_append()
Definition: cpstd.h:21
Definition: cddefs.h:177
static wordlist * devexpand()
Definition: netlist.c:477
void out_send()
struct wordlist * wl_next
Definition: cpstd.h:23
char * wl_word
Definition: cpstd.h:22
void wl_sort()
wordlist * cp_varwl()
wordlist * cp_cctowl()
struct variable * va_next
Definition: cpstd.h:51
Definition: sced.h:130
Definition: cpstd.h:41
void out_init()
Definition: output.c:128
wordlist * wl_copy()