xref: /386bsd/usr/src/bin/sh/init (revision a2142627)
1/*
2 * This file was generated by the mkinit program.
3 */
4
5#include "shell.h"
6#include "mystring.h"
7#include "eval.h"
8#include "input.h"
9#include "error.h"
10#include "options.h"
11#include "redir.h"
12#include "signames.h"
13#include "trap.h"
14#include "output.h"
15#include "memalloc.h"
16#include "var.h"
17
18
19
20#define MAXPWD 256
21#define main echocmd
22#define ALL (E_OPEN|E_CREAT|E_EXEC)
23#define EV_EXIT 01		/* exit after evaluating tree */
24#define EV_TESTED 02		/* exit status is checked; ignore -e flag */
25#define EV_BACKCMD 04		/* command executing within back quotes */
26#define SKIPBREAK 1
27#define SKIPCONT 2
28#define SKIPFUNC 3
29#define CMDTABLESIZE 31		/* should be prime */
30#define ARB 1			/* actual size determined at run time */
31#define NEWARGS 5
32#define MAXLOGNAME 32
33#define MAXPWLINE 128
34#define EOF_NLEFT -99		/* value of parsenleft when EOF pushed back */
35#define MAXMBOXES 10
36#define PROFILE 0
37#define MINSIZE 504		/* minimum size of a block */
38#define EOFMARKLEN 79
39#define GDB_HACK 1 /* avoid local declarations which gdb can't handle */
40#define EMPTY -2		/* marks an unused slot in redirtab */
41#define PIPESIZE 4096		/* amount of buffering in a pipe */
42#define S_DFL 1			/* default signal handling (SIG_DFL) */
43#define S_CATCH 2		/* signal is caught */
44#define S_IGN 3			/* signal is ignored (SIG_IGN) */
45#define S_HARD_IGN 4		/* signal is ignored permenantly */
46#define OUTBUFSIZ BUFSIZ
47#define BLOCK_OUT -2		/* output to a fixed block of memory */
48#define MEM_OUT -3		/* output to dynamically allocated memory */
49#define OUTPUT_ERR 01		/* error occurred on output */
50#define TEMPSIZE 24
51#define VTABSIZE 39
52
53
54
55extern int evalskip;		/* set if we are skipping commands */
56extern int loopnest;		/* current loop nesting level */
57
58extern void deletefuncs();
59
60struct parsefile {
61	int linno;		/* current line */
62	int fd;			/* file descriptor (or -1 if string) */
63	int nleft;		/* number of chars left in buffer */
64	char *nextc;		/* next char in buffer */
65	struct parsefile *prev;	/* preceding file on stack */
66	char *buf;		/* input buffer */
67};
68
69extern int parsenleft;		/* copy of parsefile->nleft */
70extern struct parsefile basepf;	/* top level input file */
71
72extern short backgndpid;	/* pid of last background process */
73extern int jobctl;
74
75extern int tokpushback;		/* last token pushed back */
76
77struct redirtab {
78	struct redirtab *next;
79	short renamed[10];
80};
81
82extern struct redirtab *redirlist;
83
84extern char sigmode[MAXSIG];	/* current value of signal */
85
86extern void shprocvar();
87
88
89
90/*
91 * Initialization code.
92 */
93
94void
95init() {
96
97      /* from /usr/src/bin/sh/input.c: */
98      {
99	      extern char basebuf[];
100
101	      basepf.nextc = basepf.buf = basebuf;
102      }
103
104      /* from /usr/src/bin/sh/var.c: */
105      {
106	      char **envp;
107	      extern char **environ;
108
109	      initvar();
110	      for (envp = environ ; *envp ; envp++) {
111		      if (strchr(*envp, '=')) {
112			      setvareq(*envp, VEXPORT|VTEXTFIXED);
113		      }
114	      }
115      }
116}
117
118
119
120/*
121 * This routine is called when an error or an interrupt occurs in an
122 * interactive shell and control is returned to the main command loop.
123 */
124
125void
126reset() {
127
128      /* from /usr/src/bin/sh/eval.c: */
129      {
130	      evalskip = 0;
131	      loopnest = 0;
132	      funcnest = 0;
133      }
134
135      /* from /usr/src/bin/sh/input.c: */
136      {
137	      if (exception != EXSHELLPROC)
138		      parsenleft = 0;            /* clear input buffer */
139	      popallfiles();
140      }
141
142      /* from /usr/src/bin/sh/parser.c: */
143      {
144	      tokpushback = 0;
145      }
146
147      /* from /usr/src/bin/sh/redir.c: */
148      {
149	      while (redirlist)
150		      popredir();
151      }
152
153      /* from /usr/src/bin/sh/output.c: */
154      {
155	      out1 = &output;
156	      out2 = &errout;
157	      if (memout.buf != NULL) {
158		      ckfree(memout.buf);
159		      memout.buf = NULL;
160	      }
161      }
162}
163
164
165
166/*
167 * This routine is called to initialize the shell to run a shell procedure.
168 */
169
170void
171initshellproc() {
172
173      /* from /usr/src/bin/sh/eval.c: */
174      {
175	      exitstatus = 0;
176      }
177
178      /* from /usr/src/bin/sh/exec.c: */
179      {
180	      deletefuncs();
181      }
182
183      /* from /usr/src/bin/sh/input.c: */
184      {
185	      popallfiles();
186      }
187
188      /* from /usr/src/bin/sh/jobs.c: */
189      {
190	      backgndpid = -1;
191#if JOBS
192	      jobctl = 0;
193#endif
194      }
195
196      /* from /usr/src/bin/sh/options.c: */
197      {
198	      char *p;
199
200	      for (p = optval ; p < optval + sizeof optval ; p++)
201		      *p = 0;
202      }
203
204      /* from /usr/src/bin/sh/redir.c: */
205      {
206	      clearredir();
207      }
208
209      /* from /usr/src/bin/sh/trap.c: */
210      {
211	      char *sm;
212
213	      clear_traps();
214	      for (sm = sigmode ; sm < sigmode + MAXSIG ; sm++) {
215		      if (*sm == S_IGN)
216			      *sm = S_HARD_IGN;
217	      }
218      }
219
220      /* from /usr/src/bin/sh/var.c: */
221      {
222	      shprocvar();
223      }
224}
225