diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-02-18 12:35:30 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-02-18 12:35:30 +0000 |
commit | d0733749a1e107891d7ac9fb62e8306c1bacb8ac (patch) | |
tree | 500374528bf6c99bd7b225aca561c968dc86ac9e /shell | |
parent | f44ad31a7eb5531395671a46eac0f9245ed4b23a (diff) | |
download | busybox-w32-d0733749a1e107891d7ac9fb62e8306c1bacb8ac.tar.gz busybox-w32-d0733749a1e107891d7ac9fb62e8306c1bacb8ac.tar.bz2 busybox-w32-d0733749a1e107891d7ac9fb62e8306c1bacb8ac.zip |
ash: fix indentation and style. no code changes
git-svn-id: svn://busybox.net/trunk/busybox@17921 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 1192 |
1 files changed, 593 insertions, 599 deletions
diff --git a/shell/ash.c b/shell/ash.c index bfaf04ffd..a4ce3ffcd 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -342,120 +342,120 @@ struct backcmd { /* result of evalbackcmd */ | |||
342 | 342 | ||
343 | 343 | ||
344 | struct ncmd { | 344 | struct ncmd { |
345 | int type; | 345 | int type; |
346 | union node *assign; | 346 | union node *assign; |
347 | union node *args; | 347 | union node *args; |
348 | union node *redirect; | 348 | union node *redirect; |
349 | }; | 349 | }; |
350 | 350 | ||
351 | 351 | ||
352 | struct npipe { | 352 | struct npipe { |
353 | int type; | 353 | int type; |
354 | int backgnd; | 354 | int backgnd; |
355 | struct nodelist *cmdlist; | 355 | struct nodelist *cmdlist; |
356 | }; | 356 | }; |
357 | 357 | ||
358 | 358 | ||
359 | struct nredir { | 359 | struct nredir { |
360 | int type; | 360 | int type; |
361 | union node *n; | 361 | union node *n; |
362 | union node *redirect; | 362 | union node *redirect; |
363 | }; | 363 | }; |
364 | 364 | ||
365 | 365 | ||
366 | struct nbinary { | 366 | struct nbinary { |
367 | int type; | 367 | int type; |
368 | union node *ch1; | 368 | union node *ch1; |
369 | union node *ch2; | 369 | union node *ch2; |
370 | }; | 370 | }; |
371 | 371 | ||
372 | 372 | ||
373 | struct nif { | 373 | struct nif { |
374 | int type; | 374 | int type; |
375 | union node *test; | 375 | union node *test; |
376 | union node *ifpart; | 376 | union node *ifpart; |
377 | union node *elsepart; | 377 | union node *elsepart; |
378 | }; | 378 | }; |
379 | 379 | ||
380 | 380 | ||
381 | struct nfor { | 381 | struct nfor { |
382 | int type; | 382 | int type; |
383 | union node *args; | 383 | union node *args; |
384 | union node *body; | 384 | union node *body; |
385 | char *var; | 385 | char *var; |
386 | }; | 386 | }; |
387 | 387 | ||
388 | 388 | ||
389 | struct ncase { | 389 | struct ncase { |
390 | int type; | 390 | int type; |
391 | union node *expr; | 391 | union node *expr; |
392 | union node *cases; | 392 | union node *cases; |
393 | }; | 393 | }; |
394 | 394 | ||
395 | 395 | ||
396 | struct nclist { | 396 | struct nclist { |
397 | int type; | 397 | int type; |
398 | union node *next; | 398 | union node *next; |
399 | union node *pattern; | 399 | union node *pattern; |
400 | union node *body; | 400 | union node *body; |
401 | }; | 401 | }; |
402 | 402 | ||
403 | 403 | ||
404 | struct narg { | 404 | struct narg { |
405 | int type; | 405 | int type; |
406 | union node *next; | 406 | union node *next; |
407 | char *text; | 407 | char *text; |
408 | struct nodelist *backquote; | 408 | struct nodelist *backquote; |
409 | }; | 409 | }; |
410 | 410 | ||
411 | 411 | ||
412 | struct nfile { | 412 | struct nfile { |
413 | int type; | 413 | int type; |
414 | union node *next; | 414 | union node *next; |
415 | int fd; | 415 | int fd; |
416 | union node *fname; | 416 | union node *fname; |
417 | char *expfname; | 417 | char *expfname; |
418 | }; | 418 | }; |
419 | 419 | ||
420 | 420 | ||
421 | struct ndup { | 421 | struct ndup { |
422 | int type; | 422 | int type; |
423 | union node *next; | 423 | union node *next; |
424 | int fd; | 424 | int fd; |
425 | int dupfd; | 425 | int dupfd; |
426 | union node *vname; | 426 | union node *vname; |
427 | }; | 427 | }; |
428 | 428 | ||
429 | 429 | ||
430 | struct nhere { | 430 | struct nhere { |
431 | int type; | 431 | int type; |
432 | union node *next; | 432 | union node *next; |
433 | int fd; | 433 | int fd; |
434 | union node *doc; | 434 | union node *doc; |
435 | }; | 435 | }; |
436 | 436 | ||
437 | 437 | ||
438 | struct nnot { | 438 | struct nnot { |
439 | int type; | 439 | int type; |
440 | union node *com; | 440 | union node *com; |
441 | }; | 441 | }; |
442 | 442 | ||
443 | 443 | ||
444 | union node { | 444 | union node { |
445 | int type; | 445 | int type; |
446 | struct ncmd ncmd; | 446 | struct ncmd ncmd; |
447 | struct npipe npipe; | 447 | struct npipe npipe; |
448 | struct nredir nredir; | 448 | struct nredir nredir; |
449 | struct nbinary nbinary; | 449 | struct nbinary nbinary; |
450 | struct nif nif; | 450 | struct nif nif; |
451 | struct nfor nfor; | 451 | struct nfor nfor; |
452 | struct ncase ncase; | 452 | struct ncase ncase; |
453 | struct nclist nclist; | 453 | struct nclist nclist; |
454 | struct narg narg; | 454 | struct narg narg; |
455 | struct nfile nfile; | 455 | struct nfile nfile; |
456 | struct ndup ndup; | 456 | struct ndup ndup; |
457 | struct nhere nhere; | 457 | struct nhere nhere; |
458 | struct nnot nnot; | 458 | struct nnot nnot; |
459 | }; | 459 | }; |
460 | 460 | ||
461 | 461 | ||
@@ -732,7 +732,7 @@ static const char *tokname(int tok) | |||
732 | * (assuming ascii char codes, as the original implementation did) | 732 | * (assuming ascii char codes, as the original implementation did) |
733 | */ | 733 | */ |
734 | #define is_special(c) \ | 734 | #define is_special(c) \ |
735 | ( (((unsigned int)c) - 33 < 32) \ | 735 | ( (((unsigned int)c) - 33 < 32) \ |
736 | && ((0xc1ff920dUL >> (((unsigned int)c) - 33)) & 1)) | 736 | && ((0xc1ff920dUL >> (((unsigned int)c) - 33)) & 1)) |
737 | 737 | ||
738 | #define digit_val(c) ((c) - '0') | 738 | #define digit_val(c) ((c) - '0') |
@@ -1154,32 +1154,32 @@ static pointer funcblock; /* block to allocate function from */ | |||
1154 | static char *funcstring; /* block to allocate strings from */ | 1154 | static char *funcstring; /* block to allocate strings from */ |
1155 | 1155 | ||
1156 | static const short nodesize[26] = { | 1156 | static const short nodesize[26] = { |
1157 | SHELL_ALIGN(sizeof (struct ncmd)), | 1157 | SHELL_ALIGN(sizeof(struct ncmd)), |
1158 | SHELL_ALIGN(sizeof (struct npipe)), | 1158 | SHELL_ALIGN(sizeof(struct npipe)), |
1159 | SHELL_ALIGN(sizeof (struct nredir)), | 1159 | SHELL_ALIGN(sizeof(struct nredir)), |
1160 | SHELL_ALIGN(sizeof (struct nredir)), | 1160 | SHELL_ALIGN(sizeof(struct nredir)), |
1161 | SHELL_ALIGN(sizeof (struct nredir)), | 1161 | SHELL_ALIGN(sizeof(struct nredir)), |
1162 | SHELL_ALIGN(sizeof (struct nbinary)), | 1162 | SHELL_ALIGN(sizeof(struct nbinary)), |
1163 | SHELL_ALIGN(sizeof (struct nbinary)), | 1163 | SHELL_ALIGN(sizeof(struct nbinary)), |
1164 | SHELL_ALIGN(sizeof (struct nbinary)), | 1164 | SHELL_ALIGN(sizeof(struct nbinary)), |
1165 | SHELL_ALIGN(sizeof (struct nif)), | 1165 | SHELL_ALIGN(sizeof(struct nif)), |
1166 | SHELL_ALIGN(sizeof (struct nbinary)), | 1166 | SHELL_ALIGN(sizeof(struct nbinary)), |
1167 | SHELL_ALIGN(sizeof (struct nbinary)), | 1167 | SHELL_ALIGN(sizeof(struct nbinary)), |
1168 | SHELL_ALIGN(sizeof (struct nfor)), | 1168 | SHELL_ALIGN(sizeof(struct nfor)), |
1169 | SHELL_ALIGN(sizeof (struct ncase)), | 1169 | SHELL_ALIGN(sizeof(struct ncase)), |
1170 | SHELL_ALIGN(sizeof (struct nclist)), | 1170 | SHELL_ALIGN(sizeof(struct nclist)), |
1171 | SHELL_ALIGN(sizeof (struct narg)), | 1171 | SHELL_ALIGN(sizeof(struct narg)), |
1172 | SHELL_ALIGN(sizeof (struct narg)), | 1172 | SHELL_ALIGN(sizeof(struct narg)), |
1173 | SHELL_ALIGN(sizeof (struct nfile)), | 1173 | SHELL_ALIGN(sizeof(struct nfile)), |
1174 | SHELL_ALIGN(sizeof (struct nfile)), | 1174 | SHELL_ALIGN(sizeof(struct nfile)), |
1175 | SHELL_ALIGN(sizeof (struct nfile)), | 1175 | SHELL_ALIGN(sizeof(struct nfile)), |
1176 | SHELL_ALIGN(sizeof (struct nfile)), | 1176 | SHELL_ALIGN(sizeof(struct nfile)), |
1177 | SHELL_ALIGN(sizeof (struct nfile)), | 1177 | SHELL_ALIGN(sizeof(struct nfile)), |
1178 | SHELL_ALIGN(sizeof (struct ndup)), | 1178 | SHELL_ALIGN(sizeof(struct ndup)), |
1179 | SHELL_ALIGN(sizeof (struct ndup)), | 1179 | SHELL_ALIGN(sizeof(struct ndup)), |
1180 | SHELL_ALIGN(sizeof (struct nhere)), | 1180 | SHELL_ALIGN(sizeof(struct nhere)), |
1181 | SHELL_ALIGN(sizeof (struct nhere)), | 1181 | SHELL_ALIGN(sizeof(struct nhere)), |
1182 | SHELL_ALIGN(sizeof (struct nnot)), | 1182 | SHELL_ALIGN(sizeof(struct nnot)), |
1183 | }; | 1183 | }; |
1184 | 1184 | ||
1185 | 1185 | ||
@@ -1402,8 +1402,7 @@ struct cmdentry { | |||
1402 | 1402 | ||
1403 | static const char *pathopt; /* set by padvance */ | 1403 | static const char *pathopt; /* set by padvance */ |
1404 | 1404 | ||
1405 | static void shellexec(char **, const char *, int) | 1405 | static void shellexec(char **, const char *, int) ATTRIBUTE_NORETURN; |
1406 | ATTRIBUTE_NORETURN; | ||
1407 | static char *padvance(const char **, const char *); | 1406 | static char *padvance(const char **, const char *); |
1408 | static void find_command(char *, struct cmdentry *, int, const char *); | 1407 | static void find_command(char *, struct cmdentry *, int, const char *); |
1409 | static struct builtincmd *find_builtin(const char *); | 1408 | static struct builtincmd *find_builtin(const char *); |
@@ -1619,9 +1618,9 @@ static void outcslow(int, FILE *); | |||
1619 | static void flushall(void); | 1618 | static void flushall(void); |
1620 | static void flusherr(void); | 1619 | static void flusherr(void); |
1621 | static int out1fmt(const char *, ...) | 1620 | static int out1fmt(const char *, ...) |
1622 | __attribute__((__format__(__printf__,1,2))); | 1621 | __attribute__((__format__(__printf__,1,2))); |
1623 | static int fmtstr(char *, size_t, const char *, ...) | 1622 | static int fmtstr(char *, size_t, const char *, ...) |
1624 | __attribute__((__format__(__printf__,3,4))); | 1623 | __attribute__((__format__(__printf__,3,4))); |
1625 | 1624 | ||
1626 | static int preverrout_fd; /* save fd2 before print debug if xflag is set. */ | 1625 | static int preverrout_fd; /* save fd2 before print debug if xflag is set. */ |
1627 | 1626 | ||
@@ -1672,40 +1671,40 @@ static void initvar(void) | |||
1672 | static void init(void) | 1671 | static void init(void) |
1673 | { | 1672 | { |
1674 | 1673 | ||
1675 | /* from input.c: */ | 1674 | /* from input.c: */ |
1676 | { | 1675 | { |
1677 | basepf.nextc = basepf.buf = basebuf; | 1676 | basepf.nextc = basepf.buf = basebuf; |
1678 | } | 1677 | } |
1679 | 1678 | ||
1680 | /* from trap.c: */ | 1679 | /* from trap.c: */ |
1681 | { | 1680 | { |
1682 | signal(SIGCHLD, SIG_DFL); | 1681 | signal(SIGCHLD, SIG_DFL); |
1683 | } | 1682 | } |
1684 | 1683 | ||
1685 | /* from var.c: */ | 1684 | /* from var.c: */ |
1686 | { | 1685 | { |
1687 | char **envp; | 1686 | char **envp; |
1688 | char ppid[32]; | 1687 | char ppid[32]; |
1689 | const char *p; | 1688 | const char *p; |
1690 | struct stat st1, st2; | 1689 | struct stat st1, st2; |
1691 | 1690 | ||
1692 | initvar(); | 1691 | initvar(); |
1693 | for (envp = environ ; envp && *envp ; envp++) { | 1692 | for (envp = environ ; envp && *envp ; envp++) { |
1694 | if (strchr(*envp, '=')) { | 1693 | if (strchr(*envp, '=')) { |
1695 | setvareq(*envp, VEXPORT|VTEXTFIXED); | 1694 | setvareq(*envp, VEXPORT|VTEXTFIXED); |
1696 | } | 1695 | } |
1697 | } | 1696 | } |
1698 | 1697 | ||
1699 | snprintf(ppid, sizeof(ppid), "%d", (int) getppid()); | 1698 | snprintf(ppid, sizeof(ppid), "%d", (int) getppid()); |
1700 | setvar("PPID", ppid, 0); | 1699 | setvar("PPID", ppid, 0); |
1701 | 1700 | ||
1702 | p = lookupvar("PWD"); | 1701 | p = lookupvar("PWD"); |
1703 | if (p) | 1702 | if (p) |
1704 | if (*p != '/' || stat(p, &st1) || stat(".", &st2) || | 1703 | if (*p != '/' || stat(p, &st1) || stat(".", &st2) |
1705 | st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino) | 1704 | || st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino) |
1706 | p = 0; | 1705 | p = 0; |
1707 | setpwd(p, 0); | 1706 | setpwd(p, 0); |
1708 | } | 1707 | } |
1709 | } | 1708 | } |
1710 | 1709 | ||
1711 | /* PEOF (the end of file marker) */ | 1710 | /* PEOF (the end of file marker) */ |
@@ -2070,29 +2069,28 @@ static int is_safe_applet(char *name) | |||
2070 | static void | 2069 | static void |
2071 | reset(void) | 2070 | reset(void) |
2072 | { | 2071 | { |
2073 | /* from eval.c: */ | 2072 | /* from eval.c: */ |
2074 | { | 2073 | { |
2075 | evalskip = 0; | 2074 | evalskip = 0; |
2076 | loopnest = 0; | 2075 | loopnest = 0; |
2077 | } | 2076 | } |
2078 | |||
2079 | /* from input.c: */ | ||
2080 | { | ||
2081 | parselleft = parsenleft = 0; /* clear input buffer */ | ||
2082 | popallfiles(); | ||
2083 | } | ||
2084 | 2077 | ||
2085 | /* from parser.c: */ | 2078 | /* from input.c: */ |
2086 | { | 2079 | { |
2087 | tokpushback = 0; | 2080 | parselleft = parsenleft = 0; /* clear input buffer */ |
2088 | checkkwd = 0; | 2081 | popallfiles(); |
2089 | } | 2082 | } |
2090 | 2083 | ||
2091 | /* from redir.c: */ | 2084 | /* from parser.c: */ |
2092 | { | 2085 | { |
2093 | clearredir(0); | 2086 | tokpushback = 0; |
2094 | } | 2087 | checkkwd = 0; |
2088 | } | ||
2095 | 2089 | ||
2090 | /* from redir.c: */ | ||
2091 | { | ||
2092 | clearredir(0); | ||
2093 | } | ||
2096 | } | 2094 | } |
2097 | 2095 | ||
2098 | #ifdef CONFIG_ASH_ALIAS | 2096 | #ifdef CONFIG_ASH_ALIAS |
@@ -2118,7 +2116,7 @@ setalias(const char *name, const char *val) | |||
2118 | ap->flag &= ~ALIASDEAD; | 2116 | ap->flag &= ~ALIASDEAD; |
2119 | } else { | 2117 | } else { |
2120 | /* not found */ | 2118 | /* not found */ |
2121 | ap = ckmalloc(sizeof (struct alias)); | 2119 | ap = ckmalloc(sizeof(struct alias)); |
2122 | ap->name = savestr(name); | 2120 | ap->name = savestr(name); |
2123 | ap->val = savestr(val); | 2121 | ap->val = savestr(val); |
2124 | ap->flag = 0; | 2122 | ap->flag = 0; |
@@ -2534,8 +2532,7 @@ setpwd(const char *val, int setold) | |||
2534 | 2532 | ||
2535 | 2533 | ||
2536 | 2534 | ||
2537 | static void exverror(int, const char *, va_list) | 2535 | static void exverror(int, const char *, va_list) ATTRIBUTE_NORETURN; |
2538 | ATTRIBUTE_NORETURN; | ||
2539 | 2536 | ||
2540 | /* | 2537 | /* |
2541 | * Called to raise an exception. Since C doesn't include exceptions, we | 2538 | * Called to raise an exception. Since C doesn't include exceptions, we |
@@ -2670,7 +2667,7 @@ sh_warnx(const char *fmt, ...) | |||
2670 | static const char * | 2667 | static const char * |
2671 | errmsg(int e, const char *em) | 2668 | errmsg(int e, const char *em) |
2672 | { | 2669 | { |
2673 | if(e == ENOENT || e == ENOTDIR) { | 2670 | if (e == ENOENT || e == ENOTDIR) { |
2674 | 2671 | ||
2675 | return em; | 2672 | return em; |
2676 | } | 2673 | } |
@@ -2792,7 +2789,7 @@ evaltree(union node *n, int flags) | |||
2792 | goto out; | 2789 | goto out; |
2793 | } | 2790 | } |
2794 | TRACE(("pid %d, evaltree(%p: %d, %d) called\n", | 2791 | TRACE(("pid %d, evaltree(%p: %d, %d) called\n", |
2795 | getpid(), n, n->type, flags)); | 2792 | getpid(), n, n->type, flags)); |
2796 | switch (n->type) { | 2793 | switch (n->type) { |
2797 | default: | 2794 | default: |
2798 | #if DEBUG | 2795 | #if DEBUG |
@@ -3297,7 +3294,7 @@ evalcommand(union node *cmd, int flags) | |||
3297 | argc++; | 3294 | argc++; |
3298 | } | 3295 | } |
3299 | 3296 | ||
3300 | argv = nargv = stalloc(sizeof (char *) * (argc + 1)); | 3297 | argv = nargv = stalloc(sizeof(char *) * (argc + 1)); |
3301 | for (sp = arglist.list ; sp ; sp = sp->next) { | 3298 | for (sp = arglist.list ; sp ; sp = sp->next) { |
3302 | TRACE(("evalcommand arg: %s\n", sp->text)); | 3299 | TRACE(("evalcommand arg: %s\n", sp->text)); |
3303 | *nargv++ = sp->text; | 3300 | *nargv++ = sp->text; |
@@ -3338,11 +3335,11 @@ evalcommand(union node *cmd, int flags) | |||
3338 | dprintf(preverrout_fd, p, expandstr(ps4val())); | 3335 | dprintf(preverrout_fd, p, expandstr(ps4val())); |
3339 | 3336 | ||
3340 | sp = varlist.list; | 3337 | sp = varlist.list; |
3341 | for(n = 0; n < 2; n++) { | 3338 | for (n = 0; n < 2; n++) { |
3342 | while (sp) { | 3339 | while (sp) { |
3343 | dprintf(preverrout_fd, p, sp->text); | 3340 | dprintf(preverrout_fd, p, sp->text); |
3344 | sp = sp->next; | 3341 | sp = sp->next; |
3345 | if(*p == '%') { | 3342 | if (*p == '%') { |
3346 | p--; | 3343 | p--; |
3347 | } | 3344 | } |
3348 | } | 3345 | } |
@@ -3563,10 +3560,8 @@ prehash(union node *n) | |||
3563 | { | 3560 | { |
3564 | struct cmdentry entry; | 3561 | struct cmdentry entry; |
3565 | 3562 | ||
3566 | if (n->type == NCMD && n->ncmd.args) | 3563 | if (n->type == NCMD && n->ncmd.args && goodname(n->ncmd.args->narg.text)) |
3567 | if (goodname(n->ncmd.args->narg.text)) | 3564 | find_command(n->ncmd.args->narg.text, &entry, 0, pathval()); |
3568 | find_command(n->ncmd.args->narg.text, &entry, 0, | ||
3569 | pathval()); | ||
3570 | } | 3565 | } |
3571 | 3566 | ||
3572 | 3567 | ||
@@ -4211,7 +4206,8 @@ clearcmdentry(int firstchange) | |||
4211 | if ((cmdp->cmdtype == CMDNORMAL && | 4206 | if ((cmdp->cmdtype == CMDNORMAL && |
4212 | cmdp->param.index >= firstchange) | 4207 | cmdp->param.index >= firstchange) |
4213 | || (cmdp->cmdtype == CMDBUILTIN && | 4208 | || (cmdp->cmdtype == CMDBUILTIN && |
4214 | builtinloc >= firstchange)) { | 4209 | builtinloc >= firstchange) |
4210 | ) { | ||
4215 | *pp = cmdp->next; | 4211 | *pp = cmdp->next; |
4216 | ckfree(cmdp); | 4212 | ckfree(cmdp); |
4217 | } else { | 4213 | } else { |
@@ -4257,7 +4253,7 @@ cmdlookup(const char *name, int add) | |||
4257 | pp = &cmdp->next; | 4253 | pp = &cmdp->next; |
4258 | } | 4254 | } |
4259 | if (add && cmdp == NULL) { | 4255 | if (add && cmdp == NULL) { |
4260 | cmdp = *pp = ckmalloc(sizeof (struct tblentry) - ARB | 4256 | cmdp = *pp = ckmalloc(sizeof(struct tblentry) - ARB |
4261 | + strlen(name) + 1); | 4257 | + strlen(name) + 1); |
4262 | cmdp->next = NULL; | 4258 | cmdp->next = NULL; |
4263 | cmdp->cmdtype = CMDUNKNOWN; | 4259 | cmdp->cmdtype = CMDUNKNOWN; |
@@ -4351,8 +4347,8 @@ unsetfunc(const char *name) | |||
4351 | { | 4347 | { |
4352 | struct tblentry *cmdp; | 4348 | struct tblentry *cmdp; |
4353 | 4349 | ||
4354 | if ((cmdp = cmdlookup(name, 0)) != NULL && | 4350 | cmdp = cmdlookup(name, 0); |
4355 | cmdp->cmdtype == CMDFUNCTION) | 4351 | if (cmdp!= NULL && cmdp->cmdtype == CMDFUNCTION) |
4356 | delete_cmd_entry(); | 4352 | delete_cmd_entry(); |
4357 | } | 4353 | } |
4358 | 4354 | ||
@@ -4641,7 +4637,7 @@ expandarg(union node *arg, struct arglist *arglist, int flag) | |||
4641 | } else { | 4637 | } else { |
4642 | if (flag & EXP_REDIR) /*XXX - for now, just remove escapes */ | 4638 | if (flag & EXP_REDIR) /*XXX - for now, just remove escapes */ |
4643 | rmescapes(p); | 4639 | rmescapes(p); |
4644 | sp = (struct strlist *)stalloc(sizeof (struct strlist)); | 4640 | sp = (struct strlist *)stalloc(sizeof(struct strlist)); |
4645 | sp->text = p; | 4641 | sp->text = p; |
4646 | *exparg.lastp = sp; | 4642 | *exparg.lastp = sp; |
4647 | exparg.lastp = &sp->next; | 4643 | exparg.lastp = &sp->next; |
@@ -4985,7 +4981,7 @@ expbackq(union node *cmd, int quoted, int quotes) | |||
4985 | read: | 4981 | read: |
4986 | if (in.fd < 0) | 4982 | if (in.fd < 0) |
4987 | break; | 4983 | break; |
4988 | i = safe_read(in.fd, buf, sizeof buf); | 4984 | i = safe_read(in.fd, buf, sizeof(buf)); |
4989 | TRACE(("expbackq: read returns %d\n", i)); | 4985 | TRACE(("expbackq: read returns %d\n", i)); |
4990 | if (i <= 0) | 4986 | if (i <= 0) |
4991 | break; | 4987 | break; |
@@ -5202,8 +5198,7 @@ vsplus: | |||
5202 | 5198 | ||
5203 | if (subtype == VSASSIGN || subtype == VSQUESTION) { | 5199 | if (subtype == VSASSIGN || subtype == VSQUESTION) { |
5204 | if (varlen < 0) { | 5200 | if (varlen < 0) { |
5205 | if (subevalvar(p, var, 0, subtype, startloc, | 5201 | if (subevalvar(p, var, 0, subtype, startloc, varflags, 0)) { |
5206 | varflags, 0)) { | ||
5207 | varflags &= ~VSNUL; | 5202 | varflags &= ~VSNUL; |
5208 | /* | 5203 | /* |
5209 | * Remove any recorded regions beyond | 5204 | * Remove any recorded regions beyond |
@@ -5255,7 +5250,7 @@ record: | |||
5255 | STPUTC('\0', expdest); | 5250 | STPUTC('\0', expdest); |
5256 | patloc = expdest - (char *)stackblock(); | 5251 | patloc = expdest - (char *)stackblock(); |
5257 | if (subevalvar(p, NULL, patloc, subtype, | 5252 | if (subevalvar(p, NULL, patloc, subtype, |
5258 | startloc, varflags, quotes) == 0) { | 5253 | startloc, varflags, quotes) == 0) { |
5259 | int amount = expdest - ( | 5254 | int amount = expdest - ( |
5260 | (char *)stackblock() + patloc - 1 | 5255 | (char *)stackblock() + patloc - 1 |
5261 | ); | 5256 | ); |
@@ -5450,7 +5445,7 @@ recordregion(int start, int end, int nulonly) | |||
5450 | ifsp = &ifsfirst; | 5445 | ifsp = &ifsfirst; |
5451 | } else { | 5446 | } else { |
5452 | INTOFF; | 5447 | INTOFF; |
5453 | ifsp = (struct ifsregion *)ckmalloc(sizeof (struct ifsregion)); | 5448 | ifsp = (struct ifsregion *)ckmalloc(sizeof(struct ifsregion)); |
5454 | ifsp->next = NULL; | 5449 | ifsp->next = NULL; |
5455 | ifslastp->next = ifsp; | 5450 | ifslastp->next = ifsp; |
5456 | INTON; | 5451 | INTON; |
@@ -5505,7 +5500,7 @@ ifsbreakup(char *string, struct arglist *arglist) | |||
5505 | continue; | 5500 | continue; |
5506 | } | 5501 | } |
5507 | *q = '\0'; | 5502 | *q = '\0'; |
5508 | sp = (struct strlist *)stalloc(sizeof *sp); | 5503 | sp = (struct strlist *)stalloc(sizeof(*sp)); |
5509 | sp->text = start; | 5504 | sp->text = start; |
5510 | *arglist->lastp = sp; | 5505 | *arglist->lastp = sp; |
5511 | arglist->lastp = &sp->next; | 5506 | arglist->lastp = &sp->next; |
@@ -5546,7 +5541,7 @@ ifsbreakup(char *string, struct arglist *arglist) | |||
5546 | return; | 5541 | return; |
5547 | 5542 | ||
5548 | add: | 5543 | add: |
5549 | sp = (struct strlist *)stalloc(sizeof *sp); | 5544 | sp = (struct strlist *)stalloc(sizeof(*sp)); |
5550 | sp->text = start; | 5545 | sp->text = start; |
5551 | *arglist->lastp = sp; | 5546 | *arglist->lastp = sp; |
5552 | arglist->lastp = &sp->next; | 5547 | arglist->lastp = &sp->next; |
@@ -5636,7 +5631,7 @@ addfname(const char *name) | |||
5636 | { | 5631 | { |
5637 | struct strlist *sp; | 5632 | struct strlist *sp; |
5638 | 5633 | ||
5639 | sp = (struct strlist *)stalloc(sizeof *sp); | 5634 | sp = (struct strlist *)stalloc(sizeof(*sp)); |
5640 | sp->text = sstrdup(name); | 5635 | sp->text = sstrdup(name); |
5641 | *exparg.lastp = sp; | 5636 | *exparg.lastp = sp; |
5642 | exparg.lastp = &sp->next; | 5637 | exparg.lastp = &sp->next; |
@@ -5743,8 +5738,7 @@ out: | |||
5743 | scopy(dp->d_name, enddir); | 5738 | scopy(dp->d_name, enddir); |
5744 | addfname(expdir); | 5739 | addfname(expdir); |
5745 | } else { | 5740 | } else { |
5746 | for (p = enddir, cp = dp->d_name; | 5741 | for (p = enddir, cp = dp->d_name; (*p++ = *cp++) != '\0';) |
5747 | (*p++ = *cp++) != '\0';) | ||
5748 | continue; | 5742 | continue; |
5749 | p[-1] = '/'; | 5743 | p[-1] = '/'; |
5750 | expmeta(p, endname); | 5744 | expmeta(p, endname); |
@@ -6226,7 +6220,7 @@ pushstring(char *s, void *ap) | |||
6226 | INTOFF; | 6220 | INTOFF; |
6227 | /*dprintf("*** calling pushstring: %s, %d\n", s, len);*/ | 6221 | /*dprintf("*** calling pushstring: %s, %d\n", s, len);*/ |
6228 | if (parsefile->strpush) { | 6222 | if (parsefile->strpush) { |
6229 | sp = ckmalloc(sizeof (struct strpush)); | 6223 | sp = ckmalloc(sizeof(struct strpush)); |
6230 | sp->prev = parsefile->strpush; | 6224 | sp->prev = parsefile->strpush; |
6231 | parsefile->strpush = sp; | 6225 | parsefile->strpush = sp; |
6232 | } else | 6226 | } else |
@@ -6357,7 +6351,7 @@ pushfile(void) | |||
6357 | parsefile->lleft = parselleft; | 6351 | parsefile->lleft = parselleft; |
6358 | parsefile->nextc = parsenextc; | 6352 | parsefile->nextc = parsenextc; |
6359 | parsefile->linno = plinno; | 6353 | parsefile->linno = plinno; |
6360 | pf = (struct parsefile *)ckmalloc(sizeof (struct parsefile)); | 6354 | pf = (struct parsefile *)ckmalloc(sizeof(struct parsefile)); |
6361 | pf->prev = parsefile; | 6355 | pf->prev = parsefile; |
6362 | pf->fd = -1; | 6356 | pf->fd = -1; |
6363 | pf->strpush = NULL; | 6357 | pf->strpush = NULL; |
@@ -7102,10 +7096,10 @@ makejob(union node *node, int nprocs) | |||
7102 | jp->used = 1; | 7096 | jp->used = 1; |
7103 | jp->ps = &jp->ps0; | 7097 | jp->ps = &jp->ps0; |
7104 | if (nprocs > 1) { | 7098 | if (nprocs > 1) { |
7105 | jp->ps = ckmalloc(nprocs * sizeof (struct procstat)); | 7099 | jp->ps = ckmalloc(nprocs * sizeof(struct procstat)); |
7106 | } | 7100 | } |
7107 | TRACE(("makejob(0x%lx, %d) returns %%%d\n", (long)node, nprocs, | 7101 | TRACE(("makejob(0x%lx, %d) returns %%%d\n", (long)node, nprocs, |
7108 | jobno(jp))); | 7102 | jobno(jp))); |
7109 | return jp; | 7103 | return jp; |
7110 | } | 7104 | } |
7111 | 7105 | ||
@@ -7397,7 +7391,9 @@ dowait(int block, struct job *job) | |||
7397 | sp = jp->ps; | 7391 | sp = jp->ps; |
7398 | do { | 7392 | do { |
7399 | if (sp->pid == pid) { | 7393 | if (sp->pid == pid) { |
7400 | TRACE(("Job %d: changing status of proc %d from 0x%x to 0x%x\n", jobno(jp), pid, sp->status, status)); | 7394 | TRACE(("Job %d: changing status of proc %d " |
7395 | "from 0x%x to 0x%x\n", | ||
7396 | jobno(jp), pid, sp->status, status)); | ||
7401 | sp->status = status; | 7397 | sp->status = status; |
7402 | thisjob = jp; | 7398 | thisjob = jp; |
7403 | } | 7399 | } |
@@ -7427,7 +7423,8 @@ gotjob: | |||
7427 | thisjob->changed = 1; | 7423 | thisjob->changed = 1; |
7428 | 7424 | ||
7429 | if (thisjob->state != state) { | 7425 | if (thisjob->state != state) { |
7430 | TRACE(("Job %d: changing state from %d to %d\n", jobno(thisjob), thisjob->state, state)); | 7426 | TRACE(("Job %d: changing state from %d to %d\n", |
7427 | jobno(thisjob), thisjob->state, state)); | ||
7431 | thisjob->state = state; | 7428 | thisjob->state = state; |
7432 | #if JOBS | 7429 | #if JOBS |
7433 | if (state == JOBSTOPPED) { | 7430 | if (state == JOBSTOPPED) { |
@@ -7913,7 +7910,7 @@ int ash_main(int argc, char **argv) | |||
7913 | #endif | 7910 | #endif |
7914 | 7911 | ||
7915 | #if PROFILE | 7912 | #if PROFILE |
7916 | monitor(4, etext, profile_buf, sizeof profile_buf, 50); | 7913 | monitor(4, etext, profile_buf, sizeof(profile_buf), 50); |
7917 | #endif | 7914 | #endif |
7918 | 7915 | ||
7919 | #if ENABLE_FEATURE_EDITING | 7916 | #if ENABLE_FEATURE_EDITING |
@@ -7966,7 +7963,7 @@ int ash_main(int argc, char **argv) | |||
7966 | 7963 | ||
7967 | if (hp == NULL) { | 7964 | if (hp == NULL) { |
7968 | hp = lookupvar("HOME"); | 7965 | hp = lookupvar("HOME"); |
7969 | if(hp != NULL) { | 7966 | if (hp != NULL) { |
7970 | char *defhp = concat_path_file(hp, ".ash_history"); | 7967 | char *defhp = concat_path_file(hp, ".ash_history"); |
7971 | setvar("HISTFILE", defhp, 0); | 7968 | setvar("HISTFILE", defhp, 0); |
7972 | free(defhp); | 7969 | free(defhp); |
@@ -8584,79 +8581,79 @@ sstrdup(const char *p) | |||
8584 | static void | 8581 | static void |
8585 | calcsize(union node *n) | 8582 | calcsize(union node *n) |
8586 | { | 8583 | { |
8587 | if (n == NULL) | 8584 | if (n == NULL) |
8588 | return; | 8585 | return; |
8589 | funcblocksize += nodesize[n->type]; | 8586 | funcblocksize += nodesize[n->type]; |
8590 | switch (n->type) { | 8587 | switch (n->type) { |
8591 | case NCMD: | 8588 | case NCMD: |
8592 | calcsize(n->ncmd.redirect); | 8589 | calcsize(n->ncmd.redirect); |
8593 | calcsize(n->ncmd.args); | 8590 | calcsize(n->ncmd.args); |
8594 | calcsize(n->ncmd.assign); | 8591 | calcsize(n->ncmd.assign); |
8595 | break; | 8592 | break; |
8596 | case NPIPE: | 8593 | case NPIPE: |
8597 | sizenodelist(n->npipe.cmdlist); | 8594 | sizenodelist(n->npipe.cmdlist); |
8598 | break; | 8595 | break; |
8599 | case NREDIR: | 8596 | case NREDIR: |
8600 | case NBACKGND: | 8597 | case NBACKGND: |
8601 | case NSUBSHELL: | 8598 | case NSUBSHELL: |
8602 | calcsize(n->nredir.redirect); | 8599 | calcsize(n->nredir.redirect); |
8603 | calcsize(n->nredir.n); | 8600 | calcsize(n->nredir.n); |
8604 | break; | 8601 | break; |
8605 | case NAND: | 8602 | case NAND: |
8606 | case NOR: | 8603 | case NOR: |
8607 | case NSEMI: | 8604 | case NSEMI: |
8608 | case NWHILE: | 8605 | case NWHILE: |
8609 | case NUNTIL: | 8606 | case NUNTIL: |
8610 | calcsize(n->nbinary.ch2); | 8607 | calcsize(n->nbinary.ch2); |
8611 | calcsize(n->nbinary.ch1); | 8608 | calcsize(n->nbinary.ch1); |
8612 | break; | 8609 | break; |
8613 | case NIF: | 8610 | case NIF: |
8614 | calcsize(n->nif.elsepart); | 8611 | calcsize(n->nif.elsepart); |
8615 | calcsize(n->nif.ifpart); | 8612 | calcsize(n->nif.ifpart); |
8616 | calcsize(n->nif.test); | 8613 | calcsize(n->nif.test); |
8617 | break; | 8614 | break; |
8618 | case NFOR: | 8615 | case NFOR: |
8619 | funcstringsize += strlen(n->nfor.var) + 1; | 8616 | funcstringsize += strlen(n->nfor.var) + 1; |
8620 | calcsize(n->nfor.body); | 8617 | calcsize(n->nfor.body); |
8621 | calcsize(n->nfor.args); | 8618 | calcsize(n->nfor.args); |
8622 | break; | 8619 | break; |
8623 | case NCASE: | 8620 | case NCASE: |
8624 | calcsize(n->ncase.cases); | 8621 | calcsize(n->ncase.cases); |
8625 | calcsize(n->ncase.expr); | 8622 | calcsize(n->ncase.expr); |
8626 | break; | 8623 | break; |
8627 | case NCLIST: | 8624 | case NCLIST: |
8628 | calcsize(n->nclist.body); | 8625 | calcsize(n->nclist.body); |
8629 | calcsize(n->nclist.pattern); | 8626 | calcsize(n->nclist.pattern); |
8630 | calcsize(n->nclist.next); | 8627 | calcsize(n->nclist.next); |
8631 | break; | 8628 | break; |
8632 | case NDEFUN: | 8629 | case NDEFUN: |
8633 | case NARG: | 8630 | case NARG: |
8634 | sizenodelist(n->narg.backquote); | 8631 | sizenodelist(n->narg.backquote); |
8635 | funcstringsize += strlen(n->narg.text) + 1; | 8632 | funcstringsize += strlen(n->narg.text) + 1; |
8636 | calcsize(n->narg.next); | 8633 | calcsize(n->narg.next); |
8637 | break; | 8634 | break; |
8638 | case NTO: | 8635 | case NTO: |
8639 | case NCLOBBER: | 8636 | case NCLOBBER: |
8640 | case NFROM: | 8637 | case NFROM: |
8641 | case NFROMTO: | 8638 | case NFROMTO: |
8642 | case NAPPEND: | 8639 | case NAPPEND: |
8643 | calcsize(n->nfile.fname); | 8640 | calcsize(n->nfile.fname); |
8644 | calcsize(n->nfile.next); | 8641 | calcsize(n->nfile.next); |
8645 | break; | 8642 | break; |
8646 | case NTOFD: | 8643 | case NTOFD: |
8647 | case NFROMFD: | 8644 | case NFROMFD: |
8648 | calcsize(n->ndup.vname); | 8645 | calcsize(n->ndup.vname); |
8649 | calcsize(n->ndup.next); | 8646 | calcsize(n->ndup.next); |
8650 | break; | 8647 | break; |
8651 | case NHERE: | 8648 | case NHERE: |
8652 | case NXHERE: | 8649 | case NXHERE: |
8653 | calcsize(n->nhere.doc); | 8650 | calcsize(n->nhere.doc); |
8654 | calcsize(n->nhere.next); | 8651 | calcsize(n->nhere.next); |
8655 | break; | 8652 | break; |
8656 | case NNOT: | 8653 | case NNOT: |
8657 | calcsize(n->nnot.com); | 8654 | calcsize(n->nnot.com); |
8658 | break; | 8655 | break; |
8659 | }; | 8656 | }; |
8660 | } | 8657 | } |
8661 | 8658 | ||
8662 | 8659 | ||
@@ -8674,88 +8671,89 @@ sizenodelist(struct nodelist *lp) | |||
8674 | static union node * | 8671 | static union node * |
8675 | copynode(union node *n) | 8672 | copynode(union node *n) |
8676 | { | 8673 | { |
8677 | union node *new; | 8674 | union node *new; |
8678 | 8675 | ||
8679 | if (n == NULL) | 8676 | if (n == NULL) |
8680 | return NULL; | 8677 | return NULL; |
8681 | new = funcblock; | 8678 | new = funcblock; |
8682 | funcblock = (char *) funcblock + nodesize[n->type]; | 8679 | funcblock = (char *) funcblock + nodesize[n->type]; |
8683 | switch (n->type) { | 8680 | |
8684 | case NCMD: | 8681 | switch (n->type) { |
8685 | new->ncmd.redirect = copynode(n->ncmd.redirect); | 8682 | case NCMD: |
8686 | new->ncmd.args = copynode(n->ncmd.args); | 8683 | new->ncmd.redirect = copynode(n->ncmd.redirect); |
8687 | new->ncmd.assign = copynode(n->ncmd.assign); | 8684 | new->ncmd.args = copynode(n->ncmd.args); |
8688 | break; | 8685 | new->ncmd.assign = copynode(n->ncmd.assign); |
8689 | case NPIPE: | 8686 | break; |
8690 | new->npipe.cmdlist = copynodelist(n->npipe.cmdlist); | 8687 | case NPIPE: |
8691 | new->npipe.backgnd = n->npipe.backgnd; | 8688 | new->npipe.cmdlist = copynodelist(n->npipe.cmdlist); |
8692 | break; | 8689 | new->npipe.backgnd = n->npipe.backgnd; |
8693 | case NREDIR: | 8690 | break; |
8694 | case NBACKGND: | 8691 | case NREDIR: |
8695 | case NSUBSHELL: | 8692 | case NBACKGND: |
8696 | new->nredir.redirect = copynode(n->nredir.redirect); | 8693 | case NSUBSHELL: |
8697 | new->nredir.n = copynode(n->nredir.n); | 8694 | new->nredir.redirect = copynode(n->nredir.redirect); |
8698 | break; | 8695 | new->nredir.n = copynode(n->nredir.n); |
8699 | case NAND: | 8696 | break; |
8700 | case NOR: | 8697 | case NAND: |
8701 | case NSEMI: | 8698 | case NOR: |
8702 | case NWHILE: | 8699 | case NSEMI: |
8703 | case NUNTIL: | 8700 | case NWHILE: |
8704 | new->nbinary.ch2 = copynode(n->nbinary.ch2); | 8701 | case NUNTIL: |
8705 | new->nbinary.ch1 = copynode(n->nbinary.ch1); | 8702 | new->nbinary.ch2 = copynode(n->nbinary.ch2); |
8706 | break; | 8703 | new->nbinary.ch1 = copynode(n->nbinary.ch1); |
8707 | case NIF: | 8704 | break; |
8708 | new->nif.elsepart = copynode(n->nif.elsepart); | 8705 | case NIF: |
8709 | new->nif.ifpart = copynode(n->nif.ifpart); | 8706 | new->nif.elsepart = copynode(n->nif.elsepart); |
8710 | new->nif.test = copynode(n->nif.test); | 8707 | new->nif.ifpart = copynode(n->nif.ifpart); |
8711 | break; | 8708 | new->nif.test = copynode(n->nif.test); |
8712 | case NFOR: | 8709 | break; |
8713 | new->nfor.var = nodesavestr(n->nfor.var); | 8710 | case NFOR: |
8714 | new->nfor.body = copynode(n->nfor.body); | 8711 | new->nfor.var = nodesavestr(n->nfor.var); |
8715 | new->nfor.args = copynode(n->nfor.args); | 8712 | new->nfor.body = copynode(n->nfor.body); |
8716 | break; | 8713 | new->nfor.args = copynode(n->nfor.args); |
8717 | case NCASE: | 8714 | break; |
8718 | new->ncase.cases = copynode(n->ncase.cases); | 8715 | case NCASE: |
8719 | new->ncase.expr = copynode(n->ncase.expr); | 8716 | new->ncase.cases = copynode(n->ncase.cases); |
8720 | break; | 8717 | new->ncase.expr = copynode(n->ncase.expr); |
8721 | case NCLIST: | 8718 | break; |
8722 | new->nclist.body = copynode(n->nclist.body); | 8719 | case NCLIST: |
8723 | new->nclist.pattern = copynode(n->nclist.pattern); | 8720 | new->nclist.body = copynode(n->nclist.body); |
8724 | new->nclist.next = copynode(n->nclist.next); | 8721 | new->nclist.pattern = copynode(n->nclist.pattern); |
8725 | break; | 8722 | new->nclist.next = copynode(n->nclist.next); |
8726 | case NDEFUN: | 8723 | break; |
8727 | case NARG: | 8724 | case NDEFUN: |
8728 | new->narg.backquote = copynodelist(n->narg.backquote); | 8725 | case NARG: |
8729 | new->narg.text = nodesavestr(n->narg.text); | 8726 | new->narg.backquote = copynodelist(n->narg.backquote); |
8730 | new->narg.next = copynode(n->narg.next); | 8727 | new->narg.text = nodesavestr(n->narg.text); |
8731 | break; | 8728 | new->narg.next = copynode(n->narg.next); |
8732 | case NTO: | 8729 | break; |
8733 | case NCLOBBER: | 8730 | case NTO: |
8734 | case NFROM: | 8731 | case NCLOBBER: |
8735 | case NFROMTO: | 8732 | case NFROM: |
8736 | case NAPPEND: | 8733 | case NFROMTO: |
8737 | new->nfile.fname = copynode(n->nfile.fname); | 8734 | case NAPPEND: |
8738 | new->nfile.fd = n->nfile.fd; | 8735 | new->nfile.fname = copynode(n->nfile.fname); |
8739 | new->nfile.next = copynode(n->nfile.next); | 8736 | new->nfile.fd = n->nfile.fd; |
8740 | break; | 8737 | new->nfile.next = copynode(n->nfile.next); |
8741 | case NTOFD: | 8738 | break; |
8742 | case NFROMFD: | 8739 | case NTOFD: |
8743 | new->ndup.vname = copynode(n->ndup.vname); | 8740 | case NFROMFD: |
8744 | new->ndup.dupfd = n->ndup.dupfd; | 8741 | new->ndup.vname = copynode(n->ndup.vname); |
8745 | new->ndup.fd = n->ndup.fd; | 8742 | new->ndup.dupfd = n->ndup.dupfd; |
8746 | new->ndup.next = copynode(n->ndup.next); | 8743 | new->ndup.fd = n->ndup.fd; |
8747 | break; | 8744 | new->ndup.next = copynode(n->ndup.next); |
8748 | case NHERE: | 8745 | break; |
8749 | case NXHERE: | 8746 | case NHERE: |
8750 | new->nhere.doc = copynode(n->nhere.doc); | 8747 | case NXHERE: |
8751 | new->nhere.fd = n->nhere.fd; | 8748 | new->nhere.doc = copynode(n->nhere.doc); |
8752 | new->nhere.next = copynode(n->nhere.next); | 8749 | new->nhere.fd = n->nhere.fd; |
8753 | break; | 8750 | new->nhere.next = copynode(n->nhere.next); |
8754 | case NNOT: | 8751 | break; |
8755 | new->nnot.com = copynode(n->nnot.com); | 8752 | case NNOT: |
8756 | break; | 8753 | new->nnot.com = copynode(n->nnot.com); |
8757 | }; | 8754 | break; |
8758 | new->type = n->type; | 8755 | }; |
8756 | new->type = n->type; | ||
8759 | return new; | 8757 | return new; |
8760 | } | 8758 | } |
8761 | 8759 | ||
@@ -8769,8 +8767,7 @@ copynodelist(struct nodelist *lp) | |||
8769 | lpp = &start; | 8767 | lpp = &start; |
8770 | while (lp) { | 8768 | while (lp) { |
8771 | *lpp = funcblock; | 8769 | *lpp = funcblock; |
8772 | funcblock = (char *) funcblock + | 8770 | funcblock = (char *) funcblock + SHELL_ALIGN(sizeof(struct nodelist)); |
8773 | SHELL_ALIGN(sizeof(struct nodelist)); | ||
8774 | (*lpp)->n = copynode(lp->n); | 8771 | (*lpp)->n = copynode(lp->n); |
8775 | lp = lp->next; | 8772 | lp = lp->next; |
8776 | lpp = &(*lpp)->next; | 8773 | lpp = &(*lpp)->next; |
@@ -8981,7 +8978,7 @@ setparam(char **argv) | |||
8981 | int nparam; | 8978 | int nparam; |
8982 | 8979 | ||
8983 | for (nparam = 0 ; argv[nparam] ; nparam++); | 8980 | for (nparam = 0 ; argv[nparam] ; nparam++); |
8984 | ap = newparam = ckmalloc((nparam + 1) * sizeof *ap); | 8981 | ap = newparam = ckmalloc((nparam + 1) * sizeof(*ap)); |
8985 | while (*argv) { | 8982 | while (*argv) { |
8986 | *ap++ = savestr(*argv++); | 8983 | *ap++ = savestr(*argv++); |
8987 | } | 8984 | } |
@@ -9096,7 +9093,7 @@ static void change_lc_ctype(const char *value) | |||
9096 | /* Roughly copied from bash.. */ | 9093 | /* Roughly copied from bash.. */ |
9097 | static void change_random(const char *value) | 9094 | static void change_random(const char *value) |
9098 | { | 9095 | { |
9099 | if(value == NULL) { | 9096 | if (value == NULL) { |
9100 | /* "get", generate */ | 9097 | /* "get", generate */ |
9101 | char buf[16]; | 9098 | char buf[16]; |
9102 | 9099 | ||
@@ -9124,7 +9121,7 @@ getopts(char *optstr, char *optvar, char **optfirst, int *param_optind, int *opt | |||
9124 | char s[12]; | 9121 | char s[12]; |
9125 | char **optnext; | 9122 | char **optnext; |
9126 | 9123 | ||
9127 | if(*param_optind < 1) | 9124 | if (*param_optind < 1) |
9128 | return 1; | 9125 | return 1; |
9129 | optnext = optfirst + *param_optind - 1; | 9126 | optnext = optfirst + *param_optind - 1; |
9130 | 9127 | ||
@@ -9233,7 +9230,7 @@ getoptscmd(int argc, char **argv) | |||
9233 | } | 9230 | } |
9234 | 9231 | ||
9235 | return getopts(argv[1], argv[2], optbase, &shellparam.optind, | 9232 | return getopts(argv[1], argv[2], optbase, &shellparam.optind, |
9236 | &shellparam.optoff); | 9233 | &shellparam.optoff); |
9237 | } | 9234 | } |
9238 | #endif /* CONFIG_ASH_GETOPTS */ | 9235 | #endif /* CONFIG_ASH_GETOPTS */ |
9239 | 9236 | ||
@@ -9446,7 +9443,7 @@ list(int nlflag) | |||
9446 | n1 = n2; | 9443 | n1 = n2; |
9447 | } | 9444 | } |
9448 | else { | 9445 | else { |
9449 | n3 = (union node *)stalloc(sizeof (struct nbinary)); | 9446 | n3 = (union node *)stalloc(sizeof(struct nbinary)); |
9450 | n3->type = NSEMI; | 9447 | n3->type = NSEMI; |
9451 | n3->nbinary.ch1 = n1; | 9448 | n3->nbinary.ch1 = n1; |
9452 | n3->nbinary.ch2 = n2; | 9449 | n3->nbinary.ch2 = n2; |
@@ -9504,7 +9501,7 @@ andor(void) | |||
9504 | } | 9501 | } |
9505 | checkkwd = CHKNL | CHKKWD | CHKALIAS; | 9502 | checkkwd = CHKNL | CHKKWD | CHKALIAS; |
9506 | n2 = pipeline(); | 9503 | n2 = pipeline(); |
9507 | n3 = (union node *)stalloc(sizeof (struct nbinary)); | 9504 | n3 = (union node *)stalloc(sizeof(struct nbinary)); |
9508 | n3->type = t; | 9505 | n3->type = t; |
9509 | n3->nbinary.ch1 = n1; | 9506 | n3->nbinary.ch1 = n1; |
9510 | n3->nbinary.ch2 = n2; | 9507 | n3->nbinary.ch2 = n2; |
@@ -9530,15 +9527,15 @@ pipeline(void) | |||
9530 | tokpushback++; | 9527 | tokpushback++; |
9531 | n1 = command(); | 9528 | n1 = command(); |
9532 | if (readtoken() == TPIPE) { | 9529 | if (readtoken() == TPIPE) { |
9533 | pipenode = (union node *)stalloc(sizeof (struct npipe)); | 9530 | pipenode = (union node *)stalloc(sizeof(struct npipe)); |
9534 | pipenode->type = NPIPE; | 9531 | pipenode->type = NPIPE; |
9535 | pipenode->npipe.backgnd = 0; | 9532 | pipenode->npipe.backgnd = 0; |
9536 | lp = (struct nodelist *)stalloc(sizeof (struct nodelist)); | 9533 | lp = (struct nodelist *)stalloc(sizeof(struct nodelist)); |
9537 | pipenode->npipe.cmdlist = lp; | 9534 | pipenode->npipe.cmdlist = lp; |
9538 | lp->n = n1; | 9535 | lp->n = n1; |
9539 | do { | 9536 | do { |
9540 | prev = lp; | 9537 | prev = lp; |
9541 | lp = (struct nodelist *)stalloc(sizeof (struct nodelist)); | 9538 | lp = (struct nodelist *)stalloc(sizeof(struct nodelist)); |
9542 | checkkwd = CHKNL | CHKKWD | CHKALIAS; | 9539 | checkkwd = CHKNL | CHKKWD | CHKALIAS; |
9543 | lp->n = command(); | 9540 | lp->n = command(); |
9544 | prev->next = lp; | 9541 | prev->next = lp; |
@@ -9548,7 +9545,7 @@ pipeline(void) | |||
9548 | } | 9545 | } |
9549 | tokpushback++; | 9546 | tokpushback++; |
9550 | if (negate) { | 9547 | if (negate) { |
9551 | n2 = (union node *)stalloc(sizeof (struct nnot)); | 9548 | n2 = (union node *)stalloc(sizeof(struct nnot)); |
9552 | n2->type = NNOT; | 9549 | n2->type = NNOT; |
9553 | n2->nnot.com = n1; | 9550 | n2->nnot.com = n1; |
9554 | return n2; | 9551 | return n2; |
@@ -9576,7 +9573,7 @@ command(void) | |||
9576 | synexpect(-1); | 9573 | synexpect(-1); |
9577 | /* NOTREACHED */ | 9574 | /* NOTREACHED */ |
9578 | case TIF: | 9575 | case TIF: |
9579 | n1 = (union node *)stalloc(sizeof (struct nif)); | 9576 | n1 = (union node *)stalloc(sizeof(struct nif)); |
9580 | n1->type = NIF; | 9577 | n1->type = NIF; |
9581 | n1->nif.test = list(0); | 9578 | n1->nif.test = list(0); |
9582 | if (readtoken() != TTHEN) | 9579 | if (readtoken() != TTHEN) |
@@ -9584,7 +9581,7 @@ command(void) | |||
9584 | n1->nif.ifpart = list(0); | 9581 | n1->nif.ifpart = list(0); |
9585 | n2 = n1; | 9582 | n2 = n1; |
9586 | while (readtoken() == TELIF) { | 9583 | while (readtoken() == TELIF) { |
9587 | n2->nif.elsepart = (union node *)stalloc(sizeof (struct nif)); | 9584 | n2->nif.elsepart = (union node *)stalloc(sizeof(struct nif)); |
9588 | n2 = n2->nif.elsepart; | 9585 | n2 = n2->nif.elsepart; |
9589 | n2->type = NIF; | 9586 | n2->type = NIF; |
9590 | n2->nif.test = list(0); | 9587 | n2->nif.test = list(0); |
@@ -9603,7 +9600,7 @@ command(void) | |||
9603 | case TWHILE: | 9600 | case TWHILE: |
9604 | case TUNTIL: { | 9601 | case TUNTIL: { |
9605 | int got; | 9602 | int got; |
9606 | n1 = (union node *)stalloc(sizeof (struct nbinary)); | 9603 | n1 = (union node *)stalloc(sizeof(struct nbinary)); |
9607 | n1->type = (lasttoken == TWHILE)? NWHILE : NUNTIL; | 9604 | n1->type = (lasttoken == TWHILE)? NWHILE : NUNTIL; |
9608 | n1->nbinary.ch1 = list(0); | 9605 | n1->nbinary.ch1 = list(0); |
9609 | if ((got=readtoken()) != TDO) { | 9606 | if ((got=readtoken()) != TDO) { |
@@ -9617,14 +9614,14 @@ TRACE(("expecting DO got %s %s\n", tokname(got), got == TWORD ? wordtext : "")); | |||
9617 | case TFOR: | 9614 | case TFOR: |
9618 | if (readtoken() != TWORD || quoteflag || ! goodname(wordtext)) | 9615 | if (readtoken() != TWORD || quoteflag || ! goodname(wordtext)) |
9619 | synerror("Bad for loop variable"); | 9616 | synerror("Bad for loop variable"); |
9620 | n1 = (union node *)stalloc(sizeof (struct nfor)); | 9617 | n1 = (union node *)stalloc(sizeof(struct nfor)); |
9621 | n1->type = NFOR; | 9618 | n1->type = NFOR; |
9622 | n1->nfor.var = wordtext; | 9619 | n1->nfor.var = wordtext; |
9623 | checkkwd = CHKKWD | CHKALIAS; | 9620 | checkkwd = CHKKWD | CHKALIAS; |
9624 | if (readtoken() == TIN) { | 9621 | if (readtoken() == TIN) { |
9625 | app = ≈ | 9622 | app = ≈ |
9626 | while (readtoken() == TWORD) { | 9623 | while (readtoken() == TWORD) { |
9627 | n2 = (union node *)stalloc(sizeof (struct narg)); | 9624 | n2 = (union node *)stalloc(sizeof(struct narg)); |
9628 | n2->type = NARG; | 9625 | n2->type = NARG; |
9629 | n2->narg.text = wordtext; | 9626 | n2->narg.text = wordtext; |
9630 | n2->narg.backquote = backquotelist; | 9627 | n2->narg.backquote = backquotelist; |
@@ -9636,7 +9633,7 @@ TRACE(("expecting DO got %s %s\n", tokname(got), got == TWORD ? wordtext : "")); | |||
9636 | if (lasttoken != TNL && lasttoken != TSEMI) | 9633 | if (lasttoken != TNL && lasttoken != TSEMI) |
9637 | synexpect(-1); | 9634 | synexpect(-1); |
9638 | } else { | 9635 | } else { |
9639 | n2 = (union node *)stalloc(sizeof (struct narg)); | 9636 | n2 = (union node *)stalloc(sizeof(struct narg)); |
9640 | n2->type = NARG; | 9637 | n2->type = NARG; |
9641 | n2->narg.text = (char *)dolatstr; | 9638 | n2->narg.text = (char *)dolatstr; |
9642 | n2->narg.backquote = NULL; | 9639 | n2->narg.backquote = NULL; |
@@ -9656,11 +9653,11 @@ TRACE(("expecting DO got %s %s\n", tokname(got), got == TWORD ? wordtext : "")); | |||
9656 | t = TDONE; | 9653 | t = TDONE; |
9657 | break; | 9654 | break; |
9658 | case TCASE: | 9655 | case TCASE: |
9659 | n1 = (union node *)stalloc(sizeof (struct ncase)); | 9656 | n1 = (union node *)stalloc(sizeof(struct ncase)); |
9660 | n1->type = NCASE; | 9657 | n1->type = NCASE; |
9661 | if (readtoken() != TWORD) | 9658 | if (readtoken() != TWORD) |
9662 | synexpect(TWORD); | 9659 | synexpect(TWORD); |
9663 | n1->ncase.expr = n2 = (union node *)stalloc(sizeof (struct narg)); | 9660 | n1->ncase.expr = n2 = (union node *)stalloc(sizeof(struct narg)); |
9664 | n2->type = NARG; | 9661 | n2->type = NARG; |
9665 | n2->narg.text = wordtext; | 9662 | n2->narg.text = wordtext; |
9666 | n2->narg.backquote = backquotelist; | 9663 | n2->narg.backquote = backquotelist; |
@@ -9674,14 +9671,14 @@ TRACE(("expecting DO got %s %s\n", tokname(got), got == TWORD ? wordtext : "")); | |||
9674 | next_case: | 9671 | next_case: |
9675 | checkkwd = CHKNL | CHKKWD; | 9672 | checkkwd = CHKNL | CHKKWD; |
9676 | t = readtoken(); | 9673 | t = readtoken(); |
9677 | while(t != TESAC) { | 9674 | while (t != TESAC) { |
9678 | if (lasttoken == TLP) | 9675 | if (lasttoken == TLP) |
9679 | readtoken(); | 9676 | readtoken(); |
9680 | *cpp = cp = (union node *)stalloc(sizeof (struct nclist)); | 9677 | *cpp = cp = (union node *)stalloc(sizeof(struct nclist)); |
9681 | cp->type = NCLIST; | 9678 | cp->type = NCLIST; |
9682 | app = &cp->nclist.pattern; | 9679 | app = &cp->nclist.pattern; |
9683 | for (;;) { | 9680 | for (;;) { |
9684 | *app = ap = (union node *)stalloc(sizeof (struct narg)); | 9681 | *app = ap = (union node *)stalloc(sizeof(struct narg)); |
9685 | ap->type = NARG; | 9682 | ap->type = NARG; |
9686 | ap->narg.text = wordtext; | 9683 | ap->narg.text = wordtext; |
9687 | ap->narg.backquote = backquotelist; | 9684 | ap->narg.backquote = backquotelist; |
@@ -9708,7 +9705,7 @@ next_case: | |||
9708 | *cpp = NULL; | 9705 | *cpp = NULL; |
9709 | goto redir; | 9706 | goto redir; |
9710 | case TLP: | 9707 | case TLP: |
9711 | n1 = (union node *)stalloc(sizeof (struct nredir)); | 9708 | n1 = (union node *)stalloc(sizeof(struct nredir)); |
9712 | n1->type = NSUBSHELL; | 9709 | n1->type = NSUBSHELL; |
9713 | n1->nredir.n = list(0); | 9710 | n1->nredir.n = list(0); |
9714 | n1->nredir.redirect = NULL; | 9711 | n1->nredir.redirect = NULL; |
@@ -9740,7 +9737,7 @@ redir: | |||
9740 | *rpp = NULL; | 9737 | *rpp = NULL; |
9741 | if (redir) { | 9738 | if (redir) { |
9742 | if (n1->type != NSUBSHELL) { | 9739 | if (n1->type != NSUBSHELL) { |
9743 | n2 = (union node *)stalloc(sizeof (struct nredir)); | 9740 | n2 = (union node *)stalloc(sizeof(struct nredir)); |
9744 | n2->type = NREDIR; | 9741 | n2->type = NREDIR; |
9745 | n2->nredir.n = n1; | 9742 | n2->nredir.n = n1; |
9746 | n1 = n2; | 9743 | n1 = n2; |
@@ -9772,7 +9769,7 @@ simplecmd(void) { | |||
9772 | checkkwd = savecheckkwd; | 9769 | checkkwd = savecheckkwd; |
9773 | switch (readtoken()) { | 9770 | switch (readtoken()) { |
9774 | case TWORD: | 9771 | case TWORD: |
9775 | n = (union node *)stalloc(sizeof (struct narg)); | 9772 | n = (union node *)stalloc(sizeof(struct narg)); |
9776 | n->type = NARG; | 9773 | n->type = NARG; |
9777 | n->narg.text = wordtext; | 9774 | n->narg.text = wordtext; |
9778 | n->narg.backquote = backquotelist; | 9775 | n->narg.backquote = backquotelist; |
@@ -9824,7 +9821,7 @@ out: | |||
9824 | *app = NULL; | 9821 | *app = NULL; |
9825 | *vpp = NULL; | 9822 | *vpp = NULL; |
9826 | *rpp = NULL; | 9823 | *rpp = NULL; |
9827 | n = (union node *)stalloc(sizeof (struct ncmd)); | 9824 | n = (union node *)stalloc(sizeof(struct ncmd)); |
9828 | n->type = NCMD; | 9825 | n->type = NCMD; |
9829 | n->ncmd.args = args; | 9826 | n->ncmd.args = args; |
9830 | n->ncmd.assign = vars; | 9827 | n->ncmd.assign = vars; |
@@ -9837,7 +9834,7 @@ makename(void) | |||
9837 | { | 9834 | { |
9838 | union node *n; | 9835 | union node *n; |
9839 | 9836 | ||
9840 | n = (union node *)stalloc(sizeof (struct narg)); | 9837 | n = (union node *)stalloc(sizeof(struct narg)); |
9841 | n->type = NARG; | 9838 | n->type = NARG; |
9842 | n->narg.next = NULL; | 9839 | n->narg.next = NULL; |
9843 | n->narg.text = wordtext; | 9840 | n->narg.text = wordtext; |
@@ -9918,7 +9915,7 @@ parseheredoc(void) | |||
9918 | } | 9915 | } |
9919 | readtoken1(pgetc(), here->here->type == NHERE? SQSYNTAX : DQSYNTAX, | 9916 | readtoken1(pgetc(), here->here->type == NHERE? SQSYNTAX : DQSYNTAX, |
9920 | here->eofmark, here->striptabs); | 9917 | here->eofmark, here->striptabs); |
9921 | n = (union node *)stalloc(sizeof (struct narg)); | 9918 | n = (union node *)stalloc(sizeof(struct narg)); |
9922 | n->narg.type = NARG; | 9919 | n->narg.type = NARG; |
9923 | n->narg.next = NULL; | 9920 | n->narg.next = NULL; |
9924 | n->narg.text = wordtext; | 9921 | n->narg.text = wordtext; |
@@ -9993,9 +9990,9 @@ out: | |||
9993 | checkkwd = 0; | 9990 | checkkwd = 0; |
9994 | #if DEBUG | 9991 | #if DEBUG |
9995 | if (!alreadyseen) | 9992 | if (!alreadyseen) |
9996 | TRACE(("token %s %s\n", tokname(t), t == TWORD ? wordtext : "")); | 9993 | TRACE(("token %s %s\n", tokname(t), t == TWORD ? wordtext : "")); |
9997 | else | 9994 | else |
9998 | TRACE(("reread token %s %s\n", tokname(t), t == TWORD ? wordtext : "")); | 9995 | TRACE(("reread token %s %s\n", tokname(t), t == TWORD ? wordtext : "")); |
9999 | #endif | 9996 | #endif |
10000 | return t; | 9997 | return t; |
10001 | } | 9998 | } |
@@ -10283,7 +10280,7 @@ readtoken1(int firstc, int syntax, char *eofmark, int striptabs) | |||
10283 | break; | 10280 | break; |
10284 | case CSQUOTE: | 10281 | case CSQUOTE: |
10285 | syntax = SQSYNTAX; | 10282 | syntax = SQSYNTAX; |
10286 | quotemark: | 10283 | quotemark: |
10287 | if (eofmark == NULL) { | 10284 | if (eofmark == NULL) { |
10288 | USTPUTC(CTLQUOTEMARK, out); | 10285 | USTPUTC(CTLQUOTEMARK, out); |
10289 | } | 10286 | } |
@@ -10293,8 +10290,9 @@ quotemark: | |||
10293 | dblquote = 1; | 10290 | dblquote = 1; |
10294 | goto quotemark; | 10291 | goto quotemark; |
10295 | case CENDQUOTE: | 10292 | case CENDQUOTE: |
10296 | if (eofmark != NULL && arinest == 0 && | 10293 | if (eofmark != NULL && arinest == 0 |
10297 | varnest == 0) { | 10294 | && varnest == 0 |
10295 | ) { | ||
10298 | USTPUTC(c, out); | 10296 | USTPUTC(c, out); |
10299 | } else { | 10297 | } else { |
10300 | if (dqvarnest == 0) { | 10298 | if (dqvarnest == 0) { |
@@ -10369,7 +10367,7 @@ quotemark: | |||
10369 | c = pgetc_macro(); | 10367 | c = pgetc_macro(); |
10370 | } | 10368 | } |
10371 | } | 10369 | } |
10372 | endword: | 10370 | endword: |
10373 | #ifdef CONFIG_ASH_MATH_SUPPORT | 10371 | #ifdef CONFIG_ASH_MATH_SUPPORT |
10374 | if (syntax == ARISYNTAX) | 10372 | if (syntax == ARISYNTAX) |
10375 | synerror("Missing '))'"); | 10373 | synerror("Missing '))'"); |
@@ -10399,7 +10397,8 @@ endword: | |||
10399 | backquotelist = bqlist; | 10397 | backquotelist = bqlist; |
10400 | grabstackblock(len); | 10398 | grabstackblock(len); |
10401 | wordtext = out; | 10399 | wordtext = out; |
10402 | return lasttoken = TWORD; | 10400 | lasttoken = TWORD; |
10401 | return lasttoken; | ||
10403 | /* end of readtoken routine */ | 10402 | /* end of readtoken routine */ |
10404 | 10403 | ||
10405 | 10404 | ||
@@ -10423,7 +10422,7 @@ checkend: { | |||
10423 | } | 10422 | } |
10424 | } | 10423 | } |
10425 | if (c == *eofmark) { | 10424 | if (c == *eofmark) { |
10426 | if (pfgets(line, sizeof line) != NULL) { | 10425 | if (pfgets(line, sizeof(line)) != NULL) { |
10427 | char *p, *q; | 10426 | char *p, *q; |
10428 | 10427 | ||
10429 | p = line; | 10428 | p = line; |
@@ -10452,7 +10451,7 @@ parseredir: { | |||
10452 | char fd = *out; | 10451 | char fd = *out; |
10453 | union node *np; | 10452 | union node *np; |
10454 | 10453 | ||
10455 | np = (union node *)stalloc(sizeof (struct nfile)); | 10454 | np = (union node *)stalloc(sizeof(struct nfile)); |
10456 | if (c == '>') { | 10455 | if (c == '>') { |
10457 | np->nfile.fd = 1; | 10456 | np->nfile.fd = 1; |
10458 | c = pgetc(); | 10457 | c = pgetc(); |
@@ -10470,12 +10469,12 @@ parseredir: { | |||
10470 | np->nfile.fd = 0; | 10469 | np->nfile.fd = 0; |
10471 | switch (c = pgetc()) { | 10470 | switch (c = pgetc()) { |
10472 | case '<': | 10471 | case '<': |
10473 | if (sizeof (struct nfile) != sizeof (struct nhere)) { | 10472 | if (sizeof(struct nfile) != sizeof(struct nhere)) { |
10474 | np = (union node *)stalloc(sizeof (struct nhere)); | 10473 | np = (union node *)stalloc(sizeof(struct nhere)); |
10475 | np->nfile.fd = 0; | 10474 | np->nfile.fd = 0; |
10476 | } | 10475 | } |
10477 | np->type = NHERE; | 10476 | np->type = NHERE; |
10478 | heredoc = (struct heredoc *)stalloc(sizeof (struct heredoc)); | 10477 | heredoc = (struct heredoc *)stalloc(sizeof(struct heredoc)); |
10479 | heredoc->here = np; | 10478 | heredoc->here = np; |
10480 | if ((c = pgetc()) == '-') { | 10479 | if ((c = pgetc()) == '-') { |
10481 | heredoc->striptabs = 1; | 10480 | heredoc->striptabs = 1; |
@@ -10562,13 +10561,11 @@ parsesub: { | |||
10562 | STPUTC(c, out); | 10561 | STPUTC(c, out); |
10563 | c = pgetc(); | 10562 | c = pgetc(); |
10564 | } while (is_digit(c)); | 10563 | } while (is_digit(c)); |
10565 | } | 10564 | } else if (is_special(c)) { |
10566 | else if (is_special(c)) { | ||
10567 | USTPUTC(c, out); | 10565 | USTPUTC(c, out); |
10568 | c = pgetc(); | 10566 | c = pgetc(); |
10569 | } | 10567 | } else |
10570 | else | 10568 | badsub: synerror("Bad substitution"); |
10571 | badsub: synerror("Bad substitution"); | ||
10572 | 10569 | ||
10573 | STPUTC('=', out); | 10570 | STPUTC('=', out); |
10574 | flags = 0; | 10571 | flags = 0; |
@@ -10589,7 +10586,7 @@ badsub: synerror("Bad substitution"); | |||
10589 | { | 10586 | { |
10590 | int cc = c; | 10587 | int cc = c; |
10591 | subtype = c == '#' ? VSTRIMLEFT : | 10588 | subtype = c == '#' ? VSTRIMLEFT : |
10592 | VSTRIMRIGHT; | 10589 | VSTRIMRIGHT; |
10593 | c = pgetc(); | 10590 | c = pgetc(); |
10594 | if (c == cc) | 10591 | if (c == cc) |
10595 | subtype++; | 10592 | subtype++; |
@@ -10686,7 +10683,7 @@ parsebackq: { | |||
10686 | continue; | 10683 | continue; |
10687 | } | 10684 | } |
10688 | if (pc != '\\' && pc != '`' && pc != '$' | 10685 | if (pc != '\\' && pc != '`' && pc != '$' |
10689 | && (!dblquote || pc != '"')) | 10686 | && (!dblquote || pc != '"')) |
10690 | STPUTC('\\', pout); | 10687 | STPUTC('\\', pout); |
10691 | if (pc > PEOA_OR_PEOF) { | 10688 | if (pc > PEOA_OR_PEOF) { |
10692 | break; | 10689 | break; |
@@ -10721,7 +10718,7 @@ done: | |||
10721 | nlpp = &bqlist; | 10718 | nlpp = &bqlist; |
10722 | while (*nlpp) | 10719 | while (*nlpp) |
10723 | nlpp = &(*nlpp)->next; | 10720 | nlpp = &(*nlpp)->next; |
10724 | *nlpp = (struct nodelist *)stalloc(sizeof (struct nodelist)); | 10721 | *nlpp = (struct nodelist *)stalloc(sizeof(struct nodelist)); |
10725 | (*nlpp)->next = NULL; | 10722 | (*nlpp)->next = NULL; |
10726 | parsebackquote = oldstyle; | 10723 | parsebackquote = oldstyle; |
10727 | 10724 | ||
@@ -10776,7 +10773,6 @@ done: | |||
10776 | * Parse an arithmetic expansion (indicate start of one and set state) | 10773 | * Parse an arithmetic expansion (indicate start of one and set state) |
10777 | */ | 10774 | */ |
10778 | parsearith: { | 10775 | parsearith: { |
10779 | |||
10780 | if (++arinest == 1) { | 10776 | if (++arinest == 1) { |
10781 | prevsyntax = syntax; | 10777 | prevsyntax = syntax; |
10782 | syntax = ARISYNTAX; | 10778 | syntax = ARISYNTAX; |
@@ -10835,10 +10831,10 @@ endofname(const char *name) | |||
10835 | char *p; | 10831 | char *p; |
10836 | 10832 | ||
10837 | p = (char *) name; | 10833 | p = (char *) name; |
10838 | if (! is_name(*p)) | 10834 | if (!is_name(*p)) |
10839 | return p; | 10835 | return p; |
10840 | while (*++p) { | 10836 | while (*++p) { |
10841 | if (! is_in_name(*p)) | 10837 | if (!is_in_name(*p)) |
10842 | break; | 10838 | break; |
10843 | } | 10839 | } |
10844 | return p; | 10840 | return p; |
@@ -10930,8 +10926,8 @@ static void setprompt(int whichprompt) | |||
10930 | static const char *const *findkwd(const char *s) | 10926 | static const char *const *findkwd(const char *s) |
10931 | { | 10927 | { |
10932 | return bsearch(s, tokname_array + KWDOFFSET, | 10928 | return bsearch(s, tokname_array + KWDOFFSET, |
10933 | (sizeof(tokname_array) / sizeof(const char *)) - KWDOFFSET, | 10929 | (sizeof(tokname_array) / sizeof(const char *)) - KWDOFFSET, |
10934 | sizeof(const char *), pstrcmp); | 10930 | sizeof(const char *), pstrcmp); |
10935 | } | 10931 | } |
10936 | 10932 | ||
10937 | /* redir.c */ | 10933 | /* redir.c */ |
@@ -10994,8 +10990,8 @@ static int noclobberopen(const char *fname) | |||
10994 | * revealed that it was a regular file, and the file has not been | 10990 | * revealed that it was a regular file, and the file has not been |
10995 | * replaced, return the file descriptor. | 10991 | * replaced, return the file descriptor. |
10996 | */ | 10992 | */ |
10997 | if (fstat(fd, &finfo2) == 0 && !S_ISREG(finfo2.st_mode) && | 10993 | if (fstat(fd, &finfo2) == 0 && !S_ISREG(finfo2.st_mode) |
10998 | finfo.st_dev == finfo2.st_dev && finfo.st_ino == finfo2.st_ino) | 10994 | && finfo.st_dev == finfo2.st_dev && finfo.st_ino == finfo2.st_ino) |
10999 | return fd; | 10995 | return fd; |
11000 | 10996 | ||
11001 | /* The file has been replaced. badness. */ | 10997 | /* The file has been replaced. badness. */ |
@@ -11145,7 +11141,7 @@ redirect(union node *redir, int flags) | |||
11145 | INTOFF; | 11141 | INTOFF; |
11146 | if (flags & REDIR_PUSH) { | 11142 | if (flags & REDIR_PUSH) { |
11147 | struct redirtab *q; | 11143 | struct redirtab *q; |
11148 | q = ckmalloc(sizeof (struct redirtab)); | 11144 | q = ckmalloc(sizeof(struct redirtab)); |
11149 | q->next = redirlist; | 11145 | q->next = redirlist; |
11150 | redirlist = q; | 11146 | redirlist = q; |
11151 | q->nullredirs = nullredirs - 1; | 11147 | q->nullredirs = nullredirs - 1; |
@@ -11157,8 +11153,8 @@ redirect(union node *redir, int flags) | |||
11157 | n = redir; | 11153 | n = redir; |
11158 | do { | 11154 | do { |
11159 | fd = n->nfile.fd; | 11155 | fd = n->nfile.fd; |
11160 | if ((n->nfile.type == NTOFD || n->nfile.type == NFROMFD) && | 11156 | if ((n->nfile.type == NTOFD || n->nfile.type == NFROMFD) |
11161 | n->ndup.dupfd == fd) | 11157 | && n->ndup.dupfd == fd) |
11162 | continue; /* redirect from/to same file descriptor */ | 11158 | continue; /* redirect from/to same file descriptor */ |
11163 | 11159 | ||
11164 | newfd = openredirect(n); | 11160 | newfd = openredirect(n); |
@@ -11458,8 +11454,8 @@ sharg(union node *arg, FILE *fp) | |||
11458 | } | 11454 | } |
11459 | break; | 11455 | break; |
11460 | case CTLENDVAR: | 11456 | case CTLENDVAR: |
11461 | putc('}', fp); | 11457 | putc('}', fp); |
11462 | break; | 11458 | break; |
11463 | case CTLBACKQ: | 11459 | case CTLBACKQ: |
11464 | case CTLBACKQ|CTLQUOTE: | 11460 | case CTLBACKQ|CTLQUOTE: |
11465 | putc('$', fp); | 11461 | putc('$', fp); |
@@ -11776,8 +11772,9 @@ setsignal(int signo) | |||
11776 | return; | 11772 | return; |
11777 | } | 11773 | } |
11778 | if (act.sa_handler == SIG_IGN) { | 11774 | if (act.sa_handler == SIG_IGN) { |
11779 | if (mflag && (signo == SIGTSTP || | 11775 | if (mflag && (signo == SIGTSTP || signo == SIGTTIN |
11780 | signo == SIGTTIN || signo == SIGTTOU)) { | 11776 | || signo == SIGTTOU) |
11777 | ) { | ||
11781 | tsig = S_IGN; /* don't hard ignore these */ | 11778 | tsig = S_IGN; /* don't hard ignore these */ |
11782 | } else | 11779 | } else |
11783 | tsig = S_HARD_IGN; | 11780 | tsig = S_HARD_IGN; |
@@ -11887,11 +11884,11 @@ setinteractive(int on) | |||
11887 | setsignal(SIGQUIT); | 11884 | setsignal(SIGQUIT); |
11888 | setsignal(SIGTERM); | 11885 | setsignal(SIGTERM); |
11889 | #if !ENABLE_FEATURE_SH_EXTRA_QUIET | 11886 | #if !ENABLE_FEATURE_SH_EXTRA_QUIET |
11890 | if(is_interactive > 1) { | 11887 | if (is_interactive > 1) { |
11891 | /* Looks like they want an interactive shell */ | 11888 | /* Looks like they want an interactive shell */ |
11892 | static int do_banner; | 11889 | static int do_banner; |
11893 | 11890 | ||
11894 | if(!do_banner) { | 11891 | if (!do_banner) { |
11895 | out1fmt( | 11892 | out1fmt( |
11896 | "\n\n%s Built-in shell (ash)\n" | 11893 | "\n\n%s Built-in shell (ash)\n" |
11897 | "Enter 'help' for a list of built-in commands.\n\n", | 11894 | "Enter 'help' for a list of built-in commands.\n\n", |
@@ -12083,7 +12080,7 @@ setvareq(char *s, int flags) | |||
12083 | if (flags & VNOSET) | 12080 | if (flags & VNOSET) |
12084 | return; | 12081 | return; |
12085 | /* not found */ | 12082 | /* not found */ |
12086 | vp = ckmalloc(sizeof (*vp)); | 12083 | vp = ckmalloc(sizeof(*vp)); |
12087 | vp->next = *vpp; | 12084 | vp->next = *vpp; |
12088 | vp->func = NULL; | 12085 | vp->func = NULL; |
12089 | *vpp = vp; | 12086 | *vpp = vp; |
@@ -12131,10 +12128,10 @@ lookupvar(const char *name) | |||
12131 | * As soon as they're unset, they're no longer dynamic, and dynamic | 12128 | * As soon as they're unset, they're no longer dynamic, and dynamic |
12132 | * lookup will no longer happen at that point. -- PFM. | 12129 | * lookup will no longer happen at that point. -- PFM. |
12133 | */ | 12130 | */ |
12134 | if((v->flags & VDYNAMIC)) | 12131 | if ((v->flags & VDYNAMIC)) |
12135 | (*v->func)(NULL); | 12132 | (*v->func)(NULL); |
12136 | #endif | 12133 | #endif |
12137 | if(!(v->flags & VUNSET)) | 12134 | if (!(v->flags & VUNSET)) |
12138 | return strchrnul(v->text, '=') + 1; | 12135 | return strchrnul(v->text, '=') + 1; |
12139 | } | 12136 | } |
12140 | 12137 | ||
@@ -12275,7 +12272,7 @@ static void mklocal(char *name) | |||
12275 | struct var *vp; | 12272 | struct var *vp; |
12276 | 12273 | ||
12277 | INTOFF; | 12274 | INTOFF; |
12278 | lvp = ckmalloc(sizeof (struct localvar)); | 12275 | lvp = ckmalloc(sizeof(struct localvar)); |
12279 | if (LONE_DASH(name)) { | 12276 | if (LONE_DASH(name)) { |
12280 | char *p; | 12277 | char *p; |
12281 | p = ckmalloc(sizeof(optlist)); | 12278 | p = ckmalloc(sizeof(optlist)); |
@@ -12568,7 +12565,7 @@ letcmd(int argc, char **argv) | |||
12568 | arith_t i = 0; | 12565 | arith_t i = 0; |
12569 | 12566 | ||
12570 | ap = argv + 1; | 12567 | ap = argv + 1; |
12571 | if(!*ap) | 12568 | if (!*ap) |
12572 | sh_error("expression expected"); | 12569 | sh_error("expression expected"); |
12573 | for (ap = argv + 1; *ap; ap++) { | 12570 | for (ap = argv + 1; *ap; ap++) { |
12574 | i = dash_arith(*ap); | 12571 | i = dash_arith(*ap); |
@@ -12695,11 +12692,11 @@ readcmd(int argc, char **argv) | |||
12695 | tcgetattr(0, &tty); | 12692 | tcgetattr(0, &tty); |
12696 | old_tty = tty; | 12693 | old_tty = tty; |
12697 | if (nch_flag) { | 12694 | if (nch_flag) { |
12698 | tty.c_lflag &= ~ICANON; | 12695 | tty.c_lflag &= ~ICANON; |
12699 | tty.c_cc[VMIN] = nchars; | 12696 | tty.c_cc[VMIN] = nchars; |
12700 | } | 12697 | } |
12701 | if (silent) { | 12698 | if (silent) { |
12702 | tty.c_lflag &= ~(ECHO|ECHOK|ECHONL); | 12699 | tty.c_lflag &= ~(ECHO|ECHOK|ECHONL); |
12703 | 12700 | ||
12704 | } | 12701 | } |
12705 | tcsetattr(0, TCSANOW, &tty); | 12702 | tcsetattr(0, TCSANOW, &tty); |
@@ -12964,7 +12961,7 @@ ulimitcmd(int argc, char **argv) | |||
12964 | #ifdef RLIMIT_LOCKS | 12961 | #ifdef RLIMIT_LOCKS |
12965 | "w" | 12962 | "w" |
12966 | #endif | 12963 | #endif |
12967 | )) != '\0') | 12964 | )) != '\0') |
12968 | switch (optc) { | 12965 | switch (optc) { |
12969 | case 'H': | 12966 | case 'H': |
12970 | how = HARD; | 12967 | how = HARD; |
@@ -12993,8 +12990,7 @@ ulimitcmd(int argc, char **argv) | |||
12993 | else { | 12990 | else { |
12994 | val = (rlim_t) 0; | 12991 | val = (rlim_t) 0; |
12995 | 12992 | ||
12996 | while ((c = *p++) >= '0' && c <= '9') | 12993 | while ((c = *p++) >= '0' && c <= '9') { |
12997 | { | ||
12998 | val = (val * 10) + (long)(c - '0'); | 12994 | val = (val * 10) + (long)(c - '0'); |
12999 | if (val < (rlim_t) 0) | 12995 | if (val < (rlim_t) 0) |
13000 | break; | 12996 | break; |
@@ -13158,7 +13154,7 @@ typedef unsigned char operator; | |||
13158 | #define TOK_REM_ASSIGN tok_decl(3,2) | 13154 | #define TOK_REM_ASSIGN tok_decl(3,2) |
13159 | 13155 | ||
13160 | /* all assign is right associativity and precedence eq, but (7+3)<<5 > 256 */ | 13156 | /* all assign is right associativity and precedence eq, but (7+3)<<5 > 256 */ |
13161 | #define convert_prec_is_assing(prec) do { if(prec == 3) prec = 2; } while(0) | 13157 | #define convert_prec_is_assing(prec) do { if (prec == 3) prec = 2; } while (0) |
13162 | 13158 | ||
13163 | /* conditional is right associativity too */ | 13159 | /* conditional is right associativity too */ |
13164 | #define TOK_CONDITIONAL tok_decl(4,0) | 13160 | #define TOK_CONDITIONAL tok_decl(4,0) |
@@ -13231,8 +13227,8 @@ static int tok_have_assign(operator op) | |||
13231 | 13227 | ||
13232 | static int is_right_associativity(operator prec) | 13228 | static int is_right_associativity(operator prec) |
13233 | { | 13229 | { |
13234 | return (prec == PREC(TOK_ASSIGN) || prec == PREC(TOK_EXPONENT) || | 13230 | return (prec == PREC(TOK_ASSIGN) || prec == PREC(TOK_EXPONENT) |
13235 | prec == PREC(TOK_CONDITIONAL)); | 13231 | || prec == PREC(TOK_CONDITIONAL)); |
13236 | } | 13232 | } |
13237 | 13233 | ||
13238 | 13234 | ||
@@ -13255,38 +13251,37 @@ static chk_var_recursive_looped_t *prev_chk_var_recursive; | |||
13255 | 13251 | ||
13256 | static int arith_lookup_val(v_n_t *t) | 13252 | static int arith_lookup_val(v_n_t *t) |
13257 | { | 13253 | { |
13258 | if(t->var) { | 13254 | if (t->var) { |
13259 | const char * p = lookupvar(t->var); | 13255 | const char * p = lookupvar(t->var); |
13260 | 13256 | ||
13261 | if(p) { | 13257 | if (p) { |
13262 | int errcode; | 13258 | int errcode; |
13263 | 13259 | ||
13264 | /* recursive try as expression */ | 13260 | /* recursive try as expression */ |
13265 | chk_var_recursive_looped_t *cur; | 13261 | chk_var_recursive_looped_t *cur; |
13266 | chk_var_recursive_looped_t cur_save; | 13262 | chk_var_recursive_looped_t cur_save; |
13267 | 13263 | ||
13268 | for(cur = prev_chk_var_recursive; cur; cur = cur->next) { | 13264 | for (cur = prev_chk_var_recursive; cur; cur = cur->next) { |
13269 | if(strcmp(cur->var, t->var) == 0) { | 13265 | if (strcmp(cur->var, t->var) == 0) { |
13270 | /* expression recursion loop detected */ | 13266 | /* expression recursion loop detected */ |
13271 | return -5; | 13267 | return -5; |
13272 | } | 13268 | } |
13273 | } | 13269 | } |
13274 | /* save current lookuped var name */ | 13270 | /* save current lookuped var name */ |
13275 | cur = prev_chk_var_recursive; | 13271 | cur = prev_chk_var_recursive; |
13276 | cur_save.var = t->var; | 13272 | cur_save.var = t->var; |
13277 | cur_save.next = cur; | 13273 | cur_save.next = cur; |
13278 | prev_chk_var_recursive = &cur_save; | 13274 | prev_chk_var_recursive = &cur_save; |
13279 | 13275 | ||
13280 | t->val = arith (p, &errcode); | 13276 | t->val = arith (p, &errcode); |
13281 | /* restore previous ptr after recursiving */ | 13277 | /* restore previous ptr after recursiving */ |
13282 | prev_chk_var_recursive = cur; | 13278 | prev_chk_var_recursive = cur; |
13283 | return errcode; | 13279 | return errcode; |
13284 | } else { | 13280 | } |
13285 | /* allow undefined var as 0 */ | 13281 | /* allow undefined var as 0 */ |
13286 | t->val = 0; | 13282 | t->val = 0; |
13287 | } | 13283 | } |
13288 | } | 13284 | return 0; |
13289 | return 0; | ||
13290 | } | 13285 | } |
13291 | 13286 | ||
13292 | /* "applying" a token means performing it on the top elements on the integer | 13287 | /* "applying" a token means performing it on the top elements on the integer |
@@ -13298,13 +13293,13 @@ static int arith_apply(operator op, v_n_t *numstack, v_n_t **numstackptr) | |||
13298 | arith_t numptr_val, rez; | 13293 | arith_t numptr_val, rez; |
13299 | int ret_arith_lookup_val; | 13294 | int ret_arith_lookup_val; |
13300 | 13295 | ||
13301 | if (NUMPTR == numstack) goto err; /* There is no operator that can work | 13296 | /* There is no operator that can work without arguments */ |
13302 | without arguments */ | 13297 | if (NUMPTR == numstack) goto err; |
13303 | numptr_m1 = NUMPTR - 1; | 13298 | numptr_m1 = NUMPTR - 1; |
13304 | 13299 | ||
13305 | /* check operand is var with noninteger value */ | 13300 | /* check operand is var with noninteger value */ |
13306 | ret_arith_lookup_val = arith_lookup_val(numptr_m1); | 13301 | ret_arith_lookup_val = arith_lookup_val(numptr_m1); |
13307 | if(ret_arith_lookup_val) | 13302 | if (ret_arith_lookup_val) |
13308 | return ret_arith_lookup_val; | 13303 | return ret_arith_lookup_val; |
13309 | 13304 | ||
13310 | rez = numptr_m1->val; | 13305 | rez = numptr_m1->val; |
@@ -13321,102 +13316,102 @@ static int arith_apply(operator op, v_n_t *numstack, v_n_t **numstackptr) | |||
13321 | else if (op != TOK_UPLUS) { | 13316 | else if (op != TOK_UPLUS) { |
13322 | /* Binary operators */ | 13317 | /* Binary operators */ |
13323 | 13318 | ||
13324 | /* check and binary operators need two arguments */ | 13319 | /* check and binary operators need two arguments */ |
13325 | if (numptr_m1 == numstack) goto err; | 13320 | if (numptr_m1 == numstack) goto err; |
13326 | 13321 | ||
13327 | /* ... and they pop one */ | 13322 | /* ... and they pop one */ |
13328 | --NUMPTR; | 13323 | --NUMPTR; |
13329 | numptr_val = rez; | 13324 | numptr_val = rez; |
13330 | if (op == TOK_CONDITIONAL) { | 13325 | if (op == TOK_CONDITIONAL) { |
13331 | if(! numptr_m1->contidional_second_val_initialized) { | 13326 | if (! numptr_m1->contidional_second_val_initialized) { |
13332 | /* protect $((expr1 ? expr2)) without ": expr" */ | 13327 | /* protect $((expr1 ? expr2)) without ": expr" */ |
13333 | goto err; | 13328 | goto err; |
13334 | } | 13329 | } |
13335 | rez = numptr_m1->contidional_second_val; | 13330 | rez = numptr_m1->contidional_second_val; |
13336 | } else if(numptr_m1->contidional_second_val_initialized) { | 13331 | } else if (numptr_m1->contidional_second_val_initialized) { |
13337 | /* protect $((expr1 : expr2)) without "expr ? " */ | 13332 | /* protect $((expr1 : expr2)) without "expr ? " */ |
13338 | goto err; | 13333 | goto err; |
13339 | } | 13334 | } |
13340 | numptr_m1 = NUMPTR - 1; | 13335 | numptr_m1 = NUMPTR - 1; |
13341 | if(op != TOK_ASSIGN) { | 13336 | if (op != TOK_ASSIGN) { |
13342 | /* check operand is var with noninteger value for not '=' */ | 13337 | /* check operand is var with noninteger value for not '=' */ |
13343 | ret_arith_lookup_val = arith_lookup_val(numptr_m1); | 13338 | ret_arith_lookup_val = arith_lookup_val(numptr_m1); |
13344 | if(ret_arith_lookup_val) | 13339 | if (ret_arith_lookup_val) |
13345 | return ret_arith_lookup_val; | 13340 | return ret_arith_lookup_val; |
13346 | } | 13341 | } |
13347 | if (op == TOK_CONDITIONAL) { | 13342 | if (op == TOK_CONDITIONAL) { |
13348 | numptr_m1->contidional_second_val = rez; | 13343 | numptr_m1->contidional_second_val = rez; |
13349 | } | 13344 | } |
13350 | rez = numptr_m1->val; | 13345 | rez = numptr_m1->val; |
13351 | if (op == TOK_BOR || op == TOK_OR_ASSIGN) | 13346 | if (op == TOK_BOR || op == TOK_OR_ASSIGN) |
13352 | rez |= numptr_val; | 13347 | rez |= numptr_val; |
13353 | else if (op == TOK_OR) | 13348 | else if (op == TOK_OR) |
13354 | rez = numptr_val || rez; | 13349 | rez = numptr_val || rez; |
13355 | else if (op == TOK_BAND || op == TOK_AND_ASSIGN) | 13350 | else if (op == TOK_BAND || op == TOK_AND_ASSIGN) |
13356 | rez &= numptr_val; | 13351 | rez &= numptr_val; |
13357 | else if (op == TOK_BXOR || op == TOK_XOR_ASSIGN) | 13352 | else if (op == TOK_BXOR || op == TOK_XOR_ASSIGN) |
13358 | rez ^= numptr_val; | 13353 | rez ^= numptr_val; |
13359 | else if (op == TOK_AND) | 13354 | else if (op == TOK_AND) |
13360 | rez = rez && numptr_val; | 13355 | rez = rez && numptr_val; |
13361 | else if (op == TOK_EQ) | 13356 | else if (op == TOK_EQ) |
13362 | rez = (rez == numptr_val); | 13357 | rez = (rez == numptr_val); |
13363 | else if (op == TOK_NE) | 13358 | else if (op == TOK_NE) |
13364 | rez = (rez != numptr_val); | 13359 | rez = (rez != numptr_val); |
13365 | else if (op == TOK_GE) | 13360 | else if (op == TOK_GE) |
13366 | rez = (rez >= numptr_val); | 13361 | rez = (rez >= numptr_val); |
13367 | else if (op == TOK_RSHIFT || op == TOK_RSHIFT_ASSIGN) | 13362 | else if (op == TOK_RSHIFT || op == TOK_RSHIFT_ASSIGN) |
13368 | rez >>= numptr_val; | 13363 | rez >>= numptr_val; |
13369 | else if (op == TOK_LSHIFT || op == TOK_LSHIFT_ASSIGN) | 13364 | else if (op == TOK_LSHIFT || op == TOK_LSHIFT_ASSIGN) |
13370 | rez <<= numptr_val; | 13365 | rez <<= numptr_val; |
13371 | else if (op == TOK_GT) | 13366 | else if (op == TOK_GT) |
13372 | rez = (rez > numptr_val); | 13367 | rez = (rez > numptr_val); |
13373 | else if (op == TOK_LT) | 13368 | else if (op == TOK_LT) |
13374 | rez = (rez < numptr_val); | 13369 | rez = (rez < numptr_val); |
13375 | else if (op == TOK_LE) | 13370 | else if (op == TOK_LE) |
13376 | rez = (rez <= numptr_val); | 13371 | rez = (rez <= numptr_val); |
13377 | else if (op == TOK_MUL || op == TOK_MUL_ASSIGN) | 13372 | else if (op == TOK_MUL || op == TOK_MUL_ASSIGN) |
13378 | rez *= numptr_val; | 13373 | rez *= numptr_val; |
13379 | else if (op == TOK_ADD || op == TOK_PLUS_ASSIGN) | 13374 | else if (op == TOK_ADD || op == TOK_PLUS_ASSIGN) |
13380 | rez += numptr_val; | 13375 | rez += numptr_val; |
13381 | else if (op == TOK_SUB || op == TOK_MINUS_ASSIGN) | 13376 | else if (op == TOK_SUB || op == TOK_MINUS_ASSIGN) |
13382 | rez -= numptr_val; | 13377 | rez -= numptr_val; |
13383 | else if (op == TOK_ASSIGN || op == TOK_COMMA) | 13378 | else if (op == TOK_ASSIGN || op == TOK_COMMA) |
13384 | rez = numptr_val; | 13379 | rez = numptr_val; |
13385 | else if (op == TOK_CONDITIONAL_SEP) { | 13380 | else if (op == TOK_CONDITIONAL_SEP) { |
13386 | if (numptr_m1 == numstack) { | 13381 | if (numptr_m1 == numstack) { |
13387 | /* protect $((expr : expr)) without "expr ? " */ | 13382 | /* protect $((expr : expr)) without "expr ? " */ |
13388 | goto err; | 13383 | goto err; |
13389 | } | 13384 | } |
13390 | numptr_m1->contidional_second_val_initialized = op; | 13385 | numptr_m1->contidional_second_val_initialized = op; |
13391 | numptr_m1->contidional_second_val = numptr_val; | 13386 | numptr_m1->contidional_second_val = numptr_val; |
13392 | } | 13387 | } |
13393 | else if (op == TOK_CONDITIONAL) { | 13388 | else if (op == TOK_CONDITIONAL) { |
13394 | rez = rez ? | 13389 | rez = rez ? |
13395 | numptr_val : numptr_m1->contidional_second_val; | 13390 | numptr_val : numptr_m1->contidional_second_val; |
13396 | } | 13391 | } |
13397 | else if(op == TOK_EXPONENT) { | 13392 | else if (op == TOK_EXPONENT) { |
13398 | if(numptr_val < 0) | 13393 | if (numptr_val < 0) |
13399 | return -3; /* exponent less than 0 */ | 13394 | return -3; /* exponent less than 0 */ |
13400 | else { | 13395 | else { |
13401 | arith_t c = 1; | 13396 | arith_t c = 1; |
13402 | 13397 | ||
13403 | if(numptr_val) | 13398 | if (numptr_val) |
13404 | while(numptr_val--) | 13399 | while (numptr_val--) |
13405 | c *= rez; | 13400 | c *= rez; |
13406 | rez = c; | 13401 | rez = c; |
13407 | } | 13402 | } |
13408 | } | 13403 | } |
13409 | else if(numptr_val==0) /* zero divisor check */ | 13404 | else if (numptr_val==0) /* zero divisor check */ |
13410 | return -2; | 13405 | return -2; |
13411 | else if (op == TOK_DIV || op == TOK_DIV_ASSIGN) | 13406 | else if (op == TOK_DIV || op == TOK_DIV_ASSIGN) |
13412 | rez /= numptr_val; | 13407 | rez /= numptr_val; |
13413 | else if (op == TOK_REM || op == TOK_REM_ASSIGN) | 13408 | else if (op == TOK_REM || op == TOK_REM_ASSIGN) |
13414 | rez %= numptr_val; | 13409 | rez %= numptr_val; |
13415 | } | 13410 | } |
13416 | if(tok_have_assign(op)) { | 13411 | if (tok_have_assign(op)) { |
13417 | char buf[32]; | 13412 | char buf[32]; |
13418 | 13413 | ||
13419 | if(numptr_m1->var == NULL) { | 13414 | if (numptr_m1->var == NULL) { |
13420 | /* Hmm, 1=2 ? */ | 13415 | /* Hmm, 1=2 ? */ |
13421 | goto err; | 13416 | goto err; |
13422 | } | 13417 | } |
@@ -13428,9 +13423,9 @@ static int arith_apply(operator op, v_n_t *numstack, v_n_t **numstackptr) | |||
13428 | #endif | 13423 | #endif |
13429 | setvar(numptr_m1->var, buf, 0); | 13424 | setvar(numptr_m1->var, buf, 0); |
13430 | /* after saving, make previous value for v++ or v-- */ | 13425 | /* after saving, make previous value for v++ or v-- */ |
13431 | if(op == TOK_POST_INC) | 13426 | if (op == TOK_POST_INC) |
13432 | rez--; | 13427 | rez--; |
13433 | else if(op == TOK_POST_DEC) | 13428 | else if (op == TOK_POST_DEC) |
13434 | rez++; | 13429 | rez++; |
13435 | } | 13430 | } |
13436 | numptr_m1->val = rez; | 13431 | numptr_m1->val = rez; |
@@ -13491,73 +13486,74 @@ static const char op_tokens[] = { | |||
13491 | 13486 | ||
13492 | static arith_t arith(const char *expr, int *perrcode) | 13487 | static arith_t arith(const char *expr, int *perrcode) |
13493 | { | 13488 | { |
13494 | char arithval; /* Current character under analysis */ | 13489 | char arithval; /* Current character under analysis */ |
13495 | operator lasttok, op; | 13490 | operator lasttok, op; |
13496 | operator prec; | 13491 | operator prec; |
13497 | 13492 | ||
13498 | const char *p = endexpression; | 13493 | const char *p = endexpression; |
13499 | int errcode; | 13494 | int errcode; |
13500 | 13495 | ||
13501 | size_t datasizes = strlen(expr) + 2; | 13496 | size_t datasizes = strlen(expr) + 2; |
13502 | 13497 | ||
13503 | /* Stack of integers */ | 13498 | /* Stack of integers */ |
13504 | /* The proof that there can be no more than strlen(startbuf)/2+1 integers | 13499 | /* The proof that there can be no more than strlen(startbuf)/2+1 integers |
13505 | * in any given correct or incorrect expression is left as an exercise to | 13500 | * in any given correct or incorrect expression is left as an exercise to |
13506 | * the reader. */ | 13501 | * the reader. */ |
13507 | v_n_t *numstack = alloca(((datasizes)/2)*sizeof(v_n_t)), | 13502 | v_n_t *numstack = alloca(((datasizes)/2)*sizeof(v_n_t)), |
13508 | *numstackptr = numstack; | 13503 | *numstackptr = numstack; |
13509 | /* Stack of operator tokens */ | 13504 | /* Stack of operator tokens */ |
13510 | operator *stack = alloca((datasizes) * sizeof(operator)), | 13505 | operator *stack = alloca((datasizes) * sizeof(operator)), |
13511 | *stackptr = stack; | 13506 | *stackptr = stack; |
13512 | 13507 | ||
13513 | *stackptr++ = lasttok = TOK_LPAREN; /* start off with a left paren */ | 13508 | *stackptr++ = lasttok = TOK_LPAREN; /* start off with a left paren */ |
13514 | *perrcode = errcode = 0; | 13509 | *perrcode = errcode = 0; |
13515 | 13510 | ||
13516 | while(1) { | 13511 | while (1) { |
13517 | if ((arithval = *expr) == 0) { | 13512 | if ((arithval = *expr) == 0) { |
13518 | if (p == endexpression) { | 13513 | if (p == endexpression) { |
13519 | /* Null expression. */ | 13514 | /* Null expression. */ |
13520 | return 0; | 13515 | return 0; |
13521 | } | 13516 | } |
13522 | 13517 | ||
13523 | /* This is only reached after all tokens have been extracted from the | 13518 | /* This is only reached after all tokens have been extracted from the |
13524 | * input stream. If there are still tokens on the operator stack, they | 13519 | * input stream. If there are still tokens on the operator stack, they |
13525 | * are to be applied in order. At the end, there should be a final | 13520 | * are to be applied in order. At the end, there should be a final |
13526 | * result on the integer stack */ | 13521 | * result on the integer stack */ |
13527 | 13522 | ||
13528 | if (expr != endexpression + 1) { | 13523 | if (expr != endexpression + 1) { |
13529 | /* If we haven't done so already, */ | 13524 | /* If we haven't done so already, */ |
13530 | /* append a closing right paren */ | 13525 | /* append a closing right paren */ |
13531 | expr = endexpression; | 13526 | expr = endexpression; |
13532 | /* and let the loop process it. */ | 13527 | /* and let the loop process it. */ |
13533 | continue; | 13528 | continue; |
13534 | } | 13529 | } |
13535 | /* At this point, we're done with the expression. */ | 13530 | /* At this point, we're done with the expression. */ |
13536 | if (numstackptr != numstack+1) { | 13531 | if (numstackptr != numstack+1) { |
13537 | /* ... but if there isn't, it's bad */ | 13532 | /* ... but if there isn't, it's bad */ |
13538 | err: | 13533 | err: |
13539 | return (*perrcode = -1); | 13534 | return (*perrcode = -1); |
13540 | } | 13535 | } |
13541 | if(numstack->var) { | 13536 | if (numstack->var) { |
13542 | /* expression is $((var)) only, lookup now */ | 13537 | /* expression is $((var)) only, lookup now */ |
13543 | errcode = arith_lookup_val(numstack); | 13538 | errcode = arith_lookup_val(numstack); |
13539 | } | ||
13540 | ret: | ||
13541 | *perrcode = errcode; | ||
13542 | return numstack->val; | ||
13544 | } | 13543 | } |
13545 | ret: | 13544 | |
13546 | *perrcode = errcode; | ||
13547 | return numstack->val; | ||
13548 | } else { | ||
13549 | /* Continue processing the expression. */ | 13545 | /* Continue processing the expression. */ |
13550 | if (arith_isspace(arithval)) { | 13546 | if (arith_isspace(arithval)) { |
13551 | /* Skip whitespace */ | 13547 | /* Skip whitespace */ |
13552 | goto prologue; | 13548 | goto prologue; |
13553 | } | 13549 | } |
13554 | if((p = endofname(expr)) != expr) { | 13550 | if ((p = endofname(expr)) != expr) { |
13555 | size_t var_name_size = (p-expr) + 1; /* trailing zero */ | 13551 | size_t var_name_size = (p-expr) + 1; /* trailing zero */ |
13556 | 13552 | ||
13557 | numstackptr->var = alloca(var_name_size); | 13553 | numstackptr->var = alloca(var_name_size); |
13558 | safe_strncpy(numstackptr->var, expr, var_name_size); | 13554 | safe_strncpy(numstackptr->var, expr, var_name_size); |
13559 | expr = p; | 13555 | expr = p; |
13560 | num: | 13556 | num: |
13561 | numstackptr->contidional_second_val_initialized = 0; | 13557 | numstackptr->contidional_second_val_initialized = 0; |
13562 | numstackptr++; | 13558 | numstackptr++; |
13563 | lasttok = TOK_NUM; | 13559 | lasttok = TOK_NUM; |
@@ -13571,22 +13567,22 @@ static arith_t arith(const char *expr, int *perrcode) | |||
13571 | #endif | 13567 | #endif |
13572 | goto num; | 13568 | goto num; |
13573 | } | 13569 | } |
13574 | for(p = op_tokens; ; p++) { | 13570 | for (p = op_tokens; ; p++) { |
13575 | const char *o; | 13571 | const char *o; |
13576 | 13572 | ||
13577 | if(*p == 0) { | 13573 | if (*p == 0) { |
13578 | /* strange operator not found */ | 13574 | /* strange operator not found */ |
13579 | goto err; | 13575 | goto err; |
13580 | } | 13576 | } |
13581 | for(o = expr; *p && *o == *p; p++) | 13577 | for (o = expr; *p && *o == *p; p++) |
13582 | o++; | 13578 | o++; |
13583 | if(! *p) { | 13579 | if (! *p) { |
13584 | /* found */ | 13580 | /* found */ |
13585 | expr = o - 1; | 13581 | expr = o - 1; |
13586 | break; | 13582 | break; |
13587 | } | 13583 | } |
13588 | /* skip tail uncompared token */ | 13584 | /* skip tail uncompared token */ |
13589 | while(*p) | 13585 | while (*p) |
13590 | p++; | 13586 | p++; |
13591 | /* skip zero delim */ | 13587 | /* skip zero delim */ |
13592 | p++; | 13588 | p++; |
@@ -13594,8 +13590,8 @@ static arith_t arith(const char *expr, int *perrcode) | |||
13594 | op = p[1]; | 13590 | op = p[1]; |
13595 | 13591 | ||
13596 | /* post grammar: a++ reduce to num */ | 13592 | /* post grammar: a++ reduce to num */ |
13597 | if(lasttok == TOK_POST_INC || lasttok == TOK_POST_DEC) | 13593 | if (lasttok == TOK_POST_INC || lasttok == TOK_POST_DEC) |
13598 | lasttok = TOK_NUM; | 13594 | lasttok = TOK_NUM; |
13599 | 13595 | ||
13600 | /* Plus and minus are binary (not unary) _only_ if the last | 13596 | /* Plus and minus are binary (not unary) _only_ if the last |
13601 | * token was as number, or a right paren (which pretends to be | 13597 | * token was as number, or a right paren (which pretends to be |
@@ -13603,18 +13599,18 @@ static arith_t arith(const char *expr, int *perrcode) | |||
13603 | * It makes sense. */ | 13599 | * It makes sense. */ |
13604 | if (lasttok != TOK_NUM) { | 13600 | if (lasttok != TOK_NUM) { |
13605 | switch (op) { | 13601 | switch (op) { |
13606 | case TOK_ADD: | 13602 | case TOK_ADD: |
13607 | op = TOK_UPLUS; | 13603 | op = TOK_UPLUS; |
13608 | break; | 13604 | break; |
13609 | case TOK_SUB: | 13605 | case TOK_SUB: |
13610 | op = TOK_UMINUS; | 13606 | op = TOK_UMINUS; |
13611 | break; | 13607 | break; |
13612 | case TOK_POST_INC: | 13608 | case TOK_POST_INC: |
13613 | op = TOK_PRE_INC; | 13609 | op = TOK_PRE_INC; |
13614 | break; | 13610 | break; |
13615 | case TOK_POST_DEC: | 13611 | case TOK_POST_DEC: |
13616 | op = TOK_PRE_DEC; | 13612 | op = TOK_PRE_DEC; |
13617 | break; | 13613 | break; |
13618 | } | 13614 | } |
13619 | } | 13615 | } |
13620 | /* We don't want a unary operator to cause recursive descent on the | 13616 | /* We don't want a unary operator to cause recursive descent on the |
@@ -13636,30 +13632,30 @@ static arith_t arith(const char *expr, int *perrcode) | |||
13636 | goto err; | 13632 | goto err; |
13637 | } | 13633 | } |
13638 | while (stackptr != stack) { | 13634 | while (stackptr != stack) { |
13639 | if (op == TOK_RPAREN) { | 13635 | if (op == TOK_RPAREN) { |
13640 | /* The algorithm employed here is simple: while we don't | 13636 | /* The algorithm employed here is simple: while we don't |
13641 | * hit an open paren nor the bottom of the stack, pop | 13637 | * hit an open paren nor the bottom of the stack, pop |
13642 | * tokens and apply them */ | 13638 | * tokens and apply them */ |
13643 | if (stackptr[-1] == TOK_LPAREN) { | 13639 | if (stackptr[-1] == TOK_LPAREN) { |
13644 | --stackptr; | 13640 | --stackptr; |
13645 | /* Any operator directly after a */ | 13641 | /* Any operator directly after a */ |
13646 | lasttok = TOK_NUM; | 13642 | lasttok = TOK_NUM; |
13647 | /* close paren should consider itself binary */ | 13643 | /* close paren should consider itself binary */ |
13648 | goto prologue; | 13644 | goto prologue; |
13649 | } | 13645 | } |
13650 | } else { | 13646 | } else { |
13651 | operator prev_prec = PREC(stackptr[-1]); | 13647 | operator prev_prec = PREC(stackptr[-1]); |
13652 | 13648 | ||
13653 | convert_prec_is_assing(prec); | 13649 | convert_prec_is_assing(prec); |
13654 | convert_prec_is_assing(prev_prec); | 13650 | convert_prec_is_assing(prev_prec); |
13655 | if (prev_prec < prec) | 13651 | if (prev_prec < prec) |
13656 | break; | 13652 | break; |
13657 | /* check right assoc */ | 13653 | /* check right assoc */ |
13658 | if(prev_prec == prec && is_right_associativity(prec)) | 13654 | if (prev_prec == prec && is_right_associativity(prec)) |
13659 | break; | 13655 | break; |
13660 | } | 13656 | } |
13661 | errcode = arith_apply(*--stackptr, numstack, &numstackptr); | 13657 | errcode = arith_apply(*--stackptr, numstack, &numstackptr); |
13662 | if(errcode) goto ret; | 13658 | if (errcode) goto ret; |
13663 | } | 13659 | } |
13664 | if (op == TOK_RPAREN) { | 13660 | if (op == TOK_RPAREN) { |
13665 | goto err; | 13661 | goto err; |
@@ -13668,11 +13664,9 @@ static arith_t arith(const char *expr, int *perrcode) | |||
13668 | 13664 | ||
13669 | /* Push this operator to the stack and remember it. */ | 13665 | /* Push this operator to the stack and remember it. */ |
13670 | *stackptr++ = lasttok = op; | 13666 | *stackptr++ = lasttok = op; |
13671 | 13667 | prologue: | |
13672 | prologue: | ||
13673 | ++expr; | 13668 | ++expr; |
13674 | } | 13669 | } /* while */ |
13675 | } | ||
13676 | } | 13670 | } |
13677 | #endif /* CONFIG_ASH_MATH_SUPPORT */ | 13671 | #endif /* CONFIG_ASH_MATH_SUPPORT */ |
13678 | 13672 | ||