- i = 1;
- while (i < argc and (not foundfile or corefile == nil)) {
- if (argv[i][0] == '-') {
- if (streq(argv[i], "-I")) {
- ++i;
- if (i >= argc) {
- fatal("missing directory for -I");
- }
- list_append(list_item(argv[i]), nil, sourcepath);
- } else {
- for (j = 1; argv[i][j] != '\0'; j++) {
- setoption(argv[i][j]);
- }
- }
- } else if (not foundfile) {
- objname = argv[i];
- foundfile = true;
- } else if (coredump and corefile == nil) {
- corefile = fopen(argv[i], "r");
- if (corefile == nil) {
+
+ while ((ch = getopt(argc, argv, "I:bc:eiklnrs")) != EOF)
+ switch((char)ch) {
+ case 'I':
+ list_append(list_item(optarg), nil, sourcepath);
+ break;
+ case 'b':
+ tracebpts = true;
+ break;
+ case 'c':
+ initfile = optarg;
+ break;
+ case 'e':
+ traceexec = true;
+ break;
+ case 'i':
+ interactive = true;
+ break;
+ case 'k':
+ vaddrs = true;
+ break;
+ case 'l':
+#ifdef LEXDEBUG
+ lexdebug = true;
+#else
+ fatal("\"-l\" only applicable when compiled with LEXDEBUG");
+#endif
+ break;
+ case 'n':
+ traceblocks = true;
+ break;
+ case 'r': /* run program before accepting commands */
+ runfirst = true;