diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-24 06:07:50 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-24 06:07:50 +0000 |
commit | 2dc240c0d6e0b3b0b66f08ac9cc5584df824f959 (patch) | |
tree | b5c18187a3b9121c8bfb3a655ad950fba9900b73 /shell | |
parent | 49a5eba9ae7d560bbbbdc677712091acee4f426c (diff) | |
download | busybox-w32-2dc240c0d6e0b3b0b66f08ac9cc5584df824f959.tar.gz busybox-w32-2dc240c0d6e0b3b0b66f08ac9cc5584df824f959.tar.bz2 busybox-w32-2dc240c0d6e0b3b0b66f08ac9cc5584df824f959.zip |
ash: code shrink
function old new delta
copynode 171 180 +9
evaltreenr 615 621 +6
evaltree 615 621 +6
calcsize 121 127 +6
evalpipe 349 350 +1
redirect 1059 1057 -2
parseheredoc 129 126 -3
makename 35 32 -3
expredir 130 127 -3
parsefname 224 219 -5
popstring 140 134 -6
pipeline 276 268 -8
list 360 351 -9
readtoken1 3157 3130 -27
parse_command 1504 1460 -44
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/10 up/down: 28/-110) Total: -82 bytes
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 68 |
1 files changed, 33 insertions, 35 deletions
diff --git a/shell/ash.c b/shell/ash.c index 637ba0128..4263644fc 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -526,66 +526,66 @@ static const char dolatstr[] ALIGN1 = { | |||
526 | union node; | 526 | union node; |
527 | 527 | ||
528 | struct ncmd { | 528 | struct ncmd { |
529 | int type; | 529 | smallint type; /* Nxxxx */ |
530 | union node *assign; | 530 | union node *assign; |
531 | union node *args; | 531 | union node *args; |
532 | union node *redirect; | 532 | union node *redirect; |
533 | }; | 533 | }; |
534 | 534 | ||
535 | struct npipe { | 535 | struct npipe { |
536 | int type; | 536 | smallint type; |
537 | int backgnd; | 537 | smallint pipe_backgnd; |
538 | struct nodelist *cmdlist; | 538 | struct nodelist *cmdlist; |
539 | }; | 539 | }; |
540 | 540 | ||
541 | struct nredir { | 541 | struct nredir { |
542 | int type; | 542 | smallint type; |
543 | union node *n; | 543 | union node *n; |
544 | union node *redirect; | 544 | union node *redirect; |
545 | }; | 545 | }; |
546 | 546 | ||
547 | struct nbinary { | 547 | struct nbinary { |
548 | int type; | 548 | smallint type; |
549 | union node *ch1; | 549 | union node *ch1; |
550 | union node *ch2; | 550 | union node *ch2; |
551 | }; | 551 | }; |
552 | 552 | ||
553 | struct nif { | 553 | struct nif { |
554 | int type; | 554 | smallint type; |
555 | union node *test; | 555 | union node *test; |
556 | union node *ifpart; | 556 | union node *ifpart; |
557 | union node *elsepart; | 557 | union node *elsepart; |
558 | }; | 558 | }; |
559 | 559 | ||
560 | struct nfor { | 560 | struct nfor { |
561 | int type; | 561 | smallint type; |
562 | union node *args; | 562 | union node *args; |
563 | union node *body; | 563 | union node *body; |
564 | char *var; | 564 | char *var; |
565 | }; | 565 | }; |
566 | 566 | ||
567 | struct ncase { | 567 | struct ncase { |
568 | int type; | 568 | smallint type; |
569 | union node *expr; | 569 | union node *expr; |
570 | union node *cases; | 570 | union node *cases; |
571 | }; | 571 | }; |
572 | 572 | ||
573 | struct nclist { | 573 | struct nclist { |
574 | int type; | 574 | smallint type; |
575 | union node *next; | 575 | union node *next; |
576 | union node *pattern; | 576 | union node *pattern; |
577 | union node *body; | 577 | union node *body; |
578 | }; | 578 | }; |
579 | 579 | ||
580 | struct narg { | 580 | struct narg { |
581 | int type; | 581 | smallint type; |
582 | union node *next; | 582 | union node *next; |
583 | char *text; | 583 | char *text; |
584 | struct nodelist *backquote; | 584 | struct nodelist *backquote; |
585 | }; | 585 | }; |
586 | 586 | ||
587 | struct nfile { | 587 | struct nfile { |
588 | int type; | 588 | smallint type; |
589 | union node *next; | 589 | union node *next; |
590 | int fd; | 590 | int fd; |
591 | union node *fname; | 591 | union node *fname; |
@@ -593,7 +593,7 @@ struct nfile { | |||
593 | }; | 593 | }; |
594 | 594 | ||
595 | struct ndup { | 595 | struct ndup { |
596 | int type; | 596 | smallint type; |
597 | union node *next; | 597 | union node *next; |
598 | int fd; | 598 | int fd; |
599 | int dupfd; | 599 | int dupfd; |
@@ -601,19 +601,19 @@ struct ndup { | |||
601 | }; | 601 | }; |
602 | 602 | ||
603 | struct nhere { | 603 | struct nhere { |
604 | int type; | 604 | smallint type; |
605 | union node *next; | 605 | union node *next; |
606 | int fd; | 606 | int fd; |
607 | union node *doc; | 607 | union node *doc; |
608 | }; | 608 | }; |
609 | 609 | ||
610 | struct nnot { | 610 | struct nnot { |
611 | int type; | 611 | smallint type; |
612 | union node *com; | 612 | union node *com; |
613 | }; | 613 | }; |
614 | 614 | ||
615 | union node { | 615 | union node { |
616 | int type; | 616 | smallint type; |
617 | struct ncmd ncmd; | 617 | struct ncmd ncmd; |
618 | struct npipe npipe; | 618 | struct npipe npipe; |
619 | struct nredir nredir; | 619 | struct nredir nredir; |
@@ -954,7 +954,7 @@ shtree(union node *n, int ind, char *pfx, FILE *fp) | |||
954 | if (lp->next) | 954 | if (lp->next) |
955 | fputs(" | ", fp); | 955 | fputs(" | ", fp); |
956 | } | 956 | } |
957 | if (n->npipe.backgnd) | 957 | if (n->npipe.pipe_backgnd) |
958 | fputs(" &", fp); | 958 | fputs(" &", fp); |
959 | if (ind >= 0) | 959 | if (ind >= 0) |
960 | putc('\n', fp); | 960 | putc('\n', fp); |
@@ -4899,7 +4899,6 @@ dupredirect(union node *redir, int f) | |||
4899 | static void | 4899 | static void |
4900 | redirect(union node *redir, int flags) | 4900 | redirect(union node *redir, int flags) |
4901 | { | 4901 | { |
4902 | union node *n; | ||
4903 | struct redirtab *sv; | 4902 | struct redirtab *sv; |
4904 | int i; | 4903 | int i; |
4905 | int fd; | 4904 | int fd; |
@@ -4920,14 +4919,13 @@ redirect(union node *redir, int flags) | |||
4920 | sv->renamed[i] = EMPTY; | 4919 | sv->renamed[i] = EMPTY; |
4921 | g_nullredirs = 0; | 4920 | g_nullredirs = 0; |
4922 | } | 4921 | } |
4923 | n = redir; | ||
4924 | do { | 4922 | do { |
4925 | fd = n->nfile.fd; | 4923 | fd = redir->nfile.fd; |
4926 | if ((n->nfile.type == NTOFD || n->nfile.type == NFROMFD) | 4924 | if ((redir->nfile.type == NTOFD || redir->nfile.type == NFROMFD) |
4927 | && n->ndup.dupfd == fd) | 4925 | && redir->ndup.dupfd == fd) |
4928 | continue; /* redirect from/to same file descriptor */ | 4926 | continue; /* redirect from/to same file descriptor */ |
4929 | 4927 | ||
4930 | newfd = openredirect(n); | 4928 | newfd = openredirect(redir); |
4931 | if (fd == newfd) { | 4929 | if (fd == newfd) { |
4932 | /* Descriptor wasn't open before redirect. | 4930 | /* Descriptor wasn't open before redirect. |
4933 | * Mark it for close in the future */ | 4931 | * Mark it for close in the future */ |
@@ -4953,8 +4951,8 @@ redirect(union node *redir, int flags) | |||
4953 | } else { | 4951 | } else { |
4954 | close(fd); | 4952 | close(fd); |
4955 | } | 4953 | } |
4956 | dupredirect(n, newfd); | 4954 | dupredirect(redir, newfd); |
4957 | } while ((n = n->nfile.next)); | 4955 | } while ((redir = redir->nfile.next) != NULL); |
4958 | INT_ON; | 4956 | INT_ON; |
4959 | if ((flags & REDIR_SAVEFD2) && sv && sv->renamed[2] >= 0) | 4957 | if ((flags & REDIR_SAVEFD2) && sv && sv->renamed[2] >= 0) |
4960 | preverrout_fd = sv->renamed[2]; | 4958 | preverrout_fd = sv->renamed[2]; |
@@ -6572,7 +6570,7 @@ expmeta(char *enddir, char *name) | |||
6572 | if (*p == '.') | 6570 | if (*p == '.') |
6573 | matchdot++; | 6571 | matchdot++; |
6574 | while (!intpending && (dp = readdir(dirp)) != NULL) { | 6572 | while (!intpending && (dp = readdir(dirp)) != NULL) { |
6575 | if (dp->d_name[0] == '.' && ! matchdot) | 6573 | if (dp->d_name[0] == '.' && !matchdot) |
6576 | continue; | 6574 | continue; |
6577 | if (pmatch(start, dp->d_name)) { | 6575 | if (pmatch(start, dp->d_name)) { |
6578 | if (atend) { | 6576 | if (atend) { |
@@ -6587,7 +6585,7 @@ expmeta(char *enddir, char *name) | |||
6587 | } | 6585 | } |
6588 | } | 6586 | } |
6589 | closedir(dirp); | 6587 | closedir(dirp); |
6590 | if (! atend) | 6588 | if (!atend) |
6591 | endname[-1] = '/'; | 6589 | endname[-1] = '/'; |
6592 | } | 6590 | } |
6593 | 6591 | ||
@@ -7620,7 +7618,7 @@ copynode(union node *n) | |||
7620 | break; | 7618 | break; |
7621 | case NPIPE: | 7619 | case NPIPE: |
7622 | new->npipe.cmdlist = copynodelist(n->npipe.cmdlist); | 7620 | new->npipe.cmdlist = copynodelist(n->npipe.cmdlist); |
7623 | new->npipe.backgnd = n->npipe.backgnd; | 7621 | new->npipe.pipe_backgnd = n->npipe.pipe_backgnd; |
7624 | break; | 7622 | break; |
7625 | case NREDIR: | 7623 | case NREDIR: |
7626 | case NBACKGND: | 7624 | case NBACKGND: |
@@ -8037,7 +8035,7 @@ evalsubshell(union node *n, int flags) | |||
8037 | /* never returns */ | 8035 | /* never returns */ |
8038 | } | 8036 | } |
8039 | status = 0; | 8037 | status = 0; |
8040 | if (! backgnd) | 8038 | if (!backgnd) |
8041 | status = waitforjob(jp); | 8039 | status = waitforjob(jp); |
8042 | exitstatus = status; | 8040 | exitstatus = status; |
8043 | INT_ON; | 8041 | INT_ON; |
@@ -8111,7 +8109,7 @@ evalpipe(union node *n, int flags) | |||
8111 | ash_msg_and_raise_error("pipe call failed"); | 8109 | ash_msg_and_raise_error("pipe call failed"); |
8112 | } | 8110 | } |
8113 | } | 8111 | } |
8114 | if (forkshell(jp, lp->n, n->npipe.backgnd) == 0) { | 8112 | if (forkshell(jp, lp->n, n->npipe.pipe_backgnd) == 0) { |
8115 | INT_ON; | 8113 | INT_ON; |
8116 | if (pip[1] >= 0) { | 8114 | if (pip[1] >= 0) { |
8117 | close(pip[0]); | 8115 | close(pip[0]); |
@@ -8132,7 +8130,7 @@ evalpipe(union node *n, int flags) | |||
8132 | prevfd = pip[0]; | 8130 | prevfd = pip[0]; |
8133 | close(pip[1]); | 8131 | close(pip[1]); |
8134 | } | 8132 | } |
8135 | if (n->npipe.backgnd == 0) { | 8133 | if (n->npipe.pipe_backgnd == 0) { |
8136 | exitstatus = waitforjob(jp); | 8134 | exitstatus = waitforjob(jp); |
8137 | TRACE(("evalpipe: job done exit status %d\n", exitstatus)); | 8135 | TRACE(("evalpipe: job done exit status %d\n", exitstatus)); |
8138 | } | 8136 | } |
@@ -9861,7 +9859,7 @@ list(int nlflag) | |||
9861 | tok = readtoken(); | 9859 | tok = readtoken(); |
9862 | if (tok == TBACKGND) { | 9860 | if (tok == TBACKGND) { |
9863 | if (n2->type == NPIPE) { | 9861 | if (n2->type == NPIPE) { |
9864 | n2->npipe.backgnd = 1; | 9862 | n2->npipe.pipe_backgnd = 1; |
9865 | } else { | 9863 | } else { |
9866 | if (n2->type != NREDIR) { | 9864 | if (n2->type != NREDIR) { |
9867 | n3 = stzalloc(sizeof(struct nredir)); | 9865 | n3 = stzalloc(sizeof(struct nredir)); |
@@ -9958,7 +9956,7 @@ pipeline(void) | |||
9958 | if (readtoken() == TPIPE) { | 9956 | if (readtoken() == TPIPE) { |
9959 | pipenode = stzalloc(sizeof(struct npipe)); | 9957 | pipenode = stzalloc(sizeof(struct npipe)); |
9960 | pipenode->type = NPIPE; | 9958 | pipenode->type = NPIPE; |
9961 | /*pipenode->npipe.backgnd = 0; - stzalloc did it */ | 9959 | /*pipenode->npipe.pipe_backgnd = 0; - stzalloc did it */ |
9962 | lp = stzalloc(sizeof(struct nodelist)); | 9960 | lp = stzalloc(sizeof(struct nodelist)); |
9963 | pipenode->npipe.cmdlist = lp; | 9961 | pipenode->npipe.cmdlist = lp; |
9964 | lp->n = n1; | 9962 | lp->n = n1; |
@@ -10227,7 +10225,7 @@ parse_command(void) | |||
10227 | break; | 10225 | break; |
10228 | } | 10226 | } |
10229 | case TFOR: | 10227 | case TFOR: |
10230 | if (readtoken() != TWORD || quoteflag || ! goodname(wordtext)) | 10228 | if (readtoken() != TWORD || quoteflag || !goodname(wordtext)) |
10231 | raise_error_syntax("Bad for loop variable"); | 10229 | raise_error_syntax("Bad for loop variable"); |
10232 | n1 = stzalloc(sizeof(struct nfor)); | 10230 | n1 = stzalloc(sizeof(struct nfor)); |
10233 | n1->type = NFOR; | 10231 | n1->type = NFOR; |
@@ -12854,7 +12852,7 @@ arith_apply(operator op, v_n_t *numstack, v_n_t **numstackptr) | |||
12854 | --NUMPTR; | 12852 | --NUMPTR; |
12855 | numptr_val = rez; | 12853 | numptr_val = rez; |
12856 | if (op == TOK_CONDITIONAL) { | 12854 | if (op == TOK_CONDITIONAL) { |
12857 | if (! numptr_m1->contidional_second_val_initialized) { | 12855 | if (!numptr_m1->contidional_second_val_initialized) { |
12858 | /* protect $((expr1 ? expr2)) without ": expr" */ | 12856 | /* protect $((expr1 ? expr2)) without ": expr" */ |
12859 | goto err; | 12857 | goto err; |
12860 | } | 12858 | } |
@@ -13106,7 +13104,7 @@ arith(const char *expr, int *perrcode) | |||
13106 | } | 13104 | } |
13107 | for (o = expr; *p && *o == *p; p++) | 13105 | for (o = expr; *p && *o == *p; p++) |
13108 | o++; | 13106 | o++; |
13109 | if (! *p) { | 13107 | if (!*p) { |
13110 | /* found */ | 13108 | /* found */ |
13111 | expr = o - 1; | 13109 | expr = o - 1; |
13112 | break; | 13110 | break; |