Changeset 1199 in kBuild for trunk/src/kash
- Timestamp:
- Oct 6, 2007 10:04:05 PM (17 years ago)
- Location:
- trunk/src/kash
- Files:
-
- 26 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kash/Makefile.kmk
r1198 r1199 15 15 kmk_ash_TEMPLATE = BIN 16 16 kmk_ash_DEFS = lint SHELL SMALL 17 kmk_ash_DEFS.debug = DEBUG 17 18 kmk_ash_DEFS.linux = BSD 18 19 kmk_ash_DEFS.solaris = BSD … … 42 43 show.c \ 43 44 syntax.c \ 45 output.c \ 44 46 \ 45 output.c \46 47 exec.c \ 47 48 expand.c \ -
trunk/src/kash/bltin/bltin.h
r880 r1199 55 55 #define printf out1fmt 56 56 #define putc(c, file) outc(c, file) 57 #define putchar(c) out1c( c)57 #define putchar(c) out1c(psh, c) 58 58 #define FILE struct output 59 59 #define fprintf outfmt -
trunk/src/kash/cd.c
r1198 r1199 161 161 int badstat; 162 162 163 TRACE(( "docd(\"%s\", %d) called\n", dest, print));163 TRACE((psh, "docd(\"%s\", %d) called\n", dest, print)); 164 164 165 165 /* … … 410 410 INTOFF; 411 411 if (pipe(pip) < 0) 412 error( "Pipe call failed");412 error(psh, "Pipe call failed"); 413 413 jp = makejob((union node *)NULL, 1); 414 414 if (forkshell(jp, (union node *)NULL, FORK_NOJOB) == 0) { … … 420 420 } 421 421 (void) execl("/bin/pwd", "pwd", (char *)0); 422 error( "Cannot exec /bin/pwd");422 error(psh, "Cannot exec /bin/pwd"); 423 423 } 424 424 (void) close(pip[1]); … … 434 434 status = waitforjob(jp); 435 435 if (status != 0) 436 error( (char *)0);436 error(psh, (char *)0); 437 437 if (i < 0 || p == pwd || p[-1] != '\n') { 438 438 if (noerror) { … … 440 440 return; 441 441 } 442 error( "pwd command failed");442 error(psh, "pwd command failed"); 443 443 } 444 444 p[-1] = '\0'; -
trunk/src/kash/error.c
r1198 r1199 162 162 #ifdef DEBUG 163 163 if (msg) { 164 TRACE(( "exverror(%d, \"", cond));165 TRACEV(( msg, ap));166 TRACE(( "\") pid=%d\n", getpid()));164 TRACE((psh, "exverror(%d, \"", cond)); 165 TRACEV((psh, msg, ap)); 166 TRACE((psh, "\") pid=%d\n", getpid())); 167 167 } else 168 TRACE(( "exverror(%d, NULL) pid=%d\n", cond, getpid()));168 TRACE((psh, "exverror(%d, NULL) pid=%d\n", cond, getpid())); 169 169 #endif 170 170 if (msg) -
trunk/src/kash/eval.c
r1198 r1199 226 226 { 227 227 if (n == NULL) { 228 TRACE(( "evaltree(NULL) called\n"));228 TRACE((psh, "evaltree(NULL) called\n")); 229 229 psh->exitstatus = 0; 230 230 goto out; … … 233 233 psh->displayhist = 1; /* show history substitutions done with fc */ 234 234 #endif 235 TRACE(( "pid %d, evaltree(%p: %d, %d) called\n",236 getpid(), n, n->type, flags));235 TRACE((psh, "pid %d, evaltree(%p: %d, %d) called\n", 236 getpid(), n, n->type, flags)); 237 237 switch (n->type) { 238 238 case NSEMI: … … 500 500 int pip[2]; 501 501 502 TRACE(( "evalpipe(0x%lx) called\n", (long)n));502 TRACE((psh, "evalpipe(0x%lx) called\n", (long)n)); 503 503 pipelen = 0; 504 504 for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) … … 540 540 if (n->npipe.backgnd == 0) { 541 541 psh->exitstatus = waitforjob(psh, jp); 542 TRACE(( "evalpipe: job done exit status %d\n", psh->exitstatus));542 TRACE((psh, "evalpipe: job done exit status %d\n", psh->exitstatus)); 543 543 } 544 544 INTON; … … 605 605 out: 606 606 popstackmark(psh, &smark); 607 TRACE(( "evalbackcmd done: fd=%d buf=0x%x nleft=%d jp=0x%x\n",607 TRACE((psh, "evalbackcmd done: fd=%d buf=0x%x nleft=%d jp=0x%x\n", 608 608 result->fd, result->buf, result->nleft, result->jp)); 609 609 } … … 716 716 psh->vforked = 0; 717 717 /* First expand the arguments. */ 718 TRACE(( "evalcommand(0x%lx, %d) called\n", (long)cmd, flags));718 TRACE((psh, "evalcommand(0x%lx, %d) called\n", (long)cmd, flags)); 719 719 setstackmark(psh, &smark); 720 720 psh->exitstatus = 0; … … 760 760 761 761 for (sp = arglist.list ; sp ; sp = sp->next) { 762 TRACE(( "evalcommand arg: %s\n", sp->text));762 TRACE((psh, "evalcommand arg: %s\n", sp->text)); 763 763 *argv++ = sp->text; 764 764 } … … 864 864 switch (pid = vfork()) { 865 865 case -1: 866 TRACE(( "Vfork failed, errno=%d\n", errno));866 TRACE((psh, "Vfork failed, errno=%d\n", errno)); 867 867 INTON; 868 868 error(psh, "Cannot vfork"); … … 932 932 case CMDFUNCTION: 933 933 #ifdef DEBUG 934 trputs( "Shell function: "); trargs(argv);934 trputs(psh, "Shell function: "); trargs(psh, argv); 935 935 #endif 936 936 redirect(psh, cmd->ncmd.redirect, REDIR_PUSH); … … 985 985 case CMDSPLBLTIN: 986 986 #ifdef DEBUG 987 trputs( "builtin command: "); trargs(argv);987 trputs(psh, "builtin command: "); trargs(psh, argv); 988 988 #endif 989 989 mode = (cmdentry.u.bltin == execcmd) ? 0 : REDIR_PUSH; … … 1069 1069 default: 1070 1070 #ifdef DEBUG 1071 trputs( "normal command: "); trargs(argv);1071 trputs(psh, "normal command: "); trargs(psh, argv); 1072 1072 #endif 1073 1073 clearredir(psh, psh->vforked); -
trunk/src/kash/exec.c
r1198 r1199 144 144 const int has_ext = 1; 145 145 #endif 146 TRACE(( "shellexec: argv[0]=%s idx=%d\n", argv[0], idx));146 TRACE((psh, "shellexec: argv[0]=%s idx=%d\n", argv[0], idx)); 147 147 if (strchr(argv[0], '/') != NULL) { 148 148 cmdname = stalloc(psh, strlen(argv[0]) + 5); 149 149 strcpy(cmdname, argv[0]); 150 150 tryexec(cmdname, argv, envp, vforked, has_ext); 151 TRACE(( "shellexec: cmdname=%s\n", cmdname));151 TRACE((psh, "shellexec: cmdname=%s\n", cmdname)); 152 152 stunalloc(psh, cmdname); 153 153 e = errno; … … 176 176 break; 177 177 } 178 TRACE(( "shellexec failed for '%s', errno %d, vforked %d, suppressint %d\n",178 TRACE((psh, "shellexec failed for '%s', errno %d, vforked %d, suppressint %d\n", 179 179 argv[0], e, vforked, suppressint )); 180 exerror( EXEXEC, "%s: %s", argv[0], errmsg(e, E_EXEC));180 exerror(psh, EXEXEC, "%s: %s", argv[0], errmsg(psh, e, E_EXEC)); 181 181 /* NOTREACHED */ 182 182 } … … 216 216 * with a normal fork(2). 217 217 */ 218 exraise( EXSHELLPROC);218 exraise(psh, EXSHELLPROC); 219 219 } 220 220 initshellproc(); … … 230 230 #endif 231 231 setparam(argv + 1); 232 exraise( EXSHELLPROC);232 exraise(psh, EXSHELLPROC); 233 233 } 234 234 errno = e; … … 274 274 break; 275 275 if (ap == &newargs[NEWARGS]) 276 bad: error( "Bad #! line");276 bad: error(psh, "Bad #! line"); 277 277 STARTSTACKSTR(psh, outp); 278 278 do { … … 287 287 for (;;) { 288 288 if (equal(p, "sh") || equal(p, "ash")) { 289 TRACE(( "hash bang self\n"));289 TRACE((psh, "hash bang self\n")); 290 290 return; 291 291 } … … 301 301 i = (char *)ap - (char *)newargs; /* size in bytes */ 302 302 if (i == 0) 303 error( "Bad #! line");303 error(psh, "Bad #! line"); 304 304 for (ap2 = argv ; *ap2++ != NULL ; ); 305 305 new = ckmalloc(i + ((char *)ap2 - (char *)argv)); … … 309 309 ap = argv; 310 310 while (*ap2++ = *ap++); 311 TRACE(( "hash bang '%s'\n", new[0]));311 TRACE((psh, "hash bang '%s'\n", new[0])); 312 312 shellexec(new, envp, pathval(), 0, 0); 313 313 /* NOTREACHED */ … … 464 464 printentry(cmdp, verbose); 465 465 } 466 output_flushall( );466 output_flushall(psh); 467 467 } 468 468 argptr++; … … 487 487 stunalloc(psh, name); 488 488 } while (--idx >= 0); 489 out1str( name);489 out1str(psh, name); 490 490 break; 491 491 case CMDSPLBLTIN: 492 out1fmt( "special builtin %s", cmdp->cmdname);492 out1fmt(psh, "special builtin %s", cmdp->cmdname); 493 493 break; 494 494 case CMDBUILTIN: 495 out1fmt( "builtin %s", cmdp->cmdname);495 out1fmt(psh, "builtin %s", cmdp->cmdname); 496 496 break; 497 497 case CMDFUNCTION: 498 out1fmt( "function %s", cmdp->cmdname);498 out1fmt(psh, "function %s", cmdp->cmdname); 499 499 if (verbose) { 500 500 struct procstat ps; … … 502 502 commandtext(&ps, cmdp->param.func); 503 503 INTON; 504 out1str( "() { ");505 out1str(ps .cmd);506 out1str( "; }");504 out1str(psh, "() { "); 505 out1str(psh, ps.cmd); 506 out1str(psh, "; }"); 507 507 } 508 508 break; 509 509 default: 510 error( "internal error: %s cmdtype %d", cmdp->cmdname, cmdp->cmdtype);510 error(psh, "internal error: %s cmdtype %d", cmdp->cmdname, cmdp->cmdtype); 511 511 } 512 512 if (cmdp->rehash) 513 out1c( '*');514 out1c( '\n');513 out1c(psh, '*'); 514 out1c(psh, '\n'); 515 515 } 516 516 … … 641 641 if (idx < prev) 642 642 goto loop; 643 TRACE(( "searchexec \"%s\": no change\n", name));643 TRACE((psh, "searchexec \"%s\": no change\n", name)); 644 644 goto success; 645 645 } … … 668 668 if ((cmdp = cmdlookup(name, 0)) == NULL || 669 669 cmdp->cmdtype != CMDFUNCTION) 670 error( "%s not defined in %s", name, fullname);670 error(psh, "%s not defined in %s", name, fullname); 671 671 stunalloc(psh, fullname); 672 672 goto success; … … 686 686 } 687 687 #endif 688 TRACE(( "searchexec \"%s\" returns \"%s\"\n", name, fullname));688 TRACE((psh, "searchexec \"%s\" returns \"%s\"\n", name, fullname)); 689 689 INTOFF; 690 690 if (act & DO_ALTPATH) { … … 703 703 delete_cmd_entry(); 704 704 if (act & DO_ERR) 705 outfmt(out2, "%s: %s\n", name, errmsg( e, E_EXEC));705 outfmt(out2, "%s: %s\n", name, errmsg(psh, e, E_EXEC)); 706 706 entry->cmdtype = CMDUNKNOWN; 707 707 return; … … 1094 1094 1095 1095 if (p_flag && (v_flag || V_flag)) 1096 error( "cannot specify -p with -v or -V");1096 error(psh, "cannot specify -p with -v or -V"); 1097 1097 1098 1098 while ((arg = *argptr++)) { 1099 1099 if (!v_flag) 1100 out1str( arg);1100 out1str(psh, arg); 1101 1101 /* First look at the keywords */ 1102 1102 for (pp = parsekwd; *pp; pp++) … … 1108 1108 err = 1; 1109 1109 else 1110 out1str( " is a shell keyword\n");1110 out1str(psh, " is a shell keyword\n"); 1111 1111 continue; 1112 1112 } 1113 1113 1114 1114 /* Then look at the aliases */ 1115 if ((ap = lookupalias( arg, 1)) != NULL) {1115 if ((ap = lookupalias(psh, arg, 1)) != NULL) { 1116 1116 if (!v_flag) 1117 out1fmt( " is an alias for \n");1118 out1fmt( "%s\n", ap->val);1117 out1fmt(psh, " is an alias for \n"); 1118 out1fmt(psh, "%s\n", ap->val); 1119 1119 continue; 1120 1120 } … … 1140 1140 } while (--j >= 0); 1141 1141 if (!v_flag) 1142 out1fmt( " is%s ",1142 out1fmt(psh, " is%s ", 1143 1143 cmdp ? " a tracked alias for" : ""); 1144 out1fmt( "%s\n", name);1144 out1fmt(psh, "%s\n", name); 1145 1145 } else { 1146 1146 if (access(arg, X_OK) == 0) { 1147 1147 if (!v_flag) 1148 out1fmt( " is ");1149 out1fmt( "%s\n", arg);1148 out1fmt(psh, " is "); 1149 out1fmt(psh, "%s\n", arg); 1150 1150 } else { 1151 1151 if (!v_flag) 1152 out1fmt( ": %s\n",1152 out1fmt(psh, ": %s\n", 1153 1153 strerror(errno)); 1154 1154 else … … 1160 1160 case CMDFUNCTION: 1161 1161 if (!v_flag) 1162 out1str( " is a shell function\n");1162 out1str(psh, " is a shell function\n"); 1163 1163 else 1164 out1fmt( "%s\n", arg);1164 out1fmt(psh, "%s\n", arg); 1165 1165 break; 1166 1166 1167 1167 case CMDBUILTIN: 1168 1168 if (!v_flag) 1169 out1str( " is a shell builtin\n");1169 out1str(psh, " is a shell builtin\n"); 1170 1170 else 1171 out1fmt( "%s\n", arg);1171 out1fmt(psh, "%s\n", arg); 1172 1172 break; 1173 1173 1174 1174 case CMDSPLBLTIN: 1175 1175 if (!v_flag) 1176 out1str( " is a special shell builtin\n");1176 out1str(psh, " is a special shell builtin\n"); 1177 1177 else 1178 out1fmt( "%s\n", arg);1178 out1fmt(psh, "%s\n", arg); 1179 1179 break; 1180 1180 1181 1181 default: 1182 1182 if (!v_flag) 1183 out1str( ": not found\n");1183 out1str(psh, ": not found\n"); 1184 1184 err = 127; 1185 1185 break; -
trunk/src/kash/expand.c
r1198 r1199 385 385 --p; 386 386 if (*p != CTLARI) 387 error( "missing CTLARI (shouldn't happen)");387 error(psh, "missing CTLARI (shouldn't happen)"); 388 388 if (p > start && *(p-1) == CTLESC) 389 389 for (p = start; *p != CTLARI; p++) … … 453 453 break; 454 454 while ((i = read(in.fd, buf, sizeof buf)) < 0 && errno == EINTR); 455 TRACE(( "expbackq: read returns %d\n", i));455 TRACE((psh, "expbackq: read returns %d\n", i)); 456 456 if (i <= 0) 457 457 break; … … 480 480 if (quoted == 0) 481 481 recordregion(startloc, dest - stackblock(psh), 0); 482 TRACE(( "evalbackq: size=%d: \"%.*s\"\n",482 TRACE((psh, "evalbackq: size=%d: \"%.*s\"\n", 483 483 (dest - stackblock(psh)) - startloc, 484 484 (dest - stackblock(psh)) - startloc, … … 523 523 if (*p != CTLENDVAR) { 524 524 outfmt(&errout, "%s\n", startp); 525 error( (char *)NULL);526 } 527 error( "%.*s: parameter %snot set", p - str - 1,525 error(psh, (char *)NULL); 526 } 527 error(psh, "%.*s: parameter %snot set", p - str - 1, 528 528 str, (varflags & VSNUL) ? "null or " 529 529 : nullstr); … … 658 658 case VSTRIMRIGHTMAX: 659 659 case VSLENGTH: 660 error( "%.*s: parameter not set", p - var - 1, var);660 error(psh, "%.*s: parameter not set", p - var - 1, var); 661 661 /* NOTREACHED */ 662 662 } … … 1556 1556 int i; 1557 1557 1558 out1fmt( "%d", argc - 1);1559 out1c( '\0');1558 out1fmt(psh, "%d", argc - 1); 1559 out1c(psh, '\0'); 1560 1560 for (i = 1, len = 0; i < argc; i++) 1561 1561 len += strlen(argv[i]); 1562 out1fmt( "%zd", len);1563 out1c( '\0');1562 out1fmt(psh, "%zd", len); 1563 out1c(psh, '\0'); 1564 1564 for (i = 1; i < argc; i++) { 1565 out1str( argv[i]);1566 out1c( '\0');1565 out1str(psh, argv[i]); 1566 out1c(psh, '\0'); 1567 1567 } 1568 1568 return (0); -
trunk/src/kash/generated/arith.c
r1198 r1199 346 346 i = arith(p); 347 347 348 out1fmt( "%ld\n", i);348 out1fmt(psh, "%ld\n", i); 349 349 return (! i); 350 350 } -
trunk/src/kash/generated/init.c
r1198 r1199 118 118 119 119 120 extern void rmaliases( void);120 extern void rmaliases(struct shinstance *); 121 121 122 122 extern int loopnest; /* current loop nesting level */ … … 256 256 /* from alias.c: */ 257 257 { 258 rmaliases( );258 rmaliases(psh); 259 259 } 260 260 -
trunk/src/kash/histedit.c
r1198 r1199 105 105 sethistsize(histsizeval()); 106 106 else 107 out2str( "sh: can't initialize history\n");107 out2str(psh, "sh: can't initialize history\n"); 108 108 } 109 109 if (editing && !el && isatty(0)) { /* && isatty(2) ??? */ … … 144 144 } else { 145 145 bad: 146 out2str( "sh: can't initialize editing\n");146 out2str(psh, "sh: can't initialize editing\n"); 147 147 } 148 148 INTON; … … 207 207 { 208 208 if (argc != 2) { 209 out2str( "usage: inputrc file\n");209 out2str(psh, "usage: inputrc file\n"); 210 210 return 1; 211 211 } 212 212 if (el != NULL) { 213 213 if (el_source(el, argv[1])) { 214 out2str( "inputrc: failed\n");214 out2str(psh, "inputrc: failed\n"); 215 215 return 1; 216 216 } else 217 217 return 0; 218 218 } else { 219 out2str( "sh: inputrc ignored, not editing\n");219 out2str(psh, "sh: inputrc ignored, not editing\n"); 220 220 return 1; 221 221 } … … 259 259 260 260 if (hist == NULL) 261 error( "history not active");261 error(psh, "history not active"); 262 262 263 263 if (argc == 1) 264 error( "missing history argument");264 error(psh, "missing history argument"); 265 265 266 266 optreset = 1; optind = 1; /* initialize getopt */ … … 284 284 break; 285 285 case ':': 286 error( "option -%c expects argument", optopt);286 error(psh, "option -%c expects argument", optopt); 287 287 /* NOTREACHED */ 288 288 case '?': 289 289 default: 290 error( "unknown option: -%c", optopt);290 error(psh, "unknown option: -%c", optopt); 291 291 /* NOTREACHED */ 292 292 } … … 315 315 active = 0; 316 316 displayhist = 0; 317 error( "called recursively too many times");317 error(psh, "called recursively too many times"); 318 318 } 319 319 /* … … 358 358 break; 359 359 default: 360 error( "too many args");360 error(psh, "too many args"); 361 361 /* NOTREACHED */ 362 362 } … … 387 387 snprintf(editfile, sizeof(editfile), "%s_shXXXXXX", _PATH_TMP); 388 388 if ((fd = mkstemp(editfile)) < 0) 389 error( "can't create temporary file %s", editfile);389 error(psh, "can't create temporary file %s", editfile); 390 390 if ((efp = fdopen(fd, "w")) == NULL) { 391 391 close(fd); 392 error( "can't allocate stdio buffer for temp");392 error(psh, "can't allocate stdio buffer for temp"); 393 393 } 394 394 } … … 407 407 if (lflg) { 408 408 if (!nflg) 409 out1fmt( "%5d ", he.num);410 out1str( he.str);409 out1fmt(psh, "%5d ", he.num); 410 out1str(psh, he.str); 411 411 } else { 412 412 const char *s = pat ? … … 415 415 if (sflg) { 416 416 if (displayhist) { 417 out2str( s);417 out2str(psh, s); 418 418 } 419 419 … … 523 523 } 524 524 if (retval == -1) 525 error( "history number %s not found (internal error)",525 error(psh, "history number %s not found (internal error)", 526 526 str); 527 527 } else { … … 531 531 retval = history(hist, &he, H_PREV_STR, str); 532 532 if (retval == -1) 533 error( "history pattern not found: %s", str);533 error(psh, "history pattern not found: %s", str); 534 534 } 535 535 return (he.num); -
trunk/src/kash/input.c
r1198 r1199 221 221 flags &=~ O_NONBLOCK; 222 222 if (fcntl(0, F_SETFL, flags) >= 0) { 223 out2str( "sh: turning off NDELAY mode\n");223 out2str(psh, "sh: turning off NDELAY mode\n"); 224 224 goto retry; 225 225 } … … 317 317 318 318 if (vflag(psh)) { 319 out2str(p arsenextc);319 out2str(psh, parsenextc); 320 320 flushout(out2); 321 321 } … … 397 397 INTOFF; 398 398 if ((fd = open(fname, O_RDONLY)) < 0) 399 error( "Can't open %s", fname);399 error(psh, "Can't open %s", fname); 400 400 if (fd < 10) { 401 401 fd2 = copyfd(fd, 10); 402 402 close(fd); 403 403 if (fd2 < 0) 404 error( "Out of file descriptors");404 error(psh, "Out of file descriptors"); 405 405 fd = fd2; 406 406 } -
trunk/src/kash/jobs.c
r1198 r1199 186 186 } 187 187 #else 188 out2str( "sh: Need FIOCLEX or FD_CLOEXEC to support job control");188 out2str(psh, "sh: Need FIOCLEX or FD_CLOEXEC to support job control"); 189 189 goto out; 190 190 #endif … … 192 192 if ((initialpgrp = tcgetpgrp(ttyfd)) < 0) { 193 193 out: 194 out2str( "sh: can't access tty; job control turned off\n");194 out2str(psh, "sh: can't access tty; job control turned off\n"); 195 195 mflag(psh) = 0; 196 196 return; … … 207 207 if (ioctl(ttyfd, TIOCGETD, (char *)&ldisc) < 0 208 208 || ldisc != NTTYDISC) { 209 out2str( "sh: need new tty driver to run job control; job control turned off\n");209 out2str(psh, "sh: need new tty driver to run job control; job control turned off\n"); 210 210 mflag(psh) = 0; 211 211 return; … … 216 216 setsignal(SIGTTIN, 0); 217 217 if (getpgid(0) != rootpid && setpgid(0, rootpid) == -1) 218 error( "Cannot set process group (%s) at %d",218 error(psh, "Cannot set process group (%s) at %d", 219 219 strerror(errno), __LINE__); 220 220 if (tcsetpgrp(ttyfd, rootpid) == -1) 221 error( "Cannot set tty process group (%s) at %d",221 error(psh, "Cannot set tty process group (%s) at %d", 222 222 strerror(errno), __LINE__); 223 223 } else { /* turning job control off */ 224 224 if (getpgid(0) != initialpgrp && setpgid(0, initialpgrp) == -1) 225 error( "Cannot set process group (%s) at %d",225 error(psh, "Cannot set process group (%s) at %d", 226 226 strerror(errno), __LINE__); 227 227 if (tcsetpgrp(ttyfd, initialpgrp) == -1) 228 error( "Cannot set tty process group (%s) at %d",228 error(psh, "Cannot set tty process group (%s) at %d", 229 229 strerror(errno), __LINE__); 230 230 close(ttyfd); … … 263 263 jp = getjob(*argptr, 0); 264 264 if (jp->jobctl == 0) 265 error( "job not created under job control");266 out1fmt( "%s", jp->ps[0].cmd);265 error(psh, "job not created under job control"); 266 out1fmt(psh, "%s", jp->ps[0].cmd); 267 267 for (i = 1; i < jp->nprocs; i++) 268 out1fmt( " | %s", jp->ps[i].cmd );269 out1c( '\n');270 output_flushall( );268 out1fmt(psh, " | %s", jp->ps[i].cmd ); 269 out1c(psh, '\n'); 270 output_flushall(psh); 271 271 272 272 for (i = 0; i < jp->nprocs; i++) … … 275 275 276 276 if (i >= jp->nprocs) { 277 error( "Cannot set tty process group (%s) at %d",277 error(psh, "Cannot set tty process group (%s) at %d", 278 278 strerror(errno), __LINE__); 279 279 } … … 340 340 nextopt(""); 341 341 do { 342 jp = getjob( *argptr, 0);342 jp = getjob(psh, *psh->argptr, 0); 343 343 if (jp->jobctl == 0) 344 error( "job not created under job control");344 error(psh, "job not created under job control"); 345 345 set_curjob(jp, 1); 346 out1fmt( "[%ld] %s", (long)(jp - jobtab + 1), jp->ps[0].cmd);346 out1fmt(psh, "[%ld] %s", (long)(jp - jobtab + 1), jp->ps[0].cmd); 347 347 for (i = 1; i < jp->nprocs; i++) 348 out1fmt( " | %s", jp->ps[i].cmd );349 out1c( '\n');350 output_flushall( );348 out1fmt(psh, " | %s", jp->ps[i].cmd ); 349 out1c(psh, '\n'); 350 output_flushall(psh); 351 351 restartjob(jp); 352 } while (* argptr && *++argptr);352 } while (*psh->argptr && *++psh->argptr); 353 353 return 0; 354 354 } … … 368 368 break; 369 369 if (i >= jp->nprocs) 370 error( "Cannot continue job (%s)", strerror(errno));370 error(psh, "Cannot continue job (%s)", strerror(errno)); 371 371 for (ps = jp->ps, i = jp->nprocs ; --i >= 0 ; ps++) { 372 372 if (WIFSTOPPED(ps->status)) { … … 425 425 if (mode & SHOW_SIGNALLED && !(mode & SHOW_ISSIG)) { 426 426 if (jp->state == JOBDONE && !(mode & SHOW_NO_FREE)) { 427 TRACE(( "showjob: freeing job %d\n", jp - jobtab + 1));427 TRACE((psh, "showjob: freeing job %d\n", jp - jobtab + 1)); 428 428 freejob(jp); 429 429 } … … 538 538 int silent = 0, gotpid; 539 539 540 TRACE(( "showjobs(%x) called\n", mode));540 TRACE((psh, "showjobs(%x) called\n", mode)); 541 541 542 542 /* If not even one one job changed, there is nothing to do */ … … 551 551 if (mflag(psh) && gotpid != -1 && tcgetpgrp(ttyfd) != getpid()) { 552 552 if (tcsetpgrp(ttyfd, getpid()) == -1) 553 error( "Cannot set tty process group (%s) at %d",553 error(psh, "Cannot set tty process group (%s) at %d", 554 554 strerror(errno), __LINE__); 555 TRACE(( "repaired tty process group\n"));555 TRACE((psh, "repaired tty process group\n")); 556 556 silent = 1; 557 557 } … … 668 668 jp = getjob(*argptr, 0); 669 669 for (i = 0 ; i < jp->nprocs ; ) { 670 out1fmt( "%ld", (long)jp->ps[i].pid);671 out1c( ++i < jp->nprocs ? ' ' : '\n');670 out1fmt(psh, "%ld", (long)jp->ps[i].pid); 671 out1c(psh, ++i < jp->nprocs ? ' ' : '\n'); 672 672 } 673 673 return 0; … … 762 762 } 763 763 if (!noerror) 764 error( err_msg, name);764 error(psh, err_msg, name); 765 765 return 0; 766 766 } … … 824 824 } 825 825 INTON; 826 TRACE(( "makejob(0x%lx, %d) returns %%%d\n", (long)node, nprocs,827 jp - jobtab + 1));826 TRACE((psh, "makejob(0x%lx, %d) returns %%%d\n", (long)node, nprocs, 827 jp - jobtab + 1)); 828 828 return jp; 829 829 } … … 850 850 int pid; 851 851 852 TRACE(( "forkshell(%%%d, %p, %d) called\n", jp - jobtab, n, mode));852 TRACE((psh, "forkshell(%%%d, %p, %d) called\n", jp - jobtab, n, mode)); 853 853 switch ((pid = fork())) { 854 854 case -1: 855 TRACE(( "Fork failed, errno=%d\n", errno));855 TRACE((psh, "Fork failed, errno=%d\n", errno)); 856 856 INTON; 857 error( "Cannot fork");857 error(psh, "Cannot fork"); 858 858 break; 859 859 case 0: … … 888 888 commandtext(ps, n); 889 889 } 890 TRACE(( "In parent shell: child = %d\n", pid));890 TRACE((psh, "In parent shell: child = %d\n", pid)); 891 891 return pid; 892 892 } … … 901 901 902 902 wasroot = rootshell; 903 TRACE(( "Child shell %d\n", getpid()));903 TRACE((psh, "Child shell %d\n", getpid())); 904 904 if (!vforked) 905 905 rootshell = 0; … … 919 919 if (mode == FORK_FG) { 920 920 if (tcsetpgrp(ttyfd, pgrp) == -1) 921 error( "Cannot set tty process group (%s) at %d",921 error(psh, "Cannot set tty process group (%s) at %d", 922 922 strerror(errno), __LINE__); 923 923 } … … 931 931 close(0); 932 932 if (open(devnull, O_RDONLY) != 0) 933 error( nullerr, devnull);933 error(psh, nullerr, devnull); 934 934 } 935 935 } … … 942 942 close(0); 943 943 if (open(devnull, O_RDONLY) != 0) 944 error( nullerr, devnull);944 error(psh, nullerr, devnull); 945 945 } 946 946 } … … 985 985 986 986 INTOFF; 987 TRACE(( "waitforjob(%%%d) called\n", jp - jobtab + 1));987 TRACE((psh, "waitforjob(%%%d) called\n", jp - jobtab + 1)); 988 988 while (jp->state == JOBRUNNING) { 989 989 dowait(1, jp); … … 992 992 if (jp->jobctl) { 993 993 if (tcsetpgrp(ttyfd, mypgrp) == -1) 994 error( "Cannot set tty process group (%s) at %d",994 error(psh, "Cannot set tty process group (%s) at %d", 995 995 strerror(errno), __LINE__); 996 996 } … … 1008 1008 else 1009 1009 st = WTERMSIG(status) + 128; 1010 TRACE(( "waitforjob: job %d, nproc %d, status %x, st %x\n",1010 TRACE((psh, "waitforjob: job %d, nproc %d, status %x, st %x\n", 1011 1011 jp - jobtab + 1, jp->nprocs, status, st )); 1012 1012 #if JOBS … … 1048 1048 extern volatile char gotsig[]; 1049 1049 1050 TRACE(( "dowait(%d) called\n", block));1050 TRACE((psh, "dowait(%d) called\n", block)); 1051 1051 do { 1052 1052 pid = waitproc(block, job, &status); 1053 TRACE(( "wait returns pid %d, status %d\n", pid, status));1053 TRACE((psh, "wait returns pid %d, status %d\n", pid, status)); 1054 1054 } while (pid == -1 && errno == EINTR && gotsig[SIGINT - 1] == 0); 1055 1055 if (pid <= 0) … … 1065 1065 continue; 1066 1066 if (sp->pid == pid) { 1067 TRACE(( "Job %d: changing status of proc %d from 0x%x to 0x%x\n", jp - jobtab + 1, pid, sp->status, status));1067 TRACE((psh, "Job %d: changing status of proc %d from 0x%x to 0x%x\n", jp - jobtab + 1, pid, sp->status, status)); 1068 1068 sp->status = status; 1069 1069 thisjob = jp; … … 1077 1077 int state = done ? JOBDONE : JOBSTOPPED; 1078 1078 if (jp->state != state) { 1079 TRACE(( "Job %d: changing state from %d to %d\n", jp - jobtab + 1, jp->state, state));1079 TRACE((psh, "Job %d: changing state from %d to %d\n", jp - jobtab + 1, jp->state, state)); 1080 1080 jp->state = state; 1081 1081 #if JOBS … … 1097 1097 showjob(out2, thisjob, mode); 1098 1098 else { 1099 TRACE(( "Not printing status, rootshell=%d, job=%p\n",1099 TRACE((psh, "Not printing status, rootshell=%d, job=%p\n", 1100 1100 rootshell, job)); 1101 1101 thisjob->changed = 1; … … 1196 1196 continue; 1197 1197 if (jp->state == JOBSTOPPED) { 1198 out2str( "You have stopped jobs.\n");1198 out2str(psh, "You have stopped jobs.\n"); 1199 1199 job_warning = 2; 1200 1200 return (1); … … 1233 1233 } else 1234 1234 *cmdnextc = '\0'; 1235 TRACE(( "commandtext: ps->cmd %x, end %x, left %d\n\t\"%s\"\n",1235 TRACE((psh, "commandtext: ps->cmd %x, end %x, left %d\n\t\"%s\"\n", 1236 1236 ps->cmd, cmdnextc, cmdnleft, ps->cmd)); 1237 1237 } -
trunk/src/kash/main.c
r1198 r1199 207 207 #endif 208 208 opentrace(psh); 209 trputs( "Shell args: "); trargs(argv);209 trputs(psh, "Shell args: "); trargs(psh, argv); 210 210 #endif 211 211 … … 271 271 int numeof = 0; 272 272 273 TRACE(( "cmdloop(%d) called\n", top));273 TRACE((psh, "cmdloop(%d) called\n", top)); 274 274 setstackmark(psh, &smark); 275 275 for (;;) { -
trunk/src/kash/miscbltin.c
r1198 r1199 113 113 114 114 if (prompt && isatty(0)) { 115 out2str(p rompt);116 output_flushall( );115 out2str(psh, prompt); 116 output_flushall(psh); 117 117 } 118 118 119 119 if (*(ap = argptr) == NULL) 120 error( "arg count");120 error(psh, "arg count"); 121 121 122 122 if ((ifs = bltinlookup("IFS", 1)) == NULL) … … 261 261 o[i] = '\0'; 262 262 263 out1fmt( "u=%s,g=%s,o=%s\n", u, g, o);263 out1fmt(psh, "u=%s,g=%s,o=%s\n", u, g, o); 264 264 } else { 265 out1fmt( "%.4o\n", mask);265 out1fmt(psh, "%.4o\n", mask); 266 266 } 267 267 } else { … … 270 270 do { 271 271 if (*ap >= '8' || *ap < '0') 272 error( "Illegal number: %s", argv[1]);272 error(psh, "Illegal number: %s", argv[1]); 273 273 mask = (mask << 3) + (*ap - '0'); 274 274 } while (*++ap != '\0'); … … 288 288 INTON; 289 289 if (!set) 290 error( "Illegal mode: %s", ap);290 error(psh, "Illegal mode: %s", ap); 291 291 292 292 umask(~mask & 0777); … … 384 384 ; 385 385 if (!l->name) 386 error( "internal error (%c)", what);386 error(psh, "internal error (%c)", what); 387 387 388 388 set = *argptr ? 1 : 0; … … 391 391 392 392 if (all || argptr[1]) 393 error( "too many arguments");393 error(psh, "too many arguments"); 394 394 if (strcmp(p, "unlimited") == 0) 395 395 val = RLIM_INFINITY; … … 404 404 } 405 405 if (c) 406 error( "bad number");406 error(psh, "bad number"); 407 407 val *= l->factor; 408 408 } … … 416 416 val = limit.rlim_max; 417 417 418 out1fmt( "%-20s ", l->name);418 out1fmt(psh, "%-20s ", l->name); 419 419 if (val == RLIM_INFINITY) 420 420 out1fmt("unlimited\n"); … … 423 423 val /= l->factor; 424 424 #ifdef BSD4_4 425 out1fmt( "%lld\n", (long long) val);425 out1fmt(psh, "%lld\n", (long long) val); 426 426 #else 427 out1fmt( "%ld\n", (long) val);427 out1fmt(psh, "%ld\n", (long) val); 428 428 #endif 429 429 } … … 439 439 limit.rlim_cur = val; 440 440 if (setrlimit(l->cmd, &limit) < 0) 441 error( "error setting limit (%s)", strerror(errno));441 error(psh, "error setting limit (%s)", strerror(errno)); 442 442 } else { 443 443 if (how & SOFT) … … 447 447 448 448 if (val == RLIM_INFINITY) 449 out1fmt( "unlimited\n");449 out1fmt(psh, "unlimited\n"); 450 450 else 451 451 { 452 452 val /= l->factor; 453 453 #ifdef BSD4_4 454 out1fmt( "%lld\n", (long long) val);454 out1fmt(psh, "%lld\n", (long long) val); 455 455 #else 456 out1fmt( "%ld\n", (long) val);456 out1fmt(psh, "%ld\n", (long) val); 457 457 #endif 458 458 } -
trunk/src/kash/options.c
r1198 r1199 213 213 #ifdef DEBUG 214 214 if (&psh->optlist[i].val == &debug(psh)) 215 opentrace( );215 opentrace(psh); 216 216 #endif 217 217 } -
trunk/src/kash/output.c
r1198 r1199 71 71 #include "error.h" 72 72 73 74 #define OUTBUFSIZ BUFSIZ 73 #include "shinstance.h" 74 75 //#define OUTBUFSIZ BUFSIZ 75 76 #define BLOCK_OUT -2 /* output to a fixed block of memory */ 76 #define MEM_OUT -3 /* output to dynamically allocated memory */77 //#define MEM_OUT -3 /* output to dynamically allocated memory */ 77 78 #define OUTPUT_ERR 01 /* error occurred on output */ 78 79 79 80 80 struct output output = {NULL, 0, NULL, OUTBUFSIZ, 1, 0};81 struct output errout = {NULL, 0, NULL, 100, 2, 0};82 struct output memout = {NULL, 0, NULL, 0, MEM_OUT, 0};83 struct output *out1 = &output;84 struct output *out2 = &errout;81 //struct output output = {NULL, 0, NULL, OUTBUFSIZ, 1, 0}; 82 //struct output errout = {NULL, 0, NULL, 100, 2, 0}; 83 //struct output memout = {NULL, 0, NULL, 0, MEM_OUT, 0}; 84 //struct output *out1 = &output; 85 //struct output *out2 = &errout; 85 86 86 87 … … 92 93 93 94 RESET { 94 out1 = &output;95 out2 = &errout;96 if ( memout.buf != NULL) {97 ckfree( memout.buf);98 memout.buf = NULL;95 psh->out1 = &psh->output; 96 psh->out2 = &psh->errout; 97 if (psh->memout.buf != NULL) { 98 ckfree(psh->memout.buf); 99 psh->memout.buf = NULL; 99 100 } 100 101 } … … 120 121 121 122 void 122 out1str( const char *p)123 { 124 outstr(p, out1);125 } 126 127 128 void 129 out2str( const char *p)130 { 131 outstr(p, out2);123 out1str(shinstance *psh, const char *p) 124 { 125 outstr(p, psh->out1); 126 } 127 128 129 void 130 out2str(shinstance *psh, const char *p) 131 { 132 outstr(p, psh->out2); 132 133 } 133 134 … … 138 139 while (*p) 139 140 outc(*p++, file); 140 if (file == out2)141 if (file == file->psh->out2) 141 142 flushout(file); 142 143 } … … 150 151 { 151 152 int offset; 153 shinstance *psh = dest->psh; 152 154 153 155 if (dest->fd == BLOCK_OUT) { … … 177 179 178 180 void 179 output_flushall( void)180 { 181 flushout(& output);182 flushout(& errout);181 output_flushall(shinstance *psh) 182 { 183 flushout(&psh->output); 184 flushout(&psh->errout); 183 185 } 184 186 … … 190 192 if (dest->buf == NULL || dest->nextc == dest->buf || dest->fd < 0) 191 193 return; 192 if (xwrite( psh, dest->fd, dest->buf, dest->nextc - dest->buf) < 0)194 if (xwrite(dest->psh, dest->fd, dest->buf, dest->nextc - dest->buf) < 0) 193 195 dest->flags |= OUTPUT_ERR; 194 196 dest->nextc = dest->buf; … … 198 200 199 201 void 200 freestdout( void)202 freestdout(shinstance *psh) 201 203 { 202 204 INTOFF; 203 if ( output.buf) {204 ckfree( output.buf);205 output.buf = NULL;206 output.nleft = 0;205 if (psh->output.buf) { 206 ckfree(psh->output.buf); 207 psh->output.buf = NULL; 208 psh->output.nleft = 0; 207 209 } 208 210 INTON; … … 222 224 223 225 void 224 out1fmt( const char *fmt, ...)226 out1fmt(shinstance *psh, const char *fmt, ...) 225 227 { 226 228 va_list ap; 227 229 228 230 va_start(ap, fmt); 229 doformat( out1, fmt, ap);231 doformat(psh->out1, fmt, ap); 230 232 va_end(ap); 231 233 } 232 234 233 235 void 234 dprintf( const char *fmt, ...)236 dprintf(shinstance *psh, const char *fmt, ...) 235 237 { 236 238 va_list ap; 237 239 238 240 va_start(ap, fmt); 239 doformat( out2, fmt, ap);241 doformat(psh->out2, fmt, ap); 240 242 va_end(ap); 241 flushout( out2);243 flushout(psh->out2); 242 244 } 243 245 … … 250 252 va_start(ap, fmt); 251 253 strout.nextc = outbuf; 252 strout.nleft = length;254 strout.nleft = (int)length; 253 255 strout.fd = BLOCK_OUT; 254 256 strout.flags = 0; … … 414 416 num /= base; 415 417 } 416 len = ( temp + TEMPSIZE - 1) - p;418 len = (int)((temp + TEMPSIZE - 1) - p); 417 419 if (prec < 0) 418 420 prec = 1; … … 445 447 pad = 0; 446 448 if (width) { 447 len = strlen(p);449 len = (int)strlen(p); 448 450 if (prec >= 0 && len > prec) 449 451 len = prec; … … 480 482 481 483 int 482 xwrite(shinstance *psh, int fd, char *buf, int nbytes)484 xwrite(shinstance *psh, int fd, char *buf, size_t nbytes) 483 485 { 484 486 int ntry; 485 inti;486 int n;487 long i; 488 size_t n; 487 489 488 490 n = nbytes; … … 492 494 if (i > 0) { 493 495 if ((n -= i) <= 0) 494 return nbytes;496 return (int)nbytes; 495 497 buf += i; 496 498 ntry = 0; 497 499 } else if (i == 0) { 498 500 if (++ntry > 10) 499 return nbytes - n;501 return (int)(nbytes - n); 500 502 } else if (errno != EINTR) { 501 503 return -1; … … 505 507 506 508 509 #ifdef not_used 507 510 /* 508 511 * Version of ioctl that retries after a signal is caught. … … 518 521 return i; 519 522 } 523 #endif /* not_used */ -
trunk/src/kash/output.h
r1198 r1199 54 54 extern struct output *out1; 55 55 extern struct output *out2;*/ 56 #ifdef _MSC_VER 57 # ifndef __attribute__ 58 # define __attribute__(a) 59 # endif 60 #endif 56 61 57 void open_mem( struct shinstance *,char *, int, struct output *);62 void open_mem(char *, int, struct output *); 58 63 void out1str(struct shinstance *, const char *); 59 64 void out2str(struct shinstance *, const char *); … … 72 77 __attribute__((__format__(__printf__,3,4))); 73 78 void doformat(struct output *, const char *, va_list); 74 int xwrite(struct shinstance *, int, char *, int);79 int xwrite(struct shinstance *, int, char *, size_t); 75 80 int xioctl(struct shinstance *, int, unsigned long, char *); 76 81 -
trunk/src/kash/parser.c
r1198 r1199 257 257 258 258 negate = 0; 259 TRACE(( "pipeline: entered\n"));259 TRACE((psh, "pipeline: entered\n")); 260 260 while (readtoken() == TNOT) 261 261 negate = !negate; … … 313 313 314 314 while (readtoken() == TNOT) { 315 TRACE(( "command: TNOT recognized\n"));315 TRACE((psh, "command: TNOT recognized\n")); 316 316 negate = !negate; 317 317 } … … 353 353 n1->nbinary.ch1 = list(0); 354 354 if ((got=readtoken()) != TDO) { 355 TRACE(( "expecting DO got %s %s\n", tokname[got], got == TWORD ? wordtext : ""));355 TRACE((psh, "expecting DO got %s %s\n", tokname[got], got == TWORD ? wordtext : "")); 356 356 synexpect(TDO); 357 357 } … … 554 554 555 555 while (readtoken() == TNOT) { 556 TRACE(( "command: TNOT recognized\n"));556 TRACE((psh, "command: TNOT recognized\n")); 557 557 negate = !negate; 558 558 } … … 622 622 void fixredir(union node *n, const char *text, int err) 623 623 { 624 TRACE(( "Fix redir %s %d\n", text, err));624 TRACE((psh, "Fix redir %s %d\n", text, err)); 625 625 if (!err) 626 626 n->ndup.vname = NULL; … … 654 654 if (quoteflag == 0) 655 655 n->type = NXHERE; 656 TRACE(( "Here document %d\n", n->type));656 TRACE((psh, "Here document %d\n", n->type)); 657 657 if (here->striptabs) { 658 658 while (*wordtext == '\t') … … 753 753 lasttoken = t = pp - 754 754 parsekwd + KWDOFFSET; 755 TRACE(( "keyword %s recognized\n", tokname[t]));755 TRACE((psh, "keyword %s recognized\n", tokname[t])); 756 756 goto out; 757 757 } 758 758 } 759 759 if(!noalias && 760 (ap = lookupalias( wordtext, 1)) != NULL) {760 (ap = lookupalias(psh, wordtext, 1)) != NULL) { 761 761 pushstring(ap->val, strlen(ap->val), ap); 762 762 checkkwd = savecheckkwd; … … 769 769 #ifdef DEBUG 770 770 if (!alreadyseen) 771 TRACE(( "token %s %s\n", tokname[t], t == TWORD ? wordtext : ""));771 TRACE((psh, "token %s %s\n", tokname[t], t == TWORD ? wordtext : "")); 772 772 else 773 TRACE(( "reread token %s %s\n", tokname[t], t == TWORD ? wordtext : ""));773 TRACE((psh, "reread token %s %s\n", tokname[t], t == TWORD ? wordtext : "")); 774 774 #endif 775 775 return (t); … … 1620 1620 { 1621 1621 if (commandname) 1622 outfmt(& errout, "%s: %d: ", commandname, startlinno);1623 outfmt(& errout, "Syntax error: %s\n", msg);1624 error( (char *)NULL);1622 outfmt(&psh->errout, "%s: %d: ", commandname, startlinno); 1623 outfmt(&psh->errout, "Syntax error: %s\n", msg); 1624 error(psh, (char *)NULL); 1625 1625 /* NOTREACHED */ 1626 1626 } -
trunk/src/kash/redir.c
r1198 r1199 149 149 default: 150 150 INTON; 151 error( "%d: %s", fd, strerror(errno));151 error(psh, "%d: %s", fd, strerror(errno)); 152 152 /* NOTREACHED */ 153 153 } … … 244 244 return; 245 245 ecreate: 246 error( "cannot create %s: %s", fname, errmsg(errno, E_CREAT));246 error(psh, "cannot create %s: %s", fname, errmsg(psh, errno, E_CREAT)); 247 247 eopen: 248 error( "cannot open %s: %s", fname, errmsg(errno, E_OPEN));248 error(psh, "cannot open %s: %s", fname, errmsg(psh, errno, E_OPEN)); 249 249 } 250 250 … … 263 263 264 264 if (pipe(pip) < 0) 265 error( "Pipe call failed");265 error(psh, "Pipe call failed"); 266 266 if (redir->type == NHERE) { 267 267 len = strlen(redir->nhere.doc->narg.text); … … 385 385 return EMPTY; 386 386 else 387 error( "%d: %s", from, strerror(errno));387 error(psh, "%d: %s", from, strerror(errno)); 388 388 } 389 389 return newfd; -
trunk/src/kash/shfile.h
r1198 r1199 75 75 char *shfile_getcwd(shfdtab *, char *, int); 76 76 int shfile_isatty(shfdtab *, int); 77 /*int shfile_ioctl(shfdtab *, int, unsigned long, char *);*/ 77 78 78 79 #endif -
trunk/src/kash/shinstance.c
r1198 r1199 52 52 psh->stacknxt = psh->stackbase.space; 53 53 54 /* output.c */ 55 psh->output.bufsize = OUTBUFSIZ; 56 psh->output.fd = 1; 57 psh->errout.bufsize = 100; 58 psh->errout.fd = 2; 59 psh->memout.fd = MEM_OUT; 60 psh->out1 = &psh->output; 61 psh->out2 = &psh->errout; 62 63 /* .c */ 54 64 } 55 65 return psh; -
trunk/src/kash/shinstance.h
r1198 r1199 84 84 struct output *out1; 85 85 struct output *out2; 86 /* output.c */ 87 #define OUTBUFSIZ BUFSIZ 88 #define MEM_OUT -3 /**< output to dynamically allocated memory */ 86 89 87 90 /* options.h */ -
trunk/src/kash/show.c
r1198 r1199 61 61 static void sharg(union node *, FILE *); 62 62 static void indent(int, char *, FILE *); 63 static void trstring( char *);64 65 66 void 67 showtree( union node *n)68 { 69 trputs( "showtree called\n");63 static void trstring(shinstance *, char *); 64 65 66 void 67 showtree(shinstance *psh, union node *n) 68 { 69 trputs(psh, "showtree called\n"); 70 70 shtree(n, 1, NULL, stdout); 71 71 } … … 274 274 #ifdef DEBUG 275 275 void 276 trputc( int c)276 trputc(shinstance *psh, int c) 277 277 { 278 278 if (debug(psh) != 1) … … 311 311 #ifdef DEBUG 312 312 void 313 trputs( const char *s)313 trputs(shinstance *psh, const char *s) 314 314 { 315 315 if (debug(psh) != 1) … … 320 320 321 321 static void 322 trstring( char *s)322 trstring(shinstance *psh, char *s) 323 323 { 324 324 char *p; … … 367 367 return; 368 368 while (*ap) { 369 trstring( *ap++);369 trstring(psh, *ap++); 370 370 if (*ap) 371 371 putc(' ', tracefile); … … 379 379 #ifdef DEBUG 380 380 void 381 opentrace( void)381 opentrace(shinstance *psh) 382 382 { 383 383 char s[100]; … … 424 424 fcntl(fileno(tracefile), F_SETFL, flags | O_APPEND); 425 425 #endif 426 set linebuf(tracefile);426 setvbuf(tracefile, (char *)NULL, _IOLBF, 0); //setlinebuf(tracefile); 427 427 fputs("\nTracing started.\n", tracefile); 428 428 } -
trunk/src/kash/show.h
r880 r1199 40 40 void trargs(struct shinstance *, char **); 41 41 #ifdef DEBUG 42 void trputc( int);43 void trputs( const char *);42 void trputc(struct shinstance *, int); 43 void trputs(struct shinstance *, const char *); 44 44 void opentrace(struct shinstance *); 45 45 #endif -
trunk/src/kash/trap.c
r1198 r1199 127 127 int n; 128 128 129 out1str( "EXIT ");129 out1str(psh, "EXIT "); 130 130 #ifndef HAVE_SYS_SIGNAME 131 131 init_sys_signame(); … … 133 133 134 134 for (n = 1; n < NSIG; n++) { 135 out1fmt( "%s", sys_signame[n]);135 out1fmt(psh, "%s", sys_signame[n]); 136 136 if ((n == NSIG/2) || n == (NSIG - 1)) 137 out1str( "\n");137 out1str(psh, "\n"); 138 138 else 139 out1c( ' ');139 out1c(psh, ' '); 140 140 } 141 141 } … … 158 158 for (signo = 0 ; signo <= NSIG ; signo++) 159 159 if (trap[signo] != NULL) { 160 out1fmt( "trap -- ");160 out1fmt(psh, "trap -- "); 161 161 print_quoted(trap[signo]); 162 out1fmt( " %s\n",162 out1fmt(psh, " %s\n", 163 163 (signo) ? sys_signame[signo] : "EXIT"); 164 164 } … … 182 182 } 183 183 else 184 error( "bad option %s\n", *ap);184 error(psh, "bad option %s\n", *ap); 185 185 } 186 186 else … … 195 195 196 196 if (signo < 0 || signo > NSIG) 197 error( "%s: bad trap", *ap);197 error(psh, "%s: bad trap", *ap); 198 198 199 199 INTOFF; … … 375 375 376 376 void 377 onsig( int signo)377 onsig(shinstance *psh, int signo) 378 378 { 379 379 signal(signo, onsig); 380 380 if (signo == SIGINT && trap[SIGINT] == NULL) { 381 onint( );381 onint(psh); 382 382 return; 383 383 } … … 447 447 char *p; 448 448 449 TRACE(( "pid %d, exitshell(%d)\n", getpid(), status));449 TRACE((psh, "pid %d, exitshell(%d)\n", getpid(), status)); 450 450 if (setjmp(loc1.loc)) { 451 451 goto l1; … … 460 460 } 461 461 l1: handler = &loc2; /* probably unnecessary */ 462 output_flushall( );462 output_flushall(psh); 463 463 #if JOBS 464 464 setjobctl(0); -
trunk/src/kash/var.c
r1198 r1199 332 332 namelen = p - name; 333 333 if (isbad) 334 error( "%.*s: bad variable name", namelen, name);334 error(psh, "%.*s: bad variable name", namelen, name); 335 335 len = namelen + 2; /* 2 is space for '=' and '\0' */ 336 336 if (val == NULL) { … … 370 370 if (vp != NULL) { 371 371 if (vp->flags & VREADONLY) 372 error( "%.*s: is read only", vp->name_len, s);372 error(psh, "%.*s: is read only", vp->name_len, s); 373 373 if (flags & VNOSET) 374 374 return; … … 575 575 576 576 if (strcspn(p, "|&;<>()$`\\\"' \t\n*?[]#~=%") == strlen(p)) { 577 out1fmt( "%s", p);577 out1fmt(psh, "%s", p); 578 578 return; 579 579 } 580 580 while (*p) { 581 581 if (*p == '\'') { 582 out1fmt( "\\'");582 out1fmt(psh, "\\'"); 583 583 p++; 584 584 continue; … … 586 586 q = index(p, '\''); 587 587 if (!q) { 588 out1fmt( "'%s'", p );588 out1fmt(psh, "'%s'", p ); 589 589 return; 590 590 } 591 out1fmt( "'%.*s'", (int)(q - p), p );591 out1fmt(psh, "'%.*s'", (int)(q - p), p ); 592 592 p = q; 593 593 } … … 648 648 vp = *vpp; 649 649 if (name) 650 out1fmt( "%s ", name);650 out1fmt(psh, "%s ", name); 651 651 for (p = vp->text ; *p != '=' ; p++) 652 out1c( *p);652 out1c(psh, *p); 653 653 if (!(vp->flags & VUNSET) && show_value) { 654 out1fmt( "=");655 print_quoted( ++p);656 } 657 out1c( '\n');654 out1fmt(psh, "="); 655 print_quoted(psh, ++p); 656 } 657 out1c(psh, '\n'); 658 658 } 659 659 return 0; … … 707 707 708 708 if (! in_function(psh)) 709 error( "Not in a function");709 error(psh, "Not in a function"); 710 710 while ((name = *argptr++) != NULL) { 711 711 mklocal(name, 0); … … 774 774 localvars = lvp->next; 775 775 vp = lvp->vp; 776 TRACE(( "poplocalvar %s", vp ? vp->text : "-"));776 TRACE((psh, "poplocalvar %s", vp ? vp->text : "-")); 777 777 if (vp == NULL) { /* $- saved */ 778 778 memcpy(optlist, lvp->text, sizeof_optlist); … … 801 801 setvar(argv[1], argv[2], 0); 802 802 else 803 error( "List assignment not implemented");803 error(psh, "List assignment not implemented"); 804 804 return 0; 805 805 }
Note:
See TracChangeset
for help on using the changeset viewer.