Jspice3
misccoms.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: 1985 Wayne A. Christopher
5  1992 Stephen R. Whiteley
6 ****************************************************************************/
7 
8 #include "spice.h"
9 #include "ftedefs.h"
10 #include "ftehelp.h"
11 #include "hlpdefs.h"
12 #include "scedio.h"
13 
14 #ifdef __STDC__
15 static int hcomp(struct comm**,struct comm**);
16 static void byemesg(void);
17 #else
18 static int hcomp();
19 static void byemesg();
20 #endif
21 
22 #define SHORTHELPMSG "For a complete description of %s read the %s manual.\n"
23 
24 /* Some C compilers can't handle strings longer than 256 characters */
25 
26 #define AHELPMESG1 \
27 "For a complete description of %s read the %s manual.\n\
28 There are short introductions to both Spice 3 and Nutmeg available, in\n\
29 addition to the SPICE User's Guide and the manual pages. If you don't\n"
30 
31 #define AHELPMESG2 \
32 "have these documents ask your system manager for them. Below is a short\n\
33 list of useful commands -- for a list of all commands type \"help all\",\n\
34 and for a short description of \"command\", type \"help command\".\n"
35 
36 
37 void
39 
40 wordlist *wl;
41 {
42  struct comm *c;
43  struct comm *ccc[512]; /* Should be enough. */
44  int numcoms, i;
45  bool allflag = false, tmpmm;
46 
47  if (wl && eq(wl->wl_word, "all")) {
48  allflag = true;
49  wl = NULL; /* XXX Probably right */
50  }
51 
52  /* We want to use more mode whether "moremode" is set or not. */
53  tmpmm = out_moremode;
54  out_moremode = true;
55  out_init();
56  out_moremode = tmpmm;
57  if (wl == NULL) {
58  if (allflag)
60  else {
63  }
64 
65  /* Sort the commands */
66  for (numcoms = 0; cp_coms[numcoms].co_func != NULL; numcoms++)
67  ccc[numcoms] = &cp_coms[numcoms];
68  qsort((char *) ccc, numcoms, sizeof (struct comm *),
69 #ifdef __STDC__
70  (int(*)(const void*,const void*))hcomp);
71 #else
72  hcomp);
73 #endif
74 
75  for (i = 0; i < numcoms; i++) {
76  if ((ccc[i]->co_spiceonly && ft_nutmeg) ||
77  (ccc[i]->co_help == NULL) ||
78  (!allflag && !ccc[i]->co_major))
79  continue;
80  out_printf("%s ", ccc[i]->co_comname);
81  out_printf(ccc[i]->co_help, cp_program);
82  out_send("\n");
83  }
84  }
85  else {
86  while (wl != NULL) {
87  for (c = &cp_coms[0]; c->co_func != NULL; c++)
88  if (eq(wl->wl_word, c->co_comname)) {
89  out_printf("%s ", c->co_comname);
91  if (c->co_spiceonly && ft_nutmeg)
92  out_send(
93  " (Not available in nutmeg)");
94  out_send("\n");
95  break;
96  }
97  if (c->co_func == NULL) {
98  /* See if this is aliased. */
99  struct alias *al;
100 
101  for (al = cp_aliases; al; al = al->al_next)
102  if (eq(al->al_name, wl->wl_word))
103  break;
104  if (al == NULL)
105  out_printf("Sorry, no help for %s.\n",
106  wl->wl_word);
107  else {
108  out_printf("%s is aliased to ",
109  wl->wl_word);
110  /* Minor badness here... */
111  out_wlprint(al->al_text);
112  out_send("\n");
113  }
114  }
115  wl = wl->wl_next;
116  }
117  }
118  out_send("\n");
119  return;
120 }
121 
122 
123 void
125 
126 wordlist *wl;
127 {
128 
129  int i, n;
130  /* assert: number of commands must be less than 512 */
131  struct comm *cc[512];
132  int env = 0;
133  struct comm *com;
134  int level;
135  char slevel[256];
136  extern char *kw_level;
137 
138  if (wl) {
139  com_help(wl);
140  return;
141  }
142 
143  out_init();
144 
145  /* determine environment */
146  if (plot_list->pl_next) { /* plots load */
147  env |= E_HASPLOTS;
148  } else {
149  env |= E_NOPLOTS;
150  }
151 
152  /* determine level */
153  if (cp_getvar(kw_level, VT_STRING, slevel)) {
154  switch (*slevel) {
155  case 'b': level = 1;
156  break;
157  case 'i': level = 2;
158  break;
159  case 'a': level = 4;
160  break;
161  default: level = 1;
162  break;
163  }
164  } else {
165  level = 1;
166  }
167 
168  /* Some C compilers can't handle strings longer than 256 characters */
171 
172  /* sort the commands */
173  for (n = 0; cp_coms[n].co_func != (void (*)()) NULL; n++) {
174  cc[n] = &cp_coms[n];
175  }
176  qsort((char *) cc, n, sizeof(struct comm *),
177 #ifdef __STDC__
178  (int(*)(const void*,const void*))hcomp);
179 #else
180  hcomp);
181 #endif
182 
183  /* filter the commands */
184  for (i=0; i< n; i++) {
185  com = cc[i];
186  if ((com->co_env < (level << 13)) && (!(com->co_env & 4095) ||
187  (env & com->co_env))) {
188  if ((com->co_spiceonly && ft_nutmeg) ||
189  (com->co_help == (char *) NULL)) {
190  continue;
191  }
192  out_printf("%s ", com->co_comname);
194  out_send("\n");
195  }
196  }
197 
198  out_send("\n");
199 
200  return;
201 
202 }
203 
204 void
206  wordlist *wl;
207 {
208  char *opath, *path = Help_Path, buf[BSIZE_SP];
209  int i;
210 
211  if (cp_getvar("helppath", VT_STRING, buf))
212  path = buf;
213  path = cp_tildexpand(opath = path);
214  if (path == NULL || *path == '\0') {
215  fprintf(cp_err, "Note: can't find help dir %s\n", opath);
216  fprintf(cp_err, "Defaulting to old help.\n\n");
217  com_help(wl);
218  return;
219  }
220  if (cp_getvar("helpinitxpos", VT_NUM, (char *) &i))
221  hlp_initxpos = i;
222  if (cp_getvar("helpinitypos", VT_NUM, (char *) &i))
223  hlp_initypos = i;
224  hlp_main(path, wl);
225  tfree(path);
226  return;
227 }
228 
229 
230 static int
231 hcomp(c1, c2)
232 
233 struct comm **c1, **c2;
234 {
235  return (strcmp((*c1)->co_comname, (*c2)->co_comname));
236 }
237 
238 
239 /* ARGSUSED */
240 void
242 
243 wordlist *wl;
244 {
245  struct circ *cc;
246  struct plot *pl;
247  int ncc = 0, npl = 0;
248  char buf[64];
249  char *zz = "Are you sure you want to quit (yes)? ";
250  bool noask;
251 
252  (void) cp_getvar("noaskquit", VT_BOOL, (char *) &noask);
253  cp_ccon(false);
254 
255  /* Make sure the guy really wants to quit. */
256  if (!ft_nutmeg && !noask) {
257  for (cc = ft_circuits; cc; cc = cc->ci_next)
258  if (cc->ci_inprogress)
259  ncc++;
260  for (pl = plot_list; pl; pl = pl->pl_next)
261  if (!pl->pl_written && pl->pl_hashtab)
262  npl++;
263  if (ncc || npl) {
264  out_init();
265  out_printf("Warning: ");
266  if (ncc) {
267  out_printf(
268  "the following simulation%s still in progress:\n",
269  (ncc > 1) ? "s are" : " is");
270  for (cc = ft_circuits; cc; cc = cc->ci_next)
271  if (cc->ci_inprogress)
272  out_printf("\t%s\n", cc->ci_name);
273  }
274  if (npl) {
275  if (ncc)
276  out_printf("and ");
277  out_printf(
278  "the following plot%s been saved:\n",
279  (npl > 1) ? "s haven't" : " hasn't");
280  for (pl = plot_list; pl; pl = pl->pl_next)
281  if (!pl->pl_written && pl->pl_hashtab)
282  out_printf("%s\t%s, %s\n",
283  pl->pl_typename,
284  pl->pl_title,
285  pl->pl_name);
286  }
287  (void) SCEDfgets(buf,BSIZE_SP,cp_in,zz);
288 
289  if ((*buf == 'y') || (*buf == 'Y') || (*buf == '\n'))
290  byemesg();
291  else {
292  return;
293  }
294  }
295  else
296  byemesg();
297  }
298  else
299  byemesg();
300 
301  exit(EXIT_NORMAL);
302  /* NOTREACHED */
303 }
304 
305 
306 #ifdef SYSTEM_MAIL
307 
308 /* ARGSUSED */
309 void
310 com_bug(wl)
311 
312 wordlist *wl;
313 {
314  char buf[BSIZE_SP];
315 
316  if (!Bug_Addr || !*Bug_Addr) {
317  fprintf(cp_err, "Error: No address to send bug reports to.\n");
318  return;
319  }
320  if (SCEDactive()) {
321  ShowPrompt("Exit sced to send bug report.");
322  return;
323  }
324 
325  fprintf(cp_out, "Calling the mail program . . .(sending to %s)\n\n",
326  Bug_Addr);
327  fprintf(cp_out,
328  "Please include the OS version number and machine architecture.\n");
329  fprintf(cp_out,
330  "If the problem is with a specific circuit, please include the\n");
331  fprintf(cp_out, "input file.\n");
332 
333  (void) sprintf(buf, SYSTEM_MAIL, ft_sim->simulator,
335  (void) system(buf);
336  fprintf(cp_out, "Bug report sent. Thank you.\n");
337  return;
338 }
339 
340 #else
341 
342 /* ARGSUSED */
343 void
345 
346 wordlist *wl;
347 {
348  char buf[BSIZE_SP], *s;
349  FILE *fp;
350 
351  if (SCEDactive()) {
352  ShowPrompt("Exit sced to send bug report.");
353  return;
354  }
355  if (News_File && *News_File) {
356  strcpy(buf,News_File);
357  s = strrchr(buf,DIR_TERM);
358  if (s != NULL) {
359  s++;
360  strcpy(s,"bug.log");
361  if (access(buf,0)) {
362  if ((fp = fopen(buf,"w")) != NULL) {
363  fprintf(fp,"SPICE and NUTMEG bug log file: %s\n",buf);
364  fclose(fp);
365  }
366  }
367  inp_edit(buf);
368  }
369  }
370 }
371 
372 #endif
373 
374 void
376 
377 wordlist *wl;
378 {
379  char *s;
380 
381  out_init();
382  if (!wl) {
383  out_printf("Program: %s, version: %s\n", ft_sim->simulator,
384  ft_sim->version);
385  if (Spice_Notice && *Spice_Notice)
386  out_printf("\t%s\n", Spice_Notice);
388  out_printf("Date built: %s\n", Spice_Build_Date);
389  }
390  else {
391  s = wl_flatten(wl);
392  if (!eq(ft_sim->version, s)) {
393  fprintf(stderr,
394  "Note: rawfile is version %s (current version is %s)\n",
395  wl->wl_word, ft_sim->version);
396  }
397  tfree(s);
398  }
399  return;
400 }
401 
402 
403 static void
405 {
406  out_init();
407  out_printf("%s-%s done\n", ft_sim->simulator, ft_sim->version);
408  return;
409 }
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
Definition: subckt.c:18
void com_ahelp(wordlist *wl)
Definition: misccoms.c:124
bool cp_getvar(char *n, int t, char *r)
Definition: help.c:184
void out_wlprint()
IFsimulator * ft_sim
Definition: main.c:111
char * pl_typename
Definition: ftedata.h:65
char * cp_tildexpand()
static int hcomp()
#define E_HASPLOTS
Definition: ftehelp.h:10
char * pl_title
Definition: ftedata.h:62
void out_printf()
char * strcpy()
char * pl_name
Definition: ftedata.h:64
Definition: ftedefs.h:25
Definition: cddefs.h:119
char * Help_Path
Definition: help.c:104
int system(char *str)
Definition: libfuncs.c:85
struct alias * al_next
Definition: cpdefs.h:60
char * kw_level
Definition: options.c:372
#define SHORTHELPMSG
Definition: misccoms.c:22
#define EXIT_NORMAL
Definition: misc.h:25
char * al_name
Definition: cpdefs.h:58
bool ci_inprogress
Definition: ftedefs.h:34
struct alias * cp_aliases
Definition: alias.c:22
void com_ghelp(wordlist *wl)
Definition: misccoms.c:205
Definition: ftedata.h:61
Definition: library.c:18
char * simulator
Definition: ifsim.h:357
struct comm * cp_coms
Definition: main.c:163
Definition: cpdefs.h:20
void hlp_main()
void * pl_hashtab
Definition: ftedata.h:66
bool co_spiceonly
Definition: cpdefs.h:24
void com_version(wordlist *wl)
Definition: misccoms.c:375
FILE * cp_err
Definition: help.c:101
#define AHELPMESG1
Definition: misccoms.c:26
struct circ * ft_circuits
Definition: main.c:185
wordlist * al_text
Definition: cpdefs.h:59
#define tfree(x)
Definition: cdmacs.h:22
char * News_File
Definition: ivars.c:12
#define NULL
Definition: spdefs.h:121
char * co_help
Definition: cpdefs.h:31
char * Bug_Addr
FILE * cp_out
Definition: help.c:101
bool pl_written
Definition: ftedata.h:73
#define VT_NUM
Definition: cpstd.h:61
bool co_major
Definition: cpdefs.h:25
char * cp_program
Definition: main.c:43
int access(char *pth, int m)
Definition: libfuncs.c:75
char * SCEDfgets(char *s, int n, FILE *fp, char *prompt)
Definition: scedstub.c:41
static double c
Definition: vectors.c:16
#define VT_STRING
Definition: cpstd.h:63
unsigned int co_env
Definition: cpdefs.h:27
int hlp_initxpos
Definition: readhelp.c:16
#define VT_BOOL
Definition: cpstd.h:60
Definition: cpstd.h:21
void com_quit(wordlist *wl)
Definition: misccoms.c:241
qsort()
Definition: string.c:375
void com_bug(wordlist *wl)
Definition: misccoms.c:344
int hlp_initypos
Definition: readhelp.c:17
char Spice_Notice[]
struct plot * pl_next
Definition: ftedata.h:69
struct plot * plot_list
Definition: vectors.c:44
void out_send()
char Spice_Build_Date[]
bool ft_nutmeg
Definition: main.c:161
char * ci_name
Definition: ftedefs.h:26
static void byemesg()
Definition: misccoms.c:404
#define E_NOPLOTS
Definition: ftehelp.h:11
bool inp_edit()
#define AHELPMESG2
Definition: misccoms.c:31
void(* co_func)()
Definition: cpdefs.h:22
enum Active SCEDactive()
Definition: scedstub.c:63
FILE * cp_in
Definition: help.c:101
char * version
Definition: ifsim.h:359
static char * path
Definition: paths.c:13
char * co_comname
Definition: cpdefs.h:21
char * wl_flatten()
Definition: cpdefs.h:57
void com_help(wordlist *wl)
Definition: misccoms.c:38
void ShowPrompt(char *str)
Definition: scedstub.c:71
bool out_moremode
Definition: output.c:44
void cp_ccon()
void out_init()
Definition: output.c:128