ref: 5ad8a8c95837aa39c151b1f6f98bc60f79ceccf1
parent: 282737450582d791d93022c6ceceee29a97fc190
author: Rangi <35663410+Rangi42@users.noreply.github.com>
date: Sun Sep 25 00:04:30 EDT 2022
Warn when a duplicate CLI argument overrides a previous one (#1053) Fixes #1050
--- a/src/asm/fstack.c
+++ b/src/asm/fstack.c
@@ -19,6 +19,7 @@
#include "asm/main.h"
#include "asm/symbol.h"
#include "asm/warning.h"
+#include "error.h"
#include "platform.h" // S_ISDIR (stat macro)
#define MAXINCPATHS 128
@@ -137,7 +138,11 @@
void fstk_SetPreIncludeFile(char const *path)
{
+ if (preIncludeName)
+ warnx("Overriding pre-included filename %s", preIncludeName);
preIncludeName = path;
+ if (verbose)
+ printf("Pre-included filename %s\n", preIncludeName);
}
static void printDep(char const *path)
--- a/src/asm/main.c
+++ b/src/asm/main.c
@@ -53,11 +53,11 @@
// Unfortunately, macOS still ships 2.3, which is from 2008...
int yyparse(void);
-FILE * dependfile;
-bool generatedMissingIncludes;
-bool failedOnMissingInclude;
-bool generatePhonyDeps;
-char *targetFileName;
+FILE *dependfile = NULL;
+bool generatedMissingIncludes = false;
+bool failedOnMissingInclude = false;
+bool generatePhonyDeps = false;
+char *targetFileName = NULL;
bool haltnop;
bool warnOnHaltNop;
@@ -148,9 +148,6 @@
int main(int argc, char *argv[])
{
- int ch;
- char *ep;
-
time_t now = time(NULL);
char const *sourceDateEpoch = getenv("SOURCE_DATE_EPOCH");
@@ -159,18 +156,11 @@
if (sourceDateEpoch)
now = (time_t)strtoul(sourceDateEpoch, NULL, 0);
- dependfile = NULL;
-
// Perform some init for below
sym_Init(now);
// Set defaults
- generatePhonyDeps = false;
- generatedMissingIncludes = false;
- failedOnMissingInclude = false;
- targetFileName = NULL;
-
opt_B("01");
opt_G("0123");
opt_P(0);
@@ -183,8 +173,11 @@
warnings = true;
sym_SetExportAll(false);
uint32_t maxDepth = DEFAULT_MAX_DEPTH;
+ char *dependFileName = NULL;
size_t targetFileNameLen = 0;
+ int ch;
+ char *ep;
while ((ch = musl_getopt_long_only(argc, argv, optstring, longopts, NULL)) != -1) {
switch (ch) {
case 'b':
@@ -243,12 +236,17 @@
break;
case 'M':
- if (!strcmp("-", musl_optarg))
+ if (dependfile)
+ warnx("Overriding dependfile %s", dependFileName);
+ if (!strcmp("-", musl_optarg)) {
dependfile = stdout;
- else
+ dependFileName = "<stdout>";
+ } else {
dependfile = fopen(musl_optarg, "w");
+ dependFileName = musl_optarg;
+ }
if (dependfile == NULL)
- err("Could not open dependfile %s", musl_optarg);
+ err("Could not open dependfile %s", dependFileName);
break;
case 'o':
--- a/src/asm/output.c
+++ b/src/asm/output.c
@@ -540,7 +540,9 @@
// Set the objectfilename
void out_SetFileName(char *s)
{
+ if (objectName)
+ warnx("Overriding output filename %s", objectName);
objectName = s;
if (verbose)
- printf("Output filename %s\n", s);
+ printf("Output filename %s\n", objectName);
}
--- a/src/gfx/main.cpp
+++ b/src/gfx/main.cpp
@@ -337,6 +337,8 @@
break;
case 'a':
autoAttrmap = false;
+ if (!options.attrmap.empty())
+ warning("Overriding attrmap file %s", options.attrmap.c_str());
options.attrmap = musl_optarg;
break;
case 'b':
@@ -479,6 +481,8 @@
}
break;
case 'o':
+ if (!options.output.empty())
+ warning("Overriding tile data file %s", options.output.c_str());
options.output = musl_optarg;
break;
case 'P':
@@ -486,6 +490,8 @@
break;
case 'p':
autoPalettes = false;
+ if (!options.palettes.empty())
+ warning("Overriding palettes file %s", options.palettes.c_str());
options.palettes = musl_optarg;
break;
case 'Q':
@@ -493,6 +499,8 @@
break;
case 'q':
autoPalmap = false;
+ if (!options.palmap.empty())
+ warning("Overriding palette map file %s", options.palmap.c_str());
options.palmap = musl_optarg;
break;
case 'r':
@@ -520,6 +528,8 @@
break;
case 't':
autoTilemap = false;
+ if (!options.tilemap.empty())
+ warning("Overriding tilemap file %s", options.tilemap.c_str());
options.tilemap = musl_optarg;
break;
case 'V':
--- a/src/link/main.c
+++ b/src/link/main.c
@@ -369,6 +369,8 @@
isWRA0Mode = true;
break;
case 'l':
+ if (linkerScriptName)
+ warnx("Overriding linkerscript %s", musl_optarg);
linkerScriptName = musl_optarg;
break;
case 'M':
@@ -375,15 +377,23 @@
noSymInMap = true;
break;
case 'm':
+ if (mapFileName)
+ warnx("Overriding mapfile %s", musl_optarg);
mapFileName = musl_optarg;
break;
case 'n':
+ if (symFileName)
+ warnx("Overriding symfile %s", musl_optarg);
symFileName = musl_optarg;
break;
case 'O':
+ if (overlayFileName)
+ warnx("Overriding overlay file %s", musl_optarg);
overlayFileName = musl_optarg;
break;
case 'o':
+ if (outputFileName)
+ warnx("Overriding output file %s", musl_optarg);
outputFileName = musl_optarg;
break;
case 'p':