Changeset 1198 for trunk/src/kash/main.c
- Timestamp:
- Oct 6, 2007, 11:19:19 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kash/main.c
r884 r1198 84 84 /*int rootpid; 85 85 int rootshell;*/ 86 #ifdef unused_variables 86 87 STATIC union node *curcmd; 87 88 STATIC union node *prevcmd; 89 #endif 88 90 89 91 STATIC void read_profile(struct shinstance *, const char *); … … 94 96 extern void init_syntax(void); 95 97 #endif 98 STATIC int usage(const char *argv0); 99 STATIC int version(const char *argv0); 96 100 97 101 /* … … 109 113 110 114 /* 111 * Global initializations. 112 115 * Global initializations. 116 */ 113 117 setlocale(LC_ALL, ""); 114 118 #ifdef _MSC_VER 115 119 init_syntax(); 116 120 #endif 121 122 /* 123 * Check for --version and --help. 124 */ 125 if (argc > 1 && argv[1][0] == '-' && argv[1][1] == '-') { 126 if (!strcmp(argv[1], "--help")) 127 return usage(argv[0]); 128 if (!strcmp(argv[1], "--version")) 129 return version(argv[0]); 130 } 131 117 132 /* 118 133 * Create the root shell instance. … … 123 138 shthread_set_shell(psh); 124 139 return shell_main(psh, argc, argv); 125 } 126 127 int 140 } 141 142 int 128 143 shell_main(shinstance *psh, int argc, char **argv) 129 144 { … … 161 176 162 177 if (psh->exception != EXSHELLPROC) { 163 if (state == 0 || psh->iflag== 0 || ! psh->rootshell)178 if (state == 0 || iflag(psh) == 0 || ! psh->rootshell) 164 179 exitshell(psh, psh->exitstatus); 165 180 } … … 189 204 #ifdef DEBUG 190 205 #if DEBUG == 2 191 debug = 1;206 debug(psh) = 1; 192 207 #endif 193 208 opentrace(psh); … … 215 230 state3: 216 231 state = 4; 217 if ( psh->sflag== 0 || psh->minusc) {232 if (sflag(psh) == 0 || psh->minusc) { 218 233 static int sigs[] = { 219 234 SIGINT, SIGQUIT, SIGHUP, … … 233 248 evalstring(psh, psh->minusc, 0); 234 249 235 if ( psh->sflag|| psh->minusc == NULL) {250 if (sflag(psh) || psh->minusc == NULL) { 236 251 state4: /* XXX ??? - why isn't this before the "if" statement */ 237 252 cmdloop(psh, 1); … … 262 277 dotrap(psh); 263 278 inter = 0; 264 if ( psh->iflag&& top) {279 if (iflag(psh) && top) { 265 280 inter = 1; 266 281 showjobs(psh, psh->out2, SHOW_CHANGED); … … 274 289 break; 275 290 if (!stoppedjobs(psh)) { 276 if (! psh->Iflag)291 if (!Iflag(psh)) 277 292 break; 278 293 out2str(psh, "\nUse \"exit\" to leave shell.\n"); 279 294 } 280 295 numeof++; 281 } else if (n != NULL && psh->nflag== 0) {296 } else if (n != NULL && nflag(psh) == 0) { 282 297 psh->job_warning = (psh->job_warning == 2) ? 1 : 0; 283 298 numeof = 0; … … 314 329 return; 315 330 /* -q turns off -x and -v just when executing init files */ 316 if ( psh->qflag) {317 if ( psh->xflag)318 psh->xflag= 0, xflag_set = 1;319 if ( psh->vflag)320 psh->vflag= 0, vflag_set = 1;331 if (qflag(psh)) { 332 if (xflag(psh)) 333 xflag(psh) = 0, xflag_set = 1; 334 if (vflag(psh)) 335 vflag(psh) = 0, vflag_set = 1; 321 336 } 322 337 cmdloop(psh, 0); 323 if ( psh->qflag) {338 if (qflag(psh)) { 324 339 if (xflag_set) 325 psh->xflag= 1;340 xflag(psh) = 1; 326 341 if (vflag_set) 327 psh->vflag= 1;342 vflag(psh) = 1; 328 343 } 329 344 popfile(psh); … … 414 429 return 0; 415 430 if (argc > 1) 416 psh->exitstatus = number( argv[1]);431 psh->exitstatus = number(psh, argv[1]); 417 432 exitshell(psh, psh->exitstatus); 418 433 /* NOTREACHED */ … … 420 435 } 421 436 437 438 STATIC const char * 439 strip_argv0(const char *argv0, size_t *lenp) 440 { 441 const char *tmp; 442 443 /* skip the path */ 444 for (tmp = strpbrk(argv0, "\\/:"); tmp; tmp = strpbrk(argv0, "\\/:")) 445 argv0 = tmp + 1; 446 447 /* find the end, ignoring extenions */ 448 tmp = strrchr(argv0, '.'); 449 if (!tmp) 450 tmp = strchr(argv0, '\0'); 451 *lenp = tmp - argv0; 452 return argv0; 453 } 454 455 STATIC int 456 usage(const char *argv0) 457 { 458 size_t len; 459 strip_argv0(argv0, &len); 460 461 fprintf(stdout, 462 "usage: %.*s [-aCefnuvxIimqVEb] [+aCefnuvxIimqVEb] [-o option_name]\n" 463 " [+o option_name] [command_file [argument ...]]\n" 464 " or: %.*s -c [-aCefnuvxIimqVEb] [+aCefnuvxIimqVEb] [-o option_name]\n" 465 " [+o option_name] command_string [command_name [argument ...]]\n" 466 " or: %.*s -s [-aCefnuvxIimqVEb] [+aCefnuvxIimqVEb] [-o option_name]\n" 467 " [+o option_name] [argument ...]\n" 468 " or: %.*s --help\n" 469 " or: %.*s --version\n", 470 len, argv0, len, argv0, len, argv0, len, argv0, len, argv0); 471 return 0; 472 } 473 474 STATIC int 475 version(const char *argv0) 476 { 477 size_t len; 478 strip_argv0(argv0, &len); 479 480 fprintf(stdout, 481 "%.*s - kBuild version %d.%d.%d\n", 482 len, argv0, 483 KBUILD_VERSION_MAJOR, KBUILD_VERSION_MINOR, KBUILD_VERSION_PATCH); 484 return 0; 485 } 486 487 422 488 /* 423 489 * Local Variables:
Note:
See TracChangeset
for help on using the changeset viewer.