1 /*
2 * This file was generated by the mkinit program.
3 */
4
5 #include "mystring.h"
6 #include "shell.h"
7 #include "init.h"
8 #include "eval.h"
9 #include "expand.h"
10 #include <stdio.h>
11 #include "input.h"
12 #include "error.h"
13 #include "parser.h"
14 #include "redir.h"
15 #include "trap.h"
16 #include "output.h"
17 #include "memalloc.h"
18 #include "tab.h"
19 #include <linenoise/linenoise.h>
20 #include <unistd.h>
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #include "cd.h"
24 #include "var.h"
25
26
27
28 #undef ATABSIZE
29 #define ATABSIZE 39
30 #undef ARITH_MAX_PREC
31 #define ARITH_MAX_PREC 8
32 #undef CD_PHYSICAL
33 #define CD_PHYSICAL 1
34 #undef CD_PRINT
35 #define CD_PRINT 2
36 #undef CMDTABLESIZE
37 #define CMDTABLESIZE 31 /* should be prime */
38 #undef ARB
39 #define ARB 1 /* actual size determined at run time */
40 #undef RMESCAPE_ALLOC
41 #define RMESCAPE_ALLOC 0x1 /* Allocate a new string */
42 #undef RMESCAPE_GLOB
43 #define RMESCAPE_GLOB 0x2 /* Add backslashes for glob */
44 #undef RMESCAPE_GROW
45 #define RMESCAPE_GROW 0x8 /* Grow strings instead of stalloc */
46 #undef RMESCAPE_HEAP
47 #define RMESCAPE_HEAP 0x10 /* Malloc strings instead of stalloc */
48 #undef QUOTES_ESC
49 #define QUOTES_ESC (EXP_FULL | EXP_CASE | EXP_QPAT)
50 #undef QUOTES_KEEPNUL
51 #define QUOTES_KEEPNUL EXP_TILDE
52 #undef EOF_NLEFT
53 #define EOF_NLEFT -99 /* value of parsenleft when EOF pushed back */
54 #undef IBUFSIZ
55 #define IBUFSIZ (BUFSIZ + 1)
56 #undef CUR_DELETE
57 #define CUR_DELETE 2
58 #undef CUR_RUNNING
59 #define CUR_RUNNING 1
60 #undef CUR_STOPPED
61 #define CUR_STOPPED 0
62 #undef DOWAIT_NORMAL
63 #define DOWAIT_NORMAL 0
64 #undef DOWAIT_BLOCK
65 #define DOWAIT_BLOCK 1
66 #undef DOWAIT_WAITCMD
67 #define DOWAIT_WAITCMD 2
68 #undef PROFILE
69 #define PROFILE 0
70 #undef MINSIZE
71 #define MINSIZE SHELL_ALIGN(504)
72 #undef DEFINE_OPTIONS
73 #define DEFINE_OPTIONS
74 #undef FAKEEOFMARK
75 #define FAKEEOFMARK (char *)1
76 #undef REALLY_CLOSED
77 #define REALLY_CLOSED -3 /* fd that was closed and still is */
78 #undef EMPTY
79 #define EMPTY -2 /* marks an unused slot in redirtab */
80 #undef CLOSED
81 #define CLOSED -1 /* fd opened for redir needs to be closed */
82 #undef S_DFL
83 #define S_DFL 1 /* default signal handling (SIG_DFL) */
84 #undef S_CATCH
85 #define S_CATCH 2 /* signal is caught */
86 #undef S_IGN
87 #define S_IGN 3 /* signal is ignored (SIG_IGN) */
88 #undef S_HARD_IGN
89 #define S_HARD_IGN 4 /* signal is ignored permenantly */
90 #undef S_RESET
91 #define S_RESET 5 /* temporary - to reset a hard ignored sig */
92 #undef OUTBUFSIZ
93 #define OUTBUFSIZ BUFSIZ
94 #undef MEM_OUT
95 #define MEM_OUT -3 /* output to dynamically allocated memory */
96 #undef SKIP1
97 #define SKIP1 "#-+ 0"
98 #undef SKIP2
99 #define SKIP2 "*0123456789"
100 #undef isalnum
101 #define isalnum _isalnum
102 #undef iscntrl
103 #define iscntrl _iscntrl
104 #undef islower
105 #define islower _islower
106 #undef isspace
107 #define isspace _isspace
108 #undef isalpha
109 #define isalpha _isalpha
110 #undef isdigit
111 #define isdigit _isdigit
112 #undef isprint
113 #define isprint _isprint
114 #undef isupper
115 #define isupper _isupper
116 #undef isblank
117 #define isblank _isblank
118 #undef isgraph
119 #define isgraph _isgraph
120 #undef ispunct
121 #define ispunct _ispunct
122 #undef isxdigit
123 #define isxdigit _isxdigit
124 #undef VTABSIZE
125 #define VTABSIZE 39
126
127
128
129 extern int loopnest; /* current loop nesting level */
130
131 extern struct parsefile basepf; /* top level input file */
132 extern char basebuf[IBUFSIZ]; /* buffer for top level input file */
133
134 struct redirtab {
135 struct redirtab *next;
136 int renamed[10];
137 };
138
139 extern struct redirtab *redirlist;
140
141 extern struct localvar_list *localvar_stack;
142 extern char defoptindvar[];
143 extern char **environ;
144
145
146
147 /*
148 * Initialization code.
149 */
150
151 void
init()152 init() {
153
154 /* from input.c: */
155 {
156 basepf.nextc = basepf.buf = basebuf;
157 basepf.linno = 1;
158 }
159
160 /* from trap.c: */
161 {
162 sigmode[SIGCHLD - 1] = S_DFL;
163 setsignal(SIGCHLD);
164 }
165
166 /* from output.c: */
167 {
168 #ifdef USE_GLIBC_STDIO
169 initstreams();
170 #endif
171 }
172
173 /* from tab.c: */
174 {
175 linenoiseSetCompletionCallback(tab_complete);
176 }
177
178 /* from var.c: */
179 {
180 char **envp;
181 static char ppid[32] = "PPID=";
182 const char *p;
183 struct stat st1, st2;
184
185 initvar();
186 for (envp = environ ; *envp ; envp++) {
187 p = endofname(*envp);
188 if (p != *envp && *p == '=') {
189 setvareq(*envp, VEXPORT|VTEXTFIXED);
190 }
191 }
192
193 setvareq(defoptindvar, VTEXTFIXED);
194
195 fmtstr(ppid + 5, sizeof(ppid) - 5, "%ld", (long) getppid());
196 setvareq(ppid, VTEXTFIXED);
197
198 p = lookupvar("PWD");
199 if (p)
200 if (*p != '/' || stat(p, &st1) || stat(".", &st2) ||
201 st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino)
202 p = 0;
203 setpwd(p, 0);
204 }
205 }
206
207
208
209 /*
210 * This routine is called when an error or an interrupt occurs in an
211 * interactive shell and control is returned to the main command loop.
212 */
213
214 void
reset()215 reset() {
216
217 /* from eval.c: */
218 {
219 evalskip = 0;
220 loopnest = 0;
221 if (savestatus >= 0) {
222 exitstatus = savestatus;
223 savestatus = -1;
224 }
225 }
226
227 /* from expand.c: */
228 {
229 ifsfree();
230 }
231
232 /* from input.c: */
233 {
234 /* clear input buffer */
235 basepf.lleft = basepf.nleft = 0;
236 popallfiles();
237 }
238
239 /* from redir.c: */
240 {
241 /*
242 * Discard all saved file descriptors.
243 */
244 unwindredir(0);
245 }
246
247 /* from output.c: */
248 {
249 #ifdef notyet
250 out1 = &output;
251 out2 = &errout;
252 #ifdef USE_GLIBC_STDIO
253 if (memout.stream != NULL)
254 __closememout();
255 #endif
256 if (memout.buf != NULL) {
257 ckfree(memout.buf);
258 memout.buf = NULL;
259 }
260 #endif
261 }
262
263 /* from var.c: */
264 {
265 unwindlocalvars(0);
266 }
267 }
268