mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Reimplement -M variants using long options
This commit is contained in:
127
src/asm/main.c
127
src/asm/main.c
@@ -263,6 +263,9 @@ static char *make_escape(const char *str)
|
|||||||
/* Short options */
|
/* Short options */
|
||||||
static char const *optstring = "b:D:Eg:hi:LM:o:p:r:VvW:w";
|
static char const *optstring = "b:D:Eg:hi:LM:o:p:r:VvW:w";
|
||||||
|
|
||||||
|
/* Variables for the long-only options */
|
||||||
|
static int depType; /* Variants of `-M` */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Equivalent long options
|
* Equivalent long options
|
||||||
* Please keep in the same order as short opts
|
* Please keep in the same order as short opts
|
||||||
@@ -274,21 +277,25 @@ static char const *optstring = "b:D:Eg:hi:LM:o:p:r:VvW:w";
|
|||||||
* over short opt matching
|
* over short opt matching
|
||||||
*/
|
*/
|
||||||
static struct option const longopts[] = {
|
static struct option const longopts[] = {
|
||||||
{ "binary-digits", required_argument, NULL, 'b' },
|
{ "binary-digits", required_argument, NULL, 'b' },
|
||||||
{ "define", required_argument, NULL, 'D' },
|
{ "define", required_argument, NULL, 'D' },
|
||||||
{ "export-all", no_argument, NULL, 'E' },
|
{ "export-all", no_argument, NULL, 'E' },
|
||||||
{ "gfx-chars", required_argument, NULL, 'g' },
|
{ "gfx-chars", required_argument, NULL, 'g' },
|
||||||
{ "halt-without-nop", no_argument, NULL, 'h' },
|
{ "halt-without-nop", no_argument, NULL, 'h' },
|
||||||
{ "include", required_argument, NULL, 'i' },
|
{ "include", required_argument, NULL, 'i' },
|
||||||
{ "preserve-ld", no_argument, NULL, 'L' },
|
{ "preserve-ld", no_argument, NULL, 'L' },
|
||||||
{ "dependfile", required_argument, NULL, 'M' },
|
{ "dependfile", required_argument, NULL, 'M' },
|
||||||
{ "output", required_argument, NULL, 'o' },
|
{ "MG", no_argument, &depType, 'G' },
|
||||||
{ "pad-value", required_argument, NULL, 'p' },
|
{ "MP", no_argument, &depType, 'P' },
|
||||||
{ "recursion-depth", required_argument, NULL, 'r' },
|
{ "MT", required_argument, &depType, 'T' },
|
||||||
{ "version", no_argument, NULL, 'V' },
|
{ "MQ", required_argument, &depType, 'Q' },
|
||||||
{ "verbose", no_argument, NULL, 'v' },
|
{ "output", required_argument, NULL, 'o' },
|
||||||
{ "warning", required_argument, NULL, 'W' },
|
{ "pad-value", required_argument, NULL, 'p' },
|
||||||
{ NULL, no_argument, NULL, 0 }
|
{ "recursion-depth", required_argument, NULL, 'r' },
|
||||||
|
{ "version", no_argument, NULL, 'V' },
|
||||||
|
{ "verbose", no_argument, NULL, 'v' },
|
||||||
|
{ "warning", required_argument, NULL, 'W' },
|
||||||
|
{ NULL, no_argument, NULL, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
static void print_usage(void)
|
static void print_usage(void)
|
||||||
@@ -391,50 +398,13 @@ int main(int argc, char *argv[])
|
|||||||
newopt.optimizeloads = false;
|
newopt.optimizeloads = false;
|
||||||
break;
|
break;
|
||||||
case 'M':
|
case 'M':
|
||||||
ep = strchr("GPQT", optarg[0]);
|
if (!strcmp("-", optarg))
|
||||||
if (!ep || !*ep || optarg[1]) {
|
dependfile = stdout;
|
||||||
if (!strcmp("-", optarg))
|
else
|
||||||
dependfile = stdout;
|
dependfile = fopen(optarg, "w");
|
||||||
else
|
if (dependfile == NULL)
|
||||||
dependfile = fopen(optarg, "w");
|
err(1, "Could not open dependfile %s",
|
||||||
if (dependfile == NULL)
|
optarg);
|
||||||
err(1, "Could not open dependfile %s",
|
|
||||||
optarg);
|
|
||||||
} else {
|
|
||||||
switch (optarg[0]) {
|
|
||||||
case 'G':
|
|
||||||
oGeneratedMissingIncludes = true;
|
|
||||||
break;
|
|
||||||
case 'P':
|
|
||||||
oGeneratePhonyDeps = true;
|
|
||||||
break;
|
|
||||||
case 'Q':
|
|
||||||
case 'T':
|
|
||||||
if (optind == argc)
|
|
||||||
errx(1, "-M%c takes a target file name argument",
|
|
||||||
optarg[0]);
|
|
||||||
ep = argv[optind];
|
|
||||||
optind++;
|
|
||||||
if (optarg[0] == 'Q')
|
|
||||||
ep = make_escape(ep);
|
|
||||||
|
|
||||||
nTargetFileNameLen += strlen(ep) + 1;
|
|
||||||
tzTargetFileName =
|
|
||||||
realloc(tzTargetFileName,
|
|
||||||
nTargetFileNameLen + 1);
|
|
||||||
if (tzTargetFileName == NULL)
|
|
||||||
err(1, "Cannot append new file to target file list");
|
|
||||||
strcat(tzTargetFileName, ep);
|
|
||||||
if (optarg[0] == 'Q')
|
|
||||||
free(ep);
|
|
||||||
char *ptr = tzTargetFileName +
|
|
||||||
strlen(tzTargetFileName);
|
|
||||||
*ptr++ = ' ';
|
|
||||||
*ptr = '\0';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
out_SetFileName(optarg);
|
out_SetFileName(optarg);
|
||||||
@@ -467,6 +437,45 @@ int main(int argc, char *argv[])
|
|||||||
case 'w':
|
case 'w':
|
||||||
newopt.warnings = false;
|
newopt.warnings = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* Long-only options */
|
||||||
|
case 0:
|
||||||
|
if (depType) {
|
||||||
|
switch (depType) {
|
||||||
|
case 'G':
|
||||||
|
oGeneratedMissingIncludes = true;
|
||||||
|
break;
|
||||||
|
case 'P':
|
||||||
|
oGeneratePhonyDeps = true;
|
||||||
|
break;
|
||||||
|
case 'Q':
|
||||||
|
case 'T':
|
||||||
|
if (optind == argc)
|
||||||
|
errx(1, "-M%c takes a target file name argument",
|
||||||
|
depType);
|
||||||
|
ep = optarg;
|
||||||
|
if (depType == 'Q')
|
||||||
|
ep = make_escape(ep);
|
||||||
|
|
||||||
|
nTargetFileNameLen += strlen(ep) + 1;
|
||||||
|
tzTargetFileName =
|
||||||
|
realloc(tzTargetFileName,
|
||||||
|
nTargetFileNameLen + 1);
|
||||||
|
if (tzTargetFileName == NULL)
|
||||||
|
err(1, "Cannot append new file to target file list");
|
||||||
|
strcat(tzTargetFileName, ep);
|
||||||
|
if (depType == 'Q')
|
||||||
|
free(ep);
|
||||||
|
char *ptr = tzTargetFileName +
|
||||||
|
strlen(tzTargetFileName);
|
||||||
|
*ptr++ = ' ';
|
||||||
|
*ptr = '\0';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Unrecognized options */
|
||||||
default:
|
default:
|
||||||
print_usage();
|
print_usage();
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
|
|||||||
Reference in New Issue
Block a user