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: 1987 Jeffery M. Hsu
5 1992 Stephen R. Whiteley
6 ****************************************************************************/
7
8 /*
9 * This file contains the routines to evalute arguments to a command
10 * and prompt the user if necessary.
11 */
12
13 #include "spice.h"
14 #include "ftedefs.h"
15 #include "scedio.h"
16
17 #define MAXPROMPT 1024
18 static char buf[MAXPROMPT];
19
20 #ifdef __STDC__
21 static int countargs(wordlist*);
22 static void common(char*,wordlist*,struct comm*);
23 #else
24 static int countargs();
25 static void common( );
26 #endif
27
28
29 static int
countargs(wl)30 countargs(wl)
31
32 wordlist *wl;
33 {
34
35 int number=0;
36 wordlist *w;
37
38 for (w = wl; w; w = w->wl_next) {
39 number++ ;
40 }
41 return(number);
42
43 }
44
45
arg_print(wl,command)46 arg_print(wl, command)
47 wordlist *wl;
48 struct comm *command;
49 {
50
51 common("which variable", wl, command);
52
53 }
54
arg_plot(wl,command)55 arg_plot(wl, command)
56 wordlist *wl;
57 struct comm *command;
58 {
59
60 common("which variable", wl, command);
61
62 }
63
arg_load(wl,command)64 arg_load(wl, command)
65 wordlist *wl;
66 struct comm *command;
67 {
68 /* just call com_load */
69 (*command->co_func) (wl);
70
71 }
72
arg_let(wl,command)73 arg_let(wl, command)
74 wordlist *wl;
75 struct comm *command;
76 {
77
78 common("which vector", wl, command);
79
80 }
81
arg_set(wl,command)82 arg_set(wl, command)
83 wordlist *wl;
84 struct comm *command;
85 {
86
87 common("which variable", wl, command);
88
89 }
90
arg_display()91 arg_display()
92 {
93
94 /* just return; display does the right thing */
95
96 }
97
98 /* a common prompt routine */
99 static void
common(string,wl,command)100 common(string, wl, command)
101
102 char *string;
103 struct wordlist *wl;
104 struct comm *command;
105 {
106
107 struct wordlist *w;
108 char *buf;
109
110 if (!countargs(wl)) {
111 w = outmenuprompt(string);
112 if (w == NULL)
113 return;
114 (*command->co_func) (w);
115 wl_free(w);
116 }
117 }
118
119
120 wordlist *
outmenuprompt(string)121 outmenuprompt(string)
122 char *string;
123 {
124 wordlist *wl;
125 char buf[100], buf1[100];
126 char *c;
127
128 sprintf(buf1, "%s: ", string);
129 if (SCEDfgets(buf,sizeof(buf),cp_in,buf1) == NULL)
130 return (NULL);
131 if ((c = strchr(buf,'\n')) != NULL)
132 *c = '\0';
133 wl = alloc(wordlist);
134 wl->wl_word = copy(buf);
135 cp_variablesubst(&wl);
136 cp_bquote(&wl);
137 cp_doglob(&wl);
138 return (wl);
139 }
140