shithub: rgbds

Download patch

ref: 5acc48fa54ccab78495044b169ce4f5ac7e523f7
parent: 1487eebe7953eae9788ea0735da94b2af6a95f12
author: ISSOtm <[email protected]>
date: Fri Jan 22 04:44:41 EST 2021

Error out when given several input files

Also rename tzMainFile

--- a/src/asm/main.c
+++ b/src/asm/main.c
@@ -255,7 +255,7 @@
 	fputs(
 "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"
-"              [-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"
 "    -E, --export-all         export all labels\n"
 "    -M, --dependfile <path>  set the output dependency file\n"
@@ -276,8 +276,6 @@
 
 	struct sOptions newopt;
 
-	char *tzMainfile;
-
 	time_t now = time(NULL);
 	char *sourceDateEpoch = getenv("SOURCE_DATE_EPOCH");
 
@@ -451,8 +449,6 @@
 			/* NOTREACHED */
 		}
 	}
-	argc -= optind;
-	argv += optind;
 
 	if (tzTargetFileName == NULL)
 		tzTargetFileName = tzObjectname;
@@ -461,26 +457,29 @@
 
 	DefaultOptions = CurrentOptions;
 
-	if (argc == 0) {
-		fputs("FATAL: no input files\n", stderr);
+	if (argc == optind) {
+		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();
 	}
 
-	tzMainfile = argv[argc - 1];
+	char const *mainFileName = argv[optind];
 
 	if (verbose)
-		printf("Assembling %s\n", tzMainfile);
+		printf("Assembling %s\n", mainFileName);
 
 	if (dependfile) {
 		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 */
 	lexer_Init();
-	fstk_Init(tzMainfile, maxRecursionDepth);
+	fstk_Init(mainFileName, maxRecursionDepth);
 
 	sym_Init(now);
 	sym_SetExportAll(exportall);