Changeset 1201 in kBuild
- Timestamp:
- Oct 6, 2007 11:57:35 PM (18 years ago)
- Location:
- trunk/src/kash
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kash/Makefile.kmk
r1199 r1201 44 44 syntax.c \ 45 45 output.c \ 46 input.c \ 46 47 \ 47 48 exec.c \ 48 49 expand.c \ 49 input.c \50 50 jobs.c \ 51 51 miscbltin.c \ -
trunk/src/kash/bltin/bltin.h
r1199 r1201 51 51 #undef putchar 52 52 #undef fileno 53 #define stdout out154 #define stderr out253 #define stdout psh->out1 54 #define stderr psh->out2 55 55 #define printf out1fmt 56 56 #define putc(c, file) outc(c, file) -
trunk/src/kash/exec.c
r1200 r1201 218 218 exraise(psh, EXSHELLPROC); 219 219 } 220 initshellproc( );221 setinputfile( cmd, 0);220 initshellproc(psh); 221 setinputfile(psh, cmd, 0); 222 222 commandname = arg0 = savestr(argv[0]); 223 223 #ifdef EXEC_HASH_BANG_SCRIPT 224 pgetc( ); pungetc(); /* fill up input buffer */224 pgetc(psh); pungetc(psh); /* fill up input buffer */ 225 225 p = parsenextc; 226 226 if (parsenleft > 2 && p[0] == '#' && p[1] == '!') { … … 703 703 delete_cmd_entry(); 704 704 if (act & DO_ERR) 705 outfmt( out2, "%s: %s\n", name, errmsg(psh, e, E_EXEC));705 outfmt(psh->out2, "%s: %s\n", name, errmsg(psh, e, E_EXEC)); 706 706 entry->cmdtype = CMDUNKNOWN; 707 707 return; -
trunk/src/kash/expand.c
r1200 r1201 122 122 123 123 void 124 expandhere( union node *arg, int fd)124 expandhere(shinstance *psh, union node *arg, int fd) 125 125 { 126 126 psh->herefd = fd; 127 expandarg( arg, (struct arglist *)NULL, 0);128 xwrite(psh, fd, stackblock(psh), expdest - stackblock(psh));127 expandarg(psh, arg, (struct arglist *)NULL, 0); 128 xwrite(psh, fd, stackblock(psh), psh->expdest - stackblock(psh)); 129 129 } 130 130 … … 164 164 } else { 165 165 if (flag & EXP_REDIR) /*XXX - for now, just remove escapes */ 166 rmescapes(p );166 rmescapes(psh, p); 167 167 sp = (struct strlist *)stalloc(psh, sizeof (struct strlist)); 168 168 sp->text = p; … … 231 231 break; 232 232 case CTLENDARI: 233 expari( flag);233 expari(psh, flag); 234 234 break; 235 235 case ':': … … 398 398 removerecordregions(begoff); 399 399 if (quotes) 400 rmescapes(p +2);400 rmescapes(psh, p+2); 401 401 result = arith(p+2); 402 402 fmtstr(p, 12, "%d", result); … … 522 522 case VSQUESTION: 523 523 if (*p != CTLENDVAR) { 524 outfmt(& errout, "%s\n", startp);524 outfmt(&psh->errout, "%s\n", startp); 525 525 error(psh, (char *)NULL); 526 526 } … … 534 534 c = *loc; 535 535 *loc = '\0'; 536 if (patmatch( str, startp, varflags & VSQUOTE))536 if (patmatch(psh, str, startp, varflags & VSQUOTE)) 537 537 goto recordleft; 538 538 *loc = c; … … 546 546 c = *loc; 547 547 *loc = '\0'; 548 if (patmatch( str, startp, varflags & VSQUOTE))548 if (patmatch(psh, str, startp, varflags & VSQUOTE)) 549 549 goto recordleft; 550 550 *loc = c; … … 563 563 case VSTRIMRIGHT: 564 564 for (loc = str - 1; loc >= startp;) { 565 if (patmatch( str, loc, varflags & VSQUOTE))565 if (patmatch(psh, str, loc, varflags & VSQUOTE)) 566 566 goto recordright; 567 567 loc--; … … 579 579 case VSTRIMRIGHTMAX: 580 580 for (loc = startp; loc < str - 1; loc++) { 581 if (patmatch( str, loc, varflags & VSQUOTE))581 if (patmatch(psh, str, loc, varflags & VSQUOTE)) 582 582 goto recordright; 583 583 if ((varflags & VSQUOTE) && *loc == CTLESC) … … 1111 1111 nometa: 1112 1112 *exparg.lastp = str; 1113 rmescapes( str->text);1113 rmescapes(psh, str->text); 1114 1114 exparg.lastp = &str->next; 1115 1115 } else { … … 1235 1235 if (dp->d_name[0] == '.' && ! matchdot) 1236 1236 continue; 1237 if (patmatch( start, dp->d_name, 0)) {1237 if (patmatch(psh, start, dp->d_name, 0)) { 1238 1238 if (atend) { 1239 1239 scopy(dp->d_name, enddir); … … 1516 1516 STPUTC(psh, '\0', expdest); 1517 1517 p = grabstackstr(psh, expdest); 1518 result = patmatch(p , val, 0);1518 result = patmatch(psh, p, val, 0); 1519 1519 popstackmark(psh, &smark); 1520 1520 return result; … … 1551 1551 1552 1552 int 1553 wordexpcmd( int argc, char **argv)1553 wordexpcmd(shinstance *psh, int argc, char **argv) 1554 1554 { 1555 1555 size_t len; -
trunk/src/kash/generated/init.c
r1200 r1201 173 173 174 174 void 175 init( ) {175 init(shinstance *psh) { 176 176 177 177 /* from exec.c: */ … … 206 206 207 207 void 208 reset( ) {208 reset(shinstance *psh) { 209 209 210 210 /* from eval.c: */ … … 219 219 if (exception != EXSHELLPROC) 220 220 parselleft = parsenleft = 0; /* clear input buffer */ 221 popallfiles( );221 popallfiles(psh); 222 222 } 223 223 224 224 /* from output.c: */ 225 225 { 226 out1 = &output;227 out2 = &errout;226 psh->out1 = &psh->output; 227 psh->out2 = &psh->errout; 228 228 if (memout.buf != NULL) { 229 229 ckfree(memout.buf); … … 252 252 253 253 void 254 initshellproc( ) {254 initshellproc(shinstance *psh) { 255 255 256 256 /* from alias.c: */ … … 271 271 /* from input.c: */ 272 272 { 273 popallfiles( );273 popallfiles(psh); 274 274 } 275 275 -
trunk/src/kash/histedit.c
r1200 r1201 196 196 if (el != NULL && term != NULL) 197 197 if (el_set(el, EL_TERMINAL, term) != 0) { 198 outfmt( out2, "sh: Can't set terminal type %s\n", term);199 outfmt( out2, "sh: Using dumb terminal settings.\n");198 outfmt(psh->out2, "sh: Can't set terminal type %s\n", term); 199 outfmt(psh->out2, "sh: Using dumb terminal settings.\n"); 200 200 } 201 201 } -
trunk/src/kash/input.c
r1199 r1201 69 69 #include "parser.h" 70 70 #include "myhistedit.h" 71 #include "shinstance.h" 71 72 72 73 #define EOF_NLEFT -99 /* value of parsenleft when EOF pushed back */ 73 74 74 MKINIT75 struct strpush {76 struct strpush *prev; /* preceding string on stack */77 char *prevstring;78 int prevnleft;79 int prevlleft;80 struct alias *ap; /* if push was associated with an alias */81 };82 83 / *84 * The parsefile structure pointed to by the global variable parsefile85 * contains information about the current file being read.86 */87 88 MKINIT89 struct parsefile {90 struct parsefile *prev; /* preceding file on stack */91 int linno; /* current line */92 int fd; /* file descriptor (or -1 if string) */93 int nleft; /* number of chars left in this line */94 int lleft; /* number of chars left in this buffer */95 char *nextc; /* next char in buffer */96 char *buf; /* input buffer */97 struct strpush *strpush; /* for pushing strings at this level */98 struct strpush basestrpush; /* so pushing one is fast */99 };100 101 102 int plinno = 1; /* input line number */103 int parsenleft; /* copy of parsefile->nleft */104 MKINIT int parselleft; /* copy of parsefile->lleft */105 char *parsenextc; /* copy of parsefile->nextc */106 MKINIT struct parsefile basepf; /* top level input file */107 MKINIT char basebuf[BUFSIZ]; /* buffer for top level input file */108 struct parsefile *parsefile = &basepf; /* current input file */109 int init_editline = 0; /* editline library initialized? */110 int whichprompt; /* 1 == PS1, 2 == PS2 */111 112 #ifndef SMALL113 EditLine *el; /* cookie for editline package */114 #endif115 116 STATIC void pushfile( void);117 static int preadfd( void);75 //MKINIT 76 //struct strpush { 77 // struct strpush *prev; /* preceding string on stack */ 78 // char *prevstring; 79 // int prevnleft; 80 // int prevlleft; 81 // struct alias *ap; /* if push was associated with an alias */ 82 //}; 83 // 84 ///* 85 // * The parsefile structure pointed to by the global variable parsefile 86 // * contains information about the current file being read. 87 // */ 88 // 89 //MKINIT 90 //struct parsefile { 91 // struct parsefile *prev; /* preceding file on stack */ 92 // int linno; /* current line */ 93 // int fd; /* file descriptor (or -1 if string) */ 94 // int nleft; /* number of chars left in this line */ 95 // int lleft; /* number of chars left in this buffer */ 96 // char *nextc; /* next char in buffer */ 97 // char *buf; /* input buffer */ 98 // struct strpush *strpush; /* for pushing strings at this level */ 99 // struct strpush basestrpush; /* so pushing one is fast */ 100 //}; 101 // 102 // 103 //int plinno = 1; /* input line number */ 104 //int parsenleft; /* copy of parsefile->nleft */ 105 //MKINIT int parselleft; /* copy of parsefile->lleft */ 106 //char *parsenextc; /* copy of parsefile->nextc */ 107 //MKINIT struct parsefile basepf; /* top level input file */ 108 //MKINIT char basebuf[BUFSIZ]; /* buffer for top level input file */ 109 //struct parsefile *parsefile = &basepf; /* current input file */ 110 //int init_editline = 0; /* editline library initialized? */ 111 //int whichprompt; /* 1 == PS1, 2 == PS2 */ 112 // 113 //#ifndef SMALL 114 //EditLine *el; /* cookie for editline package */ 115 //#endif 116 117 STATIC void pushfile(shinstance *psh); 118 static int preadfd(shinstance *psh); 118 119 119 120 #ifdef mkinit … … 123 124 124 125 INIT { 125 basepf.nextc = basepf.buf =basebuf;126 psh->basepf.nextc = psh->basepf.buf = psh->basebuf; 126 127 } 127 128 128 129 RESET { 129 if ( exception != EXSHELLPROC)130 p arselleft =parsenleft = 0; /* clear input buffer */131 popallfiles( );130 if (psh->exception != EXSHELLPROC) 131 psh->parselleft = psh->parsenleft = 0; /* clear input buffer */ 132 popallfiles(psh); 132 133 } 133 134 134 135 SHELLPROC { 135 popallfiles( );136 popallfiles(psh); 136 137 } 137 138 #endif … … 143 144 144 145 char * 145 pfgets( char *line, int len)146 pfgets(shinstance *psh, char *line, int len) 146 147 { 147 148 char *p = line; … … 150 151 151 152 while (--nleft > 0) { 152 c = pgetc_macro( );153 c = pgetc_macro(psh); 153 154 if (c == PEOF) { 154 155 if (p == line) … … 172 173 173 174 int 174 pgetc( void)175 { 176 return pgetc_macro( );175 pgetc(shinstance *psh) 176 { 177 return pgetc_macro(psh); 177 178 } 178 179 179 180 180 181 static int 181 preadfd( void)182 preadfd(shinstance *psh) 182 183 { 183 184 int nr; 184 char *buf = 185 p arsenextc = buf;185 char *buf = psh->parsefile->buf; 186 psh->parsenextc = buf; 186 187 187 188 retry: 188 189 #ifndef SMALL 189 if (p arsefile->fd == 0 &&el) {190 if (psh->parsefile->fd == 0 && psh->el) { 190 191 static const char *rl_cp; 191 192 static int el_len; 192 193 193 194 if (rl_cp == NULL) 194 rl_cp = el_gets( el, &el_len);195 rl_cp = el_gets(psh->el, &el_len); 195 196 if (rl_cp == NULL) 196 197 nr = 0; … … 209 210 } else 210 211 #endif 211 nr = read(parsefile->fd, buf, BUFSIZ - 8);212 nr = shfile_read(&psh->fdtab, psh->parsefile->fd, buf, BUFSIZ - 8); 212 213 213 214 … … 216 217 if (errno == EINTR) 217 218 goto retry; 218 if (p arsefile->fd == 0 && errno == EWOULDBLOCK) {219 int flags = fcntl(0, F_GETFL, 0);219 if (psh->parsefile->fd == 0 && errno == EWOULDBLOCK) { 220 int flags = shfile_fcntl(&psh->fdtab, 0, F_GETFL, 0); 220 221 if (flags >= 0 && flags & O_NONBLOCK) { 221 222 flags &=~ O_NONBLOCK; 222 if ( fcntl(0, F_SETFL, flags) >= 0) {223 if (shfile_fcntl(&psh->fdtab, 0, F_SETFL, flags) >= 0) { 223 224 out2str(psh, "sh: turning off NDELAY mode\n"); 224 225 goto retry; … … 243 244 244 245 int 245 preadbuffer( void)246 preadbuffer(shinstance *psh) 246 247 { 247 248 char *p, *q; … … 250 251 char savec; 251 252 252 if (p arsefile->strpush) {253 popstring( );254 if (--p arsenleft >= 0)255 return (*p arsenextc++);256 } 257 if (p arsenleft == EOF_NLEFT ||parsefile->buf == NULL)253 if (psh->parsefile->strpush) { 254 popstring(psh); 255 if (--psh->parsenleft >= 0) 256 return (*psh->parsenextc++); 257 } 258 if (psh->parsenleft == EOF_NLEFT || psh->parsefile->buf == NULL) 258 259 return PEOF; 259 flushout(& output);260 flushout(& errout);260 flushout(&psh->output); 261 flushout(&psh->errout); 261 262 262 263 again: 263 if (p arselleft <= 0) {264 if ((p arselleft = preadfd()) == -1) {265 p arselleft =parsenleft = EOF_NLEFT;264 if (psh->parselleft <= 0) { 265 if ((psh->parselleft = preadfd(psh)) == -1) { 266 psh->parselleft = psh->parsenleft = EOF_NLEFT; 266 267 return PEOF; 267 268 } 268 269 } 269 270 270 q = p = p arsenextc;271 q = p = psh->parsenextc; 271 272 272 273 /* delete nul characters */ … … 283 284 284 285 case '\n': 285 p arsenleft = q - parsenextc;286 psh->parsenleft = (int)(q - psh->parsenextc); 286 287 more = 0; /* Stop processing here */ 287 288 break; … … 294 295 *q++ = *p++; 295 296 check: 296 if (--p arselleft <= 0) {297 p arsenleft = q - parsenextc - 1;298 if (p arsenleft < 0)297 if (--psh->parselleft <= 0) { 298 psh->parsenleft = (int)(q - psh->parsenextc - 1); 299 if (psh->parsenleft < 0) 299 300 goto again; 300 301 *q = '\0'; … … 307 308 308 309 #ifndef SMALL 309 if (p arsefile->fd == 0 && hist && something) {310 if (psh->parsefile->fd == 0 && hist && something) { 310 311 HistEvent he; 311 312 INTOFF; 312 history(hist, &he, whichprompt == 1? H_ENTER : H_APPEND,313 p arsenextc);313 history(hist, &he, psh->whichprompt == 1? H_ENTER : H_APPEND, 314 psh->parsenextc); 314 315 INTON; 315 316 } … … 317 318 318 319 if (vflag(psh)) { 319 out2str(psh, p arsenextc);320 flushout( out2);320 out2str(psh, psh->parsenextc); 321 flushout(psh->out2); 321 322 } 322 323 323 324 *q = savec; 324 325 325 return *p arsenextc++;326 return *psh->parsenextc++; 326 327 } 327 328 … … 332 333 333 334 void 334 pungetc( void)335 { 336 p arsenleft++;337 p arsenextc--;335 pungetc(shinstance *psh) 336 { 337 psh->parsenleft++; 338 psh->parsenextc--; 338 339 } 339 340 … … 343 344 */ 344 345 void 345 pushstring( char *s, int len, void *ap)346 pushstring(shinstance *psh, char *s, int len, void *ap) 346 347 { 347 348 struct strpush *sp; … … 349 350 INTOFF; 350 351 /*dprintf("*** calling pushstring: %s, %d\n", s, len);*/ 351 if (p arsefile->strpush) {352 if (psh->parsefile->strpush) { 352 353 sp = ckmalloc(sizeof (struct strpush)); 353 sp->prev = p arsefile->strpush;354 p arsefile->strpush = sp;354 sp->prev = psh->parsefile->strpush; 355 psh->parsefile->strpush = sp; 355 356 } else 356 sp = p arsefile->strpush = &(parsefile->basestrpush);357 sp->prevstring = p arsenextc;358 sp->prevnleft = p arsenleft;359 sp->prevlleft = p arselleft;357 sp = psh->parsefile->strpush = &(psh->parsefile->basestrpush); 358 sp->prevstring = psh->parsenextc; 359 sp->prevnleft = psh->parsenleft; 360 sp->prevlleft = psh->parselleft; 360 361 sp->ap = (struct alias *)ap; 361 362 if (ap) 362 363 ((struct alias *)ap)->flag |= ALIASINUSE; 363 p arsenextc = s;364 p arsenleft = len;364 psh->parsenextc = s; 365 psh->parsenleft = len; 365 366 INTON; 366 367 } 367 368 368 369 void 369 popstring( void)370 { 371 struct strpush *sp = p arsefile->strpush;370 popstring(shinstance *psh) 371 { 372 struct strpush *sp = psh->parsefile->strpush; 372 373 373 374 INTOFF; 374 p arsenextc = sp->prevstring;375 p arsenleft = sp->prevnleft;376 p arselleft = sp->prevlleft;377 /*dprintf("*** calling popstring: restoring to '%s'\n", p arsenextc);*/375 psh->parsenextc = sp->prevstring; 376 psh->parsenleft = sp->prevnleft; 377 psh->parselleft = sp->prevlleft; 378 /*dprintf("*** calling popstring: restoring to '%s'\n", psh->parsenextc);*/ 378 379 if (sp->ap) 379 380 sp->ap->flag &= ~ALIASINUSE; 380 p arsefile->strpush = sp->prev;381 if (sp != &(p arsefile->basestrpush))381 psh->parsefile->strpush = sp->prev; 382 if (sp != &(psh->parsefile->basestrpush)) 382 383 ckfree(sp); 383 384 INTON; … … 390 391 391 392 void 392 setinputfile( const char *fname, int push)393 setinputfile(shinstance *psh, const char *fname, int push) 393 394 { 394 395 int fd; … … 396 397 397 398 INTOFF; 398 if ((fd = open(fname, O_RDONLY)) < 0) 399 /** @todo shfile fixme */ 400 if ((fd = shfile_open(&psh->fdtab, fname, O_RDONLY)) < 0) 399 401 error(psh, "Can't open %s", fname); 400 402 if (fd < 10) { 401 fd2 = copyfd( fd, 10);402 close(fd);403 fd2 = copyfd(psh, fd, 10); 404 shfile_close(&psh->fdtab, fd); 403 405 if (fd2 < 0) 404 406 error(psh, "Out of file descriptors"); 405 407 fd = fd2; 406 408 } 407 setinputfd( fd, push);409 setinputfd(psh, fd, push); 408 410 INTON; 409 411 } … … 416 418 417 419 void 418 setinputfd( int fd, int push)419 { 420 (void) fcntl(fd, F_SETFD, FD_CLOEXEC);420 setinputfd(shinstance *psh, int fd, int push) 421 { 422 (void) shfile_fcntl(&psh->fdtab, fd, F_SETFD, FD_CLOEXEC); 421 423 if (push) { 422 pushfile( );423 p arsefile->buf = ckmalloc(BUFSIZ);424 } 425 if (p arsefile->fd > 0)426 close(parsefile->fd);427 p arsefile->fd = fd;428 if (p arsefile->buf == NULL)429 p arsefile->buf = ckmalloc(BUFSIZ);430 p arselleft =parsenleft = 0;431 p linno = 1;424 pushfile(psh); 425 psh->parsefile->buf = ckmalloc(BUFSIZ); 426 } 427 if (psh->parsefile->fd > 0) 428 shfile_close(&psh->fdtab, psh->parsefile->fd); 429 psh->parsefile->fd = fd; 430 if (psh->parsefile->buf == NULL) 431 psh->parsefile->buf = ckmalloc(BUFSIZ); 432 psh->parselleft = psh->parsenleft = 0; 433 psh->plinno = 1; 432 434 } 433 435 … … 438 440 439 441 void 440 setinputstring( char *string, int push)442 setinputstring(shinstance *psh, char *string, int push) 441 443 { 442 444 INTOFF; 443 445 if (push) 444 pushfile( );445 p arsenextc = string;446 p arselleft = parsenleft =strlen(string);447 p arsefile->buf = NULL;448 p linno = 1;446 pushfile(psh); 447 psh->parsenextc = string; 448 psh->parselleft = psh->parsenleft = (int)strlen(string); 449 psh->parsefile->buf = NULL; 450 psh->plinno = 1; 449 451 INTON; 450 452 } … … 458 460 459 461 STATIC void 460 pushfile( void)462 pushfile(shinstance *psh) 461 463 { 462 464 struct parsefile *pf; 463 465 464 p arsefile->nleft =parsenleft;465 p arsefile->lleft =parselleft;466 p arsefile->nextc =parsenextc;467 p arsefile->linno =plinno;466 psh->parsefile->nleft = psh->parsenleft; 467 psh->parsefile->lleft = psh->parselleft; 468 psh->parsefile->nextc = psh->parsenextc; 469 psh->parsefile->linno = psh->plinno; 468 470 pf = (struct parsefile *)ckmalloc(sizeof (struct parsefile)); 469 pf->prev = p arsefile;471 pf->prev = psh->parsefile; 470 472 pf->fd = -1; 471 473 pf->strpush = NULL; 472 474 pf->basestrpush.prev = NULL; 473 p arsefile = pf;474 } 475 476 477 void 478 popfile( void)479 { 480 struct parsefile *pf = p arsefile;475 psh->parsefile = pf; 476 } 477 478 479 void 480 popfile(shinstance *psh) 481 { 482 struct parsefile *pf = psh->parsefile; 481 483 482 484 INTOFF; 483 485 if (pf->fd >= 0) 484 close(pf->fd);486 shfile_close(&psh->fdtab, pf->fd); 485 487 if (pf->buf) 486 488 ckfree(pf->buf); 487 489 while (pf->strpush) 488 popstring( );489 p arsefile = pf->prev;490 popstring(psh); 491 psh->parsefile = pf->prev; 490 492 ckfree(pf); 491 p arsenleft =parsefile->nleft;492 p arselleft =parsefile->lleft;493 p arsenextc =parsefile->nextc;494 p linno =parsefile->linno;493 psh->parsenleft = psh->parsefile->nleft; 494 psh->parselleft = psh->parsefile->lleft; 495 psh->parsenextc = psh->parsefile->nextc; 496 psh->plinno = psh->parsefile->linno; 495 497 INTON; 496 498 } … … 502 504 503 505 void 504 popallfiles( void)505 { 506 while (p arsefile != &basepf)507 popfile( );506 popallfiles(shinstance *psh) 507 { 508 while (psh->parsefile != &psh->basepf) 509 popfile(psh); 508 510 } 509 511 … … 525 527 526 528 void 527 closescript( int vforked)529 closescript(shinstance *psh, int vforked) 528 530 { 529 531 if (vforked) 530 532 return; 531 popallfiles( );532 if (p arsefile->fd > 0) {533 close(parsefile->fd);534 p arsefile->fd = 0;535 } 536 } 533 popallfiles(psh); 534 if (psh->parsefile->fd > 0) { 535 shfile_close(&psh->fdtab, psh->parsefile->fd); 536 psh->parsefile->fd = 0; 537 } 538 } -
trunk/src/kash/input.h
r879 r1201 42 42 * package must set its value. 43 43 */ 44 extern int plinno;45 extern int parsenleft; /* number of characters left in input buffer */46 extern char *parsenextc; /* next character in input buffer */47 extern int init_editline; /* 0 == not setup, 1 == OK, -1 == failed */44 //extern int plinno; 45 //extern int parsenleft; /* number of characters left in input buffer */ 46 //extern char *parsenextc; /* next character in input buffer */ 47 //extern int init_editline; /* 0 == not setup, 1 == OK, -1 == failed */ 48 48 49 49 char *pfgets(struct shinstance *, char *, int); … … 60 60 void closescript(struct shinstance *, int); 61 61 62 #define pgetc_macro( ) (--psh->parsenleft >= 0? *psh->parsenextc++ : preadbuffer(psh))62 #define pgetc_macro(psh) (--(psh)->parsenleft >= 0? *(psh)->parsenextc++ : preadbuffer(psh)) -
trunk/src/kash/jobs.c
r1199 r1201 905 905 rootshell = 0; 906 906 907 closescript( vforked);908 clear_traps( vforked);907 closescript(psh, vforked); 908 clear_traps(psh, vforked); 909 909 #if JOBS 910 910 if (!vforked) … … 1095 1095 mode = SHOW_SIGNALLED | SHOW_NO_FREE; 1096 1096 if (mode) 1097 showjob( out2, thisjob, mode);1097 showjob(psh->out2, thisjob, mode); 1098 1098 else { 1099 1099 TRACE((psh, "Not printing status, rootshell=%d, job=%p\n", -
trunk/src/kash/parser.c
r1199 r1201 209 209 parseheredoc(); 210 210 else 211 pungetc( ); /* push back EOF on input */211 pungetc(psh); /* push back EOF on input */ 212 212 return n1; 213 213 default: … … 661 661 if (! noexpand(wordtext) || (i = strlen(wordtext)) == 0 || i > EOFMARKLEN) 662 662 synerror("Illegal eof marker for << redirection"); 663 rmescapes( wordtext);663 rmescapes(psh, wordtext); 664 664 here->eofmark = wordtext; 665 665 here->next = NULL; … … 695 695 needprompt = 0; 696 696 } 697 readtoken1(pgetc( ), here->here->type == NHERE? SQSYNTAX : DQSYNTAX,697 readtoken1(pgetc(psh), here->here->type == NHERE? SQSYNTAX : DQSYNTAX, 698 698 here->eofmark, here->striptabs); 699 699 n = (union node *)stalloc(psh, sizeof (struct narg)); … … 759 759 if(!noalias && 760 760 (ap = lookupalias(psh, wordtext, 1)) != NULL) { 761 pushstring( ap->val, strlen(ap->val), ap);761 pushstring(psh, ap->val, strlen(ap->val), ap); 762 762 checkkwd = savecheckkwd; 763 763 goto top; … … 812 812 startlinno = plinno; 813 813 for (;;) { /* until token or start of word found */ 814 c = pgetc_macro( );814 c = pgetc_macro(psh); 815 815 if (c == ' ' || c == '\t') 816 816 continue; /* quick check for white space first */ … … 819 819 continue; 820 820 case '#': 821 while ((c = pgetc( )) != '\n' && c != PEOF);822 pungetc( );821 while ((c = pgetc(psh)) != '\n' && c != PEOF); 822 pungetc(psh); 823 823 continue; 824 824 case '\\': 825 if (pgetc( ) == '\n') {825 if (pgetc(psh) == '\n') { 826 826 startlinno = ++plinno; 827 827 if (doprompt) … … 831 831 continue; 832 832 } 833 pungetc( );833 pungetc(psh); 834 834 goto breakloop; 835 835 case '\n': … … 840 840 RETURN(TEOF); 841 841 case '&': 842 if (pgetc( ) == '&')842 if (pgetc(psh) == '&') 843 843 RETURN(TAND); 844 pungetc( );844 pungetc(psh); 845 845 RETURN(TBACKGND); 846 846 case '|': 847 if (pgetc( ) == '|')847 if (pgetc(psh) == '|') 848 848 RETURN(TOR); 849 pungetc( );849 pungetc(psh); 850 850 RETURN(TPIPE); 851 851 case ';': 852 if (pgetc( ) == ';')852 if (pgetc(psh) == ';') 853 853 RETURN(TENDCASE); 854 pungetc( );854 pungetc(psh); 855 855 RETURN(TSEMI); 856 856 case '(': … … 961 961 if (syntax == BASESYNTAX) 962 962 return readtoken(); 963 c = pgetc( );963 c = pgetc(psh); 964 964 goto loop; 965 965 } … … 978 978 else 979 979 setprompt(0); 980 c = pgetc( );980 c = pgetc(psh); 981 981 goto loop; /* continue outer loop */ 982 982 case CWORD: … … 989 989 break; 990 990 case CBACK: /* backslash */ 991 c = pgetc( );991 c = pgetc(psh); 992 992 if (c == PEOF) { 993 993 USTPUTC(psh, '\\', out); 994 pungetc( );994 pungetc(psh); 995 995 break; 996 996 } … … 1093 1093 --parenlevel; 1094 1094 } else { 1095 if (pgetc( ) == ')') {1095 if (pgetc(psh) == ')') { 1096 1096 if (--arinest == 0) { 1097 1097 USTPUTC(psh, CTLENDARI, out); … … 1108 1108 * (don't 2nd guess - no error) 1109 1109 */ 1110 pungetc( );1110 pungetc(psh); 1111 1111 USTPUTC(psh, ')', out); 1112 1112 } … … 1123 1123 USTPUTC(psh, c, out); 1124 1124 } 1125 c = pgetc_macro( );1125 c = pgetc_macro(psh); 1126 1126 } 1127 1127 } … … 1147 1147 return lasttoken = TREDIR; 1148 1148 } else { 1149 pungetc( );1149 pungetc(psh); 1150 1150 } 1151 1151 } … … 1171 1171 if (striptabs) { 1172 1172 while (c == '\t') 1173 c = pgetc( );1173 c = pgetc(psh); 1174 1174 } 1175 1175 if (c == *eofmark) { 1176 if (pfgets( line, sizeof line) != NULL) {1176 if (pfgets(psh, line, sizeof line) != NULL) { 1177 1177 char *p, *q; 1178 1178 … … 1184 1184 needprompt = doprompt; 1185 1185 } else { 1186 pushstring( line, strlen(line), NULL);1186 pushstring(psh, line, strlen(line), NULL); 1187 1187 } 1188 1188 } … … 1206 1206 if (c == '>') { 1207 1207 np->nfile.fd = 1; 1208 c = pgetc( );1208 c = pgetc(psh); 1209 1209 if (c == '>') 1210 1210 np->type = NAPPEND; … … 1215 1215 else { 1216 1216 np->type = NTO; 1217 pungetc( );1217 pungetc(psh); 1218 1218 } 1219 1219 } else { /* c == '<' */ 1220 1220 np->nfile.fd = 0; 1221 switch (c = pgetc( )) {1221 switch (c = pgetc(psh)) { 1222 1222 case '<': 1223 1223 if (sizeof (struct nfile) != sizeof (struct nhere)) { … … 1228 1228 heredoc = (struct heredoc *)stalloc(psh, sizeof (struct heredoc)); 1229 1229 heredoc->here = np; 1230 if ((c = pgetc( )) == '-') {1230 if ((c = pgetc(psh)) == '-') { 1231 1231 heredoc->striptabs = 1; 1232 1232 } else { 1233 1233 heredoc->striptabs = 0; 1234 pungetc( );1234 pungetc(psh); 1235 1235 } 1236 1236 break; … … 1246 1246 default: 1247 1247 np->type = NFROM; 1248 pungetc( );1248 pungetc(psh); 1249 1249 break; 1250 1250 } … … 1269 1269 static const char types[] = "}-+?="; 1270 1270 1271 c = pgetc( );1271 c = pgetc(psh); 1272 1272 if (c != '(' && c != OPENBRACE && !is_name(c) && !is_special(c)) { 1273 1273 USTPUTC(psh, '$', out); 1274 pungetc( );1274 pungetc(psh); 1275 1275 } else if (c == '(') { /* $(command) or $((arith)) */ 1276 if (pgetc( ) == '(') {1276 if (pgetc(psh) == '(') { 1277 1277 PARSEARITH(); 1278 1278 } else { 1279 pungetc( );1279 pungetc(psh); 1280 1280 PARSEBACKQNEW(); 1281 1281 } … … 1286 1286 subtype = VSNORMAL; 1287 1287 if (c == OPENBRACE) { 1288 c = pgetc( );1288 c = pgetc(psh); 1289 1289 if (c == '#') { 1290 if ((c = pgetc( )) == CLOSEBRACE)1290 if ((c = pgetc(psh)) == CLOSEBRACE) 1291 1291 c = '#'; 1292 1292 else … … 1299 1299 do { 1300 1300 STPUTC(psh, c, out); 1301 c = pgetc( );1301 c = pgetc(psh); 1302 1302 } while (is_in_name(c)); 1303 1303 } else if (is_digit(c)) { 1304 1304 do { 1305 1305 USTPUTC(psh, c, out); 1306 c = pgetc( );1306 c = pgetc(psh); 1307 1307 } while (is_digit(c)); 1308 1308 } 1309 1309 else if (is_special(c)) { 1310 1310 USTPUTC(psh, c, out); 1311 c = pgetc( );1311 c = pgetc(psh); 1312 1312 } 1313 1313 else … … 1320 1320 case ':': 1321 1321 flags = VSNUL; 1322 c = pgetc( );1322 c = pgetc(psh); 1323 1323 /*FALLTHROUGH*/ 1324 1324 default: … … 1334 1334 subtype = c == '#' ? VSTRIMLEFT : 1335 1335 VSTRIMRIGHT; 1336 c = pgetc( );1336 c = pgetc(psh); 1337 1337 if (c == cc) 1338 1338 subtype++; 1339 1339 else 1340 pungetc( );1340 pungetc(psh); 1341 1341 break; 1342 1342 } 1343 1343 } 1344 1344 } else { 1345 pungetc( );1345 pungetc(psh); 1346 1346 } 1347 1347 if (ISDBLQUOTE() || arinest) … … 1415 1415 needprompt = 0; 1416 1416 } 1417 switch (pc = pgetc( )) {1417 switch (pc = pgetc(psh)) { 1418 1418 case '`': 1419 1419 goto done; 1420 1420 1421 1421 case '\\': 1422 if ((pc = pgetc( )) == '\n') {1422 if ((pc = pgetc(psh)) == '\n') { 1423 1423 plinno++; 1424 1424 if (doprompt) … … 1459 1459 if (psavelen > 0) { 1460 1460 pstr = grabstackstr(psh, pout); 1461 setinputstring(ps tr, 1);1461 setinputstring(psh, pstr, 1); 1462 1462 } 1463 1463 } … … 1489 1489 * tokens left from the backquote parsing 1490 1490 */ 1491 popfile( );1491 popfile(psh); 1492 1492 tokpushback = 0; 1493 1493 } … … 1629 1629 setprompt(int which) 1630 1630 { 1631 whichprompt = which;1631 psh->whichprompt = which; 1632 1632 1633 1633 #ifndef SMALL … … 1644 1644 getprompt(void *unused) 1645 1645 { 1646 switch ( whichprompt) {1646 switch (psh->whichprompt) { 1647 1647 case 0: 1648 1648 return ""; -
trunk/src/kash/redir.c
r1199 r1201 167 167 } 168 168 if (memory[1]) 169 out1 = &memout;169 psh->out1 = &psh->memout; 170 170 if (memory[2]) 171 out2 = &memout;171 psh->out2 = &psh->memout; 172 172 } 173 173 … … 283 283 xwrite(psh, pip[1], redir->nhere.doc->narg.text, len); 284 284 else 285 expandhere( redir->nhere.doc, pip[1]);285 expandhere(psh, redir->nhere.doc, pip[1]); 286 286 _exit(0); 287 287 } -
trunk/src/kash/shinstance.c
r1199 r1201 52 52 psh->stacknxt = psh->stackbase.space; 53 53 54 /* input.c */ 55 psh->plinno = 1; 56 psh->init_editline = 0; 57 psh->parsefile = &psh->basepf; 58 54 59 /* output.c */ 55 60 psh->output.bufsize = OUTBUFSIZ; … … 61 66 psh->out2 = &psh->errout; 62 67 63 /* .c */64 68 } 65 69 return psh; -
trunk/src/kash/shinstance.h
r1199 r1201 27 27 #ifndef ___shinstance_h___ 28 28 #define ___shinstance_h___ 29 30 #include <stdio.h> /* BUFSIZ */ 29 31 30 32 #include "shtypes.h" … … 36 38 #include "var.h" 37 39 40 /* memalloc.c */ 38 41 #define MINSIZE 504 /* minimum size of a block */ 39 42 struct stack_block { … … 41 44 char space[MINSIZE]; 42 45 }; 46 47 /* input.c */ 48 struct strpush { 49 struct strpush *prev; /* preceding string on stack */ 50 char *prevstring; 51 int prevnleft; 52 int prevlleft; 53 struct alias *ap; /* if push was associated with an alias */ 54 }; 55 56 /* 57 * The parsefile structure pointed to by the global variable parsefile 58 * contains information about the current file being read. 59 */ 60 struct parsefile { 61 struct parsefile *prev; /* preceding file on stack */ 62 int linno; /* current line */ 63 int fd; /* file descriptor (or -1 if string) */ 64 int nleft; /* number of chars left in this line */ 65 int lleft; /* number of chars left in this buffer */ 66 char *nextc; /* next char in buffer */ 67 char *buf; /* input buffer */ 68 struct strpush *strpush; /* for pushing strings at this level */ 69 struct strpush basestrpush; /* so pushing one is fast */ 70 }; 71 43 72 44 73 … … 136 165 struct stackmark *markp; 137 166 138 139 167 /* jobs.h */ 140 168 pid_t backgndpid; /**< pid of last background process */ … … 142 170 143 171 /* input.h */ 144 int plinno ;172 int plinno/* = 1 */;/**< input line number */ 145 173 int parsenleft; /**< number of characters left in input buffer */ 146 174 char *parsenextc; /**< next character in input buffer */ 147 int init_editline; /**< 0 == not setup, 1 == OK, -1 == failed */ 175 int init_editline/* = 0 */; /**< 0 == not setup, 1 == OK, -1 == failed */ 176 177 /* input.c */ 178 int parselleft; /**< copy of parsefile->lleft */ 179 struct parsefile basepf; /**< top level input file */ 180 char basebuf[BUFSIZ];/**< buffer for top level input file */ 181 struct parsefile *parsefile/* = &basepf*/; /**< current input file */ 182 #ifndef SMALL 183 EditLine *el; /**< cookie for editline package */ 184 #endif 185 148 186 149 187 /* exec.h */
Note:
See TracChangeset
for help on using the changeset viewer.