| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: parser.c,v 1.109 2016/03/27 14:35:30 christos Exp $ */ | | 1 | /* $NetBSD: parser.c,v 1.110 2016/03/27 14:36:29 christos Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1991, 1993 | | 4 | * Copyright (c) 1991, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to Berkeley by | | 7 | * This code is derived from software contributed to Berkeley by |
8 | * Kenneth Almquist. | | 8 | * Kenneth Almquist. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -27,27 +27,27 @@ | | | @@ -27,27 +27,27 @@ |
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | * SUCH DAMAGE. | | 32 | * SUCH DAMAGE. |
33 | */ | | 33 | */ |
34 | | | 34 | |
35 | #include <sys/cdefs.h> | | 35 | #include <sys/cdefs.h> |
36 | #ifndef lint | | 36 | #ifndef lint |
37 | #if 0 | | 37 | #if 0 |
38 | static char sccsid[] = "@(#)parser.c 8.7 (Berkeley) 5/16/95"; | | 38 | static char sccsid[] = "@(#)parser.c 8.7 (Berkeley) 5/16/95"; |
39 | #else | | 39 | #else |
40 | __RCSID("$NetBSD: parser.c,v 1.109 2016/03/27 14:35:30 christos Exp $"); | | 40 | __RCSID("$NetBSD: parser.c,v 1.110 2016/03/27 14:36:29 christos Exp $"); |
41 | #endif | | 41 | #endif |
42 | #endif /* not lint */ | | 42 | #endif /* not lint */ |
43 | | | 43 | |
44 | #include <stdio.h> | | 44 | #include <stdio.h> |
45 | #include <stdlib.h> | | 45 | #include <stdlib.h> |
46 | #include <limits.h> | | 46 | #include <limits.h> |
47 | | | 47 | |
48 | #include "shell.h" | | 48 | #include "shell.h" |
49 | #include "parser.h" | | 49 | #include "parser.h" |
50 | #include "nodes.h" | | 50 | #include "nodes.h" |
51 | #include "expand.h" /* defines rmescapes() */ | | 51 | #include "expand.h" /* defines rmescapes() */ |
52 | #include "eval.h" /* defines commandname */ | | 52 | #include "eval.h" /* defines commandname */ |
53 | #include "redir.h" /* defines copyfd() */ | | 53 | #include "redir.h" /* defines copyfd() */ |
| @@ -550,64 +550,57 @@ checkneg: | | | @@ -550,64 +550,57 @@ checkneg: |
550 | n2->type = NNOT; | | 550 | n2->type = NNOT; |
551 | n2->nnot.com = n1; | | 551 | n2->nnot.com = n1; |
552 | return n2; | | 552 | return n2; |
553 | } | | 553 | } |
554 | else | | 554 | else |
555 | return n1; | | 555 | return n1; |
556 | } | | 556 | } |
557 | | | 557 | |
558 | | | 558 | |
559 | STATIC union node * | | 559 | STATIC union node * |
560 | simplecmd(union node **rpp, union node *redir) | | 560 | simplecmd(union node **rpp, union node *redir) |
561 | { | | 561 | { |
562 | union node *args, **app; | | 562 | union node *args, **app; |
563 | union node **orig_rpp = rpp; | | | |
564 | union node *n = NULL, *n2; | | 563 | union node *n = NULL, *n2; |
565 | int negate = 0; | | 564 | int negate = 0; |
566 | | | 565 | |
567 | /* If we don't have any redirections already, then we must reset */ | | 566 | /* If we don't have any redirections already, then we must reset */ |
568 | /* rpp to be the address of the local redir variable. */ | | 567 | /* rpp to be the address of the local redir variable. */ |
569 | if (redir == 0) | | 568 | if (redir == 0) |
570 | rpp = &redir; | | 569 | rpp = &redir; |
571 | | | 570 | |
572 | args = NULL; | | 571 | args = NULL; |
573 | app = &args; | | 572 | app = &args; |
574 | /* | | | |
575 | * We save the incoming value, because we need this for shell | | | |
576 | * functions. There can not be a redirect or an argument between | | | |
577 | * the function name and the open parenthesis. | | | |
578 | */ | | | |
579 | orig_rpp = rpp; | | | |
580 | | | 573 | |
581 | while (readtoken() == TNOT) { | | 574 | while (readtoken() == TNOT) { |
582 | TRACE(("simplcmd: TNOT recognized\n")); | | 575 | TRACE(("simplcmd: TNOT recognized\n")); |
583 | negate = !negate; | | 576 | negate = !negate; |
584 | } | | 577 | } |
585 | tokpushback++; | | 578 | tokpushback++; |
586 | | | 579 | |
587 | for (;;) { | | 580 | for (;;) { |
588 | if (readtoken() == TWORD) { | | 581 | if (readtoken() == TWORD) { |
589 | n = stalloc(sizeof(struct narg)); | | 582 | n = stalloc(sizeof(struct narg)); |
590 | n->type = NARG; | | 583 | n->type = NARG; |
591 | n->narg.text = wordtext; | | 584 | n->narg.text = wordtext; |
592 | n->narg.backquote = backquotelist; | | 585 | n->narg.backquote = backquotelist; |
593 | *app = n; | | 586 | *app = n; |
594 | app = &n->narg.next; | | 587 | app = &n->narg.next; |
595 | } else if (lasttoken == TREDIR) { | | 588 | } else if (lasttoken == TREDIR) { |
596 | *rpp = n = redirnode; | | 589 | *rpp = n = redirnode; |
597 | rpp = &n->nfile.next; | | 590 | rpp = &n->nfile.next; |
598 | parsefname(); /* read name of redirection file */ | | 591 | parsefname(); /* read name of redirection file */ |
599 | } else if (lasttoken == TLP && app == &args->narg.next | | 592 | } else if (lasttoken == TLP && app == &args->narg.next |
600 | && rpp == orig_rpp) { | | 593 | && redir == 0) { |
601 | /* We have a function */ | | 594 | /* We have a function */ |
602 | if (readtoken() != TRP) | | 595 | if (readtoken() != TRP) |
603 | synexpect(TRP, 0); | | 596 | synexpect(TRP, 0); |
604 | funclinno = plinno; | | 597 | funclinno = plinno; |
605 | rmescapes(n->narg.text); | | 598 | rmescapes(n->narg.text); |
606 | if (!goodname(n->narg.text)) | | 599 | if (!goodname(n->narg.text)) |
607 | synerror("Bad function name"); | | 600 | synerror("Bad function name"); |
608 | n->type = NDEFUN; | | 601 | n->type = NDEFUN; |
609 | n->narg.next = command(); | | 602 | n->narg.next = command(); |
610 | funclinno = 0; | | 603 | funclinno = 0; |
611 | goto checkneg; | | 604 | goto checkneg; |
612 | } else { | | 605 | } else { |
613 | tokpushback++; | | 606 | tokpushback++; |