Skip to content

Commit f065243

Browse files
authored
Enable RGBGFX's CLI "at-files" for all programs (#1848)
1 parent a0bb830 commit f065243

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1384
-1252
lines changed

ARCHITECTURE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ These files in the `src/` directory are shared across multiple programs: often a
120120

121121
- **`backtrace.cpp`:**
122122
Generic printing of location backtraces for RGBASM and RGBLINK. Allows configuring backtrace styles with a command-line flag (conventionally `-B/--backtrace`). Renders warnings in yellow, errors in red, and locations in cyan.
123+
- **`cli.cpp`:**
124+
A function for parsing command-line options, including RGBDS-specific "at-files" (a filename containing more options, prepended with an "`@`").
125+
This is the only file to use the extern/getopt.cpp variables and functions.
123126
- **`diagnostics.cpp`:**
124127
Generic warning/error diagnostic support for all programs. Allows command-line flags (conventionally `-W`) to have `no-`, `error=`, or `no-error=` prefixes, and `=` level suffixes; allows "meta" flags to affect groups of individual flags; and counts how many total errors there have been. Every program has its own `warning.cpp` file that uses this.
125128
- **`linkdefs.cpp`:**

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ all: rgbasm rgblink rgbfix rgbgfx
5151

5252
common_obj := \
5353
src/extern/getopt.o \
54+
src/cli.o \
5455
src/diagnostics.o \
5556
src/style.o \
5657
src/usage.o \

include/asm/main.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#ifndef RGBDS_ASM_MAIN_HPP
44
#define RGBDS_ASM_MAIN_HPP
55

6+
#include <optional>
67
#include <stdint.h>
78
#include <stdio.h>
89
#include <string>
@@ -20,10 +21,10 @@ struct Options {
2021
char binDigits[2] = {'0', '1'}; // -b
2122
char gfxDigits[4] = {'0', '1', '2', '3'}; // -g
2223
FILE *dependFile = nullptr; // -M
23-
std::string targetFileName; // -MQ, -MT
24+
std::optional<std::string> targetFileName{}; // -MQ, -MT
2425
MissingInclude missingIncludeState = INC_ERROR; // -MC, -MG
2526
bool generatePhonyDeps = false; // -MP
26-
std::string objectFileName; // -o
27+
std::optional<std::string> objectFileName{}; // -o
2728
uint8_t padByte = 0; // -p
2829
uint64_t maxErrors = 0; // -X
2930

@@ -35,7 +36,7 @@ struct Options {
3536

3637
void printDep(std::string const &depName) {
3738
if (dependFile) {
38-
fprintf(dependFile, "%s: %s\n", targetFileName.c_str(), depName.c_str());
39+
fprintf(dependFile, "%s: %s\n", targetFileName->c_str(), depName.c_str());
3940
}
4041
}
4142
};

include/cli.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
#ifndef RGBDS_CLI_HPP
4+
#define RGBDS_CLI_HPP
5+
6+
#include <stdarg.h>
7+
#include <string>
8+
9+
#include "extern/getopt.hpp" // option
10+
11+
void cli_ParseArgs(
12+
int argc,
13+
char *argv[],
14+
char const *shortOpts,
15+
option const *longOpts,
16+
void (*parseArg)(int, char *),
17+
void (*fatal)(char const *, ...)
18+
);
19+
20+
#endif // RGBDS_CLI_HPP

include/fix/main.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
#ifndef RGBDS_FIX_MAIN_HPP
44
#define RGBDS_FIX_MAIN_HPP
55

6+
#include <optional>
67
#include <stdint.h>
8+
#include <string>
79

810
#include "fix/mbc.hpp" // UNSPECIFIED, MbcType
911

@@ -28,19 +30,19 @@ struct Options {
2830
uint16_t ramSize = UNSPECIFIED; // -r
2931
bool sgb = false; // -s
3032

31-
char const *gameID = nullptr; // -i
33+
std::optional<std::string> gameID; // -i
3234
uint8_t gameIDLen;
3335

34-
char const *newLicensee = nullptr; // -k
36+
std::optional<std::string> newLicensee; // -k
3537
uint8_t newLicenseeLen;
3638

37-
char const *logoFilename = nullptr; // -L
39+
std::optional<std::string> logoFilename; // -L
3840
uint8_t logo[48] = {};
3941

4042
MbcType cartridgeType = MBC_NONE; // -m
4143
uint8_t tpp1Rev[2];
4244

43-
char const *title = nullptr; // -t
45+
std::optional<std::string> title; // -t
4446
uint8_t titleLen;
4547
};
4648

include/link/lexer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ void lexer_TraceCurrent();
1010
void lexer_IncludeFile(std::string &&path);
1111
void lexer_IncLineNo();
1212

13-
bool lexer_Init(char const *linkerScriptName);
13+
bool lexer_Init(std::string const &linkerScriptName);
1414

1515
#endif // RGBDS_LINK_LEXER_HPP

include/link/main.hpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33
#ifndef RGBDS_LINK_MAIN_HPP
44
#define RGBDS_LINK_MAIN_HPP
55

6+
#include <optional>
67
#include <stdint.h>
8+
#include <string>
79

810
struct Options {
9-
bool isDmgMode; // -d
10-
char const *mapFileName; // -m
11-
bool noSymInMap; // -M
12-
char const *symFileName; // -n
13-
char const *overlayFileName; // -O
14-
char const *outputFileName; // -o
15-
uint8_t padValue; // -p
11+
bool isDmgMode; // -d
12+
std::optional<std::string> mapFileName; // -m
13+
bool noSymInMap; // -M
14+
std::optional<std::string> symFileName; // -n
15+
std::optional<std::string> overlayFileName; // -O
16+
std::optional<std::string> outputFileName; // -o
17+
uint8_t padValue; // -p
1618
bool hasPadValue = false;
1719
// Setting these three to 0 disables the functionality
1820
uint16_t scrambleROMX; // -S

include/link/object.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
#ifndef RGBDS_LINK_OBJECT_HPP
44
#define RGBDS_LINK_OBJECT_HPP
55

6+
#include <stddef.h>
7+
#include <string>
8+
69
// Read an object (.o) file, and add its info to the data structures.
7-
void obj_ReadFile(char const *fileName, unsigned int fileID);
10+
void obj_ReadFile(std::string const &filePath, size_t fileID);
811

912
// Sets up object file reading
10-
void obj_Setup(unsigned int nbFiles);
13+
void obj_Setup(size_t nbFiles);
1114

1215
#endif // RGBDS_LINK_OBJECT_HPP

man/rgbasm.1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,23 @@ disables this behavior.
351351
The default is 100 if
352352
.Nm
353353
is printing errors to a terminal, and 0 otherwise.
354+
.It @ Ns Ar at_file
355+
Read more options and arguments from a file, as if its contents were given on the command line.
356+
Arguments are separated by whitespace or newlines.
357+
Lines starting with a hash sign
358+
.Pq Ql #
359+
are considered comments and ignored.
360+
.Pp
361+
No shell processing is performed, such as wildcard or variable expansion.
362+
There is no support for escaping or quoting whitespace to be included in arguments.
363+
The standard
364+
.Ql --
365+
to stop option processing also disables at-file processing.
366+
Note that while
367+
.Ql --
368+
can be used
369+
.Em inside
370+
an at-file, it only disables option processing within that at-file, and processing continues in the parent scope.
354371
.El
355372
.Sh DIAGNOSTICS
356373
Warnings are diagnostic messages that indicate possibly erroneous behavior that does not necessarily compromise the assembling process.

man/rgbfix.1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,23 @@ See the
243243
section for a list of warnings.
244244
.It Fl w
245245
Disable all warning output, even when turned into errors.
246+
.It @ Ns Ar at_file
247+
Read more options and arguments from a file, as if its contents were given on the command line.
248+
Arguments are separated by whitespace or newlines.
249+
Lines starting with a hash sign
250+
.Pq Ql #
251+
are considered comments and ignored.
252+
.Pp
253+
No shell processing is performed, such as wildcard or variable expansion.
254+
There is no support for escaping or quoting whitespace to be included in arguments.
255+
The standard
256+
.Ql --
257+
to stop option processing also disables at-file processing.
258+
Note that while
259+
.Ql --
260+
can be used
261+
.Em inside
262+
an at-file, it only disables option processing within that at-file, and processing continues in the parent scope.
246263
.El
247264
.Sh DIAGNOSTICS
248265
Warnings are diagnostic messages that indicate possibly erroneous behavior that does not necessarily compromise the header-fixing process.

0 commit comments

Comments
 (0)