mirror of
https://github.com/sheumann/hush.git
synced 2024-10-11 10:23:41 +00:00
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
This commit is contained in:
parent
49a5eba9ae
commit
2dc240c0d6
56
shell/ash.c
56
shell/ash.c
@ -526,66 +526,66 @@ static const char dolatstr[] ALIGN1 = {
|
|||||||
union node;
|
union node;
|
||||||
|
|
||||||
struct ncmd {
|
struct ncmd {
|
||||||
int type;
|
smallint type; /* Nxxxx */
|
||||||
union node *assign;
|
union node *assign;
|
||||||
union node *args;
|
union node *args;
|
||||||
union node *redirect;
|
union node *redirect;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct npipe {
|
struct npipe {
|
||||||
int type;
|
smallint type;
|
||||||
int backgnd;
|
smallint pipe_backgnd;
|
||||||
struct nodelist *cmdlist;
|
struct nodelist *cmdlist;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct nredir {
|
struct nredir {
|
||||||
int type;
|
smallint type;
|
||||||
union node *n;
|
union node *n;
|
||||||
union node *redirect;
|
union node *redirect;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct nbinary {
|
struct nbinary {
|
||||||
int type;
|
smallint type;
|
||||||
union node *ch1;
|
union node *ch1;
|
||||||
union node *ch2;
|
union node *ch2;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct nif {
|
struct nif {
|
||||||
int type;
|
smallint type;
|
||||||
union node *test;
|
union node *test;
|
||||||
union node *ifpart;
|
union node *ifpart;
|
||||||
union node *elsepart;
|
union node *elsepart;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct nfor {
|
struct nfor {
|
||||||
int type;
|
smallint type;
|
||||||
union node *args;
|
union node *args;
|
||||||
union node *body;
|
union node *body;
|
||||||
char *var;
|
char *var;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ncase {
|
struct ncase {
|
||||||
int type;
|
smallint type;
|
||||||
union node *expr;
|
union node *expr;
|
||||||
union node *cases;
|
union node *cases;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct nclist {
|
struct nclist {
|
||||||
int type;
|
smallint type;
|
||||||
union node *next;
|
union node *next;
|
||||||
union node *pattern;
|
union node *pattern;
|
||||||
union node *body;
|
union node *body;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct narg {
|
struct narg {
|
||||||
int type;
|
smallint type;
|
||||||
union node *next;
|
union node *next;
|
||||||
char *text;
|
char *text;
|
||||||
struct nodelist *backquote;
|
struct nodelist *backquote;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct nfile {
|
struct nfile {
|
||||||
int type;
|
smallint type;
|
||||||
union node *next;
|
union node *next;
|
||||||
int fd;
|
int fd;
|
||||||
union node *fname;
|
union node *fname;
|
||||||
@ -593,7 +593,7 @@ struct nfile {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct ndup {
|
struct ndup {
|
||||||
int type;
|
smallint type;
|
||||||
union node *next;
|
union node *next;
|
||||||
int fd;
|
int fd;
|
||||||
int dupfd;
|
int dupfd;
|
||||||
@ -601,19 +601,19 @@ struct ndup {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct nhere {
|
struct nhere {
|
||||||
int type;
|
smallint type;
|
||||||
union node *next;
|
union node *next;
|
||||||
int fd;
|
int fd;
|
||||||
union node *doc;
|
union node *doc;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct nnot {
|
struct nnot {
|
||||||
int type;
|
smallint type;
|
||||||
union node *com;
|
union node *com;
|
||||||
};
|
};
|
||||||
|
|
||||||
union node {
|
union node {
|
||||||
int type;
|
smallint type;
|
||||||
struct ncmd ncmd;
|
struct ncmd ncmd;
|
||||||
struct npipe npipe;
|
struct npipe npipe;
|
||||||
struct nredir nredir;
|
struct nredir nredir;
|
||||||
@ -954,7 +954,7 @@ shtree(union node *n, int ind, char *pfx, FILE *fp)
|
|||||||
if (lp->next)
|
if (lp->next)
|
||||||
fputs(" | ", fp);
|
fputs(" | ", fp);
|
||||||
}
|
}
|
||||||
if (n->npipe.backgnd)
|
if (n->npipe.pipe_backgnd)
|
||||||
fputs(" &", fp);
|
fputs(" &", fp);
|
||||||
if (ind >= 0)
|
if (ind >= 0)
|
||||||
putc('\n', fp);
|
putc('\n', fp);
|
||||||
@ -4899,7 +4899,6 @@ dupredirect(union node *redir, int f)
|
|||||||
static void
|
static void
|
||||||
redirect(union node *redir, int flags)
|
redirect(union node *redir, int flags)
|
||||||
{
|
{
|
||||||
union node *n;
|
|
||||||
struct redirtab *sv;
|
struct redirtab *sv;
|
||||||
int i;
|
int i;
|
||||||
int fd;
|
int fd;
|
||||||
@ -4920,14 +4919,13 @@ redirect(union node *redir, int flags)
|
|||||||
sv->renamed[i] = EMPTY;
|
sv->renamed[i] = EMPTY;
|
||||||
g_nullredirs = 0;
|
g_nullredirs = 0;
|
||||||
}
|
}
|
||||||
n = redir;
|
|
||||||
do {
|
do {
|
||||||
fd = n->nfile.fd;
|
fd = redir->nfile.fd;
|
||||||
if ((n->nfile.type == NTOFD || n->nfile.type == NFROMFD)
|
if ((redir->nfile.type == NTOFD || redir->nfile.type == NFROMFD)
|
||||||
&& n->ndup.dupfd == fd)
|
&& redir->ndup.dupfd == fd)
|
||||||
continue; /* redirect from/to same file descriptor */
|
continue; /* redirect from/to same file descriptor */
|
||||||
|
|
||||||
newfd = openredirect(n);
|
newfd = openredirect(redir);
|
||||||
if (fd == newfd) {
|
if (fd == newfd) {
|
||||||
/* Descriptor wasn't open before redirect.
|
/* Descriptor wasn't open before redirect.
|
||||||
* Mark it for close in the future */
|
* Mark it for close in the future */
|
||||||
@ -4953,8 +4951,8 @@ redirect(union node *redir, int flags)
|
|||||||
} else {
|
} else {
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
dupredirect(n, newfd);
|
dupredirect(redir, newfd);
|
||||||
} while ((n = n->nfile.next));
|
} while ((redir = redir->nfile.next) != NULL);
|
||||||
INT_ON;
|
INT_ON;
|
||||||
if ((flags & REDIR_SAVEFD2) && sv && sv->renamed[2] >= 0)
|
if ((flags & REDIR_SAVEFD2) && sv && sv->renamed[2] >= 0)
|
||||||
preverrout_fd = sv->renamed[2];
|
preverrout_fd = sv->renamed[2];
|
||||||
@ -7620,7 +7618,7 @@ copynode(union node *n)
|
|||||||
break;
|
break;
|
||||||
case NPIPE:
|
case NPIPE:
|
||||||
new->npipe.cmdlist = copynodelist(n->npipe.cmdlist);
|
new->npipe.cmdlist = copynodelist(n->npipe.cmdlist);
|
||||||
new->npipe.backgnd = n->npipe.backgnd;
|
new->npipe.pipe_backgnd = n->npipe.pipe_backgnd;
|
||||||
break;
|
break;
|
||||||
case NREDIR:
|
case NREDIR:
|
||||||
case NBACKGND:
|
case NBACKGND:
|
||||||
@ -8111,7 +8109,7 @@ evalpipe(union node *n, int flags)
|
|||||||
ash_msg_and_raise_error("pipe call failed");
|
ash_msg_and_raise_error("pipe call failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (forkshell(jp, lp->n, n->npipe.backgnd) == 0) {
|
if (forkshell(jp, lp->n, n->npipe.pipe_backgnd) == 0) {
|
||||||
INT_ON;
|
INT_ON;
|
||||||
if (pip[1] >= 0) {
|
if (pip[1] >= 0) {
|
||||||
close(pip[0]);
|
close(pip[0]);
|
||||||
@ -8132,7 +8130,7 @@ evalpipe(union node *n, int flags)
|
|||||||
prevfd = pip[0];
|
prevfd = pip[0];
|
||||||
close(pip[1]);
|
close(pip[1]);
|
||||||
}
|
}
|
||||||
if (n->npipe.backgnd == 0) {
|
if (n->npipe.pipe_backgnd == 0) {
|
||||||
exitstatus = waitforjob(jp);
|
exitstatus = waitforjob(jp);
|
||||||
TRACE(("evalpipe: job done exit status %d\n", exitstatus));
|
TRACE(("evalpipe: job done exit status %d\n", exitstatus));
|
||||||
}
|
}
|
||||||
@ -9861,7 +9859,7 @@ list(int nlflag)
|
|||||||
tok = readtoken();
|
tok = readtoken();
|
||||||
if (tok == TBACKGND) {
|
if (tok == TBACKGND) {
|
||||||
if (n2->type == NPIPE) {
|
if (n2->type == NPIPE) {
|
||||||
n2->npipe.backgnd = 1;
|
n2->npipe.pipe_backgnd = 1;
|
||||||
} else {
|
} else {
|
||||||
if (n2->type != NREDIR) {
|
if (n2->type != NREDIR) {
|
||||||
n3 = stzalloc(sizeof(struct nredir));
|
n3 = stzalloc(sizeof(struct nredir));
|
||||||
@ -9958,7 +9956,7 @@ pipeline(void)
|
|||||||
if (readtoken() == TPIPE) {
|
if (readtoken() == TPIPE) {
|
||||||
pipenode = stzalloc(sizeof(struct npipe));
|
pipenode = stzalloc(sizeof(struct npipe));
|
||||||
pipenode->type = NPIPE;
|
pipenode->type = NPIPE;
|
||||||
/*pipenode->npipe.backgnd = 0; - stzalloc did it */
|
/*pipenode->npipe.pipe_backgnd = 0; - stzalloc did it */
|
||||||
lp = stzalloc(sizeof(struct nodelist));
|
lp = stzalloc(sizeof(struct nodelist));
|
||||||
pipenode->npipe.cmdlist = lp;
|
pipenode->npipe.cmdlist = lp;
|
||||||
lp->n = n1;
|
lp->n = n1;
|
||||||
|
Loading…
Reference in New Issue
Block a user