Skip to content

Commit

Permalink
Consistent behavior with missing or incorrect parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Rangi42 committed Oct 25, 2023
1 parent 944c5f0 commit bab1ec3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
2 changes: 2 additions & 0 deletions include/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@
#if defined(_MSC_VER) || defined(__MINGW32__)
# include <io.h>
# define setmode(fd, mode) _setmode(fd, mode)
# define isatty(fd) _isatty(fd)
#else
# define setmode(fd, mode) (0)
# define isatty(fd) (0)
#endif

#endif // RGBDS_PLATFORM_H
2 changes: 1 addition & 1 deletion src/asm/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ static struct option const longopts[] = {
{ NULL, no_argument, NULL, 0 }
};

static void print_usage(void)
_Noreturn static void print_usage(void)
{
fputs(
"Usage: rgbasm [-EHhLlVvw] [-b chars] [-D name[=value]] [-g chars] [-I path]\n"
Expand Down
9 changes: 6 additions & 3 deletions src/fix/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static struct option const longopts[] = {
{ NULL, no_argument, NULL, 0 }
};

static void printUsage(void)
_Noreturn static void printUsage(void)
{
fputs(
"Usage: rgbfix [-jOsVv] [-C | -c] [-f <fix_spec>] [-i <game_id>] [-k <licensee>]\n"
Expand All @@ -78,6 +78,7 @@ static void printUsage(void)
"\n"
"For help, use `man rgbfix' or go to https://rgbds.gbdev.io/docs/\n",
stderr);
exit(1);
}

static uint8_t nbErrors;
Expand Down Expand Up @@ -1401,9 +1402,7 @@ do { \
break;

default:
fprintf(stderr, "FATAL: unknown option '%c'\n", ch);
printUsage();
exit(1);
}
#undef parseByte
}
Expand Down Expand Up @@ -1443,6 +1442,10 @@ do { \
bool failed = nbErrors;

if (!*argv) {
if (isatty(STDIN_FILENO)) {
fputs("FATAL: Please specify an input file (pass `-` to read from standard input)\n", stderr);
printUsage();
}
failed |= processFilename("-");
} else {
do {
Expand Down
8 changes: 3 additions & 5 deletions src/gfx/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static struct option const longopts[] = {
{NULL, no_argument, NULL, 0 }
};

static void printUsage(void) {
[[noreturn]] static void printUsage(void) {
fputs("Usage: rgbgfx [-r stride] [-CmuVZ] [-v [-v ...]] [-a <attr_map> | -A]\n"
" [-b <base_ids>] [-c <colors>] [-d <depth>] [-L <slice>] [-N <nb_tiles>]\n"
" [-n <nb_pals>] [-o <out_file>] [-p <pal_file> | -P] [-q <pal_map> | -Q]\n"
Expand Down Expand Up @@ -241,11 +241,9 @@ static void registerInput(char const *arg) {
"\"%s\")\n",
options.input.c_str(), arg);
printUsage();
exit(1);
} else if (arg[0] == '\0') { // Empty input path
fprintf(stderr, "FATAL: input image path cannot be empty!\n");
printUsage();
exit(1);
} else {
options.input = arg;
}
Expand Down Expand Up @@ -573,7 +571,6 @@ static char *parseArgv(int argc, char **argv, bool &autoAttrmap, bool &autoTilem
break;
default:
printUsage();
exit(1);
}
}

Expand Down Expand Up @@ -769,7 +766,8 @@ int main(int argc, char *argv[]) {
}

if (options.input.empty()) {
fatal("No input image specified");
fputs("FATAL: No input image specified\n", stderr);
printUsage();
}

// Do not do anything if option parsing went wrong
Expand Down
8 changes: 3 additions & 5 deletions src/link/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ static struct option const longopts[] = {
{ NULL, no_argument, NULL, 0 }
};

// Prints the program's usage to stdout.
static void printUsage(void)
_Noreturn static void printUsage(void)
{
fputs(
"Usage: rgblink [-dMtVvwx] [-l script] [-m map_file] [-n sym_file]\n"
Expand All @@ -214,6 +213,7 @@ static void printUsage(void)
"\n"
"For help, use `man rgblink' or go to https://rgbds.gbdev.io/docs/\n",
stderr);
exit(1);
}

// Cleans up what has been done
Expand Down Expand Up @@ -435,17 +435,15 @@ int main(int argc, char *argv[])
break;
default:
printUsage();
exit(1);
}
}

int curArgIndex = musl_optind;

// If no input files were specified, the user must have screwed up
if (curArgIndex == argc) {
fputs("FATAL: no input files\n", stderr);
fputs("FATAL: Please specify an input file (pass `-` to read from standard input)\n", stderr);
printUsage();
exit(1);
}

// Patch the size array depending on command-line options
Expand Down

0 comments on commit bab1ec3

Please sign in to comment.