- Timestamp:
- Apr 21, 2007 10:17:42 PM (18 years ago)
- Location:
- trunk/src/ash-messup
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/ash-messup/Makefile.kmk
r882 r884 30 30 kmk_ash_INCS.win = win 31 31 kmk_ash_SOURCES = \ 32 main.c \ 32 33 alias.c \ 33 34 cd.c \ … … 40 41 jobs.c \ 41 42 mail.c \ 42 main.c \43 43 memalloc.c \ 44 44 miscbltin.c \ -
trunk/src/ash-messup/eval.c
r883 r884 87 87 #include "myhistedit.h" 88 88 #endif 89 #include "shinstance.h" 89 90 90 91 … … 94 95 #define EV_BACKCMD 04 /* command executing within back quotes */ 95 96 96 int evalskip;/* set if we are skipping commands */97 STATIC int skipcount;/* number of levels to skip */98 MKINIT int loopnest;/* current loop nesting level */99 int funcnest;/* depth of function calls */97 /*int evalskip;*/ /* set if we are skipping commands */ 98 /*STATIC int skipcount;*/ /* number of levels to skip */ 99 /*MKINIT int loopnest;*/ /* current loop nesting level */ 100 /*int funcnest;*/ /* depth of function calls */ 100 101 101 102 102 103 /*char *commandname;*/ 103 struct strlist *cmdenviron; 104 int exitstatus;/* exit status of last command */105 int back_exitstatus;/* exit status of backquoted command */106 107 108 STATIC void evalloop( union node *, int);109 STATIC void evalfor( union node *, int);110 STATIC void evalcase( union node *, int);111 STATIC void evalsubshell( union node *, int);112 STATIC void expredir( union node *);113 STATIC void evalpipe( union node *);114 STATIC void evalcommand( union node *, int, struct backcmd *);115 STATIC void prehash( union node *);104 /*struct strlist *cmdenviron;*/ 105 /*int exitstatus;*/ /* exit status of last command */ 106 /*int back_exitstatus;*/ /* exit status of backquoted command */ 107 108 109 STATIC void evalloop(shinstance *, union node *, int); 110 STATIC void evalfor(shinstance *, union node *, int); 111 STATIC void evalcase(shinstance *, union node *, int); 112 STATIC void evalsubshell(shinstance *, union node *, int); 113 STATIC void expredir(shinstance *, union node *); 114 STATIC void evalpipe(shinstance *, union node *); 115 STATIC void evalcommand(shinstance *, union node *, int, struct backcmd *); 116 STATIC void prehash(shinstance *, union node *); 116 117 117 118 … … 135 136 136 137 static int 137 sh_pipe( int fds[2])138 sh_pipe(shinstance *psh, int fds[2]) 138 139 { 139 140 int nfd; 140 141 141 if ( pipe(fds))142 if (shfile_pipe(&psh->fdtab, fds)) 142 143 return -1; 143 144 144 145 if (fds[0] < 3) { 145 nfd = fcntl(fds[0], F_DUPFD, 3);146 nfd = shfile_fcntl(&psh->fdtab, fds[0], F_DUPFD, 3); 146 147 if (nfd != -1) { 147 close(fds[0]);148 shfile_close(&psh->fdtab, fds[0]); 148 149 fds[0] = nfd; 149 150 } … … 151 152 152 153 if (fds[1] < 3) { 153 nfd = fcntl(fds[1], F_DUPFD, 3);154 nfd = shfile_fcntl(&psh->fdtab, fds[1], F_DUPFD, 3); 154 155 if (nfd != -1) { 155 close(fds[1]);156 shfile_close(&psh->fdtab, fds[1]); 156 157 fds[1] = nfd; 157 158 } … … 166 167 167 168 int 168 evalcmd( int argc, char **argv)169 evalcmd(shinstance *psh, int argc, char **argv) 169 170 { 170 171 char *p; … … 187 188 p = grabstackstr(concat); 188 189 } 189 evalstring(p , EV_TESTED);190 evalstring(psh, p, EV_TESTED); 190 191 } 191 return exitstatus;192 return psh->exitstatus; 192 193 } 193 194 … … 198 199 199 200 void 200 evalstring( char *s, int flag)201 evalstring(shinstance *psh, char *s, int flag) 201 202 { 202 203 union node *n; 203 204 struct stackmark smark; 204 205 205 setstackmark( &smark);206 setinputstring( s, 1);207 208 while ((n = parsecmd( 0)) != NEOF) {209 evaltree( n, flag);210 popstackmark( &smark);211 } 212 popfile( );213 popstackmark( &smark);206 setstackmark(psh, &smark); 207 setinputstring(psh, s, 1); 208 209 while ((n = parsecmd(psh, 0)) != NEOF) { 210 evaltree(psh, n, flag); 211 popstackmark(psh, &smark); 212 } 213 popfile(psh); 214 popstackmark(psh, &smark); 214 215 } 215 216 … … 222 223 223 224 void 224 evaltree( union node *n, int flags)225 evaltree(shinstance *psh, union node *n, int flags) 225 226 { 226 227 if (n == NULL) { 227 228 TRACE(("evaltree(NULL) called\n")); 228 exitstatus = 0;229 psh->exitstatus = 0; 229 230 goto out; 230 231 } 231 232 #ifndef SMALL 232 displayhist = 1; /* show history substitutions done with fc */233 psh->displayhist = 1; /* show history substitutions done with fc */ 233 234 #endif 234 235 TRACE(("pid %d, evaltree(%p: %d, %d) called\n", … … 236 237 switch (n->type) { 237 238 case NSEMI: 238 evaltree( n->nbinary.ch1, flags & EV_TESTED);239 if ( evalskip)239 evaltree(psh, n->nbinary.ch1, flags & EV_TESTED); 240 if (psh->evalskip) 240 241 goto out; 241 evaltree( n->nbinary.ch2, flags);242 evaltree(psh, n->nbinary.ch2, flags); 242 243 break; 243 244 case NAND: 244 evaltree( n->nbinary.ch1, EV_TESTED);245 if ( evalskip ||exitstatus != 0)245 evaltree(psh, n->nbinary.ch1, EV_TESTED); 246 if (psh->evalskip || psh->exitstatus != 0) 246 247 goto out; 247 evaltree( n->nbinary.ch2, flags);248 evaltree(psh, n->nbinary.ch2, flags); 248 249 break; 249 250 case NOR: 250 evaltree( n->nbinary.ch1, EV_TESTED);251 if ( evalskip ||exitstatus == 0)251 evaltree(psh, n->nbinary.ch1, EV_TESTED); 252 if (psh->evalskip || psh->exitstatus == 0) 252 253 goto out; 253 evaltree( n->nbinary.ch2, flags);254 evaltree(psh, n->nbinary.ch2, flags); 254 255 break; 255 256 case NREDIR: 256 expredir( n->nredir.redirect);257 redirect( n->nredir.redirect, REDIR_PUSH);258 evaltree( n->nredir.n, flags);259 popredir( );257 expredir(psh, n->nredir.redirect); 258 redirect(psh, n->nredir.redirect, REDIR_PUSH); 259 evaltree(psh, n->nredir.n, flags); 260 popredir(psh); 260 261 break; 261 262 case NSUBSHELL: 262 evalsubshell( n, flags);263 evalsubshell(psh, n, flags); 263 264 break; 264 265 case NBACKGND: 265 evalsubshell( n, flags);266 evalsubshell(psh, n, flags); 266 267 break; 267 268 case NIF: { 268 evaltree( n->nif.test, EV_TESTED);269 if ( evalskip)269 evaltree(psh, n->nif.test, EV_TESTED); 270 if (psh->evalskip) 270 271 goto out; 271 if ( exitstatus == 0)272 evaltree( n->nif.ifpart, flags);272 if (psh->exitstatus == 0) 273 evaltree(psh, n->nif.ifpart, flags); 273 274 else if (n->nif.elsepart) 274 evaltree( n->nif.elsepart, flags);275 evaltree(psh, n->nif.elsepart, flags); 275 276 else 276 exitstatus = 0;277 psh->exitstatus = 0; 277 278 break; 278 279 } 279 280 case NWHILE: 280 281 case NUNTIL: 281 evalloop( n, flags);282 evalloop(psh, n, flags); 282 283 break; 283 284 case NFOR: 284 evalfor( n, flags);285 evalfor(psh, n, flags); 285 286 break; 286 287 case NCASE: 287 evalcase( n, flags);288 evalcase(psh, n, flags); 288 289 break; 289 290 case NDEFUN: 290 defun( n->narg.text, n->narg.next);291 exitstatus = 0;291 defun(psh, n->narg.text, n->narg.next); 292 psh->exitstatus = 0; 292 293 break; 293 294 case NNOT: 294 evaltree( n->nnot.com, EV_TESTED);295 exitstatus = !exitstatus;295 evaltree(psh, n->nnot.com, EV_TESTED); 296 psh->exitstatus = !psh->exitstatus; 296 297 break; 297 298 case NPIPE: 298 evalpipe( n);299 evalpipe(psh, n); 299 300 break; 300 301 case NCMD: 301 evalcommand( n, flags, (struct backcmd *)NULL);302 evalcommand(psh, n, flags, (struct backcmd *)NULL); 302 303 break; 303 304 default: 304 out1fmt( "Node type = %d\n", n->type);305 flushout(& output);305 out1fmt(psh, "Node type = %d\n", n->type); 306 flushout(&psh->output); 306 307 break; 307 308 } 308 309 out: 309 if (p endingsigs)310 dotrap( );310 if (psh->pendingsigs) 311 dotrap(psh); 311 312 if ((flags & EV_EXIT) != 0) 312 exitshell( exitstatus);313 exitshell(psh, psh->exitstatus); 313 314 } 314 315 315 316 316 317 STATIC void 317 evalloop( union node *n, int flags)318 evalloop(shinstance *psh, union node *n, int flags) 318 319 { 319 320 int status; 320 321 321 loopnest++;322 psh->loopnest++; 322 323 status = 0; 323 324 for (;;) { 324 evaltree( n->nbinary.ch1, EV_TESTED);325 if ( evalskip) {326 skipping: if ( evalskip == SKIPCONT && --skipcount <= 0) {327 evalskip = 0;325 evaltree(psh, n->nbinary.ch1, EV_TESTED); 326 if (psh->evalskip) { 327 skipping: if (psh->evalskip == SKIPCONT && --psh->skipcount <= 0) { 328 psh->evalskip = 0; 328 329 continue; 329 330 } 330 if ( evalskip == SKIPBREAK && --skipcount <= 0)331 evalskip = 0;331 if (psh->evalskip == SKIPBREAK && --psh->skipcount <= 0) 332 psh->evalskip = 0; 332 333 break; 333 334 } 334 335 if (n->type == NWHILE) { 335 if ( exitstatus != 0)336 if (psh->exitstatus != 0) 336 337 break; 337 338 } else { 338 if ( exitstatus == 0)339 if (psh->exitstatus == 0) 339 340 break; 340 341 } 341 evaltree( n->nbinary.ch2, flags & EV_TESTED);342 status = exitstatus;343 if ( evalskip)342 evaltree(psh, n->nbinary.ch2, flags & EV_TESTED); 343 status = psh->exitstatus; 344 if (psh->evalskip) 344 345 goto skipping; 345 346 } 346 loopnest--;347 exitstatus = status;347 psh->loopnest--; 348 psh->exitstatus = status; 348 349 } 349 350 … … 351 352 352 353 STATIC void 353 evalfor( union node *n, int flags)354 evalfor(shinstance *psh, union node *n, int flags) 354 355 { 355 356 struct arglist arglist; … … 359 360 int status = 0; 360 361 361 setstackmark( &smark);362 setstackmark(psh, &smark); 362 363 arglist.lastp = &arglist.list; 363 364 for (argp = n->nfor.args ; argp ; argp = argp->narg.next) { 364 expandarg( argp, &arglist, EXP_FULL | EXP_TILDE);365 if ( evalskip)365 expandarg(psh, argp, &arglist, EXP_FULL | EXP_TILDE); 366 if (psh->evalskip) 366 367 goto out; 367 368 } 368 369 *arglist.lastp = NULL; 369 370 370 loopnest++;371 psh->loopnest++; 371 372 for (sp = arglist.list ; sp ; sp = sp->next) { 372 setvar( n->nfor.var, sp->text, 0);373 evaltree( n->nfor.body, flags & EV_TESTED);374 status = exitstatus;375 if ( evalskip) {376 if ( evalskip == SKIPCONT && --skipcount <= 0) {377 evalskip = 0;373 setvar(psh, n->nfor.var, sp->text, 0); 374 evaltree(psh, n->nfor.body, flags & EV_TESTED); 375 status = psh->exitstatus; 376 if (psh->evalskip) { 377 if (psh->evalskip == SKIPCONT && --psh->skipcount <= 0) { 378 psh->evalskip = 0; 378 379 continue; 379 380 } 380 if ( evalskip == SKIPBREAK && --skipcount <= 0)381 evalskip = 0;381 if (psh->evalskip == SKIPBREAK && --psh->skipcount <= 0) 382 psh->evalskip = 0; 382 383 break; 383 384 } 384 385 } 385 loopnest--;386 exitstatus = status;386 psh->loopnest--; 387 psh->exitstatus = status; 387 388 out: 388 popstackmark( &smark);389 popstackmark(psh, &smark); 389 390 } 390 391 … … 392 393 393 394 STATIC void 394 evalcase( union node *n, int flags)395 evalcase(shinstance *psh, union node *n, int flags) 395 396 { 396 397 union node *cp; … … 400 401 int status = 0; 401 402 402 setstackmark( &smark);403 setstackmark(psh, &smark); 403 404 arglist.lastp = &arglist.list; 404 expandarg( n->ncase.expr, &arglist, EXP_TILDE);405 for (cp = n->ncase.cases ; cp && evalskip == 0 ; cp = cp->nclist.next) {405 expandarg(psh, n->ncase.expr, &arglist, EXP_TILDE); 406 for (cp = n->ncase.cases ; cp && psh->evalskip == 0 ; cp = cp->nclist.next) { 406 407 for (patp = cp->nclist.pattern ; patp ; patp = patp->narg.next) { 407 if (casematch(p atp, arglist.list->text)) {408 if ( evalskip == 0) {409 evaltree( cp->nclist.body, flags);410 status = exitstatus;408 if (casematch(psh, patp, arglist.list->text)) { 409 if (psh->evalskip == 0) { 410 evaltree(psh, cp->nclist.body, flags); 411 status = psh->exitstatus; 411 412 } 412 413 goto out; … … 415 416 } 416 417 out: 417 exitstatus = status;418 popstackmark( &smark);418 psh->exitstatus = status; 419 popstackmark(psh, &smark); 419 420 } 420 421 … … 426 427 427 428 STATIC void 428 evalsubshell( union node *n, int flags)429 evalsubshell(shinstance *psh, union node *n, int flags) 429 430 { 430 431 struct job *jp; 431 432 int backgnd = (n->type == NBACKGND); 432 433 433 expredir( n->nredir.redirect);434 expredir(psh, n->nredir.redirect); 434 435 INTOFF; 435 jp = makejob( n, 1);436 if (forkshell( jp, n, backgnd ? FORK_BG : FORK_FG) == 0) {436 jp = makejob(psh, n, 1); 437 if (forkshell(psh, jp, n, backgnd ? FORK_BG : FORK_FG) == 0) { 437 438 INTON; 438 439 if (backgnd) 439 440 flags &=~ EV_TESTED; 440 redirect( n->nredir.redirect, 0);441 redirect(psh, n->nredir.redirect, 0); 441 442 /* never returns */ 442 evaltree( n->nredir.n, flags | EV_EXIT);443 evaltree(psh, n->nredir.n, flags | EV_EXIT); 443 444 } 444 445 if (! backgnd) 445 exitstatus = waitforjob(jp);446 psh->exitstatus = waitforjob(psh, jp); 446 447 INTON; 447 448 } … … 454 455 455 456 STATIC void 456 expredir( union node *n)457 expredir(shinstance *psh, union node *n) 457 458 { 458 459 union node *redir; … … 467 468 case NCLOBBER: 468 469 case NAPPEND: 469 expandarg( redir->nfile.fname, &fn, EXP_TILDE | EXP_REDIR);470 expandarg(psh, redir->nfile.fname, &fn, EXP_TILDE | EXP_REDIR); 470 471 redir->nfile.expfname = fn.list->text; 471 472 break; … … 473 474 case NTOFD: 474 475 if (redir->ndup.vname) { 475 expandarg( redir->ndup.vname, &fn, EXP_FULL | EXP_TILDE);476 fixredir( redir, fn.list->text, 1);476 expandarg(psh, redir->ndup.vname, &fn, EXP_FULL | EXP_TILDE); 477 fixredir(psh, redir, fn.list->text, 1); 477 478 } 478 479 break; … … 491 492 492 493 STATIC void 493 evalpipe( union node *n)494 evalpipe(shinstance *psh, union node *n) 494 495 { 495 496 struct job *jp; … … 504 505 pipelen++; 505 506 INTOFF; 506 jp = makejob( n, pipelen);507 jp = makejob(psh, n, pipelen); 507 508 prevfd = -1; 508 509 for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) { 509 prehash( lp->n);510 prehash(psh, lp->n); 510 511 pip[1] = -1; 511 512 if (lp->next) { 512 if (sh_pipe(p ip) < 0) {513 close(prevfd);514 error( "Pipe call failed");515 } 516 } 517 if (forkshell( jp, lp->n, n->npipe.backgnd ? FORK_BG : FORK_FG) == 0) {513 if (sh_pipe(psh, pip) < 0) { 514 shfile_close(&psh->fdtab, prevfd); 515 error(psh, "Pipe call failed"); 516 } 517 } 518 if (forkshell(psh, jp, lp->n, n->npipe.backgnd ? FORK_BG : FORK_FG) == 0) { 518 519 INTON; 519 520 if (prevfd > 0) { 520 close(0);521 copyfd(p revfd, 0);522 close(prevfd);521 shfile_close(&psh->fdtab, 0); 522 copyfd(psh, prevfd, 0); 523 shfile_close(&psh->fdtab, prevfd); 523 524 } 524 525 if (pip[1] >= 0) { 525 close(pip[0]);526 shfile_close(&psh->fdtab, pip[0]); 526 527 if (pip[1] != 1) { 527 close(1);528 copyfd(p ip[1], 1);529 close(pip[1]);528 shfile_close(&psh->fdtab, 1); 529 copyfd(psh, pip[1], 1); 530 shfile_close(&psh->fdtab, pip[1]); 530 531 } 531 532 } 532 evaltree( lp->n, EV_EXIT);533 evaltree(psh, lp->n, EV_EXIT); 533 534 } 534 535 if (prevfd >= 0) 535 close(prevfd);536 shfile_close(&psh->fdtab, prevfd); 536 537 prevfd = pip[0]; 537 close(pip[1]);538 shfile_close(&psh->fdtab, pip[1]); 538 539 } 539 540 if (n->npipe.backgnd == 0) { 540 exitstatus = waitforjob(jp);541 TRACE(("evalpipe: job done exit status %d\n", exitstatus));541 psh->exitstatus = waitforjob(psh, jp); 542 TRACE(("evalpipe: job done exit status %d\n", psh->exitstatus)); 542 543 } 543 544 INTON; … … 554 555 555 556 void 556 evalbackcmd( union node *n, struct backcmd *result)557 evalbackcmd(shinstance *psh, union node *n, struct backcmd *result) 557 558 { 558 559 int pip[2]; … … 560 561 struct stackmark smark; /* unnecessary */ 561 562 562 setstackmark( &smark);563 setstackmark(psh, &smark); 563 564 result->fd = -1; 564 565 result->buf = NULL; … … 576 577 */ 577 578 if (n->type == NCMD) { 578 exitstatus = oexitstatus;579 evalcommand( n, EV_BACKCMD, result);579 psh->exitstatus = opsh->exitstatus; 580 evalcommand(psh, n, EV_BACKCMD, result); 580 581 } else 581 582 #endif 582 583 { 583 584 INTOFF; 584 if (sh_pipe(p ip) < 0)585 error( "Pipe call failed");586 jp = makejob( n, 1);587 if (forkshell( jp, n, FORK_NOJOB) == 0) {585 if (sh_pipe(psh, pip) < 0) 586 error(psh, "Pipe call failed"); 587 jp = makejob(psh, n, 1); 588 if (forkshell(psh, jp, n, FORK_NOJOB) == 0) { 588 589 FORCEINTON; 589 close(pip[0]);590 shfile_close(&psh->fdtab, pip[0]); 590 591 if (pip[1] != 1) { 591 close(1);592 copyfd(p ip[1], 1);593 close(pip[1]);594 } 595 eflag = 0;596 evaltree( n, EV_EXIT);592 shfile_close(&psh->fdtab, 1); 593 copyfd(psh, pip[1], 1); 594 shfile_close(&psh->fdtab, pip[1]); 595 } 596 psh->eflag = 0; 597 evaltree(psh, n, EV_EXIT); 597 598 /* NOTREACHED */ 598 599 } 599 close(pip[1]);600 shfile_close(&psh->fdtab, pip[1]); 600 601 result->fd = pip[0]; 601 602 result->jp = jp; … … 603 604 } 604 605 out: 605 popstackmark( &smark);606 popstackmark(psh, &smark); 606 607 TRACE(("evalbackcmd done: fd=%d buf=0x%x nleft=%d jp=0x%x\n", 607 608 result->fd, result->buf, result->nleft, result->jp)); … … 609 610 610 611 static const char * 611 syspath( void)612 syspath(shinstance *psh) 612 613 { 613 614 #ifdef CTL_USER … … 641 642 642 643 static int 643 parse_command_args( int argc, char **argv, int *use_syspath)644 parse_command_args(shinstance *psh, int argc, char **argv, int *use_syspath) 644 645 { 645 646 int sv_argc = argc; … … 674 675 } 675 676 676 int vforked = 0; 677 /*int vforked = 0;*/ 677 678 678 679 /* … … 681 682 682 683 STATIC void 683 evalcommand( union node *cmd, int flags, struct backcmd *backcmd)684 evalcommand(shinstance *psh, union node *cmd, int flags, struct backcmd *backcmd) 684 685 { 685 686 struct stackmark smark; … … 703 704 volatile int e; 704 705 char *lastarg; 705 const char *path = pathval( );706 const char *path = pathval(psh); 706 707 volatile int temp_path; 707 708 #if __GNUC__ … … 713 714 #endif 714 715 715 vforked = 0;716 psh->vforked = 0; 716 717 /* First expand the arguments. */ 717 718 TRACE(("evalcommand(0x%lx, %d) called\n", (long)cmd, flags)); 718 setstackmark( &smark);719 back_exitstatus = 0;719 setstackmark(psh, &smark); 720 psh->exitstatus = 0; 720 721 721 722 arglist.lastp = &arglist.list; … … 731 732 continue; 732 733 } 733 expandarg( argp, &arglist, EXP_FULL | EXP_TILDE);734 expandarg(psh, argp, &arglist, EXP_FULL | EXP_TILDE); 734 735 varflag = 0; 735 736 } 736 737 *arglist.lastp = NULL; 737 738 738 expredir( cmd->ncmd.redirect);739 expredir(psh, cmd->ncmd.redirect); 739 740 740 741 /* Now do the initial 'name=value' ones we skipped above */ … … 749 750 if (*p != '=') 750 751 break; 751 expandarg( argp, &varlist, EXP_VARTILDE);752 expandarg(psh, argp, &varlist, EXP_VARTILDE); 752 753 } 753 754 *varlist.lastp = NULL; … … 756 757 for (sp = arglist.list ; sp ; sp = sp->next) 757 758 argc++; 758 argv = stalloc( sizeof (char *) * (argc + 1));759 argv = stalloc(psh, sizeof (char *) * (argc + 1)); 759 760 760 761 for (sp = arglist.list ; sp ; sp = sp->next) { … … 764 765 *argv = NULL; 765 766 lastarg = NULL; 766 if ( iflag &&funcnest == 0 && argc > 0)767 if (psh->iflag && psh->funcnest == 0 && argc > 0) 767 768 lastarg = argv[-1]; 768 769 argv -= argc; 769 770 770 771 /* Print the command if xflag is set. */ 771 if ( xflag) {772 if (psh->xflag) { 772 773 char sep = 0; 773 out2str(ps 4val());774 out2str(psh, ps4val(psh)); 774 775 for (sp = varlist.list ; sp ; sp = sp->next) { 775 776 if (sep != 0) 776 outc(sep, & errout);777 out2str( sp->text);777 outc(sep, &psh->errout); 778 out2str(psh, sp->text); 778 779 sep = ' '; 779 780 } 780 781 for (sp = arglist.list ; sp ; sp = sp->next) { 781 782 if (sep != 0) 782 outc(sep, & errout);783 out2str( sp->text);783 outc(sep, &psh->errout); 784 out2str(psh, sp->text); 784 785 sep = ' '; 785 786 } 786 outc('\n', & errout);787 flushout(& errout);787 outc('\n', &psh->errout); 788 flushout(&psh->errout); 788 789 } 789 790 … … 806 807 do { 807 808 int argsused, use_syspath; 808 find_command( argv[0], &cmdentry, cmd_flags, path);809 find_command(psh, argv[0], &cmdentry, cmd_flags, path); 809 810 if (cmdentry.cmdtype == CMDUNKNOWN) { 810 exitstatus = 127;811 flushout(& errout);811 psh->exitstatus = 127; 812 flushout(&psh->errout); 812 813 goto out; 813 814 } … … 818 819 break; 819 820 cmd_flags |= DO_NOFUNC; 820 argsused = parse_command_args( argc, argv, &use_syspath);821 argsused = parse_command_args(psh, argc, argv, &use_syspath); 821 822 if (argsused == 0) { 822 823 /* use 'type' builting to display info */ … … 827 828 argv += argsused; 828 829 if (use_syspath) 829 path = syspath( ) + 5;830 path = syspath(psh) + 5; 830 831 } while (argc != 0); 831 832 if (cmdentry.cmdtype == CMDSPLBLTIN && cmd_flags & DO_NOFUNC) … … 843 844 || cmdentry.u.bltin == evalcmd))) { 844 845 INTOFF; 845 jp = makejob( cmd, 1);846 jp = makejob(psh, cmd, 1); 846 847 mode = cmd->ncmd.backgnd; 847 848 if (flags & EV_BACKCMD) { 848 849 mode = FORK_NOJOB; 849 if (sh_pipe(p ip) < 0)850 error( "Pipe call failed");850 if (sh_pipe(psh, pip) < 0) 851 error(psh, "Pipe call failed"); 851 852 } 852 853 #ifdef DO_SHAREDVFORK … … 858 859 pid_t pid; 859 860 860 savelocalvars = localvars;861 localvars = NULL;862 vforked = 1;861 savelocalvars = psh->localvars; 862 psh->localvars = NULL; 863 psh->vforked = 1; 863 864 switch (pid = vfork()) { 864 865 case -1: 865 866 TRACE(("Vfork failed, errno=%d\n", errno)); 866 867 INTON; 867 error( "Cannot vfork");868 error(psh, "Cannot vfork"); 868 869 break; 869 870 case 0: … … 872 873 */ 873 874 if (setjmp(jmploc.loc)) { 874 if ( exception == EXSHELLPROC) {875 if (psh->exception == EXSHELLPROC) { 875 876 /* We can't progress with the vfork, 876 877 * so, set vforked = 2 so the parent 877 878 * knows, and _exit(); 878 879 */ 879 vforked = 2;880 _exit(0);880 psh->vforked = 2; 881 sh__exit(psh, 0); 881 882 } else { 882 _exit(exerrno);883 sh__exit(psh, exerrno); 883 884 } 884 885 } 885 savehandler = handler;886 handler = &jmploc;887 listmklocal( varlist.list, VEXPORT | VNOFUNC);888 forkchild( jp, cmd, mode,vforked);886 savehandler = psh->handler; 887 psh->handler = &jmploc; 888 listmklocal(psh, varlist.list, VEXPORT | VNOFUNC); 889 forkchild(psh, jp, cmd, mode, psh->vforked); 889 890 break; 890 891 default: 891 handler = savehandler; /* restore from vfork(2) */892 poplocalvars( );893 localvars = savelocalvars;894 if ( vforked == 2) {895 vforked = 0;896 897 (void) waitpid(pid, NULL, 0);892 psh->handler = savehandler; /* restore from vfork(2) */ 893 poplocalvars(psh); 894 psh->localvars = savelocalvars; 895 if (psh->vforked == 2) { 896 psh->vforked = 0; 897 898 (void)sh_waitpid(psh, pid, NULL, 0); 898 899 /* We need to progress in a normal fork fashion */ 899 900 goto normal_fork; 900 901 } 901 vforked = 0;902 forkparent( jp, cmd, mode, pid);902 psh->vforked = 0; 903 forkparent(psh, jp, cmd, mode, pid); 903 904 goto parent; 904 905 } … … 906 907 normal_fork: 907 908 #endif 908 if (forkshell( jp, cmd, mode) != 0)909 if (forkshell(psh, jp, cmd, mode) != 0) 909 910 goto parent; /* at end of routine */ 910 911 FORCEINTON; … … 913 914 #endif 914 915 if (flags & EV_BACKCMD) { 915 if (! vforked) {916 if (!psh->vforked) { 916 917 FORCEINTON; 917 918 } 918 close(pip[0]);919 shfile_close(&psh->fdtab, pip[0]); 919 920 if (pip[1] != 1) { 920 close(1);921 copyfd(p ip[1], 1);922 close(pip[1]);921 shfile_close(&psh->fdtab, 1); 922 copyfd(psh, pip[1], 1); 923 shfile_close(&psh->fdtab, pip[1]); 923 924 } 924 925 } … … 933 934 trputs("Shell function: "); trargs(argv); 934 935 #endif 935 redirect( cmd->ncmd.redirect, REDIR_PUSH);936 saveparam = shellparam;937 shellparam.malloc = 0;938 shellparam.reset = 1;939 shellparam.nparam = argc - 1;940 shellparam.p = argv + 1;941 shellparam.optnext = NULL;936 redirect(psh, cmd->ncmd.redirect, REDIR_PUSH); 937 saveparam = psh->shellparam; 938 psh->shellparam.malloc = 0; 939 psh->shellparam.reset = 1; 940 psh->shellparam.nparam = argc - 1; 941 psh->shellparam.p = argv + 1; 942 psh->shellparam.optnext = NULL; 942 943 INTOFF; 943 savelocalvars = localvars;944 localvars = NULL;944 savelocalvars = psh->localvars; 945 psh->localvars = NULL; 945 946 INTON; 946 947 if (setjmp(jmploc.loc)) { 947 if ( exception == EXSHELLPROC) {948 if (psh->exception == EXSHELLPROC) { 948 949 freeparam((volatile struct shparam *) 949 950 &saveparam); 950 951 } else { 951 freeparam(& shellparam);952 shellparam = saveparam;953 } 954 poplocalvars( );955 localvars = savelocalvars;956 handler = savehandler;957 longjmp( handler->loc, 1);958 } 959 savehandler = handler;960 handler = &jmploc;961 listmklocal( varlist.list, 0);952 freeparam(&psh->shellparam); 953 psh->shellparam = saveparam; 954 } 955 poplocalvars(psh); 956 psh->localvars = savelocalvars; 957 psh->handler = savehandler; 958 longjmp(psh->handler->loc, 1); 959 } 960 savehandler = psh->handler; 961 psh->handler = &jmploc; 962 listmklocal(psh, varlist.list, 0); 962 963 /* stop shell blowing its stack */ 963 if (++ funcnest > 1000)964 error( "too many nested function calls");965 evaltree( cmdentry.u.func, flags & EV_TESTED);966 funcnest--;964 if (++psh->funcnest > 1000) 965 error(psh, "too many nested function calls"); 966 evaltree(psh, cmdentry.u.func, flags & EV_TESTED); 967 psh->funcnest--; 967 968 INTOFF; 968 poplocalvars( );969 localvars = savelocalvars;970 freeparam(& shellparam);971 shellparam = saveparam;972 handler = savehandler;973 popredir( );969 poplocalvars(psh); 970 psh->localvars = savelocalvars; 971 freeparam(&psh->shellparam); 972 psh->shellparam = saveparam; 973 psh->handler = savehandler; 974 popredir(psh); 974 975 INTON; 975 if ( evalskip == SKIPFUNC) {976 evalskip = 0;977 skipcount = 0;976 if (psh->evalskip == SKIPFUNC) { 977 psh->evalskip = 0; 978 psh->skipcount = 0; 978 979 } 979 980 if (flags & EV_EXIT) 980 exitshell( exitstatus);981 exitshell(psh, psh->exitstatus); 981 982 break; 982 983 … … 988 989 mode = (cmdentry.u.bltin == execcmd) ? 0 : REDIR_PUSH; 989 990 if (flags == EV_BACKCMD) { 990 memout.nleft = 0;991 memout.nextc =memout.buf;992 memout.bufsize = 64;991 psh->memout.nleft = 0; 992 psh->memout.nextc = psh->memout.buf; 993 psh->memout.bufsize = 64; 993 994 mode |= REDIR_BACKQ; 994 995 } 995 996 e = -1; 996 savehandler = handler;997 savecmdname = commandname;998 handler = &jmploc;997 savehandler = psh->handler; 998 savecmdname = psh->commandname; 999 psh->handler = &jmploc; 999 1000 if (!setjmp(jmploc.loc)) { 1000 1001 /* We need to ensure the command hash table isn't … … 1002 1003 * However we must ensure the 'local' command works! 1003 1004 */ 1004 if (path != pathval( ) && (cmdentry.u.bltin == hashcmd ||1005 if (path != pathval(psh) && (cmdentry.u.bltin == hashcmd || 1005 1006 cmdentry.u.bltin == typecmd)) { 1006 savelocalvars = localvars;1007 localvars = 0;1008 mklocal(p ath - 5 /* PATH= */, 0);1007 savelocalvars = psh->localvars; 1008 psh->localvars = 0; 1009 mklocal(psh, path - 5 /* PATH= */, 0); 1009 1010 temp_path = 1; 1010 1011 } else 1011 1012 temp_path = 0; 1012 redirect( cmd->ncmd.redirect, mode);1013 redirect(psh, cmd->ncmd.redirect, mode); 1013 1014 1014 1015 /* exec is a special builtin, but needs this list... */ 1015 cmdenviron = varlist.list;1016 psh->cmdenviron = varlist.list; 1016 1017 /* we must check 'readonly' flag for all builtins */ 1017 listsetvar( varlist.list,1018 listsetvar(psh, varlist.list, 1018 1019 cmdentry.cmdtype == CMDSPLBLTIN ? 0 : VNOSET); 1019 commandname = argv[0];1020 psh->commandname = argv[0]; 1020 1021 /* initialize nextopt */ 1021 argptr = argv + 1;1022 optptr = NULL;1022 psh->argptr = argv + 1; 1023 psh->optptr = NULL; 1023 1024 /* and getopt */ 1025 /** @todo fix getop usage! */ 1024 1026 #if defined(__FreeBSD__) || defined(__EMX__) || defined(__APPLE__) 1025 1027 optreset = 1; … … 1029 1031 #endif 1030 1032 1031 exitstatus = cmdentry.u.bltin(argc, argv);1033 psh->exitstatus = cmdentry.u.bltin(psh, argc, argv); 1032 1034 } else { 1033 e = exception;1034 exitstatus = e == EXINT ? SIGINT + 128 :1035 e == EXEXEC ? exerrno : 2;1036 } 1037 handler = savehandler;1038 output_flushall( );1039 out1 = &output;1040 out2 = &errout;1041 freestdout( );1035 e = psh->exception; 1036 psh->exitstatus = e == EXINT ? SIGINT + 128 : 1037 e == EXEXEC ? psh->exerrno : 2; 1038 } 1039 psh->handler = savehandler; 1040 output_flushall(psh); 1041 psh->out1 = &psh->output; 1042 psh->out2 = &psh->errout; 1043 freestdout(psh); 1042 1044 if (temp_path) { 1043 poplocalvars( );1044 localvars = savelocalvars;1045 } 1046 cmdenviron = NULL;1045 poplocalvars(psh); 1046 psh->localvars = savelocalvars; 1047 } 1048 psh->cmdenviron = NULL; 1047 1049 if (e != EXSHELLPROC) { 1048 commandname = savecmdname;1050 psh->commandname = savecmdname; 1049 1051 if (flags & EV_EXIT) 1050 exitshell( exitstatus);1052 exitshell(psh, psh->exitstatus); 1051 1053 } 1052 1054 if (e != -1) { 1053 1055 if ((e != EXERROR && e != EXEXEC) 1054 1056 || cmdentry.cmdtype == CMDSPLBLTIN) 1055 exraise( e);1057 exraise(psh, e); 1056 1058 FORCEINTON; 1057 1059 } 1058 1060 if (cmdentry.u.bltin != execcmd) 1059 popredir( );1061 popredir(psh); 1060 1062 if (flags == EV_BACKCMD) { 1061 backcmd->buf = memout.buf;1062 backcmd->nleft = memout.nextc -memout.buf;1063 memout.buf = NULL;1063 backcmd->buf = psh->memout.buf; 1064 backcmd->nleft = psh->memout.nextc - psh->memout.buf; 1065 psh->memout.buf = NULL; 1064 1066 } 1065 1067 break; … … 1069 1071 trputs("normal command: "); trargs(argv); 1070 1072 #endif 1071 clearredir( vforked);1072 redirect( cmd->ncmd.redirect,vforked ? REDIR_VFORK : 0);1073 if (! vforked)1073 clearredir(psh, psh->vforked); 1074 redirect(psh, cmd->ncmd.redirect, psh->vforked ? REDIR_VFORK : 0); 1075 if (!psh->vforked) 1074 1076 for (sp = varlist.list ; sp ; sp = sp->next) 1075 setvareq( sp->text, VEXPORT|VSTACK);1076 envp = environment( );1077 shellexec( argv, envp, path, cmdentry.u.index,vforked);1077 setvareq(psh, sp->text, VEXPORT|VSTACK); 1078 envp = environment(psh); 1079 shellexec(psh, argv, envp, path, cmdentry.u.index, psh->vforked); 1078 1080 break; 1079 1081 } … … 1082 1084 parent: /* parent process gets here (if we forked) */ 1083 1085 if (mode == FORK_FG) { /* argument to fork */ 1084 exitstatus = waitforjob(jp);1086 psh->exitstatus = waitforjob(psh, jp); 1085 1087 } else if (mode == FORK_NOJOB) { 1086 1088 backcmd->fd = pip[0]; 1087 close(pip[1]);1089 shfile_close(&psh->fdtab, pip[1]); 1088 1090 backcmd->jp = jp; 1089 1091 } … … 1096 1098 * However I implemented that within libedit itself. 1097 1099 */ 1098 setvar( "_", lastarg, 0);1099 popstackmark( &smark);1100 1101 if ( eflag &&exitstatus && !(flags & EV_TESTED))1102 exitshell( exitstatus);1100 setvar(psh, "_", lastarg, 0); 1101 popstackmark(psh, &smark); 1102 1103 if (psh->eflag && psh->exitstatus && !(flags & EV_TESTED)) 1104 exitshell(psh, psh->exitstatus); 1103 1105 } 1104 1106 … … 1112 1114 1113 1115 STATIC void 1114 prehash( union node *n)1116 prehash(shinstance *psh, union node *n) 1115 1117 { 1116 1118 struct cmdentry entry; … … 1118 1120 if (n->type == NCMD && n->ncmd.args) 1119 1121 if (goodname(n->ncmd.args->narg.text)) 1120 find_command( n->ncmd.args->narg.text, &entry, 0,1121 pathval( ));1122 find_command(psh, n->ncmd.args->narg.text, &entry, 0, 1123 pathval(psh)); 1122 1124 } 1123 1125 … … 1134 1136 1135 1137 int 1136 bltincmd( int argc, char **argv)1138 bltincmd(shinstance *psh, int argc, char **argv) 1137 1139 { 1138 1140 /* 1139 * Preserve exitstatus of a previous possible redirection1141 * Preserve psh->exitstatus of a previous possible redirection 1140 1142 * as POSIX mandates 1141 1143 */ 1142 return back_exitstatus;1144 return psh->exitstatus; 1143 1145 } 1144 1146 … … 1146 1148 /* 1147 1149 * Handle break and continue commands. Break, continue, and return are 1148 * all handled by setting the evalskip flag. The evaluation routines1150 * all handled by setting the psh->evalskip flag. The evaluation routines 1149 1151 * above all check this flag, and if it is set they start skipping 1150 1152 * commands rather than executing them. The variable skipcount is … … 1156 1158 1157 1159 int 1158 breakcmd( int argc, char **argv)1160 breakcmd(shinstance *psh, int argc, char **argv) 1159 1161 { 1160 1162 int n = argc > 1 ? number(argv[1]) : 1; 1161 1163 1162 if (n > loopnest)1163 n = loopnest;1164 if (n > psh->loopnest) 1165 n = psh->loopnest; 1164 1166 if (n > 0) { 1165 evalskip = (**argv == 'c')? SKIPCONT : SKIPBREAK;1166 skipcount = n;1167 psh->evalskip = (**argv == 'c')? SKIPCONT : SKIPBREAK; 1168 psh->skipcount = n; 1167 1169 } 1168 1170 return 0; … … 1175 1177 1176 1178 int 1177 returncmd( int argc, char **argv)1178 { 1179 int ret = argc > 1 ? number(argv[1]) : exitstatus;1180 1181 if ( funcnest) {1182 evalskip = SKIPFUNC;1183 skipcount = 1;1179 returncmd(shinstance *psh, int argc, char **argv) 1180 { 1181 int ret = argc > 1 ? number(argv[1]) : psh->exitstatus; 1182 1183 if (psh->funcnest) { 1184 psh->evalskip = SKIPFUNC; 1185 psh->skipcount = 1; 1184 1186 return ret; 1185 1187 } 1186 1188 else { 1187 1189 /* Do what ksh does; skip the rest of the file */ 1188 evalskip = SKIPFILE;1189 skipcount = 1;1190 psh->evalskip = SKIPFILE; 1191 psh->skipcount = 1; 1190 1192 return ret; 1191 1193 } … … 1194 1196 1195 1197 int 1196 falsecmd( int argc, char **argv)1198 falsecmd(shinstance *psh, int argc, char **argv) 1197 1199 { 1198 1200 return 1; … … 1201 1203 1202 1204 int 1203 truecmd( int argc, char **argv)1205 truecmd(shinstance *psh, int argc, char **argv) 1204 1206 { 1205 1207 return 0; … … 1208 1210 1209 1211 int 1210 execcmd( int argc, char **argv)1212 execcmd(shinstance *psh, int argc, char **argv) 1211 1213 { 1212 1214 if (argc > 1) { 1213 1215 struct strlist *sp; 1214 1216 1215 iflag = 0; /* exit on error */1216 mflag = 0;1217 optschanged( );1218 for (sp = cmdenviron; sp; sp = sp->next)1219 setvareq( sp->text, VEXPORT|VSTACK);1220 shellexec( argv + 1, environment(), pathval(), 0, 0);1217 psh->iflag = 0; /* exit on error */ 1218 psh->mflag = 0; 1219 optschanged(psh); 1220 for (sp = psh->cmdenviron; sp; sp = sp->next) 1221 setvareq(psh, sp->text, VEXPORT|VSTACK); 1222 shellexec(psh, argv + 1, environment(psh), pathval(psh), 0, 0); 1221 1223 } 1222 1224 return 0; … … 1231 1233 1232 1234 if (!tpm) 1233 tpm = sysconf(_SC_CLK_TCK) * 60;1235 tpm = /*sysconf(_SC_CLK_TCK)*/sh_sysconf_clk_tck() * 60; 1234 1236 1235 1237 mins = ticks / tpm; … … 1251 1253 1252 1254 int 1253 timescmd( int argc, char **argv)1254 { 1255 struct tms tms;1255 timescmd(shinstance *psh, int argc, char **argv) 1256 { 1257 struct sh_tms tms; 1256 1258 int u, s, cu, cs; 1257 1259 char us[8], ss[8], cus[8], css[8]; 1258 1260 1259 nextopt( "");1260 1261 times(&tms);1261 nextopt(psh, ""); 1262 1263 sh_times(&tms); 1262 1264 1263 1265 u = conv_time(tms.tms_utime, us, sizeof(us)); … … 1266 1268 cs = conv_time(tms.tms_cstime, css, sizeof(css)); 1267 1269 1268 outfmt( out1, "%dm%ss %dm%ss\n%dm%ss %dm%ss\n",1270 outfmt(psh->out1, "%dm%ss %dm%ss\n%dm%ss %dm%ss\n", 1269 1271 u, us, s, ss, cu, cus, cs, css); 1270 1272 -
trunk/src/ash-messup/exec.h
r879 r884 47 47 union param { 48 48 int index; 49 int (*bltin)( int, char**);49 int (*bltin)(struct shinstance*, int, char**); 50 50 union node *func; 51 51 } u; -
trunk/src/ash-messup/expand.h
r879 r884 68 68 /* From arith.y */ 69 69 int arith(const char *); 70 int expcmd( int , char **);70 int expcmd(struct shinstance *, int , char **); 71 71 void arith_lex_reset(void); 72 72 int yylex(void); -
trunk/src/ash-messup/generated/builtins.h
r631 r884 7 7 struct builtincmd { 8 8 const char *name; 9 int (*builtin)( int, char **);9 int (*builtin)(struct shinstance *, int, char **); 10 10 }; 11 11 … … 14 14 15 15 16 int bltincmd( int, char **);17 int bgcmd( int, char **);18 int breakcmd( int, char **);19 int cdcmd( int, char **);20 int dotcmd( int, char **);21 int echocmd( int, char **);22 int evalcmd( int, char **);23 int execcmd( int, char **);24 int exitcmd( int, char **);25 int expcmd( int, char **);26 int exportcmd( int, char **);27 int falsecmd( int, char **);28 int histcmd( int, char **);29 int inputrc( int, char **);30 int fgcmd( int, char **);31 int getoptscmd( int, char **);32 int hashcmd( int, char **);33 int jobidcmd( int, char **);34 int jobscmd( int, char **);35 int localcmd( int, char **);16 int bltincmd(struct shinstance *, int, char **); 17 int bgcmd(struct shinstance *, int, char **); 18 int breakcmd(struct shinstance *, int, char **); 19 int cdcmd(struct shinstance *, int, char **); 20 int dotcmd(struct shinstance *, int, char **); 21 int echocmd(struct shinstance *, int, char **); 22 int evalcmd(struct shinstance *, int, char **); 23 int execcmd(struct shinstance *, int, char **); 24 int exitcmd(struct shinstance *, int, char **); 25 int expcmd(struct shinstance *, int, char **); 26 int exportcmd(struct shinstance *, int, char **); 27 int falsecmd(struct shinstance *, int, char **); 28 int histcmd(struct shinstance *, int, char **); 29 int inputrc(struct shinstance *, int, char **); 30 int fgcmd(struct shinstance *, int, char **); 31 int getoptscmd(struct shinstance *, int, char **); 32 int hashcmd(struct shinstance *, int, char **); 33 int jobidcmd(struct shinstance *, int, char **); 34 int jobscmd(struct shinstance *, int, char **); 35 int localcmd(struct shinstance *, int, char **); 36 36 #ifndef SMALL 37 int printfcmd( int, char **);37 int printfcmd(struct shinstance *, int, char **); 38 38 #endif 39 int pwdcmd( int, char **);40 int readcmd( int, char **);41 int returncmd( int, char **);42 int setcmd( int, char **);43 int setvarcmd( int, char **);44 int shiftcmd( int, char **);45 int timescmd( int, char **);46 int trapcmd( int, char **);47 int truecmd( int, char **);48 int typecmd( int, char **);49 int umaskcmd( int, char **);50 int unaliascmd( int, char **);51 int unsetcmd( int, char **);52 int waitcmd( int, char **);53 int aliascmd( int, char **);54 int ulimitcmd( int, char **);55 int testcmd( int, char **);56 int killcmd( int, char **);57 int wordexpcmd( int, char **);39 int pwdcmd(struct shinstance *, int, char **); 40 int readcmd(struct shinstance *, int, char **); 41 int returncmd(struct shinstance *, int, char **); 42 int setcmd(struct shinstance *, int, char **); 43 int setvarcmd(struct shinstance *, int, char **); 44 int shiftcmd(struct shinstance *, int, char **); 45 int timescmd(struct shinstance *, int, char **); 46 int trapcmd(struct shinstance *, int, char **); 47 int truecmd(struct shinstance *, int, char **); 48 int typecmd(struct shinstance *, int, char **); 49 int umaskcmd(struct shinstance *, int, char **); 50 int unaliascmd(struct shinstance *, int, char **); 51 int unsetcmd(struct shinstance *, int, char **); 52 int waitcmd(struct shinstance *, int, char **); 53 int aliascmd(struct shinstance *, int, char **); 54 int ulimitcmd(struct shinstance *, int, char **); 55 int testcmd(struct shinstance *, int, char **); 56 int killcmd(struct shinstance *, int, char **); 57 int wordexpcmd(struct shinstance *, int, char **); -
trunk/src/ash-messup/main.c
r883 r884 342 342 343 343 INTOFF; 344 if ((fd = open(name, O_RDONLY)) >= 0)344 if ((fd = shfile_open(&psh->fdtab, name, O_RDONLY)) >= 0) 345 345 setinputfd(psh, fd, 1); 346 346 else … … 371 371 372 372 while ((fullname = padvance(psh, &path, basename)) != NULL) { 373 if ((s tat(fullname, &statb) == 0) && S_ISREG(statb.st_mode)) {373 if ((shfile_stat(&psh->fdtab, fullname, &statb) == 0) && S_ISREG(statb.st_mode)) { 374 374 /* 375 375 * Don't bother freeing here, since it will -
trunk/src/ash-messup/memalloc.h
r879 r884 73 73 #define STTOPC(p) p[-1] 74 74 #define STADJUST(amount, p) (p += (amount), psh->sstrnleft -= (amount)) 75 #define grabstackstr(p) stalloc( stackblocksize() - psh->sstrnleft)75 #define grabstackstr(p) stalloc(psh, stackblocksize() - psh->sstrnleft) 76 76 77 77 #define ckfree(p) free((pointer)(p)) -
trunk/src/ash-messup/options.h
r880 r884 130 130 void optschanged(struct shinstance *); 131 131 void setparam(struct shinstance *, char **); 132 void freeparam( struct shinstance *,volatile struct shparam *);132 void freeparam(volatile struct shparam *); 133 133 int shiftcmd(struct shinstance *, int, char **); 134 134 int setcmd(struct shinstance *, int, char **); -
trunk/src/ash-messup/parser.h
r879 r884 79 79 union node *parsecmd(struct shinstance *, int); 80 80 void fixredir(struct shinstance *, union node *, const char *, int); 81 int goodname( struct shinstance *,char *);81 int goodname(char *); 82 82 const char *getprompt(struct shinstance *, void *); -
trunk/src/ash-messup/shfile.h
r883 r884 53 53 54 54 int shfile_open(shfdtab *, const char *, unsigned); 55 int shfile_pipe(shfdtab *, int [2]); 55 56 int shfile_close(shfdtab *, unsigned); 57 int shfile_fcntl(shfdtab *, int fd, int cmd, int arg); 58 #ifdef _MSC_VER 59 # define F_DUPFD 0 60 # define F_GETFD 1 61 # define F_SETFD 2 62 # define F_GETFL 3 63 # define F_SETFL 4 64 # define FD_CLOEXEC 1 65 #else 66 # include <sys/fcntl.h> 67 #endif 56 68 57 69 int shfile_stat(shfdtab *, const char *, struct stat *); -
trunk/src/ash-messup/shinstance.h
r883 r884 138 138 int back_exitstatus;/**< exit status of backquoted command */ 139 139 struct strlist *cmdenviron; /**< environment for builtin command */ 140 int funcnest; 141 int evalskip; 140 int funcnest; /**< depth of function calls */ 141 int evalskip; /**< set if we are skipping commands */ 142 int skipcount; /**< number of levels to skip */ 143 int loopnest; /**< current loop nesting level */ 142 144 143 145 /* builtins.h */ … … 156 158 char errmsg_buf[16]; /**< static in errmsg. (bss) */ 157 159 160 /* eval.c */ 161 int vforked; 158 162 } shinstance; 159 163 … … 165 169 #include <signal.h> 166 170 #ifdef _MSC_VER 167 typedef uint32_t sh_sigset_t;171 typedef uint32_t sh_sigset_t; 168 172 #else 169 typedef sigset_t sh_sigset_t;173 typedef sigset_t sh_sigset_t; 170 174 #endif 171 175 … … 176 180 int sh_sigprocmask(shinstance *, int op, sh_sigset_t const *new, sh_sigset_t *old); 177 181 178 #endif 182 /* times */ 183 #include <time.h> 184 #ifdef _MSC_VER 185 typedef struct sh_tms 186 { 187 clock_t tms_utime; 188 clock_t tms_stime; 189 clock_t tms_cutime; 190 clock_t tms_cstime; 191 } sh_tms; 192 #else 193 # include <times.h> 194 typedef struct tms sh_tms; 195 #endif 196 clock_t sh_times(sh_tms *); 197 int sh_sysconf_clk_tck(void); 198 199 /* wait */ 200 #ifdef _MSC_VER 201 # include <process.h> 202 # define WNOHANG 1 /* Don't hang in wait. */ 203 # define WUNTRACED 2 /* Tell about stopped, untraced children. */ 204 # define WCONTINUED 4 /* Report a job control continued process. */ 205 # define _W_INT(w) (*(int *)&(w)) /* Convert union wait to int. */ 206 # define WCOREFLAG 0200 207 # define _WSTATUS(x) (_W_INT(x) & 0177) 208 # define _WSTOPPED 0177 /* _WSTATUS if process is stopped */ 209 # define WIFSTOPPED(x) (_WSTATUS(x) == _WSTOPPED) 210 # define WSTOPSIG(x) (_W_INT(x) >> 8) 211 # define WIFSIGNALED(x) (_WSTATUS(x) != 0 && !WIFSTOPPED(x) && !WIFCONTINUED(x)) /* bird: made GLIBC tests happy. */ 212 # define WTERMSIG(x) (_WSTATUS(x)) 213 # define WIFEXITED(x) (_WSTATUS(x) == 0) 214 # define WEXITSTATUS(x) (_W_INT(x) >> 8) 215 # define WIFCONTINUED(x) (x == 0x13) /* 0x13 == SIGCONT */ 216 # define WCOREDUMP(x) (_W_INT(x) & WCOREFLAG) 217 # define W_EXITCODE(ret, sig) ((ret) << 8 | (sig)) 218 # define W_STOPCODE(sig) ((sig) << 8 | _WSTOPPED) 219 #else 220 # include <sys/wait.h> 221 #endif 222 pid_t sh_waitpid(shinstance *, pid_t, int *, int); 223 void sh__exit(shinstance *, int); 224 225 #endif -
trunk/src/ash-messup/var.h
r880 r884 34 34 * @(#)var.h 8.2 (Berkeley) 5/4/95 35 35 */ 36 37 #ifndef ___var_h___ 38 #define ___var_h___ 36 39 37 40 /* … … 143 146 int setvarsafe(struct shinstance *, const char *, const char *, int); 144 147 void print_quoted(struct shinstance *, const char *); 148 149 #endif
Note:
See TracChangeset
for help on using the changeset viewer.