Deleted Added
full compact
eval.c (230154) eval.c (230161)
1/*-
2 * Copyright (c) 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Kenneth Almquist.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 22 unchanged lines hidden (view full) ---

31 */
32
33#ifndef lint
34#if 0
35static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95";
36#endif
37#endif /* not lint */
38#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Kenneth Almquist.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 22 unchanged lines hidden (view full) ---

31 */
32
33#ifndef lint
34#if 0
35static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95";
36#endif
37#endif /* not lint */
38#include <sys/cdefs.h>
39__FBSDID("$FreeBSD: head/bin/sh/eval.c 230154 2012-01-15 20:04:05Z jilles $");
39__FBSDID("$FreeBSD: head/bin/sh/eval.c 230161 2012-01-15 21:39:38Z jilles $");
40
41#include <paths.h>
42#include <signal.h>
43#include <stdlib.h>
44#include <unistd.h>
45#include <sys/resource.h>
46#include <sys/wait.h> /* For WIFSIGNALED(status) */
47#include <errno.h>

--- 36 unchanged lines hidden (view full) ---

84char *commandname;
85struct strlist *cmdenviron;
86int exitstatus; /* exit status of last command */
87int oexitstatus; /* saved exit status */
88
89
90static void evalloop(union node *, int);
91static void evalfor(union node *, int);
40
41#include <paths.h>
42#include <signal.h>
43#include <stdlib.h>
44#include <unistd.h>
45#include <sys/resource.h>
46#include <sys/wait.h> /* For WIFSIGNALED(status) */
47#include <errno.h>

--- 36 unchanged lines hidden (view full) ---

84char *commandname;
85struct strlist *cmdenviron;
86int exitstatus; /* exit status of last command */
87int oexitstatus; /* saved exit status */
88
89
90static void evalloop(union node *, int);
91static void evalfor(union node *, int);
92static union node *evalcase(union node *, int);
92static union node *evalcase(union node *);
93static void evalsubshell(union node *, int);
94static void evalredir(union node *, int);
95static void expredir(union node *);
96static void evalpipe(union node *);
97static int is_valid_fast_cmdsubst(union node *n);
98static void evalcommand(union node *, int, struct backcmd *);
99static void prehash(union node *);
100

--- 150 unchanged lines hidden (view full) ---

251 case NWHILE:
252 case NUNTIL:
253 evalloop(n, flags & ~EV_EXIT);
254 break;
255 case NFOR:
256 evalfor(n, flags & ~EV_EXIT);
257 break;
258 case NCASE:
93static void evalsubshell(union node *, int);
94static void evalredir(union node *, int);
95static void expredir(union node *);
96static void evalpipe(union node *);
97static int is_valid_fast_cmdsubst(union node *n);
98static void evalcommand(union node *, int, struct backcmd *);
99static void prehash(union node *);
100

--- 150 unchanged lines hidden (view full) ---

251 case NWHILE:
252 case NUNTIL:
253 evalloop(n, flags & ~EV_EXIT);
254 break;
255 case NFOR:
256 evalfor(n, flags & ~EV_EXIT);
257 break;
258 case NCASE:
259 next = evalcase(n, flags);
259 next = evalcase(n);
260 break;
260 break;
261 case NCLIST:
262 next = n->nclist.body;
263 break;
264 case NCLISTFALLTHRU:
265 if (n->nclist.body) {
266 evaltree(n->nclist.body, flags & ~EV_EXIT);
267 if (evalskip)
268 goto out;
269 }
270 next = n->nclist.next;
271 break;
261 case NDEFUN:
262 defun(n->narg.text, n->narg.next);
263 exitstatus = 0;
264 break;
265 case NNOT:
266 evaltree(n->nnot.com, EV_TESTED);
267 exitstatus = !exitstatus;
268 break;

--- 92 unchanged lines hidden (view full) ---

361 break;
362 }
363 }
364 loopnest--;
365 popstackmark(&smark);
366}
367
368
272 case NDEFUN:
273 defun(n->narg.text, n->narg.next);
274 exitstatus = 0;
275 break;
276 case NNOT:
277 evaltree(n->nnot.com, EV_TESTED);
278 exitstatus = !exitstatus;
279 break;

--- 92 unchanged lines hidden (view full) ---

372 break;
373 }
374 }
375 loopnest--;
376 popstackmark(&smark);
377}
378
379
380/*
381 * Evaluate a case statement, returning the selected tree.
382 *
383 * The exit status needs care to get right.
384 */
369
370static union node *
385
386static union node *
371evalcase(union node *n, int flags)
387evalcase(union node *n)
372{
373 union node *cp;
374 union node *patp;
375 struct arglist arglist;
376 struct stackmark smark;
377
378 setstackmark(&smark);
379 arglist.lastp = &arglist.list;
380 oexitstatus = exitstatus;
381 expandarg(n->ncase.expr, &arglist, EXP_TILDE);
382 for (cp = n->ncase.cases ; cp ; cp = cp->nclist.next) {
383 for (patp = cp->nclist.pattern ; patp ; patp = patp->narg.next) {
384 if (casematch(patp, arglist.list->text)) {
385 popstackmark(&smark);
386 while (cp->nclist.next &&
388{
389 union node *cp;
390 union node *patp;
391 struct arglist arglist;
392 struct stackmark smark;
393
394 setstackmark(&smark);
395 arglist.lastp = &arglist.list;
396 oexitstatus = exitstatus;
397 expandarg(n->ncase.expr, &arglist, EXP_TILDE);
398 for (cp = n->ncase.cases ; cp ; cp = cp->nclist.next) {
399 for (patp = cp->nclist.pattern ; patp ; patp = patp->narg.next) {
400 if (casematch(patp, arglist.list->text)) {
401 popstackmark(&smark);
402 while (cp->nclist.next &&
387 cp->type == NCLISTFALLTHRU) {
388 evaltree(cp->nclist.body,
389 flags & ~EV_EXIT);
390 if (evalskip != 0)
391 return (NULL);
403 cp->type == NCLISTFALLTHRU &&
404 cp->nclist.body == NULL)
392 cp = cp->nclist.next;
405 cp = cp->nclist.next;
393 }
406 if (cp->nclist.next &&
407 cp->type == NCLISTFALLTHRU)
408 return (cp);
394 if (cp->nclist.body == NULL)
395 exitstatus = 0;
396 return (cp->nclist.body);
397 }
398 }
399 }
400 popstackmark(&smark);
401 exitstatus = 0;

--- 877 unchanged lines hidden ---
409 if (cp->nclist.body == NULL)
410 exitstatus = 0;
411 return (cp->nclist.body);
412 }
413 }
414 }
415 popstackmark(&smark);
416 exitstatus = 0;

--- 877 unchanged lines hidden ---