From 6a65cbc9ed74a35ca3fa91ea1ba438063c5563c4 Mon Sep 17 00:00:00 2001 From: Sylvie <35663410+Rangi42@users.noreply.github.com> Date: Fri, 26 Jul 2024 11:51:27 -0400 Subject: [PATCH] Some refactoring and reformatting (#1431) --- include/link/main.hpp | 2 +- src/asm/format.cpp | 2 +- src/asm/main.cpp | 62 ++++++++++++++++++++----------------------- src/asm/output.cpp | 3 +++ src/gfx/main.cpp | 52 ++++++++++++++++++------------------ src/link/main.cpp | 26 +++++++++--------- 6 files changed, 73 insertions(+), 74 deletions(-) diff --git a/include/link/main.hpp b/include/link/main.hpp index be82befe..9b378c27 100644 --- a/include/link/main.hpp +++ b/include/link/main.hpp @@ -13,7 +13,7 @@ // Variables related to CLI options extern bool isDmgMode; -extern char *linkerScriptName; +extern char const *linkerScriptName; extern char const *mapFileName; extern bool noSymInMap; extern char const *symFileName; diff --git a/src/asm/format.cpp b/src/asm/format.cpp index 864729ea..333b6d99 100644 --- a/src/asm/format.cpp +++ b/src/asm/format.cpp @@ -203,7 +203,7 @@ void FormatSpec::appendNumber(std::string &str, uint32_t value) const { uint32_t uval = value != (uint32_t)INT32_MIN ? labs((int32_t)value) : value; snprintf(valueBuf, sizeof(valueBuf), "%" PRIu32, uval); } else { - char const *spec = useType == 'u' ? "%" PRIu32 + char const *spec = useType == 'u' ? "%" PRIu32 : useType == 'X' ? "%" PRIX32 : useType == 'x' ? "%" PRIx32 : useType == 'o' ? "%" PRIo32 diff --git a/src/asm/main.cpp b/src/asm/main.cpp index 85164346..6187d48f 100644 --- a/src/asm/main.cpp +++ b/src/asm/main.cpp @@ -21,14 +21,13 @@ #include "asm/symbol.hpp" #include "asm/warning.hpp" -FILE *dependFile = nullptr; -bool generatedMissingIncludes = false; +FILE *dependFile = nullptr; // -M +bool generatedMissingIncludes = false; // -MG +bool generatePhonyDeps = false; // -MP +std::string targetFileName; // -MQ, -MT bool failedOnMissingInclude = false; -bool generatePhonyDeps = false; -std::string targetFileName; - -bool verbose; -bool warnings; // True to enable warnings, false to disable them. +bool verbose = false; // -v +bool warnings = true; // -w // Escapes Make-special chars from a string static std::string make_escape(std::string &str) { @@ -62,27 +61,27 @@ static int depType; // Variants of `-M` // This is because long opt matching, even to a single char, is prioritized // over short opt matching static option const longopts[] = { - {"binary-digits", required_argument, nullptr, 'b'}, - {"define", required_argument, nullptr, 'D'}, - {"export-all", no_argument, nullptr, 'E'}, - {"gfx-chars", required_argument, nullptr, 'g'}, - {"include", required_argument, nullptr, 'I'}, - {"dependfile", required_argument, nullptr, 'M'}, - {"MG", no_argument, &depType, 'G'}, - {"MP", no_argument, &depType, 'P'}, - {"MT", required_argument, &depType, 'T'}, - {"warning", required_argument, nullptr, 'W'}, - {"MQ", required_argument, &depType, 'Q'}, - {"output", required_argument, nullptr, 'o'}, - {"preinclude", required_argument, nullptr, 'P'}, - {"pad-value", required_argument, nullptr, 'p'}, - {"q-precision", required_argument, nullptr, 'Q'}, - {"recursion-depth", required_argument, nullptr, 'r'}, - {"version", no_argument, nullptr, 'V'}, - {"verbose", no_argument, nullptr, 'v'}, - {"warning", required_argument, nullptr, 'W'}, - {"max-errors", required_argument, nullptr, 'X'}, - {nullptr, no_argument, nullptr, 0 } + {"binary-digits", required_argument, nullptr, 'b'}, + {"define", required_argument, nullptr, 'D'}, + {"export-all", no_argument, nullptr, 'E'}, + {"gfx-chars", required_argument, nullptr, 'g'}, + {"include", required_argument, nullptr, 'I'}, + {"dependfile", required_argument, nullptr, 'M'}, + {"MG", no_argument, &depType, 'G'}, + {"MP", no_argument, &depType, 'P'}, + {"MT", required_argument, &depType, 'T'}, + {"warning", required_argument, nullptr, 'W'}, + {"MQ", required_argument, &depType, 'Q'}, + {"output", required_argument, nullptr, 'o'}, + {"preinclude", required_argument, nullptr, 'P'}, + {"pad-value", required_argument, nullptr, 'p'}, + {"q-precision", required_argument, nullptr, 'Q'}, + {"recursion-depth", required_argument, nullptr, 'r'}, + {"version", no_argument, nullptr, 'V'}, + {"verbose", no_argument, nullptr, 'v'}, + {"warning", required_argument, nullptr, 'W'}, + {"max-errors", required_argument, nullptr, 'X'}, + {nullptr, no_argument, nullptr, 0 } }; static void printUsage() { @@ -124,8 +123,6 @@ int main(int argc, char *argv[]) { opt_G("0123"); opt_P(0); opt_Q(16); - verbose = false; - warnings = true; sym_SetExportAll(false); uint32_t maxDepth = DEFAULT_MAX_DEPTH; char const *dependFileName = nullptr; @@ -336,8 +333,7 @@ int main(int argc, char *argv[]) { if (failedOnMissingInclude) return 0; - // If no path specified, don't write file - if (!objectName.empty()) - out_WriteObject(); + out_WriteObject(); + return 0; } diff --git a/src/asm/output.cpp b/src/asm/output.cpp index b6b0ccbc..59ac3cc2 100644 --- a/src/asm/output.cpp +++ b/src/asm/output.cpp @@ -304,6 +304,9 @@ static void writeFileStackNode(FileStackNode const &node, FILE *file) { // Write an object file void out_WriteObject() { + if (objectName.empty()) + return; + FILE *file; if (objectName != "-") { file = fopen(objectName.c_str(), "wb"); diff --git a/src/gfx/main.cpp b/src/gfx/main.cpp index 00955c50..676f3653 100644 --- a/src/gfx/main.cpp +++ b/src/gfx/main.cpp @@ -114,32 +114,32 @@ static char const *optstring = "-Aa:b:Cc:Dd:FfhL:mN:n:Oo:Pp:Qq:r:s:Tt:U:uVvx:Z"; * over short opt matching */ static option const longopts[] = { - {"auto-attr-map", no_argument, nullptr, 'A' }, - {"attr-map", required_argument, nullptr, 'a' }, - {"base-tiles", required_argument, nullptr, 'b' }, - {"color-curve", no_argument, nullptr, 'C' }, - {"colors", required_argument, nullptr, 'c' }, - {"depth", required_argument, nullptr, 'd' }, - {"slice", required_argument, nullptr, 'L' }, - {"mirror-tiles", no_argument, nullptr, 'm' }, - {"nb-tiles", required_argument, nullptr, 'N' }, - {"nb-palettes", required_argument, nullptr, 'n' }, - {"group-outputs", no_argument, nullptr, 'O' }, - {"output", required_argument, nullptr, 'o' }, - {"auto-palette", no_argument, nullptr, 'P' }, - {"palette", required_argument, nullptr, 'p' }, - {"auto-palette-map", no_argument, nullptr, 'Q' }, - {"palette-map", required_argument, nullptr, 'q' }, - {"reverse", required_argument, nullptr, 'r' }, - {"auto-tilemap", no_argument, nullptr, 'T' }, - {"tilemap", required_argument, nullptr, 't' }, - {"unit-size", required_argument, nullptr, 'U' }, - {"unique-tiles", no_argument, nullptr, 'u' }, - {"version", no_argument, nullptr, 'V' }, - {"verbose", no_argument, nullptr, 'v' }, - {"trim-end", required_argument, nullptr, 'x' }, - {"columns", no_argument, nullptr, 'Z' }, - {nullptr, no_argument, nullptr, 0 } + {"auto-attr-map", no_argument, nullptr, 'A'}, + {"attr-map", required_argument, nullptr, 'a'}, + {"base-tiles", required_argument, nullptr, 'b'}, + {"color-curve", no_argument, nullptr, 'C'}, + {"colors", required_argument, nullptr, 'c'}, + {"depth", required_argument, nullptr, 'd'}, + {"slice", required_argument, nullptr, 'L'}, + {"mirror-tiles", no_argument, nullptr, 'm'}, + {"nb-tiles", required_argument, nullptr, 'N'}, + {"nb-palettes", required_argument, nullptr, 'n'}, + {"group-outputs", no_argument, nullptr, 'O'}, + {"output", required_argument, nullptr, 'o'}, + {"auto-palette", no_argument, nullptr, 'P'}, + {"palette", required_argument, nullptr, 'p'}, + {"auto-palette-map", no_argument, nullptr, 'Q'}, + {"palette-map", required_argument, nullptr, 'q'}, + {"reverse", required_argument, nullptr, 'r'}, + {"auto-tilemap", no_argument, nullptr, 'T'}, + {"tilemap", required_argument, nullptr, 't'}, + {"unit-size", required_argument, nullptr, 'U'}, + {"unique-tiles", no_argument, nullptr, 'u'}, + {"version", no_argument, nullptr, 'V'}, + {"verbose", no_argument, nullptr, 'v'}, + {"trim-end", required_argument, nullptr, 'x'}, + {"columns", no_argument, nullptr, 'Z'}, + {nullptr, no_argument, nullptr, 0 } }; static void printUsage() { diff --git a/src/link/main.cpp b/src/link/main.cpp index adff69b8..97438a32 100644 --- a/src/link/main.cpp +++ b/src/link/main.cpp @@ -24,14 +24,14 @@ #include "link/section.hpp" #include "link/symbol.hpp" -bool isDmgMode; // -d -char *linkerScriptName; // -l -char const *mapFileName; // -m -bool noSymInMap; // -M -char const *symFileName; // -n -char const *overlayFileName; // -O -char const *outputFileName; // -o -uint8_t padValue; // -p +bool isDmgMode; // -d +char const *linkerScriptName; // -l +char const *mapFileName; // -m +bool noSymInMap; // -M +char const *symFileName; // -n +char const *overlayFileName; // -O +char const *outputFileName; // -o +uint8_t padValue; // -p bool hasPadValue = false; // Setting these three to 0 disables the functionality uint16_t scrambleROMX = 0; // -S @@ -349,7 +349,7 @@ int main(int argc, char *argv[]) { break; case 'l': if (linkerScriptName) - warnx("Overriding linker script %s", musl_optarg); + warnx("Overriding linker script %s", linkerScriptName); linkerScriptName = musl_optarg; break; case 'M': @@ -357,22 +357,22 @@ int main(int argc, char *argv[]) { break; case 'm': if (mapFileName) - warnx("Overriding map file %s", musl_optarg); + warnx("Overriding map file %s", mapFileName); mapFileName = musl_optarg; break; case 'n': if (symFileName) - warnx("Overriding sym file %s", musl_optarg); + warnx("Overriding sym file %s", symFileName); symFileName = musl_optarg; break; case 'O': if (overlayFileName) - warnx("Overriding overlay file %s", musl_optarg); + warnx("Overriding overlay file %s", overlayFileName); overlayFileName = musl_optarg; break; case 'o': if (outputFileName) - warnx("Overriding output file %s", musl_optarg); + warnx("Overriding output file %s", outputFileName); outputFileName = musl_optarg; break; case 'p': {