Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate extern getopt implementation from the unistd.h one #728

Merged
merged 1 commit into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/extern/getopt.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
#ifndef RGBDS_EXTERN_GETOPT_H
#define RGBDS_EXTERN_GETOPT_H

extern char *optarg;
extern int optind, opterr, optopt, optreset;
extern char *musl_optarg;
extern int musl_optind, musl_opterr, musl_optopt, musl_optreset;

struct option {
const char *name;
Expand Down
44 changes: 22 additions & 22 deletions src/asm/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,20 +177,20 @@ int main(int argc, char *argv[])
while ((ch = musl_getopt_long_only(argc, argv, optstring, longopts, NULL)) != -1) {
switch (ch) {
case 'b':
if (strlen(optarg) == 2)
opt_B(&optarg[1]);
if (strlen(musl_optarg) == 2)
opt_B(&musl_optarg[1]);
else
errx(1, "Must specify exactly 2 characters for option 'b'");
break;

char *equals;
case 'D':
equals = strchr(optarg, '=');
equals = strchr(musl_optarg, '=');
if (equals) {
*equals = '\0';
sym_AddString(optarg, equals + 1);
sym_AddString(musl_optarg, equals + 1);
} else {
sym_AddString(optarg, "1");
sym_AddString(musl_optarg, "1");
}
break;

Expand All @@ -199,8 +199,8 @@ int main(int argc, char *argv[])
break;

case 'g':
if (strlen(optarg) == 4)
opt_G(&optarg[1]);
if (strlen(musl_optarg) == 4)
opt_G(&musl_optarg[1]);
else
errx(1, "Must specify exactly 4 characters for option 'g'");
break;
Expand All @@ -210,31 +210,31 @@ int main(int argc, char *argv[])
break;

case 'i':
fstk_AddIncludePath(optarg);
fstk_AddIncludePath(musl_optarg);
break;

case 'L':
optimizeloads = false;
break;

case 'M':
if (!strcmp("-", optarg))
if (!strcmp("-", musl_optarg))
dependfile = stdout;
else
dependfile = fopen(optarg, "w");
dependfile = fopen(musl_optarg, "w");
if (dependfile == NULL)
err(1, "Could not open dependfile %s", optarg);
err(1, "Could not open dependfile %s", musl_optarg);
break;

case 'o':
out_SetFileName(optarg);
out_SetFileName(musl_optarg);
break;

unsigned long fill;
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'");

if (fill < 0 || fill > 0xFF)
Expand All @@ -244,9 +244,9 @@ int main(int argc, char *argv[])
break;

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'");
break;

Expand All @@ -258,7 +258,7 @@ int main(int argc, char *argv[])
break;

case 'W':
processWarningFlag(optarg);
processWarningFlag(musl_optarg);
break;

case 'w':
Expand All @@ -278,9 +278,9 @@ int main(int argc, char *argv[])

case 'Q':
case 'T':
if (optind == argc)
if (musl_optind == argc)
errx(1, "-M%c takes a target file name argument", depType);
ep = optarg;
ep = musl_optarg;
if (depType == 'Q')
ep = make_escape(ep);

Expand Down Expand Up @@ -317,15 +317,15 @@ int main(int argc, char *argv[])
if (tzTargetFileName == NULL)
tzTargetFileName = tzObjectname;

if (argc == optind) {
if (argc == musl_optind) {
fputs("FATAL: No input files\n", stderr);
print_usage();
} else if (argc != optind + 1) {
} else if (argc != musl_optind + 1) {
fputs("FATAL: More than one input file given\n", stderr);
print_usage();
}

char const *mainFileName = argv[optind];
char const *mainFileName = argv[musl_optind];

if (verbose)
printf("Assembling %s\n", mainFileName);
Expand Down
Loading