1 #include "ngspice/ngspice.h"
2 
3 #include "ngspice/macros.h"
4 #include "ngspice/wordlist.h"
5 #include "ngspice/cpdefs.h"
6 #include "ngspice/bool.h"
7 
8 #include "hcomp.h"
9 #include "com_help.h"
10 #include "ngspice/fteext.h"
11 
12 #define N_CMD_DFLT  512
com_help(wordlist * wl)13 void com_help(wordlist *wl)
14 {
15     bool allflag = FALSE;
16 
17     /* Make empty list and "all" behave the same except for the part
18      * related to "help all" */
19     if (wl && eq(wl->wl_word, "all")) {
20         allflag = TRUE;
21         wl = (wordlist *) NULL;
22     }
23 
24     /* We want to use more mode whether "moremode" is set or not.
25      * In that case the code below should be changed... */
26     out_moremode = TRUE;
27     out_init();
28     out_moremode = FALSE;
29 
30 
31     if (wl == NULL) {
32         struct comm *ccc_dflt[N_CMD_DFLT];  /* Should be enough. */
33         struct comm **ccc; /* dynamic alloc in case it is not */
34         int numcoms;
35 
36         if (!allflag) {
37             out_printf("For a list of all commands "
38                        "type \"help all\", for a short\n"
39                        "description of \"command\", "
40                        "type \"help command\".\n");
41             return;
42         }
43 
44         /* Count the number of commands */
45         for (numcoms = 0; cp_coms[numcoms].co_func != NULL; numcoms++) {
46             ;
47         }
48         if (numcoms > N_CMD_DFLT) {
49             ccc = TMALLOC(struct comm *, numcoms);
50         }
51         else {
52             ccc = ccc_dflt;
53         }
54 
55         /* Sort the commands */
56         for (numcoms = 0; cp_coms[numcoms].co_func != NULL; numcoms++) {
57             ccc[numcoms] = &cp_coms[numcoms];
58         }
59         qsort(ccc, (size_t) numcoms, sizeof(struct comm *), hcomp);
60 
61         /* Print help for each of the "major" commands */
62         {
63             int i;
64             for (i = 0; i < numcoms; i++) {
65                 if ((ccc[i]->co_spiceonly && ft_nutmeg) ||
66                         (ccc[i]->co_help == NULL) ||
67                         (!allflag && !ccc[i]->co_major)) {
68                     continue;
69                 }
70                 out_printf("%s ", ccc[i]->co_comname);
71                 out_printf(ccc[i]->co_help, cp_program);
72                 out_send("\n");
73             }
74         }
75 
76         /* Free allocation if it was required */
77         if (ccc != ccc_dflt) {
78             txfree(ccc);
79         }
80     }
81     else {
82         while (wl != NULL) {
83             struct comm *c;
84             for (c = &cp_coms[0]; c->co_func != NULL; c++)
85                 if (eq(wl->wl_word, c->co_comname)) {
86                     out_printf("%s ", c->co_comname);
87                     out_printf(c->co_help, cp_program);
88                     if (c->co_spiceonly && ft_nutmeg)
89                         out_send(" (Not available in nutmeg)");
90                     out_send("\n");
91                     break;
92                 }
93             if (c->co_func == NULL) {
94                 /* See if this is aliased. */
95                 struct alias *al;
96 
97                 for (al = cp_aliases; al; al = al->al_next)
98                     if (eq(al->al_name, wl->wl_word))
99                         break;
100 
101                 if (al == NULL) {
102                     fprintf(cp_out, "Sorry, no help for %s.\n", wl->wl_word);
103                 }
104                 else {
105                     out_printf("%s is aliased to ", wl->wl_word);
106                     /* Minor badness here... */
107                     wl_print(al->al_text, cp_out);
108                     out_send("\n");
109                 }
110             } /* end of case that a function with the given name was found */
111             wl = wl->wl_next; /* step to next word in list of help items */
112         } /* end of loop over list of help items */
113     }
114 
115     out_send("\n");
116 } /* end of function com_help */
117 
118 
119 
120