Jspice3
misccoms.c File Reference
#include "spice.h"
#include "ftedefs.h"
#include "ftehelp.h"
#include "hlpdefs.h"
#include "scedio.h"
Include dependency graph for misccoms.c:

Go to the source code of this file.

Macros

#define SHORTHELPMSG   "For a complete description of %s read the %s manual.\n"
 
#define AHELPMESG1   "For a complete description of %s read the %s manual.\n\There are short introductions to both Spice 3 and Nutmeg available, in\n\addition to the SPICE User's Guide and the manual pages. If you don't\n"
 
#define AHELPMESG2   "have these documents ask your system manager for them. Below is a short\n\list of useful commands -- for a list of all commands type \"help all\",\n\and for a short description of \"command\", type \"help command\".\n"
 

Functions

static int hcomp ()
 
static void byemesg ()
 
void com_help (wordlist *wl)
 
void com_ahelp (wordlist *wl)
 
void com_ghelp (wordlist *wl)
 
static int hcomp (struct comm **c1, struct comm **c2)
 
void com_quit (wordlist *wl)
 
void com_bug (wordlist *wl)
 
void com_version (wordlist *wl)
 

Macro Definition Documentation

#define AHELPMESG1   "For a complete description of %s read the %s manual.\n\There are short introductions to both Spice 3 and Nutmeg available, in\n\addition to the SPICE User's Guide and the manual pages. If you don't\n"

Definition at line 26 of file misccoms.c.

#define AHELPMESG2   "have these documents ask your system manager for them. Below is a short\n\list of useful commands -- for a list of all commands type \"help all\",\n\and for a short description of \"command\", type \"help command\".\n"

Definition at line 31 of file misccoms.c.

#define SHORTHELPMSG   "For a complete description of %s read the %s manual.\n"

Definition at line 22 of file misccoms.c.

Function Documentation

static void byemesg ( )
static

Definition at line 404 of file misccoms.c.

405 {
406  out_init();
407  out_printf("%s-%s done\n", ft_sim->simulator, ft_sim->version);
408  return;
409 }
IFsimulator * ft_sim
Definition: main.c:111
void out_printf()
char * simulator
Definition: ifsim.h:357
char * version
Definition: ifsim.h:359
void out_init()
Definition: output.c:128
void com_ahelp ( wordlist wl)

Definition at line 124 of file misccoms.c.

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 }
Definition: subckt.c:18
bool cp_getvar(char *n, int t, char *r)
Definition: help.c:184
static int hcomp()
#define E_HASPLOTS
Definition: ftehelp.h:10
void out_printf()
char * kw_level
Definition: options.c:372
struct comm * cp_coms
Definition: main.c:163
Definition: cpdefs.h:20
bool co_spiceonly
Definition: cpdefs.h:24
#define AHELPMESG1
Definition: misccoms.c:26
#define NULL
Definition: spdefs.h:121
char * co_help
Definition: cpdefs.h:31
char * cp_program
Definition: main.c:43
#define VT_STRING
Definition: cpstd.h:63
unsigned int co_env
Definition: cpdefs.h:27
qsort()
Definition: string.c:375
struct plot * pl_next
Definition: ftedata.h:69
struct plot * plot_list
Definition: vectors.c:44
void out_send()
bool ft_nutmeg
Definition: main.c:161
#define E_NOPLOTS
Definition: ftehelp.h:11
#define AHELPMESG2
Definition: misccoms.c:31
void(* co_func)()
Definition: cpdefs.h:22
char * co_comname
Definition: cpdefs.h:21
void com_help(wordlist *wl)
Definition: misccoms.c:38
void out_init()
Definition: output.c:128
void com_bug ( wordlist wl)

Definition at line 344 of file misccoms.c.

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 }
static char buf[MAXPROMPT]
Definition: arg.c:18
#define BSIZE_SP
Definition: misc.h:19
char * strcpy()
Definition: cddefs.h:119
char * News_File
Definition: ivars.c:12
#define NULL
Definition: spdefs.h:121
int access(char *pth, int m)
Definition: libfuncs.c:75
bool inp_edit()
enum Active SCEDactive()
Definition: scedstub.c:63
void ShowPrompt(char *str)
Definition: scedstub.c:71
void com_ghelp ( wordlist wl)

Definition at line 205 of file misccoms.c.

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 }
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
char * cp_tildexpand()
char * Help_Path
Definition: help.c:104
void hlp_main()
FILE * cp_err
Definition: help.c:101
#define tfree(x)
Definition: cdmacs.h:22
#define NULL
Definition: spdefs.h:121
#define VT_NUM
Definition: cpstd.h:61
#define VT_STRING
Definition: cpstd.h:63
int hlp_initxpos
Definition: readhelp.c:16
int hlp_initypos
Definition: readhelp.c:17
static char * path
Definition: paths.c:13
void com_help(wordlist *wl)
Definition: misccoms.c:38
void com_help ( wordlist wl)

Definition at line 38 of file misccoms.c.

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 }
#define eq(a, b)
Definition: misc.h:29
void out_wlprint()
static int hcomp()
void out_printf()
struct alias * al_next
Definition: cpdefs.h:60
#define SHORTHELPMSG
Definition: misccoms.c:22
char * al_name
Definition: cpdefs.h:58
struct alias * cp_aliases
Definition: alias.c:22
struct comm * cp_coms
Definition: main.c:163
Definition: cpdefs.h:20
bool co_spiceonly
Definition: cpdefs.h:24
#define AHELPMESG1
Definition: misccoms.c:26
wordlist * al_text
Definition: cpdefs.h:59
#define NULL
Definition: spdefs.h:121
char * co_help
Definition: cpdefs.h:31
bool co_major
Definition: cpdefs.h:25
char * cp_program
Definition: main.c:43
static double c
Definition: vectors.c:16
qsort()
Definition: string.c:375
void out_send()
struct wordlist * wl_next
Definition: cpstd.h:23
bool ft_nutmeg
Definition: main.c:161
char * wl_word
Definition: cpstd.h:22
#define AHELPMESG2
Definition: misccoms.c:31
void(* co_func)()
Definition: cpdefs.h:22
char * co_comname
Definition: cpdefs.h:21
Definition: cpdefs.h:57
bool out_moremode
Definition: output.c:44
void out_init()
Definition: output.c:128
void com_quit ( wordlist wl)

Definition at line 241 of file misccoms.c.

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 }
static char buf[MAXPROMPT]
Definition: arg.c:18
#define BSIZE_SP
Definition: misc.h:19
struct circ * ci_next
Definition: ftedefs.h:37
Definition: subckt.c:18
bool cp_getvar(char *n, int t, char *r)
Definition: help.c:184
char * pl_typename
Definition: ftedata.h:65
char * pl_title
Definition: ftedata.h:62
void out_printf()
char * pl_name
Definition: ftedata.h:64
Definition: ftedefs.h:25
#define EXIT_NORMAL
Definition: misc.h:25
bool ci_inprogress
Definition: ftedefs.h:34
Definition: ftedata.h:61
void * pl_hashtab
Definition: ftedata.h:66
struct circ * ft_circuits
Definition: main.c:185
bool pl_written
Definition: ftedata.h:73
char * SCEDfgets(char *s, int n, FILE *fp, char *prompt)
Definition: scedstub.c:41
#define VT_BOOL
Definition: cpstd.h:60
struct plot * pl_next
Definition: ftedata.h:69
struct plot * plot_list
Definition: vectors.c:44
bool ft_nutmeg
Definition: main.c:161
char * ci_name
Definition: ftedefs.h:26
static void byemesg()
Definition: misccoms.c:404
FILE * cp_in
Definition: help.c:101
void cp_ccon()
void out_init()
Definition: output.c:128
void com_version ( wordlist wl)

Definition at line 375 of file misccoms.c.

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 }
#define eq(a, b)
Definition: misc.h:29
IFsimulator * ft_sim
Definition: main.c:111
void out_printf()
Definition: cddefs.h:119
char * simulator
Definition: ifsim.h:357
#define tfree(x)
Definition: cdmacs.h:22
char Spice_Notice[]
char Spice_Build_Date[]
char * wl_word
Definition: cpstd.h:22
char * version
Definition: ifsim.h:359
char * wl_flatten()
void out_init()
Definition: output.c:128
static int hcomp ( )
static
static int hcomp ( struct comm **  c1,
struct comm **  c2 
)
static

Definition at line 231 of file misccoms.c.

234 {
235  return (strcmp((*c1)->co_comname, (*c2)->co_comname));
236 }