mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
4
include/extern/getopt.h
vendored
4
include/extern/getopt.h
vendored
@@ -26,8 +26,8 @@
|
|||||||
#ifndef RGBDS_EXTERN_GETOPT_H
|
#ifndef RGBDS_EXTERN_GETOPT_H
|
||||||
#define RGBDS_EXTERN_GETOPT_H
|
#define RGBDS_EXTERN_GETOPT_H
|
||||||
|
|
||||||
extern char *optarg;
|
extern char *musl_optarg;
|
||||||
extern int optind, opterr, optopt, optreset;
|
extern int musl_optind, musl_opterr, musl_optopt, musl_optreset;
|
||||||
|
|
||||||
struct option {
|
struct option {
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|||||||
@@ -177,20 +177,20 @@ int main(int argc, char *argv[])
|
|||||||
while ((ch = musl_getopt_long_only(argc, argv, optstring, longopts, NULL)) != -1) {
|
while ((ch = musl_getopt_long_only(argc, argv, optstring, longopts, NULL)) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'b':
|
case 'b':
|
||||||
if (strlen(optarg) == 2)
|
if (strlen(musl_optarg) == 2)
|
||||||
opt_B(&optarg[1]);
|
opt_B(&musl_optarg[1]);
|
||||||
else
|
else
|
||||||
errx(1, "Must specify exactly 2 characters for option 'b'");
|
errx(1, "Must specify exactly 2 characters for option 'b'");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
char *equals;
|
char *equals;
|
||||||
case 'D':
|
case 'D':
|
||||||
equals = strchr(optarg, '=');
|
equals = strchr(musl_optarg, '=');
|
||||||
if (equals) {
|
if (equals) {
|
||||||
*equals = '\0';
|
*equals = '\0';
|
||||||
sym_AddString(optarg, equals + 1);
|
sym_AddString(musl_optarg, equals + 1);
|
||||||
} else {
|
} else {
|
||||||
sym_AddString(optarg, "1");
|
sym_AddString(musl_optarg, "1");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -199,8 +199,8 @@ int main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'g':
|
case 'g':
|
||||||
if (strlen(optarg) == 4)
|
if (strlen(musl_optarg) == 4)
|
||||||
opt_G(&optarg[1]);
|
opt_G(&musl_optarg[1]);
|
||||||
else
|
else
|
||||||
errx(1, "Must specify exactly 4 characters for option 'g'");
|
errx(1, "Must specify exactly 4 characters for option 'g'");
|
||||||
break;
|
break;
|
||||||
@@ -210,7 +210,7 @@ int main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'i':
|
case 'i':
|
||||||
fstk_AddIncludePath(optarg);
|
fstk_AddIncludePath(musl_optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'L':
|
case 'L':
|
||||||
@@ -218,23 +218,23 @@ int main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'M':
|
case 'M':
|
||||||
if (!strcmp("-", optarg))
|
if (!strcmp("-", musl_optarg))
|
||||||
dependfile = stdout;
|
dependfile = stdout;
|
||||||
else
|
else
|
||||||
dependfile = fopen(optarg, "w");
|
dependfile = fopen(musl_optarg, "w");
|
||||||
if (dependfile == NULL)
|
if (dependfile == NULL)
|
||||||
err(1, "Could not open dependfile %s", optarg);
|
err(1, "Could not open dependfile %s", musl_optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'o':
|
case 'o':
|
||||||
out_SetFileName(optarg);
|
out_SetFileName(musl_optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
unsigned long fill;
|
unsigned long fill;
|
||||||
case 'p':
|
case 'p':
|
||||||
fill = strtoul(optarg, &ep, 0);
|
fill = strtoul(musl_optarg, &ep, 0);
|
||||||
|
|
||||||
if (optarg[0] == '\0' || *ep != '\0')
|
if (musl_optarg[0] == '\0' || *ep != '\0')
|
||||||
errx(1, "Invalid argument for option 'p'");
|
errx(1, "Invalid argument for option 'p'");
|
||||||
|
|
||||||
if (fill < 0 || fill > 0xFF)
|
if (fill < 0 || fill > 0xFF)
|
||||||
@@ -244,9 +244,9 @@ int main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'r':
|
case 'r':
|
||||||
maxRecursionDepth = strtoul(optarg, &ep, 0);
|
maxRecursionDepth = strtoul(musl_optarg, &ep, 0);
|
||||||
|
|
||||||
if (optarg[0] == '\0' || *ep != '\0')
|
if (musl_optarg[0] == '\0' || *ep != '\0')
|
||||||
errx(1, "Invalid argument for option 'r'");
|
errx(1, "Invalid argument for option 'r'");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -258,7 +258,7 @@ int main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'W':
|
case 'W':
|
||||||
processWarningFlag(optarg);
|
processWarningFlag(musl_optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'w':
|
case 'w':
|
||||||
@@ -278,9 +278,9 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
case 'Q':
|
case 'Q':
|
||||||
case 'T':
|
case 'T':
|
||||||
if (optind == argc)
|
if (musl_optind == argc)
|
||||||
errx(1, "-M%c takes a target file name argument", depType);
|
errx(1, "-M%c takes a target file name argument", depType);
|
||||||
ep = optarg;
|
ep = musl_optarg;
|
||||||
if (depType == 'Q')
|
if (depType == 'Q')
|
||||||
ep = make_escape(ep);
|
ep = make_escape(ep);
|
||||||
|
|
||||||
@@ -317,15 +317,15 @@ int main(int argc, char *argv[])
|
|||||||
if (tzTargetFileName == NULL)
|
if (tzTargetFileName == NULL)
|
||||||
tzTargetFileName = tzObjectname;
|
tzTargetFileName = tzObjectname;
|
||||||
|
|
||||||
if (argc == optind) {
|
if (argc == musl_optind) {
|
||||||
fputs("FATAL: No input files\n", stderr);
|
fputs("FATAL: No input files\n", stderr);
|
||||||
print_usage();
|
print_usage();
|
||||||
} else if (argc != optind + 1) {
|
} else if (argc != musl_optind + 1) {
|
||||||
fputs("FATAL: More than one input file given\n", stderr);
|
fputs("FATAL: More than one input file given\n", stderr);
|
||||||
print_usage();
|
print_usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
char const *mainFileName = argv[optind];
|
char const *mainFileName = argv[musl_optind];
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
printf("Assembling %s\n", mainFileName);
|
printf("Assembling %s\n", mainFileName);
|
||||||
|
|||||||
203
src/extern/getopt.c
vendored
203
src/extern/getopt.c
vendored
@@ -26,21 +26,16 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#ifndef _MSC_VER
|
|
||||||
# include <unistd.h>
|
|
||||||
#endif
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
|
|
||||||
#include "extern/getopt.h"
|
#include "extern/getopt.h"
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
char *musl_optarg;
|
||||||
char *optarg;
|
int musl_optind = 1, musl_opterr = 1, musl_optopt;
|
||||||
int optind=1, opterr=1, optopt;
|
int musl_optreset = 0;
|
||||||
#endif
|
static int musl_optpos;
|
||||||
int optreset=0;
|
|
||||||
static int optpos;
|
|
||||||
|
|
||||||
static void musl_getopt_msg(const char *a, const char *b, const char *c, size_t l)
|
static void musl_getopt_msg(const char *a, const char *b, const char *c, size_t l)
|
||||||
{
|
{
|
||||||
@@ -52,7 +47,6 @@ static void musl_getopt_msg(const char *a, const char *b, const char *c, size_t
|
|||||||
putc('\n', f);
|
putc('\n', f);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
static int getopt(int argc, char *argv[], const char *optstring)
|
static int getopt(int argc, char *argv[], const char *optstring)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@@ -60,40 +54,42 @@ static int getopt(int argc, char *argv[], const char *optstring)
|
|||||||
int k, l;
|
int k, l;
|
||||||
char *optchar;
|
char *optchar;
|
||||||
|
|
||||||
if (!optind || optreset) {
|
if (!musl_optind || musl_optreset) {
|
||||||
optreset = 0;
|
musl_optreset = 0;
|
||||||
optpos = 0;
|
musl_optpos = 0;
|
||||||
optind = 1;
|
musl_optind = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (optind >= argc || !argv[optind])
|
if (musl_optind >= argc || !argv[musl_optind])
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (argv[optind][0] != '-') {
|
if (argv[musl_optind][0] != '-') {
|
||||||
if (optstring[0] == '-') {
|
if (optstring[0] == '-') {
|
||||||
optarg = argv[optind++];
|
musl_optarg = argv[musl_optind++];
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!argv[optind][1])
|
if (!argv[musl_optind][1])
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (argv[optind][1] == '-' && !argv[optind][2])
|
if (argv[musl_optind][1] == '-' && !argv[musl_optind][2])
|
||||||
return optind++, -1;
|
return musl_optind++, -1;
|
||||||
|
|
||||||
if (!optpos) optpos++;
|
if (!musl_optpos)
|
||||||
if ((k = mbtowc(&c, argv[optind]+optpos, MB_LEN_MAX)) < 0) {
|
musl_optpos++;
|
||||||
|
k = mbtowc(&c, argv[musl_optind] + musl_optpos, MB_LEN_MAX);
|
||||||
|
if (k < 0) {
|
||||||
k = 1;
|
k = 1;
|
||||||
c = 0xfffd; /* replacement char */
|
c = 0xfffd; /* replacement char */
|
||||||
}
|
}
|
||||||
optchar = argv[optind]+optpos;
|
optchar = argv[musl_optind] + musl_optpos;
|
||||||
optpos += k;
|
musl_optpos += k;
|
||||||
|
|
||||||
if (!argv[optind][optpos]) {
|
if (!argv[musl_optind][musl_optpos]) {
|
||||||
optind++;
|
musl_optind++;
|
||||||
optpos = 0;
|
musl_optpos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (optstring[0] == '-' || optstring[0] == '+')
|
if (optstring[0] == '-' || optstring[0] == '+')
|
||||||
@@ -103,39 +99,43 @@ static int getopt(int argc, char *argv[], const char *optstring)
|
|||||||
d = 0;
|
d = 0;
|
||||||
do {
|
do {
|
||||||
l = mbtowc(&d, optstring+i, MB_LEN_MAX);
|
l = mbtowc(&d, optstring+i, MB_LEN_MAX);
|
||||||
if (l>0) i+=l; else i++;
|
if (l > 0)
|
||||||
|
i += l;
|
||||||
|
else
|
||||||
|
i++;
|
||||||
} while (l && d != c);
|
} while (l && d != c);
|
||||||
|
|
||||||
if (d != c || c == ':') {
|
if (d != c || c == ':') {
|
||||||
optopt = c;
|
musl_optopt = c;
|
||||||
if (optstring[0] != ':' && opterr)
|
if (optstring[0] != ':' && musl_opterr)
|
||||||
musl_getopt_msg(argv[0], ": unrecognized option: ", optchar, k);
|
musl_getopt_msg(argv[0], ": unrecognized option: ", optchar, k);
|
||||||
return '?';
|
return '?';
|
||||||
}
|
}
|
||||||
if (optstring[i] == ':') {
|
if (optstring[i] == ':') {
|
||||||
optarg = 0;
|
musl_optarg = 0;
|
||||||
if (optstring[i+1] != ':' || optpos) {
|
if (optstring[i + 1] != ':' || musl_optpos) {
|
||||||
optarg = argv[optind++] + optpos;
|
musl_optarg = argv[musl_optind++] + musl_optpos;
|
||||||
optpos = 0;
|
musl_optpos = 0;
|
||||||
}
|
}
|
||||||
if (optind > argc) {
|
if (musl_optind > argc) {
|
||||||
optopt = c;
|
musl_optopt = c;
|
||||||
if (optstring[0] == ':') return ':';
|
if (optstring[0] == ':')
|
||||||
if (opterr) musl_getopt_msg(argv[0],
|
return ':';
|
||||||
": option requires an argument: ",
|
if (musl_opterr)
|
||||||
optchar, k);
|
musl_getopt_msg(argv[0], ": option requires an argument: ",
|
||||||
|
optchar, k);
|
||||||
return '?';
|
return '?';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
#endif /* _MSC_VER */
|
|
||||||
|
|
||||||
static void permute(char **argv, int dest, int src)
|
static void permute(char **argv, int dest, int src)
|
||||||
{
|
{
|
||||||
char *tmp = argv[src];
|
char *tmp = argv[src];
|
||||||
int i;
|
int i;
|
||||||
for (i=src; i>dest; i--)
|
|
||||||
|
for (i = src; i > dest; i--)
|
||||||
argv[i] = argv[i-1];
|
argv[i] = argv[i-1];
|
||||||
argv[dest] = tmp;
|
argv[dest] = tmp;
|
||||||
}
|
}
|
||||||
@@ -145,49 +145,61 @@ static int musl_getopt_long_core(int argc, char **argv, const char *optstring, c
|
|||||||
static int musl_getopt_long(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
|
static int musl_getopt_long(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
|
||||||
{
|
{
|
||||||
int ret, skipped, resumed;
|
int ret, skipped, resumed;
|
||||||
if (!optind || optreset) {
|
|
||||||
optreset = 0;
|
if (!musl_optind || musl_optreset) {
|
||||||
optpos = 0;
|
musl_optreset = 0;
|
||||||
optind = 1;
|
musl_optpos = 0;
|
||||||
|
musl_optind = 1;
|
||||||
}
|
}
|
||||||
if (optind >= argc || !argv[optind]) return -1;
|
|
||||||
skipped = optind;
|
if (musl_optind >= argc || !argv[musl_optind])
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
skipped = musl_optind;
|
||||||
if (optstring[0] != '+' && optstring[0] != '-') {
|
if (optstring[0] != '+' && optstring[0] != '-') {
|
||||||
int i;
|
int i;
|
||||||
for (i=optind; ; i++) {
|
for (i = musl_optind; ; i++) {
|
||||||
if (i >= argc || !argv[i]) return -1;
|
if (i >= argc || !argv[i])
|
||||||
if (argv[i][0] == '-' && argv[i][1]) break;
|
return -1;
|
||||||
|
if (argv[i][0] == '-' && argv[i][1])
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
optind = i;
|
musl_optind = i;
|
||||||
}
|
}
|
||||||
resumed = optind;
|
resumed = musl_optind;
|
||||||
ret = musl_getopt_long_core(argc, argv, optstring, longopts, idx, longonly);
|
ret = musl_getopt_long_core(argc, argv, optstring, longopts, idx, longonly);
|
||||||
if (resumed > skipped) {
|
if (resumed > skipped) {
|
||||||
int i, cnt = optind-resumed;
|
int i, cnt = musl_optind - resumed;
|
||||||
for (i=0; i<cnt; i++)
|
|
||||||
permute(argv, skipped, optind-1);
|
for (i = 0; i < cnt; i++)
|
||||||
optind = skipped + cnt;
|
permute(argv, skipped, musl_optind - 1);
|
||||||
|
musl_optind = skipped + cnt;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int musl_getopt_long_core(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
|
static int musl_getopt_long_core(int argc, char **argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
|
||||||
{
|
{
|
||||||
optarg = 0;
|
musl_optarg = 0;
|
||||||
if (longopts && argv[optind][0] == '-' &&
|
if (longopts && argv[musl_optind][0] == '-' &&
|
||||||
((longonly && argv[optind][1] && argv[optind][1] != '-') ||
|
((longonly && argv[musl_optind][1] && argv[musl_optind][1] != '-') ||
|
||||||
(argv[optind][1] == '-' && argv[optind][2])))
|
(argv[musl_optind][1] == '-' && argv[musl_optind][2]))) {
|
||||||
{
|
int colon = optstring[optstring[0] == '+' || optstring[0] == '-'] == ':';
|
||||||
int colon = optstring[optstring[0]=='+'||optstring[0]=='-']==':';
|
|
||||||
int i, cnt, match = 0;
|
int i, cnt, match = 0;
|
||||||
char *arg = 0, *opt, *start = argv[optind]+1;
|
char *arg = 0, *opt, *start = argv[musl_optind] + 1;
|
||||||
for (cnt=i=0; longopts[i].name; i++) {
|
|
||||||
|
for (cnt = i = 0; longopts[i].name; i++) {
|
||||||
const char *name = longopts[i].name;
|
const char *name = longopts[i].name;
|
||||||
|
|
||||||
opt = start;
|
opt = start;
|
||||||
if (*opt == '-') opt++;
|
if (*opt == '-')
|
||||||
while (*opt && *opt != '=' && *opt == *name)
|
opt++;
|
||||||
name++, opt++;
|
while (*opt && *opt != '=' && *opt == *name) {
|
||||||
if (*opt && *opt != '=') continue;
|
name++;
|
||||||
|
opt++;
|
||||||
|
}
|
||||||
|
if (*opt && *opt != '=')
|
||||||
|
continue;
|
||||||
arg = opt;
|
arg = opt;
|
||||||
match = i;
|
match = i;
|
||||||
if (!*name) {
|
if (!*name) {
|
||||||
@@ -196,25 +208,28 @@ static int musl_getopt_long_core(int argc, char **argv, const char *optstring, c
|
|||||||
}
|
}
|
||||||
cnt++;
|
cnt++;
|
||||||
}
|
}
|
||||||
if (cnt==1 && longonly && arg-start == mblen(start, MB_LEN_MAX)) {
|
if (cnt == 1 && longonly && arg - start == mblen(start, MB_LEN_MAX)) {
|
||||||
int l = arg-start;
|
int l = arg - start;
|
||||||
for (i=0; optstring[i]; i++) {
|
|
||||||
int j;
|
for (i = 0; optstring[i]; i++) {
|
||||||
for (j=0; j<l && start[j]==optstring[i+j]; j++);
|
int j = 0;
|
||||||
if (j==l) {
|
|
||||||
|
while (j < l && start[j] == optstring[i + j])
|
||||||
|
j++;
|
||||||
|
if (j == l) {
|
||||||
cnt++;
|
cnt++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cnt==1) {
|
if (cnt == 1) {
|
||||||
i = match;
|
i = match;
|
||||||
opt = arg;
|
opt = arg;
|
||||||
optind++;
|
musl_optind++;
|
||||||
if (*opt == '=') {
|
if (*opt == '=') {
|
||||||
if (!longopts[i].has_arg) {
|
if (!longopts[i].has_arg) {
|
||||||
optopt = longopts[i].val;
|
musl_optopt = longopts[i].val;
|
||||||
if (colon || !opterr)
|
if (colon || !musl_opterr)
|
||||||
return '?';
|
return '?';
|
||||||
musl_getopt_msg(argv[0],
|
musl_getopt_msg(argv[0],
|
||||||
": option does not take an argument: ",
|
": option does not take an argument: ",
|
||||||
@@ -222,36 +237,40 @@ static int musl_getopt_long_core(int argc, char **argv, const char *optstring, c
|
|||||||
strlen(longopts[i].name));
|
strlen(longopts[i].name));
|
||||||
return '?';
|
return '?';
|
||||||
}
|
}
|
||||||
optarg = opt+1;
|
musl_optarg = opt + 1;
|
||||||
} else if (longopts[i].has_arg == required_argument) {
|
} else if (longopts[i].has_arg == required_argument) {
|
||||||
if (!(optarg = argv[optind])) {
|
musl_optarg = argv[musl_optind];
|
||||||
optopt = longopts[i].val;
|
if (!musl_optarg) {
|
||||||
if (colon) return ':';
|
musl_optopt = longopts[i].val;
|
||||||
if (!opterr) return '?';
|
if (colon)
|
||||||
|
return ':';
|
||||||
|
if (!musl_opterr)
|
||||||
|
return '?';
|
||||||
musl_getopt_msg(argv[0],
|
musl_getopt_msg(argv[0],
|
||||||
": option requires an argument: ",
|
": option requires an argument: ",
|
||||||
longopts[i].name,
|
longopts[i].name,
|
||||||
strlen(longopts[i].name));
|
strlen(longopts[i].name));
|
||||||
return '?';
|
return '?';
|
||||||
}
|
}
|
||||||
optind++;
|
musl_optind++;
|
||||||
}
|
}
|
||||||
if (idx) *idx = i;
|
if (idx)
|
||||||
|
*idx = i;
|
||||||
if (longopts[i].flag) {
|
if (longopts[i].flag) {
|
||||||
*longopts[i].flag = longopts[i].val;
|
*longopts[i].flag = longopts[i].val;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return longopts[i].val;
|
return longopts[i].val;
|
||||||
}
|
}
|
||||||
if (argv[optind][1] == '-') {
|
if (argv[musl_optind][1] == '-') {
|
||||||
optopt = 0;
|
musl_optopt = 0;
|
||||||
if (!colon && opterr)
|
if (!colon && musl_opterr)
|
||||||
musl_getopt_msg(argv[0], cnt ?
|
musl_getopt_msg(argv[0], cnt ?
|
||||||
": option is ambiguous: " :
|
": option is ambiguous: " :
|
||||||
": unrecognized option: ",
|
": unrecognized option: ",
|
||||||
argv[optind]+2,
|
argv[musl_optind] + 2,
|
||||||
strlen(argv[optind]+2));
|
strlen(argv[musl_optind] + 2));
|
||||||
optind++;
|
musl_optind++;
|
||||||
return '?';
|
return '?';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -973,17 +973,17 @@ do { \
|
|||||||
char *endptr; \
|
char *endptr; \
|
||||||
unsigned long tmp; \
|
unsigned long tmp; \
|
||||||
\
|
\
|
||||||
if (optarg[0] == 0) { \
|
if (musl_optarg[0] == 0) { \
|
||||||
report("error: Argument to option '" name "' may not be empty\n"); \
|
report("error: Argument to option '" name "' may not be empty\n"); \
|
||||||
} else { \
|
} else { \
|
||||||
if (optarg[0] == '$') { \
|
if (musl_optarg[0] == '$') { \
|
||||||
tmp = strtoul(&optarg[1], &endptr, 16); \
|
tmp = strtoul(&musl_optarg[1], &endptr, 16); \
|
||||||
} else { \
|
} else { \
|
||||||
tmp = strtoul(optarg, &endptr, 0); \
|
tmp = strtoul(musl_optarg, &endptr, 0); \
|
||||||
} \
|
} \
|
||||||
if (*endptr) \
|
if (*endptr) \
|
||||||
report("error: Expected number as argument to option '" name "', got %s\n", \
|
report("error: Expected number as argument to option '" name "', got %s\n", \
|
||||||
optarg); \
|
musl_optarg); \
|
||||||
else if (tmp > 0xFF) \
|
else if (tmp > 0xFF) \
|
||||||
report("error: Argument to option '" name "' is larger than 255: %lu\n", tmp); \
|
report("error: Argument to option '" name "' is larger than 255: %lu\n", tmp); \
|
||||||
else \
|
else \
|
||||||
@@ -1003,8 +1003,8 @@ do { \
|
|||||||
|
|
||||||
case 'f':
|
case 'f':
|
||||||
fixSpec = 0;
|
fixSpec = 0;
|
||||||
while (*optarg) {
|
while (*musl_optarg) {
|
||||||
switch (*optarg) {
|
switch (*musl_optarg) {
|
||||||
#define SPEC_l FIX_LOGO
|
#define SPEC_l FIX_LOGO
|
||||||
#define SPEC_L TRASH_LOGO
|
#define SPEC_L TRASH_LOGO
|
||||||
#define SPEC_h FIX_HEADER_SUM
|
#define SPEC_h FIX_HEADER_SUM
|
||||||
@@ -1041,15 +1041,15 @@ do { \
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "warning: Ignoring '%c' in fix spec\n",
|
fprintf(stderr, "warning: Ignoring '%c' in fix spec\n",
|
||||||
*optarg);
|
*musl_optarg);
|
||||||
#undef or
|
#undef or
|
||||||
}
|
}
|
||||||
optarg++;
|
musl_optarg++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'i':
|
case 'i':
|
||||||
gameID = optarg;
|
gameID = musl_optarg;
|
||||||
len = strlen(gameID);
|
len = strlen(gameID);
|
||||||
if (len > 4) {
|
if (len > 4) {
|
||||||
len = 4;
|
len = 4;
|
||||||
@@ -1069,7 +1069,7 @@ do { \
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'k':
|
case 'k':
|
||||||
newLicensee = optarg;
|
newLicensee = musl_optarg;
|
||||||
len = strlen(newLicensee);
|
len = strlen(newLicensee);
|
||||||
if (len > 2) {
|
if (len > 2) {
|
||||||
len = 2;
|
len = 2;
|
||||||
@@ -1085,14 +1085,15 @@ do { \
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'm':
|
case 'm':
|
||||||
cartridgeType = parseMBC(optarg);
|
cartridgeType = parseMBC(musl_optarg);
|
||||||
if (cartridgeType == MBC_BAD) {
|
if (cartridgeType == MBC_BAD) {
|
||||||
report("error: Unknown MBC \"%s\"\n", optarg);
|
report("error: Unknown MBC \"%s\"\n", musl_optarg);
|
||||||
} else if (cartridgeType == MBC_WRONG_FEATURES) {
|
} else if (cartridgeType == MBC_WRONG_FEATURES) {
|
||||||
report("error: Features incompatible with MBC (\"%s\")\n", optarg);
|
report("error: Features incompatible with MBC (\"%s\")\n",
|
||||||
|
musl_optarg);
|
||||||
} else if (cartridgeType == MBC_BAD_RANGE) {
|
} else if (cartridgeType == MBC_BAD_RANGE) {
|
||||||
report("error: Specified MBC ID out of range 0-255: %s\n",
|
report("error: Specified MBC ID out of range 0-255: %s\n",
|
||||||
optarg);
|
musl_optarg);
|
||||||
} else if (cartridgeType == ROM_RAM || cartridgeType == ROM_RAM_BATTERY) {
|
} else if (cartridgeType == ROM_RAM || cartridgeType == ROM_RAM_BATTERY) {
|
||||||
fprintf(stderr, "warning: ROM+RAM / ROM+RAM+BATTERY are under-specified and poorly supported\n");
|
fprintf(stderr, "warning: ROM+RAM / ROM+RAM+BATTERY are under-specified and poorly supported\n");
|
||||||
}
|
}
|
||||||
@@ -1115,7 +1116,7 @@ do { \
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
title = optarg;
|
title = musl_optarg;
|
||||||
len = strlen(title);
|
len = strlen(title);
|
||||||
uint8_t maxLen = maxTitleLen();
|
uint8_t maxLen = maxTitleLen();
|
||||||
|
|
||||||
@@ -1170,7 +1171,7 @@ do { \
|
|||||||
"warning: SGB compatibility enabled, but old licensee is %#x, not 0x33\n",
|
"warning: SGB compatibility enabled, but old licensee is %#x, not 0x33\n",
|
||||||
oldLicensee);
|
oldLicensee);
|
||||||
|
|
||||||
argv += optind;
|
argv += musl_optind;
|
||||||
bool failed = nbErrors;
|
bool failed = nbErrors;
|
||||||
|
|
||||||
if (!*argv) {
|
if (!*argv) {
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ int main(int argc, char *argv[])
|
|||||||
opts.attrmapout = true;
|
opts.attrmapout = true;
|
||||||
break;
|
break;
|
||||||
case 'a':
|
case 'a':
|
||||||
opts.attrmapfile = optarg;
|
opts.attrmapfile = musl_optarg;
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
opts.colorcurve = true;
|
opts.colorcurve = true;
|
||||||
@@ -105,7 +105,7 @@ int main(int argc, char *argv[])
|
|||||||
opts.debug = true;
|
opts.debug = true;
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
depth = strtoul(optarg, NULL, 0);
|
depth = strtoul(musl_optarg, NULL, 0);
|
||||||
break;
|
break;
|
||||||
case 'F':
|
case 'F':
|
||||||
opts.hardfix = true;
|
opts.hardfix = true;
|
||||||
@@ -121,19 +121,19 @@ int main(int argc, char *argv[])
|
|||||||
opts.unique = true;
|
opts.unique = true;
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
opts.outfile = optarg;
|
opts.outfile = musl_optarg;
|
||||||
break;
|
break;
|
||||||
case 'P':
|
case 'P':
|
||||||
opts.palout = true;
|
opts.palout = true;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
opts.palfile = optarg;
|
opts.palfile = musl_optarg;
|
||||||
break;
|
break;
|
||||||
case 'T':
|
case 'T':
|
||||||
opts.tilemapout = true;
|
opts.tilemapout = true;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
opts.tilemapfile = optarg;
|
opts.tilemapfile = musl_optarg;
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
opts.unique = true;
|
opts.unique = true;
|
||||||
@@ -145,15 +145,15 @@ int main(int argc, char *argv[])
|
|||||||
opts.verbose = true;
|
opts.verbose = true;
|
||||||
break;
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
opts.trim = strtoul(optarg, NULL, 0);
|
opts.trim = strtoul(musl_optarg, NULL, 0);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
print_usage();
|
print_usage();
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
argc -= optind;
|
argc -= musl_optind;
|
||||||
argv += optind;
|
argv += musl_optind;
|
||||||
|
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
fputs("FATAL: no input files\n", stderr);
|
fputs("FATAL: no input files\n", stderr);
|
||||||
|
|||||||
@@ -217,23 +217,23 @@ int main(int argc, char *argv[])
|
|||||||
isWRA0Mode = true;
|
isWRA0Mode = true;
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
linkerScriptName = optarg;
|
linkerScriptName = musl_optarg;
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
mapFileName = optarg;
|
mapFileName = musl_optarg;
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
symFileName = optarg;
|
symFileName = musl_optarg;
|
||||||
break;
|
break;
|
||||||
case 'O':
|
case 'O':
|
||||||
overlayFileName = optarg;
|
overlayFileName = musl_optarg;
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
outputFileName = optarg;
|
outputFileName = musl_optarg;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
value = strtoul(optarg, &endptr, 0);
|
value = strtoul(musl_optarg, &endptr, 0);
|
||||||
if (optarg[0] == '\0' || *endptr != '\0') {
|
if (musl_optarg[0] == '\0' || *endptr != '\0') {
|
||||||
error(NULL, 0, "Invalid argument for option 'p'");
|
error(NULL, 0, "Invalid argument for option 'p'");
|
||||||
value = 0xFF;
|
value = 0xFF;
|
||||||
}
|
}
|
||||||
@@ -245,7 +245,7 @@ int main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
/* FIXME: nobody knows what this does, figure it out */
|
/* FIXME: nobody knows what this does, figure it out */
|
||||||
(void)optarg;
|
(void)musl_optarg;
|
||||||
warning(NULL, 0, "Nobody has any idea what `-s` does");
|
warning(NULL, 0, "Nobody has any idea what `-s` does");
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
@@ -271,7 +271,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int curArgIndex = optind;
|
int curArgIndex = musl_optind;
|
||||||
|
|
||||||
/* If no input files were specified, the user must have screwed up */
|
/* If no input files were specified, the user must have screwed up */
|
||||||
if (curArgIndex == argc) {
|
if (curArgIndex == argc) {
|
||||||
|
|||||||
Reference in New Issue
Block a user