Error out when given several input files

Also rename tzMainFile
This commit is contained in:
ISSOtm
2021-01-22 09:44:41 +01:00
parent 1487eebe79
commit 5acc48fa54

View File

@@ -255,7 +255,7 @@ static void print_usage(void)
fputs( fputs(
"Usage: rgbasm [-EhLVvw] [-b chars] [-D name[=value]] [-g chars] [-i path]\n" "Usage: rgbasm [-EhLVvw] [-b chars] [-D name[=value]] [-g chars] [-i path]\n"
" [-M depend_file] [-MG] [-MP] [-MT target_file] [-MQ target_file]\n" " [-M depend_file] [-MG] [-MP] [-MT target_file] [-MQ target_file]\n"
" [-o out_file] [-p pad_value] [-r depth] [-W warning] <file> ...\n" " [-o out_file] [-p pad_value] [-r depth] [-W warning] <file>\n"
"Useful options:\n" "Useful options:\n"
" -E, --export-all export all labels\n" " -E, --export-all export all labels\n"
" -M, --dependfile <path> set the output dependency file\n" " -M, --dependfile <path> set the output dependency file\n"
@@ -276,8 +276,6 @@ int main(int argc, char *argv[])
struct sOptions newopt; struct sOptions newopt;
char *tzMainfile;
time_t now = time(NULL); time_t now = time(NULL);
char *sourceDateEpoch = getenv("SOURCE_DATE_EPOCH"); char *sourceDateEpoch = getenv("SOURCE_DATE_EPOCH");
@@ -451,8 +449,6 @@ int main(int argc, char *argv[])
/* NOTREACHED */ /* NOTREACHED */
} }
} }
argc -= optind;
argv += optind;
if (tzTargetFileName == NULL) if (tzTargetFileName == NULL)
tzTargetFileName = tzObjectname; tzTargetFileName = tzObjectname;
@@ -461,26 +457,29 @@ int main(int argc, char *argv[])
DefaultOptions = CurrentOptions; DefaultOptions = CurrentOptions;
if (argc == 0) { if (argc == optind) {
fputs("FATAL: no input files\n", stderr); fputs("FATAL: No input files\n", stderr);
print_usage();
} else if (argc != optind + 1) {
fputs("FATAL: More than one input file given\n", stderr);
print_usage(); print_usage();
} }
tzMainfile = argv[argc - 1]; char const *mainFileName = argv[optind];
if (verbose) if (verbose)
printf("Assembling %s\n", tzMainfile); printf("Assembling %s\n", mainFileName);
if (dependfile) { if (dependfile) {
if (!tzTargetFileName) if (!tzTargetFileName)
errx(1, "Dependency files can only be created if a target file is specified with either -o, -MQ or -MT.\n"); errx(1, "Dependency files can only be created if a target file is specified with either -o, -MQ or -MT\n");
fprintf(dependfile, "%s: %s\n", tzTargetFileName, tzMainfile); fprintf(dependfile, "%s: %s\n", tzTargetFileName, mainFileName);
} }
/* Init file stack; important to do first, since it provides the file name, line, etc */ /* Init file stack; important to do first, since it provides the file name, line, etc */
lexer_Init(); lexer_Init();
fstk_Init(tzMainfile, maxRecursionDepth); fstk_Init(mainFileName, maxRecursionDepth);
sym_Init(now); sym_Init(now);
sym_SetExportAll(exportall); sym_SetExportAll(exportall);