1 | /*
|
---|
2 | * This file was generated by the mkinit program.
|
---|
3 | */
|
---|
4 |
|
---|
5 | #include "shell.h"
|
---|
6 | #include "mystring.h"
|
---|
7 | #include "init.h"
|
---|
8 | #include "eval.h"
|
---|
9 | #include <stdio.h>
|
---|
10 | #include "input.h"
|
---|
11 | #include "error.h"
|
---|
12 | #include <stdlib.h>
|
---|
13 | #include "options.h"
|
---|
14 | #include "output.h"
|
---|
15 | #include "memalloc.h"
|
---|
16 | #include "redir.h"
|
---|
17 | #include <signal.h>
|
---|
18 | #include "trap.h"
|
---|
19 | #include "var.h"
|
---|
20 |
|
---|
21 |
|
---|
22 |
|
---|
23 | #undef ATABSIZE
|
---|
24 | #define ATABSIZE 39
|
---|
25 | #undef MAXPWD
|
---|
26 | #define MAXPWD 256
|
---|
27 | #undef ALL
|
---|
28 | #define ALL (E_OPEN|E_CREAT|E_EXEC)
|
---|
29 | #undef EV_EXIT
|
---|
30 | #define EV_EXIT 01 /* exit after evaluating tree */
|
---|
31 | #undef EV_TESTED
|
---|
32 | #define EV_TESTED 02 /* exit status is checked; ignore -e flag */
|
---|
33 | #undef EV_BACKCMD
|
---|
34 | #define EV_BACKCMD 04 /* command executing within back quotes */
|
---|
35 | #undef CMDTABLESIZE
|
---|
36 | #define CMDTABLESIZE 31 /* should be prime */
|
---|
37 | #undef ARB
|
---|
38 | #define ARB 1 /* actual size determined at run time */
|
---|
39 | #undef NEWARGS
|
---|
40 | #define NEWARGS 5
|
---|
41 | #undef MAXHISTLOOPS
|
---|
42 | #define MAXHISTLOOPS 4 /* max recursions through fc */
|
---|
43 | #undef DEFEDITOR
|
---|
44 | #define DEFEDITOR "ed" /* default editor *should* be $EDITOR */
|
---|
45 | #undef editing
|
---|
46 | #define editing (Eflag(psh) || Vflag(psh))
|
---|
47 | #undef EOF_NLEFT
|
---|
48 | #define EOF_NLEFT -99 /* value of parsenleft when EOF pushed back */
|
---|
49 | #undef MAXMBOXES
|
---|
50 | #define MAXMBOXES 10
|
---|
51 | #undef PROFILE
|
---|
52 | #define PROFILE 0
|
---|
53 | #undef SIGSSIZE
|
---|
54 | #define SIGSSIZE (sizeof(sigs)/sizeof(sigs[0]))
|
---|
55 | #undef MINSIZE
|
---|
56 | #define MINSIZE 504 /* minimum size of a block */
|
---|
57 | #undef DEFINE_OPTIONS
|
---|
58 | #define DEFINE_OPTIONS
|
---|
59 | #undef OUTBUFSIZ
|
---|
60 | #define OUTBUFSIZ BUFSIZ
|
---|
61 | #undef BLOCK_OUT
|
---|
62 | #define BLOCK_OUT -2 /* output to a fixed block of memory */
|
---|
63 | #undef MEM_OUT
|
---|
64 | #define MEM_OUT -3 /* output to dynamically allocated memory */
|
---|
65 | #undef OUTPUT_ERR
|
---|
66 | #define OUTPUT_ERR 01 /* error occurred on output */
|
---|
67 | #undef TEMPSIZE
|
---|
68 | #define TEMPSIZE 24
|
---|
69 | #undef HAVE_VASPRINTF
|
---|
70 | #define HAVE_VASPRINTF 1
|
---|
71 | #undef EOFMARKLEN
|
---|
72 | #define EOFMARKLEN 79
|
---|
73 | #undef OPENBRACE
|
---|
74 | #define OPENBRACE '{'
|
---|
75 | #undef CLOSEBRACE
|
---|
76 | #define CLOSEBRACE '}'
|
---|
77 | #undef EMPTY
|
---|
78 | #define EMPTY -2 /* marks an unused slot in redirtab */
|
---|
79 | #undef S_DFL
|
---|
80 | #define S_DFL 1 /* default signal handling (SIG_DFL) */
|
---|
81 | #undef S_CATCH
|
---|
82 | #define S_CATCH 2 /* signal is caught */
|
---|
83 | #undef S_IGN
|
---|
84 | #define S_IGN 3 /* signal is ignored (SIG_IGN) */
|
---|
85 | #undef S_HARD_IGN
|
---|
86 | #define S_HARD_IGN 4 /* signal is ignored permenantly */
|
---|
87 | #undef S_RESET
|
---|
88 | #define S_RESET 5 /* temporary - to reset a hard ignored sig */
|
---|
89 | #undef INCL_BASE
|
---|
90 | #define INCL_BASE
|
---|
91 | #undef LIBPATHSTRICT
|
---|
92 | #define LIBPATHSTRICT 3
|
---|
93 | #undef QHINF_EXEINFO
|
---|
94 | #define QHINF_EXEINFO 1 /* NE exeinfo. */
|
---|
95 | #undef QHINF_READRSRCTBL
|
---|
96 | #define QHINF_READRSRCTBL 2 /* Reads from the resource table. */
|
---|
97 | #undef QHINF_READFILE
|
---|
98 | #define QHINF_READFILE 3 /* Reads from the executable file. */
|
---|
99 | #undef QHINF_LIBPATHLENGTH
|
---|
100 | #define QHINF_LIBPATHLENGTH 4 /* Gets the libpath length. */
|
---|
101 | #undef QHINF_LIBPATH
|
---|
102 | #define QHINF_LIBPATH 5 /* Gets the entire libpath. */
|
---|
103 | #undef QHINF_FIXENTRY
|
---|
104 | #define QHINF_FIXENTRY 6 /* NE only */
|
---|
105 | #undef QHINF_STE
|
---|
106 | #define QHINF_STE 7 /* NE only */
|
---|
107 | #undef QHINF_MAPSEL
|
---|
108 | #define QHINF_MAPSEL 8 /* NE only */
|
---|
109 | #undef VTABSIZE
|
---|
110 | #define VTABSIZE 39
|
---|
111 | #undef VTABSIZE
|
---|
112 | #define VTABSIZE 517
|
---|
113 | #undef main
|
---|
114 | #define main echocmd
|
---|
115 | #undef main
|
---|
116 | #define main killcmd
|
---|
117 |
|
---|
118 |
|
---|
119 |
|
---|
120 | extern void rmaliases(struct shinstance *);
|
---|
121 |
|
---|
122 | extern int loopnest; /* current loop nesting level */
|
---|
123 |
|
---|
124 | extern void deletefuncs(struct shinstance *);
|
---|
125 | extern void hash_special_builtins(struct shinstance *);
|
---|
126 |
|
---|
127 | struct strpush {
|
---|
128 | struct strpush *prev; /* preceding string on stack */
|
---|
129 | char *prevstring;
|
---|
130 | int prevnleft;
|
---|
131 | int prevlleft;
|
---|
132 | struct alias *ap; /* if push was associated with an alias */
|
---|
133 | };
|
---|
134 |
|
---|
135 | struct parsefile {
|
---|
136 | struct parsefile *prev; /* preceding file on stack */
|
---|
137 | int linno; /* current line */
|
---|
138 | int fd; /* file descriptor (or -1 if string) */
|
---|
139 | int nleft; /* number of chars left in this line */
|
---|
140 | int lleft; /* number of chars left in this buffer */
|
---|
141 | char *nextc; /* next char in buffer */
|
---|
142 | char *buf; /* input buffer */
|
---|
143 | struct strpush *strpush; /* for pushing strings at this level */
|
---|
144 | struct strpush basestrpush; /* so pushing one is fast */
|
---|
145 | };
|
---|
146 |
|
---|
147 | extern int parselleft; /* copy of parsefile->lleft */
|
---|
148 | extern struct parsefile basepf; /* top level input file */
|
---|
149 | extern char basebuf[BUFSIZ]; /* buffer for top level input file */
|
---|
150 |
|
---|
151 | extern pid_t backgndpid; /* pid of last background process */
|
---|
152 | extern int jobctl;
|
---|
153 |
|
---|
154 | extern int tokpushback; /* last token pushed back */
|
---|
155 | extern int checkkwd; /* 1 == check for kwds, 2 == also eat newlines */
|
---|
156 |
|
---|
157 | struct redirtab {
|
---|
158 | struct redirtab *next;
|
---|
159 | short renamed[10];
|
---|
160 | };
|
---|
161 |
|
---|
162 | extern struct redirtab *redirlist;
|
---|
163 |
|
---|
164 | extern char sigmode[NSIG]; /* current value of signal */
|
---|
165 |
|
---|
166 | extern char **environ;
|
---|
167 |
|
---|
168 |
|
---|
169 |
|
---|
170 | /*
|
---|
171 | * Initialization code.
|
---|
172 | */
|
---|
173 |
|
---|
174 | void
|
---|
175 | init(shinstance *psh) {
|
---|
176 |
|
---|
177 | /* from exec.c: */
|
---|
178 | {
|
---|
179 | hash_special_builtins();
|
---|
180 | }
|
---|
181 |
|
---|
182 | /* from input.c: */
|
---|
183 | {
|
---|
184 | basepf.nextc = basepf.buf = basebuf;
|
---|
185 | }
|
---|
186 |
|
---|
187 | /* from var.c: */
|
---|
188 | {
|
---|
189 | char **envp;
|
---|
190 |
|
---|
191 | initvar(psh);
|
---|
192 | for (envp = environ ; *envp ; envp++) {
|
---|
193 | if (strchr(*envp, '=')) {
|
---|
194 | setvareq(psh, *envp, VEXPORT|VTEXTFIXED);
|
---|
195 | }
|
---|
196 | }
|
---|
197 | }
|
---|
198 | }
|
---|
199 |
|
---|
200 |
|
---|
201 |
|
---|
202 | /*
|
---|
203 | * This routine is called when an error or an interrupt occurs in an
|
---|
204 | * interactive shell and control is returned to the main command loop.
|
---|
205 | */
|
---|
206 |
|
---|
207 | void
|
---|
208 | reset(shinstance *psh) {
|
---|
209 |
|
---|
210 | /* from eval.c: */
|
---|
211 | {
|
---|
212 | psh->evalskip = 0;
|
---|
213 | psh->loopnest = 0;
|
---|
214 | psh->funcnest = 0;
|
---|
215 | }
|
---|
216 |
|
---|
217 | /* from input.c: */
|
---|
218 | {
|
---|
219 | if (psh->exception != EXSHELLPROC)
|
---|
220 | psh->parselleft = psh->parsenleft = 0; /* clear input buffer */
|
---|
221 | popallfiles(psh);
|
---|
222 | }
|
---|
223 |
|
---|
224 | /* from output.c: */
|
---|
225 | {
|
---|
226 | psh->out1 = &psh->output;
|
---|
227 | psh->out2 = &psh->errout;
|
---|
228 | if (memout.buf != NULL) {
|
---|
229 | ckfree(memout.buf);
|
---|
230 | memout.buf = NULL;
|
---|
231 | }
|
---|
232 | }
|
---|
233 |
|
---|
234 | /* from parser.c: */
|
---|
235 | {
|
---|
236 | psh->tokpushback = 0;
|
---|
237 | psh->checkkwd = 0;
|
---|
238 | }
|
---|
239 |
|
---|
240 | /* from redir.c: */
|
---|
241 | {
|
---|
242 | while (psh->redirlist)
|
---|
243 | popredir(psh);
|
---|
244 | }
|
---|
245 | }
|
---|
246 |
|
---|
247 |
|
---|
248 |
|
---|
249 | /*
|
---|
250 | * This routine is called to initialize the shell to run a shell procedure.
|
---|
251 | */
|
---|
252 |
|
---|
253 | void
|
---|
254 | initshellproc(shinstance *psh) {
|
---|
255 |
|
---|
256 | /* from alias.c: */
|
---|
257 | {
|
---|
258 | rmaliases(psh);
|
---|
259 | }
|
---|
260 |
|
---|
261 | /* from eval.c: */
|
---|
262 | {
|
---|
263 | psh->exitstatus = 0;
|
---|
264 | }
|
---|
265 |
|
---|
266 | /* from exec.c: */
|
---|
267 | {
|
---|
268 | deletefuncs(psh);
|
---|
269 | }
|
---|
270 |
|
---|
271 | /* from input.c: */
|
---|
272 | {
|
---|
273 | popallfiles(psh);
|
---|
274 | }
|
---|
275 |
|
---|
276 | /* from jobs.c: */
|
---|
277 | {
|
---|
278 | psh->backgndpid = -1;
|
---|
279 | #if JOBS
|
---|
280 | jobctl = 0;
|
---|
281 | #endif
|
---|
282 | }
|
---|
283 |
|
---|
284 | /* from options.c: */
|
---|
285 | {
|
---|
286 | int i;
|
---|
287 |
|
---|
288 | for (i = 0; optlist[i].name; i++)
|
---|
289 | optlist[i].val = 0;
|
---|
290 | optschanged(psh);
|
---|
291 |
|
---|
292 | }
|
---|
293 |
|
---|
294 | /* from redir.c: */
|
---|
295 | {
|
---|
296 | clearredir(psh, 0);
|
---|
297 | }
|
---|
298 |
|
---|
299 | /* from trap.c: */
|
---|
300 | {
|
---|
301 | char *sm;
|
---|
302 |
|
---|
303 | clear_traps(psh, 0);
|
---|
304 | for (sm = psh->sigmode ; sm < psh->sigmode + NSIG ; sm++) {
|
---|
305 | if (*sm == S_IGN)
|
---|
306 | *sm = S_HARD_IGN;
|
---|
307 | }
|
---|
308 | }
|
---|
309 |
|
---|
310 | /* from var.c: */
|
---|
311 | {
|
---|
312 | shprocvar(psh);
|
---|
313 | }
|
---|
314 | }
|
---|