Changeset 880
- Timestamp:
- Apr 21, 2007, 9:47:39 AM (18 years ago)
- Location:
- trunk/src/ash-messup
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/ash-messup/bltin/bltin.h
r626 r880 84 84 #endif 85 85 86 pointer stalloc( int);87 void error( const char *, ...);88 void sh_warnx( const char *, ...);89 void sh_exit( int) __attribute__((__noreturn__));86 pointer stalloc(struct shinstance *, int); 87 void error(struct shinstance *, const char *, ...); 88 void sh_warnx(struct shinstance *, const char *, ...); 89 void sh_exit(struct shinstance *, int) __attribute__((__noreturn__)); 90 90 91 int echocmd( int, char **);91 int echocmd(struct shinstance *, int, char **); 92 92 93 93 94 extern const char *commandname; 94 /*extern const char *commandname;*/ -
trunk/src/ash-messup/main.c
r879 r880 81 81 #define PROFILE 0 82 82 83 int rootpid;84 int rootshell; 83 /*int rootpid; 84 int rootshell;*/ 85 85 STATIC union node *curcmd; 86 86 STATIC union node *prevcmd; … … 89 89 STATIC char *find_dot_file(char *); 90 90 int main(int, char **); 91 int shell_main(shinstance *, int, char **); 92 #ifdef _MSC_VER 93 extern void init_syntax(void); 94 #endif 91 95 92 96 /* … … 103 107 shinstance *psh; 104 108 109 /* 110 * Global initializations. 111 */ 105 112 setlocale(LC_ALL, ""); 106 113 #ifdef _MSC_VER 114 init_syntax(); 115 #endif 107 116 /* 108 117 * Create the root shell instance. … … 111 120 if (!psh) 112 121 return 2; 122 shthread_set_shell(psh); 113 123 return shell_main(psh, argc); 114 124 } … … 129 139 * the shell procedure. 130 140 */ 131 switch ( exception) {141 switch (psh->exception) { 132 142 case EXSHELLPROC: 133 rootpid = getpid();134 rootshell = 1;135 minusc = NULL;136 state = 3;143 psh->rootpid = /*getpid()*/ psh->pid; 144 psh->rootshell = 1; 145 psh->minusc = NULL; 146 psh->state = 3; 137 147 break; 138 148 139 149 case EXEXEC: 140 exitstatus =exerrno;150 psh->exitstatus = psh->exerrno; 141 151 break; 142 152 143 153 case EXERROR: 144 exitstatus = 2;154 psh->exitstatus = 2; 145 155 break; 146 156 … … 149 159 } 150 160 151 if ( exception != EXSHELLPROC) {152 if (state == 0 || iflag == 0 || ! rootshell)153 exitshell( exitstatus);154 } 155 reset( );156 if ( exception == EXINT161 if (psh->exception != EXSHELLPROC) { 162 if (state == 0 || iflag == 0 || ! psh->rootshell) 163 exitshell(psh, exitstatus); 164 } 165 reset(psh); 166 if (psh->exception == EXINT 157 167 #if ATTY 158 && (! attyset( ) || equal(termval(), "emacs"))168 && (! attyset(psh) || equal(termval(psh), "emacs")) 159 169 #endif 160 170 ) { 161 out2c( '\n');171 out2c(psh, '\n'); 162 172 flushout(&errout); 163 173 } 164 popstackmark( &smark);174 popstackmark(psh, &smark); 165 175 FORCEINTON; /* enable interrupts */ 166 176 if (state == 1) … … 174 184 } 175 185 psh->handler = &jmploc; 186 psh->rootpid = /*getpid()*/ psh->pid; 187 psh->rootshell = 1; 176 188 #ifdef DEBUG 177 189 #if DEBUG == 2 178 190 debug = 1; 179 191 #endif 180 opentrace( );192 opentrace(psh); 181 193 trputs("Shell args: "); trargs(argv); 182 194 #endif 183 psh->rootpid = getpid(); 184 psh->rootshell = 1; 185 #ifdef _MSC_VER 186 { 187 extern void init_syntax(void); 188 init_syntax(); 189 } 190 #endif 191 init(); 192 setstackmark(&smark); 193 procargs(argc, argv); 195 196 init(psh); 197 setstackmark(psh, &smark); 198 procargs(psh, argc, argv); 194 199 if (argv[0] && argv[0][0] == '-') { 195 200 state = 1; … … 209 214 state3: 210 215 state = 4; 211 if ( sflag == 0 ||minusc) {216 if (psh->sflag == 0 || psh->minusc) { 212 217 static int sigs[] = { 213 218 SIGINT, SIGQUIT, SIGHUP, … … 242 247 243 248 void 244 cmdloop( int top)249 cmdloop(struct shinstance *psh, int top) 245 250 { 246 251 union node *n; … … 250 255 251 256 TRACE(("cmdloop(%d) called\n", top)); 252 setstackmark( &smark);257 setstackmark(psh, &smark); 253 258 for (;;) { 254 if (p endingsigs)255 dotrap( );259 if (psh->pendingsigs) 260 dotrap(psh); 256 261 inter = 0; 257 if ( iflag && top) {262 if (psh->iflag && top) { 258 263 inter = 1; 259 showjobs( out2, SHOW_CHANGED);260 chkmail( 0);261 flushout(& errout);262 } 263 n = parsecmd( inter);264 showjobs(psh, psh->out2, SHOW_CHANGED); 265 chkmail(psh, 0); 266 flushout(&psh->errout); 267 } 268 n = parsecmd(psh, inter); 264 269 /* showtree(n); DEBUG */ 265 270 if (n == NEOF) { 266 271 if (!top || numeof >= 50) 267 272 break; 268 if (!stoppedjobs( )) {269 if (! Iflag)273 if (!stoppedjobs(psh)) { 274 if (!psh->Iflag) 270 275 break; 271 out2str( "\nUse \"exit\" to leave shell.\n");276 out2str(psh, "\nUse \"exit\" to leave shell.\n"); 272 277 } 273 278 numeof++; 274 } else if (n != NULL && nflag == 0) {275 job_warning = (job_warning == 2) ? 1 : 0;279 } else if (n != NULL && psh->nflag == 0) { 280 psh->job_warning = (psh->job_warning == 2) ? 1 : 0; 276 281 numeof = 0; 277 evaltree( n, 0);278 } 279 popstackmark( &smark);280 setstackmark( &smark);281 if ( evalskip == SKIPFILE) {282 evalskip = 0;282 evaltree(psh, n, 0); 283 } 284 popstackmark(psh, &smark); 285 setstackmark(psh, &smark); 286 if (psh->evalskip == SKIPFILE) { 287 psh->evalskip = 0; 283 288 break; 284 289 } 285 290 } 286 popstackmark( &smark);291 popstackmark(psh, &smark); 287 292 } 288 293 … … 294 299 295 300 STATIC void 296 read_profile( const char *name)301 read_profile(struct shinstance *psh, const char *name) 297 302 { 298 303 int fd; … … 301 306 302 307 INTOFF; 303 if ((fd = open(name, O_RDONLY)) >= 0)304 setinputfd( fd, 1);308 if ((fd = shfile_open(psh, name, O_RDONLY)) >= 0) 309 setinputfd(psh, fd, 1); 305 310 INTON; 306 311 if (fd < 0) 307 312 return; 308 313 /* -q turns off -x and -v just when executing init files */ 309 if ( qflag) {310 if ( xflag)311 xflag = 0, xflag_set = 1;312 if ( vflag)313 vflag = 0, vflag_set = 1;314 } 315 cmdloop( 0);316 if ( qflag) {314 if (psh->qflag) { 315 if (psh->xflag) 316 psh->xflag = 0, xflag_set = 1; 317 if (psh->vflag) 318 psh->vflag = 0, vflag_set = 1; 319 } 320 cmdloop(psh, 0); 321 if (psh->qflag) { 317 322 if (xflag_set) 318 xflag = 1;323 psh->xflag = 1; 319 324 if (vflag_set) 320 vflag = 1;321 } 322 popfile( );325 psh->vflag = 1; 326 } 327 popfile(psh); 323 328 } 324 329 … … 330 335 331 336 void 332 readcmdfile( char *name)337 readcmdfile(struct shinstance *psh, char *name) 333 338 { 334 339 int fd; … … 336 341 INTOFF; 337 342 if ((fd = open(name, O_RDONLY)) >= 0) 338 setinputfd( fd, 1);343 setinputfd(psh, fd, 1); 339 344 else 340 345 error("Can't open %s", name); 341 346 INTON; 342 cmdloop( 0);343 popfile( );347 cmdloop(psh, 0); 348 popfile(psh); 344 349 } 345 350 … … 353 358 354 359 STATIC char * 355 find_dot_file( char *basename)360 find_dot_file(struct shinstance *psh, char *basename) 356 361 { 357 362 char *fullname; 358 const char *path = pathval( );363 const char *path = pathval(psh); 359 364 struct stat statb; 360 365 … … 363 368 return basename; 364 369 365 while ((fullname = padvance( &path, basename)) != NULL) {370 while ((fullname = padvance(psh, &path, basename)) != NULL) { 366 371 if ((stat(fullname, &statb) == 0) && S_ISREG(statb.st_mode)) { 367 372 /* … … 371 376 return fullname; 372 377 } 373 stunalloc( fullname);378 stunalloc(psh, fullname); 374 379 } 375 380 … … 380 385 381 386 int 382 dotcmd( int argc, char **argv)383 { 384 exitstatus = 0;387 dotcmd(struct shinstance *psh, int argc, char **argv) 388 { 389 psh->exitstatus = 0; 385 390 386 391 if (argc >= 2) { /* That's what SVR2 does */ … … 388 393 struct stackmark smark; 389 394 390 setstackmark( &smark);391 fullname = find_dot_file( argv[1]);392 setinputfile( fullname, 1);393 commandname = fullname;394 cmdloop( 0);395 popfile( );396 popstackmark( &smark);397 } 398 return exitstatus;395 setstackmark(psh, &smark); 396 fullname = find_dot_file(psh, argv[1]); 397 setinputfile(psh, fullname, 1); 398 psh->commandname = fullname; 399 cmdloop(psh, 0); 400 popfile(psh); 401 popstackmark(psh, &smark); 402 } 403 return psh->exitstatus; 399 404 } 400 405 401 406 402 407 int 403 exitcmd( int argc, char **argv)404 { 405 if (stoppedjobs( ))408 exitcmd(struct shinstance *psh, int argc, char **argv) 409 { 410 if (stoppedjobs(psh)) 406 411 return 0; 407 412 if (argc > 1) 408 exitstatus = number(argv[1]);409 exitshell( exitstatus);413 psh->exitstatus = number(argv[1]); 414 exitshell(psh, exitstatus); 410 415 /* NOTREACHED */ 411 416 } 417 418 /* 419 * Local Variables: 420 * c-file-style: bsd 421 * End: 422 */ -
trunk/src/ash-messup/options.h
r879 r880 69 69 70 70 DEF_OPT( "errexit", 'e' ) /* exit on error */ 71 #define eflag psh->optlist[0].val71 #define eflag optlist[0].val 72 72 DEF_OPT( "noglob", 'f' ) /* no pathname expansion */ 73 #define fflag psh->optlist[1].val73 #define fflag optlist[1].val 74 74 DEF_OPT( "ignoreeof", 'I' ) /* do not exit on EOF */ 75 #define Iflag psh->optlist[2].val75 #define Iflag optlist[2].val 76 76 DEF_OPT( "interactive",'i' ) /* interactive shell */ 77 #define iflag psh->optlist[3].val77 #define iflag optlist[3].val 78 78 DEF_OPT( "monitor", 'm' ) /* job control */ 79 #define mflag psh->optlist[4].val79 #define mflag optlist[4].val 80 80 DEF_OPT( "noexec", 'n' ) /* [U] do not exec commands */ 81 #define nflag psh->optlist[5].val81 #define nflag optlist[5].val 82 82 DEF_OPT( "stdin", 's' ) /* read from stdin */ 83 #define sflag psh->optlist[6].val83 #define sflag optlist[6].val 84 84 DEF_OPT( "xtrace", 'x' ) /* trace after expansion */ 85 #define xflag psh->optlist[7].val85 #define xflag optlist[7].val 86 86 DEF_OPT( "verbose", 'v' ) /* trace read input */ 87 #define vflag psh->optlist[8].val87 #define vflag optlist[8].val 88 88 DEF_OPTS( "vi", 'V', 'V' ) /* vi style editing */ 89 #define Vflag psh->optlist[9].val89 #define Vflag optlist[9].val 90 90 DEF_OPTS( "emacs", 'E', 'V' ) /* emacs style editing */ 91 #define Eflag psh->optlist[10].val91 #define Eflag optlist[10].val 92 92 DEF_OPT( "noclobber", 'C' ) /* do not overwrite files with > */ 93 #define Cflag psh->optlist[11].val93 #define Cflag optlist[11].val 94 94 DEF_OPT( "allexport", 'a' ) /* export all variables */ 95 #define aflag psh->optlist[12].val95 #define aflag optlist[12].val 96 96 DEF_OPT( "notify", 'b' ) /* [U] report completion of background jobs */ 97 #define bflag psh->optlist[13].val97 #define bflag optlist[13].val 98 98 DEF_OPT( "nounset", 'u' ) /* error expansion of unset variables */ 99 #define uflag psh->optlist[14].val99 #define uflag optlist[14].val 100 100 DEF_OPT( "quietprofile", 'q' ) 101 #define qflag psh->optlist[15].val101 #define qflag optlist[15].val 102 102 DEF_OPT( "nolog", 0 ) /* [U] no functon defs in command history */ 103 #define nolog psh->optlist[16].val103 #define nolog optlist[16].val 104 104 DEF_OPT( "cdprint", 0 ) /* always print result of cd */ 105 #define cdprint psh->optlist[17].val105 #define cdprint optlist[17].val 106 106 DEF_OPT( "tabcomplete", 0 ) /* <tab> causes filename expansion */ 107 #define tabcomplete psh->optlist[18].val107 #define tabcomplete optlist[18].val 108 108 #ifdef DEBUG 109 109 DEF_OPT( "debug", 0 ) /* enable debug prints */ 110 #define debug psh->optlist[19].val110 #define debug optlist[19].val 111 111 #endif 112 112 -
trunk/src/ash-messup/output.h
r879 r880 75 75 int xioctl(int, unsigned long, char *); 76 76 77 #define outc(c, file) (--(file)->nleft < 0? (emptyoutbuf( psh,file), *(file)->nextc++ = (c)) : (*(file)->nextc++ = (c)))78 #define out1c( c) outc(c, psh->out1);79 #define out2c( c) outc(c, psh->out2);77 #define outc(c, file) (--(file)->nleft < 0? (emptyoutbuf(file), *(file)->nextc++ = (c)) : (*(file)->nextc++ = (c))) 78 #define out1c(psh, c) outc(c, (psh)->out1); 79 #define out2c(psh, c) outc(c, (psh)->out2); 80 80 81 81 #define OUTPUT_INCL -
trunk/src/ash-messup/shinstance.h
r879 r880 153 153 int funcnest; 154 154 int evalskip; 155 156 /* builtins.h */ 157 const char *commandname; 158 155 159 } shinstance; 156 160 -
trunk/src/ash-messup/show.h
r879 r880 42 42 void trputc(int); 43 43 void trputs(const char *); 44 void opentrace( void);44 void opentrace(struct shinstance *); 45 45 #endif -
trunk/src/ash-messup/var.h
r879 r880 100 100 */ 101 101 102 #define ifsval( ) (psh->vifs.text + 4)103 #define ifsset( ) ((psh->vifs.flags & VUNSET) == 0)104 #define mailval( ) (psh->vmail.text + 5)105 #define mpathval( ) (psh->vmpath.text + 9)102 #define ifsval(psh) ((psh)->vifs.text + 4) 103 #define ifsset(psh) (((psh)->vifs.flags & VUNSET) == 0) 104 #define mailval(psh) ((psh)->vmail.text + 5) 105 #define mpathval(psh) ((psh)->vmpath.text + 9) 106 106 #ifdef _MSC_VER 107 #define pathval( ) (psh->vpath.text[5] ? &psh->vpath.text[5] : &psh->vpath2.text[5])107 #define pathval(psh) ((psh)->vpath.text[5] ? &(psh)->vpath.text[5] : &(psh)->vpath2.text[5]) 108 108 #else 109 #define pathval( ) (psh->vpath.text + 5)109 #define pathval(psh) ((psh)->vpath.text + 5) 110 110 #endif 111 #define ps1val( ) (psh->vps1.text + 4)112 #define ps2val( ) (psh->vps2.text + 4)113 #define ps4val( ) (psh->vps4.text + 4)114 #define optindval( ) (psh->voptind.text + 7)111 #define ps1val(psh) ((psh)->vps1.text + 4) 112 #define ps2val(psh) ((psh)->vps2.text + 4) 113 #define ps4val(psh) ((psh)->vps4.text + 4) 114 #define optindval(psh) ((psh)->voptind.text + 7) 115 115 #ifndef SMALL 116 #define histsizeval( ) (psh->vhistsize.text + 9)117 #define termval( ) (psh->vterm.text + 5)116 #define histsizeval(psh) ((psh)->vhistsize.text + 9) 117 #define termval(psh) ((psh)->vterm.text + 5) 118 118 #endif 119 119 120 120 #if ATTY 121 #define attyset( ) ((psh->vatty.flags & VUNSET) == 0)121 #define attyset(psh) (((psh)->vatty.flags & VUNSET) == 0) 122 122 #endif 123 #define mpathset( ) ((psh->vmpath.flags & VUNSET) == 0)123 #define mpathset(psh) (((psh)->vmpath.flags & VUNSET) == 0) 124 124 125 125 void initvar(struct shinstance *);
Note:
See TracChangeset
for help on using the changeset viewer.