Changeset 880 for trunk/src/ash-messup/main.c
- Timestamp:
- Apr 21, 2007, 9:47:39 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 */
Note:
See TracChangeset
for help on using the changeset viewer.