diff options
author | Eric Andersen <andersen@codepoet.org> | 2004-08-04 19:16:54 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2004-08-04 19:16:54 +0000 |
commit | 8401eeafd654d447053036cdd1dfbca9a0e297a8 (patch) | |
tree | f39ae5b08f0339efe56c7bc68caf1a7273a48a33 | |
parent | 44b5758247cd42721e4bc681df5516e8f01dc8c7 (diff) | |
download | busybox-w32-8401eeafd654d447053036cdd1dfbca9a0e297a8.tar.gz busybox-w32-8401eeafd654d447053036cdd1dfbca9a0e297a8.tar.bz2 busybox-w32-8401eeafd654d447053036cdd1dfbca9a0e297a8.zip |
Run msh through indent
-rw-r--r-- | shell/msh.c | 2477 |
1 files changed, 1164 insertions, 1313 deletions
diff --git a/shell/msh.c b/shell/msh.c index 62e7844a8..722d90d57 100644 --- a/shell/msh.c +++ b/shell/msh.c | |||
@@ -55,12 +55,12 @@ | |||
55 | */ | 55 | */ |
56 | 56 | ||
57 | #define LINELIM 2100 | 57 | #define LINELIM 2100 |
58 | #define NPUSH 8 /* limit to input nesting */ | 58 | #define NPUSH 8 /* limit to input nesting */ |
59 | 59 | ||
60 | #undef NOFILE | 60 | #undef NOFILE |
61 | #define NOFILE 20 /* Number of open files */ | 61 | #define NOFILE 20 /* Number of open files */ |
62 | #define NUFILE 10 /* Number of user-accessible files */ | 62 | #define NUFILE 10 /* Number of user-accessible files */ |
63 | #define FDBASE 10 /* First file usable by Shell */ | 63 | #define FDBASE 10 /* First file usable by Shell */ |
64 | 64 | ||
65 | /* | 65 | /* |
66 | * values returned by wait | 66 | * values returned by wait |
@@ -72,7 +72,7 @@ | |||
72 | /* | 72 | /* |
73 | * library and system definitions | 73 | * library and system definitions |
74 | */ | 74 | */ |
75 | typedef void xint; /* base type of jmp_buf, for not broken compilers */ | 75 | typedef void xint; /* base type of jmp_buf, for not broken compilers */ |
76 | 76 | ||
77 | /* | 77 | /* |
78 | * shell components | 78 | * shell components |
@@ -90,20 +90,20 @@ typedef void xint; /* base type of jmp_buf, for not broken compilers */ | |||
90 | * Might eventually use a union. | 90 | * Might eventually use a union. |
91 | */ | 91 | */ |
92 | struct op { | 92 | struct op { |
93 | int type; /* operation type, see below */ | 93 | int type; /* operation type, see below */ |
94 | char **words; /* arguments to a command */ | 94 | char **words; /* arguments to a command */ |
95 | struct ioword **ioact; /* IO actions (eg, < > >>) */ | 95 | struct ioword **ioact; /* IO actions (eg, < > >>) */ |
96 | struct op *left; | 96 | struct op *left; |
97 | struct op *right; | 97 | struct op *right; |
98 | char *str; /* identifier for case and for */ | 98 | char *str; /* identifier for case and for */ |
99 | }; | 99 | }; |
100 | 100 | ||
101 | #define TCOM 1 /* command */ | 101 | #define TCOM 1 /* command */ |
102 | #define TPAREN 2 /* (c-list) */ | 102 | #define TPAREN 2 /* (c-list) */ |
103 | #define TPIPE 3 /* a | b */ | 103 | #define TPIPE 3 /* a | b */ |
104 | #define TLIST 4 /* a [&;] b */ | 104 | #define TLIST 4 /* a [&;] b */ |
105 | #define TOR 5 /* || */ | 105 | #define TOR 5 /* || */ |
106 | #define TAND 6 /* && */ | 106 | #define TAND 6 /* && */ |
107 | #define TFOR 7 | 107 | #define TFOR 7 |
108 | #define TDO 8 | 108 | #define TDO 8 |
109 | #define TCASE 9 | 109 | #define TCASE 9 |
@@ -111,40 +111,40 @@ struct op { | |||
111 | #define TWHILE 11 | 111 | #define TWHILE 11 |
112 | #define TUNTIL 12 | 112 | #define TUNTIL 12 |
113 | #define TELIF 13 | 113 | #define TELIF 13 |
114 | #define TPAT 14 /* pattern in case */ | 114 | #define TPAT 14 /* pattern in case */ |
115 | #define TBRACE 15 /* {c-list} */ | 115 | #define TBRACE 15 /* {c-list} */ |
116 | #define TASYNC 16 /* c & */ | 116 | #define TASYNC 16 /* c & */ |
117 | 117 | ||
118 | /* | 118 | /* |
119 | * actions determining the environment of a process | 119 | * actions determining the environment of a process |
120 | */ | 120 | */ |
121 | #define BIT(i) (1<<(i)) | 121 | #define BIT(i) (1<<(i)) |
122 | #define FEXEC BIT(0) /* execute without forking */ | 122 | #define FEXEC BIT(0) /* execute without forking */ |
123 | 123 | ||
124 | /* | 124 | /* |
125 | * flags to control evaluation of words | 125 | * flags to control evaluation of words |
126 | */ | 126 | */ |
127 | #define DOSUB 1 /* interpret $, `, and quotes */ | 127 | #define DOSUB 1 /* interpret $, `, and quotes */ |
128 | #define DOBLANK 2 /* perform blank interpretation */ | 128 | #define DOBLANK 2 /* perform blank interpretation */ |
129 | #define DOGLOB 4 /* interpret [?* */ | 129 | #define DOGLOB 4 /* interpret [?* */ |
130 | #define DOKEY 8 /* move words with `=' to 2nd arg. list */ | 130 | #define DOKEY 8 /* move words with `=' to 2nd arg. list */ |
131 | #define DOTRIM 16 /* trim resulting string */ | 131 | #define DOTRIM 16 /* trim resulting string */ |
132 | 132 | ||
133 | #define DOALL (DOSUB|DOBLANK|DOGLOB|DOKEY|DOTRIM) | 133 | #define DOALL (DOSUB|DOBLANK|DOGLOB|DOKEY|DOTRIM) |
134 | 134 | ||
135 | static char **dolv; | 135 | static char **dolv; |
136 | static int dolc; | 136 | static int dolc; |
137 | static int exstat; | 137 | static int exstat; |
138 | static char gflg; | 138 | static char gflg; |
139 | static int interactive; /* Is this an interactive shell */ | 139 | static int interactive; /* Is this an interactive shell */ |
140 | static int execflg; | 140 | static int execflg; |
141 | static int multiline; /* \n changed to ; */ | 141 | static int multiline; /* \n changed to ; */ |
142 | static struct op *outtree; /* result from parser */ | 142 | static struct op *outtree; /* result from parser */ |
143 | 143 | ||
144 | static xint *failpt; | 144 | static xint *failpt; |
145 | static xint *errpt; | 145 | static xint *errpt; |
146 | static struct brkcon *brklist; | 146 | static struct brkcon *brklist; |
147 | static int isbreak; | 147 | static int isbreak; |
148 | static int newfile(char *s); | 148 | static int newfile(char *s); |
149 | static char *findeq(char *cp); | 149 | static char *findeq(char *cp); |
150 | static char *cclass(char *p, int sub); | 150 | static char *cclass(char *p, int sub); |
@@ -152,42 +152,43 @@ static void initarea(void); | |||
152 | extern int msh_main(int argc, char **argv); | 152 | extern int msh_main(int argc, char **argv); |
153 | 153 | ||
154 | 154 | ||
155 | struct brkcon { | 155 | struct brkcon { |
156 | jmp_buf brkpt; | 156 | jmp_buf brkpt; |
157 | struct brkcon *nextlev; | 157 | struct brkcon *nextlev; |
158 | } ; | 158 | }; |
159 | 159 | ||
160 | /* | 160 | /* |
161 | * redirection | 161 | * redirection |
162 | */ | 162 | */ |
163 | struct ioword { | 163 | struct ioword { |
164 | short io_unit; /* unit affected */ | 164 | short io_unit; /* unit affected */ |
165 | short io_flag; /* action (below) */ | 165 | short io_flag; /* action (below) */ |
166 | char *io_name; /* file name */ | 166 | char *io_name; /* file name */ |
167 | }; | 167 | }; |
168 | #define IOREAD 1 /* < */ | ||
169 | #define IOHERE 2 /* << (here file) */ | ||
170 | #define IOWRITE 4 /* > */ | ||
171 | #define IOCAT 8 /* >> */ | ||
172 | #define IOXHERE 16 /* ${}, ` in << */ | ||
173 | #define IODUP 32 /* >&digit */ | ||
174 | #define IOCLOSE 64 /* >&- */ | ||
175 | 168 | ||
176 | #define IODEFAULT (-1) /* token for default IO unit */ | 169 | #define IOREAD 1 /* < */ |
170 | #define IOHERE 2 /* << (here file) */ | ||
171 | #define IOWRITE 4 /* > */ | ||
172 | #define IOCAT 8 /* >> */ | ||
173 | #define IOXHERE 16 /* ${}, ` in << */ | ||
174 | #define IODUP 32 /* >&digit */ | ||
175 | #define IOCLOSE 64 /* >&- */ | ||
176 | |||
177 | #define IODEFAULT (-1) /* token for default IO unit */ | ||
177 | 178 | ||
178 | static struct wdblock *wdlist; | 179 | static struct wdblock *wdlist; |
179 | static struct wdblock *iolist; | 180 | static struct wdblock *iolist; |
180 | 181 | ||
181 | /* | 182 | /* |
182 | * parsing & execution environment | 183 | * parsing & execution environment |
183 | */ | 184 | */ |
184 | static struct env { | 185 | static struct env { |
185 | char *linep; | 186 | char *linep; |
186 | struct io *iobase; | 187 | struct io *iobase; |
187 | struct io *iop; | 188 | struct io *iop; |
188 | xint *errpt; | 189 | xint *errpt; |
189 | int iofd; | 190 | int iofd; |
190 | struct env *oenv; | 191 | struct env *oenv; |
191 | } e; | 192 | } e; |
192 | 193 | ||
193 | /* | 194 | /* |
@@ -200,65 +201,65 @@ static struct env { | |||
200 | * -x: trace | 201 | * -x: trace |
201 | * -u: unset variables net diagnostic | 202 | * -u: unset variables net diagnostic |
202 | */ | 203 | */ |
203 | static char *flag; | 204 | static char *flag; |
204 | 205 | ||
205 | static char *null; /* null value for variable */ | 206 | static char *null; /* null value for variable */ |
206 | static int intr; /* interrupt pending */ | 207 | static int intr; /* interrupt pending */ |
207 | 208 | ||
208 | static char *trap[_NSIG+1]; | 209 | static char *trap[_NSIG + 1]; |
209 | static char ourtrap[_NSIG+1]; | 210 | static char ourtrap[_NSIG + 1]; |
210 | static int trapset; /* trap pending */ | 211 | static int trapset; /* trap pending */ |
211 | 212 | ||
212 | static int heedint; /* heed interrupt signals */ | 213 | static int heedint; /* heed interrupt signals */ |
213 | 214 | ||
214 | static int yynerrs; /* yacc */ | 215 | static int yynerrs; /* yacc */ |
215 | 216 | ||
216 | static char line[LINELIM]; | 217 | static char line[LINELIM]; |
217 | static char *elinep; | 218 | static char *elinep; |
218 | 219 | ||
219 | /* | 220 | /* |
220 | * other functions | 221 | * other functions |
221 | */ | 222 | */ |
222 | static int(*inbuilt(char *s))(struct op *); | 223 | static int (*inbuilt(char *s)) (struct op *); |
223 | 224 | ||
224 | 225 | ||
225 | static char *rexecve (char *c , char **v, char **envp ); | 226 | static char *rexecve(char *c, char **v, char **envp); |
226 | static char *space (int n ); | 227 | static char *space(int n); |
227 | static char *strsave (char *s, int a ); | 228 | static char *strsave(char *s, int a); |
228 | static char *evalstr (char *cp, int f ); | 229 | static char *evalstr(char *cp, int f); |
229 | static char *putn (int n ); | 230 | static char *putn(int n); |
230 | static char *itoa (int n ); | 231 | static char *itoa(int n); |
231 | static char *unquote (char *as ); | 232 | static char *unquote(char *as); |
232 | static struct var *lookup (char *n ); | 233 | static struct var *lookup(char *n); |
233 | static int rlookup (char *n ); | 234 | static int rlookup(char *n); |
234 | static struct wdblock *glob (char *cp, struct wdblock *wb ); | 235 | static struct wdblock *glob(char *cp, struct wdblock *wb); |
235 | static int my_getc( int ec); | 236 | static int my_getc(int ec); |
236 | static int subgetc (int ec, int quoted ); | 237 | static int subgetc(int ec, int quoted); |
237 | static char **makenv (void); | 238 | static char **makenv(void); |
238 | static char **eval (char **ap, int f ); | 239 | static char **eval(char **ap, int f); |
239 | static int setstatus (int s ); | 240 | static int setstatus(int s); |
240 | static int waitfor (int lastpid, int canintr ); | 241 | static int waitfor(int lastpid, int canintr); |
241 | 242 | ||
242 | static void onintr (int s ); /* SIGINT handler */ | 243 | static void onintr(int s); /* SIGINT handler */ |
243 | 244 | ||
244 | static int newenv (int f ); | 245 | static int newenv(int f); |
245 | static void quitenv (void); | 246 | static void quitenv(void); |
246 | static void err (char *s ); | 247 | static void err(char *s); |
247 | static int anys (char *s1, char *s2 ); | 248 | static int anys(char *s1, char *s2); |
248 | static int any (int c, char *s ); | 249 | static int any(int c, char *s); |
249 | static void next (int f ); | 250 | static void next(int f); |
250 | static void setdash (void); | 251 | static void setdash(void); |
251 | static void onecommand (void); | 252 | static void onecommand(void); |
252 | static void runtrap (int i ); | 253 | static void runtrap(int i); |
253 | static int gmatch (char *s, char *p ); | 254 | static int gmatch(char *s, char *p); |
254 | 255 | ||
255 | /* | 256 | /* |
256 | * error handling | 257 | * error handling |
257 | */ | 258 | */ |
258 | static void leave (void); /* abort shell (or fail in subshell) */ | 259 | static void leave(void); /* abort shell (or fail in subshell) */ |
259 | static void fail (void); /* fail but return to process next command */ | 260 | static void fail(void); /* fail but return to process next command */ |
260 | static void warn (char *s ); | 261 | static void warn(char *s); |
261 | static void sig (int i ); /* default signal handler */ | 262 | static void sig(int i); /* default signal handler */ |
262 | 263 | ||
263 | 264 | ||
264 | 265 | ||
@@ -266,7 +267,7 @@ static void sig (int i ); /* default signal handler */ | |||
266 | 267 | ||
267 | #define REGSIZE sizeof(struct region) | 268 | #define REGSIZE sizeof(struct region) |
268 | #define GROWBY 256 | 269 | #define GROWBY 256 |
269 | //#define SHRINKBY 64 | 270 | //#define SHRINKBY 64 |
270 | #undef SHRINKBY | 271 | #undef SHRINKBY |
271 | #define FREE 32767 | 272 | #define FREE 32767 |
272 | #define BUSY 0 | 273 | #define BUSY 0 |
@@ -274,19 +275,20 @@ static void sig (int i ); /* default signal handler */ | |||
274 | 275 | ||
275 | 276 | ||
276 | struct region { | 277 | struct region { |
277 | struct region *next; | 278 | struct region *next; |
278 | int area; | 279 | int area; |
279 | }; | 280 | }; |
280 | 281 | ||
281 | 282 | ||
282 | 283 | ||
283 | /* -------- grammar stuff -------- */ | 284 | /* -------- grammar stuff -------- */ |
284 | typedef union { | 285 | typedef union { |
285 | char *cp; | 286 | char *cp; |
286 | char **wp; | 287 | char **wp; |
287 | int i; | 288 | int i; |
288 | struct op *o; | 289 | struct op *o; |
289 | } YYSTYPE; | 290 | } YYSTYPE; |
291 | |||
290 | #define WORD 256 | 292 | #define WORD 256 |
291 | #define LOGAND 257 | 293 | #define LOGAND 257 |
292 | #define LOGOR 258 | 294 | #define LOGOR 258 |
@@ -307,113 +309,116 @@ typedef union { | |||
307 | #define YYERRCODE 300 | 309 | #define YYERRCODE 300 |
308 | 310 | ||
309 | /* flags to yylex */ | 311 | /* flags to yylex */ |
310 | #define CONTIN 01 /* skip new lines to complete command */ | 312 | #define CONTIN 01 /* skip new lines to complete command */ |
311 | 313 | ||
312 | #define SYNTAXERR zzerr() | 314 | #define SYNTAXERR zzerr() |
313 | static struct op *pipeline(int cf ); | 315 | static struct op *pipeline(int cf); |
314 | static struct op *andor(void); | 316 | static struct op *andor(void); |
315 | static struct op *c_list(void); | 317 | static struct op *c_list(void); |
316 | static int synio(int cf ); | 318 | static int synio(int cf); |
317 | static void musthave (int c, int cf ); | 319 | static void musthave(int c, int cf); |
318 | static struct op *simple(void); | 320 | static struct op *simple(void); |
319 | static struct op *nested(int type, int mark ); | 321 | static struct op *nested(int type, int mark); |
320 | static struct op *command(int cf ); | 322 | static struct op *command(int cf); |
321 | static struct op *dogroup(int onlydone ); | 323 | static struct op *dogroup(int onlydone); |
322 | static struct op *thenpart(void); | 324 | static struct op *thenpart(void); |
323 | static struct op *elsepart(void); | 325 | static struct op *elsepart(void); |
324 | static struct op *caselist(void); | 326 | static struct op *caselist(void); |
325 | static struct op *casepart(void); | 327 | static struct op *casepart(void); |
326 | static char **pattern(void); | 328 | static char **pattern(void); |
327 | static char **wordlist(void); | 329 | static char **wordlist(void); |
328 | static struct op *list(struct op *t1, struct op *t2 ); | 330 | static struct op *list(struct op *t1, struct op *t2); |
329 | static struct op *block(int type, struct op *t1, struct op *t2, char **wp ); | 331 | static struct op *block(int type, struct op *t1, struct op *t2, char **wp); |
330 | static struct op *newtp(void); | 332 | static struct op *newtp(void); |
331 | static struct op *namelist(struct op *t ); | 333 | static struct op *namelist(struct op *t); |
332 | static char **copyw(void); | 334 | static char **copyw(void); |
333 | static void word(char *cp ); | 335 | static void word(char *cp); |
334 | static struct ioword **copyio(void); | 336 | static struct ioword **copyio(void); |
335 | static struct ioword *io (int u, int f, char *cp ); | 337 | static struct ioword *io(int u, int f, char *cp); |
336 | static void zzerr(void); | 338 | static void zzerr(void); |
337 | static void yyerror(char *s ); | 339 | static void yyerror(char *s); |
338 | static int yylex(int cf ); | 340 | static int yylex(int cf); |
339 | static int collect(int c, int c1 ); | 341 | static int collect(int c, int c1); |
340 | static int dual(int c ); | 342 | static int dual(int c); |
341 | static void diag(int ec ); | 343 | static void diag(int ec); |
342 | static char *tree(unsigned size ); | 344 | static char *tree(unsigned size); |
343 | 345 | ||
344 | /* -------- var.h -------- */ | 346 | /* -------- var.h -------- */ |
345 | 347 | ||
346 | struct var { | 348 | struct var { |
347 | char *value; | 349 | char *value; |
348 | char *name; | 350 | char *name; |
349 | struct var *next; | 351 | struct var *next; |
350 | char status; | 352 | char status; |
351 | }; | 353 | }; |
352 | #define COPYV 1 /* flag to setval, suggesting copy */ | 354 | |
353 | #define RONLY 01 /* variable is read-only */ | 355 | #define COPYV 1 /* flag to setval, suggesting copy */ |
354 | #define EXPORT 02 /* variable is to be exported */ | 356 | #define RONLY 01 /* variable is read-only */ |
355 | #define GETCELL 04 /* name & value space was got with getcell */ | 357 | #define EXPORT 02 /* variable is to be exported */ |
356 | 358 | #define GETCELL 04 /* name & value space was got with getcell */ | |
357 | static struct var *vlist; /* dictionary */ | 359 | |
358 | 360 | static struct var *vlist; /* dictionary */ | |
359 | static struct var *homedir; /* home directory */ | 361 | |
360 | static struct var *prompt; /* main prompt */ | 362 | static struct var *homedir; /* home directory */ |
361 | static struct var *cprompt; /* continuation prompt */ | 363 | static struct var *prompt; /* main prompt */ |
362 | static struct var *path; /* search path for commands */ | 364 | static struct var *cprompt; /* continuation prompt */ |
363 | static struct var *shell; /* shell to interpret command files */ | 365 | static struct var *path; /* search path for commands */ |
364 | static struct var *ifs; /* field separators */ | 366 | static struct var *shell; /* shell to interpret command files */ |
365 | 367 | static struct var *ifs; /* field separators */ | |
366 | static int yyparse (void); | 368 | |
367 | static struct var *lookup (char *n ); | 369 | static int yyparse(void); |
368 | static void setval (struct var *vp, char *val ); | 370 | static struct var *lookup(char *n); |
369 | static void nameval (struct var *vp, char *val, char *name ); | 371 | static void setval(struct var *vp, char *val); |
370 | static void export (struct var *vp ); | 372 | static void nameval(struct var *vp, char *val, char *name); |
371 | static void ronly (struct var *vp ); | 373 | static void export(struct var *vp); |
372 | static int isassign (char *s ); | 374 | static void ronly(struct var *vp); |
373 | static int checkname (char *cp ); | 375 | static int isassign(char *s); |
374 | static int assign (char *s, int cf ); | 376 | static int checkname(char *cp); |
375 | static void putvlist (int f, int out ); | 377 | static int assign(char *s, int cf); |
376 | static int eqname (char *n1, char *n2 ); | 378 | static void putvlist(int f, int out); |
377 | 379 | static int eqname(char *n1, char *n2); | |
378 | static int execute (struct op *t, int *pin, int *pout, int act ); | 380 | |
381 | static int execute(struct op *t, int *pin, int *pout, int act); | ||
379 | 382 | ||
380 | /* -------- io.h -------- */ | 383 | /* -------- io.h -------- */ |
381 | /* io buffer */ | 384 | /* io buffer */ |
382 | struct iobuf { | 385 | struct iobuf { |
383 | unsigned id; /* buffer id */ | 386 | unsigned id; /* buffer id */ |
384 | char buf[512]; /* buffer */ | 387 | char buf[512]; /* buffer */ |
385 | char *bufp; /* pointer into buffer */ | 388 | char *bufp; /* pointer into buffer */ |
386 | char *ebufp; /* pointer to end of buffer */ | 389 | char *ebufp; /* pointer to end of buffer */ |
387 | }; | 390 | }; |
388 | 391 | ||
389 | /* possible arguments to an IO function */ | 392 | /* possible arguments to an IO function */ |
390 | struct ioarg { | 393 | struct ioarg { |
391 | char *aword; | 394 | char *aword; |
392 | char **awordlist; | 395 | char **awordlist; |
393 | int afile; /* file descriptor */ | 396 | int afile; /* file descriptor */ |
394 | unsigned afid; /* buffer id */ | 397 | unsigned afid; /* buffer id */ |
395 | long afpos; /* file position */ | 398 | long afpos; /* file position */ |
396 | struct iobuf *afbuf; /* buffer for this file */ | 399 | struct iobuf *afbuf; /* buffer for this file */ |
397 | }; | 400 | }; |
401 | |||
398 | //static struct ioarg ioargstack[NPUSH]; | 402 | //static struct ioarg ioargstack[NPUSH]; |
399 | #define AFID_NOBUF (~0) | 403 | #define AFID_NOBUF (~0) |
400 | #define AFID_ID 0 | 404 | #define AFID_ID 0 |
401 | 405 | ||
402 | /* an input generator's state */ | 406 | /* an input generator's state */ |
403 | struct io { | 407 | struct io { |
404 | int (*iofn)(struct ioarg *, struct io *); | 408 | int (*iofn) (struct ioarg *, struct io *); |
405 | struct ioarg *argp; | 409 | struct ioarg *argp; |
406 | int peekc; | 410 | int peekc; |
407 | char prev; /* previous character read by readc() */ | 411 | char prev; /* previous character read by readc() */ |
408 | char nlcount; /* for `'s */ | 412 | char nlcount; /* for `'s */ |
409 | char xchar; /* for `'s */ | 413 | char xchar; /* for `'s */ |
410 | char task; /* reason for pushed IO */ | 414 | char task; /* reason for pushed IO */ |
411 | }; | 415 | }; |
412 | //static struct io iostack[NPUSH]; | 416 | |
413 | #define XOTHER 0 /* none of the below */ | 417 | //static struct io iostack[NPUSH]; |
414 | #define XDOLL 1 /* expanding ${} */ | 418 | #define XOTHER 0 /* none of the below */ |
415 | #define XGRAVE 2 /* expanding `'s */ | 419 | #define XDOLL 1 /* expanding ${} */ |
416 | #define XIO 3 /* file IO */ | 420 | #define XGRAVE 2 /* expanding `'s */ |
421 | #define XIO 3 /* file IO */ | ||
417 | 422 | ||
418 | /* in substitution */ | 423 | /* in substitution */ |
419 | #define INSUB() (e.iop->task == XGRAVE || e.iop->task == XDOLL) | 424 | #define INSUB() (e.iop->task == XGRAVE || e.iop->task == XDOLL) |
@@ -421,75 +426,76 @@ struct io { | |||
421 | /* | 426 | /* |
422 | * input generators for IO structure | 427 | * input generators for IO structure |
423 | */ | 428 | */ |
424 | static int nlchar (struct ioarg *ap ); | 429 | static int nlchar(struct ioarg *ap); |
425 | static int strchar (struct ioarg *ap ); | 430 | static int strchar(struct ioarg *ap); |
426 | static int qstrchar (struct ioarg *ap ); | 431 | static int qstrchar(struct ioarg *ap); |
427 | static int filechar (struct ioarg *ap ); | 432 | static int filechar(struct ioarg *ap); |
428 | static int herechar (struct ioarg *ap ); | 433 | static int herechar(struct ioarg *ap); |
429 | static int linechar (struct ioarg *ap ); | 434 | static int linechar(struct ioarg *ap); |
430 | static int gravechar (struct ioarg *ap, struct io *iop ); | 435 | static int gravechar(struct ioarg *ap, struct io *iop); |
431 | static int qgravechar (struct ioarg *ap, struct io *iop ); | 436 | static int qgravechar(struct ioarg *ap, struct io *iop); |
432 | static int dolchar (struct ioarg *ap ); | 437 | static int dolchar(struct ioarg *ap); |
433 | static int wdchar (struct ioarg *ap ); | 438 | static int wdchar(struct ioarg *ap); |
434 | static void scraphere (void); | 439 | static void scraphere(void); |
435 | static void freehere (int area ); | 440 | static void freehere(int area); |
436 | static void gethere (void); | 441 | static void gethere(void); |
437 | static void markhere (char *s, struct ioword *iop ); | 442 | static void markhere(char *s, struct ioword *iop); |
438 | static int herein (char *hname, int xdoll ); | 443 | static int herein(char *hname, int xdoll); |
439 | static int run (struct ioarg *argp, int (*f)(struct ioarg *)); | 444 | static int run(struct ioarg *argp, int (*f) (struct ioarg *)); |
440 | 445 | ||
441 | /* | 446 | /* |
442 | * IO functions | 447 | * IO functions |
443 | */ | 448 | */ |
444 | static int eofc (void); | 449 | static int eofc(void); |
445 | static int readc (void); | 450 | static int readc(void); |
446 | static void unget (int c ); | 451 | static void unget(int c); |
447 | static void ioecho (int c ); | 452 | static void ioecho(int c); |
448 | static void prs (char *s ); | 453 | static void prs(char *s); |
449 | static void prn (unsigned u ); | 454 | static void prn(unsigned u); |
450 | static void closef (int i ); | 455 | static void closef(int i); |
451 | static void closeall (void); | 456 | static void closeall(void); |
452 | 457 | ||
453 | /* | 458 | /* |
454 | * IO control | 459 | * IO control |
455 | */ | 460 | */ |
456 | static void pushio (struct ioarg *argp, int (*f)(struct ioarg *)); | 461 | static void pushio(struct ioarg *argp, int (*f) (struct ioarg *)); |
457 | static int remap (int fd ); | 462 | static int remap(int fd); |
458 | static int openpipe (int *pv ); | 463 | static int openpipe(int *pv); |
459 | static void closepipe (int *pv ); | 464 | static void closepipe(int *pv); |
460 | static struct io *setbase (struct io *ip ); | 465 | static struct io *setbase(struct io *ip); |
466 | |||
467 | static struct ioarg temparg; /* temporary for PUSHIO */ | ||
461 | 468 | ||
462 | static struct ioarg temparg; /* temporary for PUSHIO */ | ||
463 | #define PUSHIO(what,arg,gen) ((temparg.what = (arg)),pushio(&temparg,(gen))) | 469 | #define PUSHIO(what,arg,gen) ((temparg.what = (arg)),pushio(&temparg,(gen))) |
464 | #define RUN(what,arg,gen) ((temparg.what = (arg)), run(&temparg,(gen))) | 470 | #define RUN(what,arg,gen) ((temparg.what = (arg)), run(&temparg,(gen))) |
465 | 471 | ||
466 | /* -------- word.h -------- */ | 472 | /* -------- word.h -------- */ |
467 | 473 | ||
468 | #define NSTART 16 /* default number of words to allow for initially */ | 474 | #define NSTART 16 /* default number of words to allow for initially */ |
469 | 475 | ||
470 | struct wdblock { | 476 | struct wdblock { |
471 | short w_bsize; | 477 | short w_bsize; |
472 | short w_nword; | 478 | short w_nword; |
473 | /* bounds are arbitrary */ | 479 | /* bounds are arbitrary */ |
474 | char *w_words[1]; | 480 | char *w_words[1]; |
475 | }; | 481 | }; |
476 | 482 | ||
477 | static struct wdblock *addword (char *wd, struct wdblock *wb ); | 483 | static struct wdblock *addword(char *wd, struct wdblock *wb); |
478 | static struct wdblock *newword (int nw ); | 484 | static struct wdblock *newword(int nw); |
479 | static char **getwords (struct wdblock *wb ); | 485 | static char **getwords(struct wdblock *wb); |
480 | 486 | ||
481 | /* -------- area.h -------- */ | 487 | /* -------- area.h -------- */ |
482 | 488 | ||
483 | /* | 489 | /* |
484 | * storage allocation | 490 | * storage allocation |
485 | */ | 491 | */ |
486 | static char *getcell (unsigned nbytes ); | 492 | static char *getcell(unsigned nbytes); |
487 | static void garbage (void); | 493 | static void garbage(void); |
488 | static void setarea (char *cp, int a ); | 494 | static void setarea(char *cp, int a); |
489 | static int getarea (char *cp ); | 495 | static int getarea(char *cp); |
490 | static void freearea (int a ); | 496 | static void freearea(int a); |
491 | static void freecell (char *cp ); | 497 | static void freecell(char *cp); |
492 | static int areanum; /* current allocation area */ | 498 | static int areanum; /* current allocation area */ |
493 | 499 | ||
494 | #define NEW(type) (type *)getcell(sizeof(type)) | 500 | #define NEW(type) (type *)getcell(sizeof(type)) |
495 | #define DELETE(obj) freecell((char *)obj) | 501 | #define DELETE(obj) freecell((char *)obj) |
@@ -497,65 +503,67 @@ static int areanum; /* current allocation area */ | |||
497 | 503 | ||
498 | /* -------- misc stuff -------- */ | 504 | /* -------- misc stuff -------- */ |
499 | 505 | ||
500 | static int forkexec (struct op *t, int *pin, int *pout, int act, char **wp, int *pforked ); | 506 | static int forkexec(struct op *t, int *pin, int *pout, int act, char **wp, |
501 | static int iosetup (struct ioword *iop, int pipein, int pipeout ); | 507 | int *pforked); |
502 | static void echo(char **wp ); | 508 | static int iosetup(struct ioword *iop, int pipein, int pipeout); |
503 | static struct op **find1case (struct op *t, char *w ); | 509 | static void echo(char **wp); |
504 | static struct op *findcase (struct op *t, char *w ); | 510 | static struct op **find1case(struct op *t, char *w); |
505 | static void brkset(struct brkcon *bc ); | 511 | static struct op *findcase(struct op *t, char *w); |
506 | static int dolabel(struct op *t ); | 512 | static void brkset(struct brkcon *bc); |
507 | static int dohelp(struct op *t ); | 513 | static int dolabel(struct op *t); |
508 | static int dochdir(struct op *t ); | 514 | static int dohelp(struct op *t); |
509 | static int doshift(struct op *t ); | 515 | static int dochdir(struct op *t); |
510 | static int dologin(struct op *t ); | 516 | static int doshift(struct op *t); |
511 | static int doumask(struct op *t ); | 517 | static int dologin(struct op *t); |
512 | static int doexec(struct op *t ); | 518 | static int doumask(struct op *t); |
513 | static int dodot(struct op *t ); | 519 | static int doexec(struct op *t); |
514 | static int dowait(struct op *t ); | 520 | static int dodot(struct op *t); |
515 | static int doread(struct op *t ); | 521 | static int dowait(struct op *t); |
516 | static int doeval(struct op *t ); | 522 | static int doread(struct op *t); |
517 | static int dotrap(struct op *t ); | 523 | static int doeval(struct op *t); |
518 | static int getsig(char *s ); | 524 | static int dotrap(struct op *t); |
519 | static void setsig (int n, sighandler_t f); | 525 | static int getsig(char *s); |
520 | static int getn(char *as ); | 526 | static void setsig(int n, sighandler_t f); |
521 | static int dobreak(struct op *t ); | 527 | static int getn(char *as); |
522 | static int docontinue(struct op *t ); | 528 | static int dobreak(struct op *t); |
523 | static int brkcontin (char *cp, int val ); | 529 | static int docontinue(struct op *t); |
524 | static int doexit(struct op *t ); | 530 | static int brkcontin(char *cp, int val); |
525 | static int doexport(struct op *t ); | 531 | static int doexit(struct op *t); |
526 | static int doreadonly(struct op *t ); | 532 | static int doexport(struct op *t); |
527 | static void rdexp (char **wp, void (*f)(struct var *), int key); | 533 | static int doreadonly(struct op *t); |
528 | static void badid(char *s ); | 534 | static void rdexp(char **wp, void (*f) (struct var *), int key); |
529 | static int doset(struct op *t ); | 535 | static void badid(char *s); |
530 | static void varput (char *s, int out ); | 536 | static int doset(struct op *t); |
531 | static int dotimes(struct op *t ); | 537 | static void varput(char *s, int out); |
532 | static int expand (char *cp, struct wdblock **wbp, int f ); | 538 | static int dotimes(struct op *t); |
533 | static char *blank(int f ); | 539 | static int expand(char *cp, struct wdblock **wbp, int f); |
534 | static int dollar(int quoted ); | 540 | static char *blank(int f); |
535 | static int grave(int quoted ); | 541 | static int dollar(int quoted); |
536 | static void globname (char *we, char *pp ); | 542 | static int grave(int quoted); |
537 | static char *generate (char *start1, char *end1, char *middle, char *end ); | 543 | static void globname(char *we, char *pp); |
538 | static int anyspcl(struct wdblock *wb ); | 544 | static char *generate(char *start1, char *end1, char *middle, char *end); |
539 | static int xstrcmp (char *p1, char *p2 ); | 545 | static int anyspcl(struct wdblock *wb); |
540 | static void glob0 (char *a0, unsigned int a1, int a2, int (*a3)(char *, char *)); | 546 | static int xstrcmp(char *p1, char *p2); |
541 | static void glob1 (char *base, char *lim ); | 547 | static void glob0(char *a0, unsigned int a1, int a2, |
542 | static void glob2 (char *i, char *j ); | 548 | int (*a3) (char *, char *)); |
543 | static void glob3 (char *i, char *j, char *k ); | 549 | static void glob1(char *base, char *lim); |
544 | static void readhere (char **name, char *s, int ec ); | 550 | static void glob2(char *i, char *j); |
545 | static void pushio (struct ioarg *argp, int (*f)(struct ioarg *)); | 551 | static void glob3(char *i, char *j, char *k); |
546 | static int xxchar(struct ioarg *ap ); | 552 | static void readhere(char **name, char *s, int ec); |
547 | 553 | static void pushio(struct ioarg *argp, int (*f) (struct ioarg *)); | |
548 | struct here { | 554 | static int xxchar(struct ioarg *ap); |
549 | char *h_tag; | 555 | |
550 | int h_dosub; | 556 | struct here { |
551 | struct ioword *h_iop; | 557 | char *h_tag; |
552 | struct here *h_next; | 558 | int h_dosub; |
559 | struct ioword *h_iop; | ||
560 | struct here *h_next; | ||
553 | }; | 561 | }; |
554 | 562 | ||
555 | static char *signame[] = { | 563 | static char *signame[] = { |
556 | "Signal 0", | 564 | "Signal 0", |
557 | "Hangup", | 565 | "Hangup", |
558 | (char *)NULL, /* interrupt */ | 566 | (char *) NULL, /* interrupt */ |
559 | "Quit", | 567 | "Quit", |
560 | "Illegal instruction", | 568 | "Illegal instruction", |
561 | "Trace/BPT trap", | 569 | "Trace/BPT trap", |
@@ -566,128 +574,131 @@ static char *signame[] = { | |||
566 | "SIGUSR1", | 574 | "SIGUSR1", |
567 | "SIGSEGV", | 575 | "SIGSEGV", |
568 | "SIGUSR2", | 576 | "SIGUSR2", |
569 | (char *)NULL, /* broken pipe */ | 577 | (char *) NULL, /* broken pipe */ |
570 | "Alarm clock", | 578 | "Alarm clock", |
571 | "Terminated", | 579 | "Terminated", |
572 | }; | 580 | }; |
581 | |||
573 | #define NSIGNAL (sizeof(signame)/sizeof(signame[0])) | 582 | #define NSIGNAL (sizeof(signame)/sizeof(signame[0])) |
574 | 583 | ||
575 | struct res { | 584 | struct res { |
576 | char *r_name; | 585 | char *r_name; |
577 | int r_val; | 586 | int r_val; |
578 | }; | 587 | }; |
579 | static struct res restab[] = { | 588 | static struct res restab[] = { |
580 | {"for", FOR}, | 589 | {"for", FOR}, |
581 | {"case", CASE}, | 590 | {"case", CASE}, |
582 | {"esac", ESAC}, | 591 | {"esac", ESAC}, |
583 | {"while", WHILE}, | 592 | {"while", WHILE}, |
584 | {"do", DO}, | 593 | {"do", DO}, |
585 | {"done", DONE}, | 594 | {"done", DONE}, |
586 | {"if", IF}, | 595 | {"if", IF}, |
587 | {"in", IN}, | 596 | {"in", IN}, |
588 | {"then", THEN}, | 597 | {"then", THEN}, |
589 | {"else", ELSE}, | 598 | {"else", ELSE}, |
590 | {"elif", ELIF}, | 599 | {"elif", ELIF}, |
591 | {"until", UNTIL}, | 600 | {"until", UNTIL}, |
592 | {"fi", FI}, | 601 | {"fi", FI}, |
593 | 602 | ||
594 | {";;", BREAK}, | 603 | {";;", BREAK}, |
595 | {"||", LOGOR}, | 604 | {"||", LOGOR}, |
596 | {"&&", LOGAND}, | 605 | {"&&", LOGAND}, |
597 | {"{", '{'}, | 606 | {"{", '{'}, |
598 | {"}", '}'}, | 607 | {"}", '}'}, |
599 | {0, 0}, | 608 | {0, 0}, |
600 | }; | 609 | }; |
601 | 610 | ||
602 | 611 | ||
603 | struct builtincmd { | 612 | struct builtincmd { |
604 | const char *name; | 613 | const char *name; |
605 | int (*builtinfunc)(struct op *t); | 614 | int (*builtinfunc) (struct op * t); |
606 | }; | 615 | }; |
607 | static const struct builtincmd builtincmds[] = { | 616 | static const struct builtincmd builtincmds[] = { |
608 | {".", dodot}, | 617 | {".", dodot}, |
609 | {":", dolabel}, | 618 | {":", dolabel}, |
610 | {"break", dobreak}, | 619 | {"break", dobreak}, |
611 | {"cd", dochdir}, | 620 | {"cd", dochdir}, |
612 | {"continue",docontinue}, | 621 | {"continue", docontinue}, |
613 | {"eval", doeval}, | 622 | {"eval", doeval}, |
614 | {"exec", doexec}, | 623 | {"exec", doexec}, |
615 | {"exit", doexit}, | 624 | {"exit", doexit}, |
616 | {"export", doexport}, | 625 | {"export", doexport}, |
617 | {"help", dohelp}, | 626 | {"help", dohelp}, |
618 | {"login", dologin}, | 627 | {"login", dologin}, |
619 | {"newgrp", dologin}, | 628 | {"newgrp", dologin}, |
620 | {"read", doread}, | 629 | {"read", doread}, |
621 | {"readonly",doreadonly}, | 630 | {"readonly", doreadonly}, |
622 | {"set", doset}, | 631 | {"set", doset}, |
623 | {"shift", doshift}, | 632 | {"shift", doshift}, |
624 | {"times", dotimes}, | 633 | {"times", dotimes}, |
625 | {"trap", dotrap}, | 634 | {"trap", dotrap}, |
626 | {"umask", doumask}, | 635 | {"umask", doumask}, |
627 | {"wait", dowait}, | 636 | {"wait", dowait}, |
628 | {0,0} | 637 | {0, 0} |
629 | }; | 638 | }; |
630 | 639 | ||
631 | /* Globals */ | 640 | /* Globals */ |
632 | extern char **environ; /* environment pointer */ | 641 | extern char **environ; /* environment pointer */ |
633 | static char **dolv; | 642 | static char **dolv; |
634 | static int dolc; | 643 | static int dolc; |
635 | static int exstat; | 644 | static int exstat; |
636 | static char gflg; | 645 | static char gflg; |
637 | static int interactive; /* Is this an interactive shell */ | 646 | static int interactive; /* Is this an interactive shell */ |
638 | static int execflg; | 647 | static int execflg; |
639 | static int multiline; /* \n changed to ; */ | 648 | static int multiline; /* \n changed to ; */ |
640 | static struct op *outtree; /* result from parser */ | 649 | static struct op *outtree; /* result from parser */ |
641 | static xint *failpt; | 650 | static xint *failpt; |
642 | static xint *errpt; | 651 | static xint *errpt; |
643 | static struct brkcon *brklist; | 652 | static struct brkcon *brklist; |
644 | static int isbreak; | 653 | static int isbreak; |
645 | static struct wdblock *wdlist; | 654 | static struct wdblock *wdlist; |
646 | static struct wdblock *iolist; | 655 | static struct wdblock *iolist; |
647 | static char *trap[_NSIG+1]; | 656 | static char *trap[_NSIG + 1]; |
648 | static char ourtrap[_NSIG+1]; | 657 | static char ourtrap[_NSIG + 1]; |
649 | static int trapset; /* trap pending */ | 658 | static int trapset; /* trap pending */ |
650 | static int yynerrs; /* yacc */ | 659 | static int yynerrs; /* yacc */ |
651 | static char line[LINELIM]; | 660 | static char line[LINELIM]; |
652 | static struct var *vlist; /* dictionary */ | 661 | static struct var *vlist; /* dictionary */ |
653 | static struct var *homedir; /* home directory */ | 662 | static struct var *homedir; /* home directory */ |
654 | static struct var *prompt; /* main prompt */ | 663 | static struct var *prompt; /* main prompt */ |
655 | static struct var *cprompt; /* continuation prompt */ | 664 | static struct var *cprompt; /* continuation prompt */ |
656 | static struct var *path; /* search path for commands */ | 665 | static struct var *path; /* search path for commands */ |
657 | static struct var *shell; /* shell to interpret command files */ | 666 | static struct var *shell; /* shell to interpret command files */ |
658 | static struct var *ifs; /* field separators */ | 667 | static struct var *ifs; /* field separators */ |
659 | static struct ioarg ioargstack[NPUSH]; | 668 | static struct ioarg ioargstack[NPUSH]; |
660 | static struct io iostack[NPUSH]; | 669 | static struct io iostack[NPUSH]; |
661 | static int areanum; /* current allocation area */ | 670 | static int areanum; /* current allocation area */ |
662 | static int intr; | 671 | static int intr; |
663 | static int inparse; | 672 | static int inparse; |
664 | static char flags['z'-'a'+1]; | 673 | static char flags['z' - 'a' + 1]; |
665 | static char *flag = flags-'a'; | 674 | static char *flag = flags - 'a'; |
666 | static char *elinep = line+sizeof(line)-5; | 675 | static char *elinep = line + sizeof(line) - 5; |
667 | static char *null = ""; | 676 | static char *null = ""; |
668 | static int heedint =1; | 677 | static int heedint = 1; |
669 | static struct env e ={line, iostack, iostack-1, (xint *)NULL, FDBASE, (struct env *)NULL}; | 678 | static struct env e = |
670 | static void (*qflag)(int) = SIG_IGN; | 679 | { line, iostack, iostack - 1, (xint *) NULL, FDBASE, |
671 | static int startl; | 680 | (struct env *) NULL }; |
672 | static int peeksym; | 681 | static void (*qflag) (int) = SIG_IGN; |
673 | static int nlseen; | 682 | static int startl; |
674 | static int iounit = IODEFAULT; | 683 | static int peeksym; |
675 | static YYSTYPE yylval; | 684 | static int nlseen; |
676 | static struct iobuf sharedbuf = {AFID_NOBUF}; | 685 | static int iounit = IODEFAULT; |
677 | static struct iobuf mainbuf = {AFID_NOBUF}; | 686 | static YYSTYPE yylval; |
687 | static struct iobuf sharedbuf = { AFID_NOBUF }; | ||
688 | static struct iobuf mainbuf = { AFID_NOBUF }; | ||
678 | static unsigned bufid = AFID_ID; /* buffer id counter */ | 689 | static unsigned bufid = AFID_ID; /* buffer id counter */ |
679 | static struct ioarg temparg = {0, 0, 0, AFID_NOBUF, 0}; | 690 | static struct ioarg temparg = { 0, 0, 0, AFID_NOBUF, 0 }; |
680 | static struct here *inhere; /* list of hear docs while parsing */ | 691 | static struct here *inhere; /* list of hear docs while parsing */ |
681 | static struct here *acthere; /* list of active here documents */ | 692 | static struct here *acthere; /* list of active here documents */ |
682 | static struct region *areabot; /* bottom of area */ | 693 | static struct region *areabot; /* bottom of area */ |
683 | static struct region *areatop; /* top of area */ | 694 | static struct region *areatop; /* top of area */ |
684 | static struct region *areanxt; /* starting point of scan */ | 695 | static struct region *areanxt; /* starting point of scan */ |
685 | static void * brktop; | 696 | static void *brktop; |
686 | static void * brkaddr; | 697 | static void *brkaddr; |
687 | 698 | ||
688 | 699 | ||
689 | #ifdef CONFIG_FEATURE_COMMAND_EDITING | 700 | #ifdef CONFIG_FEATURE_COMMAND_EDITING |
690 | static char * current_prompt; | 701 | static char *current_prompt; |
691 | #endif | 702 | #endif |
692 | 703 | ||
693 | /* -------- sh.c -------- */ | 704 | /* -------- sh.c -------- */ |
@@ -702,7 +713,7 @@ extern int msh_main(int argc, char **argv) | |||
702 | register char *s; | 713 | register char *s; |
703 | int cflag; | 714 | int cflag; |
704 | char *name, **ap; | 715 | char *name, **ap; |
705 | int (*iof)(struct ioarg *); | 716 | int (*iof) (struct ioarg *); |
706 | 717 | ||
707 | initarea(); | 718 | initarea(); |
708 | if ((ap = environ) != NULL) { | 719 | if ((ap = environ) != NULL) { |
@@ -758,8 +769,8 @@ extern int msh_main(int argc, char **argv) | |||
758 | cflag = 0; | 769 | cflag = 0; |
759 | name = *argv++; | 770 | name = *argv++; |
760 | if (--argc >= 1) { | 771 | if (--argc >= 1) { |
761 | if(argv[0][0] == '-' && argv[0][1] != '\0') { | 772 | if (argv[0][0] == '-' && argv[0][1] != '\0') { |
762 | for (s = argv[0]+1; *s; s++) | 773 | for (s = argv[0] + 1; *s; s++) |
763 | switch (*s) { | 774 | switch (*s) { |
764 | case 'c': | 775 | case 'c': |
765 | prompt->status &= ~EXPORT; | 776 | prompt->status &= ~EXPORT; |
@@ -788,8 +799,8 @@ extern int msh_main(int argc, char **argv) | |||
788 | case 'i': | 799 | case 'i': |
789 | interactive++; | 800 | interactive++; |
790 | default: | 801 | default: |
791 | if (*s>='a' && *s<='z') | 802 | if (*s >= 'a' && *s <= 'z') |
792 | flag[(int)*s]++; | 803 | flag[(int) *s]++; |
793 | } | 804 | } |
794 | } else { | 805 | } else { |
795 | argv--; | 806 | argv--; |
@@ -810,8 +821,8 @@ extern int msh_main(int argc, char **argv) | |||
810 | if (isatty(0) && isatty(1) && !cflag) { | 821 | if (isatty(0) && isatty(1) && !cflag) { |
811 | interactive++; | 822 | interactive++; |
812 | #ifndef CONFIG_FEATURE_SH_EXTRA_QUIET | 823 | #ifndef CONFIG_FEATURE_SH_EXTRA_QUIET |
813 | printf( "\n\n" BB_BANNER " Built-in shell (msh)\n"); | 824 | printf("\n\n" BB_BANNER " Built-in shell (msh)\n"); |
814 | printf( "Enter 'help' for a list of built-in commands.\n\n"); | 825 | printf("Enter 'help' for a list of built-in commands.\n\n"); |
815 | #endif | 826 | #endif |
816 | } | 827 | } |
817 | } | 828 | } |
@@ -833,7 +844,7 @@ extern int msh_main(int argc, char **argv) | |||
833 | if (dolc > 1) { | 844 | if (dolc > 1) { |
834 | for (ap = ++argv; --argc > 0;) { | 845 | for (ap = ++argv; --argc > 0;) { |
835 | if (assign(*ap = *argv++, !COPYV)) { | 846 | if (assign(*ap = *argv++, !COPYV)) { |
836 | dolc--; /* keyword */ | 847 | dolc--; /* keyword */ |
837 | } else { | 848 | } else { |
838 | ap++; | 849 | ap++; |
839 | } | 850 | } |
@@ -844,7 +855,7 @@ extern int msh_main(int argc, char **argv) | |||
844 | for (;;) { | 855 | for (;;) { |
845 | if (interactive && e.iop <= iostack) { | 856 | if (interactive && e.iop <= iostack) { |
846 | #ifdef CONFIG_FEATURE_COMMAND_EDITING | 857 | #ifdef CONFIG_FEATURE_COMMAND_EDITING |
847 | current_prompt=prompt->value; | 858 | current_prompt = prompt->value; |
848 | #else | 859 | #else |
849 | prs(prompt->value); | 860 | prs(prompt->value); |
850 | #endif | 861 | #endif |
@@ -855,23 +866,21 @@ extern int msh_main(int argc, char **argv) | |||
855 | } | 866 | } |
856 | } | 867 | } |
857 | 868 | ||
858 | static void | 869 | static void setdash() |
859 | setdash() | ||
860 | { | 870 | { |
861 | register char *cp; | 871 | register char *cp; |
862 | register int c; | 872 | register int c; |
863 | char m['z'-'a'+1]; | 873 | char m['z' - 'a' + 1]; |
864 | 874 | ||
865 | cp = m; | 875 | cp = m; |
866 | for (c='a'; c<='z'; c++) | 876 | for (c = 'a'; c <= 'z'; c++) |
867 | if (flag[(int)c]) | 877 | if (flag[(int) c]) |
868 | *cp++ = c; | 878 | *cp++ = c; |
869 | *cp = 0; | 879 | *cp = 0; |
870 | setval(lookup("-"), m); | 880 | setval(lookup("-"), m); |
871 | } | 881 | } |
872 | 882 | ||
873 | static int | 883 | static int newfile(s) |
874 | newfile(s) | ||
875 | register char *s; | 884 | register char *s; |
876 | { | 885 | { |
877 | register int f; | 886 | register int f; |
@@ -881,16 +890,15 @@ register char *s; | |||
881 | if (f < 0) { | 890 | if (f < 0) { |
882 | prs(s); | 891 | prs(s); |
883 | err(": cannot open"); | 892 | err(": cannot open"); |
884 | return(1); | 893 | return (1); |
885 | } | 894 | } |
886 | } else | 895 | } else |
887 | f = 0; | 896 | f = 0; |
888 | next(remap(f)); | 897 | next(remap(f)); |
889 | return(0); | 898 | return (0); |
890 | } | 899 | } |
891 | 900 | ||
892 | static void | 901 | static void onecommand() |
893 | onecommand() | ||
894 | { | 902 | { |
895 | register int i; | 903 | register int i; |
896 | jmp_buf m1; | 904 | jmp_buf m1; |
@@ -910,7 +918,7 @@ onecommand() | |||
910 | inparse = 1; | 918 | inparse = 1; |
911 | intr = 0; | 919 | intr = 0; |
912 | execflg = 0; | 920 | execflg = 0; |
913 | setjmp(failpt = m1); /* Bruce Evans' fix */ | 921 | setjmp(failpt = m1); /* Bruce Evans' fix */ |
914 | if (setjmp(failpt = m1) || yyparse() || intr) { | 922 | if (setjmp(failpt = m1) || yyparse() || intr) { |
915 | while (e.oenv) | 923 | while (e.oenv) |
916 | quitenv(); | 924 | quitenv(); |
@@ -937,15 +945,13 @@ onecommand() | |||
937 | } | 945 | } |
938 | } | 946 | } |
939 | 947 | ||
940 | static void | 948 | static void fail() |
941 | fail() | ||
942 | { | 949 | { |
943 | longjmp(failpt, 1); | 950 | longjmp(failpt, 1); |
944 | /* NOTREACHED */ | 951 | /* NOTREACHED */ |
945 | } | 952 | } |
946 | 953 | ||
947 | static void | 954 | static void leave() |
948 | leave() | ||
949 | { | 955 | { |
950 | if (execflg) | 956 | if (execflg) |
951 | fail(); | 957 | fail(); |
@@ -956,11 +962,10 @@ leave() | |||
956 | /* NOTREACHED */ | 962 | /* NOTREACHED */ |
957 | } | 963 | } |
958 | 964 | ||
959 | static void | 965 | static void warn(s) |
960 | warn(s) | ||
961 | register char *s; | 966 | register char *s; |
962 | { | 967 | { |
963 | if(*s) { | 968 | if (*s) { |
964 | prs(s); | 969 | prs(s); |
965 | exstat = -1; | 970 | exstat = -1; |
966 | } | 971 | } |
@@ -969,8 +974,7 @@ register char *s; | |||
969 | leave(); | 974 | leave(); |
970 | } | 975 | } |
971 | 976 | ||
972 | static void | 977 | static void err(s) |
973 | err(s) | ||
974 | char *s; | 978 | char *s; |
975 | { | 979 | { |
976 | warn(s); | 980 | warn(s); |
@@ -984,15 +988,14 @@ char *s; | |||
984 | e.iop = e.iobase = iostack; | 988 | e.iop = e.iobase = iostack; |
985 | } | 989 | } |
986 | 990 | ||
987 | static int | 991 | static int newenv(f) |
988 | newenv(f) | ||
989 | int f; | 992 | int f; |
990 | { | 993 | { |
991 | register struct env *ep; | 994 | register struct env *ep; |
992 | 995 | ||
993 | if (f) { | 996 | if (f) { |
994 | quitenv(); | 997 | quitenv(); |
995 | return(1); | 998 | return (1); |
996 | } | 999 | } |
997 | ep = (struct env *) space(sizeof(*ep)); | 1000 | ep = (struct env *) space(sizeof(*ep)); |
998 | if (ep == NULL) { | 1001 | if (ep == NULL) { |
@@ -1003,11 +1006,10 @@ int f; | |||
1003 | *ep = e; | 1006 | *ep = e; |
1004 | e.oenv = ep; | 1007 | e.oenv = ep; |
1005 | e.errpt = errpt; | 1008 | e.errpt = errpt; |
1006 | return(0); | 1009 | return (0); |
1007 | } | 1010 | } |
1008 | 1011 | ||
1009 | static void | 1012 | static void quitenv() |
1010 | quitenv() | ||
1011 | { | 1013 | { |
1012 | register struct env *ep; | 1014 | register struct env *ep; |
1013 | register int fd; | 1015 | register int fd; |
@@ -1025,55 +1027,50 @@ quitenv() | |||
1025 | /* | 1027 | /* |
1026 | * Is any character from s1 in s2? | 1028 | * Is any character from s1 in s2? |
1027 | */ | 1029 | */ |
1028 | static int | 1030 | static int anys(s1, s2) |
1029 | anys(s1, s2) | ||
1030 | register char *s1, *s2; | 1031 | register char *s1, *s2; |
1031 | { | 1032 | { |
1032 | while (*s1) | 1033 | while (*s1) |
1033 | if (any(*s1++, s2)) | 1034 | if (any(*s1++, s2)) |
1034 | return(1); | 1035 | return (1); |
1035 | return(0); | 1036 | return (0); |
1036 | } | 1037 | } |
1037 | 1038 | ||
1038 | /* | 1039 | /* |
1039 | * Is character c in s? | 1040 | * Is character c in s? |
1040 | */ | 1041 | */ |
1041 | static int | 1042 | static int any(c, s) |
1042 | any(c, s) | ||
1043 | register int c; | 1043 | register int c; |
1044 | register char *s; | 1044 | register char *s; |
1045 | { | 1045 | { |
1046 | while (*s) | 1046 | while (*s) |
1047 | if (*s++ == c) | 1047 | if (*s++ == c) |
1048 | return(1); | 1048 | return (1); |
1049 | return(0); | 1049 | return (0); |
1050 | } | 1050 | } |
1051 | 1051 | ||
1052 | static char * | 1052 | static char *putn(n) |
1053 | putn(n) | ||
1054 | register int n; | 1053 | register int n; |
1055 | { | 1054 | { |
1056 | return(itoa(n)); | 1055 | return (itoa(n)); |
1057 | } | 1056 | } |
1058 | 1057 | ||
1059 | static char * | 1058 | static char *itoa(n) |
1060 | itoa(n) | ||
1061 | register int n; | 1059 | register int n; |
1062 | { | 1060 | { |
1063 | static char s[20]; | 1061 | static char s[20]; |
1062 | |||
1064 | snprintf(s, sizeof(s), "%u", n); | 1063 | snprintf(s, sizeof(s), "%u", n); |
1065 | return(s); | 1064 | return (s); |
1066 | } | 1065 | } |
1067 | 1066 | ||
1068 | static void | 1067 | static void next(int f) |
1069 | next(int f) | ||
1070 | { | 1068 | { |
1071 | PUSHIO(afile, f, filechar); | 1069 | PUSHIO(afile, f, filechar); |
1072 | } | 1070 | } |
1073 | 1071 | ||
1074 | static void | 1072 | static void onintr(s) |
1075 | onintr(s) | 1073 | int s; /* ANSI C requires a parameter */ |
1076 | int s; /* ANSI C requires a parameter */ | ||
1077 | { | 1074 | { |
1078 | signal(SIGINT, onintr); | 1075 | signal(SIGINT, onintr); |
1079 | intr = 1; | 1076 | intr = 1; |
@@ -1082,45 +1079,40 @@ int s; /* ANSI C requires a parameter */ | |||
1082 | prs("\n"); | 1079 | prs("\n"); |
1083 | fail(); | 1080 | fail(); |
1084 | } | 1081 | } |
1085 | } | 1082 | } else if (heedint) { |
1086 | else if (heedint) { | ||
1087 | execflg = 0; | 1083 | execflg = 0; |
1088 | leave(); | 1084 | leave(); |
1089 | } | 1085 | } |
1090 | } | 1086 | } |
1091 | 1087 | ||
1092 | static char * | 1088 | static char *space(n) |
1093 | space(n) | ||
1094 | int n; | 1089 | int n; |
1095 | { | 1090 | { |
1096 | register char *cp; | 1091 | register char *cp; |
1097 | 1092 | ||
1098 | if ((cp = getcell(n)) == 0) | 1093 | if ((cp = getcell(n)) == 0) |
1099 | err("out of string space"); | 1094 | err("out of string space"); |
1100 | return(cp); | 1095 | return (cp); |
1101 | } | 1096 | } |
1102 | 1097 | ||
1103 | static char * | 1098 | static char *strsave(s, a) |
1104 | strsave(s, a) | ||
1105 | register char *s; | 1099 | register char *s; |
1106 | int a; | 1100 | int a; |
1107 | { | 1101 | { |
1108 | register char *cp, *xp; | 1102 | register char *cp, *xp; |
1109 | 1103 | ||
1110 | if ((cp = space(strlen(s)+1)) != NULL) { | 1104 | if ((cp = space(strlen(s) + 1)) != NULL) { |
1111 | setarea((char *)cp, a); | 1105 | setarea((char *) cp, a); |
1112 | for (xp = cp; (*xp++ = *s++) != '\0';) | 1106 | for (xp = cp; (*xp++ = *s++) != '\0';); |
1113 | ; | 1107 | return (cp); |
1114 | return(cp); | ||
1115 | } | 1108 | } |
1116 | return(""); | 1109 | return (""); |
1117 | } | 1110 | } |
1118 | 1111 | ||
1119 | /* | 1112 | /* |
1120 | * trap handling | 1113 | * trap handling |
1121 | */ | 1114 | */ |
1122 | static void | 1115 | static void sig(i) |
1123 | sig(i) | ||
1124 | register int i; | 1116 | register int i; |
1125 | { | 1117 | { |
1126 | trapset = i; | 1118 | trapset = i; |
@@ -1147,8 +1139,7 @@ int i; | |||
1147 | * not previously there, enter it now and | 1139 | * not previously there, enter it now and |
1148 | * return a null value. | 1140 | * return a null value. |
1149 | */ | 1141 | */ |
1150 | static struct var * | 1142 | static struct var *lookup(n) |
1151 | lookup(n) | ||
1152 | register char *n; | 1143 | register char *n; |
1153 | { | 1144 | { |
1154 | register struct var *vp; | 1145 | register struct var *vp; |
@@ -1159,43 +1150,41 @@ register char *n; | |||
1159 | if (isdigit(*n)) { | 1150 | if (isdigit(*n)) { |
1160 | dummy.name = n; | 1151 | dummy.name = n; |
1161 | for (c = 0; isdigit(*n) && c < 1000; n++) | 1152 | for (c = 0; isdigit(*n) && c < 1000; n++) |
1162 | c = c*10 + *n-'0'; | 1153 | c = c * 10 + *n - '0'; |
1163 | dummy.status = RONLY; | 1154 | dummy.status = RONLY; |
1164 | dummy.value = c <= dolc? dolv[c]: null; | 1155 | dummy.value = c <= dolc ? dolv[c] : null; |
1165 | return(&dummy); | 1156 | return (&dummy); |
1166 | } | 1157 | } |
1167 | for (vp = vlist; vp; vp = vp->next) | 1158 | for (vp = vlist; vp; vp = vp->next) |
1168 | if (eqname(vp->name, n)) | 1159 | if (eqname(vp->name, n)) |
1169 | return(vp); | 1160 | return (vp); |
1170 | cp = findeq(n); | 1161 | cp = findeq(n); |
1171 | vp = (struct var *)space(sizeof(*vp)); | 1162 | vp = (struct var *) space(sizeof(*vp)); |
1172 | if (vp == 0 || (vp->name = space((int)(cp-n)+2)) == 0) { | 1163 | if (vp == 0 || (vp->name = space((int) (cp - n) + 2)) == 0) { |
1173 | dummy.name = dummy.value = ""; | 1164 | dummy.name = dummy.value = ""; |
1174 | return(&dummy); | 1165 | return (&dummy); |
1175 | } | 1166 | } |
1176 | for (cp = vp->name; (*cp = *n++) && *cp != '='; cp++) | 1167 | for (cp = vp->name; (*cp = *n++) && *cp != '='; cp++); |
1177 | ; | ||
1178 | if (*cp == 0) | 1168 | if (*cp == 0) |
1179 | *cp = '='; | 1169 | *cp = '='; |
1180 | *++cp = 0; | 1170 | *++cp = 0; |
1181 | setarea((char *)vp, 0); | 1171 | setarea((char *) vp, 0); |
1182 | setarea((char *)vp->name, 0); | 1172 | setarea((char *) vp->name, 0); |
1183 | vp->value = null; | 1173 | vp->value = null; |
1184 | vp->next = vlist; | 1174 | vp->next = vlist; |
1185 | vp->status = GETCELL; | 1175 | vp->status = GETCELL; |
1186 | vlist = vp; | 1176 | vlist = vp; |
1187 | return(vp); | 1177 | return (vp); |
1188 | } | 1178 | } |
1189 | 1179 | ||
1190 | /* | 1180 | /* |
1191 | * give variable at `vp' the value `val'. | 1181 | * give variable at `vp' the value `val'. |
1192 | */ | 1182 | */ |
1193 | static void | 1183 | static void setval(vp, val) |
1194 | setval(vp, val) | ||
1195 | struct var *vp; | 1184 | struct var *vp; |
1196 | char *val; | 1185 | char *val; |
1197 | { | 1186 | { |
1198 | nameval(vp, val, (char *)NULL); | 1187 | nameval(vp, val, (char *) NULL); |
1199 | } | 1188 | } |
1200 | 1189 | ||
1201 | /* | 1190 | /* |
@@ -1205,8 +1194,7 @@ char *val; | |||
1205 | * this is all so that exporting | 1194 | * this is all so that exporting |
1206 | * values is reasonably painless. | 1195 | * values is reasonably painless. |
1207 | */ | 1196 | */ |
1208 | static void | 1197 | static void nameval(vp, val, name) |
1209 | nameval(vp, val, name) | ||
1210 | register struct var *vp; | 1198 | register struct var *vp; |
1211 | char *val, *name; | 1199 | char *val, *name; |
1212 | { | 1200 | { |
@@ -1222,58 +1210,52 @@ char *val, *name; | |||
1222 | } | 1210 | } |
1223 | fl = 0; | 1211 | fl = 0; |
1224 | if (name == NULL) { | 1212 | if (name == NULL) { |
1225 | xp = space(strlen(vp->name)+strlen(val)+2); | 1213 | xp = space(strlen(vp->name) + strlen(val) + 2); |
1226 | if (xp == 0) | 1214 | if (xp == 0) |
1227 | return; | 1215 | return; |
1228 | /* make string: name=value */ | 1216 | /* make string: name=value */ |
1229 | setarea((char *)xp, 0); | 1217 | setarea((char *) xp, 0); |
1230 | name = xp; | 1218 | name = xp; |
1231 | for (cp = vp->name; (*xp = *cp++) && *xp!='='; xp++) | 1219 | for (cp = vp->name; (*xp = *cp++) && *xp != '='; xp++); |
1232 | ; | ||
1233 | if (*xp++ == 0) | 1220 | if (*xp++ == 0) |
1234 | xp[-1] = '='; | 1221 | xp[-1] = '='; |
1235 | nv = xp; | 1222 | nv = xp; |
1236 | for (cp = val; (*xp++ = *cp++) != '\0';) | 1223 | for (cp = val; (*xp++ = *cp++) != '\0';); |
1237 | ; | ||
1238 | val = nv; | 1224 | val = nv; |
1239 | fl = GETCELL; | 1225 | fl = GETCELL; |
1240 | } | 1226 | } |
1241 | if (vp->status & GETCELL) | 1227 | if (vp->status & GETCELL) |
1242 | freecell(vp->name); /* form new string `name=value' */ | 1228 | freecell(vp->name); /* form new string `name=value' */ |
1243 | vp->name = name; | 1229 | vp->name = name; |
1244 | vp->value = val; | 1230 | vp->value = val; |
1245 | vp->status |= fl; | 1231 | vp->status |= fl; |
1246 | } | 1232 | } |
1247 | 1233 | ||
1248 | static void | 1234 | static void export(vp) |
1249 | export(vp) | ||
1250 | struct var *vp; | 1235 | struct var *vp; |
1251 | { | 1236 | { |
1252 | vp->status |= EXPORT; | 1237 | vp->status |= EXPORT; |
1253 | } | 1238 | } |
1254 | 1239 | ||
1255 | static void | 1240 | static void ronly(vp) |
1256 | ronly(vp) | ||
1257 | struct var *vp; | 1241 | struct var *vp; |
1258 | { | 1242 | { |
1259 | if (isalpha(vp->name[0]) || vp->name[0] == '_') /* not an internal symbol */ | 1243 | if (isalpha(vp->name[0]) || vp->name[0] == '_') /* not an internal symbol */ |
1260 | vp->status |= RONLY; | 1244 | vp->status |= RONLY; |
1261 | } | 1245 | } |
1262 | 1246 | ||
1263 | static int | 1247 | static int isassign(s) |
1264 | isassign(s) | ||
1265 | register char *s; | 1248 | register char *s; |
1266 | { | 1249 | { |
1267 | if (!isalpha((int)*s) && *s != '_') | 1250 | if (!isalpha((int) *s) && *s != '_') |
1268 | return(0); | 1251 | return (0); |
1269 | for (; *s != '='; s++) | 1252 | for (; *s != '='; s++) |
1270 | if (*s == 0 || (!isalnum(*s) && *s != '_')) | 1253 | if (*s == 0 || (!isalnum(*s) && *s != '_')) |
1271 | return(0); | 1254 | return (0); |
1272 | return(1); | 1255 | return (1); |
1273 | } | 1256 | } |
1274 | 1257 | ||
1275 | static int | 1258 | static int assign(s, cf) |
1276 | assign(s, cf) | ||
1277 | register char *s; | 1259 | register char *s; |
1278 | int cf; | 1260 | int cf; |
1279 | { | 1261 | { |
@@ -1281,31 +1263,29 @@ int cf; | |||
1281 | struct var *vp; | 1263 | struct var *vp; |
1282 | 1264 | ||
1283 | if (!isalpha(*s) && *s != '_') | 1265 | if (!isalpha(*s) && *s != '_') |
1284 | return(0); | 1266 | return (0); |
1285 | for (cp = s; *cp != '='; cp++) | 1267 | for (cp = s; *cp != '='; cp++) |
1286 | if (*cp == 0 || (!isalnum(*cp) && *cp != '_')) | 1268 | if (*cp == 0 || (!isalnum(*cp) && *cp != '_')) |
1287 | return(0); | 1269 | return (0); |
1288 | vp = lookup(s); | 1270 | vp = lookup(s); |
1289 | nameval(vp, ++cp, cf == COPYV? (char *)NULL: s); | 1271 | nameval(vp, ++cp, cf == COPYV ? (char *) NULL : s); |
1290 | if (cf != COPYV) | 1272 | if (cf != COPYV) |
1291 | vp->status &= ~GETCELL; | 1273 | vp->status &= ~GETCELL; |
1292 | return(1); | 1274 | return (1); |
1293 | } | 1275 | } |
1294 | 1276 | ||
1295 | static int | 1277 | static int checkname(cp) |
1296 | checkname(cp) | ||
1297 | register char *cp; | 1278 | register char *cp; |
1298 | { | 1279 | { |
1299 | if (!isalpha(*cp++) && *(cp-1) != '_') | 1280 | if (!isalpha(*cp++) && *(cp - 1) != '_') |
1300 | return(0); | 1281 | return (0); |
1301 | while (*cp) | 1282 | while (*cp) |
1302 | if (!isalnum(*cp++) && *(cp-1) != '_') | 1283 | if (!isalnum(*cp++) && *(cp - 1) != '_') |
1303 | return(0); | 1284 | return (0); |
1304 | return(1); | 1285 | return (1); |
1305 | } | 1286 | } |
1306 | 1287 | ||
1307 | static void | 1288 | static void putvlist(f, out) |
1308 | putvlist(f, out) | ||
1309 | register int f, out; | 1289 | register int f, out; |
1310 | { | 1290 | { |
1311 | register struct var *vp; | 1291 | register struct var *vp; |
@@ -1316,28 +1296,26 @@ register int f, out; | |||
1316 | write(out, "export ", 7); | 1296 | write(out, "export ", 7); |
1317 | if (vp->status & RONLY) | 1297 | if (vp->status & RONLY) |
1318 | write(out, "readonly ", 9); | 1298 | write(out, "readonly ", 9); |
1319 | write(out, vp->name, (int)(findeq(vp->name) - vp->name)); | 1299 | write(out, vp->name, (int) (findeq(vp->name) - vp->name)); |
1320 | write(out, "\n", 1); | 1300 | write(out, "\n", 1); |
1321 | } | 1301 | } |
1322 | } | 1302 | } |
1323 | 1303 | ||
1324 | static int | 1304 | static int eqname(n1, n2) |
1325 | eqname(n1, n2) | ||
1326 | register char *n1, *n2; | 1305 | register char *n1, *n2; |
1327 | { | 1306 | { |
1328 | for (; *n1 != '=' && *n1 != 0; n1++) | 1307 | for (; *n1 != '=' && *n1 != 0; n1++) |
1329 | if (*n2++ != *n1) | 1308 | if (*n2++ != *n1) |
1330 | return(0); | 1309 | return (0); |
1331 | return(*n2 == 0 || *n2 == '='); | 1310 | return (*n2 == 0 || *n2 == '='); |
1332 | } | 1311 | } |
1333 | 1312 | ||
1334 | static char * | 1313 | static char *findeq(cp) |
1335 | findeq(cp) | ||
1336 | register char *cp; | 1314 | register char *cp; |
1337 | { | 1315 | { |
1338 | while (*cp != '\0' && *cp != '=') | 1316 | while (*cp != '\0' && *cp != '=') |
1339 | cp++; | 1317 | cp++; |
1340 | return(cp); | 1318 | return (cp); |
1341 | } | 1319 | } |
1342 | 1320 | ||
1343 | /* -------- gmatch.c -------- */ | 1321 | /* -------- gmatch.c -------- */ |
@@ -1351,47 +1329,45 @@ register char *cp; | |||
1351 | #define CMASK 0377 | 1329 | #define CMASK 0377 |
1352 | #define QUOTE 0200 | 1330 | #define QUOTE 0200 |
1353 | #define QMASK (CMASK&~QUOTE) | 1331 | #define QMASK (CMASK&~QUOTE) |
1354 | #define NOT '!' /* might use ^ */ | 1332 | #define NOT '!' /* might use ^ */ |
1355 | 1333 | ||
1356 | static int | 1334 | static int gmatch(s, p) |
1357 | gmatch(s, p) | ||
1358 | register char *s, *p; | 1335 | register char *s, *p; |
1359 | { | 1336 | { |
1360 | register int sc, pc; | 1337 | register int sc, pc; |
1361 | 1338 | ||
1362 | if (s == NULL || p == NULL) | 1339 | if (s == NULL || p == NULL) |
1363 | return(0); | 1340 | return (0); |
1364 | while ((pc = *p++ & CMASK) != '\0') { | 1341 | while ((pc = *p++ & CMASK) != '\0') { |
1365 | sc = *s++ & QMASK; | 1342 | sc = *s++ & QMASK; |
1366 | switch (pc) { | 1343 | switch (pc) { |
1367 | case '[': | 1344 | case '[': |
1368 | if ((p = cclass(p, sc)) == NULL) | 1345 | if ((p = cclass(p, sc)) == NULL) |
1369 | return(0); | 1346 | return (0); |
1370 | break; | 1347 | break; |
1371 | 1348 | ||
1372 | case '?': | 1349 | case '?': |
1373 | if (sc == 0) | 1350 | if (sc == 0) |
1374 | return(0); | 1351 | return (0); |
1375 | break; | 1352 | break; |
1376 | 1353 | ||
1377 | case '*': | 1354 | case '*': |
1378 | s--; | 1355 | s--; |
1379 | do { | 1356 | do { |
1380 | if (*p == '\0' || gmatch(s, p)) | 1357 | if (*p == '\0' || gmatch(s, p)) |
1381 | return(1); | 1358 | return (1); |
1382 | } while (*s++ != '\0'); | 1359 | } while (*s++ != '\0'); |
1383 | return(0); | 1360 | return (0); |
1384 | 1361 | ||
1385 | default: | 1362 | default: |
1386 | if (sc != (pc&~QUOTE)) | 1363 | if (sc != (pc & ~QUOTE)) |
1387 | return(0); | 1364 | return (0); |
1388 | } | 1365 | } |
1389 | } | 1366 | } |
1390 | return(*s == 0); | 1367 | return (*s == 0); |
1391 | } | 1368 | } |
1392 | 1369 | ||
1393 | static char * | 1370 | static char *cclass(p, sub) |
1394 | cclass(p, sub) | ||
1395 | register char *p; | 1371 | register char *p; |
1396 | register int sub; | 1372 | register int sub; |
1397 | { | 1373 | { |
@@ -1402,7 +1378,7 @@ register int sub; | |||
1402 | found = not; | 1378 | found = not; |
1403 | do { | 1379 | do { |
1404 | if (*p == '\0') | 1380 | if (*p == '\0') |
1405 | return((char *)NULL); | 1381 | return ((char *) NULL); |
1406 | c = *p & CMASK; | 1382 | c = *p & CMASK; |
1407 | if (p[1] == '-' && p[2] != ']') { | 1383 | if (p[1] == '-' && p[2] != ']') { |
1408 | d = p[2] & CMASK; | 1384 | d = p[2] & CMASK; |
@@ -1412,7 +1388,7 @@ register int sub; | |||
1412 | if (c == sub || (c <= sub && sub <= d)) | 1388 | if (c == sub || (c <= sub && sub <= d)) |
1413 | found = !not; | 1389 | found = !not; |
1414 | } while (*++p != ']'); | 1390 | } while (*++p != ']'); |
1415 | return(found? p+1: (char *)NULL); | 1391 | return (found ? p + 1 : (char *) NULL); |
1416 | } | 1392 | } |
1417 | 1393 | ||
1418 | 1394 | ||
@@ -1426,15 +1402,14 @@ register int sub; | |||
1426 | 1402 | ||
1427 | #define sbrk(X) ({ void * __q = (void *)-1; if (brkaddr + (int)(X) < brktop) { __q = brkaddr; brkaddr+=(int)(X); } __q;}) | 1403 | #define sbrk(X) ({ void * __q = (void *)-1; if (brkaddr + (int)(X) < brktop) { __q = brkaddr; brkaddr+=(int)(X); } __q;}) |
1428 | 1404 | ||
1429 | static void | 1405 | static void initarea() |
1430 | initarea() | ||
1431 | { | 1406 | { |
1432 | brkaddr = malloc(65000); | 1407 | brkaddr = malloc(65000); |
1433 | brktop = brkaddr + 65000; | 1408 | brktop = brkaddr + 65000; |
1434 | 1409 | ||
1435 | while ((int)sbrk(0) & ALIGN) | 1410 | while ((int) sbrk(0) & ALIGN) |
1436 | sbrk(1); | 1411 | sbrk(1); |
1437 | areabot = (struct region *)sbrk(REGSIZE); | 1412 | areabot = (struct region *) sbrk(REGSIZE); |
1438 | 1413 | ||
1439 | areabot->next = areabot; | 1414 | areabot->next = areabot; |
1440 | areabot->area = BUSY; | 1415 | areabot->area = BUSY; |
@@ -1442,8 +1417,7 @@ initarea() | |||
1442 | areanxt = areabot; | 1417 | areanxt = areabot; |
1443 | } | 1418 | } |
1444 | 1419 | ||
1445 | char * | 1420 | char *getcell(nbytes) |
1446 | getcell(nbytes) | ||
1447 | unsigned nbytes; | 1421 | unsigned nbytes; |
1448 | { | 1422 | { |
1449 | register int nregio; | 1423 | register int nregio; |
@@ -1453,11 +1427,12 @@ unsigned nbytes; | |||
1453 | if (nbytes == 0) { | 1427 | if (nbytes == 0) { |
1454 | puts("getcell(0)"); | 1428 | puts("getcell(0)"); |
1455 | abort(); | 1429 | abort(); |
1456 | } /* silly and defeats the algorithm */ | 1430 | } |
1431 | /* silly and defeats the algorithm */ | ||
1457 | /* | 1432 | /* |
1458 | * round upwards and add administration area | 1433 | * round upwards and add administration area |
1459 | */ | 1434 | */ |
1460 | nregio = (nbytes+(REGSIZE-1))/REGSIZE + 1; | 1435 | nregio = (nbytes + (REGSIZE - 1)) / REGSIZE + 1; |
1461 | for (p = areanxt;;) { | 1436 | for (p = areanxt;;) { |
1462 | if (p->area > areanum) { | 1437 | if (p->area > areanum) { |
1463 | /* | 1438 | /* |
@@ -1476,13 +1451,13 @@ unsigned nbytes; | |||
1476 | break; | 1451 | break; |
1477 | } | 1452 | } |
1478 | i = nregio >= GROWBY ? nregio : GROWBY; | 1453 | i = nregio >= GROWBY ? nregio : GROWBY; |
1479 | p = (struct region *)sbrk(i * REGSIZE); | 1454 | p = (struct region *) sbrk(i * REGSIZE); |
1480 | if (p == (struct region *)-1) | 1455 | if (p == (struct region *) -1) |
1481 | return((char *)NULL); | 1456 | return ((char *) NULL); |
1482 | p--; | 1457 | p--; |
1483 | if (p != areatop) { | 1458 | if (p != areatop) { |
1484 | puts("not contig"); | 1459 | puts("not contig"); |
1485 | abort(); /* allocated areas are contiguous */ | 1460 | abort(); /* allocated areas are contiguous */ |
1486 | } | 1461 | } |
1487 | q = p + i; | 1462 | q = p + i; |
1488 | p->next = q; | 1463 | p->next = q; |
@@ -1490,7 +1465,7 @@ unsigned nbytes; | |||
1490 | q->next = areabot; | 1465 | q->next = areabot; |
1491 | q->area = BUSY; | 1466 | q->area = BUSY; |
1492 | areatop = q; | 1467 | areatop = q; |
1493 | found: | 1468 | found: |
1494 | /* | 1469 | /* |
1495 | * we found a FREE area big enough, pointed to by 'p', and up to 'q' | 1470 | * we found a FREE area big enough, pointed to by 'p', and up to 'q' |
1496 | */ | 1471 | */ |
@@ -1499,25 +1474,24 @@ found: | |||
1499 | /* | 1474 | /* |
1500 | * split into requested area and rest | 1475 | * split into requested area and rest |
1501 | */ | 1476 | */ |
1502 | if (areanxt+1 > q) { | 1477 | if (areanxt + 1 > q) { |
1503 | puts("OOM"); | 1478 | puts("OOM"); |
1504 | abort(); /* insufficient space left for admin */ | 1479 | abort(); /* insufficient space left for admin */ |
1505 | } | 1480 | } |
1506 | areanxt->next = q; | 1481 | areanxt->next = q; |
1507 | areanxt->area = FREE; | 1482 | areanxt->area = FREE; |
1508 | p->next = areanxt; | 1483 | p->next = areanxt; |
1509 | } | 1484 | } |
1510 | p->area = areanum; | 1485 | p->area = areanum; |
1511 | return((char *)(p+1)); | 1486 | return ((char *) (p + 1)); |
1512 | } | 1487 | } |
1513 | 1488 | ||
1514 | static void | 1489 | static void freecell(cp) |
1515 | freecell(cp) | ||
1516 | char *cp; | 1490 | char *cp; |
1517 | { | 1491 | { |
1518 | register struct region *p; | 1492 | register struct region *p; |
1519 | 1493 | ||
1520 | if ((p = (struct region *)cp) != NULL) { | 1494 | if ((p = (struct region *) cp) != NULL) { |
1521 | p--; | 1495 | p--; |
1522 | if (p < areanxt) | 1496 | if (p < areanxt) |
1523 | areanxt = p; | 1497 | areanxt = p; |
@@ -1525,8 +1499,7 @@ char *cp; | |||
1525 | } | 1499 | } |
1526 | } | 1500 | } |
1527 | 1501 | ||
1528 | static void | 1502 | static void freearea(a) |
1529 | freearea(a) | ||
1530 | register int a; | 1503 | register int a; |
1531 | { | 1504 | { |
1532 | register struct region *p, *top; | 1505 | register struct region *p, *top; |
@@ -1537,26 +1510,23 @@ register int a; | |||
1537 | p->area = FREE; | 1510 | p->area = FREE; |
1538 | } | 1511 | } |
1539 | 1512 | ||
1540 | static void | 1513 | static void setarea(cp, a) |
1541 | setarea(cp,a) | ||
1542 | char *cp; | 1514 | char *cp; |
1543 | int a; | 1515 | int a; |
1544 | { | 1516 | { |
1545 | register struct region *p; | 1517 | register struct region *p; |
1546 | 1518 | ||
1547 | if ((p = (struct region *)cp) != NULL) | 1519 | if ((p = (struct region *) cp) != NULL) |
1548 | (p-1)->area = a; | 1520 | (p - 1)->area = a; |
1549 | } | 1521 | } |
1550 | 1522 | ||
1551 | int | 1523 | int getarea(cp) |
1552 | getarea(cp) | ||
1553 | char *cp; | 1524 | char *cp; |
1554 | { | 1525 | { |
1555 | return ((struct region*)cp-1)->area; | 1526 | return ((struct region *) cp - 1)->area; |
1556 | } | 1527 | } |
1557 | 1528 | ||
1558 | static void | 1529 | static void garbage() |
1559 | garbage() | ||
1560 | { | 1530 | { |
1561 | register struct region *p, *q, *top; | 1531 | register struct region *p, *q, *top; |
1562 | 1532 | ||
@@ -1570,7 +1540,7 @@ garbage() | |||
1570 | } | 1540 | } |
1571 | #ifdef SHRINKBY | 1541 | #ifdef SHRINKBY |
1572 | if (areatop >= q + SHRINKBY && q->area > areanum) { | 1542 | if (areatop >= q + SHRINKBY && q->area > areanum) { |
1573 | brk((char *)(q+1)); | 1543 | brk((char *) (q + 1)); |
1574 | q->next = areabot; | 1544 | q->next = areabot; |
1575 | q->area = BUSY; | 1545 | q->area = BUSY; |
1576 | areatop = q; | 1546 | areatop = q; |
@@ -1584,19 +1554,17 @@ garbage() | |||
1584 | */ | 1554 | */ |
1585 | 1555 | ||
1586 | 1556 | ||
1587 | int | 1557 | int yyparse() |
1588 | yyparse() | ||
1589 | { | 1558 | { |
1590 | startl = 1; | 1559 | startl = 1; |
1591 | peeksym = 0; | 1560 | peeksym = 0; |
1592 | yynerrs = 0; | 1561 | yynerrs = 0; |
1593 | outtree = c_list(); | 1562 | outtree = c_list(); |
1594 | musthave('\n', 0); | 1563 | musthave('\n', 0); |
1595 | return(yynerrs!=0); | 1564 | return (yynerrs != 0); |
1596 | } | 1565 | } |
1597 | 1566 | ||
1598 | static struct op * | 1567 | static struct op *pipeline(cf) |
1599 | pipeline(cf) | ||
1600 | int cf; | 1568 | int cf; |
1601 | { | 1569 | { |
1602 | register struct op *t, *p; | 1570 | register struct op *t, *p; |
@@ -1615,11 +1583,10 @@ int cf; | |||
1615 | } | 1583 | } |
1616 | peeksym = c; | 1584 | peeksym = c; |
1617 | } | 1585 | } |
1618 | return(t); | 1586 | return (t); |
1619 | } | 1587 | } |
1620 | 1588 | ||
1621 | static struct op * | 1589 | static struct op *andor() |
1622 | andor() | ||
1623 | { | 1590 | { |
1624 | register struct op *t, *p; | 1591 | register struct op *t, *p; |
1625 | register int c; | 1592 | register int c; |
@@ -1629,38 +1596,37 @@ andor() | |||
1629 | while ((c = yylex(0)) == LOGAND || c == LOGOR) { | 1596 | while ((c = yylex(0)) == LOGAND || c == LOGOR) { |
1630 | if ((p = pipeline(CONTIN)) == NULL) | 1597 | if ((p = pipeline(CONTIN)) == NULL) |
1631 | SYNTAXERR; | 1598 | SYNTAXERR; |
1632 | t = block(c == LOGAND? TAND: TOR, t, p, NOWORDS); | 1599 | t = block(c == LOGAND ? TAND : TOR, t, p, NOWORDS); |
1633 | } | 1600 | } |
1634 | peeksym = c; | 1601 | peeksym = c; |
1635 | } | 1602 | } |
1636 | return(t); | 1603 | return (t); |
1637 | } | 1604 | } |
1638 | 1605 | ||
1639 | static struct op * | 1606 | static struct op *c_list() |
1640 | c_list() | ||
1641 | { | 1607 | { |
1642 | register struct op *t, *p; | 1608 | register struct op *t, *p; |
1643 | register int c; | 1609 | register int c; |
1644 | 1610 | ||
1645 | t = andor(); | 1611 | t = andor(); |
1646 | if (t != NULL) { | 1612 | if (t != NULL) { |
1647 | if((peeksym = yylex(0)) == '&') | 1613 | if ((peeksym = yylex(0)) == '&') |
1648 | t = block(TASYNC, t, NOBLOCK, NOWORDS); | 1614 | t = block(TASYNC, t, NOBLOCK, NOWORDS); |
1649 | while ((c = yylex(0)) == ';' || c == '&' || (multiline && c == '\n')) { | 1615 | while ((c = yylex(0)) == ';' || c == '&' |
1616 | || (multiline && c == '\n')) { | ||
1650 | if ((p = andor()) == NULL) | 1617 | if ((p = andor()) == NULL) |
1651 | return(t); | 1618 | return (t); |
1652 | if((peeksym = yylex(0)) == '&') | 1619 | if ((peeksym = yylex(0)) == '&') |
1653 | p = block(TASYNC, p, NOBLOCK, NOWORDS); | 1620 | p = block(TASYNC, p, NOBLOCK, NOWORDS); |
1654 | t = list(t, p); | 1621 | t = list(t, p); |
1655 | } | 1622 | } |
1656 | peeksym = c; | 1623 | peeksym = c; |
1657 | } | 1624 | } |
1658 | return(t); | 1625 | return (t); |
1659 | } | 1626 | } |
1660 | 1627 | ||
1661 | 1628 | ||
1662 | static int | 1629 | static int synio(cf) |
1663 | synio(cf) | ||
1664 | int cf; | 1630 | int cf; |
1665 | { | 1631 | { |
1666 | register struct ioword *iop; | 1632 | register struct ioword *iop; |
@@ -1669,7 +1635,7 @@ int cf; | |||
1669 | 1635 | ||
1670 | if ((c = yylex(cf)) != '<' && c != '>') { | 1636 | if ((c = yylex(cf)) != '<' && c != '>') { |
1671 | peeksym = c; | 1637 | peeksym = c; |
1672 | return(0); | 1638 | return (0); |
1673 | } | 1639 | } |
1674 | i = yylval.i; | 1640 | i = yylval.i; |
1675 | musthave(WORD, 0); | 1641 | musthave(WORD, 0); |
@@ -1677,11 +1643,10 @@ int cf; | |||
1677 | iounit = IODEFAULT; | 1643 | iounit = IODEFAULT; |
1678 | if (i & IOHERE) | 1644 | if (i & IOHERE) |
1679 | markhere(yylval.cp, iop); | 1645 | markhere(yylval.cp, iop); |
1680 | return(1); | 1646 | return (1); |
1681 | } | 1647 | } |
1682 | 1648 | ||
1683 | static void | 1649 | static void musthave(c, cf) |
1684 | musthave(c, cf) | ||
1685 | int c, cf; | 1650 | int c, cf; |
1686 | { | 1651 | { |
1687 | if ((peeksym = yylex(cf)) != c) | 1652 | if ((peeksym = yylex(cf)) != c) |
@@ -1689,8 +1654,7 @@ int c, cf; | |||
1689 | peeksym = 0; | 1654 | peeksym = 0; |
1690 | } | 1655 | } |
1691 | 1656 | ||
1692 | static struct op * | 1657 | static struct op *simple() |
1693 | simple() | ||
1694 | { | 1658 | { |
1695 | register struct op *t; | 1659 | register struct op *t; |
1696 | 1660 | ||
@@ -1712,13 +1676,12 @@ simple() | |||
1712 | break; | 1676 | break; |
1713 | 1677 | ||
1714 | default: | 1678 | default: |
1715 | return(t); | 1679 | return (t); |
1716 | } | 1680 | } |
1717 | } | 1681 | } |
1718 | } | 1682 | } |
1719 | 1683 | ||
1720 | static struct op * | 1684 | static struct op *nested(type, mark) |
1721 | nested(type, mark) | ||
1722 | int type, mark; | 1685 | int type, mark; |
1723 | { | 1686 | { |
1724 | register struct op *t; | 1687 | register struct op *t; |
@@ -1727,11 +1690,10 @@ int type, mark; | |||
1727 | t = c_list(); | 1690 | t = c_list(); |
1728 | musthave(mark, 0); | 1691 | musthave(mark, 0); |
1729 | multiline--; | 1692 | multiline--; |
1730 | return(block(type, t, NOBLOCK, NOWORDS)); | 1693 | return (block(type, t, NOBLOCK, NOWORDS)); |
1731 | } | 1694 | } |
1732 | 1695 | ||
1733 | static struct op * | 1696 | static struct op *command(cf) |
1734 | command(cf) | ||
1735 | int cf; | 1697 | int cf; |
1736 | { | 1698 | { |
1737 | register struct op *t; | 1699 | register struct op *t; |
@@ -1749,7 +1711,7 @@ int cf; | |||
1749 | peeksym = c; | 1711 | peeksym = c; |
1750 | if ((t = simple()) == NULL) { | 1712 | if ((t = simple()) == NULL) { |
1751 | if (iolist == NULL) | 1713 | if (iolist == NULL) |
1752 | return((struct op *)NULL); | 1714 | return ((struct op *) NULL); |
1753 | t = newtp(); | 1715 | t = newtp(); |
1754 | t->type = TCOM; | 1716 | t->type = TCOM; |
1755 | } | 1717 | } |
@@ -1781,7 +1743,7 @@ int cf; | |||
1781 | case UNTIL: | 1743 | case UNTIL: |
1782 | multiline++; | 1744 | multiline++; |
1783 | t = newtp(); | 1745 | t = newtp(); |
1784 | t->type = c == WHILE? TWHILE: TUNTIL; | 1746 | t->type = c == WHILE ? TWHILE : TUNTIL; |
1785 | t->left = c_list(); | 1747 | t->left = c_list(); |
1786 | t->right = dogroup(1); | 1748 | t->right = dogroup(1); |
1787 | t->words = NULL; | 1749 | t->words = NULL; |
@@ -1812,15 +1774,13 @@ int cf; | |||
1812 | multiline--; | 1774 | multiline--; |
1813 | break; | 1775 | break; |
1814 | } | 1776 | } |
1815 | while (synio(0)) | 1777 | while (synio(0)); |
1816 | ; | ||
1817 | t = namelist(t); | 1778 | t = namelist(t); |
1818 | iolist = iosave; | 1779 | iolist = iosave; |
1819 | return(t); | 1780 | return (t); |
1820 | } | 1781 | } |
1821 | 1782 | ||
1822 | static struct op * | 1783 | static struct op *dogroup(onlydone) |
1823 | dogroup(onlydone) | ||
1824 | int onlydone; | 1784 | int onlydone; |
1825 | { | 1785 | { |
1826 | register int c; | 1786 | register int c; |
@@ -1828,23 +1788,22 @@ int onlydone; | |||
1828 | 1788 | ||
1829 | c = yylex(CONTIN); | 1789 | c = yylex(CONTIN); |
1830 | if (c == DONE && onlydone) | 1790 | if (c == DONE && onlydone) |
1831 | return((struct op *)NULL); | 1791 | return ((struct op *) NULL); |
1832 | if (c != DO) | 1792 | if (c != DO) |
1833 | SYNTAXERR; | 1793 | SYNTAXERR; |
1834 | mylist = c_list(); | 1794 | mylist = c_list(); |
1835 | musthave(DONE, 0); | 1795 | musthave(DONE, 0); |
1836 | return(mylist); | 1796 | return (mylist); |
1837 | } | 1797 | } |
1838 | 1798 | ||
1839 | static struct op * | 1799 | static struct op *thenpart() |
1840 | thenpart() | ||
1841 | { | 1800 | { |
1842 | register int c; | 1801 | register int c; |
1843 | register struct op *t; | 1802 | register struct op *t; |
1844 | 1803 | ||
1845 | if ((c = yylex(0)) != THEN) { | 1804 | if ((c = yylex(0)) != THEN) { |
1846 | peeksym = c; | 1805 | peeksym = c; |
1847 | return((struct op *)NULL); | 1806 | return ((struct op *) NULL); |
1848 | } | 1807 | } |
1849 | t = newtp(); | 1808 | t = newtp(); |
1850 | t->type = 0; | 1809 | t->type = 0; |
@@ -1852,11 +1811,10 @@ thenpart() | |||
1852 | if (t->left == NULL) | 1811 | if (t->left == NULL) |
1853 | SYNTAXERR; | 1812 | SYNTAXERR; |
1854 | t->right = elsepart(); | 1813 | t->right = elsepart(); |
1855 | return(t); | 1814 | return (t); |
1856 | } | 1815 | } |
1857 | 1816 | ||
1858 | static struct op * | 1817 | static struct op *elsepart() |
1859 | elsepart() | ||
1860 | { | 1818 | { |
1861 | register int c; | 1819 | register int c; |
1862 | register struct op *t; | 1820 | register struct op *t; |
@@ -1865,34 +1823,32 @@ elsepart() | |||
1865 | case ELSE: | 1823 | case ELSE: |
1866 | if ((t = c_list()) == NULL) | 1824 | if ((t = c_list()) == NULL) |
1867 | SYNTAXERR; | 1825 | SYNTAXERR; |
1868 | return(t); | 1826 | return (t); |
1869 | 1827 | ||
1870 | case ELIF: | 1828 | case ELIF: |
1871 | t = newtp(); | 1829 | t = newtp(); |
1872 | t->type = TELIF; | 1830 | t->type = TELIF; |
1873 | t->left = c_list(); | 1831 | t->left = c_list(); |
1874 | t->right = thenpart(); | 1832 | t->right = thenpart(); |
1875 | return(t); | 1833 | return (t); |
1876 | 1834 | ||
1877 | default: | 1835 | default: |
1878 | peeksym = c; | 1836 | peeksym = c; |
1879 | return((struct op *)NULL); | 1837 | return ((struct op *) NULL); |
1880 | } | 1838 | } |
1881 | } | 1839 | } |
1882 | 1840 | ||
1883 | static struct op * | 1841 | static struct op *caselist() |
1884 | caselist() | ||
1885 | { | 1842 | { |
1886 | register struct op *t; | 1843 | register struct op *t; |
1887 | 1844 | ||
1888 | t = NULL; | 1845 | t = NULL; |
1889 | while ((peeksym = yylex(CONTIN)) != ESAC) | 1846 | while ((peeksym = yylex(CONTIN)) != ESAC) |
1890 | t = list(t, casepart()); | 1847 | t = list(t, casepart()); |
1891 | return(t); | 1848 | return (t); |
1892 | } | 1849 | } |
1893 | 1850 | ||
1894 | static struct op * | 1851 | static struct op *casepart() |
1895 | casepart() | ||
1896 | { | 1852 | { |
1897 | register struct op *t; | 1853 | register struct op *t; |
1898 | 1854 | ||
@@ -1903,11 +1859,10 @@ casepart() | |||
1903 | t->left = c_list(); | 1859 | t->left = c_list(); |
1904 | if ((peeksym = yylex(CONTIN)) != ESAC) | 1860 | if ((peeksym = yylex(CONTIN)) != ESAC) |
1905 | musthave(BREAK, CONTIN); | 1861 | musthave(BREAK, CONTIN); |
1906 | return(t); | 1862 | return (t); |
1907 | } | 1863 | } |
1908 | 1864 | ||
1909 | static char ** | 1865 | static char **pattern() |
1910 | pattern() | ||
1911 | { | 1866 | { |
1912 | register int c, cf; | 1867 | register int c, cf; |
1913 | 1868 | ||
@@ -1919,42 +1874,39 @@ pattern() | |||
1919 | } while ((c = yylex(0)) == '|'); | 1874 | } while ((c = yylex(0)) == '|'); |
1920 | peeksym = c; | 1875 | peeksym = c; |
1921 | word(NOWORD); | 1876 | word(NOWORD); |
1922 | return(copyw()); | 1877 | return (copyw()); |
1923 | } | 1878 | } |
1924 | 1879 | ||
1925 | static char ** | 1880 | static char **wordlist() |
1926 | wordlist() | ||
1927 | { | 1881 | { |
1928 | register int c; | 1882 | register int c; |
1929 | 1883 | ||
1930 | if ((c = yylex(0)) != IN) { | 1884 | if ((c = yylex(0)) != IN) { |
1931 | peeksym = c; | 1885 | peeksym = c; |
1932 | return((char **)NULL); | 1886 | return ((char **) NULL); |
1933 | } | 1887 | } |
1934 | startl = 0; | 1888 | startl = 0; |
1935 | while ((c = yylex(0)) == WORD) | 1889 | while ((c = yylex(0)) == WORD) |
1936 | word(yylval.cp); | 1890 | word(yylval.cp); |
1937 | word(NOWORD); | 1891 | word(NOWORD); |
1938 | peeksym = c; | 1892 | peeksym = c; |
1939 | return(copyw()); | 1893 | return (copyw()); |
1940 | } | 1894 | } |
1941 | 1895 | ||
1942 | /* | 1896 | /* |
1943 | * supporting functions | 1897 | * supporting functions |
1944 | */ | 1898 | */ |
1945 | static struct op * | 1899 | static struct op *list(t1, t2) |
1946 | list(t1, t2) | ||
1947 | register struct op *t1, *t2; | 1900 | register struct op *t1, *t2; |
1948 | { | 1901 | { |
1949 | if (t1 == NULL) | 1902 | if (t1 == NULL) |
1950 | return(t2); | 1903 | return (t2); |
1951 | if (t2 == NULL) | 1904 | if (t2 == NULL) |
1952 | return(t1); | 1905 | return (t1); |
1953 | return(block(TLIST, t1, t2, NOWORDS)); | 1906 | return (block(TLIST, t1, t2, NOWORDS)); |
1954 | } | 1907 | } |
1955 | 1908 | ||
1956 | static struct op * | 1909 | static struct op *block(type, t1, t2, wp) |
1957 | block(type, t1, t2, wp) | ||
1958 | int type; | 1910 | int type; |
1959 | struct op *t1, *t2; | 1911 | struct op *t1, *t2; |
1960 | char **wp; | 1912 | char **wp; |
@@ -1966,42 +1918,39 @@ char **wp; | |||
1966 | t->left = t1; | 1918 | t->left = t1; |
1967 | t->right = t2; | 1919 | t->right = t2; |
1968 | t->words = wp; | 1920 | t->words = wp; |
1969 | return(t); | 1921 | return (t); |
1970 | } | 1922 | } |
1971 | 1923 | ||
1972 | static int | 1924 | static int rlookup(n) |
1973 | rlookup(n) | ||
1974 | register char *n; | 1925 | register char *n; |
1975 | { | 1926 | { |
1976 | register struct res *rp; | 1927 | register struct res *rp; |
1977 | 1928 | ||
1978 | for (rp = restab; rp->r_name; rp++) | 1929 | for (rp = restab; rp->r_name; rp++) |
1979 | if (strcmp(rp->r_name, n) == 0) | 1930 | if (strcmp(rp->r_name, n) == 0) |
1980 | return(rp->r_val); | 1931 | return (rp->r_val); |
1981 | return(0); | 1932 | return (0); |
1982 | } | 1933 | } |
1983 | 1934 | ||
1984 | static struct op * | 1935 | static struct op *newtp() |
1985 | newtp() | ||
1986 | { | 1936 | { |
1987 | register struct op *t; | 1937 | register struct op *t; |
1988 | 1938 | ||
1989 | t = (struct op *)tree(sizeof(*t)); | 1939 | t = (struct op *) tree(sizeof(*t)); |
1990 | t->type = 0; | 1940 | t->type = 0; |
1991 | t->words = NULL; | 1941 | t->words = NULL; |
1992 | t->ioact = NULL; | 1942 | t->ioact = NULL; |
1993 | t->left = NULL; | 1943 | t->left = NULL; |
1994 | t->right = NULL; | 1944 | t->right = NULL; |
1995 | t->str = NULL; | 1945 | t->str = NULL; |
1996 | return(t); | 1946 | return (t); |
1997 | } | 1947 | } |
1998 | 1948 | ||
1999 | static struct op * | 1949 | static struct op *namelist(t) |
2000 | namelist(t) | ||
2001 | register struct op *t; | 1950 | register struct op *t; |
2002 | { | 1951 | { |
2003 | if (iolist) { | 1952 | if (iolist) { |
2004 | iolist = addword((char *)NULL, iolist); | 1953 | iolist = addword((char *) NULL, iolist); |
2005 | t->ioact = copyio(); | 1954 | t->ioact = copyio(); |
2006 | } else | 1955 | } else |
2007 | t->ioact = NULL; | 1956 | t->ioact = NULL; |
@@ -2011,42 +1960,38 @@ register struct op *t; | |||
2011 | t->ioact = t->left->ioact; | 1960 | t->ioact = t->left->ioact; |
2012 | t->left->ioact = NULL; | 1961 | t->left->ioact = NULL; |
2013 | } | 1962 | } |
2014 | return(t); | 1963 | return (t); |
2015 | } | 1964 | } |
2016 | word(NOWORD); | 1965 | word(NOWORD); |
2017 | t->words = copyw(); | 1966 | t->words = copyw(); |
2018 | return(t); | 1967 | return (t); |
2019 | } | 1968 | } |
2020 | 1969 | ||
2021 | static char ** | 1970 | static char **copyw() |
2022 | copyw() | ||
2023 | { | 1971 | { |
2024 | register char **wd; | 1972 | register char **wd; |
2025 | 1973 | ||
2026 | wd = getwords(wdlist); | 1974 | wd = getwords(wdlist); |
2027 | wdlist = 0; | 1975 | wdlist = 0; |
2028 | return(wd); | 1976 | return (wd); |
2029 | } | 1977 | } |
2030 | 1978 | ||
2031 | static void | 1979 | static void word(cp) |
2032 | word(cp) | ||
2033 | char *cp; | 1980 | char *cp; |
2034 | { | 1981 | { |
2035 | wdlist = addword(cp, wdlist); | 1982 | wdlist = addword(cp, wdlist); |
2036 | } | 1983 | } |
2037 | 1984 | ||
2038 | static struct ioword ** | 1985 | static struct ioword **copyio() |
2039 | copyio() | ||
2040 | { | 1986 | { |
2041 | register struct ioword **iop; | 1987 | register struct ioword **iop; |
2042 | 1988 | ||
2043 | iop = (struct ioword **) getwords(iolist); | 1989 | iop = (struct ioword **) getwords(iolist); |
2044 | iolist = 0; | 1990 | iolist = 0; |
2045 | return(iop); | 1991 | return (iop); |
2046 | } | 1992 | } |
2047 | 1993 | ||
2048 | static struct ioword * | 1994 | static struct ioword *io(u, f, cp) |
2049 | io(u, f, cp) | ||
2050 | int u; | 1995 | int u; |
2051 | int f; | 1996 | int f; |
2052 | char *cp; | 1997 | char *cp; |
@@ -2057,32 +2002,28 @@ char *cp; | |||
2057 | iop->io_unit = u; | 2002 | iop->io_unit = u; |
2058 | iop->io_flag = f; | 2003 | iop->io_flag = f; |
2059 | iop->io_name = cp; | 2004 | iop->io_name = cp; |
2060 | iolist = addword((char *)iop, iolist); | 2005 | iolist = addword((char *) iop, iolist); |
2061 | return(iop); | 2006 | return (iop); |
2062 | } | 2007 | } |
2063 | 2008 | ||
2064 | static void | 2009 | static void zzerr() |
2065 | zzerr() | ||
2066 | { | 2010 | { |
2067 | yyerror("syntax error"); | 2011 | yyerror("syntax error"); |
2068 | } | 2012 | } |
2069 | 2013 | ||
2070 | static void | 2014 | static void yyerror(s) |
2071 | yyerror(s) | ||
2072 | char *s; | 2015 | char *s; |
2073 | { | 2016 | { |
2074 | yynerrs++; | 2017 | yynerrs++; |
2075 | if (interactive && e.iop <= iostack) { | 2018 | if (interactive && e.iop <= iostack) { |
2076 | multiline = 0; | 2019 | multiline = 0; |
2077 | while (eofc() == 0 && yylex(0) != '\n') | 2020 | while (eofc() == 0 && yylex(0) != '\n'); |
2078 | ; | ||
2079 | } | 2021 | } |
2080 | err(s); | 2022 | err(s); |
2081 | fail(); | 2023 | fail(); |
2082 | } | 2024 | } |
2083 | 2025 | ||
2084 | static int | 2026 | static int yylex(cf) |
2085 | yylex(cf) | ||
2086 | int cf; | 2027 | int cf; |
2087 | { | 2028 | { |
2088 | register int c, c1; | 2029 | register int c, c1; |
@@ -2092,7 +2033,7 @@ int cf; | |||
2092 | peeksym = 0; | 2033 | peeksym = 0; |
2093 | if (c == '\n') | 2034 | if (c == '\n') |
2094 | startl = 1; | 2035 | startl = 1; |
2095 | return(c); | 2036 | return (c); |
2096 | } | 2037 | } |
2097 | nlseen = 0; | 2038 | nlseen = 0; |
2098 | e.linep = line; | 2039 | e.linep = line; |
@@ -2100,9 +2041,8 @@ int cf; | |||
2100 | startl = 0; | 2041 | startl = 0; |
2101 | yylval.i = 0; | 2042 | yylval.i = 0; |
2102 | 2043 | ||
2103 | loop: | 2044 | loop: |
2104 | while ((c = my_getc(0)) == ' ' || c == '\t') | 2045 | while ((c = my_getc(0)) == ' ' || c == '\t'); |
2105 | ; | ||
2106 | switch (c) { | 2046 | switch (c) { |
2107 | default: | 2047 | default: |
2108 | if (any(c, "0123456789")) { | 2048 | if (any(c, "0123456789")) { |
@@ -2117,19 +2057,18 @@ loop: | |||
2117 | break; | 2057 | break; |
2118 | 2058 | ||
2119 | case '#': | 2059 | case '#': |
2120 | while ((c = my_getc(0)) != 0 && c != '\n') | 2060 | while ((c = my_getc(0)) != 0 && c != '\n'); |
2121 | ; | ||
2122 | unget(c); | 2061 | unget(c); |
2123 | goto loop; | 2062 | goto loop; |
2124 | 2063 | ||
2125 | case 0: | 2064 | case 0: |
2126 | return(c); | 2065 | return (c); |
2127 | 2066 | ||
2128 | case '$': | 2067 | case '$': |
2129 | *e.linep++ = c; | 2068 | *e.linep++ = c; |
2130 | if ((c = my_getc(0)) == '{') { | 2069 | if ((c = my_getc(0)) == '{') { |
2131 | if ((c = collect(c, '}')) != '\0') | 2070 | if ((c = collect(c, '}')) != '\0') |
2132 | return(c); | 2071 | return (c); |
2133 | goto pack; | 2072 | goto pack; |
2134 | } | 2073 | } |
2135 | break; | 2074 | break; |
@@ -2138,7 +2077,7 @@ loop: | |||
2138 | case '\'': | 2077 | case '\'': |
2139 | case '"': | 2078 | case '"': |
2140 | if ((c = collect(c, c)) != '\0') | 2079 | if ((c = collect(c, c)) != '\0') |
2141 | return(c); | 2080 | return (c); |
2142 | goto pack; | 2081 | goto pack; |
2143 | 2082 | ||
2144 | case '|': | 2083 | case '|': |
@@ -2146,17 +2085,17 @@ loop: | |||
2146 | case ';': | 2085 | case ';': |
2147 | if ((c1 = dual(c)) != '\0') { | 2086 | if ((c1 = dual(c)) != '\0') { |
2148 | startl = 1; | 2087 | startl = 1; |
2149 | return(c1); | 2088 | return (c1); |
2150 | } | 2089 | } |
2151 | startl = 1; | 2090 | startl = 1; |
2152 | return(c); | 2091 | return (c); |
2153 | case '^': | 2092 | case '^': |
2154 | startl = 1; | 2093 | startl = 1; |
2155 | return('|'); | 2094 | return ('|'); |
2156 | case '>': | 2095 | case '>': |
2157 | case '<': | 2096 | case '<': |
2158 | diag(c); | 2097 | diag(c); |
2159 | return(c); | 2098 | return (c); |
2160 | 2099 | ||
2161 | case '\n': | 2100 | case '\n': |
2162 | nlseen++; | 2101 | nlseen++; |
@@ -2165,44 +2104,43 @@ loop: | |||
2165 | if (multiline || cf & CONTIN) { | 2104 | if (multiline || cf & CONTIN) { |
2166 | if (interactive && e.iop <= iostack) { | 2105 | if (interactive && e.iop <= iostack) { |
2167 | #ifdef CONFIG_FEATURE_COMMAND_EDITING | 2106 | #ifdef CONFIG_FEATURE_COMMAND_EDITING |
2168 | current_prompt=cprompt->value; | 2107 | current_prompt = cprompt->value; |
2169 | #else | 2108 | #else |
2170 | prs(cprompt->value); | 2109 | prs(cprompt->value); |
2171 | #endif | 2110 | #endif |
2172 | } | 2111 | } |
2173 | if (cf & CONTIN) | 2112 | if (cf & CONTIN) |
2174 | goto loop; | 2113 | goto loop; |
2175 | } | 2114 | } |
2176 | return(c); | 2115 | return (c); |
2177 | 2116 | ||
2178 | case '(': | 2117 | case '(': |
2179 | case ')': | 2118 | case ')': |
2180 | startl = 1; | 2119 | startl = 1; |
2181 | return(c); | 2120 | return (c); |
2182 | } | 2121 | } |
2183 | 2122 | ||
2184 | unget(c); | 2123 | unget(c); |
2185 | 2124 | ||
2186 | pack: | 2125 | pack: |
2187 | while ((c = my_getc(0)) != 0 && !any(c, "`$ '\"\t;&<>()|^\n")) | 2126 | while ((c = my_getc(0)) != 0 && !any(c, "`$ '\"\t;&<>()|^\n")) |
2188 | if (e.linep >= elinep) | 2127 | if (e.linep >= elinep) |
2189 | err("word too long"); | 2128 | err("word too long"); |
2190 | else | 2129 | else |
2191 | *e.linep++ = c; | 2130 | *e.linep++ = c; |
2192 | unget(c); | 2131 | unget(c); |
2193 | if(any(c, "\"'`$")) | 2132 | if (any(c, "\"'`$")) |
2194 | goto loop; | 2133 | goto loop; |
2195 | *e.linep++ = '\0'; | 2134 | *e.linep++ = '\0'; |
2196 | if (atstart && (c = rlookup(line))!=0) { | 2135 | if (atstart && (c = rlookup(line)) != 0) { |
2197 | startl = 1; | 2136 | startl = 1; |
2198 | return(c); | 2137 | return (c); |
2199 | } | 2138 | } |
2200 | yylval.cp = strsave(line, areanum); | 2139 | yylval.cp = strsave(line, areanum); |
2201 | return(WORD); | 2140 | return (WORD); |
2202 | } | 2141 | } |
2203 | 2142 | ||
2204 | static int | 2143 | static int collect(c, c1) |
2205 | collect(c, c1) | ||
2206 | register int c, c1; | 2144 | register int c, c1; |
2207 | { | 2145 | { |
2208 | char s[2]; | 2146 | char s[2]; |
@@ -2213,24 +2151,24 @@ register int c, c1; | |||
2213 | unget(c); | 2151 | unget(c); |
2214 | s[0] = c1; | 2152 | s[0] = c1; |
2215 | s[1] = 0; | 2153 | s[1] = 0; |
2216 | prs("no closing "); yyerror(s); | 2154 | prs("no closing "); |
2217 | return(YYERRCODE); | 2155 | yyerror(s); |
2156 | return (YYERRCODE); | ||
2218 | } | 2157 | } |
2219 | if (interactive && c == '\n' && e.iop <= iostack) { | 2158 | if (interactive && c == '\n' && e.iop <= iostack) { |
2220 | #ifdef CONFIG_FEATURE_COMMAND_EDITING | 2159 | #ifdef CONFIG_FEATURE_COMMAND_EDITING |
2221 | current_prompt=cprompt->value; | 2160 | current_prompt = cprompt->value; |
2222 | #else | 2161 | #else |
2223 | prs(cprompt->value); | 2162 | prs(cprompt->value); |
2224 | #endif | 2163 | #endif |
2225 | } | 2164 | } |
2226 | *e.linep++ = c; | 2165 | *e.linep++ = c; |
2227 | } | 2166 | } |
2228 | *e.linep++ = c; | 2167 | *e.linep++ = c; |
2229 | return(0); | 2168 | return (0); |
2230 | } | 2169 | } |
2231 | 2170 | ||
2232 | static int | 2171 | static int dual(c) |
2233 | dual(c) | ||
2234 | register int c; | 2172 | register int c; |
2235 | { | 2173 | { |
2236 | char s[3]; | 2174 | char s[3]; |
@@ -2241,11 +2179,10 @@ register int c; | |||
2241 | *cp = 0; | 2179 | *cp = 0; |
2242 | if ((c = rlookup(s)) == 0) | 2180 | if ((c = rlookup(s)) == 0) |
2243 | unget(*--cp); | 2181 | unget(*--cp); |
2244 | return(c); | 2182 | return (c); |
2245 | } | 2183 | } |
2246 | 2184 | ||
2247 | static void | 2185 | static void diag(ec) |
2248 | diag(ec) | ||
2249 | register int ec; | 2186 | register int ec; |
2250 | { | 2187 | { |
2251 | register int c; | 2188 | register int c; |
@@ -2254,18 +2191,17 @@ register int ec; | |||
2254 | if (c == '>' || c == '<') { | 2191 | if (c == '>' || c == '<') { |
2255 | if (c != ec) | 2192 | if (c != ec) |
2256 | zzerr(); | 2193 | zzerr(); |
2257 | yylval.i = ec == '>'? IOWRITE|IOCAT: IOHERE; | 2194 | yylval.i = ec == '>' ? IOWRITE | IOCAT : IOHERE; |
2258 | c = my_getc(0); | 2195 | c = my_getc(0); |
2259 | } else | 2196 | } else |
2260 | yylval.i = ec == '>'? IOWRITE: IOREAD; | 2197 | yylval.i = ec == '>' ? IOWRITE : IOREAD; |
2261 | if (c != '&' || yylval.i == IOHERE) | 2198 | if (c != '&' || yylval.i == IOHERE) |
2262 | unget(c); | 2199 | unget(c); |
2263 | else | 2200 | else |
2264 | yylval.i |= IODUP; | 2201 | yylval.i |= IODUP; |
2265 | } | 2202 | } |
2266 | 2203 | ||
2267 | static char * | 2204 | static char *tree(size) |
2268 | tree(size) | ||
2269 | unsigned size; | 2205 | unsigned size; |
2270 | { | 2206 | { |
2271 | register char *t; | 2207 | register char *t; |
@@ -2275,7 +2211,7 @@ unsigned size; | |||
2275 | fail(); | 2211 | fail(); |
2276 | /* NOTREACHED */ | 2212 | /* NOTREACHED */ |
2277 | } | 2213 | } |
2278 | return(t); | 2214 | return (t); |
2279 | } | 2215 | } |
2280 | 2216 | ||
2281 | /* VARARGS1 */ | 2217 | /* VARARGS1 */ |
@@ -2288,8 +2224,7 @@ unsigned size; | |||
2288 | */ | 2224 | */ |
2289 | 2225 | ||
2290 | 2226 | ||
2291 | static int | 2227 | static int execute(t, pin, pout, act) |
2292 | execute(t, pin, pout, act) | ||
2293 | register struct op *t; | 2228 | register struct op *t; |
2294 | int *pin, *pout; | 2229 | int *pin, *pout; |
2295 | int act; | 2230 | int act; |
@@ -2307,14 +2242,14 @@ int act; | |||
2307 | 2242 | ||
2308 | 2243 | ||
2309 | if (t == NULL) | 2244 | if (t == NULL) |
2310 | return(0); | 2245 | return (0); |
2311 | rv = 0; | 2246 | rv = 0; |
2312 | a = areanum++; | 2247 | a = areanum++; |
2313 | wp = (wp2 = t->words) != NULL | 2248 | wp = (wp2 = t->words) != NULL |
2314 | ? eval(wp2, t->type == TCOM ? DOALL : DOALL & ~DOKEY) | 2249 | ? eval(wp2, t->type == TCOM ? DOALL : DOALL & ~DOKEY) |
2315 | : NULL; | 2250 | : NULL; |
2316 | 2251 | ||
2317 | switch(t->type) { | 2252 | switch (t->type) { |
2318 | case TPAREN: | 2253 | case TPAREN: |
2319 | rv = execute(t->left, pin, pout, 0); | 2254 | rv = execute(t->left, pin, pout, 0); |
2320 | break; | 2255 | break; |
@@ -2322,6 +2257,7 @@ int act; | |||
2322 | case TCOM: | 2257 | case TCOM: |
2323 | { | 2258 | { |
2324 | int child; | 2259 | int child; |
2260 | |||
2325 | rv = forkexec(t, pin, pout, act, wp, &child); | 2261 | rv = forkexec(t, pin, pout, act, wp, &child); |
2326 | if (child) { | 2262 | if (child) { |
2327 | exstat = rv; | 2263 | exstat = rv; |
@@ -2332,13 +2268,14 @@ int act; | |||
2332 | 2268 | ||
2333 | case TPIPE: | 2269 | case TPIPE: |
2334 | { | 2270 | { |
2335 | int pv[2]; | 2271 | int pv[2]; |
2336 | if ((rv = openpipe(pv)) < 0) | 2272 | |
2337 | break; | 2273 | if ((rv = openpipe(pv)) < 0) |
2338 | pv[0] = remap(pv[0]); | 2274 | break; |
2339 | pv[1] = remap(pv[1]); | 2275 | pv[0] = remap(pv[0]); |
2340 | (void) execute(t->left, pin, pv, 0); | 2276 | pv[1] = remap(pv[1]); |
2341 | rv = execute(t->right, pv, pout, 0); | 2277 | (void) execute(t->left, pin, pv, 0); |
2278 | rv = execute(t->right, pv, pout, 0); | ||
2342 | } | 2279 | } |
2343 | break; | 2280 | break; |
2344 | 2281 | ||
@@ -2348,54 +2285,53 @@ int act; | |||
2348 | break; | 2285 | break; |
2349 | 2286 | ||
2350 | case TASYNC: | 2287 | case TASYNC: |
2351 | { | 2288 | { |
2352 | int hinteractive = interactive; | 2289 | int hinteractive = interactive; |
2353 | 2290 | ||
2354 | i = vfork(); | 2291 | i = vfork(); |
2355 | if (i != 0) { | 2292 | if (i != 0) { |
2356 | interactive = hinteractive; | 2293 | interactive = hinteractive; |
2357 | if (i != -1) { | 2294 | if (i != -1) { |
2358 | setval(lookup("!"), putn(i)); | 2295 | setval(lookup("!"), putn(i)); |
2359 | if (pin != NULL) | 2296 | if (pin != NULL) |
2360 | closepipe(pin); | 2297 | closepipe(pin); |
2361 | if (interactive) { | 2298 | if (interactive) { |
2362 | prs(putn(i)); | 2299 | prs(putn(i)); |
2363 | prs("\n"); | 2300 | prs("\n"); |
2301 | } | ||
2302 | } else | ||
2303 | rv = -1; | ||
2304 | setstatus(rv); | ||
2305 | } else { | ||
2306 | signal(SIGINT, SIG_IGN); | ||
2307 | signal(SIGQUIT, SIG_IGN); | ||
2308 | if (interactive) | ||
2309 | signal(SIGTERM, SIG_DFL); | ||
2310 | interactive = 0; | ||
2311 | if (pin == NULL) { | ||
2312 | close(0); | ||
2313 | open("/dev/null", 0); | ||
2364 | } | 2314 | } |
2365 | } else | 2315 | exit(execute(t->left, pin, pout, FEXEC)); |
2366 | rv = -1; | ||
2367 | setstatus(rv); | ||
2368 | } else { | ||
2369 | signal(SIGINT, SIG_IGN); | ||
2370 | signal(SIGQUIT, SIG_IGN); | ||
2371 | if (interactive) | ||
2372 | signal(SIGTERM, SIG_DFL); | ||
2373 | interactive = 0; | ||
2374 | if (pin == NULL) { | ||
2375 | close(0); | ||
2376 | open("/dev/null", 0); | ||
2377 | } | 2316 | } |
2378 | exit(execute(t->left, pin, pout, FEXEC)); | ||
2379 | } | 2317 | } |
2380 | } | ||
2381 | break; | 2318 | break; |
2382 | 2319 | ||
2383 | case TOR: | 2320 | case TOR: |
2384 | case TAND: | 2321 | case TAND: |
2385 | rv = execute(t->left, pin, pout, 0); | 2322 | rv = execute(t->left, pin, pout, 0); |
2386 | if ((t1 = t->right)!=NULL && (rv == 0) == (t->type == TAND)) | 2323 | if ((t1 = t->right) != NULL && (rv == 0) == (t->type == TAND)) |
2387 | rv = execute(t1, pin, pout, 0); | 2324 | rv = execute(t1, pin, pout, 0); |
2388 | break; | 2325 | break; |
2389 | 2326 | ||
2390 | case TFOR: | 2327 | case TFOR: |
2391 | if (wp == NULL) { | 2328 | if (wp == NULL) { |
2392 | wp = dolv+1; | 2329 | wp = dolv + 1; |
2393 | if ((i = dolc) < 0) | 2330 | if ((i = dolc) < 0) |
2394 | i = 0; | 2331 | i = 0; |
2395 | } else { | 2332 | } else { |
2396 | i = -1; | 2333 | i = -1; |
2397 | while (*wp++ != NULL) | 2334 | while (*wp++ != NULL); |
2398 | ; | ||
2399 | } | 2335 | } |
2400 | vp = lookup(t->str); | 2336 | vp = lookup(t->str); |
2401 | while (setjmp(bc.brkpt)) | 2337 | while (setjmp(bc.brkpt)) |
@@ -2423,15 +2359,15 @@ int act; | |||
2423 | 2359 | ||
2424 | case TIF: | 2360 | case TIF: |
2425 | case TELIF: | 2361 | case TELIF: |
2426 | if (t->right != NULL) { | 2362 | if (t->right != NULL) { |
2427 | rv = !execute(t->left, pin, pout, 0) ? | 2363 | rv = !execute(t->left, pin, pout, 0) ? |
2428 | execute(t->right->left, pin, pout, 0): | 2364 | execute(t->right->left, pin, pout, 0) : |
2429 | execute(t->right->right, pin, pout, 0); | 2365 | execute(t->right->right, pin, pout, 0); |
2430 | } | 2366 | } |
2431 | break; | 2367 | break; |
2432 | 2368 | ||
2433 | case TCASE: | 2369 | case TCASE: |
2434 | if ((cp = evalstr(t->str, DOSUB|DOTRIM)) == 0) | 2370 | if ((cp = evalstr(t->str, DOSUB | DOTRIM)) == 0) |
2435 | cp = ""; | 2371 | cp = ""; |
2436 | if ((t1 = findcase(t->left, cp)) != NULL) | 2372 | if ((t1 = findcase(t->left, cp)) != NULL) |
2437 | rv = execute(t1, pin, pout, 0); | 2373 | rv = execute(t1, pin, pout, 0); |
@@ -2451,7 +2387,7 @@ int act; | |||
2451 | break; | 2387 | break; |
2452 | } | 2388 | } |
2453 | 2389 | ||
2454 | broken: | 2390 | broken: |
2455 | t->words = wp2; | 2391 | t->words = wp2; |
2456 | isbreak = 0; | 2392 | isbreak = 0; |
2457 | freehere(areanum); | 2393 | freehere(areanum); |
@@ -2465,14 +2401,15 @@ broken: | |||
2465 | trapset = 0; | 2401 | trapset = 0; |
2466 | runtrap(i); | 2402 | runtrap(i); |
2467 | } | 2403 | } |
2468 | return(rv); | 2404 | return (rv); |
2469 | } | 2405 | } |
2470 | 2406 | ||
2471 | static int | 2407 | static int |
2472 | forkexec( register struct op *t, int *pin, int *pout, int act, char **wp, int *pforked) | 2408 | forkexec(register struct op *t, int *pin, int *pout, int act, char **wp, |
2409 | int *pforked) | ||
2473 | { | 2410 | { |
2474 | int i, rv; | 2411 | int i, rv; |
2475 | int (*shcom)(struct op *) = NULL; | 2412 | int (*shcom) (struct op *) = NULL; |
2476 | register int f; | 2413 | register int f; |
2477 | char *cp = NULL; | 2414 | char *cp = NULL; |
2478 | struct ioword **iopp; | 2415 | struct ioword **iopp; |
@@ -2485,7 +2422,7 @@ forkexec( register struct op *t, int *pin, int *pout, int act, char **wp, int *p | |||
2485 | char *hwp; | 2422 | char *hwp; |
2486 | int hinteractive; | 2423 | int hinteractive; |
2487 | int hintr; | 2424 | int hintr; |
2488 | struct brkcon * hbrklist; | 2425 | struct brkcon *hbrklist; |
2489 | int hexecflg; | 2426 | int hexecflg; |
2490 | 2427 | ||
2491 | #if __GNUC__ | 2428 | #if __GNUC__ |
@@ -2502,22 +2439,19 @@ forkexec( register struct op *t, int *pin, int *pout, int act, char **wp, int *p | |||
2502 | owp = wp; | 2439 | owp = wp; |
2503 | resetsig = 0; | 2440 | resetsig = 0; |
2504 | *pforked = 0; | 2441 | *pforked = 0; |
2505 | rv = -1; /* system-detected error */ | 2442 | rv = -1; /* system-detected error */ |
2506 | if (t->type == TCOM) { | 2443 | if (t->type == TCOM) { |
2507 | while ((cp = *wp++) != NULL) | 2444 | while ((cp = *wp++) != NULL); |
2508 | ; | ||
2509 | cp = *wp; | 2445 | cp = *wp; |
2510 | 2446 | ||
2511 | /* strip all initial assignments */ | 2447 | /* strip all initial assignments */ |
2512 | /* not correct wrt PATH=yyy command etc */ | 2448 | /* not correct wrt PATH=yyy command etc */ |
2513 | if (flag['x']) | 2449 | if (flag['x']) |
2514 | echo (cp ? wp: owp); | 2450 | echo(cp ? wp : owp); |
2515 | if (cp == NULL && t->ioact == NULL) { | 2451 | if (cp == NULL && t->ioact == NULL) { |
2516 | while ((cp = *owp++) != NULL && assign(cp, COPYV)) | 2452 | while ((cp = *owp++) != NULL && assign(cp, COPYV)); |
2517 | ; | 2453 | return (setstatus(0)); |
2518 | return(setstatus(0)); | 2454 | } else if (cp != NULL) |
2519 | } | ||
2520 | else if (cp != NULL) | ||
2521 | shcom = inbuilt(cp); | 2455 | shcom = inbuilt(cp); |
2522 | } | 2456 | } |
2523 | t->words = wp; | 2457 | t->words = wp; |
@@ -2535,7 +2469,7 @@ forkexec( register struct op *t, int *pin, int *pout, int act, char **wp, int *p | |||
2535 | 2469 | ||
2536 | i = vfork(); | 2470 | i = vfork(); |
2537 | if (i != 0) { | 2471 | if (i != 0) { |
2538 | /* who wrote this crappy non vfork safe shit? */ | 2472 | /* who wrote this crappy non vfork safe shit? */ |
2539 | pin = hpin; | 2473 | pin = hpin; |
2540 | pout = hpout; | 2474 | pout = hpout; |
2541 | *pforked = hforked; | 2475 | *pforked = hforked; |
@@ -2547,10 +2481,10 @@ forkexec( register struct op *t, int *pin, int *pout, int act, char **wp, int *p | |||
2547 | 2481 | ||
2548 | *pforked = 0; | 2482 | *pforked = 0; |
2549 | if (i == -1) | 2483 | if (i == -1) |
2550 | return(rv); | 2484 | return (rv); |
2551 | if (pin != NULL) | 2485 | if (pin != NULL) |
2552 | closepipe(pin); | 2486 | closepipe(pin); |
2553 | return(pout==NULL? setstatus(waitfor(i,0)): 0); | 2487 | return (pout == NULL ? setstatus(waitfor(i, 0)) : 0); |
2554 | } | 2488 | } |
2555 | 2489 | ||
2556 | if (interactive) { | 2490 | if (interactive) { |
@@ -2571,7 +2505,7 @@ forkexec( register struct op *t, int *pin, int *pout, int act, char **wp, int *p | |||
2571 | #ifdef COMPIPE | 2505 | #ifdef COMPIPE |
2572 | if ((pin != NULL || pout != NULL) && shcom != NULL && shcom != doexec) { | 2506 | if ((pin != NULL || pout != NULL) && shcom != NULL && shcom != doexec) { |
2573 | err("piping to/from shell builtins not yet done"); | 2507 | err("piping to/from shell builtins not yet done"); |
2574 | return(-1); | 2508 | return (-1); |
2575 | } | 2509 | } |
2576 | #endif | 2510 | #endif |
2577 | if (pin != NULL) { | 2511 | if (pin != NULL) { |
@@ -2586,16 +2520,16 @@ forkexec( register struct op *t, int *pin, int *pout, int act, char **wp, int *p | |||
2586 | if (shcom != NULL && shcom != doexec) { | 2520 | if (shcom != NULL && shcom != doexec) { |
2587 | prs(cp); | 2521 | prs(cp); |
2588 | err(": cannot redirect shell command"); | 2522 | err(": cannot redirect shell command"); |
2589 | return(-1); | 2523 | return (-1); |
2590 | } | 2524 | } |
2591 | while (*iopp) | 2525 | while (*iopp) |
2592 | if (iosetup(*iopp++, pin!=NULL, pout!=NULL)) | 2526 | if (iosetup(*iopp++, pin != NULL, pout != NULL)) |
2593 | return(rv); | 2527 | return (rv); |
2594 | } | 2528 | } |
2595 | if (shcom) | 2529 | if (shcom) |
2596 | return(setstatus((*shcom)(t))); | 2530 | return (setstatus((*shcom) (t))); |
2597 | /* should use FIOCEXCL */ | 2531 | /* should use FIOCEXCL */ |
2598 | for (i=FDBASE; i<NOFILE; i++) | 2532 | for (i = FDBASE; i < NOFILE; i++) |
2599 | close(i); | 2533 | close(i); |
2600 | if (resetsig) { | 2534 | if (resetsig) { |
2601 | signal(SIGINT, SIG_DFL); | 2535 | signal(SIGINT, SIG_DFL); |
@@ -2607,7 +2541,9 @@ forkexec( register struct op *t, int *pin, int *pout, int act, char **wp, int *p | |||
2607 | exit(0); | 2541 | exit(0); |
2608 | 2542 | ||
2609 | cp = rexecve(wp[0], wp, makenv()); | 2543 | cp = rexecve(wp[0], wp, makenv()); |
2610 | prs(wp[0]); prs(": "); warn(cp); | 2544 | prs(wp[0]); |
2545 | prs(": "); | ||
2546 | warn(cp); | ||
2611 | if (!execflg) | 2547 | if (!execflg) |
2612 | trap[0] = NULL; | 2548 | trap[0] = NULL; |
2613 | leave(); | 2549 | leave(); |
@@ -2619,35 +2555,34 @@ forkexec( register struct op *t, int *pin, int *pout, int act, char **wp, int *p | |||
2619 | * 0< 1> are ignored as required | 2555 | * 0< 1> are ignored as required |
2620 | * within pipelines. | 2556 | * within pipelines. |
2621 | */ | 2557 | */ |
2622 | static int | 2558 | static int iosetup(iop, pipein, pipeout) |
2623 | iosetup(iop, pipein, pipeout) | ||
2624 | register struct ioword *iop; | 2559 | register struct ioword *iop; |
2625 | int pipein, pipeout; | 2560 | int pipein, pipeout; |
2626 | { | 2561 | { |
2627 | register int u = -1; | 2562 | register int u = -1; |
2628 | char *cp=NULL, *msg; | 2563 | char *cp = NULL, *msg; |
2629 | 2564 | ||
2630 | if (iop->io_unit == IODEFAULT) /* take default */ | 2565 | if (iop->io_unit == IODEFAULT) /* take default */ |
2631 | iop->io_unit = iop->io_flag&(IOREAD|IOHERE)? 0: 1; | 2566 | iop->io_unit = iop->io_flag & (IOREAD | IOHERE) ? 0 : 1; |
2632 | if (pipein && iop->io_unit == 0) | 2567 | if (pipein && iop->io_unit == 0) |
2633 | return(0); | 2568 | return (0); |
2634 | if (pipeout && iop->io_unit == 1) | 2569 | if (pipeout && iop->io_unit == 1) |
2635 | return(0); | 2570 | return (0); |
2636 | msg = iop->io_flag&(IOREAD|IOHERE)? "open": "create"; | 2571 | msg = iop->io_flag & (IOREAD | IOHERE) ? "open" : "create"; |
2637 | if ((iop->io_flag & IOHERE) == 0) { | 2572 | if ((iop->io_flag & IOHERE) == 0) { |
2638 | cp = iop->io_name; | 2573 | cp = iop->io_name; |
2639 | if ((cp = evalstr(cp, DOSUB|DOTRIM)) == NULL) | 2574 | if ((cp = evalstr(cp, DOSUB | DOTRIM)) == NULL) |
2640 | return(1); | 2575 | return (1); |
2641 | } | 2576 | } |
2642 | if (iop->io_flag & IODUP) { | 2577 | if (iop->io_flag & IODUP) { |
2643 | if (cp[1] || (!isdigit(*cp) && *cp != '-')) { | 2578 | if (cp[1] || (!isdigit(*cp) && *cp != '-')) { |
2644 | prs(cp); | 2579 | prs(cp); |
2645 | err(": illegal >& argument"); | 2580 | err(": illegal >& argument"); |
2646 | return(1); | 2581 | return (1); |
2647 | } | 2582 | } |
2648 | if (*cp == '-') | 2583 | if (*cp == '-') |
2649 | iop->io_flag = IOCLOSE; | 2584 | iop->io_flag = IOCLOSE; |
2650 | iop->io_flag &= ~(IOREAD|IOWRITE); | 2585 | iop->io_flag &= ~(IOREAD | IOWRITE); |
2651 | } | 2586 | } |
2652 | switch (iop->io_flag) { | 2587 | switch (iop->io_flag) { |
2653 | case IOREAD: | 2588 | case IOREAD: |
@@ -2655,14 +2590,14 @@ int pipein, pipeout; | |||
2655 | break; | 2590 | break; |
2656 | 2591 | ||
2657 | case IOHERE: | 2592 | case IOHERE: |
2658 | case IOHERE|IOXHERE: | 2593 | case IOHERE | IOXHERE: |
2659 | u = herein(iop->io_name, iop->io_flag&IOXHERE); | 2594 | u = herein(iop->io_name, iop->io_flag & IOXHERE); |
2660 | cp = "here file"; | 2595 | cp = "here file"; |
2661 | break; | 2596 | break; |
2662 | 2597 | ||
2663 | case IOWRITE|IOCAT: | 2598 | case IOWRITE | IOCAT: |
2664 | if ((u = open(cp, 1)) >= 0) { | 2599 | if ((u = open(cp, 1)) >= 0) { |
2665 | lseek(u, (long)0, 2); | 2600 | lseek(u, (long) 0, 2); |
2666 | break; | 2601 | break; |
2667 | } | 2602 | } |
2668 | case IOWRITE: | 2603 | case IOWRITE: |
@@ -2670,35 +2605,34 @@ int pipein, pipeout; | |||
2670 | break; | 2605 | break; |
2671 | 2606 | ||
2672 | case IODUP: | 2607 | case IODUP: |
2673 | u = dup2(*cp-'0', iop->io_unit); | 2608 | u = dup2(*cp - '0', iop->io_unit); |
2674 | break; | 2609 | break; |
2675 | 2610 | ||
2676 | case IOCLOSE: | 2611 | case IOCLOSE: |
2677 | close(iop->io_unit); | 2612 | close(iop->io_unit); |
2678 | return(0); | 2613 | return (0); |
2679 | } | 2614 | } |
2680 | if (u < 0) { | 2615 | if (u < 0) { |
2681 | prs(cp); | 2616 | prs(cp); |
2682 | prs(": cannot "); | 2617 | prs(": cannot "); |
2683 | warn(msg); | 2618 | warn(msg); |
2684 | return(1); | 2619 | return (1); |
2685 | } else { | 2620 | } else { |
2686 | if (u != iop->io_unit) { | 2621 | if (u != iop->io_unit) { |
2687 | dup2(u, iop->io_unit); | 2622 | dup2(u, iop->io_unit); |
2688 | close(u); | 2623 | close(u); |
2689 | } | 2624 | } |
2690 | } | 2625 | } |
2691 | return(0); | 2626 | return (0); |
2692 | } | 2627 | } |
2693 | 2628 | ||
2694 | static void | 2629 | static void echo(wp) |
2695 | echo(wp) | ||
2696 | register char **wp; | 2630 | register char **wp; |
2697 | { | 2631 | { |
2698 | register int i; | 2632 | register int i; |
2699 | 2633 | ||
2700 | prs("+"); | 2634 | prs("+"); |
2701 | for (i=0; wp[i]; i++) { | 2635 | for (i = 0; wp[i]; i++) { |
2702 | if (i) | 2636 | if (i) |
2703 | prs(" "); | 2637 | prs(" "); |
2704 | prs(wp[i]); | 2638 | prs(wp[i]); |
@@ -2706,8 +2640,7 @@ register char **wp; | |||
2706 | prs("\n"); | 2640 | prs("\n"); |
2707 | } | 2641 | } |
2708 | 2642 | ||
2709 | static struct op ** | 2643 | static struct op **find1case(t, w) |
2710 | find1case(t, w) | ||
2711 | struct op *t; | 2644 | struct op *t; |
2712 | char *w; | 2645 | char *w; |
2713 | { | 2646 | { |
@@ -2716,34 +2649,32 @@ char *w; | |||
2716 | register char **wp, *cp; | 2649 | register char **wp, *cp; |
2717 | 2650 | ||
2718 | if (t == NULL) | 2651 | if (t == NULL) |
2719 | return((struct op **)NULL); | 2652 | return ((struct op **) NULL); |
2720 | if (t->type == TLIST) { | 2653 | if (t->type == TLIST) { |
2721 | if ((tp = find1case(t->left, w)) != NULL) | 2654 | if ((tp = find1case(t->left, w)) != NULL) |
2722 | return(tp); | 2655 | return (tp); |
2723 | t1 = t->right; /* TPAT */ | 2656 | t1 = t->right; /* TPAT */ |
2724 | } else | 2657 | } else |
2725 | t1 = t; | 2658 | t1 = t; |
2726 | for (wp = t1->words; *wp;) | 2659 | for (wp = t1->words; *wp;) |
2727 | if ((cp = evalstr(*wp++, DOSUB)) && gmatch(w, cp)) | 2660 | if ((cp = evalstr(*wp++, DOSUB)) && gmatch(w, cp)) |
2728 | return(&t1->left); | 2661 | return (&t1->left); |
2729 | return((struct op **)NULL); | 2662 | return ((struct op **) NULL); |
2730 | } | 2663 | } |
2731 | 2664 | ||
2732 | static struct op * | 2665 | static struct op *findcase(t, w) |
2733 | findcase(t, w) | ||
2734 | struct op *t; | 2666 | struct op *t; |
2735 | char *w; | 2667 | char *w; |
2736 | { | 2668 | { |
2737 | register struct op **tp; | 2669 | register struct op **tp; |
2738 | 2670 | ||
2739 | return((tp = find1case(t, w)) != NULL? *tp: (struct op *)NULL); | 2671 | return ((tp = find1case(t, w)) != NULL ? *tp : (struct op *) NULL); |
2740 | } | 2672 | } |
2741 | 2673 | ||
2742 | /* | 2674 | /* |
2743 | * Enter a new loop level (marked for break/continue). | 2675 | * Enter a new loop level (marked for break/continue). |
2744 | */ | 2676 | */ |
2745 | static void | 2677 | static void brkset(bc) |
2746 | brkset(bc) | ||
2747 | struct brkcon *bc; | 2678 | struct brkcon *bc; |
2748 | { | 2679 | { |
2749 | bc->nextlev = brklist; | 2680 | bc->nextlev = brklist; |
@@ -2757,8 +2688,7 @@ struct brkcon *bc; | |||
2757 | * Ignore interrupt signals while waiting | 2688 | * Ignore interrupt signals while waiting |
2758 | * unless `canintr' is true. | 2689 | * unless `canintr' is true. |
2759 | */ | 2690 | */ |
2760 | static int | 2691 | static int waitfor(lastpid, canintr) |
2761 | waitfor(lastpid, canintr) | ||
2762 | register int lastpid; | 2692 | register int lastpid; |
2763 | int canintr; | 2693 | int canintr; |
2764 | { | 2694 | { |
@@ -2788,7 +2718,9 @@ int canintr; | |||
2788 | prn(pid); | 2718 | prn(pid); |
2789 | prs(": "); | 2719 | prs(": "); |
2790 | } | 2720 | } |
2791 | prs("Signal "); prn(rv); prs(" "); | 2721 | prs("Signal "); |
2722 | prn(rv); | ||
2723 | prs(" "); | ||
2792 | } | 2724 | } |
2793 | if (WAITCORE(s)) | 2725 | if (WAITCORE(s)) |
2794 | prs(" - core dumped"); | 2726 | prs(" - core dumped"); |
@@ -2805,20 +2737,20 @@ int canintr; | |||
2805 | if (canintr) | 2737 | if (canintr) |
2806 | intr = 0; | 2738 | intr = 0; |
2807 | } else { | 2739 | } else { |
2808 | if (exstat == 0) exstat = rv; | 2740 | if (exstat == 0) |
2741 | exstat = rv; | ||
2809 | onintr(0); | 2742 | onintr(0); |
2810 | } | 2743 | } |
2811 | } | 2744 | } |
2812 | return(rv); | 2745 | return (rv); |
2813 | } | 2746 | } |
2814 | 2747 | ||
2815 | static int | 2748 | static int setstatus(s) |
2816 | setstatus(s) | ||
2817 | register int s; | 2749 | register int s; |
2818 | { | 2750 | { |
2819 | exstat = s; | 2751 | exstat = s; |
2820 | setval(lookup("?"), putn(s)); | 2752 | setval(lookup("?"), putn(s)); |
2821 | return(s); | 2753 | return (s); |
2822 | } | 2754 | } |
2823 | 2755 | ||
2824 | /* | 2756 | /* |
@@ -2826,8 +2758,7 @@ register int s; | |||
2826 | * If getenv("PATH") were kept up-to-date, | 2758 | * If getenv("PATH") were kept up-to-date, |
2827 | * execvp might be used. | 2759 | * execvp might be used. |
2828 | */ | 2760 | */ |
2829 | static char * | 2761 | static char *rexecve(c, v, envp) |
2830 | rexecve(c, v, envp) | ||
2831 | char *c, **v, **envp; | 2762 | char *c, **v, **envp; |
2832 | { | 2763 | { |
2833 | register int i; | 2764 | register int i; |
@@ -2836,6 +2767,7 @@ char *c, **v, **envp; | |||
2836 | 2767 | ||
2837 | #ifdef CONFIG_FEATURE_SH_STANDALONE_SHELL | 2768 | #ifdef CONFIG_FEATURE_SH_STANDALONE_SHELL |
2838 | char *name = c; | 2769 | char *name = c; |
2770 | |||
2839 | optind = 1; | 2771 | optind = 1; |
2840 | if (find_applet_by_name(name)) { | 2772 | if (find_applet_by_name(name)) { |
2841 | /* We have to exec here since we vforked. Running | 2773 | /* We have to exec here since we vforked. Running |
@@ -2846,7 +2778,7 @@ char *c, **v, **envp; | |||
2846 | } | 2778 | } |
2847 | #endif | 2779 | #endif |
2848 | 2780 | ||
2849 | sp = any('/', c)? "": path->value; | 2781 | sp = any('/', c) ? "" : path->value; |
2850 | asis = *sp == '\0'; | 2782 | asis = *sp == '\0'; |
2851 | while (asis || *sp != '\0') { | 2783 | while (asis || *sp != '\0') { |
2852 | asis = 0; | 2784 | asis = 0; |
@@ -2858,8 +2790,7 @@ char *c, **v, **envp; | |||
2858 | } | 2790 | } |
2859 | if (tp != e.linep) | 2791 | if (tp != e.linep) |
2860 | *tp++ = '/'; | 2792 | *tp++ = '/'; |
2861 | for (i = 0; (*tp++ = c[i++]) != '\0';) | 2793 | for (i = 0; (*tp++ = c[i++]) != '\0';); |
2862 | ; | ||
2863 | 2794 | ||
2864 | execve(e.linep, v, envp); | 2795 | execve(e.linep, v, envp); |
2865 | switch (errno) { | 2796 | switch (errno) { |
@@ -2869,28 +2800,27 @@ char *c, **v, **envp; | |||
2869 | *v = e.linep; | 2800 | *v = e.linep; |
2870 | execve(DEFAULT_SHELL, v, envp); | 2801 | execve(DEFAULT_SHELL, v, envp); |
2871 | *v = tp; | 2802 | *v = tp; |
2872 | return("no Shell"); | 2803 | return ("no Shell"); |
2873 | 2804 | ||
2874 | case ENOMEM: | 2805 | case ENOMEM: |
2875 | return((char*)bb_msg_memory_exhausted); | 2806 | return ((char *) bb_msg_memory_exhausted); |
2876 | 2807 | ||
2877 | case E2BIG: | 2808 | case E2BIG: |
2878 | return("argument list too long"); | 2809 | return ("argument list too long"); |
2879 | 2810 | ||
2880 | case EACCES: | 2811 | case EACCES: |
2881 | eacces++; | 2812 | eacces++; |
2882 | break; | 2813 | break; |
2883 | } | 2814 | } |
2884 | } | 2815 | } |
2885 | return(errno==ENOENT ? "not found" : "cannot execute"); | 2816 | return (errno == ENOENT ? "not found" : "cannot execute"); |
2886 | } | 2817 | } |
2887 | 2818 | ||
2888 | /* | 2819 | /* |
2889 | * Run the command produced by generator `f' | 2820 | * Run the command produced by generator `f' |
2890 | * applied to stream `arg'. | 2821 | * applied to stream `arg'. |
2891 | */ | 2822 | */ |
2892 | static int | 2823 | static int run(struct ioarg *argp, int (*f) (struct ioarg *)) |
2893 | run(struct ioarg *argp, int (*f)(struct ioarg *)) | ||
2894 | { | 2824 | { |
2895 | struct op *otree; | 2825 | struct op *otree; |
2896 | struct wdblock *swdlist; | 2826 | struct wdblock *swdlist; |
@@ -2925,7 +2855,7 @@ run(struct ioarg *argp, int (*f)(struct ioarg *)) | |||
2925 | failpt = ofail; | 2855 | failpt = ofail; |
2926 | outtree = otree; | 2856 | outtree = otree; |
2927 | freearea(areanum--); | 2857 | freearea(areanum--); |
2928 | return(rv); | 2858 | return (rv); |
2929 | } | 2859 | } |
2930 | 2860 | ||
2931 | /* -------- do.c -------- */ | 2861 | /* -------- do.c -------- */ |
@@ -2934,7 +2864,7 @@ run(struct ioarg *argp, int (*f)(struct ioarg *)) | |||
2934 | * built-in commands: doX | 2864 | * built-in commands: doX |
2935 | */ | 2865 | */ |
2936 | 2866 | ||
2937 | static int dohelp(struct op *t ) | 2867 | static int dohelp(struct op *t) |
2938 | { | 2868 | { |
2939 | int col; | 2869 | int col; |
2940 | const struct builtincmd *x; | 2870 | const struct builtincmd *x; |
@@ -2942,7 +2872,7 @@ static int dohelp(struct op *t ) | |||
2942 | printf("\nBuilt-in commands:\n"); | 2872 | printf("\nBuilt-in commands:\n"); |
2943 | printf("-------------------\n"); | 2873 | printf("-------------------\n"); |
2944 | 2874 | ||
2945 | for (col=0, x = builtincmds; x->builtinfunc != NULL; x++) { | 2875 | for (col = 0, x = builtincmds; x->builtinfunc != NULL; x++) { |
2946 | if (!x->name) | 2876 | if (!x->name) |
2947 | continue; | 2877 | continue; |
2948 | col += printf("%s%s", ((col == 0) ? "\t" : " "), x->name); | 2878 | col += printf("%s%s", ((col == 0) ? "\t" : " "), x->name); |
@@ -2958,12 +2888,11 @@ static int dohelp(struct op *t ) | |||
2958 | extern const struct BB_applet applets[]; | 2888 | extern const struct BB_applet applets[]; |
2959 | extern const size_t NUM_APPLETS; | 2889 | extern const size_t NUM_APPLETS; |
2960 | 2890 | ||
2961 | for (i=0, applet = applets; i < NUM_APPLETS; applet++, i++) { | 2891 | for (i = 0, applet = applets; i < NUM_APPLETS; applet++, i++) { |
2962 | if (!applet->name) | 2892 | if (!applet->name) |
2963 | continue; | 2893 | continue; |
2964 | 2894 | ||
2965 | col += printf("%s%s", ((col == 0) ? "\t" : " "), | 2895 | col += printf("%s%s", ((col == 0) ? "\t" : " "), applet->name); |
2966 | applet->name); | ||
2967 | if (col > 60) { | 2896 | if (col > 60) { |
2968 | printf("\n"); | 2897 | printf("\n"); |
2969 | col = 0; | 2898 | col = 0; |
@@ -2977,51 +2906,48 @@ static int dohelp(struct op *t ) | |||
2977 | 2906 | ||
2978 | 2907 | ||
2979 | 2908 | ||
2980 | static int dolabel(struct op *t ) | 2909 | static int dolabel(struct op *t) |
2981 | { | 2910 | { |
2982 | return(0); | 2911 | return (0); |
2983 | } | 2912 | } |
2984 | 2913 | ||
2985 | static int | 2914 | static int dochdir(t) |
2986 | dochdir(t) | ||
2987 | register struct op *t; | 2915 | register struct op *t; |
2988 | { | 2916 | { |
2989 | register char *cp, *er; | 2917 | register char *cp, *er; |
2990 | 2918 | ||
2991 | if ((cp = t->words[1]) == NULL && (cp = homedir->value) == NULL) | 2919 | if ((cp = t->words[1]) == NULL && (cp = homedir->value) == NULL) |
2992 | er = ": no home directory"; | 2920 | er = ": no home directory"; |
2993 | else if(chdir(cp) < 0) | 2921 | else if (chdir(cp) < 0) |
2994 | er = ": bad directory"; | 2922 | er = ": bad directory"; |
2995 | else | 2923 | else |
2996 | return(0); | 2924 | return (0); |
2997 | prs(cp != NULL? cp: "cd"); | 2925 | prs(cp != NULL ? cp : "cd"); |
2998 | err(er); | 2926 | err(er); |
2999 | return(1); | 2927 | return (1); |
3000 | } | 2928 | } |
3001 | 2929 | ||
3002 | static int | 2930 | static int doshift(t) |
3003 | doshift(t) | ||
3004 | register struct op *t; | 2931 | register struct op *t; |
3005 | { | 2932 | { |
3006 | register int n; | 2933 | register int n; |
3007 | 2934 | ||
3008 | n = t->words[1]? getn(t->words[1]): 1; | 2935 | n = t->words[1] ? getn(t->words[1]) : 1; |
3009 | if(dolc < n) { | 2936 | if (dolc < n) { |
3010 | err("nothing to shift"); | 2937 | err("nothing to shift"); |
3011 | return(1); | 2938 | return (1); |
3012 | } | 2939 | } |
3013 | dolv[n] = dolv[0]; | 2940 | dolv[n] = dolv[0]; |
3014 | dolv += n; | 2941 | dolv += n; |
3015 | dolc -= n; | 2942 | dolc -= n; |
3016 | setval(lookup("#"), putn(dolc)); | 2943 | setval(lookup("#"), putn(dolc)); |
3017 | return(0); | 2944 | return (0); |
3018 | } | 2945 | } |
3019 | 2946 | ||
3020 | /* | 2947 | /* |
3021 | * execute login and newgrp directly | 2948 | * execute login and newgrp directly |
3022 | */ | 2949 | */ |
3023 | static int | 2950 | static int dologin(t) |
3024 | dologin(t) | ||
3025 | struct op *t; | 2951 | struct op *t; |
3026 | { | 2952 | { |
3027 | register char *cp; | 2953 | register char *cp; |
@@ -3031,12 +2957,13 @@ struct op *t; | |||
3031 | signal(SIGQUIT, SIG_DFL); | 2957 | signal(SIGQUIT, SIG_DFL); |
3032 | } | 2958 | } |
3033 | cp = rexecve(t->words[0], t->words, makenv()); | 2959 | cp = rexecve(t->words[0], t->words, makenv()); |
3034 | prs(t->words[0]); prs(": "); err(cp); | 2960 | prs(t->words[0]); |
3035 | return(1); | 2961 | prs(": "); |
2962 | err(cp); | ||
2963 | return (1); | ||
3036 | } | 2964 | } |
3037 | 2965 | ||
3038 | static int | 2966 | static int doumask(t) |
3039 | doumask(t) | ||
3040 | register struct op *t; | 2967 | register struct op *t; |
3041 | { | 2968 | { |
3042 | register int i, n; | 2969 | register int i, n; |
@@ -3045,19 +2972,18 @@ register struct op *t; | |||
3045 | if ((cp = t->words[1]) == NULL) { | 2972 | if ((cp = t->words[1]) == NULL) { |
3046 | i = umask(0); | 2973 | i = umask(0); |
3047 | umask(i); | 2974 | umask(i); |
3048 | for (n=3*4; (n-=3) >= 0;) | 2975 | for (n = 3 * 4; (n -= 3) >= 0;) |
3049 | putc('0'+((i>>n)&07), stderr); | 2976 | putc('0' + ((i >> n) & 07), stderr); |
3050 | putc('\n', stderr); | 2977 | putc('\n', stderr); |
3051 | } else { | 2978 | } else { |
3052 | for (n=0; *cp>='0' && *cp<='9'; cp++) | 2979 | for (n = 0; *cp >= '0' && *cp <= '9'; cp++) |
3053 | n = n*8 + (*cp-'0'); | 2980 | n = n * 8 + (*cp - '0'); |
3054 | umask(n); | 2981 | umask(n); |
3055 | } | 2982 | } |
3056 | return(0); | 2983 | return (0); |
3057 | } | 2984 | } |
3058 | 2985 | ||
3059 | static int | 2986 | static int doexec(t) |
3060 | doexec(t) | ||
3061 | register struct op *t; | 2987 | register struct op *t; |
3062 | { | 2988 | { |
3063 | register int i; | 2989 | register int i; |
@@ -3065,21 +2991,19 @@ register struct op *t; | |||
3065 | xint *ofail; | 2991 | xint *ofail; |
3066 | 2992 | ||
3067 | t->ioact = NULL; | 2993 | t->ioact = NULL; |
3068 | for(i = 0; (t->words[i]=t->words[i+1]) != NULL; i++) | 2994 | for (i = 0; (t->words[i] = t->words[i + 1]) != NULL; i++); |
3069 | ; | ||
3070 | if (i == 0) | 2995 | if (i == 0) |
3071 | return(1); | 2996 | return (1); |
3072 | execflg = 1; | 2997 | execflg = 1; |
3073 | ofail = failpt; | 2998 | ofail = failpt; |
3074 | if (setjmp(failpt = ex) == 0) | 2999 | if (setjmp(failpt = ex) == 0) |
3075 | execute(t, NOPIPE, NOPIPE, FEXEC); | 3000 | execute(t, NOPIPE, NOPIPE, FEXEC); |
3076 | failpt = ofail; | 3001 | failpt = ofail; |
3077 | execflg = 0; | 3002 | execflg = 0; |
3078 | return(1); | 3003 | return (1); |
3079 | } | 3004 | } |
3080 | 3005 | ||
3081 | static int | 3006 | static int dodot(t) |
3082 | dodot(t) | ||
3083 | struct op *t; | 3007 | struct op *t; |
3084 | { | 3008 | { |
3085 | register int i; | 3009 | register int i; |
@@ -3087,29 +3011,27 @@ struct op *t; | |||
3087 | char *cp; | 3011 | char *cp; |
3088 | 3012 | ||
3089 | if ((cp = t->words[1]) == NULL) | 3013 | if ((cp = t->words[1]) == NULL) |
3090 | return(0); | 3014 | return (0); |
3091 | sp = any('/', cp)? ":": path->value; | 3015 | sp = any('/', cp) ? ":" : path->value; |
3092 | while (*sp) { | 3016 | while (*sp) { |
3093 | tp = e.linep; | 3017 | tp = e.linep; |
3094 | while (*sp && (*tp = *sp++) != ':') | 3018 | while (*sp && (*tp = *sp++) != ':') |
3095 | tp++; | 3019 | tp++; |
3096 | if (tp != e.linep) | 3020 | if (tp != e.linep) |
3097 | *tp++ = '/'; | 3021 | *tp++ = '/'; |
3098 | for (i = 0; (*tp++ = cp[i++]) != '\0';) | 3022 | for (i = 0; (*tp++ = cp[i++]) != '\0';); |
3099 | ; | ||
3100 | if ((i = open(e.linep, 0)) >= 0) { | 3023 | if ((i = open(e.linep, 0)) >= 0) { |
3101 | exstat = 0; | 3024 | exstat = 0; |
3102 | next(remap(i)); | 3025 | next(remap(i)); |
3103 | return(exstat); | 3026 | return (exstat); |
3104 | } | 3027 | } |
3105 | } | 3028 | } |
3106 | prs(cp); | 3029 | prs(cp); |
3107 | err(": not found"); | 3030 | err(": not found"); |
3108 | return(-1); | 3031 | return (-1); |
3109 | } | 3032 | } |
3110 | 3033 | ||
3111 | static int | 3034 | static int dowait(t) |
3112 | dowait(t) | ||
3113 | struct op *t; | 3035 | struct op *t; |
3114 | { | 3036 | { |
3115 | register int i; | 3037 | register int i; |
@@ -3118,62 +3040,58 @@ struct op *t; | |||
3118 | if ((cp = t->words[1]) != NULL) { | 3040 | if ((cp = t->words[1]) != NULL) { |
3119 | i = getn(cp); | 3041 | i = getn(cp); |
3120 | if (i == 0) | 3042 | if (i == 0) |
3121 | return(0); | 3043 | return (0); |
3122 | } else | 3044 | } else |
3123 | i = -1; | 3045 | i = -1; |
3124 | setstatus(waitfor(i, 1)); | 3046 | setstatus(waitfor(i, 1)); |
3125 | return(0); | 3047 | return (0); |
3126 | } | 3048 | } |
3127 | 3049 | ||
3128 | static int | 3050 | static int doread(t) |
3129 | doread(t) | ||
3130 | struct op *t; | 3051 | struct op *t; |
3131 | { | 3052 | { |
3132 | register char *cp, **wp; | 3053 | register char *cp, **wp; |
3133 | register int nb = 0; | 3054 | register int nb = 0; |
3134 | register int nl = 0; | 3055 | register int nl = 0; |
3135 | 3056 | ||
3136 | if (t->words[1] == NULL) { | 3057 | if (t->words[1] == NULL) { |
3137 | err("Usage: read name ..."); | 3058 | err("Usage: read name ..."); |
3138 | return(1); | 3059 | return (1); |
3139 | } | 3060 | } |
3140 | for (wp = t->words+1; *wp; wp++) { | 3061 | for (wp = t->words + 1; *wp; wp++) { |
3141 | for (cp = e.linep; !nl && cp < elinep-1; cp++) | 3062 | for (cp = e.linep; !nl && cp < elinep - 1; cp++) |
3142 | if ((nb = read(0, cp, sizeof(*cp))) != sizeof(*cp) || | 3063 | if ((nb = read(0, cp, sizeof(*cp))) != sizeof(*cp) || |
3143 | (nl = (*cp == '\n')) || | 3064 | (nl = (*cp == '\n')) || (wp[1] && any(*cp, ifs->value))) |
3144 | (wp[1] && any(*cp, ifs->value))) | ||
3145 | break; | 3065 | break; |
3146 | *cp = 0; | 3066 | *cp = 0; |
3147 | if (nb <= 0) | 3067 | if (nb <= 0) |
3148 | break; | 3068 | break; |
3149 | setval(lookup(*wp), e.linep); | 3069 | setval(lookup(*wp), e.linep); |
3150 | } | 3070 | } |
3151 | return(nb <= 0); | 3071 | return (nb <= 0); |
3152 | } | 3072 | } |
3153 | 3073 | ||
3154 | static int | 3074 | static int doeval(t) |
3155 | doeval(t) | ||
3156 | register struct op *t; | 3075 | register struct op *t; |
3157 | { | 3076 | { |
3158 | return(RUN(awordlist, t->words+1, wdchar)); | 3077 | return (RUN(awordlist, t->words + 1, wdchar)); |
3159 | } | 3078 | } |
3160 | 3079 | ||
3161 | static int | 3080 | static int dotrap(t) |
3162 | dotrap(t) | ||
3163 | register struct op *t; | 3081 | register struct op *t; |
3164 | { | 3082 | { |
3165 | register int n, i; | 3083 | register int n, i; |
3166 | register int resetsig; | 3084 | register int resetsig; |
3167 | 3085 | ||
3168 | if (t->words[1] == NULL) { | 3086 | if (t->words[1] == NULL) { |
3169 | for (i=0; i<=_NSIG; i++) | 3087 | for (i = 0; i <= _NSIG; i++) |
3170 | if (trap[i]) { | 3088 | if (trap[i]) { |
3171 | prn(i); | 3089 | prn(i); |
3172 | prs(": "); | 3090 | prs(": "); |
3173 | prs(trap[i]); | 3091 | prs(trap[i]); |
3174 | prs("\n"); | 3092 | prs("\n"); |
3175 | } | 3093 | } |
3176 | return(0); | 3094 | return (0); |
3177 | } | 3095 | } |
3178 | resetsig = isdigit(*t->words[1]); | 3096 | resetsig = isdigit(*t->words[1]); |
3179 | for (i = resetsig ? 1 : 2; t->words[i] != NULL; ++i) { | 3097 | for (i = resetsig ? 1 : 2; t->words[i] != NULL; ++i) { |
@@ -3191,17 +3109,15 @@ register struct op *t; | |||
3191 | if (n == SIGINT) | 3109 | if (n == SIGINT) |
3192 | setsig(n, onintr); | 3110 | setsig(n, onintr); |
3193 | else | 3111 | else |
3194 | setsig(n, n == SIGQUIT ? SIG_IGN | 3112 | setsig(n, n == SIGQUIT ? SIG_IGN : SIG_DFL); |
3195 | : SIG_DFL); | ||
3196 | else | 3113 | else |
3197 | setsig(n, SIG_DFL); | 3114 | setsig(n, SIG_DFL); |
3198 | } | 3115 | } |
3199 | } | 3116 | } |
3200 | return(0); | 3117 | return (0); |
3201 | } | 3118 | } |
3202 | 3119 | ||
3203 | static int | 3120 | static int getsig(s) |
3204 | getsig(s) | ||
3205 | char *s; | 3121 | char *s; |
3206 | { | 3122 | { |
3207 | register int n; | 3123 | register int n; |
@@ -3210,11 +3126,10 @@ char *s; | |||
3210 | err("trap: bad signal number"); | 3126 | err("trap: bad signal number"); |
3211 | n = 0; | 3127 | n = 0; |
3212 | } | 3128 | } |
3213 | return(n); | 3129 | return (n); |
3214 | } | 3130 | } |
3215 | 3131 | ||
3216 | static void | 3132 | static void setsig(register int n, sighandler_t f) |
3217 | setsig( register int n, sighandler_t f) | ||
3218 | { | 3133 | { |
3219 | if (n == 0) | 3134 | if (n == 0) |
3220 | return; | 3135 | return; |
@@ -3224,8 +3139,7 @@ setsig( register int n, sighandler_t f) | |||
3224 | } | 3139 | } |
3225 | } | 3140 | } |
3226 | 3141 | ||
3227 | static int | 3142 | static int getn(as) |
3228 | getn(as) | ||
3229 | char *as; | 3143 | char *as; |
3230 | { | 3144 | { |
3231 | register char *s; | 3145 | register char *s; |
@@ -3238,37 +3152,34 @@ char *as; | |||
3238 | s++; | 3152 | s++; |
3239 | } | 3153 | } |
3240 | for (n = 0; isdigit(*s); s++) | 3154 | for (n = 0; isdigit(*s); s++) |
3241 | n = (n*10) + (*s-'0'); | 3155 | n = (n * 10) + (*s - '0'); |
3242 | if (*s) { | 3156 | if (*s) { |
3243 | prs(as); | 3157 | prs(as); |
3244 | err(": bad number"); | 3158 | err(": bad number"); |
3245 | } | 3159 | } |
3246 | return(n*m); | 3160 | return (n * m); |
3247 | } | 3161 | } |
3248 | 3162 | ||
3249 | static int | 3163 | static int dobreak(t) |
3250 | dobreak(t) | ||
3251 | struct op *t; | 3164 | struct op *t; |
3252 | { | 3165 | { |
3253 | return(brkcontin(t->words[1], 1)); | 3166 | return (brkcontin(t->words[1], 1)); |
3254 | } | 3167 | } |
3255 | 3168 | ||
3256 | static int | 3169 | static int docontinue(t) |
3257 | docontinue(t) | ||
3258 | struct op *t; | 3170 | struct op *t; |
3259 | { | 3171 | { |
3260 | return(brkcontin(t->words[1], 0)); | 3172 | return (brkcontin(t->words[1], 0)); |
3261 | } | 3173 | } |
3262 | 3174 | ||
3263 | static int | 3175 | static int brkcontin(cp, val) |
3264 | brkcontin(cp, val) | ||
3265 | register char *cp; | 3176 | register char *cp; |
3266 | int val; | 3177 | int val; |
3267 | { | 3178 | { |
3268 | register struct brkcon *bc; | 3179 | register struct brkcon *bc; |
3269 | register int nl; | 3180 | register int nl; |
3270 | 3181 | ||
3271 | nl = cp == NULL? 1: getn(cp); | 3182 | nl = cp == NULL ? 1 : getn(cp); |
3272 | if (nl <= 0) | 3183 | if (nl <= 0) |
3273 | nl = 999; | 3184 | nl = 999; |
3274 | do { | 3185 | do { |
@@ -3278,15 +3189,14 @@ int val; | |||
3278 | } while (--nl); | 3189 | } while (--nl); |
3279 | if (nl) { | 3190 | if (nl) { |
3280 | err("bad break/continue level"); | 3191 | err("bad break/continue level"); |
3281 | return(1); | 3192 | return (1); |
3282 | } | 3193 | } |
3283 | isbreak = val; | 3194 | isbreak = val; |
3284 | longjmp(bc->brkpt, 1); | 3195 | longjmp(bc->brkpt, 1); |
3285 | /* NOTREACHED */ | 3196 | /* NOTREACHED */ |
3286 | } | 3197 | } |
3287 | 3198 | ||
3288 | static int | 3199 | static int doexit(t) |
3289 | doexit(t) | ||
3290 | struct op *t; | 3200 | struct op *t; |
3291 | { | 3201 | { |
3292 | register char *cp; | 3202 | register char *cp; |
@@ -3296,38 +3206,36 @@ struct op *t; | |||
3296 | setstatus(getn(cp)); | 3206 | setstatus(getn(cp)); |
3297 | leave(); | 3207 | leave(); |
3298 | /* NOTREACHED */ | 3208 | /* NOTREACHED */ |
3299 | return(0); | 3209 | return (0); |
3300 | } | 3210 | } |
3301 | 3211 | ||
3302 | static int | 3212 | static int doexport(t) |
3303 | doexport(t) | ||
3304 | struct op *t; | 3213 | struct op *t; |
3305 | { | 3214 | { |
3306 | rdexp(t->words+1, export, EXPORT); | 3215 | rdexp(t->words + 1, export, EXPORT); |
3307 | return(0); | 3216 | return (0); |
3308 | } | 3217 | } |
3309 | 3218 | ||
3310 | static int | 3219 | static int doreadonly(t) |
3311 | doreadonly(t) | ||
3312 | struct op *t; | 3220 | struct op *t; |
3313 | { | 3221 | { |
3314 | rdexp(t->words+1, ronly, RONLY); | 3222 | rdexp(t->words + 1, ronly, RONLY); |
3315 | return(0); | 3223 | return (0); |
3316 | } | 3224 | } |
3317 | 3225 | ||
3318 | static void rdexp (char **wp, void (*f)(struct var *), int key) | 3226 | static void rdexp(char **wp, void (*f) (struct var *), int key) |
3319 | { | 3227 | { |
3320 | if (*wp != NULL) { | 3228 | if (*wp != NULL) { |
3321 | for (; *wp != NULL; wp++) { | 3229 | for (; *wp != NULL; wp++) { |
3322 | if (isassign(*wp)) { | 3230 | if (isassign(*wp)) { |
3323 | char *cp; | 3231 | char *cp; |
3232 | |||
3324 | assign(*wp, COPYV); | 3233 | assign(*wp, COPYV); |
3325 | for (cp = *wp; *cp != '='; cp++) | 3234 | for (cp = *wp; *cp != '='; cp++); |
3326 | ; | ||
3327 | *cp = '\0'; | 3235 | *cp = '\0'; |
3328 | } | 3236 | } |
3329 | if (checkname(*wp)) | 3237 | if (checkname(*wp)) |
3330 | (*f)(lookup(*wp)); | 3238 | (*f) (lookup(*wp)); |
3331 | else | 3239 | else |
3332 | badid(*wp); | 3240 | badid(*wp); |
3333 | } | 3241 | } |
@@ -3335,16 +3243,14 @@ static void rdexp (char **wp, void (*f)(struct var *), int key) | |||
3335 | putvlist(key, 1); | 3243 | putvlist(key, 1); |
3336 | } | 3244 | } |
3337 | 3245 | ||
3338 | static void | 3246 | static void badid(s) |
3339 | badid(s) | ||
3340 | register char *s; | 3247 | register char *s; |
3341 | { | 3248 | { |
3342 | prs(s); | 3249 | prs(s); |
3343 | err(": bad identifier"); | 3250 | err(": bad identifier"); |
3344 | } | 3251 | } |
3345 | 3252 | ||
3346 | static int | 3253 | static int doset(t) |
3347 | doset(t) | ||
3348 | register struct op *t; | 3254 | register struct op *t; |
3349 | { | 3255 | { |
3350 | register struct var *vp; | 3256 | register struct var *vp; |
@@ -3354,12 +3260,11 @@ register struct op *t; | |||
3354 | if ((cp = t->words[1]) == NULL) { | 3260 | if ((cp = t->words[1]) == NULL) { |
3355 | for (vp = vlist; vp; vp = vp->next) | 3261 | for (vp = vlist; vp; vp = vp->next) |
3356 | varput(vp->name, 1); | 3262 | varput(vp->name, 1); |
3357 | return(0); | 3263 | return (0); |
3358 | } | 3264 | } |
3359 | if (*cp == '-') { | 3265 | if (*cp == '-') { |
3360 | /* bad: t->words++; */ | 3266 | /* bad: t->words++; */ |
3361 | for(n = 0; (t->words[n]=t->words[n+1]) != NULL; n++) | 3267 | for (n = 0; (t->words[n] = t->words[n + 1]) != NULL; n++); |
3362 | ; | ||
3363 | if (*++cp == 0) | 3268 | if (*++cp == 0) |
3364 | flag['x'] = flag['v'] = 0; | 3269 | flag['x'] = flag['v'] = 0; |
3365 | else | 3270 | else |
@@ -3371,26 +3276,25 @@ register struct op *t; | |||
3371 | break; | 3276 | break; |
3372 | 3277 | ||
3373 | default: | 3278 | default: |
3374 | if (*cp>='a' && *cp<='z') | 3279 | if (*cp >= 'a' && *cp <= 'z') |
3375 | flag[(int)*cp]++; | 3280 | flag[(int) *cp]++; |
3376 | break; | 3281 | break; |
3377 | } | 3282 | } |
3378 | setdash(); | 3283 | setdash(); |
3379 | } | 3284 | } |
3380 | if (t->words[1]) { | 3285 | if (t->words[1]) { |
3381 | t->words[0] = dolv[0]; | 3286 | t->words[0] = dolv[0]; |
3382 | for (n=1; t->words[n]; n++) | 3287 | for (n = 1; t->words[n]; n++) |
3383 | setarea((char *)t->words[n], 0); | 3288 | setarea((char *) t->words[n], 0); |
3384 | dolc = n-1; | 3289 | dolc = n - 1; |
3385 | dolv = t->words; | 3290 | dolv = t->words; |
3386 | setval(lookup("#"), putn(dolc)); | 3291 | setval(lookup("#"), putn(dolc)); |
3387 | setarea((char *)(dolv-1), 0); | 3292 | setarea((char *) (dolv - 1), 0); |
3388 | } | 3293 | } |
3389 | return(0); | 3294 | return (0); |
3390 | } | 3295 | } |
3391 | 3296 | ||
3392 | static void | 3297 | static void varput(s, out) |
3393 | varput(s, out) | ||
3394 | register char *s; | 3298 | register char *s; |
3395 | int out; | 3299 | int out; |
3396 | { | 3300 | { |
@@ -3405,34 +3309,33 @@ int out; | |||
3405 | * Copyright (c) 1999 Herbert Xu <herbert@debian.org> | 3309 | * Copyright (c) 1999 Herbert Xu <herbert@debian.org> |
3406 | * This file contains code for the times builtin. | 3310 | * This file contains code for the times builtin. |
3407 | */ | 3311 | */ |
3408 | static int dotimes(struct op *t ) | 3312 | static int dotimes(struct op *t) |
3409 | { | 3313 | { |
3410 | struct tms buf; | 3314 | struct tms buf; |
3411 | long int clk_tck = sysconf(_SC_CLK_TCK); | 3315 | long int clk_tck = sysconf(_SC_CLK_TCK); |
3412 | 3316 | ||
3413 | times(&buf); | 3317 | times(&buf); |
3414 | printf("%dm%fs %dm%fs\n%dm%fs %dm%fs\n", | 3318 | printf("%dm%fs %dm%fs\n%dm%fs %dm%fs\n", |
3415 | (int) (buf.tms_utime / clk_tck / 60), | 3319 | (int) (buf.tms_utime / clk_tck / 60), |
3416 | ((double) buf.tms_utime) / clk_tck, | 3320 | ((double) buf.tms_utime) / clk_tck, |
3417 | (int) (buf.tms_stime / clk_tck / 60), | 3321 | (int) (buf.tms_stime / clk_tck / 60), |
3418 | ((double) buf.tms_stime) / clk_tck, | 3322 | ((double) buf.tms_stime) / clk_tck, |
3419 | (int) (buf.tms_cutime / clk_tck / 60), | 3323 | (int) (buf.tms_cutime / clk_tck / 60), |
3420 | ((double) buf.tms_cutime) / clk_tck, | 3324 | ((double) buf.tms_cutime) / clk_tck, |
3421 | (int) (buf.tms_cstime / clk_tck / 60), | 3325 | (int) (buf.tms_cstime / clk_tck / 60), |
3422 | ((double) buf.tms_cstime) / clk_tck); | 3326 | ((double) buf.tms_cstime) / clk_tck); |
3423 | return 0; | 3327 | return 0; |
3424 | } | 3328 | } |
3425 | 3329 | ||
3426 | 3330 | ||
3427 | static int(*inbuilt(char *s))(struct op *) | 3331 | static int (*inbuilt(char *s)) (struct op *) { |
3428 | { | ||
3429 | const struct builtincmd *bp; | 3332 | const struct builtincmd *bp; |
3430 | 3333 | ||
3431 | for (bp = builtincmds; bp->name != NULL; bp++) | 3334 | for (bp = builtincmds; bp->name != NULL; bp++) |
3432 | if (strcmp(bp->name, s) == 0) | 3335 | if (strcmp(bp->name, s) == 0) |
3433 | return(bp->builtinfunc); | 3336 | return (bp->builtinfunc); |
3434 | 3337 | ||
3435 | return(NULL); | 3338 | return (NULL); |
3436 | } | 3339 | } |
3437 | 3340 | ||
3438 | /* -------- eval.c -------- */ | 3341 | /* -------- eval.c -------- */ |
@@ -3445,7 +3348,7 @@ static int(*inbuilt(char *s))(struct op *) | |||
3445 | * glob | 3348 | * glob |
3446 | */ | 3349 | */ |
3447 | 3350 | ||
3448 | static char ** eval( char **ap, int f) | 3351 | static char **eval(char **ap, int f) |
3449 | { | 3352 | { |
3450 | struct wdblock *wb; | 3353 | struct wdblock *wb; |
3451 | char **wp; | 3354 | char **wp; |
@@ -3469,16 +3372,16 @@ static char ** eval( char **ap, int f) | |||
3469 | expand(*wf, &wb, f & ~DOGLOB); | 3372 | expand(*wf, &wb, f & ~DOGLOB); |
3470 | } | 3373 | } |
3471 | } | 3374 | } |
3472 | for (wb = addword((char *)0, wb); *ap; ap++) { | 3375 | for (wb = addword((char *) 0, wb); *ap; ap++) { |
3473 | if (!flag['k'] || !isassign(*ap)) | 3376 | if (!flag['k'] || !isassign(*ap)) |
3474 | expand(*ap, &wb, f & ~DOKEY); | 3377 | expand(*ap, &wb, f & ~DOKEY); |
3475 | } | 3378 | } |
3476 | wb = addword((char *)0, wb); | 3379 | wb = addword((char *) 0, wb); |
3477 | wp = getwords(wb); | 3380 | wp = getwords(wb); |
3478 | quitenv(); | 3381 | quitenv(); |
3479 | } else | 3382 | } else |
3480 | gflg = 1; | 3383 | gflg = 1; |
3481 | return(gflg? (char **)NULL: wp); | 3384 | return (gflg ? (char **) NULL : wp); |
3482 | } | 3385 | } |
3483 | 3386 | ||
3484 | /* | 3387 | /* |
@@ -3486,9 +3389,7 @@ static char ** eval( char **ap, int f) | |||
3486 | * names in the dictionary. Keyword assignments | 3389 | * names in the dictionary. Keyword assignments |
3487 | * will already have been done. | 3390 | * will already have been done. |
3488 | */ | 3391 | */ |
3489 | static char ** | 3392 | static char **makenv() |
3490 | makenv() | ||
3491 | |||
3492 | { | 3393 | { |
3493 | register struct wdblock *wb; | 3394 | register struct wdblock *wb; |
3494 | register struct var *vp; | 3395 | register struct var *vp; |
@@ -3497,12 +3398,11 @@ makenv() | |||
3497 | for (vp = vlist; vp; vp = vp->next) | 3398 | for (vp = vlist; vp; vp = vp->next) |
3498 | if (vp->status & EXPORT) | 3399 | if (vp->status & EXPORT) |
3499 | wb = addword(vp->name, wb); | 3400 | wb = addword(vp->name, wb); |
3500 | wb = addword((char *)0, wb); | 3401 | wb = addword((char *) 0, wb); |
3501 | return(getwords(wb)); | 3402 | return (getwords(wb)); |
3502 | } | 3403 | } |
3503 | 3404 | ||
3504 | static char * | 3405 | static char *evalstr(cp, f) |
3505 | evalstr(cp, f) | ||
3506 | register char *cp; | 3406 | register char *cp; |
3507 | int f; | 3407 | int f; |
3508 | { | 3408 | { |
@@ -3510,16 +3410,16 @@ int f; | |||
3510 | 3410 | ||
3511 | wb = NULL; | 3411 | wb = NULL; |
3512 | if (expand(cp, &wb, f)) { | 3412 | if (expand(cp, &wb, f)) { |
3513 | if (wb == NULL || wb->w_nword == 0 || (cp = wb->w_words[0]) == NULL) | 3413 | if (wb == NULL || wb->w_nword == 0 |
3414 | || (cp = wb->w_words[0]) == NULL) | ||
3514 | cp = ""; | 3415 | cp = ""; |
3515 | DELETE(wb); | 3416 | DELETE(wb); |
3516 | } else | 3417 | } else |
3517 | cp = NULL; | 3418 | cp = NULL; |
3518 | return(cp); | 3419 | return (cp); |
3519 | } | 3420 | } |
3520 | 3421 | ||
3521 | static int | 3422 | static int expand(char *cp, register struct wdblock **wbp, int f) |
3522 | expand( char *cp, register struct wdblock **wbp, int f) | ||
3523 | { | 3423 | { |
3524 | jmp_buf ev; | 3424 | jmp_buf ev; |
3525 | 3425 | ||
@@ -3529,15 +3429,14 @@ expand( char *cp, register struct wdblock **wbp, int f) | |||
3529 | #endif | 3429 | #endif |
3530 | gflg = 0; | 3430 | gflg = 0; |
3531 | if (cp == NULL) | 3431 | if (cp == NULL) |
3532 | return(0); | 3432 | return (0); |
3533 | if (!anys("$`'\"", cp) && | 3433 | if (!anys("$`'\"", cp) && |
3534 | !anys(ifs->value, cp) && | 3434 | !anys(ifs->value, cp) && ((f & DOGLOB) == 0 || !anys("[*?", cp))) { |
3535 | ((f&DOGLOB)==0 || !anys("[*?", cp))) { | ||
3536 | cp = strsave(cp, areanum); | 3435 | cp = strsave(cp, areanum); |
3537 | if (f & DOTRIM) | 3436 | if (f & DOTRIM) |
3538 | unquote(cp); | 3437 | unquote(cp); |
3539 | *wbp = addword(cp, *wbp); | 3438 | *wbp = addword(cp, *wbp); |
3540 | return(1); | 3439 | return (1); |
3541 | } | 3440 | } |
3542 | if (newenv(setjmp(errpt = ev)) == 0) { | 3441 | if (newenv(setjmp(errpt = ev)) == 0) { |
3543 | PUSHIO(aword, cp, strchar); | 3442 | PUSHIO(aword, cp, strchar); |
@@ -3545,7 +3444,7 @@ expand( char *cp, register struct wdblock **wbp, int f) | |||
3545 | while ((cp = blank(f)) && gflg == 0) { | 3444 | while ((cp = blank(f)) && gflg == 0) { |
3546 | e.linep = cp; | 3445 | e.linep = cp; |
3547 | cp = strsave(cp, areanum); | 3446 | cp = strsave(cp, areanum); |
3548 | if ((f&DOGLOB) == 0) { | 3447 | if ((f & DOGLOB) == 0) { |
3549 | if (f & DOTRIM) | 3448 | if (f & DOTRIM) |
3550 | unquote(cp); | 3449 | unquote(cp); |
3551 | *wbp = addword(cp, *wbp); | 3450 | *wbp = addword(cp, *wbp); |
@@ -3555,14 +3454,13 @@ expand( char *cp, register struct wdblock **wbp, int f) | |||
3555 | quitenv(); | 3454 | quitenv(); |
3556 | } else | 3455 | } else |
3557 | gflg = 1; | 3456 | gflg = 1; |
3558 | return(gflg == 0); | 3457 | return (gflg == 0); |
3559 | } | 3458 | } |
3560 | 3459 | ||
3561 | /* | 3460 | /* |
3562 | * Blank interpretation and quoting | 3461 | * Blank interpretation and quoting |
3563 | */ | 3462 | */ |
3564 | static char * | 3463 | static char *blank(f) |
3565 | blank(f) | ||
3566 | int f; | 3464 | int f; |
3567 | { | 3465 | { |
3568 | register int c, c1; | 3466 | register int c, c1; |
@@ -3573,13 +3471,13 @@ int f; | |||
3573 | scanequals = f & DOKEY; | 3471 | scanequals = f & DOKEY; |
3574 | foundequals = 0; | 3472 | foundequals = 0; |
3575 | 3473 | ||
3576 | loop: | 3474 | loop: |
3577 | switch (c = subgetc('"', foundequals)) { | 3475 | switch (c = subgetc('"', foundequals)) { |
3578 | case 0: | 3476 | case 0: |
3579 | if (sp == e.linep) | 3477 | if (sp == e.linep) |
3580 | return(0); | 3478 | return (0); |
3581 | *e.linep++ = 0; | 3479 | *e.linep++ = 0; |
3582 | return(sp); | 3480 | return (sp); |
3583 | 3481 | ||
3584 | default: | 3482 | default: |
3585 | if (f & DOBLANK && any(c, ifs->value)) | 3483 | if (f & DOBLANK && any(c, ifs->value)) |
@@ -3606,9 +3504,9 @@ loop: | |||
3606 | for (;;) { | 3504 | for (;;) { |
3607 | c = subgetc('"', foundequals); | 3505 | c = subgetc('"', foundequals); |
3608 | if (c == 0 || | 3506 | if (c == 0 || |
3609 | f & (DOBLANK && any(c, ifs->value)) || | 3507 | f & (DOBLANK && any(c, ifs->value)) || |
3610 | (!INSUB() && any(c, "\"'"))) { | 3508 | (!INSUB() && any(c, "\"'"))) { |
3611 | scanequals = 0; | 3509 | scanequals = 0; |
3612 | unget(c); | 3510 | unget(c); |
3613 | if (any(c, "\"'")) | 3511 | if (any(c, "\"'")) |
3614 | goto loop; | 3512 | goto loop; |
@@ -3617,33 +3515,31 @@ loop: | |||
3617 | if (scanequals) { | 3515 | if (scanequals) { |
3618 | if (c == '=') { | 3516 | if (c == '=') { |
3619 | foundequals = 1; | 3517 | foundequals = 1; |
3620 | scanequals = 0; | 3518 | scanequals = 0; |
3621 | } | 3519 | } else if (!isalnum(c) && c != '_') |
3622 | else if (!isalnum(c) && c != '_') | ||
3623 | scanequals = 0; | 3520 | scanequals = 0; |
3624 | } | 3521 | } |
3625 | *e.linep++ = c; | 3522 | *e.linep++ = c; |
3626 | } | 3523 | } |
3627 | *e.linep++ = 0; | 3524 | *e.linep++ = 0; |
3628 | return(sp); | 3525 | return (sp); |
3629 | } | 3526 | } |
3630 | 3527 | ||
3631 | /* | 3528 | /* |
3632 | * Get characters, substituting for ` and $ | 3529 | * Get characters, substituting for ` and $ |
3633 | */ | 3530 | */ |
3634 | static int | 3531 | static int subgetc(ec, quoted) |
3635 | subgetc(ec, quoted) | ||
3636 | register char ec; | 3532 | register char ec; |
3637 | int quoted; | 3533 | int quoted; |
3638 | { | 3534 | { |
3639 | register char c; | 3535 | register char c; |
3640 | 3536 | ||
3641 | again: | 3537 | again: |
3642 | c = my_getc(ec); | 3538 | c = my_getc(ec); |
3643 | if (!INSUB() && ec != '\'') { | 3539 | if (!INSUB() && ec != '\'') { |
3644 | if (c == '`') { | 3540 | if (c == '`') { |
3645 | if (grave(quoted) == 0) | 3541 | if (grave(quoted) == 0) |
3646 | return(0); | 3542 | return (0); |
3647 | e.iop->task = XGRAVE; | 3543 | e.iop->task = XGRAVE; |
3648 | goto again; | 3544 | goto again; |
3649 | } | 3545 | } |
@@ -3652,20 +3548,19 @@ again: | |||
3652 | goto again; | 3548 | goto again; |
3653 | } | 3549 | } |
3654 | } | 3550 | } |
3655 | return(c); | 3551 | return (c); |
3656 | } | 3552 | } |
3657 | 3553 | ||
3658 | /* | 3554 | /* |
3659 | * Prepare to generate the string returned by ${} substitution. | 3555 | * Prepare to generate the string returned by ${} substitution. |
3660 | */ | 3556 | */ |
3661 | static int | 3557 | static int dollar(quoted) |
3662 | dollar(quoted) | ||
3663 | int quoted; | 3558 | int quoted; |
3664 | { | 3559 | { |
3665 | int otask; | 3560 | int otask; |
3666 | struct io *oiop; | 3561 | struct io *oiop; |
3667 | char *dolp; | 3562 | char *dolp; |
3668 | register char *s, c, *cp=NULL; | 3563 | register char *s, c, *cp = NULL; |
3669 | struct var *vp; | 3564 | struct var *vp; |
3670 | 3565 | ||
3671 | c = readc(); | 3566 | c = readc(); |
@@ -3673,7 +3568,7 @@ int quoted; | |||
3673 | if (c != '{') { | 3568 | if (c != '{') { |
3674 | *e.linep++ = c; | 3569 | *e.linep++ = c; |
3675 | if (isalpha(c) || c == '_') { | 3570 | if (isalpha(c) || c == '_') { |
3676 | while ((c = readc())!=0 && (isalnum(c) || c == '_')) | 3571 | while ((c = readc()) != 0 && (isalnum(c) || c == '_')) |
3677 | if (e.linep < elinep) | 3572 | if (e.linep < elinep) |
3678 | *e.linep++ = c; | 3573 | *e.linep++ = c; |
3679 | unget(c); | 3574 | unget(c); |
@@ -3683,7 +3578,7 @@ int quoted; | |||
3683 | oiop = e.iop; | 3578 | oiop = e.iop; |
3684 | otask = e.iop->task; | 3579 | otask = e.iop->task; |
3685 | e.iop->task = XOTHER; | 3580 | e.iop->task = XOTHER; |
3686 | while ((c = subgetc('"', 0))!=0 && c!='}' && c!='\n') | 3581 | while ((c = subgetc('"', 0)) != 0 && c != '}' && c != '\n') |
3687 | if (e.linep < elinep) | 3582 | if (e.linep < elinep) |
3688 | *e.linep++ = c; | 3583 | *e.linep++ = c; |
3689 | if (oiop == e.iop) | 3584 | if (oiop == e.iop) |
@@ -3691,7 +3586,7 @@ int quoted; | |||
3691 | if (c != '}') { | 3586 | if (c != '}') { |
3692 | err("unclosed ${"); | 3587 | err("unclosed ${"); |
3693 | gflg++; | 3588 | gflg++; |
3694 | return(c); | 3589 | return (c); |
3695 | } | 3590 | } |
3696 | } | 3591 | } |
3697 | if (e.linep >= elinep) { | 3592 | if (e.linep >= elinep) { |
@@ -3701,7 +3596,7 @@ int quoted; | |||
3701 | } | 3596 | } |
3702 | *e.linep = 0; | 3597 | *e.linep = 0; |
3703 | if (*s) | 3598 | if (*s) |
3704 | for (cp = s+1; *cp; cp++) | 3599 | for (cp = s + 1; *cp; cp++) |
3705 | if (any(*cp, "=-+?")) { | 3600 | if (any(*cp, "=-+?")) { |
3706 | c = *cp; | 3601 | c = *cp; |
3707 | *cp++ = 0; | 3602 | *cp++ = 0; |
@@ -3712,9 +3607,9 @@ int quoted; | |||
3712 | /* currently this does not distinguish $* and $@ */ | 3607 | /* currently this does not distinguish $* and $@ */ |
3713 | /* should check dollar */ | 3608 | /* should check dollar */ |
3714 | e.linep = s; | 3609 | e.linep = s; |
3715 | PUSHIO(awordlist, dolv+1, dolchar); | 3610 | PUSHIO(awordlist, dolv + 1, dolchar); |
3716 | return(0); | 3611 | return (0); |
3717 | } else { /* trap the nasty ${=} */ | 3612 | } else { /* trap the nasty ${=} */ |
3718 | s[0] = '1'; | 3613 | s[0] = '1'; |
3719 | s[1] = 0; | 3614 | s[1] = 0; |
3720 | } | 3615 | } |
@@ -3754,15 +3649,14 @@ int quoted; | |||
3754 | } | 3649 | } |
3755 | e.linep = s; | 3650 | e.linep = s; |
3756 | PUSHIO(aword, dolp, quoted ? qstrchar : strchar); | 3651 | PUSHIO(aword, dolp, quoted ? qstrchar : strchar); |
3757 | return(0); | 3652 | return (0); |
3758 | } | 3653 | } |
3759 | 3654 | ||
3760 | /* | 3655 | /* |
3761 | * Run the command in `...` and read its output. | 3656 | * Run the command in `...` and read its output. |
3762 | */ | 3657 | */ |
3763 | 3658 | ||
3764 | static int | 3659 | static int grave(quoted) |
3765 | grave(quoted) | ||
3766 | int quoted; | 3660 | int quoted; |
3767 | { | 3661 | { |
3768 | char *cp; | 3662 | char *cp; |
@@ -3785,7 +3679,7 @@ int quoted; | |||
3785 | for (cp = e.iop->argp->aword; *cp != '`'; cp++) | 3679 | for (cp = e.iop->argp->aword; *cp != '`'; cp++) |
3786 | if (*cp == 0) { | 3680 | if (*cp == 0) { |
3787 | err("no closing `"); | 3681 | err("no closing `"); |
3788 | return(0); | 3682 | return (0); |
3789 | } | 3683 | } |
3790 | 3684 | ||
3791 | /* string copy with dollar expansion */ | 3685 | /* string copy with dollar expansion */ |
@@ -3828,11 +3722,11 @@ int quoted; | |||
3828 | case '=': | 3722 | case '=': |
3829 | case '+': | 3723 | case '+': |
3830 | case '?': | 3724 | case '?': |
3831 | operator = *src; | 3725 | operator = * src; |
3832 | break; | 3726 | break; |
3833 | default: | 3727 | default: |
3834 | err("unclosed ${\n"); | 3728 | err("unclosed ${\n"); |
3835 | return(0); | 3729 | return (0); |
3836 | } | 3730 | } |
3837 | if (operator) { | 3731 | if (operator) { |
3838 | src++; | 3732 | src++; |
@@ -3842,7 +3736,7 @@ int quoted; | |||
3842 | alt_value[alt_index] = 0; | 3736 | alt_value[alt_index] = 0; |
3843 | if (*src != '}') { | 3737 | if (*src != '}') { |
3844 | err("unclosed ${\n"); | 3738 | err("unclosed ${\n"); |
3845 | return(0); | 3739 | return (0); |
3846 | } | 3740 | } |
3847 | } | 3741 | } |
3848 | src++; | 3742 | src++; |
@@ -3850,10 +3744,10 @@ int quoted; | |||
3850 | 3744 | ||
3851 | vp = lookup(var_name); | 3745 | vp = lookup(var_name); |
3852 | if (vp->value != null) | 3746 | if (vp->value != null) |
3853 | value = (operator == '+')? alt_value : vp->value; | 3747 | value = (operator == '+') ? alt_value : vp->value; |
3854 | else if (operator == '?') { | 3748 | else if (operator == '?') { |
3855 | err(alt_value); | 3749 | err(alt_value); |
3856 | return(0); | 3750 | return (0); |
3857 | } else if (alt_index && (operator != '+')) { | 3751 | } else if (alt_index && (operator != '+')) { |
3858 | value = alt_value; | 3752 | value = alt_value; |
3859 | if (operator == '=') | 3753 | if (operator == '=') |
@@ -3874,31 +3768,32 @@ int quoted; | |||
3874 | *dest = '\0'; | 3768 | *dest = '\0'; |
3875 | 3769 | ||
3876 | if (openpipe(pf) < 0) | 3770 | if (openpipe(pf) < 0) |
3877 | return(0); | 3771 | return (0); |
3878 | while ((i = vfork()) == -1 && errno == EAGAIN) | 3772 | while ((i = vfork()) == -1 && errno == EAGAIN); |
3879 | ; | ||
3880 | if (i < 0) { | 3773 | if (i < 0) { |
3881 | closepipe(pf); | 3774 | closepipe(pf); |
3882 | err((char*)bb_msg_memory_exhausted); | 3775 | err((char *) bb_msg_memory_exhausted); |
3883 | return(0); | 3776 | return (0); |
3884 | } | 3777 | } |
3885 | if (i != 0) { | 3778 | if (i != 0) { |
3886 | waitpid(i, NULL, 0); | 3779 | waitpid(i, NULL, 0); |
3887 | e.iop->argp->aword = ++cp; | 3780 | e.iop->argp->aword = ++cp; |
3888 | close(pf[1]); | 3781 | close(pf[1]); |
3889 | PUSHIO(afile, remap(pf[0]), (int(*)(struct ioarg *))((quoted)? qgravechar: gravechar)); | 3782 | PUSHIO(afile, remap(pf[0]), |
3890 | return(1); | 3783 | (int (*)(struct ioarg *)) ((quoted) ? qgravechar : |
3784 | gravechar)); | ||
3785 | return (1); | ||
3891 | } | 3786 | } |
3892 | /* allow trapped signals */ | 3787 | /* allow trapped signals */ |
3893 | /* XXX - Maybe this signal stuff should go as well? */ | 3788 | /* XXX - Maybe this signal stuff should go as well? */ |
3894 | for (j=0; j<=_NSIG; j++) | 3789 | for (j = 0; j <= _NSIG; j++) |
3895 | if (ourtrap[j] && signal(j, SIG_IGN) != SIG_IGN) | 3790 | if (ourtrap[j] && signal(j, SIG_IGN) != SIG_IGN) |
3896 | signal(j, SIG_DFL); | 3791 | signal(j, SIG_DFL); |
3897 | 3792 | ||
3898 | dup2(pf[1], 1); | 3793 | dup2(pf[1], 1); |
3899 | closepipe(pf); | 3794 | closepipe(pf); |
3900 | 3795 | ||
3901 | argument_list[0] = (char *)DEFAULT_SHELL; | 3796 | argument_list[0] = (char *) DEFAULT_SHELL; |
3902 | argument_list[1] = "-c"; | 3797 | argument_list[1] = "-c"; |
3903 | argument_list[2] = child_cmd; | 3798 | argument_list[2] = child_cmd; |
3904 | argument_list[3] = 0; | 3799 | argument_list[3] = 0; |
@@ -3908,8 +3803,7 @@ int quoted; | |||
3908 | } | 3803 | } |
3909 | 3804 | ||
3910 | 3805 | ||
3911 | static char * | 3806 | static char *unquote(as) |
3912 | unquote(as) | ||
3913 | register char *as; | 3807 | register char *as; |
3914 | { | 3808 | { |
3915 | register char *s; | 3809 | register char *s; |
@@ -3917,7 +3811,7 @@ register char *as; | |||
3917 | if ((s = as) != NULL) | 3811 | if ((s = as) != NULL) |
3918 | while (*s) | 3812 | while (*s) |
3919 | *s++ &= ~QUOTE; | 3813 | *s++ &= ~QUOTE; |
3920 | return(as); | 3814 | return (as); |
3921 | } | 3815 | } |
3922 | 3816 | ||
3923 | /* -------- glob.c -------- */ | 3817 | /* -------- glob.c -------- */ |
@@ -3930,11 +3824,10 @@ register char *as; | |||
3930 | #define BLKSIZ 512 | 3824 | #define BLKSIZ 512 |
3931 | #define NDENT ((BLKSIZ+sizeof(struct dirent)-1)/sizeof(struct dirent)) | 3825 | #define NDENT ((BLKSIZ+sizeof(struct dirent)-1)/sizeof(struct dirent)) |
3932 | 3826 | ||
3933 | static struct wdblock *cl, *nl; | 3827 | static struct wdblock *cl, *nl; |
3934 | static char spcl[] = "[?*"; | 3828 | static char spcl[] = "[?*"; |
3935 | 3829 | ||
3936 | static struct wdblock * | 3830 | static struct wdblock *glob(cp, wb) |
3937 | glob(cp, wb) | ||
3938 | char *cp; | 3831 | char *cp; |
3939 | struct wdblock *wb; | 3832 | struct wdblock *wb; |
3940 | { | 3833 | { |
@@ -3942,7 +3835,7 @@ struct wdblock *wb; | |||
3942 | register char *pp; | 3835 | register char *pp; |
3943 | 3836 | ||
3944 | if (cp == 0) | 3837 | if (cp == 0) |
3945 | return(wb); | 3838 | return (wb); |
3946 | i = 0; | 3839 | i = 0; |
3947 | for (pp = cp; *pp; pp++) | 3840 | for (pp = cp; *pp; pp++) |
3948 | if (any(*pp, spcl)) | 3841 | if (any(*pp, spcl)) |
@@ -3950,9 +3843,10 @@ struct wdblock *wb; | |||
3950 | else if (!any(*pp & ~QUOTE, spcl)) | 3843 | else if (!any(*pp & ~QUOTE, spcl)) |
3951 | *pp &= ~QUOTE; | 3844 | *pp &= ~QUOTE; |
3952 | if (i != 0) { | 3845 | if (i != 0) { |
3953 | for (cl = addword(scopy(cp), (struct wdblock *)0); anyspcl(cl); cl = nl) { | 3846 | for (cl = addword(scopy(cp), (struct wdblock *) 0); anyspcl(cl); |
3954 | nl = newword(cl->w_nword*2); | 3847 | cl = nl) { |
3955 | for(i=0; i<cl->w_nword; i++) { /* for each argument */ | 3848 | nl = newword(cl->w_nword * 2); |
3849 | for (i = 0; i < cl->w_nword; i++) { /* for each argument */ | ||
3956 | for (pp = cl->w_words[i]; *pp; pp++) | 3850 | for (pp = cl->w_words[i]; *pp; pp++) |
3957 | if (any(*pp, spcl)) { | 3851 | if (any(*pp, spcl)) { |
3958 | globname(cl->w_words[i], pp); | 3852 | globname(cl->w_words[i], pp); |
@@ -3961,26 +3855,25 @@ struct wdblock *wb; | |||
3961 | if (*pp == '\0') | 3855 | if (*pp == '\0') |
3962 | nl = addword(scopy(cl->w_words[i]), nl); | 3856 | nl = addword(scopy(cl->w_words[i]), nl); |
3963 | } | 3857 | } |
3964 | for(i=0; i<cl->w_nword; i++) | 3858 | for (i = 0; i < cl->w_nword; i++) |
3965 | DELETE(cl->w_words[i]); | 3859 | DELETE(cl->w_words[i]); |
3966 | DELETE(cl); | 3860 | DELETE(cl); |
3967 | } | 3861 | } |
3968 | for(i=0; i<cl->w_nword; i++) | 3862 | for (i = 0; i < cl->w_nword; i++) |
3969 | unquote(cl->w_words[i]); | 3863 | unquote(cl->w_words[i]); |
3970 | glob0((char *)cl->w_words, cl->w_nword, sizeof(char *), xstrcmp); | 3864 | glob0((char *) cl->w_words, cl->w_nword, sizeof(char *), xstrcmp); |
3971 | if (cl->w_nword) { | 3865 | if (cl->w_nword) { |
3972 | for (i=0; i<cl->w_nword; i++) | 3866 | for (i = 0; i < cl->w_nword; i++) |
3973 | wb = addword(cl->w_words[i], wb); | 3867 | wb = addword(cl->w_words[i], wb); |
3974 | DELETE(cl); | 3868 | DELETE(cl); |
3975 | return(wb); | 3869 | return (wb); |
3976 | } | 3870 | } |
3977 | } | 3871 | } |
3978 | wb = addword(unquote(cp), wb); | 3872 | wb = addword(unquote(cp), wb); |
3979 | return(wb); | 3873 | return (wb); |
3980 | } | 3874 | } |
3981 | 3875 | ||
3982 | static void | 3876 | static void globname(we, pp) |
3983 | globname(we, pp) | ||
3984 | char *we; | 3877 | char *we; |
3985 | register char *pp; | 3878 | register char *pp; |
3986 | { | 3879 | { |
@@ -3989,17 +3882,17 @@ register char *pp; | |||
3989 | int k; | 3882 | int k; |
3990 | DIR *dirp; | 3883 | DIR *dirp; |
3991 | struct dirent *de; | 3884 | struct dirent *de; |
3992 | char dname[NAME_MAX+1]; | 3885 | char dname[NAME_MAX + 1]; |
3993 | struct stat dbuf; | 3886 | struct stat dbuf; |
3994 | 3887 | ||
3995 | for (np = we; np != pp; pp--) | 3888 | for (np = we; np != pp; pp--) |
3996 | if (pp[-1] == '/') | 3889 | if (pp[-1] == '/') |
3997 | break; | 3890 | break; |
3998 | for (dp = cp = space((int)(pp-np)+3); np < pp;) | 3891 | for (dp = cp = space((int) (pp - np) + 3); np < pp;) |
3999 | *cp++ = *np++; | 3892 | *cp++ = *np++; |
4000 | *cp++ = '.'; | 3893 | *cp++ = '.'; |
4001 | *cp = '\0'; | 3894 | *cp = '\0'; |
4002 | for (gp = cp = space(strlen(pp)+1); *np && *np != '/';) | 3895 | for (gp = cp = space(strlen(pp) + 1); *np && *np != '/';) |
4003 | *cp++ = *np++; | 3896 | *cp++ = *np++; |
4004 | *cp = '\0'; | 3897 | *cp = '\0'; |
4005 | dirp = opendir(dp); | 3898 | dirp = opendir(dp); |
@@ -4009,29 +3902,29 @@ register char *pp; | |||
4009 | return; | 3902 | return; |
4010 | } | 3903 | } |
4011 | dname[NAME_MAX] = '\0'; | 3904 | dname[NAME_MAX] = '\0'; |
4012 | while ((de=readdir(dirp))!=NULL) { | 3905 | while ((de = readdir(dirp)) != NULL) { |
4013 | /* XXX Hmmm... What this could be? (abial) */ | 3906 | /* XXX Hmmm... What this could be? (abial) */ |
4014 | /* | 3907 | /* |
4015 | if (ent[j].d_ino == 0) | 3908 | if (ent[j].d_ino == 0) |
4016 | continue; | 3909 | continue; |
4017 | */ | 3910 | */ |
4018 | strncpy(dname, de->d_name, NAME_MAX); | 3911 | strncpy(dname, de->d_name, NAME_MAX); |
4019 | if (dname[0] == '.') | 3912 | if (dname[0] == '.') |
4020 | if (*gp != '.') | 3913 | if (*gp != '.') |
3914 | continue; | ||
3915 | for (k = 0; k < NAME_MAX; k++) | ||
3916 | if (any(dname[k], spcl)) | ||
3917 | dname[k] |= QUOTE; | ||
3918 | if (gmatch(dname, gp)) { | ||
3919 | name = generate(we, pp, dname, np); | ||
3920 | if (*np && !anys(np, spcl)) { | ||
3921 | if (stat(name, &dbuf)) { | ||
3922 | DELETE(name); | ||
4021 | continue; | 3923 | continue; |
4022 | for(k=0; k<NAME_MAX; k++) | ||
4023 | if (any(dname[k], spcl)) | ||
4024 | dname[k] |= QUOTE; | ||
4025 | if (gmatch(dname, gp)) { | ||
4026 | name = generate(we, pp, dname, np); | ||
4027 | if (*np && !anys(np, spcl)) { | ||
4028 | if (stat(name,&dbuf)) { | ||
4029 | DELETE(name); | ||
4030 | continue; | ||
4031 | } | ||
4032 | } | 3924 | } |
4033 | nl = addword(name, nl); | ||
4034 | } | 3925 | } |
3926 | nl = addword(name, nl); | ||
3927 | } | ||
4035 | } | 3928 | } |
4036 | closedir(dirp); | 3929 | closedir(dirp); |
4037 | DELETE(dp); | 3930 | DELETE(dp); |
@@ -4043,8 +3936,7 @@ register char *pp; | |||
4043 | * start..end1 / middle end | 3936 | * start..end1 / middle end |
4044 | * the slashes come for free | 3937 | * the slashes come for free |
4045 | */ | 3938 | */ |
4046 | static char * | 3939 | static char *generate(start1, end1, middle, end) |
4047 | generate(start1, end1, middle, end) | ||
4048 | char *start1; | 3940 | char *start1; |
4049 | register char *end1; | 3941 | register char *end1; |
4050 | char *middle, *end; | 3942 | char *middle, *end; |
@@ -4052,54 +3944,49 @@ char *middle, *end; | |||
4052 | char *p; | 3944 | char *p; |
4053 | register char *op, *xp; | 3945 | register char *op, *xp; |
4054 | 3946 | ||
4055 | p = op = space((int)(end1-start1)+strlen(middle)+strlen(end)+2); | 3947 | p = op = |
3948 | space((int) (end1 - start1) + strlen(middle) + strlen(end) + 2); | ||
4056 | for (xp = start1; xp != end1;) | 3949 | for (xp = start1; xp != end1;) |
4057 | *op++ = *xp++; | 3950 | *op++ = *xp++; |
4058 | for (xp = middle; (*op++ = *xp++) != '\0';) | 3951 | for (xp = middle; (*op++ = *xp++) != '\0';); |
4059 | ; | ||
4060 | op--; | 3952 | op--; |
4061 | for (xp = end; (*op++ = *xp++) != '\0';) | 3953 | for (xp = end; (*op++ = *xp++) != '\0';); |
4062 | ; | 3954 | return (p); |
4063 | return(p); | ||
4064 | } | 3955 | } |
4065 | 3956 | ||
4066 | static int | 3957 | static int anyspcl(wb) |
4067 | anyspcl(wb) | ||
4068 | register struct wdblock *wb; | 3958 | register struct wdblock *wb; |
4069 | { | 3959 | { |
4070 | register int i; | 3960 | register int i; |
4071 | register char **wd; | 3961 | register char **wd; |
4072 | 3962 | ||
4073 | wd = wb->w_words; | 3963 | wd = wb->w_words; |
4074 | for (i=0; i<wb->w_nword; i++) | 3964 | for (i = 0; i < wb->w_nword; i++) |
4075 | if (anys(spcl, *wd++)) | 3965 | if (anys(spcl, *wd++)) |
4076 | return(1); | 3966 | return (1); |
4077 | return(0); | 3967 | return (0); |
4078 | } | 3968 | } |
4079 | 3969 | ||
4080 | static int | 3970 | static int xstrcmp(p1, p2) |
4081 | xstrcmp(p1, p2) | ||
4082 | char *p1, *p2; | 3971 | char *p1, *p2; |
4083 | { | 3972 | { |
4084 | return(strcmp(*(char **)p1, *(char **)p2)); | 3973 | return (strcmp(*(char **) p1, *(char **) p2)); |
4085 | } | 3974 | } |
4086 | 3975 | ||
4087 | /* -------- word.c -------- */ | 3976 | /* -------- word.c -------- */ |
4088 | 3977 | ||
4089 | static struct wdblock * | 3978 | static struct wdblock *newword(nw) |
4090 | newword(nw) | ||
4091 | register int nw; | 3979 | register int nw; |
4092 | { | 3980 | { |
4093 | register struct wdblock *wb; | 3981 | register struct wdblock *wb; |
4094 | 3982 | ||
4095 | wb = (struct wdblock *) space(sizeof(*wb) + nw*sizeof(char *)); | 3983 | wb = (struct wdblock *) space(sizeof(*wb) + nw * sizeof(char *)); |
4096 | wb->w_bsize = nw; | 3984 | wb->w_bsize = nw; |
4097 | wb->w_nword = 0; | 3985 | wb->w_nword = 0; |
4098 | return(wb); | 3986 | return (wb); |
4099 | } | 3987 | } |
4100 | 3988 | ||
4101 | static struct wdblock * | 3989 | static struct wdblock *addword(wd, wb) |
4102 | addword(wd, wb) | ||
4103 | char *wd; | 3990 | char *wd; |
4104 | register struct wdblock *wb; | 3991 | register struct wdblock *wb; |
4105 | { | 3992 | { |
@@ -4110,39 +3997,39 @@ register struct wdblock *wb; | |||
4110 | wb = newword(NSTART); | 3997 | wb = newword(NSTART); |
4111 | if ((nw = wb->w_nword) >= wb->w_bsize) { | 3998 | if ((nw = wb->w_nword) >= wb->w_bsize) { |
4112 | wb2 = newword(nw * 2); | 3999 | wb2 = newword(nw * 2); |
4113 | memcpy((char *)wb2->w_words, (char *)wb->w_words, nw*sizeof(char *)); | 4000 | memcpy((char *) wb2->w_words, (char *) wb->w_words, |
4001 | nw * sizeof(char *)); | ||
4114 | wb2->w_nword = nw; | 4002 | wb2->w_nword = nw; |
4115 | DELETE(wb); | 4003 | DELETE(wb); |
4116 | wb = wb2; | 4004 | wb = wb2; |
4117 | } | 4005 | } |
4118 | wb->w_words[wb->w_nword++] = wd; | 4006 | wb->w_words[wb->w_nword++] = wd; |
4119 | return(wb); | 4007 | return (wb); |
4120 | } | 4008 | } |
4009 | |||
4121 | static | 4010 | static |
4122 | char ** | 4011 | char **getwords(wb) |
4123 | getwords(wb) | ||
4124 | register struct wdblock *wb; | 4012 | register struct wdblock *wb; |
4125 | { | 4013 | { |
4126 | register char **wd; | 4014 | register char **wd; |
4127 | register int nb; | 4015 | register int nb; |
4128 | 4016 | ||
4129 | if (wb == NULL) | 4017 | if (wb == NULL) |
4130 | return((char **)NULL); | 4018 | return ((char **) NULL); |
4131 | if (wb->w_nword == 0) { | 4019 | if (wb->w_nword == 0) { |
4132 | DELETE(wb); | 4020 | DELETE(wb); |
4133 | return((char **)NULL); | 4021 | return ((char **) NULL); |
4134 | } | 4022 | } |
4135 | wd = (char **) space(nb = sizeof(*wd) * wb->w_nword); | 4023 | wd = (char **) space(nb = sizeof(*wd) * wb->w_nword); |
4136 | memcpy((char *)wd, (char *)wb->w_words, nb); | 4024 | memcpy((char *) wd, (char *) wb->w_words, nb); |
4137 | DELETE(wb); /* perhaps should done by caller */ | 4025 | DELETE(wb); /* perhaps should done by caller */ |
4138 | return(wd); | 4026 | return (wd); |
4139 | } | 4027 | } |
4140 | 4028 | ||
4141 | int (*func)(char *, char *); | 4029 | int (*func) (char *, char *); |
4142 | int globv; | 4030 | int globv; |
4143 | 4031 | ||
4144 | static void | 4032 | static void glob0(a0, a1, a2, a3) |
4145 | glob0(a0, a1, a2, a3) | ||
4146 | char *a0; | 4033 | char *a0; |
4147 | unsigned a1; | 4034 | unsigned a1; |
4148 | int a2; | 4035 | int a2; |
@@ -4153,8 +4040,7 @@ int (*a3) (char *, char *); | |||
4153 | glob1(a0, a0 + a1 * a2); | 4040 | glob1(a0, a0 + a1 * a2); |
4154 | } | 4041 | } |
4155 | 4042 | ||
4156 | static void | 4043 | static void glob1(base, lim) |
4157 | glob1(base, lim) | ||
4158 | char *base, *lim; | 4044 | char *base, *lim; |
4159 | { | 4045 | { |
4160 | register char *i, *j; | 4046 | register char *i, *j; |
@@ -4166,16 +4052,16 @@ char *base, *lim; | |||
4166 | 4052 | ||
4167 | v2 = globv; | 4053 | v2 = globv; |
4168 | 4054 | ||
4169 | top: | 4055 | top: |
4170 | if ((n=(int)(lim-base)) <= v2) | 4056 | if ((n = (int) (lim - base)) <= v2) |
4171 | return; | 4057 | return; |
4172 | n = v2 * (n / (2*v2)); | 4058 | n = v2 * (n / (2 * v2)); |
4173 | hptr = lptr = base+n; | 4059 | hptr = lptr = base + n; |
4174 | i = base; | 4060 | i = base; |
4175 | j = lim-v2; | 4061 | j = lim - v2; |
4176 | for(;;) { | 4062 | for (;;) { |
4177 | if (i < lptr) { | 4063 | if (i < lptr) { |
4178 | if ((c = (*func)(i, lptr)) == 0) { | 4064 | if ((c = (*func) (i, lptr)) == 0) { |
4179 | glob2(i, lptr -= v2); | 4065 | glob2(i, lptr -= v2); |
4180 | continue; | 4066 | continue; |
4181 | } | 4067 | } |
@@ -4185,9 +4071,9 @@ top: | |||
4185 | } | 4071 | } |
4186 | } | 4072 | } |
4187 | 4073 | ||
4188 | begin: | 4074 | begin: |
4189 | if (j > hptr) { | 4075 | if (j > hptr) { |
4190 | if ((c = (*func)(hptr, j)) == 0) { | 4076 | if ((c = (*func) (hptr, j)) == 0) { |
4191 | glob2(hptr += v2, j); | 4077 | glob2(hptr += v2, j); |
4192 | goto begin; | 4078 | goto begin; |
4193 | } | 4079 | } |
@@ -4208,12 +4094,12 @@ begin: | |||
4208 | 4094 | ||
4209 | 4095 | ||
4210 | if (i == lptr) { | 4096 | if (i == lptr) { |
4211 | if (lptr-base >= lim-hptr) { | 4097 | if (lptr - base >= lim - hptr) { |
4212 | glob1(hptr+v2, lim); | 4098 | glob1(hptr + v2, lim); |
4213 | lim = lptr; | 4099 | lim = lptr; |
4214 | } else { | 4100 | } else { |
4215 | glob1(base, lptr); | 4101 | glob1(base, lptr); |
4216 | base = hptr+v2; | 4102 | base = hptr + v2; |
4217 | } | 4103 | } |
4218 | goto top; | 4104 | goto top; |
4219 | } | 4105 | } |
@@ -4224,8 +4110,7 @@ begin: | |||
4224 | } | 4110 | } |
4225 | } | 4111 | } |
4226 | 4112 | ||
4227 | static void | 4113 | static void glob2(i, j) |
4228 | glob2(i, j) | ||
4229 | char *i, *j; | 4114 | char *i, *j; |
4230 | { | 4115 | { |
4231 | register char *index1, *index2, c; | 4116 | register char *index1, *index2, c; |
@@ -4238,11 +4123,10 @@ char *i, *j; | |||
4238 | c = *index1; | 4123 | c = *index1; |
4239 | *index1++ = *index2; | 4124 | *index1++ = *index2; |
4240 | *index2++ = c; | 4125 | *index2++ = c; |
4241 | } while(--m); | 4126 | } while (--m); |
4242 | } | 4127 | } |
4243 | 4128 | ||
4244 | static void | 4129 | static void glob3(i, j, k) |
4245 | glob3(i, j, k) | ||
4246 | char *i, *j, *k; | 4130 | char *i, *j, *k; |
4247 | { | 4131 | { |
4248 | register char *index1, *index2, *index3; | 4132 | register char *index1, *index2, *index3; |
@@ -4258,7 +4142,7 @@ char *i, *j, *k; | |||
4258 | *index1++ = *index3; | 4142 | *index1++ = *index3; |
4259 | *index3++ = *index2; | 4143 | *index3++ = *index2; |
4260 | *index2++ = c; | 4144 | *index2++ = c; |
4261 | } while(--m); | 4145 | } while (--m); |
4262 | } | 4146 | } |
4263 | 4147 | ||
4264 | /* -------- io.c -------- */ | 4148 | /* -------- io.c -------- */ |
@@ -4267,101 +4151,92 @@ char *i, *j, *k; | |||
4267 | * shell IO | 4151 | * shell IO |
4268 | */ | 4152 | */ |
4269 | 4153 | ||
4270 | static int my_getc( int ec) | 4154 | static int my_getc(int ec) |
4271 | { | 4155 | { |
4272 | register int c; | 4156 | register int c; |
4273 | 4157 | ||
4274 | if(e.linep > elinep) { | 4158 | if (e.linep > elinep) { |
4275 | while((c=readc()) != '\n' && c) | 4159 | while ((c = readc()) != '\n' && c); |
4276 | ; | ||
4277 | err("input line too long"); | 4160 | err("input line too long"); |
4278 | gflg++; | 4161 | gflg++; |
4279 | return(c); | 4162 | return (c); |
4280 | } | 4163 | } |
4281 | c = readc(); | 4164 | c = readc(); |
4282 | if ((ec != '\'') && (ec != '`') && (e.iop->task != XGRAVE)) { | 4165 | if ((ec != '\'') && (ec != '`') && (e.iop->task != XGRAVE)) { |
4283 | if(c == '\\') { | 4166 | if (c == '\\') { |
4284 | c = readc(); | 4167 | c = readc(); |
4285 | if (c == '\n' && ec != '\"') | 4168 | if (c == '\n' && ec != '\"') |
4286 | return(my_getc(ec)); | 4169 | return (my_getc(ec)); |
4287 | c |= QUOTE; | 4170 | c |= QUOTE; |
4288 | } | 4171 | } |
4289 | } | 4172 | } |
4290 | return(c); | 4173 | return (c); |
4291 | } | 4174 | } |
4292 | 4175 | ||
4293 | static void | 4176 | static void unget(c) |
4294 | unget(c) | ||
4295 | int c; | 4177 | int c; |
4296 | { | 4178 | { |
4297 | if (e.iop >= e.iobase) | 4179 | if (e.iop >= e.iobase) |
4298 | e.iop->peekc = c; | 4180 | e.iop->peekc = c; |
4299 | } | 4181 | } |
4300 | 4182 | ||
4301 | static int | 4183 | static int eofc() |
4302 | eofc() | ||
4303 | |||
4304 | { | 4184 | { |
4305 | return e.iop < e.iobase || (e.iop->peekc == 0 && e.iop->prev == 0); | 4185 | return e.iop < e.iobase || (e.iop->peekc == 0 && e.iop->prev == 0); |
4306 | } | 4186 | } |
4307 | 4187 | ||
4308 | static int | 4188 | static int readc() |
4309 | readc() | ||
4310 | { | 4189 | { |
4311 | register int c; | 4190 | register int c; |
4312 | 4191 | ||
4313 | for (; e.iop >= e.iobase; e.iop--) | 4192 | for (; e.iop >= e.iobase; e.iop--) |
4314 | if ((c = e.iop->peekc) != '\0') { | 4193 | if ((c = e.iop->peekc) != '\0') { |
4315 | e.iop->peekc = 0; | 4194 | e.iop->peekc = 0; |
4316 | return(c); | 4195 | return (c); |
4317 | } | 4196 | } else { |
4318 | else { | 4197 | if (e.iop->prev != 0) { |
4319 | if (e.iop->prev != 0) { | 4198 | if ((c = (*e.iop->iofn) (e.iop->argp, e.iop)) != '\0') { |
4320 | if ((c = (*e.iop->iofn)(e.iop->argp, e.iop)) != '\0') { | 4199 | if (c == -1) { |
4321 | if (c == -1) { | 4200 | e.iop++; |
4322 | e.iop++; | 4201 | continue; |
4323 | continue; | 4202 | } |
4324 | } | 4203 | if (e.iop == iostack) |
4325 | if (e.iop == iostack) | 4204 | ioecho(c); |
4326 | ioecho(c); | 4205 | return (e.iop->prev = c); |
4327 | return(e.iop->prev = c); | 4206 | } else if (e.iop->task == XIO && e.iop->prev != '\n') { |
4328 | } | 4207 | e.iop->prev = 0; |
4329 | else if (e.iop->task == XIO && e.iop->prev != '\n') { | 4208 | if (e.iop == iostack) |
4330 | e.iop->prev = 0; | 4209 | ioecho('\n'); |
4331 | if (e.iop == iostack) | 4210 | return '\n'; |
4332 | ioecho('\n'); | 4211 | } |
4333 | return '\n'; | 4212 | } |
4334 | } | 4213 | if (e.iop->task == XIO) { |
4335 | } | 4214 | if (multiline) |
4336 | if (e.iop->task == XIO) { | 4215 | return e.iop->prev = 0; |
4337 | if (multiline) | 4216 | if (interactive && e.iop == iostack + 1) { |
4338 | return e.iop->prev = 0; | ||
4339 | if (interactive && e.iop == iostack+1) { | ||
4340 | #ifdef CONFIG_FEATURE_COMMAND_EDITING | 4217 | #ifdef CONFIG_FEATURE_COMMAND_EDITING |
4341 | current_prompt=prompt->value; | 4218 | current_prompt = prompt->value; |
4342 | #else | 4219 | #else |
4343 | prs(prompt->value); | 4220 | prs(prompt->value); |
4344 | #endif | 4221 | #endif |
4222 | } | ||
4345 | } | 4223 | } |
4346 | } | ||
4347 | } | 4224 | } |
4348 | if (e.iop >= iostack) | 4225 | if (e.iop >= iostack) |
4349 | return(0); | 4226 | return (0); |
4350 | leave(); | 4227 | leave(); |
4351 | /* NOTREACHED */ | 4228 | /* NOTREACHED */ |
4352 | return(0); | 4229 | return (0); |
4353 | } | 4230 | } |
4354 | 4231 | ||
4355 | static void | 4232 | static void ioecho(c) |
4356 | ioecho(c) | ||
4357 | char c; | 4233 | char c; |
4358 | { | 4234 | { |
4359 | if (flag['v']) | 4235 | if (flag['v']) |
4360 | write(2, &c, sizeof c); | 4236 | write(2, &c, sizeof c); |
4361 | } | 4237 | } |
4362 | 4238 | ||
4363 | static void | 4239 | static void pushio(struct ioarg *argp, int (*fn) (struct ioarg *)) |
4364 | pushio(struct ioarg *argp, int (*fn)(struct ioarg *)) | ||
4365 | { | 4240 | { |
4366 | if (++e.iop >= &iostack[NPUSH]) { | 4241 | if (++e.iop >= &iostack[NPUSH]) { |
4367 | e.iop--; | 4242 | e.iop--; |
@@ -4369,44 +4244,44 @@ pushio(struct ioarg *argp, int (*fn)(struct ioarg *)) | |||
4369 | gflg++; | 4244 | gflg++; |
4370 | return; | 4245 | return; |
4371 | } | 4246 | } |
4372 | e.iop->iofn = (int (*)(struct ioarg *, struct io *))fn; | 4247 | e.iop->iofn = (int (*)(struct ioarg *, struct io *)) fn; |
4373 | 4248 | ||
4374 | if (argp->afid != AFID_NOBUF) | 4249 | if (argp->afid != AFID_NOBUF) |
4375 | e.iop->argp = argp; | 4250 | e.iop->argp = argp; |
4376 | else { | 4251 | else { |
4377 | e.iop->argp = ioargstack + (e.iop - iostack); | 4252 | e.iop->argp = ioargstack + (e.iop - iostack); |
4378 | *e.iop->argp = *argp; | 4253 | *e.iop->argp = *argp; |
4379 | e.iop->argp->afbuf = e.iop == &iostack[0] ? &mainbuf : &sharedbuf; | 4254 | e.iop->argp->afbuf = e.iop == &iostack[0] ? &mainbuf : &sharedbuf; |
4380 | if (isatty(e.iop->argp->afile) == 0 && | 4255 | if (isatty(e.iop->argp->afile) == 0 && |
4381 | (e.iop == &iostack[0] || | 4256 | (e.iop == &iostack[0] || |
4382 | lseek(e.iop->argp->afile, 0L, 1) != -1)) { | 4257 | lseek(e.iop->argp->afile, 0L, 1) != -1)) { |
4383 | if (++bufid == AFID_NOBUF) | 4258 | if (++bufid == AFID_NOBUF) |
4384 | bufid = AFID_ID; | 4259 | bufid = AFID_ID; |
4385 | e.iop->argp->afid = bufid; | 4260 | e.iop->argp->afid = bufid; |
4386 | } | 4261 | } |
4387 | } | 4262 | } |
4388 | 4263 | ||
4389 | e.iop->prev = ~'\n'; | 4264 | e.iop->prev = ~'\n'; |
4390 | e.iop->peekc = 0; | 4265 | e.iop->peekc = 0; |
4391 | e.iop->xchar = 0; | 4266 | e.iop->xchar = 0; |
4392 | e.iop->nlcount = 0; | 4267 | e.iop->nlcount = 0; |
4393 | if (fn == filechar || fn == linechar) | 4268 | if (fn == filechar || fn == linechar) |
4394 | e.iop->task = XIO; | 4269 | e.iop->task = XIO; |
4395 | else if (fn == (int(*)(struct ioarg *))gravechar || fn == (int(*)(struct ioarg *))qgravechar) | 4270 | else if (fn == (int (*)(struct ioarg *)) gravechar |
4271 | || fn == (int (*)(struct ioarg *)) qgravechar) | ||
4396 | e.iop->task = XGRAVE; | 4272 | e.iop->task = XGRAVE; |
4397 | else | 4273 | else |
4398 | e.iop->task = XOTHER; | 4274 | e.iop->task = XOTHER; |
4399 | } | 4275 | } |
4400 | 4276 | ||
4401 | static struct io * | 4277 | static struct io *setbase(ip) |
4402 | setbase(ip) | ||
4403 | struct io *ip; | 4278 | struct io *ip; |
4404 | { | 4279 | { |
4405 | register struct io *xp; | 4280 | register struct io *xp; |
4406 | 4281 | ||
4407 | xp = e.iobase; | 4282 | xp = e.iobase; |
4408 | e.iobase = ip; | 4283 | e.iobase = ip; |
4409 | return(xp); | 4284 | return (xp); |
4410 | } | 4285 | } |
4411 | 4286 | ||
4412 | /* | 4287 | /* |
@@ -4416,109 +4291,102 @@ struct io *ip; | |||
4416 | /* | 4291 | /* |
4417 | * Produce the characters of a string, then a newline, then EOF. | 4292 | * Produce the characters of a string, then a newline, then EOF. |
4418 | */ | 4293 | */ |
4419 | static int | 4294 | static int nlchar(ap) |
4420 | nlchar(ap) | ||
4421 | register struct ioarg *ap; | 4295 | register struct ioarg *ap; |
4422 | { | 4296 | { |
4423 | register int c; | 4297 | register int c; |
4424 | 4298 | ||
4425 | if (ap->aword == NULL) | 4299 | if (ap->aword == NULL) |
4426 | return(0); | 4300 | return (0); |
4427 | if ((c = *ap->aword++) == 0) { | 4301 | if ((c = *ap->aword++) == 0) { |
4428 | ap->aword = NULL; | 4302 | ap->aword = NULL; |
4429 | return('\n'); | 4303 | return ('\n'); |
4430 | } | 4304 | } |
4431 | return(c); | 4305 | return (c); |
4432 | } | 4306 | } |
4433 | 4307 | ||
4434 | /* | 4308 | /* |
4435 | * Given a list of words, produce the characters | 4309 | * Given a list of words, produce the characters |
4436 | * in them, with a space after each word. | 4310 | * in them, with a space after each word. |
4437 | */ | 4311 | */ |
4438 | static int | 4312 | static int wdchar(ap) |
4439 | wdchar(ap) | ||
4440 | register struct ioarg *ap; | 4313 | register struct ioarg *ap; |
4441 | { | 4314 | { |
4442 | register char c; | 4315 | register char c; |
4443 | register char **wl; | 4316 | register char **wl; |
4444 | 4317 | ||
4445 | if ((wl = ap->awordlist) == NULL) | 4318 | if ((wl = ap->awordlist) == NULL) |
4446 | return(0); | 4319 | return (0); |
4447 | if (*wl != NULL) { | 4320 | if (*wl != NULL) { |
4448 | if ((c = *(*wl)++) != 0) | 4321 | if ((c = *(*wl)++) != 0) |
4449 | return(c & 0177); | 4322 | return (c & 0177); |
4450 | ap->awordlist++; | 4323 | ap->awordlist++; |
4451 | return(' '); | 4324 | return (' '); |
4452 | } | 4325 | } |
4453 | ap->awordlist = NULL; | 4326 | ap->awordlist = NULL; |
4454 | return('\n'); | 4327 | return ('\n'); |
4455 | } | 4328 | } |
4456 | 4329 | ||
4457 | /* | 4330 | /* |
4458 | * Return the characters of a list of words, | 4331 | * Return the characters of a list of words, |
4459 | * producing a space between them. | 4332 | * producing a space between them. |
4460 | */ | 4333 | */ |
4461 | static int | 4334 | static int dolchar(ap) |
4462 | dolchar(ap) | ||
4463 | register struct ioarg *ap; | 4335 | register struct ioarg *ap; |
4464 | { | 4336 | { |
4465 | register char *wp; | 4337 | register char *wp; |
4466 | 4338 | ||
4467 | if ((wp = *ap->awordlist++) != NULL) { | 4339 | if ((wp = *ap->awordlist++) != NULL) { |
4468 | PUSHIO(aword, wp, *ap->awordlist == NULL? strchar: xxchar); | 4340 | PUSHIO(aword, wp, *ap->awordlist == NULL ? strchar : xxchar); |
4469 | return(-1); | 4341 | return (-1); |
4470 | } | 4342 | } |
4471 | return(0); | 4343 | return (0); |
4472 | } | 4344 | } |
4473 | 4345 | ||
4474 | static int | 4346 | static int xxchar(ap) |
4475 | xxchar(ap) | ||
4476 | register struct ioarg *ap; | 4347 | register struct ioarg *ap; |
4477 | { | 4348 | { |
4478 | register int c; | 4349 | register int c; |
4479 | 4350 | ||
4480 | if (ap->aword == NULL) | 4351 | if (ap->aword == NULL) |
4481 | return(0); | 4352 | return (0); |
4482 | if ((c = *ap->aword++) == '\0') { | 4353 | if ((c = *ap->aword++) == '\0') { |
4483 | ap->aword = NULL; | 4354 | ap->aword = NULL; |
4484 | return(' '); | 4355 | return (' '); |
4485 | } | 4356 | } |
4486 | return(c); | 4357 | return (c); |
4487 | } | 4358 | } |
4488 | 4359 | ||
4489 | /* | 4360 | /* |
4490 | * Produce the characters from a single word (string). | 4361 | * Produce the characters from a single word (string). |
4491 | */ | 4362 | */ |
4492 | static int | 4363 | static int strchar(ap) |
4493 | strchar(ap) | ||
4494 | register struct ioarg *ap; | 4364 | register struct ioarg *ap; |
4495 | { | 4365 | { |
4496 | register int c; | 4366 | register int c; |
4497 | 4367 | ||
4498 | if (ap->aword == NULL || (c = *ap->aword++) == 0) | 4368 | if (ap->aword == NULL || (c = *ap->aword++) == 0) |
4499 | return(0); | 4369 | return (0); |
4500 | return(c); | 4370 | return (c); |
4501 | } | 4371 | } |
4502 | 4372 | ||
4503 | /* | 4373 | /* |
4504 | * Produce quoted characters from a single word (string). | 4374 | * Produce quoted characters from a single word (string). |
4505 | */ | 4375 | */ |
4506 | static int | 4376 | static int qstrchar(ap) |
4507 | qstrchar(ap) | ||
4508 | register struct ioarg *ap; | 4377 | register struct ioarg *ap; |
4509 | { | 4378 | { |
4510 | register int c; | 4379 | register int c; |
4511 | 4380 | ||
4512 | if (ap->aword == NULL || (c = *ap->aword++) == 0) | 4381 | if (ap->aword == NULL || (c = *ap->aword++) == 0) |
4513 | return(0); | 4382 | return (0); |
4514 | return(c|QUOTE); | 4383 | return (c | QUOTE); |
4515 | } | 4384 | } |
4516 | 4385 | ||
4517 | /* | 4386 | /* |
4518 | * Return the characters from a file. | 4387 | * Return the characters from a file. |
4519 | */ | 4388 | */ |
4520 | static int | 4389 | static int filechar(ap) |
4521 | filechar(ap) | ||
4522 | register struct ioarg *ap; | 4390 | register struct ioarg *ap; |
4523 | { | 4391 | { |
4524 | register int i; | 4392 | register int i; |
@@ -4526,47 +4394,45 @@ register struct ioarg *ap; | |||
4526 | struct iobuf *bp = ap->afbuf; | 4394 | struct iobuf *bp = ap->afbuf; |
4527 | 4395 | ||
4528 | if (ap->afid != AFID_NOBUF) { | 4396 | if (ap->afid != AFID_NOBUF) { |
4529 | if ((i = ap->afid != bp->id) || bp->bufp == bp->ebufp) { | 4397 | if ((i = ap->afid != bp->id) || bp->bufp == bp->ebufp) { |
4530 | if (i) | 4398 | if (i) |
4531 | lseek(ap->afile, ap->afpos, 0); | 4399 | lseek(ap->afile, ap->afpos, 0); |
4532 | i = safe_read(ap->afile, bp->buf, sizeof(bp->buf)); | 4400 | i = safe_read(ap->afile, bp->buf, sizeof(bp->buf)); |
4533 | if (i <= 0) { | 4401 | if (i <= 0) { |
4534 | closef(ap->afile); | 4402 | closef(ap->afile); |
4535 | return 0; | 4403 | return 0; |
4536 | } | 4404 | } |
4537 | bp->id = ap->afid; | 4405 | bp->id = ap->afid; |
4538 | bp->ebufp = (bp->bufp = bp->buf) + i; | 4406 | bp->ebufp = (bp->bufp = bp->buf) + i; |
4539 | } | 4407 | } |
4540 | ap->afpos++; | 4408 | ap->afpos++; |
4541 | return *bp->bufp++ & 0177; | 4409 | return *bp->bufp++ & 0177; |
4542 | } | 4410 | } |
4543 | |||
4544 | #ifdef CONFIG_FEATURE_COMMAND_EDITING | 4411 | #ifdef CONFIG_FEATURE_COMMAND_EDITING |
4545 | if (interactive && isatty(ap->afile)) { | 4412 | if (interactive && isatty(ap->afile)) { |
4546 | static char mycommand[BUFSIZ]; | 4413 | static char mycommand[BUFSIZ]; |
4547 | static int position = 0, size = 0; | 4414 | static int position = 0, size = 0; |
4548 | 4415 | ||
4549 | while (size == 0 || position >= size) { | 4416 | while (size == 0 || position >= size) { |
4550 | cmdedit_read_input(current_prompt, mycommand); | 4417 | cmdedit_read_input(current_prompt, mycommand); |
4551 | size = strlen(mycommand); | 4418 | size = strlen(mycommand); |
4552 | position = 0; | 4419 | position = 0; |
4553 | } | 4420 | } |
4554 | c = mycommand[position]; | 4421 | c = mycommand[position]; |
4555 | position++; | 4422 | position++; |
4556 | return(c); | 4423 | return (c); |
4557 | } else | 4424 | } else |
4558 | #endif | 4425 | #endif |
4559 | { | 4426 | { |
4560 | i = safe_read(ap->afile, &c, sizeof(c)); | 4427 | i = safe_read(ap->afile, &c, sizeof(c)); |
4561 | return(i == sizeof(c)? c&0177: (closef(ap->afile), 0)); | 4428 | return (i == sizeof(c) ? c & 0177 : (closef(ap->afile), 0)); |
4562 | } | 4429 | } |
4563 | } | 4430 | } |
4564 | 4431 | ||
4565 | /* | 4432 | /* |
4566 | * Return the characters from a here temp file. | 4433 | * Return the characters from a here temp file. |
4567 | */ | 4434 | */ |
4568 | static int | 4435 | static int herechar(ap) |
4569 | herechar(ap) | ||
4570 | register struct ioarg *ap; | 4436 | register struct ioarg *ap; |
4571 | { | 4437 | { |
4572 | char c; | 4438 | char c; |
@@ -4584,20 +4450,18 @@ register struct ioarg *ap; | |||
4584 | * Return the characters produced by a process (`...`). | 4450 | * Return the characters produced by a process (`...`). |
4585 | * Quote them if required, and remove any trailing newline characters. | 4451 | * Quote them if required, and remove any trailing newline characters. |
4586 | */ | 4452 | */ |
4587 | static int | 4453 | static int gravechar(ap, iop) |
4588 | gravechar(ap, iop) | ||
4589 | struct ioarg *ap; | 4454 | struct ioarg *ap; |
4590 | struct io *iop; | 4455 | struct io *iop; |
4591 | { | 4456 | { |
4592 | register int c; | 4457 | register int c; |
4593 | 4458 | ||
4594 | if ((c = qgravechar(ap, iop)&~QUOTE) == '\n') | 4459 | if ((c = qgravechar(ap, iop) & ~QUOTE) == '\n') |
4595 | c = ' '; | 4460 | c = ' '; |
4596 | return(c); | 4461 | return (c); |
4597 | } | 4462 | } |
4598 | 4463 | ||
4599 | static int | 4464 | static int qgravechar(ap, iop) |
4600 | qgravechar(ap, iop) | ||
4601 | register struct ioarg *ap; | 4465 | register struct ioarg *ap; |
4602 | struct io *iop; | 4466 | struct io *iop; |
4603 | { | 4467 | { |
@@ -4606,7 +4470,7 @@ struct io *iop; | |||
4606 | if (iop->xchar) { | 4470 | if (iop->xchar) { |
4607 | if (iop->nlcount) { | 4471 | if (iop->nlcount) { |
4608 | iop->nlcount--; | 4472 | iop->nlcount--; |
4609 | return('\n'|QUOTE); | 4473 | return ('\n' | QUOTE); |
4610 | } | 4474 | } |
4611 | c = iop->xchar; | 4475 | c = iop->xchar; |
4612 | iop->xchar = 0; | 4476 | iop->xchar = 0; |
@@ -4616,18 +4480,17 @@ struct io *iop; | |||
4616 | iop->nlcount++; | 4480 | iop->nlcount++; |
4617 | iop->xchar = c; | 4481 | iop->xchar = c; |
4618 | if (c == 0) | 4482 | if (c == 0) |
4619 | return(c); | 4483 | return (c); |
4620 | iop->nlcount--; | 4484 | iop->nlcount--; |
4621 | c = '\n'; | 4485 | c = '\n'; |
4622 | } | 4486 | } |
4623 | return(c!=0? c|QUOTE: 0); | 4487 | return (c != 0 ? c | QUOTE : 0); |
4624 | } | 4488 | } |
4625 | 4489 | ||
4626 | /* | 4490 | /* |
4627 | * Return a single command (usually the first line) from a file. | 4491 | * Return a single command (usually the first line) from a file. |
4628 | */ | 4492 | */ |
4629 | static int | 4493 | static int linechar(ap) |
4630 | linechar(ap) | ||
4631 | register struct ioarg *ap; | 4494 | register struct ioarg *ap; |
4632 | { | 4495 | { |
4633 | register int c; | 4496 | register int c; |
@@ -4635,83 +4498,76 @@ register struct ioarg *ap; | |||
4635 | if ((c = filechar(ap)) == '\n') { | 4498 | if ((c = filechar(ap)) == '\n') { |
4636 | if (!multiline) { | 4499 | if (!multiline) { |
4637 | closef(ap->afile); | 4500 | closef(ap->afile); |
4638 | ap->afile = -1; /* illegal value */ | 4501 | ap->afile = -1; /* illegal value */ |
4639 | } | 4502 | } |
4640 | } | 4503 | } |
4641 | return(c); | 4504 | return (c); |
4642 | } | 4505 | } |
4643 | 4506 | ||
4644 | static void | 4507 | static void prs(s) |
4645 | prs(s) | ||
4646 | register char *s; | 4508 | register char *s; |
4647 | { | 4509 | { |
4648 | if (*s) | 4510 | if (*s) |
4649 | write(2, s, strlen(s)); | 4511 | write(2, s, strlen(s)); |
4650 | } | 4512 | } |
4651 | 4513 | ||
4652 | static void | 4514 | static void prn(u) |
4653 | prn(u) | ||
4654 | unsigned u; | 4515 | unsigned u; |
4655 | { | 4516 | { |
4656 | prs(itoa(u)); | 4517 | prs(itoa(u)); |
4657 | } | 4518 | } |
4658 | 4519 | ||
4659 | static void | 4520 | static void closef(i) |
4660 | closef(i) | ||
4661 | register int i; | 4521 | register int i; |
4662 | { | 4522 | { |
4663 | if (i > 2) | 4523 | if (i > 2) |
4664 | close(i); | 4524 | close(i); |
4665 | } | 4525 | } |
4666 | 4526 | ||
4667 | static void | 4527 | static void closeall() |
4668 | closeall() | ||
4669 | { | 4528 | { |
4670 | register int u; | 4529 | register int u; |
4671 | 4530 | ||
4672 | for (u=NUFILE; u<NOFILE;) | 4531 | for (u = NUFILE; u < NOFILE;) |
4673 | close(u++); | 4532 | close(u++); |
4674 | } | 4533 | } |
4675 | 4534 | ||
4676 | /* | 4535 | /* |
4677 | * remap fd into Shell's fd space | 4536 | * remap fd into Shell's fd space |
4678 | */ | 4537 | */ |
4679 | static int | 4538 | static int remap(fd) |
4680 | remap(fd) | ||
4681 | register int fd; | 4539 | register int fd; |
4682 | { | 4540 | { |
4683 | register int i; | 4541 | register int i; |
4684 | int map[NOFILE]; | 4542 | int map[NOFILE]; |
4685 | 4543 | ||
4686 | if (fd < e.iofd) { | 4544 | if (fd < e.iofd) { |
4687 | for (i=0; i<NOFILE; i++) | 4545 | for (i = 0; i < NOFILE; i++) |
4688 | map[i] = 0; | 4546 | map[i] = 0; |
4689 | do { | 4547 | do { |
4690 | map[fd] = 1; | 4548 | map[fd] = 1; |
4691 | fd = dup(fd); | 4549 | fd = dup(fd); |
4692 | } while (fd >= 0 && fd < e.iofd); | 4550 | } while (fd >= 0 && fd < e.iofd); |
4693 | for (i=0; i<NOFILE; i++) | 4551 | for (i = 0; i < NOFILE; i++) |
4694 | if (map[i]) | 4552 | if (map[i]) |
4695 | close(i); | 4553 | close(i); |
4696 | if (fd < 0) | 4554 | if (fd < 0) |
4697 | err("too many files open in shell"); | 4555 | err("too many files open in shell"); |
4698 | } | 4556 | } |
4699 | return(fd); | 4557 | return (fd); |
4700 | } | 4558 | } |
4701 | 4559 | ||
4702 | static int | 4560 | static int openpipe(pv) |
4703 | openpipe(pv) | ||
4704 | register int *pv; | 4561 | register int *pv; |
4705 | { | 4562 | { |
4706 | register int i; | 4563 | register int i; |
4707 | 4564 | ||
4708 | if ((i = pipe(pv)) < 0) | 4565 | if ((i = pipe(pv)) < 0) |
4709 | err("can't create pipe - try again"); | 4566 | err("can't create pipe - try again"); |
4710 | return(i); | 4567 | return (i); |
4711 | } | 4568 | } |
4712 | 4569 | ||
4713 | static void | 4570 | static void closepipe(pv) |
4714 | closepipe(pv) | ||
4715 | register int *pv; | 4571 | register int *pv; |
4716 | { | 4572 | { |
4717 | if (pv != NULL) { | 4573 | if (pv != NULL) { |
@@ -4726,8 +4582,7 @@ register int *pv; | |||
4726 | * here documents | 4582 | * here documents |
4727 | */ | 4583 | */ |
4728 | 4584 | ||
4729 | static void | 4585 | static void markhere(s, iop) |
4730 | markhere(s, iop) | ||
4731 | register char *s; | 4586 | register char *s; |
4732 | struct ioword *iop; | 4587 | struct ioword *iop; |
4733 | { | 4588 | { |
@@ -4745,39 +4600,37 @@ struct ioword *iop; | |||
4745 | if (inhere == 0) | 4600 | if (inhere == 0) |
4746 | inhere = h; | 4601 | inhere = h; |
4747 | else | 4602 | else |
4748 | for (lh = inhere; lh!=NULL; lh = lh->h_next) | 4603 | for (lh = inhere; lh != NULL; lh = lh->h_next) |
4749 | if (lh->h_next == 0) { | 4604 | if (lh->h_next == 0) { |
4750 | lh->h_next = h; | 4605 | lh->h_next = h; |
4751 | break; | 4606 | break; |
4752 | } | 4607 | } |
4753 | iop->io_flag |= IOHERE|IOXHERE; | 4608 | iop->io_flag |= IOHERE | IOXHERE; |
4754 | for (s = h->h_tag; *s; s++) | 4609 | for (s = h->h_tag; *s; s++) |
4755 | if (*s & QUOTE) { | 4610 | if (*s & QUOTE) { |
4756 | iop->io_flag &= ~ IOXHERE; | 4611 | iop->io_flag &= ~IOXHERE; |
4757 | *s &= ~ QUOTE; | 4612 | *s &= ~QUOTE; |
4758 | } | 4613 | } |
4759 | h->h_dosub = iop->io_flag & IOXHERE; | 4614 | h->h_dosub = iop->io_flag & IOXHERE; |
4760 | } | 4615 | } |
4761 | 4616 | ||
4762 | static void | 4617 | static void gethere() |
4763 | gethere() | ||
4764 | { | 4618 | { |
4765 | register struct here *h, *hp; | 4619 | register struct here *h, *hp; |
4766 | 4620 | ||
4767 | /* Scan here files first leaving inhere list in place */ | 4621 | /* Scan here files first leaving inhere list in place */ |
4768 | for (hp = h = inhere; h != NULL; hp = h, h = h->h_next) | 4622 | for (hp = h = inhere; h != NULL; hp = h, h = h->h_next) |
4769 | readhere(&h->h_iop->io_name, h->h_tag, h->h_dosub? 0: '\''); | 4623 | readhere(&h->h_iop->io_name, h->h_tag, h->h_dosub ? 0 : '\''); |
4770 | 4624 | ||
4771 | /* Make inhere list active - keep list intact for scraphere */ | 4625 | /* Make inhere list active - keep list intact for scraphere */ |
4772 | if (hp != NULL) { | 4626 | if (hp != NULL) { |
4773 | hp->h_next = acthere; | 4627 | hp->h_next = acthere; |
4774 | acthere = inhere; | 4628 | acthere = inhere; |
4775 | inhere = NULL; | 4629 | inhere = NULL; |
4776 | } | 4630 | } |
4777 | } | 4631 | } |
4778 | 4632 | ||
4779 | static void | 4633 | static void readhere(name, s, ec) |
4780 | readhere(name, s, ec) | ||
4781 | char **name; | 4634 | char **name; |
4782 | register char *s; | 4635 | register char *s; |
4783 | int ec; | 4636 | int ec; |
@@ -4786,7 +4639,7 @@ int ec; | |||
4786 | char tname[30] = ".msh_XXXXXX"; | 4639 | char tname[30] = ".msh_XXXXXX"; |
4787 | register int c; | 4640 | register int c; |
4788 | jmp_buf ev; | 4641 | jmp_buf ev; |
4789 | char myline [LINELIM+1]; | 4642 | char myline[LINELIM + 1]; |
4790 | char *thenext; | 4643 | char *thenext; |
4791 | 4644 | ||
4792 | tf = mkstemp(tname); | 4645 | tf = mkstemp(tname); |
@@ -4796,20 +4649,20 @@ int ec; | |||
4796 | if (newenv(setjmp(errpt = ev)) != 0) | 4649 | if (newenv(setjmp(errpt = ev)) != 0) |
4797 | unlink(tname); | 4650 | unlink(tname); |
4798 | else { | 4651 | else { |
4799 | pushio(e.iop->argp, (int(*)(struct ioarg *))e.iop->iofn); | 4652 | pushio(e.iop->argp, (int (*)(struct ioarg *)) e.iop->iofn); |
4800 | e.iobase = e.iop; | 4653 | e.iobase = e.iop; |
4801 | for (;;) { | 4654 | for (;;) { |
4802 | if (interactive && e.iop <= iostack) { | 4655 | if (interactive && e.iop <= iostack) { |
4803 | #ifdef CONFIG_FEATURE_COMMAND_EDITING | 4656 | #ifdef CONFIG_FEATURE_COMMAND_EDITING |
4804 | current_prompt=cprompt->value; | 4657 | current_prompt = cprompt->value; |
4805 | #else | 4658 | #else |
4806 | prs(cprompt->value); | 4659 | prs(cprompt->value); |
4807 | #endif | 4660 | #endif |
4808 | } | 4661 | } |
4809 | thenext = myline; | 4662 | thenext = myline; |
4810 | while ((c = my_getc(ec)) != '\n' && c) { | 4663 | while ((c = my_getc(ec)) != '\n' && c) { |
4811 | if (ec == '\'') | 4664 | if (ec == '\'') |
4812 | c &= ~ QUOTE; | 4665 | c &= ~QUOTE; |
4813 | if (thenext >= &myline[LINELIM]) { | 4666 | if (thenext >= &myline[LINELIM]) { |
4814 | c = 0; | 4667 | c = 0; |
4815 | break; | 4668 | break; |
@@ -4820,10 +4673,12 @@ int ec; | |||
4820 | if (strcmp(s, myline) == 0 || c == 0) | 4673 | if (strcmp(s, myline) == 0 || c == 0) |
4821 | break; | 4674 | break; |
4822 | *thenext++ = '\n'; | 4675 | *thenext++ = '\n'; |
4823 | write (tf, myline, (int)(thenext-myline)); | 4676 | write(tf, myline, (int) (thenext - myline)); |
4824 | } | 4677 | } |
4825 | if (c == 0) { | 4678 | if (c == 0) { |
4826 | prs("here document `"); prs(s); err("' unclosed"); | 4679 | prs("here document `"); |
4680 | prs(s); | ||
4681 | err("' unclosed"); | ||
4827 | } | 4682 | } |
4828 | quitenv(); | 4683 | quitenv(); |
4829 | } | 4684 | } |
@@ -4834,8 +4689,7 @@ int ec; | |||
4834 | * open here temp file. | 4689 | * open here temp file. |
4835 | * if unquoted here, expand here temp file into second temp file. | 4690 | * if unquoted here, expand here temp file into second temp file. |
4836 | */ | 4691 | */ |
4837 | static int | 4692 | static int herein(hname, xdoll) |
4838 | herein(hname, xdoll) | ||
4839 | char *hname; | 4693 | char *hname; |
4840 | int xdoll; | 4694 | int xdoll; |
4841 | { | 4695 | { |
@@ -4847,7 +4701,7 @@ int xdoll; | |||
4847 | (void) &tf; | 4701 | (void) &tf; |
4848 | #endif | 4702 | #endif |
4849 | if (hname == 0) | 4703 | if (hname == 0) |
4850 | return(-1); | 4704 | return (-1); |
4851 | hf = open(hname, 0); | 4705 | hf = open(hname, 0); |
4852 | if (hf < 0) | 4706 | if (hf < 0) |
4853 | return (-1); | 4707 | return (-1); |
@@ -4863,7 +4717,7 @@ int xdoll; | |||
4863 | PUSHIO(afile, hf, herechar); | 4717 | PUSHIO(afile, hf, herechar); |
4864 | setbase(e.iop); | 4718 | setbase(e.iop); |
4865 | while ((c = subgetc(0, 0)) != 0) { | 4719 | while ((c = subgetc(0, 0)) != 0) { |
4866 | c &= ~ QUOTE; | 4720 | c &= ~QUOTE; |
4867 | write(tf, &c, sizeof c); | 4721 | write(tf, &c, sizeof c); |
4868 | } | 4722 | } |
4869 | quitenv(); | 4723 | quitenv(); |
@@ -4877,21 +4731,19 @@ int xdoll; | |||
4877 | return (hf); | 4731 | return (hf); |
4878 | } | 4732 | } |
4879 | 4733 | ||
4880 | static void | 4734 | static void scraphere() |
4881 | scraphere() | ||
4882 | { | 4735 | { |
4883 | register struct here *h; | 4736 | register struct here *h; |
4884 | 4737 | ||
4885 | for (h = inhere; h != NULL; h = h->h_next) { | 4738 | for (h = inhere; h != NULL; h = h->h_next) { |
4886 | if (h->h_iop && h->h_iop->io_name) | 4739 | if (h->h_iop && h->h_iop->io_name) |
4887 | unlink(h->h_iop->io_name); | 4740 | unlink(h->h_iop->io_name); |
4888 | } | 4741 | } |
4889 | inhere = NULL; | 4742 | inhere = NULL; |
4890 | } | 4743 | } |
4891 | 4744 | ||
4892 | /* unlink here temp files before a freearea(area) */ | 4745 | /* unlink here temp files before a freearea(area) */ |
4893 | static void | 4746 | static void freehere(area) |
4894 | freehere(area) | ||
4895 | int area; | 4747 | int area; |
4896 | { | 4748 | { |
4897 | register struct here *h, *hl; | 4749 | register struct here *h, *hl; |
@@ -4946,4 +4798,3 @@ int area; | |||
4946 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 4798 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
4947 | * | 4799 | * |
4948 | */ | 4800 | */ |
4949 | |||