Changeset 1198 in kBuild for trunk/src/kash
- Timestamp:
- Oct 6, 2007 9:19:19 PM (17 years ago)
- Location:
- trunk/src/kash
- Files:
-
- 33 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kash/Makefile.kmk
r884 r1198 35 35 error.c \ 36 36 eval.c \ 37 histedit.c \ 38 mail.c \ 39 memalloc.c \ 40 mystring.c \ 41 options.c \ 42 show.c \ 43 syntax.c \ 44 \ 45 output.c \ 37 46 exec.c \ 38 47 expand.c \ 39 histedit.c \40 48 input.c \ 41 49 jobs.c \ 42 mail.c \43 memalloc.c \44 50 miscbltin.c \ 45 mystring.c \46 options.c \47 output.c \48 51 parser.c \ 49 52 redir.c \ 50 show.c \51 syntax.c \52 53 trap.c \ 53 54 var.c \ … … 106 107 # Use the pregenerated code. 107 108 # 108 kmk_ash_DEPS := 109 kmk_ash_DEPS := 109 110 110 111 define def_copy_generated … … 119 120 120 121 kmk_ash_INCS += generated 121 kmk_ash_DEFS += HAVE_SYS_CDEFS_H 122 kmk_ash_DEFS += HAVE_SYS_CDEFS_H 122 123 123 124 include $(PATH_KBUILD)/footer.kmk -
trunk/src/kash/alias.c
r882 r1198 105 105 #else /* hack */ 106 106 { 107 int len = strlen(val);107 size_t len = strlen(val); 108 108 ap->val = ckmalloc(len + 2); 109 109 memcpy(ap->val, val, len); -
trunk/src/kash/cd.c
r883 r1198 86 86 char *p, *d; 87 87 struct stat statb; 88 int print = psh->cdprint; /* set -cdprint to enable */88 int print = cdprint(psh); /* set -cdprint to enable */ 89 89 90 90 nextopt(psh, nullstr); … … 171 171 psh->cdcomppath = stalloc(psh, strlen(dest) + 1); 172 172 scopy(dest, psh->cdcomppath); 173 STARTSTACKSTR(p );173 STARTSTACKSTR(psh, p); 174 174 if (IS_ROOT(dest)) { 175 STPUTC( '/', p);175 STPUTC(psh, '/', p); 176 176 psh->cdcomppath++; 177 177 } … … 181 181 continue; 182 182 if (! first) 183 STPUTC( '/', p);183 STPUTC(psh, '/', p); 184 184 first = 0; 185 185 component = q; 186 186 while (*q) 187 STPUTC( *q++, p);187 STPUTC(psh, *q++, p); 188 188 if (equal(component, "..")) 189 189 continue; 190 STACKSTRNUL(p );191 if ((shfile_lstat(&psh->fdtab, stackblock( ), &statb) < 0)190 STACKSTRNUL(psh, p); 191 if ((shfile_lstat(&psh->fdtab, stackblock(psh), &statb) < 0) 192 192 || (S_ISLNK(statb.st_mode))) { 193 193 /* print = 1; */ … … 204 204 updatepwd(psh, badstat ? NULL : dest); 205 205 INTON; 206 if (print && psh->iflag&& psh->curdir)206 if (print && iflag(psh) && psh->curdir) 207 207 out1fmt(psh, "%s\n", psh->curdir); 208 208 return 0; … … 272 272 psh->cdcomppath = stalloc(psh, strlen(dir) + 1); 273 273 scopy(dir, psh->cdcomppath); 274 STARTSTACKSTR( new);274 STARTSTACKSTR(psh, new); 275 275 if (!IS_ROOT(dir)) { 276 276 p = psh->curdir; 277 277 while (*p) 278 STPUTC( *p++, new);278 STPUTC(psh, *p++, new); 279 279 if (p[-1] == '/') 280 STUNPUTC( new);280 STUNPUTC(psh, new); 281 281 } 282 282 while ((p = getcomponent(psh)) != NULL) { 283 283 if (equal(p, "..")) { 284 while (new > stackblock( ) && (STUNPUTC(new), *new) != '/');284 while (new > stackblock(psh) && (STUNPUTC(psh, new), *new) != '/'); 285 285 } else if (*p != '\0' && ! equal(p, ".")) { 286 STPUTC( '/', new);286 STPUTC(psh, '/', new); 287 287 while (*p) 288 STPUTC( *p++, new);289 } 290 } 291 if (new == stackblock( ))292 STPUTC( '/', new);293 STACKSTRNUL( new);288 STPUTC(psh, *p++, new); 289 } 290 } 291 if (new == stackblock(psh)) 292 STPUTC(psh, '/', new); 293 STACKSTRNUL(psh, new); 294 294 INTOFF; 295 295 if (psh->prevdir) 296 296 ckfree(psh->prevdir); 297 297 psh->prevdir = psh->curdir; 298 psh->curdir = savestr(stackblock( ));298 psh->curdir = savestr(stackblock(psh)); 299 299 setvar(psh, "PWD", psh->curdir, VEXPORT); 300 300 INTON; -
trunk/src/kash/error.c
r883 r1198 116 116 sh_sigemptyset(&nsigset); 117 117 sh_sigprocmask(psh, SIG_SETMASK, &nsigset, NULL); 118 if (psh->rootshell && psh->iflag)118 if (psh->rootshell && iflag(psh)) 119 119 exraise(psh, EXINT); 120 120 else { -
trunk/src/kash/eval.c
r884 r1198 125 125 126 126 RESET { 127 evalskip = 0;128 loopnest = 0;129 funcnest = 0;127 psh->evalskip = 0; 128 psh->loopnest = 0; 129 psh->funcnest = 0; 130 130 } 131 131 132 132 SHELLPROC { 133 exitstatus = 0;133 psh->exitstatus = 0; 134 134 } 135 135 #endif … … 176 176 p = argv[1]; 177 177 if (argc > 2) { 178 STARTSTACKSTR( concat);178 STARTSTACKSTR(psh, concat); 179 179 ap = argv + 2; 180 180 for (;;) { 181 181 while (*p) 182 STPUTC( *p++, concat);182 STPUTC(psh, *p++, concat); 183 183 if ((p = *ap++) == NULL) 184 184 break; 185 STPUTC( ' ', concat);185 STPUTC(psh, ' ', concat); 186 186 } 187 STPUTC( '\0', concat);188 p = grabstackstr( concat);187 STPUTC(psh, '\0', concat); 188 p = grabstackstr(psh, concat); 189 189 } 190 190 evalstring(psh, p, EV_TESTED); … … 594 594 shfile_close(&psh->fdtab, pip[1]); 595 595 } 596 psh->eflag= 0;596 eflag(psh) = 0; 597 597 evaltree(psh, n, EV_EXIT); 598 598 /* NOTREACHED */ … … 765 765 *argv = NULL; 766 766 lastarg = NULL; 767 if ( psh->iflag&& psh->funcnest == 0 && argc > 0)767 if (iflag(psh) && psh->funcnest == 0 && argc > 0) 768 768 lastarg = argv[-1]; 769 769 argv -= argc; 770 770 771 771 /* Print the command if xflag is set. */ 772 if ( psh->xflag) {772 if (xflag(psh)) { 773 773 char sep = 0; 774 774 out2str(psh, ps4val(psh)); … … 1062 1062 if (flags == EV_BACKCMD) { 1063 1063 backcmd->buf = psh->memout.buf; 1064 backcmd->nleft = psh->memout.nextc - psh->memout.buf;1064 backcmd->nleft = (int)(psh->memout.nextc - psh->memout.buf); 1065 1065 psh->memout.buf = NULL; 1066 1066 } … … 1101 1101 popstackmark(psh, &smark); 1102 1102 1103 if ( psh->eflag&& psh->exitstatus && !(flags & EV_TESTED))1103 if (eflag(psh) && psh->exitstatus && !(flags & EV_TESTED)) 1104 1104 exitshell(psh, psh->exitstatus); 1105 1105 } … … 1160 1160 breakcmd(shinstance *psh, int argc, char **argv) 1161 1161 { 1162 int n = argc > 1 ? number( argv[1]) : 1;1162 int n = argc > 1 ? number(psh, argv[1]) : 1; 1163 1163 1164 1164 if (n > psh->loopnest) … … 1179 1179 returncmd(shinstance *psh, int argc, char **argv) 1180 1180 { 1181 int ret = argc > 1 ? number( argv[1]) : psh->exitstatus;1181 int ret = argc > 1 ? number(psh, argv[1]) : psh->exitstatus; 1182 1182 1183 1183 if (psh->funcnest) { … … 1215 1215 struct strlist *sp; 1216 1216 1217 psh->iflag= 0; /* exit on error */1218 psh->mflag= 0;1217 iflag(psh) = 0; /* exit on error */ 1218 mflag(psh) = 0; 1219 1219 optschanged(psh); 1220 1220 for (sp = psh->cmdenviron; sp; sp = sp->next) … … 1230 1230 static clock_t tpm = 0; 1231 1231 clock_t mins; 1232 int i;1232 size_t i; 1233 1233 1234 1234 if (!tpm) -
trunk/src/kash/eval.h
r879 r1198 54 54 55 55 /* in_function returns nonzero if we are currently evaluating a function */ 56 #define in_function( ) psh->funcnest56 #define in_function(psh) (psh)->funcnest 57 57 /*extern int funcnest; 58 58 extern int evalskip;*/ -
trunk/src/kash/exec.c
r809 r1198 146 146 TRACE(("shellexec: argv[0]=%s idx=%d\n", argv[0], idx)); 147 147 if (strchr(argv[0], '/') != NULL) { 148 cmdname = stalloc( strlen(argv[0]) + 5);148 cmdname = stalloc(psh, strlen(argv[0]) + 5); 149 149 strcpy(cmdname, argv[0]); 150 150 tryexec(cmdname, argv, envp, vforked, has_ext); 151 151 TRACE(("shellexec: cmdname=%s\n", cmdname)); 152 stunalloc( cmdname);152 stunalloc(psh, cmdname); 153 153 e = errno; 154 154 } else { … … 160 160 e = errno; 161 161 } 162 stunalloc( cmdname);162 stunalloc(psh, cmdname); 163 163 } 164 164 } … … 275 275 if (ap == &newargs[NEWARGS]) 276 276 bad: error("Bad #! line"); 277 STARTSTACKSTR( outp);277 STARTSTACKSTR(psh, outp); 278 278 do { 279 STPUTC( c, outp);279 STPUTC(psh, c, outp); 280 280 } while (--n >= 0 && (c = *inp++) != ' ' && c != '\t' && c != '\n'); 281 STPUTC( '\0', outp);281 STPUTC(psh, '\0', outp); 282 282 n++, inp--; 283 *ap++ = grabstackstr( outp);283 *ap++ = grabstackstr(psh, outp); 284 284 } 285 285 if (ap == newargs + 1) { /* if no args, maybe no exec is needed */ … … 349 349 len += 4; /* "4" is for .exe/.com/.cmd/.bat/.btm */ 350 350 #endif 351 while (stackblocksize( ) < len)352 growstackblock( );353 q = stackblock( );351 while (stackblocksize(psh) < len) 352 growstackblock(psh); 353 q = stackblock(psh); 354 354 if (p != start) { 355 355 memcpy(q, start, p - start); … … 375 375 else 376 376 *path = NULL; 377 return stalloc( len);377 return stalloc(psh, len); 378 378 } 379 379 … … 485 485 do { 486 486 name = padvance(&path, cmdp->cmdname); 487 stunalloc( name);487 stunalloc(psh, name); 488 488 } while (--idx >= 0); 489 489 out1str(name); … … 623 623 loop: 624 624 while ((fullname = padvance(&path, name)) != NULL) { 625 stunalloc( fullname);625 stunalloc(psh, fullname); 626 626 idx++; 627 627 if (pathopt) { … … 664 664 if (act & DO_NOFUNC) 665 665 goto loop; 666 stalloc( strlen(fullname) + 1);666 stalloc(psh, strlen(fullname) + 1); 667 667 readcmdfile(fullname); 668 668 if ((cmdp = cmdlookup(name, 0)) == NULL || 669 669 cmdp->cmdtype != CMDFUNCTION) 670 670 error("%s not defined in %s", name, fullname); 671 stunalloc( fullname);671 stunalloc(psh, fullname); 672 672 goto success; 673 673 } … … 689 689 INTOFF; 690 690 if (act & DO_ALTPATH) { 691 stalloc( strlen(fullname) + 1);691 stalloc(psh, strlen(fullname) + 1); 692 692 cmdp = &loc_cmd; 693 693 } else … … 1137 1137 do { 1138 1138 name = padvance(&path, arg); 1139 stunalloc( name);1139 stunalloc(psh, name); 1140 1140 } while (--j >= 0); 1141 1141 if (!v_flag) -
trunk/src/kash/expand.c
r809 r1198 124 124 expandhere(union node *arg, int fd) 125 125 { 126 herefd = fd;126 psh->herefd = fd; 127 127 expandarg(arg, (struct arglist *)NULL, 0); 128 xwrite( fd, stackblock(), expdest - stackblock());128 xwrite(psh, fd, stackblock(psh), expdest - stackblock(psh)); 129 129 } 130 130 … … 144 144 145 145 argbackq = arg->narg.backquote; 146 STARTSTACKSTR( expdest);146 STARTSTACKSTR(psh, expdest); 147 147 ifsfirst.next = NULL; 148 148 ifslastp = NULL; … … 151 151 return; /* here document expanded */ 152 152 } 153 STPUTC( '\0', expdest);154 p = grabstackstr( expdest);153 STPUTC(psh, '\0', expdest); 154 p = grabstackstr(psh, expdest); 155 155 exparg.lastp = &exparg.list; 156 156 /* … … 165 165 if (flag & EXP_REDIR) /*XXX - for now, just remove escapes */ 166 166 rmescapes(p); 167 sp = (struct strlist *)stalloc( sizeof (struct strlist));167 sp = (struct strlist *)stalloc(psh, sizeof (struct strlist)); 168 168 sp->text = p; 169 169 *exparg.lastp = sp; … … 210 210 break; 211 211 if ((flag & EXP_FULL) != 0) 212 STPUTC( c, expdest);212 STPUTC(psh, c, expdest); 213 213 ifs_split = 0; 214 214 break; … … 218 218 case CTLESC: 219 219 if (quotes) 220 STPUTC( c, expdest);220 STPUTC(psh, c, expdest); 221 221 c = *p++; 222 STPUTC( c, expdest);222 STPUTC(psh, c, expdest); 223 223 break; 224 224 case CTLVAR: … … 239 239 * assignments (after the first '=' and after ':'s). 240 240 */ 241 STPUTC( c, expdest);241 STPUTC(psh, c, expdest); 242 242 if (flag & EXP_VARTILDE && *p == '~') { 243 243 if (c == '=') { … … 251 251 break; 252 252 default: 253 STPUTC( c, expdest);253 STPUTC(psh, c, expdest); 254 254 if (flag & EXP_IFS_SPLIT & ifs_split && strchr(ifs, c) != NULL) { 255 255 /* We need to get the output split here... */ 256 recordregion(expdest - stackblock( ) - 1,257 expdest - stackblock( ), 0);256 recordregion(expdest - stackblock(psh) - 1, 257 expdest - stackblock(psh), 0); 258 258 } 259 259 break; … … 300 300 while ((c = *home++) != '\0') { 301 301 if (quotes && SQSYNTAX[(int)c] == CCTL) 302 STPUTC( CTLESC, expdest);303 STPUTC( c, expdest);302 STPUTC(psh, CTLESC, expdest); 303 STPUTC(psh, c, expdest); 304 304 } 305 305 return (p); … … 378 378 #error "integers with more than 10 digits are not supported" 379 379 #endif 380 CHECKSTRSPACE( 12 - 2, expdest);381 USTPUTC( '\0', expdest);382 start = stackblock( );380 CHECKSTRSPACE(psh, 12 - 2, expdest); 381 USTPUTC(psh, '\0', expdest); 382 start = stackblock(psh); 383 383 p = expdest - 1; 384 384 while (*p != CTLARI && p >= start) … … 408 408 recordregion(begoff, p - 1 - start, 0); 409 409 result = expdest - p + 1; 410 STADJUST( -result, expdest);410 STADJUST(psh, -result, expdest); 411 411 } 412 412 … … 427 427 struct nodelist *saveargbackq; 428 428 char lastc; 429 int startloc = dest - stackblock( );429 int startloc = dest - stackblock(psh); 430 430 char const *syntax = quoted? DQSYNTAX : BASESYNTAX; 431 431 int saveherefd; … … 436 436 savelastp = ifslastp; 437 437 saveargbackq = argbackq; 438 saveherefd = herefd;439 herefd = -1;440 p = grabstackstr( dest);438 saveherefd = psh->herefd; 439 psh->herefd = -1; 440 p = grabstackstr(psh, dest); 441 441 evalbackcmd(cmd, &in); 442 ungrabstackstr(p , dest);442 ungrabstackstr(psh, p, dest); 443 443 ifsfirst = saveifs; 444 444 ifslastp = savelastp; 445 445 argbackq = saveargbackq; 446 herefd = saveherefd;446 psh->herefd = saveherefd; 447 447 448 448 p = in.buf; … … 462 462 if (lastc != '\0') { 463 463 if (quotes && syntax[(int)lastc] == CCTL) 464 STPUTC( CTLESC, dest);465 STPUTC( lastc, dest);464 STPUTC(psh, CTLESC, dest); 465 STPUTC(psh, lastc, dest); 466 466 } 467 467 } 468 468 469 469 /* Eat all trailing newlines */ 470 p = stackblock( ) + startloc;470 p = stackblock(psh) + startloc; 471 471 while (dest > p && dest[-1] == '\n') 472 STUNPUTC( dest);472 STUNPUTC(psh, dest); 473 473 474 474 if (in.fd >= 0) … … 479 479 back_exitstatus = waitforjob(in.jp); 480 480 if (quoted == 0) 481 recordregion(startloc, dest - stackblock( ), 0);481 recordregion(startloc, dest - stackblock(psh), 0); 482 482 TRACE(("evalbackq: size=%d: \"%.*s\"\n", 483 (dest - stackblock( )) - startloc,484 (dest - stackblock( )) - startloc,485 stackblock( ) + startloc));483 (dest - stackblock(psh)) - startloc, 484 (dest - stackblock(psh)) - startloc, 485 stackblock(psh) + startloc)); 486 486 expdest = dest; 487 487 INTON; … … 497 497 char *q; 498 498 int c = 0; 499 int saveherefd = herefd;499 int saveherefd = psh->herefd; 500 500 struct nodelist *saveargbackq = argbackq; 501 501 int amount; 502 502 503 herefd = -1;503 psh->herefd = -1; 504 504 argstr(p, 0); 505 STACKSTRNUL( expdest);506 herefd = saveherefd;505 STACKSTRNUL(psh, expdest); 506 psh->herefd = saveherefd; 507 507 argbackq = saveargbackq; 508 startp = stackblock( ) + startloc;508 startp = stackblock(psh) + startloc; 509 509 if (str == NULL) 510 str = stackblock( ) + strloc;510 str = stackblock(psh) + strloc; 511 511 512 512 switch (subtype) { … … 514 514 setvar(str, startp, 0); 515 515 amount = startp - expdest; 516 STADJUST( amount, expdest);516 STADJUST(psh, amount, expdest); 517 517 varflags &= ~VSNUL; 518 518 if (c != 0) … … 593 593 *loc = c; 594 594 amount = ((str - 1) - (loc - startp)) - expdest; 595 STADJUST( amount, expdest);595 STADJUST(psh, amount, expdest); 596 596 while (loc != str - 1) 597 597 *startp++ = *loc++; … … 600 600 recordright: 601 601 amount = loc - expdest; 602 STADJUST( amount, expdest);603 STPUTC( '\0', expdest);604 STADJUST( -1, expdest);602 STADJUST(psh, amount, expdest); 603 STPUTC(psh, '\0', expdest); 604 STADJUST(psh, -1, expdest); 605 605 return 1; 606 606 } … … 648 648 649 649 varlen = 0; 650 startloc = expdest - stackblock( );651 652 if (!set && uflag ) {650 startloc = expdest - stackblock(psh); 651 652 if (!set && uflag(psh)) { 653 653 switch (subtype) { 654 654 case VSNORMAL: … … 668 668 varvalue(var, varflags & VSQUOTE, subtype, flag); 669 669 if (subtype == VSLENGTH) { 670 varlen = expdest - stackblock( ) - startloc;671 STADJUST( -varlen, expdest);670 varlen = expdest - stackblock(psh) - startloc; 671 STADJUST(psh, -varlen, expdest); 672 672 } 673 673 } else { … … 681 681 while (*val) { 682 682 if (quotes && syntax[(int)*val] == CCTL) 683 STPUTC( CTLESC, expdest);684 STPUTC( *val++, expdest);683 STPUTC(psh, CTLESC, expdest); 684 STPUTC(psh, *val++, expdest); 685 685 } 686 686 … … 727 727 * right after it 728 728 */ 729 STPUTC( '\0', expdest);730 patloc = expdest - stackblock( );729 STPUTC(psh, '\0', expdest); 730 patloc = expdest - stackblock(psh); 731 731 if (subevalvar(p, NULL, patloc, subtype, 732 732 startloc, varflags) == 0) { 733 int amount = (expdest - stackblock( ) - patloc) + 1;734 STADJUST( -amount, expdest);733 int amount = (expdest - stackblock(psh) - patloc) + 1; 734 STADJUST(psh, -amount, expdest); 735 735 } 736 736 /* Remove any recorded regions beyond start of variable */ … … 760 760 761 761 if (apply_ifs) 762 recordregion(startloc, expdest - stackblock( ),762 recordregion(startloc, expdest - stackblock(psh), 763 763 varflags & VSQUOTE); 764 764 … … 846 846 while (*p) { \ 847 847 if (syntax[(int)*p] == CCTL) \ 848 STPUTC( CTLESC, expdest); \849 STPUTC( *p++, expdest); \848 STPUTC(psh, CTLESC, expdest); \ 849 STPUTC(psh, *p++, expdest); \ 850 850 } \ 851 851 } else \ 852 852 while (*p) \ 853 STPUTC( *p++, expdest); \853 STPUTC(psh, *p++, expdest); \ 854 854 } while (0) 855 855 … … 873 873 for (i = 0; optlist[i].name; i++) { 874 874 if (optlist[i].val) 875 STPUTC( optlist[i].letter, expdest);875 STPUTC(psh, optlist[i].letter, expdest); 876 876 } 877 877 break; … … 881 881 STRTODEST(p); 882 882 if (*ap) 883 STPUTC( '\0', expdest);883 STPUTC(psh, '\0', expdest); 884 884 } 885 885 break; … … 894 894 STRTODEST(p); 895 895 if (*ap && sep) 896 STPUTC( sep, expdest);896 STPUTC(psh, sep, expdest); 897 897 } 898 898 break; … … 969 969 if (ifslastp == NULL) { 970 970 /* Return entire argument, IFS doesn't apply to any of it */ 971 sp = (struct strlist *)stalloc( sizeof *sp);971 sp = (struct strlist *)stalloc(psh, sizeof *sp); 972 972 sp->text = start; 973 973 *arglist->lastp = sp; … … 1009 1009 /* Save this argument... */ 1010 1010 *q = '\0'; 1011 sp = (struct strlist *)stalloc( sizeof *sp);1011 sp = (struct strlist *)stalloc(psh, sizeof *sp); 1012 1012 sp->text = start; 1013 1013 *arglist->lastp = sp; … … 1043 1043 */ 1044 1044 if (*start /* || (!ifsspc && start > string) */) { 1045 sp = (struct strlist *)stalloc( sizeof *sp);1045 sp = (struct strlist *)stalloc(psh, sizeof *sp); 1046 1046 sp->text = start; 1047 1047 *arglist->lastp = sp; … … 1085 1085 1086 1086 while (str) { 1087 if (fflag )1087 if (fflag(psh)) 1088 1088 goto nometa; 1089 1089 p = str->text; … … 1264 1264 struct strlist *sp; 1265 1265 1266 p = stalloc( strlen(name) + 1);1266 p = stalloc(psh, strlen(name) + 1); 1267 1267 scopy(name, p); 1268 sp = (struct strlist *)stalloc( sizeof *sp);1268 sp = (struct strlist *)stalloc(psh, sizeof *sp); 1269 1269 sp->text = p; 1270 1270 *exparg.lastp = sp; … … 1509 1509 char *p; 1510 1510 1511 setstackmark( &smark);1511 setstackmark(psh, &smark); 1512 1512 argbackq = pattern->narg.backquote; 1513 STARTSTACKSTR( expdest);1513 STARTSTACKSTR(psh, expdest); 1514 1514 ifslastp = NULL; 1515 1515 argstr(pattern->narg.text, EXP_TILDE | EXP_CASE); 1516 STPUTC( '\0', expdest);1517 p = grabstackstr( expdest);1516 STPUTC(psh, '\0', expdest); 1517 p = grabstackstr(psh, expdest); 1518 1518 result = patmatch(p, val, 0); 1519 popstackmark( &smark);1519 popstackmark(psh, &smark); 1520 1520 return result; 1521 1521 } … … 1542 1542 1543 1543 while (*p) 1544 STPUTC( *p++, buf);1544 STPUTC(psh, *p++, buf); 1545 1545 return buf; 1546 1546 } -
trunk/src/kash/generated/arith.c
r631 r1198 329 329 * concatenate arguments 330 330 */ 331 STARTSTACKSTR( concat);331 STARTSTACKSTR(psh, concat); 332 332 ap = argv + 2; 333 333 for (;;) { 334 334 while (*p) 335 STPUTC( *p++, concat);335 STPUTC(psh, *p++, concat); 336 336 if ((p = *ap++) == NULL) 337 337 break; 338 STPUTC( ' ', concat);338 STPUTC(psh, ' ', concat); 339 339 } 340 STPUTC( '\0', concat);341 p = grabstackstr( concat);340 STPUTC(psh, '\0', concat); 341 p = grabstackstr(psh, concat); 342 342 } 343 343 } else … … 382 382 #define YYERROR goto yyerrlab 383 383 #ifdef __cplusplus 384 extern "C" { 384 extern "C" { 385 385 char * getenv(); 386 386 int yylex(); -
trunk/src/kash/generated/init.c
r631 r1198 44 44 #define DEFEDITOR "ed" /* default editor *should* be $EDITOR */ 45 45 #undef editing 46 #define editing (Eflag || Vflag)46 #define editing (Eflag(psh) || Vflag(psh)) 47 47 #undef EOF_NLEFT 48 48 #define EOF_NLEFT -99 /* value of parsenleft when EOF pushed back */ -
trunk/src/kash/histedit.c
r809 r1198 91 91 FILE *el_err; 92 92 93 #define editing (Eflag || Vflag)94 95 if (iflag ) {93 #define editing (Eflag(psh) || Vflag(psh)) 94 95 if (iflag(psh)) { 96 96 if (!hist) { 97 97 /* … … 154 154 } 155 155 if (el) { 156 if (Vflag )156 if (Vflag(psh)) 157 157 el_set(el, EL_EDITOR, "vi"); 158 else if (Eflag )158 else if (Eflag(psh)) 159 159 el_set(el, EL_EDITOR, "emacs"); 160 160 el_set(el, EL_BIND, "^I", 161 tabcomplete ? "rl-complete" : "ed-insert", NULL);161 tabcomplete(psh) ? "rl-complete" : "ed-insert", NULL); 162 162 el_source(el, NULL); 163 163 } … … 418 418 } 419 419 420 evalstring(strcpy(stalloc( strlen(s) + 1), s), 0);420 evalstring(strcpy(stalloc(psh, strlen(s) + 1), s), 0); 421 421 if (displayhist && hist) { 422 422 /* … … 440 440 441 441 fclose(efp); 442 editcmd = stalloc( strlen(editor) + strlen(editfile) + 2);442 editcmd = stalloc(psh, strlen(editor) + strlen(editfile) + 2); 443 443 sprintf(editcmd, "%s %s", editor, editfile); 444 444 evalstring(editcmd, 0); /* XXX - should use no JC command */ … … 461 461 int plen = strlen(p); 462 462 463 STARTSTACKSTR( dest);463 STARTSTACKSTR(psh, dest); 464 464 while (*s) { 465 465 if (*s == *p && strncmp(s, p, plen) == 0) { 466 466 while (*r) 467 STPUTC( *r++, dest);467 STPUTC(psh, *r++, dest); 468 468 s += plen; 469 469 *p = '\0'; /* so no more matches */ 470 470 } else 471 STPUTC( *s++, dest);472 } 473 STACKSTRNUL( dest);474 dest = grabstackstr( dest);471 STPUTC(psh, *s++, dest); 472 } 473 STACKSTRNUL(psh, dest); 474 dest = grabstackstr(psh, dest); 475 475 476 476 return (dest); … … 537 537 #else 538 538 int 539 histcmd( int argc, char **argv)540 { 541 error( "not compiled with history support");539 histcmd(shinstance *psh, int argc, char **argv) 540 { 541 error(psh, "not compiled with history support"); 542 542 /* NOTREACHED */ 543 return -1; 543 544 } 544 545 int 545 inputrc( int argc, char **argv)546 { 547 error( "not compiled with history support");546 inputrc(shinstance *psh, int argc, char **argv) 547 { 548 error(psh, "not compiled with history support"); 548 549 /* NOTREACHED */ 549 } 550 #endif 550 return -1; 551 } 552 #endif -
trunk/src/kash/input.c
r809 r1198 316 316 #endif 317 317 318 if (vflag ) {318 if (vflag(psh)) { 319 319 out2str(parsenextc); 320 320 flushout(out2); -
trunk/src/kash/jobs.c
r883 r1198 193 193 out: 194 194 out2str("sh: can't access tty; job control turned off\n"); 195 mflag = 0;195 mflag(psh) = 0; 196 196 return; 197 197 } … … 208 208 || ldisc != NTTYDISC) { 209 209 out2str("sh: need new tty driver to run job control; job control turned off\n"); 210 mflag = 0;210 mflag(psh) = 0; 211 211 return; 212 212 } … … 549 549 * put us in it. 550 550 */ 551 if (mflag && gotpid != -1 && tcgetpgrp(ttyfd) != getpid()) {551 if (mflag(psh) && gotpid != -1 && tcgetpgrp(ttyfd) != getpid()) { 552 552 if (tcsetpgrp(ttyfd, getpid()) == -1) 553 553 error("Cannot set tty process group (%s) at %d", … … 651 651 retval = WTERMSIG(status) + 128; 652 652 } 653 if (!iflag )653 if (!iflag(psh)) 654 654 freejob(job); 655 655 } … … 705 705 } else if (name[0] == '%') { 706 706 if (is_number(name + 1)) { 707 jobno = number( name + 1) - 1;707 jobno = number(psh, name + 1) - 1; 708 708 } else if (!name[2]) { 709 709 switch (name[1]) { … … 748 748 749 749 } else if (is_number(name)) { 750 pid = number( name);750 pid = number(psh, name); 751 751 for (jp = jobtab, i = njobs ; --i >= 0 ; jp++) { 752 752 if (jp->used && jp->nprocs > 0 … … 870 870 int pgrp; 871 871 872 if (rootshell && mode != FORK_NOJOB && mflag ) {872 if (rootshell && mode != FORK_NOJOB && mflag(psh)) { 873 873 if (jp == NULL || jp->nprocs == 0) 874 874 pgrp = pid; … … 910 910 if (!vforked) 911 911 jobctl = 0; /* do job control only in root shell */ 912 if (wasroot && mode != FORK_NOJOB && mflag ) {912 if (wasroot && mode != FORK_NOJOB && mflag(psh)) { 913 913 if (jp == NULL || jp->nprocs == 0) 914 914 pgrp = getpid(); … … 946 946 } 947 947 #endif 948 if (wasroot && iflag ) {948 if (wasroot && iflag(psh)) { 949 949 setsignal(SIGINT, vforked); 950 950 setsignal(SIGQUIT, vforked); … … 1090 1090 if (thisjob && thisjob->state != JOBRUNNING) { 1091 1091 int mode = 0; 1092 if (!rootshell || !iflag )1092 if (!rootshell || !iflag(psh)) 1093 1093 mode = SHOW_SIGNALLED; 1094 1094 if (job == thisjob) … … 1219 1219 1220 1220 cmdnextc = ps->cmd; 1221 if (iflag || mflag|| sizeof ps->cmd < 100)1221 if (iflag(psh) || mflag(psh) || sizeof ps->cmd < 100) 1222 1222 len = sizeof(ps->cmd); 1223 1223 else -
trunk/src/kash/machdep.h
r626 r1198 40 40 */ 41 41 42 #ifdef _MSC_VER 43 #define SHELL_SIZE (8 - 1) 44 #else 42 45 #define SHELL_SIZE (sizeof(union {int i; char *cp; double d; }) - 1) 46 #endif 47 43 48 /* 44 49 * It appears that grabstackstr() will barf with such alignments -
trunk/src/kash/mail.c
r809 r1198 58 58 #include "error.h" 59 59 #include "mail.h" 60 #include "shinstance.h" 60 61 61 62 62 #define MAXMBOXES 10 63 /*#define MAXMBOXES 10*/ 63 64 64 65 65 STATIC int nmboxes; /* number of mailboxes */66 STATIC time_t mailtime[MAXMBOXES];/* times of mailboxes */66 /*STATIC int nmboxes; /* number of mailboxes */ 67 /*STATIC time_t mailtime[MAXMBOXES];*/ /* times of mailboxes */ 67 68 68 69 … … 75 76 76 77 void 77 chkmail( int silent)78 chkmail(shinstance *psh, int silent) 78 79 { 79 80 int i; … … 85 86 86 87 if (silent) 87 nmboxes = 10;88 if ( nmboxes == 0)88 psh->nmboxes = 10; 89 if (psh->nmboxes == 0) 89 90 return; 90 setstackmark( &smark);91 mpath = mpathset( ) ? mpathval() : mailval();92 for (i = 0 ; i < nmboxes ; i++) {93 p = padvance( &mpath, nullstr);91 setstackmark(psh, &smark); 92 mpath = mpathset(psh) ? mpathval(psh) : mailval(psh); 93 for (i = 0 ; i < psh->nmboxes ; i++) { 94 p = padvance(psh, &mpath, nullstr); 94 95 if (p == NULL) 95 96 break; … … 101 102 q[-1] = '\0'; /* delete trailing '/' */ 102 103 #ifdef notdef /* this is what the System V shell claims to do (it lies) */ 103 if (s tat(p, &statb) < 0)104 if (shfile_stat(&psh->fdtab, p, &statb) < 0) 104 105 statb.st_mtime = 0; 105 if (statb.st_mtime > mailtime[i] && ! silent) {106 out2str(p athopt ?pathopt : "you have mail");107 out2c( '\n');106 if (statb.st_mtime > psh->mailtime[i] && ! silent) { 107 out2str(psh, psh->pathopt ? psh->pathopt : "you have mail"); 108 out2c(psh, '\n'); 108 109 } 109 mailtime[i] = statb.st_mtime;110 psh->mailtime[i] = statb.st_mtime; 110 111 #else /* this is what it should do */ 111 if (s tat(p, &statb) < 0)112 if (shfile_stat(&psh->fdtab, p, &statb) < 0) 112 113 statb.st_size = 0; 113 if (statb.st_size > mailtime[i] && ! silent) {114 out2str(p athopt ?pathopt : "you have mail");115 out2c( '\n');114 if (statb.st_size > psh->mailtime[i] && ! silent) { 115 out2str(psh, psh->pathopt ? psh->pathopt : "you have mail"); 116 out2c(psh, '\n'); 116 117 } 117 mailtime[i] = statb.st_size;118 psh->mailtime[i] = statb.st_size; 118 119 #endif 119 120 } 120 nmboxes = i;121 popstackmark( &smark);121 psh->nmboxes = i; 122 popstackmark(psh, &smark); 122 123 } -
trunk/src/kash/main.c
r884 r1198 84 84 /*int rootpid; 85 85 int rootshell;*/ 86 #ifdef unused_variables 86 87 STATIC union node *curcmd; 87 88 STATIC union node *prevcmd; 89 #endif 88 90 89 91 STATIC void read_profile(struct shinstance *, const char *); … … 94 96 extern void init_syntax(void); 95 97 #endif 98 STATIC int usage(const char *argv0); 99 STATIC int version(const char *argv0); 96 100 97 101 /* … … 109 113 110 114 /* 111 * Global initializations. 112 115 * Global initializations. 116 */ 113 117 setlocale(LC_ALL, ""); 114 118 #ifdef _MSC_VER 115 119 init_syntax(); 116 120 #endif 121 122 /* 123 * Check for --version and --help. 124 */ 125 if (argc > 1 && argv[1][0] == '-' && argv[1][1] == '-') { 126 if (!strcmp(argv[1], "--help")) 127 return usage(argv[0]); 128 if (!strcmp(argv[1], "--version")) 129 return version(argv[0]); 130 } 131 117 132 /* 118 133 * Create the root shell instance. … … 123 138 shthread_set_shell(psh); 124 139 return shell_main(psh, argc, argv); 125 } 126 127 int 140 } 141 142 int 128 143 shell_main(shinstance *psh, int argc, char **argv) 129 144 { … … 161 176 162 177 if (psh->exception != EXSHELLPROC) { 163 if (state == 0 || psh->iflag== 0 || ! psh->rootshell)178 if (state == 0 || iflag(psh) == 0 || ! psh->rootshell) 164 179 exitshell(psh, psh->exitstatus); 165 180 } … … 189 204 #ifdef DEBUG 190 205 #if DEBUG == 2 191 debug = 1;206 debug(psh) = 1; 192 207 #endif 193 208 opentrace(psh); … … 215 230 state3: 216 231 state = 4; 217 if ( psh->sflag== 0 || psh->minusc) {232 if (sflag(psh) == 0 || psh->minusc) { 218 233 static int sigs[] = { 219 234 SIGINT, SIGQUIT, SIGHUP, … … 233 248 evalstring(psh, psh->minusc, 0); 234 249 235 if ( psh->sflag|| psh->minusc == NULL) {250 if (sflag(psh) || psh->minusc == NULL) { 236 251 state4: /* XXX ??? - why isn't this before the "if" statement */ 237 252 cmdloop(psh, 1); … … 262 277 dotrap(psh); 263 278 inter = 0; 264 if ( psh->iflag&& top) {279 if (iflag(psh) && top) { 265 280 inter = 1; 266 281 showjobs(psh, psh->out2, SHOW_CHANGED); … … 274 289 break; 275 290 if (!stoppedjobs(psh)) { 276 if (! psh->Iflag)291 if (!Iflag(psh)) 277 292 break; 278 293 out2str(psh, "\nUse \"exit\" to leave shell.\n"); 279 294 } 280 295 numeof++; 281 } else if (n != NULL && psh->nflag== 0) {296 } else if (n != NULL && nflag(psh) == 0) { 282 297 psh->job_warning = (psh->job_warning == 2) ? 1 : 0; 283 298 numeof = 0; … … 314 329 return; 315 330 /* -q turns off -x and -v just when executing init files */ 316 if ( psh->qflag) {317 if ( psh->xflag)318 psh->xflag= 0, xflag_set = 1;319 if ( psh->vflag)320 psh->vflag= 0, vflag_set = 1;331 if (qflag(psh)) { 332 if (xflag(psh)) 333 xflag(psh) = 0, xflag_set = 1; 334 if (vflag(psh)) 335 vflag(psh) = 0, vflag_set = 1; 321 336 } 322 337 cmdloop(psh, 0); 323 if ( psh->qflag) {338 if (qflag(psh)) { 324 339 if (xflag_set) 325 psh->xflag= 1;340 xflag(psh) = 1; 326 341 if (vflag_set) 327 psh->vflag= 1;342 vflag(psh) = 1; 328 343 } 329 344 popfile(psh); … … 414 429 return 0; 415 430 if (argc > 1) 416 psh->exitstatus = number( argv[1]);431 psh->exitstatus = number(psh, argv[1]); 417 432 exitshell(psh, psh->exitstatus); 418 433 /* NOTREACHED */ … … 420 435 } 421 436 437 438 STATIC const char * 439 strip_argv0(const char *argv0, size_t *lenp) 440 { 441 const char *tmp; 442 443 /* skip the path */ 444 for (tmp = strpbrk(argv0, "\\/:"); tmp; tmp = strpbrk(argv0, "\\/:")) 445 argv0 = tmp + 1; 446 447 /* find the end, ignoring extenions */ 448 tmp = strrchr(argv0, '.'); 449 if (!tmp) 450 tmp = strchr(argv0, '\0'); 451 *lenp = tmp - argv0; 452 return argv0; 453 } 454 455 STATIC int 456 usage(const char *argv0) 457 { 458 size_t len; 459 strip_argv0(argv0, &len); 460 461 fprintf(stdout, 462 "usage: %.*s [-aCefnuvxIimqVEb] [+aCefnuvxIimqVEb] [-o option_name]\n" 463 " [+o option_name] [command_file [argument ...]]\n" 464 " or: %.*s -c [-aCefnuvxIimqVEb] [+aCefnuvxIimqVEb] [-o option_name]\n" 465 " [+o option_name] command_string [command_name [argument ...]]\n" 466 " or: %.*s -s [-aCefnuvxIimqVEb] [+aCefnuvxIimqVEb] [-o option_name]\n" 467 " [+o option_name] [argument ...]\n" 468 " or: %.*s --help\n" 469 " or: %.*s --version\n", 470 len, argv0, len, argv0, len, argv0, len, argv0, len, argv0); 471 return 0; 472 } 473 474 STATIC int 475 version(const char *argv0) 476 { 477 size_t len; 478 strip_argv0(argv0, &len); 479 480 fprintf(stdout, 481 "%.*s - kBuild version %d.%d.%d\n", 482 len, argv0, 483 KBUILD_VERSION_MAJOR, KBUILD_VERSION_MINOR, KBUILD_VERSION_PATCH); 484 return 0; 485 } 486 487 422 488 /* 423 489 * Local Variables: -
trunk/src/kash/memalloc.c
r809 r1198 59 59 60 60 pointer 61 ckmalloc( int nbytes)61 ckmalloc(size_t nbytes) 62 62 { 63 63 pointer p; … … 65 65 p = malloc(nbytes); 66 66 if (p == NULL) 67 error( "Out of space");67 error(NULL, "Out of space"); 68 68 return p; 69 69 } … … 75 75 76 76 pointer 77 ckrealloc(pointer p, int nbytes)77 ckrealloc(pointer p, size_t nbytes) 78 78 { 79 79 p = realloc(p, nbytes); 80 80 if (p == NULL) 81 error( "Out of space");81 error(NULL, "Out of space"); 82 82 return p; 83 83 } … … 108 108 */ 109 109 110 #define MINSIZE 504 /* minimum size of a block */111 112 struct stack_block {113 struct stack_block *prev;114 char space[MINSIZE];115 };116 117 struct stack_block stackbase;118 struct stack_block *stackp = &stackbase;119 struct stackmark *markp;120 char *stacknxt = stackbase.space;121 int stacknleft = MINSIZE;122 int sstrnleft;123 int herefd = -1;110 //#define MINSIZE 504 /* minimum size of a block */ 111 112 //struct stack_block { 113 // struct stack_block *prev; 114 // char space[MINSIZE]; 115 //}; 116 117 //struct stack_block stackbase; 118 //struct stack_block *stackp = &stackbase; 119 //struct stackmark *markp; 120 //char *stacknxt = stackbase.space; 121 //int stacknleft = MINSIZE; 122 //int sstrnleft; 123 //int herefd = -1; 124 124 125 125 pointer 126 stalloc( int nbytes)126 stalloc(shinstance *psh, size_t nbytes) 127 127 { 128 128 char *p; 129 129 130 130 nbytes = SHELL_ALIGN(nbytes); 131 if (nbytes > stacknleft) {132 int blocksize;131 if (nbytes > psh->stacknleft) { 132 size_t blocksize; 133 133 struct stack_block *sp; 134 134 … … 138 138 INTOFF; 139 139 sp = ckmalloc(sizeof(struct stack_block) - MINSIZE + blocksize); 140 sp->prev = stackp;141 stacknxt = sp->space;142 stacknleft =blocksize;143 stackp = sp;140 sp->prev = psh->stackp; 141 psh->stacknxt = sp->space; 142 psh->stacknleft = (int)blocksize; 143 psh->stackp = sp; 144 144 INTON; 145 145 } 146 p = stacknxt;147 stacknxt += nbytes;148 stacknleft -=nbytes;146 p = psh->stacknxt; 147 psh->stacknxt += nbytes; 148 psh->stacknleft -= (int)nbytes; 149 149 return p; 150 150 } … … 152 152 153 153 void 154 stunalloc( pointer p)154 stunalloc(shinstance *psh, pointer p) 155 155 { 156 156 if (p == NULL) { /*DEBUG */ 157 write(2, "stunalloc\n", 10);158 abort();159 } 160 stacknleft += stacknxt - (char *)p;161 stacknxt = p;162 } 163 164 165 166 void 167 setstackmark(s truct stackmark *mark)168 { 169 mark->stackp = stackp;170 mark->stacknxt = stacknxt;171 mark->stacknleft = stacknleft;172 mark->marknext = markp;173 markp = mark;174 } 175 176 177 void 178 popstackmark(s truct stackmark *mark)157 shfile_write(&psh->fdtab, 2, "stunalloc\n", 10); 158 sh_abort(psh); 159 } 160 psh->stacknleft += (int)(psh->stacknxt - (char *)p); 161 psh->stacknxt = p; 162 } 163 164 165 166 void 167 setstackmark(shinstance *psh, struct stackmark *mark) 168 { 169 mark->stackp = psh->stackp; 170 mark->stacknxt = psh->stacknxt; 171 mark->stacknleft = psh->stacknleft; 172 mark->marknext = psh->markp; 173 psh->markp = mark; 174 } 175 176 177 void 178 popstackmark(shinstance *psh, struct stackmark *mark) 179 179 { 180 180 struct stack_block *sp; 181 181 182 182 INTOFF; 183 markp = mark->marknext;184 while ( stackp != mark->stackp) {185 sp = stackp;186 stackp = sp->prev;183 psh->markp = mark->marknext; 184 while (psh->stackp != mark->stackp) { 185 sp = psh->stackp; 186 psh->stackp = sp->prev; 187 187 ckfree(sp); 188 188 } 189 stacknxt = mark->stacknxt;190 stacknleft = mark->stacknleft;189 psh->stacknxt = mark->stacknxt; 190 psh->stacknleft = mark->stacknleft; 191 191 INTON; 192 192 } … … 204 204 205 205 void 206 growstackblock( void)207 { 208 int newlen = SHELL_ALIGN( stacknleft * 2 + 100);209 210 if ( stacknxt == stackp->space && stackp != &stackbase) {206 growstackblock(shinstance *psh) 207 { 208 int newlen = SHELL_ALIGN(psh->stacknleft * 2 + 100); 209 210 if (psh->stacknxt == psh->stackp->space && psh->stackp != &psh->stackbase) { 211 211 struct stack_block *oldstackp; 212 212 struct stackmark *xmark; … … 214 214 215 215 INTOFF; 216 oldstackp = stackp;217 sp = stackp;218 stackp = sp->prev;216 oldstackp = psh->stackp; 217 sp = psh->stackp; 218 psh->stackp = sp->prev; 219 219 sp = ckrealloc((pointer)sp, 220 220 sizeof(struct stack_block) - MINSIZE + newlen); 221 sp->prev = stackp;222 stackp = sp;223 stacknxt = sp->space;224 stacknleft = newlen;221 sp->prev = psh->stackp; 222 psh->stackp = sp; 223 psh->stacknxt = sp->space; 224 psh->stacknleft = newlen; 225 225 226 226 /* … … 228 228 * must be relocated to point to the new block 229 229 */ 230 xmark = markp;230 xmark = psh->markp; 231 231 while (xmark != NULL && xmark->stackp == oldstackp) { 232 xmark->stackp = stackp;233 xmark->stacknxt = stacknxt;234 xmark->stacknleft = stacknleft;232 xmark->stackp = psh->stackp; 233 xmark->stacknxt = psh->stacknxt; 234 xmark->stacknleft = psh->stacknleft; 235 235 xmark = xmark->marknext; 236 236 } 237 237 INTON; 238 238 } else { 239 char *oldspace = stacknxt;240 int oldlen = stacknleft;241 char *p = stalloc( newlen);239 char *oldspace = psh->stacknxt; 240 int oldlen = psh->stacknleft; 241 char *p = stalloc(psh, newlen); 242 242 243 243 (void)memcpy(p, oldspace, oldlen); 244 stacknxt = p; /* free the space */245 stacknleft += newlen; /* we just allocated */246 } 247 } 248 249 void 250 grabstackblock( int len)244 psh->stacknxt = p; /* free the space */ 245 psh->stacknleft += newlen; /* we just allocated */ 246 } 247 } 248 249 void 250 grabstackblock(shinstance *psh, int len) 251 251 { 252 252 len = SHELL_ALIGN(len); 253 stacknxt += len;254 stacknleft -= len;253 psh->stacknxt += len; 254 psh->stacknleft -= len; 255 255 } 256 256 … … 260 260 * to be a register. The macro STARTSTACKSTR initializes things. Then 261 261 * the user uses the macro STPUTC to add characters to the string. In 262 * effect, STPUTC( c, p) is the same as *p++ = c except that the stack is262 * effect, STPUTC(psh, c, p) is the same as *p++ = c except that the stack is 263 263 * grown as necessary. When the user is done, she can just leave the 264 * string there and refer to it using stackblock( ). Or she can allocate264 * string there and refer to it using stackblock(psh). Or she can allocate 265 265 * the space for it using grabstackstr(). If it is necessary to allow 266 266 * someone else to use the stack temporarily and then continue to grow … … 274 274 275 275 char * 276 growstackstr( void)277 { 278 int len = stackblocksize( );279 if ( herefd >= 0 && len >= 1024) {280 xwrite( herefd, stackblock(), len);281 sstrnleft = len - 1;282 return stackblock( );283 } 284 growstackblock( );285 sstrnleft = stackblocksize() - len - 1;286 return stackblock( ) + len;276 growstackstr(shinstance *psh) 277 { 278 int len = stackblocksize(psh); 279 if (psh->herefd >= 0 && len >= 1024) { 280 xwrite(psh, psh->herefd, stackblock(psh), len); 281 psh->sstrnleft = len - 1; 282 return stackblock(psh); 283 } 284 growstackblock(psh); 285 psh->sstrnleft = stackblocksize(psh) - len - 1; 286 return stackblock(psh) + len; 287 287 } 288 288 … … 292 292 293 293 char * 294 makestrspace( void)295 { 296 int len = stackblocksize( ) -sstrnleft;297 growstackblock( );298 sstrnleft = stackblocksize() - len;299 return stackblock( ) + len;300 } 301 302 void 303 ungrabstackstr( char *s, char *p)304 { 305 stacknleft += stacknxt - s;306 stacknxt = s;307 sstrnleft = stacknleft - (p - s);308 309 } 294 makestrspace(shinstance *psh) 295 { 296 int len = stackblocksize(psh) - psh->sstrnleft; 297 growstackblock(psh); 298 psh->sstrnleft = stackblocksize(psh) - len; 299 return stackblock(psh) + len; 300 } 301 302 void 303 ungrabstackstr(shinstance *psh, char *s, char *p) 304 { 305 psh->stacknleft += (int)(psh->stacknxt - s); 306 psh->stacknxt = s; 307 psh->sstrnleft = (int)(psh->stacknleft - (p - s)); 308 309 } -
trunk/src/kash/memalloc.h
r884 r1198 48 48 extern int herefd;*/ 49 49 50 pointer ckmalloc( int);51 pointer ckrealloc(pointer, int);50 pointer ckmalloc(size_t); 51 pointer ckrealloc(pointer, size_t); 52 52 char *savestr(const char *); 53 pointer stalloc(struct shinstance *, int);53 pointer stalloc(struct shinstance *, size_t); 54 54 void stunalloc(struct shinstance *, pointer); 55 55 void setstackmark(struct shinstance *, struct stackmark *); … … 63 63 64 64 65 #define stackblock( ) psh->stacknxt66 #define stackblocksize( ) psh->stacknleft67 #define STARTSTACKSTR(p ) p = stackblock(), psh->sstrnleft = stackblocksize()68 #define STPUTC( c, p) (--psh->sstrnleft >= 0? (*p++ = (c)) : (p = growstackstr(psh), *p++ = (c)))69 #define CHECKSTRSPACE( n, p) { if (psh->sstrnleft < n) p = makestrspace(psh); }70 #define USTPUTC( c, p) (--psh->sstrnleft, *p++ = (c))71 #define STACKSTRNUL(p ) (psh->sstrnleft == 0? (p = growstackstr(psh), *p = '\0') : (*p = '\0'))72 #define STUNPUTC(p ) (++psh->sstrnleft, --p)73 #define STTOPC(p )p[-1]74 #define STADJUST( amount, p) (p += (amount), psh->sstrnleft -= (amount))75 #define grabstackstr(p ) stalloc(psh, stackblocksize() - psh->sstrnleft)65 #define stackblock(psh) (psh)->stacknxt 66 #define stackblocksize(psh) (psh)->stacknleft 67 #define STARTSTACKSTR(psh, p) p = stackblock(psh), (psh)->sstrnleft = stackblocksize(psh) 68 #define STPUTC(psh, c, p) (--(psh)->sstrnleft >= 0? (*p++ = (c)) : (p = growstackstr(psh), *p++ = (c))) 69 #define CHECKSTRSPACE(psh, n, p) { if ((psh)->sstrnleft < n) p = makestrspace(psh); } 70 #define USTPUTC(psh, c, p) (--(psh)->sstrnleft, *p++ = (c)) 71 #define STACKSTRNUL(psh, p) ((psh)->sstrnleft == 0? (p = growstackstr(psh), *p = '\0') : (*p = '\0')) 72 #define STUNPUTC(psh, p) (++(psh)->sstrnleft, --p) 73 #define STTOPC(psh, p) p[-1] 74 #define STADJUST(psh, amount, p) (p += (amount), (psh)->sstrnleft -= (amount)) 75 #define grabstackstr(psh, p) stalloc((psh), stackblocksize(psh) - (psh)->sstrnleft) 76 76 77 77 #define ckfree(p) free((pointer)(p)) -
trunk/src/kash/miscbltin.c
r809 r1198 125 125 status = 0; 126 126 startword = 2; 127 STARTSTACKSTR(p );127 STARTSTACKSTR(psh, p); 128 128 for (;;) { 129 129 if (read(0, &c, 1) != 1) { … … 139 139 } 140 140 if (c != '\n') 141 STPUTC( c, p);141 STPUTC(psh, c, p); 142 142 continue; 143 143 } … … 153 153 /* Ignore leading IFS whitespace */ 154 154 if (saveall) 155 STPUTC( c, p);155 STPUTC(psh, c, p); 156 156 continue; 157 157 } … … 160 160 startword = 2; 161 161 if (saveall) 162 STPUTC( c, p);162 STPUTC(psh, c, p); 163 163 continue; 164 164 } … … 171 171 /* Not just a spare terminator */ 172 172 saveall++; 173 STPUTC( c, p);173 STPUTC(psh, c, p); 174 174 continue; 175 175 } … … 181 181 /* Last variable needs all IFS chars */ 182 182 saveall++; 183 STPUTC( c, p);183 STPUTC(psh, c, p); 184 184 continue; 185 185 } 186 186 187 STACKSTRNUL(p );188 setvar(*ap, stackblock( ), 0);187 STACKSTRNUL(psh, p); 188 setvar(*ap, stackblock(psh), 0); 189 189 ap++; 190 STARTSTACKSTR(p );191 } 192 STACKSTRNUL(p );190 STARTSTACKSTR(psh, p); 191 } 192 STACKSTRNUL(psh, p); 193 193 194 194 /* Remove trailing IFS chars */ 195 for (; stackblock( ) <= --p; *p = 0) {195 for (; stackblock(psh) <= --p; *p = 0) { 196 196 if (!strchr(ifs, *p)) 197 197 break; … … 203 203 break; 204 204 } 205 setvar(*ap, stackblock( ), 0);205 setvar(*ap, stackblock(psh), 0); 206 206 207 207 /* Set any remaining args to "" */ -
trunk/src/kash/mystring.c
r809 r1198 111 111 112 112 int 113 number( const char *s)113 number(shinstance *psh, const char *s) 114 114 { 115 115 116 116 if (! is_number(s)) 117 error( "Illegal number: %s", s);117 error(psh, "Illegal number: %s", s); 118 118 return atoi(s); 119 119 } -
trunk/src/kash/mystring.h
r626 r1198 36 36 37 37 #include <string.h> 38 #include "shinstance.h" 38 39 39 40 void scopyn(const char *, char *, int); 40 41 int prefix(const char *, const char *); 41 int number( const char *);42 int number(shinstance *, const char *); 42 43 int is_number(const char *); 43 44 -
trunk/src/kash/options.c
r809 r1198 66 66 #endif 67 67 #include "show.h" 68 69 char *arg0; /* value of $0 */ 70 struct shparam shellparam; /* current positional parameters */ 71 char **argptr; /* argument list for builtin commands */ 72 char *optionarg; /* set by nextopt (like getopt) */ 73 char *optptr; /* used by nextopt */ 74 75 char *minusc; /* argument to -c option */ 76 77 78 STATIC void options(int); 79 STATIC void minus_o(char *, int); 80 STATIC void setoption(int, int); 81 STATIC int getopts(char *, char *, char **, char ***, char **); 68 #include "shinstance.h" 69 70 //char *arg0; /* value of $0 */ 71 //struct shparam shellparam; /* current positional parameters */ 72 //char **argptr; /* argument list for builtin commands */ 73 //char *optionarg; /* set by nextopt (like getopt) */ 74 //char *optptr; /* used by nextopt */ 75 76 //char *minusc; /* argument to -c option */ 77 78 79 STATIC void options(shinstance *, int); 80 STATIC void minus_o(shinstance *, char *, int); 81 STATIC void setoption(shinstance *, int, int); 82 STATIC int getopts(shinstance *, char *, char *, char **, char ***, char **); 82 83 83 84 … … 87 88 88 89 void 89 procargs( int argc, char **argv)90 procargs(shinstance *psh, int argc, char **argv) 90 91 { 91 92 int i; 92 93 93 argptr = argv;94 psh->argptr = argv; 94 95 if (argc > 0) 95 argptr++;96 psh->argptr++; 96 97 for (i = 0; i < NOPTS; i++) 97 optlist[i].val = 2;98 options( 1);99 if (* argptr == NULL &&minusc == NULL)100 sflag = 1;101 if (iflag == 2 && sflag == 1 && isatty(0) && isatty(1))102 iflag = 1;103 if (mflag == 2)104 mflag = iflag;98 psh->optlist[i].val = 2; 99 options(psh, 1); 100 if (*psh->argptr == NULL && psh->minusc == NULL) 101 sflag(psh) = 1; 102 if (iflag(psh) == 2 && sflag(psh) == 1 && shfile_isatty(&psh->fdtab, 0) && shfile_isatty(&psh->fdtab, 1)) 103 iflag(psh) = 1; 104 if (mflag(psh) == 2) 105 mflag(psh) = iflag(psh); 105 106 for (i = 0; i < NOPTS; i++) 106 if ( optlist[i].val == 2)107 optlist[i].val = 0;107 if (psh->optlist[i].val == 2) 108 psh->optlist[i].val = 0; 108 109 #if DEBUG == 2 109 debug = 1;110 #endif 111 arg0 = argv[0];112 if (sflag == 0 &&minusc == NULL) {113 commandname = argv[0];114 arg0 = *argptr++;115 setinputfile( arg0, 0);116 commandname =arg0;110 debug(psh) = 1; 111 #endif 112 psh->arg0 = argv[0]; 113 if (sflag(psh) == 0 && psh->minusc == NULL) { 114 psh->commandname = argv[0]; 115 psh->arg0 = *psh->argptr++; 116 setinputfile(psh, psh->arg0, 0); 117 psh->commandname = psh->arg0; 117 118 } 118 119 /* POSIX 1003.2: first arg after -c cmd is $0, remainder $1... */ 119 if ( minusc != NULL) {120 if ( argptr == NULL || *argptr == NULL)121 error( "Bad -c option");122 minusc = *argptr++;123 if (* argptr != 0)124 arg0 = *argptr++;125 } 126 127 shellparam.p =argptr;128 shellparam.reset = 1;120 if (psh->minusc != NULL) { 121 if (psh->argptr == NULL || *psh->argptr == NULL) 122 error(psh, "Bad -c option"); 123 psh->minusc = *psh->argptr++; 124 if (*psh->argptr != 0) 125 psh->arg0 = *psh->argptr++; 126 } 127 128 psh->shellparam.p = psh->argptr; 129 psh->shellparam.reset = 1; 129 130 /* assert(shellparam.malloc == 0 && shellparam.nparam == 0); */ 130 while (* argptr) {131 shellparam.nparam++;132 argptr++;133 } 134 optschanged( );131 while (*psh->argptr) { 132 psh->shellparam.nparam++; 133 psh->argptr++; 134 } 135 optschanged(psh); 135 136 } 136 137 137 138 138 139 void 139 optschanged( void)140 { 141 setinteractive( iflag);140 optschanged(shinstance *psh) 141 { 142 setinteractive(psh, iflag(psh)); 142 143 #ifndef SMALL 143 histedit( );144 #endif 145 setjobctl( mflag);144 histedit(psh); 145 #endif 146 setjobctl(psh, mflag(psh)); 146 147 } 147 148 … … 152 153 153 154 STATIC void 154 options( int cmdline)155 options(shinstance *psh, int cmdline) 155 156 { 156 157 static char empty[] = ""; … … 160 161 161 162 if (cmdline) 162 minusc = NULL;163 while ((p = * argptr) != NULL) {164 argptr++;163 psh->minusc = NULL; 164 while ((p = *psh->argptr) != NULL) { 165 psh->argptr++; 165 166 if ((c = *p++) == '-') { 166 167 val = 1; … … 169 170 /* "-" means turn off -x and -v */ 170 171 if (p[0] == '\0') 171 xflag = vflag= 0;172 xflag(psh) = vflag(psh) = 0; 172 173 /* "--" means reset params */ 173 else if (* argptr == NULL)174 setparam( argptr);174 else if (*psh->argptr == NULL) 175 setparam(psh, psh->argptr); 175 176 } 176 177 break; /* "-" or "--" terminates options */ … … 179 180 val = 0; 180 181 } else { 181 argptr--;182 psh->argptr--; 182 183 break; 183 184 } … … 185 186 if (c == 'c' && cmdline) { 186 187 /* command is after shell args*/ 187 minusc = empty;188 psh->minusc = empty; 188 189 } else if (c == 'o') { 189 minus_o( *argptr, val);190 if (* argptr)191 argptr++;190 minus_o(psh, *psh->argptr, val); 191 if (*psh->argptr) 192 psh->argptr++; 192 193 } else { 193 setoption( c, val);194 setoption(psh, c, val); 194 195 } 195 196 } … … 198 199 199 200 static void 200 set_opt_val( int i, int val)201 set_opt_val(shinstance *psh, int i, int val) 201 202 { 202 203 int j; 203 204 int flag; 204 205 205 if (val && (flag = optlist[i].opt_set)) {206 if (val && (flag = psh->optlist[i].opt_set)) { 206 207 /* some options (eg vi/emacs) are mutually exclusive */ 207 208 for (j = 0; j < NOPTS; j++) 208 if ( optlist[j].opt_set == flag)209 optlist[j].val = 0;210 } 211 optlist[i].val = val;209 if (psh->optlist[j].opt_set == flag) 210 psh->optlist[j].val = 0; 211 } 212 psh->optlist[i].val = val; 212 213 #ifdef DEBUG 213 if (& optlist[i].val == &debug)214 if (&psh->optlist[i].val == &debug(psh)) 214 215 opentrace(); 215 216 #endif … … 217 218 218 219 STATIC void 219 minus_o( char *name, int val)220 minus_o(shinstance *psh, char *name, int val) 220 221 { 221 222 int i; 222 223 223 224 if (name == NULL) { 224 out1str( "Current option settings\n");225 out1str(psh, "Current option settings\n"); 225 226 for (i = 0; i < NOPTS; i++) 226 out1fmt( "%-16s%s\n",optlist[i].name,227 optlist[i].val ? "on" : "off");227 out1fmt(psh, "%-16s%s\n", psh->optlist[i].name, 228 psh->optlist[i].val ? "on" : "off"); 228 229 } else { 229 230 for (i = 0; i < NOPTS; i++) 230 if (equal(name, optlist[i].name)) {231 set_opt_val( i, val);231 if (equal(name, psh->optlist[i].name)) { 232 set_opt_val(psh, i, val); 232 233 return; 233 234 } 234 error( "Illegal option -o %s", name);235 error(psh, "Illegal option -o %s", name); 235 236 } 236 237 } … … 238 239 239 240 STATIC void 240 setoption( int flag, int val)241 setoption(shinstance *psh, int flag, int val) 241 242 { 242 243 int i; 243 244 244 245 for (i = 0; i < NOPTS; i++) 245 if ( optlist[i].letter == flag) {246 set_opt_val( i, val );246 if (psh->optlist[i].letter == flag) { 247 set_opt_val(psh, i, val ); 247 248 return; 248 249 } 249 error( "Illegal option -%c", flag);250 error(psh, "Illegal option -%c", flag); 250 251 /* NOTREACHED */ 251 252 } … … 259 260 int i; 260 261 261 for (i = 0; optlist[i].name; i++)262 optlist[i].val = 0;263 optschanged( );262 for (i = 0; psh->optlist[i].name; i++) 263 psh->optlist[i].val = 0; 264 optschanged(psh); 264 265 265 266 } … … 272 273 273 274 void 274 setparam( char **argv)275 setparam(shinstance *psh, char **argv) 275 276 { 276 277 char **newparam; … … 285 286 } 286 287 *ap = NULL; 287 freeparam(& shellparam);288 shellparam.malloc = 1;289 shellparam.nparam = nparam;290 shellparam.p = newparam;291 shellparam.optnext = NULL;288 freeparam(&psh->shellparam); 289 psh->shellparam.malloc = 1; 290 psh->shellparam.nparam = nparam; 291 psh->shellparam.p = newparam; 292 psh->shellparam.optnext = NULL; 292 293 } 293 294 … … 316 317 317 318 int 318 shiftcmd( int argc, char **argv)319 shiftcmd(shinstance *psh, int argc, char **argv) 319 320 { 320 321 int n; … … 323 324 n = 1; 324 325 if (argc > 1) 325 n = number( argv[1]);326 if (n > shellparam.nparam)327 error( "can't shift that many");326 n = number(psh, argv[1]); 327 if (n > psh->shellparam.nparam) 328 error(psh, "can't shift that many"); 328 329 INTOFF; 329 shellparam.nparam -= n;330 for (ap1 = shellparam.p ; --n >= 0 ; ap1++) {331 if ( shellparam.malloc)330 psh->shellparam.nparam -= n; 331 for (ap1 = psh->shellparam.p ; --n >= 0 ; ap1++) { 332 if (psh->shellparam.malloc) 332 333 ckfree(*ap1); 333 334 } 334 ap2 = shellparam.p;335 ap2 = psh->shellparam.p; 335 336 while ((*ap2++ = *ap1++) != NULL); 336 shellparam.optnext = NULL;337 psh->shellparam.optnext = NULL; 337 338 INTON; 338 339 return 0; … … 346 347 347 348 int 348 setcmd( int argc, char **argv)349 setcmd(shinstance *psh, int argc, char **argv) 349 350 { 350 351 if (argc == 1) 351 return showvars( 0, 0, 1);352 return showvars(psh, 0, 0, 1); 352 353 INTOFF; 353 options( 0);354 optschanged( );355 if (* argptr != NULL) {356 setparam( argptr);354 options(psh, 0); 355 optschanged(psh); 356 if (*psh->argptr != NULL) { 357 setparam(psh, psh->argptr); 357 358 } 358 359 INTON; … … 362 363 363 364 void 364 getoptsreset(value) 365 const char *value; 366 { 367 if (number(value) == 1) { 368 shellparam.optnext = NULL; 369 shellparam.reset = 1; 365 getoptsreset(shinstance *psh, const char *value) 366 { 367 if (number(psh, value) == 1) { 368 psh->shellparam.optnext = NULL; 369 psh->shellparam.reset = 1; 370 370 } 371 371 } … … 379 379 380 380 int 381 getoptscmd( int argc, char **argv)381 getoptscmd(shinstance *psh, int argc, char **argv) 382 382 { 383 383 char **optbase; 384 384 385 385 if (argc < 3) 386 error( "usage: getopts optstring var [arg]");386 error(psh, "usage: getopts optstring var [arg]"); 387 387 else if (argc == 3) 388 optbase = shellparam.p;388 optbase = psh->shellparam.p; 389 389 else 390 390 optbase = &argv[3]; 391 391 392 if ( shellparam.reset == 1) {393 shellparam.optnext = optbase;394 shellparam.optptr = NULL;395 shellparam.reset = 0;396 } 397 398 return getopts( argv[1], argv[2], optbase, &shellparam.optnext,399 & shellparam.optptr);392 if (psh->shellparam.reset == 1) { 393 psh->shellparam.optnext = optbase; 394 psh->shellparam.optptr = NULL; 395 psh->shellparam.reset = 0; 396 } 397 398 return getopts(psh, argv[1], argv[2], optbase, &psh->shellparam.optnext, 399 &psh->shellparam.optptr); 400 400 } 401 401 402 402 STATIC int 403 getopts( char *optstr, char *optvar, char **optfirst, char ***optnext, char **optpptr)403 getopts(shinstance *psh, char *optstr, char *optvar, char **optfirst, char ***optnext, char **optpptr) 404 404 { 405 405 char *p, *q; … … 417 417 if (p == NULL || *p != '-' || *++p == '\0') { 418 418 atend: 419 ind = *optnext - optfirst + 1;419 ind = (int)(*optnext - optfirst + 1); 420 420 *optnext = NULL; 421 421 p = NULL; … … 434 434 s[0] = c; 435 435 s[1] = '\0'; 436 err |= setvarsafe( "OPTARG", s, 0);436 err |= setvarsafe(psh, "OPTARG", s, 0); 437 437 } else { 438 outfmt(& errout, "Illegal option -%c\n", c);439 (void) unsetvar( "OPTARG", 0);438 outfmt(&psh->errout, "Illegal option -%c\n", c); 439 (void) unsetvar(psh, "OPTARG", 0); 440 440 } 441 441 c = '?'; … … 451 451 s[0] = c; 452 452 s[1] = '\0'; 453 err |= setvarsafe( "OPTARG", s, 0);453 err |= setvarsafe(psh, "OPTARG", s, 0); 454 454 c = ':'; 455 455 } else { 456 outfmt(& errout, "No arg for -%c option\n", c);457 (void) unsetvar( "OPTARG", 0);456 outfmt(&psh->errout, "No arg for -%c option\n", c); 457 (void) unsetvar(psh, "OPTARG", 0); 458 458 c = '?'; 459 459 } … … 463 463 if (p == **optnext) 464 464 (*optnext)++; 465 err |= setvarsafe( "OPTARG", p, 0);465 err |= setvarsafe(psh, "OPTARG", p, 0); 466 466 p = NULL; 467 467 } else 468 err |= setvarsafe( "OPTARG", "", 0);469 ind = *optnext - optfirst + 1;468 err |= setvarsafe(psh, "OPTARG", "", 0); 469 ind = (int)(*optnext - optfirst + 1); 470 470 goto out; 471 471 … … 477 477 *optpptr = p; 478 478 fmtstr(s, sizeof(s), "%d", ind); 479 err |= setvarsafe( "OPTIND", s, VNOFUNC);479 err |= setvarsafe(psh, "OPTIND", s, VNOFUNC); 480 480 s[0] = c; 481 481 s[1] = '\0'; 482 err |= setvarsafe( optvar, s, 0);482 err |= setvarsafe(psh, optvar, s, 0); 483 483 if (err) { 484 484 *optnext = NULL; 485 485 *optpptr = NULL; 486 output_flushall( );487 exraise( EXERROR);486 output_flushall(psh); 487 exraise(psh, EXERROR); 488 488 } 489 489 return done; … … 502 502 503 503 int 504 nextopt( const char *optstring)504 nextopt(shinstance *psh, const char *optstring) 505 505 { 506 506 char *p; … … 508 508 char c; 509 509 510 if ((p = optptr) == NULL || *p == '\0') {511 p = * argptr;510 if ((p = psh->optptr) == NULL || *p == '\0') { 511 p = *psh->argptr; 512 512 if (p == NULL || *p != '-' || *++p == '\0') 513 513 return '\0'; 514 argptr++;514 psh->argptr++; 515 515 if (p[0] == '-' && p[1] == '\0') /* check for "--" */ 516 516 return '\0'; … … 519 519 for (q = optstring ; *q != c ; ) { 520 520 if (*q == '\0') 521 error( "Illegal option -%c", c);521 error(psh, "Illegal option -%c", c); 522 522 if (*++q == ':') 523 523 q++; 524 524 } 525 525 if (*++q == ':') { 526 if (*p == '\0' && (p = * argptr++) == NULL)527 error( "No arg for -%c option", c);528 optionarg = p;526 if (*p == '\0' && (p = *psh->argptr++) == NULL) 527 error(psh, "No arg for -%c option", c); 528 psh->optionarg = p; 529 529 p = NULL; 530 530 } 531 optptr = p;531 psh->optptr = p; 532 532 return c; 533 533 } -
trunk/src/kash/options.h
r884 r1198 35 35 */ 36 36 37 #ifndef ___options_h 38 #define ___options_h 39 37 40 struct shparam { 38 41 int nparam; /* # of positional parameters (without $0) */ … … 58 61 #else 59 62 # define NOPTS 20 60 #endif 63 #endif 61 64 62 65 #ifdef DEFINE_OPTIONS … … 69 72 70 73 DEF_OPT( "errexit", 'e' ) /* exit on error */ 71 #define eflag 74 #define eflag(psh) (psh)->optlist[0].val 72 75 DEF_OPT( "noglob", 'f' ) /* no pathname expansion */ 73 #define fflag 76 #define fflag(psh) (psh)->optlist[1].val 74 77 DEF_OPT( "ignoreeof", 'I' ) /* do not exit on EOF */ 75 #define Iflag 78 #define Iflag(psh) (psh)->optlist[2].val 76 79 DEF_OPT( "interactive",'i' ) /* interactive shell */ 77 #define iflag 80 #define iflag(psh) (psh)->optlist[3].val 78 81 DEF_OPT( "monitor", 'm' ) /* job control */ 79 #define mflag 82 #define mflag(psh) (psh)->optlist[4].val 80 83 DEF_OPT( "noexec", 'n' ) /* [U] do not exec commands */ 81 #define nflag 84 #define nflag(psh) (psh)->optlist[5].val 82 85 DEF_OPT( "stdin", 's' ) /* read from stdin */ 83 #define sflag 86 #define sflag(psh) (psh)->optlist[6].val 84 87 DEF_OPT( "xtrace", 'x' ) /* trace after expansion */ 85 #define xflag 88 #define xflag(psh) (psh)->optlist[7].val 86 89 DEF_OPT( "verbose", 'v' ) /* trace read input */ 87 #define vflag 90 #define vflag(psh) (psh)->optlist[8].val 88 91 DEF_OPTS( "vi", 'V', 'V' ) /* vi style editing */ 89 #define Vflag 92 #define Vflag(psh) (psh)->optlist[9].val 90 93 DEF_OPTS( "emacs", 'E', 'V' ) /* emacs style editing */ 91 #define Eflag 94 #define Eflag(psh) (psh)->optlist[10].val 92 95 DEF_OPT( "noclobber", 'C' ) /* do not overwrite files with > */ 93 #define Cflag 96 #define Cflag(psh) (psh)->optlist[11].val 94 97 DEF_OPT( "allexport", 'a' ) /* export all variables */ 95 #define aflag 98 #define aflag(psh) (psh)->optlist[12].val 96 99 DEF_OPT( "notify", 'b' ) /* [U] report completion of background jobs */ 97 #define bflag 100 #define bflag(psh) (psh)->optlist[13].val 98 101 DEF_OPT( "nounset", 'u' ) /* error expansion of unset variables */ 99 #define uflag 102 #define uflag(psh) (psh)->optlist[14].val 100 103 DEF_OPT( "quietprofile", 'q' ) 101 #define qflag 104 #define qflag(psh) (psh)->optlist[15].val 102 105 DEF_OPT( "nolog", 0 ) /* [U] no functon defs in command history */ 103 #define nolog 106 #define nolog(psh) (psh)->optlist[16].val 104 107 DEF_OPT( "cdprint", 0 ) /* always print result of cd */ 105 #define cdprint 108 #define cdprint(psh) (psh)->optlist[17].val 106 109 DEF_OPT( "tabcomplete", 0 ) /* <tab> causes filename expansion */ 107 #define tabcomplete 110 #define tabcomplete(psh) (psh)->optlist[18].val 108 111 #ifdef DEBUG 109 112 DEF_OPT( "debug", 0 ) /* enable debug prints */ 110 #define debug 113 #define debug(psh) (psh)->optlist[19].val 111 114 #endif 112 115 … … 136 139 int nextopt(struct shinstance *, const char *); 137 140 void getoptsreset(struct shinstance *, const char *); 141 142 #endif -
trunk/src/kash/output.c
r883 r1198 190 190 if (dest->buf == NULL || dest->nextc == dest->buf || dest->fd < 0) 191 191 return; 192 if (xwrite( dest->fd, dest->buf, dest->nextc - dest->buf) < 0)192 if (xwrite(psh, dest->fd, dest->buf, dest->nextc - dest->buf) < 0) 193 193 dest->flags |= OUTPUT_ERR; 194 194 dest->nextc = dest->buf; … … 480 480 481 481 int 482 xwrite( int fd, char *buf, int nbytes)482 xwrite(shinstance *psh, int fd, char *buf, int nbytes) 483 483 { 484 484 int ntry; … … 489 489 ntry = 0; 490 490 for (;;) { 491 i = write(fd, buf, n);491 i = shfile_write(&psh->fdtab, fd, buf, n); 492 492 if (i > 0) { 493 493 if ((n -= i) <= 0) … … 511 511 512 512 int 513 xioctl( int fd, unsigned long request, char *arg)513 xioctl(shinstance *psh, int fd, unsigned long request, char *arg) 514 514 { 515 515 int i; 516 516 517 while ((i = ioctl(fd, request, arg)) == -1 && errno == EINTR);517 while ((i = shfile_ioctl(&psh->fdtab, fd, request, arg)) == -1 && errno == EINTR); 518 518 return i; 519 519 } -
trunk/src/kash/output.h
r883 r1198 72 72 __attribute__((__format__(__printf__,3,4))); 73 73 void doformat(struct output *, const char *, va_list); 74 int xwrite( int, char *, int);75 int xioctl( int, unsigned long, char *);74 int xwrite(struct shinstance *, int, char *, int); 75 int xioctl(struct shinstance *, int, unsigned long, char *); 76 76 77 77 #define outc(c, file) (--(file)->nleft < 0? (emptyoutbuf(file), *(file)->nextc++ = (c)) : (*(file)->nextc++ = (c))) -
trunk/src/kash/parser.c
r809 r1198 171 171 n2->type = NBACKGND; 172 172 } else { 173 n3 = (union node *)stalloc( sizeof (struct nredir));173 n3 = (union node *)stalloc(psh, sizeof (struct nredir)); 174 174 n3->type = NBACKGND; 175 175 n3->nredir.n = n2; … … 182 182 } 183 183 else { 184 n3 = (union node *)stalloc( sizeof (struct nbinary));184 n3 = (union node *)stalloc(psh, sizeof (struct nbinary)); 185 185 n3->type = NSEMI; 186 186 n3->nbinary.ch1 = n1; … … 239 239 } 240 240 n2 = pipeline(); 241 n3 = (union node *)stalloc( sizeof (struct nbinary));241 n3 = (union node *)stalloc(psh, sizeof (struct nbinary)); 242 242 n3->type = t; 243 243 n3->nbinary.ch1 = n1; … … 263 263 n1 = command(); 264 264 if (readtoken() == TPIPE) { 265 pipenode = (union node *)stalloc( sizeof (struct npipe));265 pipenode = (union node *)stalloc(psh, sizeof (struct npipe)); 266 266 pipenode->type = NPIPE; 267 267 pipenode->npipe.backgnd = 0; 268 lp = (struct nodelist *)stalloc( sizeof (struct nodelist));268 lp = (struct nodelist *)stalloc(psh, sizeof (struct nodelist)); 269 269 pipenode->npipe.cmdlist = lp; 270 270 lp->n = n1; 271 271 do { 272 272 prev = lp; 273 lp = (struct nodelist *)stalloc( sizeof (struct nodelist));273 lp = (struct nodelist *)stalloc(psh, sizeof (struct nodelist)); 274 274 lp->n = command(); 275 275 prev->next = lp; … … 280 280 tokpushback++; 281 281 if (negate) { 282 n2 = (union node *)stalloc( sizeof (struct nnot));282 n2 = (union node *)stalloc(psh, sizeof (struct nnot)); 283 283 n2->type = NNOT; 284 284 n2->nnot.com = n1; … … 320 320 switch (readtoken()) { 321 321 case TIF: 322 n1 = (union node *)stalloc( sizeof (struct nif));322 n1 = (union node *)stalloc(psh, sizeof (struct nif)); 323 323 n1->type = NIF; 324 324 n1->nif.test = list(0); … … 328 328 n2 = n1; 329 329 while (readtoken() == TELIF) { 330 n2->nif.elsepart = (union node *)stalloc( sizeof (struct nif));330 n2->nif.elsepart = (union node *)stalloc(psh, sizeof (struct nif)); 331 331 n2 = n2->nif.elsepart; 332 332 n2->type = NIF; … … 349 349 case TUNTIL: { 350 350 int got; 351 n1 = (union node *)stalloc( sizeof (struct nbinary));351 n1 = (union node *)stalloc(psh, sizeof (struct nbinary)); 352 352 n1->type = (lasttoken == TWHILE)? NWHILE : NUNTIL; 353 353 n1->nbinary.ch1 = list(0); … … 365 365 if (readtoken() != TWORD || quoteflag || ! goodname(wordtext)) 366 366 synerror("Bad for loop variable"); 367 n1 = (union node *)stalloc( sizeof (struct nfor));367 n1 = (union node *)stalloc(psh, sizeof (struct nfor)); 368 368 n1->type = NFOR; 369 369 n1->nfor.var = wordtext; … … 371 371 app = ≈ 372 372 while (readtoken() == TWORD) { 373 n2 = (union node *)stalloc( sizeof (struct narg));373 n2 = (union node *)stalloc(psh, sizeof (struct narg)); 374 374 n2->type = NARG; 375 375 n2->narg.text = wordtext; … … 385 385 static char argvars[5] = {CTLVAR, VSNORMAL|VSQUOTE, 386 386 '@', '=', '\0'}; 387 n2 = (union node *)stalloc( sizeof (struct narg));387 n2 = (union node *)stalloc(psh, sizeof (struct narg)); 388 388 n2->type = NARG; 389 389 n2->narg.text = argvars; … … 411 411 break; 412 412 case TCASE: 413 n1 = (union node *)stalloc( sizeof (struct ncase));413 n1 = (union node *)stalloc(psh, sizeof (struct ncase)); 414 414 n1->type = NCASE; 415 415 if (readtoken() != TWORD) 416 416 synexpect(TWORD); 417 n1->ncase.expr = n2 = (union node *)stalloc( sizeof (struct narg));417 n1->ncase.expr = n2 = (union node *)stalloc(psh, sizeof (struct narg)); 418 418 n2->type = NARG; 419 419 n2->narg.text = wordtext; … … 427 427 checkkwd = 2, readtoken(); 428 428 do { 429 *cpp = cp = (union node *)stalloc( sizeof (struct nclist));429 *cpp = cp = (union node *)stalloc(psh, sizeof (struct nclist)); 430 430 cp->type = NCLIST; 431 431 app = &cp->nclist.pattern; 432 432 for (;;) { 433 *app = ap = (union node *)stalloc( sizeof (struct narg));433 *app = ap = (union node *)stalloc(psh, sizeof (struct narg)); 434 434 ap->type = NARG; 435 435 ap->narg.text = wordtext; … … 465 465 break; 466 466 case TLP: 467 n1 = (union node *)stalloc( sizeof (struct nredir));467 n1 = (union node *)stalloc(psh, sizeof (struct nredir)); 468 468 n1->type = NSUBSHELL; 469 469 n1->nredir.n = list(0); … … 511 511 if (redir) { 512 512 if (n1->type != NSUBSHELL) { 513 n2 = (union node *)stalloc( sizeof (struct nredir));513 n2 = (union node *)stalloc(psh, sizeof (struct nredir)); 514 514 n2->type = NREDIR; 515 515 n2->nredir.n = n1; … … 521 521 checkneg: 522 522 if (negate) { 523 n2 = (union node *)stalloc( sizeof (struct nnot));523 n2 = (union node *)stalloc(psh, sizeof (struct nnot)); 524 524 n2->type = NNOT; 525 525 n2->nnot.com = n1; … … 561 561 for (;;) { 562 562 if (readtoken() == TWORD) { 563 n = (union node *)stalloc( sizeof (struct narg));563 n = (union node *)stalloc(psh, sizeof (struct narg)); 564 564 n->type = NARG; 565 565 n->narg.text = wordtext; … … 590 590 *app = NULL; 591 591 *rpp = NULL; 592 n = (union node *)stalloc( sizeof (struct ncmd));592 n = (union node *)stalloc(psh, sizeof (struct ncmd)); 593 593 n->type = NCMD; 594 594 n->ncmd.backgnd = 0; … … 598 598 checkneg: 599 599 if (negate) { 600 n2 = (union node *)stalloc( sizeof (struct nnot));600 n2 = (union node *)stalloc(psh, sizeof (struct nnot)); 601 601 n2->type = NNOT; 602 602 n2->nnot.com = n; … … 612 612 union node *n; 613 613 614 n = (union node *)stalloc( sizeof (struct narg));614 n = (union node *)stalloc(psh, sizeof (struct narg)); 615 615 n->type = NARG; 616 616 n->narg.next = NULL; … … 697 697 readtoken1(pgetc(), here->here->type == NHERE? SQSYNTAX : DQSYNTAX, 698 698 here->eofmark, here->striptabs); 699 n = (union node *)stalloc( sizeof (struct narg));699 n = (union node *)stalloc(psh, sizeof (struct narg)); 700 700 n->narg.type = NARG; 701 701 n->narg.next = NULL; … … 953 953 parenlevel = 0; 954 954 955 STARTSTACKSTR( out);955 STARTSTACKSTR(psh, out); 956 956 loop: { /* for each line, until end of word */ 957 957 #if ATTY … … 967 967 CHECKEND(); /* set c to PEOF if at end of here document */ 968 968 for (;;) { /* until end of line or end of word */ 969 CHECKSTRSPACE( 4, out); /* permit 4 calls to USTPUTC */969 CHECKSTRSPACE(psh, 4, out); /* permit 4 calls to USTPUTC */ 970 970 switch(syntax[c]) { 971 971 case CNL: /* '\n' */ 972 972 if (syntax == BASESYNTAX) 973 973 goto endword; /* exit outer loop */ 974 USTPUTC( c, out);974 USTPUTC(psh, c, out); 975 975 plinno++; 976 976 if (doprompt) … … 981 981 goto loop; /* continue outer loop */ 982 982 case CWORD: 983 USTPUTC( c, out);983 USTPUTC(psh, c, out); 984 984 break; 985 985 case CCTL: 986 986 if (eofmark == NULL || ISDBLQUOTE()) 987 USTPUTC( CTLESC, out);988 USTPUTC( c, out);987 USTPUTC(psh, CTLESC, out); 988 USTPUTC(psh, c, out); 989 989 break; 990 990 case CBACK: /* backslash */ 991 991 c = pgetc(); 992 992 if (c == PEOF) { 993 USTPUTC( '\\', out);993 USTPUTC(psh, '\\', out); 994 994 pungetc(); 995 995 break; … … 1006 1006 c != '`' && c != '$' && 1007 1007 (c != '"' || eofmark != NULL)) 1008 USTPUTC( '\\', out);1008 USTPUTC(psh, '\\', out); 1009 1009 if (SQSYNTAX[c] == CCTL) 1010 USTPUTC( CTLESC, out);1010 USTPUTC(psh, CTLESC, out); 1011 1011 else if (eofmark == NULL) { 1012 USTPUTC( CTLQUOTEMARK, out);1013 USTPUTC( c, out);1012 USTPUTC(psh, CTLQUOTEMARK, out); 1013 USTPUTC(psh, c, out); 1014 1014 if (varnest != 0) 1015 USTPUTC( CTLQUOTEEND, out);1015 USTPUTC(psh, CTLQUOTEEND, out); 1016 1016 break; 1017 1017 } 1018 USTPUTC( c, out);1018 USTPUTC(psh, c, out); 1019 1019 break; 1020 1020 case CSQUOTE: 1021 1021 if (syntax != SQSYNTAX) { 1022 1022 if (eofmark == NULL) 1023 USTPUTC( CTLQUOTEMARK, out);1023 USTPUTC(psh, CTLQUOTEMARK, out); 1024 1024 quotef = 1; 1025 1025 syntax = SQSYNTAX; … … 1029 1029 varnest == 0) { 1030 1030 /* Ignore inside quoted here document */ 1031 USTPUTC( c, out);1031 USTPUTC(psh, c, out); 1032 1032 break; 1033 1033 } … … 1038 1038 syntax = BASESYNTAX; 1039 1039 if (varnest != 0) 1040 USTPUTC( CTLQUOTEEND, out);1040 USTPUTC(psh, CTLQUOTEEND, out); 1041 1041 } 1042 1042 break; … … 1045 1045 varnest == 0) { 1046 1046 /* Ignore inside here document */ 1047 USTPUTC( c, out);1047 USTPUTC(psh, c, out); 1048 1048 break; 1049 1049 } … … 1056 1056 syntax = DQSYNTAX; 1057 1057 SETDBLQUOTE(); 1058 USTPUTC( CTLQUOTEMARK, out);1058 USTPUTC(psh, CTLQUOTEMARK, out); 1059 1059 } 1060 1060 break; … … 1064 1064 if (ISDBLQUOTE()) { 1065 1065 if (varnest != 0) 1066 USTPUTC( CTLQUOTEEND, out);1066 USTPUTC(psh, CTLQUOTEEND, out); 1067 1067 syntax = BASESYNTAX; 1068 1068 CLRDBLQUOTE(); … … 1070 1070 syntax = DQSYNTAX; 1071 1071 SETDBLQUOTE(); 1072 USTPUTC( CTLQUOTEMARK, out);1072 USTPUTC(psh, CTLQUOTEMARK, out); 1073 1073 } 1074 1074 break; … … 1079 1079 if (varnest > 0 && !ISDBLQUOTE()) { 1080 1080 varnest--; 1081 USTPUTC( CTLENDVAR, out);1081 USTPUTC(psh, CTLENDVAR, out); 1082 1082 } else { 1083 USTPUTC( c, out);1083 USTPUTC(psh, c, out); 1084 1084 } 1085 1085 break; 1086 1086 case CLP: /* '(' in arithmetic */ 1087 1087 parenlevel++; 1088 USTPUTC( c, out);1088 USTPUTC(psh, c, out); 1089 1089 break; 1090 1090 case CRP: /* ')' in arithmetic */ 1091 1091 if (parenlevel > 0) { 1092 USTPUTC( c, out);1092 USTPUTC(psh, c, out); 1093 1093 --parenlevel; 1094 1094 } else { 1095 1095 if (pgetc() == ')') { 1096 1096 if (--arinest == 0) { 1097 USTPUTC( CTLENDARI, out);1097 USTPUTC(psh, CTLENDARI, out); 1098 1098 syntax = prevsyntax; 1099 1099 if (syntax == DQSYNTAX) … … 1102 1102 CLRDBLQUOTE(); 1103 1103 } else 1104 USTPUTC( ')', out);1104 USTPUTC(psh, ')', out); 1105 1105 } else { 1106 1106 /* … … 1109 1109 */ 1110 1110 pungetc(); 1111 USTPUTC( ')', out);1111 USTPUTC(psh, ')', out); 1112 1112 } 1113 1113 } … … 1121 1121 if (varnest == 0) 1122 1122 goto endword; /* exit outer loop */ 1123 USTPUTC( c, out);1123 USTPUTC(psh, c, out); 1124 1124 } 1125 1125 c = pgetc_macro(); … … 1136 1136 synerror("Missing '}'"); 1137 1137 } 1138 USTPUTC( '\0', out);1139 len = out - stackblock( );1140 out = stackblock( );1138 USTPUTC(psh, '\0', out); 1139 len = out - stackblock(psh); 1140 out = stackblock(psh); 1141 1141 if (eofmark == NULL) { 1142 1142 if ((c == '>' || c == '<') … … 1152 1152 quoteflag = quotef; 1153 1153 backquotelist = bqlist; 1154 grabstackblock( len);1154 grabstackblock(psh, len); 1155 1155 wordtext = out; 1156 1156 if (dblquotep != NULL) … … 1203 1203 union node *np; 1204 1204 1205 np = (union node *)stalloc( sizeof (struct nfile));1205 np = (union node *)stalloc(psh, sizeof (struct nfile)); 1206 1206 if (c == '>') { 1207 1207 np->nfile.fd = 1; … … 1222 1222 case '<': 1223 1223 if (sizeof (struct nfile) != sizeof (struct nhere)) { 1224 np = (union node *)stalloc( sizeof (struct nhere));1224 np = (union node *)stalloc(psh, sizeof (struct nhere)); 1225 1225 np->nfile.fd = 0; 1226 1226 } 1227 1227 np->type = NHERE; 1228 heredoc = (struct heredoc *)stalloc( sizeof (struct heredoc));1228 heredoc = (struct heredoc *)stalloc(psh, sizeof (struct heredoc)); 1229 1229 heredoc->here = np; 1230 1230 if ((c = pgetc()) == '-') { … … 1271 1271 c = pgetc(); 1272 1272 if (c != '(' && c != OPENBRACE && !is_name(c) && !is_special(c)) { 1273 USTPUTC( '$', out);1273 USTPUTC(psh, '$', out); 1274 1274 pungetc(); 1275 1275 } else if (c == '(') { /* $(command) or $((arith)) */ … … 1281 1281 } 1282 1282 } else { 1283 USTPUTC( CTLVAR, out);1284 typeloc = out - stackblock( );1285 USTPUTC( VSNORMAL, out);1283 USTPUTC(psh, CTLVAR, out); 1284 typeloc = out - stackblock(psh); 1285 USTPUTC(psh, VSNORMAL, out); 1286 1286 subtype = VSNORMAL; 1287 1287 if (c == OPENBRACE) { … … 1298 1298 if (is_name(c)) { 1299 1299 do { 1300 STPUTC( c, out);1300 STPUTC(psh, c, out); 1301 1301 c = pgetc(); 1302 1302 } while (is_in_name(c)); 1303 1303 } else if (is_digit(c)) { 1304 1304 do { 1305 USTPUTC( c, out);1305 USTPUTC(psh, c, out); 1306 1306 c = pgetc(); 1307 1307 } while (is_digit(c)); 1308 1308 } 1309 1309 else if (is_special(c)) { 1310 USTPUTC( c, out);1310 USTPUTC(psh, c, out); 1311 1311 c = pgetc(); 1312 1312 } … … 1314 1314 badsub: synerror("Bad substitution"); 1315 1315 1316 STPUTC( '=', out);1316 STPUTC(psh, '=', out); 1317 1317 flags = 0; 1318 1318 if (subtype == 0) { … … 1347 1347 if (ISDBLQUOTE() || arinest) 1348 1348 flags |= VSQUOTE; 1349 *(stackblock( ) + typeloc) = subtype | flags;1349 *(stackblock(psh) + typeloc) = subtype | flags; 1350 1350 if (subtype != VSNORMAL) { 1351 1351 varnest++; … … 1391 1391 INTOFF; 1392 1392 str = NULL; 1393 savelen = out - stackblock( );1393 savelen = out - stackblock(psh); 1394 1394 if (savelen > 0) { 1395 1395 str = ckmalloc(savelen); 1396 memcpy(str, stackblock( ), savelen);1396 memcpy(str, stackblock(psh), savelen); 1397 1397 } 1398 1398 savehandler = handler; … … 1409 1409 1410 1410 1411 STARTSTACKSTR(p out);1411 STARTSTACKSTR(psh, pout); 1412 1412 for (;;) { 1413 1413 if (needprompt) { … … 1436 1436 if (pc != '\\' && pc != '`' && pc != '$' 1437 1437 && (!ISDBLQUOTE() || pc != '"')) 1438 STPUTC( '\\', pout);1438 STPUTC(psh, '\\', pout); 1439 1439 break; 1440 1440 … … 1452 1452 break; 1453 1453 } 1454 STPUTC(p c, pout);1454 STPUTC(psh, pc, pout); 1455 1455 } 1456 1456 done: 1457 STPUTC( '\0', pout);1458 psavelen = pout - stackblock( );1457 STPUTC(psh, '\0', pout); 1458 psavelen = pout - stackblock(psh); 1459 1459 if (psavelen > 0) { 1460 pstr = grabstackstr(p out);1460 pstr = grabstackstr(psh, pout); 1461 1461 setinputstring(pstr, 1); 1462 1462 } … … 1465 1465 while (*nlpp) 1466 1466 nlpp = &(*nlpp)->next; 1467 *nlpp = (struct nodelist *)stalloc( sizeof (struct nodelist));1467 *nlpp = (struct nodelist *)stalloc(psh, sizeof (struct nodelist)); 1468 1468 (*nlpp)->next = NULL; 1469 1469 parsebackquote = oldstyle; … … 1492 1492 tokpushback = 0; 1493 1493 } 1494 while (stackblocksize( ) <= savelen)1495 growstackblock( );1496 STARTSTACKSTR( out);1494 while (stackblocksize(psh) <= savelen) 1495 growstackblock(psh); 1496 STARTSTACKSTR(psh, out); 1497 1497 if (str) { 1498 1498 memcpy(out, str, savelen); 1499 STADJUST( savelen, out);1499 STADJUST(psh, savelen, out); 1500 1500 INTOFF; 1501 1501 ckfree(str); … … 1506 1506 handler = savehandler; 1507 1507 if (arinest || ISDBLQUOTE()) 1508 USTPUTC( CTLBACKQ | CTLQUOTE, out);1508 USTPUTC(psh, CTLBACKQ | CTLQUOTE, out); 1509 1509 else 1510 USTPUTC( CTLBACKQ, out);1510 USTPUTC(psh, CTLBACKQ, out); 1511 1511 if (oldstyle) 1512 1512 goto parsebackq_oldreturn; … … 1523 1523 prevsyntax = syntax; 1524 1524 syntax = ARISYNTAX; 1525 USTPUTC( CTLARI, out);1525 USTPUTC(psh, CTLARI, out); 1526 1526 if (ISDBLQUOTE()) 1527 USTPUTC( '"',out);1527 USTPUTC(psh, '"',out); 1528 1528 else 1529 USTPUTC( ' ',out);1529 USTPUTC(psh, ' ',out); 1530 1530 } else { 1531 1531 /* … … 1533 1533 * parenthesis, which should be equivalent 1534 1534 */ 1535 USTPUTC( '(', out);1535 USTPUTC(psh, '(', out); 1536 1536 } 1537 1537 goto parsearith_return; -
trunk/src/kash/redir.c
r809 r1198 206 206 break; 207 207 case NTO: 208 if (Cflag )208 if (Cflag(psh)) 209 209 oflags |= O_EXCL; 210 210 /* FALLTHROUGH */ … … 267 267 len = strlen(redir->nhere.doc->narg.text); 268 268 if (len <= PIPESIZE) { 269 xwrite(p ip[1], redir->nhere.doc->narg.text, len);269 xwrite(psh, pip[1], redir->nhere.doc->narg.text, len); 270 270 goto out; 271 271 } … … 281 281 signal(SIGPIPE, SIG_DFL); 282 282 if (redir->type == NHERE) 283 xwrite(p ip[1], redir->nhere.doc->narg.text, len);283 xwrite(psh, pip[1], redir->nhere.doc->narg.text, len); 284 284 else 285 285 expandhere(redir->nhere.doc, pip[1]); -
trunk/src/kash/shfile.h
r884 r1198 2 2 /** @file 3 3 * 4 * File management. 4 * File management. 5 5 * 6 6 * Copyright (c) 2007 knut st. osmundsen <[email protected]> … … 55 55 int shfile_pipe(shfdtab *, int [2]); 56 56 int shfile_close(shfdtab *, unsigned); 57 long shfile_read(shfdtab *, int, void *, size_t); 58 long shfile_write(shfdtab *, int, const void *, size_t); 59 long shfile_lseek(shfdtab *, int, long, int); 57 60 int shfile_fcntl(shfdtab *, int fd, int cmd, int arg); 58 61 #ifdef _MSC_VER … … 71 74 int shfile_chdir(shfdtab *, const char *); 72 75 char *shfile_getcwd(shfdtab *, char *, int); 73 76 int shfile_isatty(shfdtab *, int); 77 74 78 #endif 75 79 -
trunk/src/kash/shinstance.c
r883 r1198 30 30 /** 31 31 * Creates a root shell instance. 32 * 32 * 33 33 * @param inherit The shell to inherit from. If NULL inherit from environment and such. 34 34 * @param argc The argument count. 35 35 * @param argv The argument vector. 36 * 36 * 37 37 * @returns pointer to root shell on success, NULL on failure. 38 38 */ … … 45 45 { 46 46 memset(psh, 0, sizeof(*psh)); 47 psh-> 47 48 /* memalloc.c */ 49 psh->stacknleft = MINSIZE; 50 psh->herefd = -1; 51 psh->stackp = &psh->stackbase; 52 psh->stacknxt = psh->stackbase.space; 53 48 54 } 49 55 return psh; -
trunk/src/kash/shinstance.h
r884 r1198 31 31 #include "shthread.h" 32 32 #include "shfile.h" 33 #include "output.h" 34 #include "options.h" 33 35 34 36 #include "var.h" 37 38 #define MINSIZE 504 /* minimum size of a block */ 39 struct stack_block { 40 struct stack_block *prev; 41 char space[MINSIZE]; 42 }; 35 43 36 44 … … 97 105 #ifdef _MSC_VER 98 106 struct var vpath2; 99 #endif 107 #endif 100 108 struct var vps1; 101 109 struct var vps2; … … 115 123 116 124 /* memalloc.h */ 117 char *stacknxt ;118 int stacknleft ;125 char *stacknxt/* = stackbase.space*/; 126 int stacknleft/* = MINSIZE*/; 119 127 int sstrnleft; 120 int herefd; 128 int herefd/* = -1 */; 129 130 /* memalloc.c */ 131 struct stack_block stackbase; 132 struct stack_block *stackp/* = &stackbase*/; 133 struct stackmark *markp; 134 121 135 122 136 /* jobs.h */ … … 151 165 /* cd.c */ 152 166 char *curdir; /**< current working directory */ 153 char *prevdir; 167 char *prevdir; /**< previous working directory */ 154 168 char *cdcomppath; 155 169 int getpwd_first; /**< static in getpwd. (initialized to 1!) */ … … 160 174 /* eval.c */ 161 175 int vforked; 176 177 /* mail.c */ 178 #define MAXMBOXES 10 179 int nmboxes; /**< number of mailboxes */ 180 time_t mailtime[MAXMBOXES]; /**< times of mailboxes */ 181 162 182 } shinstance; 163 183 … … 172 192 #else 173 193 typedef sigset_t sh_sigset_t; 174 #endif 194 #endif 175 195 176 196 typedef void (*sh_handler)(int); … … 179 199 void sh_sigemptyset(sh_sigset_t *set); 180 200 int sh_sigprocmask(shinstance *, int op, sh_sigset_t const *new, sh_sigset_t *old); 201 void sh_abort(shinstance *); 181 202 182 203 /* times */ … … 193 214 # include <times.h> 194 215 typedef struct tms sh_tms; 195 #endif 216 #endif 196 217 clock_t sh_times(sh_tms *); 197 218 int sh_sysconf_clk_tck(void); … … 219 240 #else 220 241 # include <sys/wait.h> 221 #endif 242 #endif 222 243 pid_t sh_waitpid(shinstance *, pid_t, int *, int); 223 244 void sh__exit(shinstance *, int); 224 245 225 #endif 246 247 #endif -
trunk/src/kash/show.c
r809 r1198 276 276 trputc(int c) 277 277 { 278 if (debug != 1)278 if (debug(psh) != 1) 279 279 return; 280 280 putc(c, tracefile); … … 283 283 284 284 void 285 trace( const char *fmt, ...)285 trace(shinstance *psh, const char *fmt, ...) 286 286 { 287 287 #ifdef DEBUG 288 288 va_list va; 289 289 290 if (debug != 1)290 if (debug(psh) != 1) 291 291 return; 292 292 fprintf(tracefile, "[%d] ", getpid()); … … 298 298 299 299 void 300 tracev( const char *fmt, va_list va)301 { 302 #ifdef DEBUG 303 if (debug != 1)300 tracev(shinstance *psh, const char *fmt, va_list va) 301 { 302 #ifdef DEBUG 303 if (debug(psh) != 1) 304 304 return; 305 305 fprintf(tracefile, "[%d] ", getpid()); … … 313 313 trputs(const char *s) 314 314 { 315 if (debug != 1)315 if (debug(psh) != 1) 316 316 return; 317 317 fputs(s, tracefile); … … 325 325 char c; 326 326 327 if (debug != 1)327 if (debug(psh) != 1) 328 328 return; 329 329 putc('"', tracefile); … … 361 361 362 362 void 363 trargs( char **ap)364 { 365 #ifdef DEBUG 366 if (debug != 1)363 trargs(shinstance *psh, char **ap) 364 { 365 #ifdef DEBUG 366 if (debug(psh) != 1) 367 367 return; 368 368 while (*ap) { … … 386 386 #endif 387 387 388 if (debug != 1) {388 if (debug(psh) != 1) { 389 389 if (tracefile) 390 390 fflush(tracefile); … … 410 410 if (!freopen(s, "a", tracefile)) { 411 411 fprintf(stderr, "Can't re-open %s\n", s); 412 debug = 0;412 debug(psh) = 0; 413 413 return; 414 414 } … … 416 416 if ((tracefile = fopen(s, "a")) == NULL) { 417 417 fprintf(stderr, "Can't open %s\n", s); 418 debug = 0;418 debug(psh) = 0; 419 419 return; 420 420 } -
trunk/src/kash/trap.c
r809 r1198 102 102 103 103 if (is_number(p)) 104 return number(p );104 return number(psh, p); 105 105 106 106 if (strcasecmp(p, "exit") == 0 ) … … 190 190 while (*ap) { 191 191 if (is_number(*ap)) 192 signo = number( *ap);192 signo = number(psh, *ap); 193 193 else 194 194 signo = signame_to_signum(*ap); … … 264 264 switch (signo) { 265 265 case SIGINT: 266 if (iflag || minusc || sflag== 0)266 if (iflag(psh) || minusc || sflag(psh) == 0) 267 267 action = S_CATCH; 268 268 break; 269 269 case SIGQUIT: 270 270 #ifdef DEBUG 271 if (debug )271 if (debug(psh)) 272 272 break; 273 273 #endif 274 274 /* FALLTHROUGH */ 275 275 case SIGTERM: 276 if (iflag )276 if (iflag(psh)) 277 277 action = S_IGN; 278 278 break; … … 280 280 case SIGTSTP: 281 281 case SIGTTOU: 282 if (mflag )282 if (mflag(psh)) 283 283 action = S_IGN; 284 284 break; … … 302 302 } 303 303 if (sigact == SIG_IGN) { 304 if (mflag && (signo == SIGTSTP ||304 if (mflag(psh) && (signo == SIGTSTP || 305 305 signo == SIGTTIN || signo == SIGTTOU)) { 306 306 tsig = S_IGN; /* don't hard ignore these */ -
trunk/src/kash/var.c
r888 r1198 228 228 if (i > 0) 229 229 { 230 psz[0] = psz[1] = psz[2] = psz[3] = '\0'; 230 psz[0] = psz[1] = psz[2] = psz[3] = '\0'; 231 231 rc = DosQueryExtLIBPATH(psz, i); 232 232 } … … 365 365 int nlen; 366 366 367 if (aflag )367 if (aflag(psh)) 368 368 flags |= VEXPORT; 369 369 vp = find_var(s, &vpp, &nlen); … … 501 501 nenv++; 502 502 } 503 ep = env = stalloc( (nenv + 1) * sizeof *env);503 ep = env = stalloc(psh, (nenv + 1) * sizeof *env); 504 504 for (vpp = vartab ; vpp < vartab + VTABSIZE ; vpp++) { 505 505 for (vp = *vpp ; vp ; vp = vp->next) … … 706 706 char *name; 707 707 708 if (! in_function( ))708 if (! in_function(psh)) 709 709 error("Not in a function"); 710 710 while ((name = *argptr++) != NULL) {
Note:
See TracChangeset
for help on using the changeset viewer.