fix options in C scripts after -run

This commit is contained in:
grischka 2008-04-27 18:50:35 +00:00
parent 5247bbc2f0
commit f2698687fb

31
tcc.c
View file

@ -10761,15 +10761,8 @@ int parse_args(TCCState *s, int argc, char **argv)
char *r; char *r;
optind = 0; optind = 0;
while (1) { while (optind < argc) {
if (optind >= argc) {
if (nb_files == 0 && !print_search_dirs) {
if (verbose)
exit(0);
goto show_help;
}
break;
}
r = argv[optind++]; r = argv[optind++];
if (r[0] != '-' || r[1] == '\0') { if (r[0] != '-' || r[1] == '\0') {
/* add a new file */ /* add a new file */
@ -10808,15 +10801,14 @@ int parse_args(TCCState *s, int argc, char **argv)
} }
} else { } else {
if (*r1 != '\0') if (*r1 != '\0')
goto show_help; return 0;
optarg = NULL; optarg = NULL;
} }
switch(popt->index) { switch(popt->index) {
case TCC_OPTION_HELP: case TCC_OPTION_HELP:
show_help: return 0;
help();
exit(1);
case TCC_OPTION_I: case TCC_OPTION_I:
if (tcc_add_include_path(s, optarg) < 0) if (tcc_add_include_path(s, optarg) < 0)
error("too many include paths"); error("too many include paths");
@ -10963,7 +10955,7 @@ int parse_args(TCCState *s, int argc, char **argv)
} }
} }
} }
return optind; return optind + 1;
} }
int main(int argc, char **argv) int main(int argc, char **argv)
@ -10989,14 +10981,19 @@ int main(int argc, char **argv)
print_search_dirs = 0; print_search_dirs = 0;
ret = 0; ret = 0;
optind = parse_args(s, argc - 1, argv + 1) + 1; optind = parse_args(s, argc - 1, argv + 1);
if (print_search_dirs) { if (print_search_dirs) {
/* enough for Linux kernel */ /* enough for Linux kernel */
printf("install: %s/\n", tcc_lib_path); printf("install: %s/\n", tcc_lib_path);
return 0; return 0;
} }
if (optind == 0 || nb_files == 0) {
if (optind && verbose)
return 0;
help();
return 1;
}
nb_objfiles = nb_files - nb_libraries; nb_objfiles = nb_files - nb_libraries;
/* if outfile provided without other options, we output an /* if outfile provided without other options, we output an