Skip to content

Commit a4626ea

Browse files
committed
command line options working properly
1 parent 387b2cf commit a4626ea

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/main.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#define USAGE_MESSAGE "Usage: raycaster [-h] [-c] mapname\n"
1515
#define DESCRIPTION_MESSAGE "Runs the raycaster, loading the specified map file.\n"
16+
#define NO_MAP_MESSAGE "Must specify a map file to load!\n"
1617

1718
float min(float v1, float v2) {
1819
return v1 < v2 ? v1 : v2;
@@ -22,12 +23,12 @@ int main(int argc, char* argv[]) {
2223
// Argument handling
2324
if (argc <= 1) {
2425
fprintf(stderr, USAGE_MESSAGE);
25-
fprintf(stderr, "Must specify a map file to load!\n");
26+
fprintf(stderr, NO_MAP_MESSAGE);
2627

2728
return EXIT_FAILURE;
2829
}
2930

30-
const char* map_name;
31+
const char* map_name = NULL;
3132
bool uncapped = false;
3233
for (int i = 1; i < argc; i++) {
3334
if (strncmp(argv[i], "-h", 2) == 0) {
@@ -40,6 +41,12 @@ int main(int argc, char* argv[]) {
4041
map_name = argv[i];
4142
}
4243
}
44+
if (map_name == NULL) {
45+
fprintf(stderr, USAGE_MESSAGE);
46+
fprintf(stderr, NO_MAP_MESSAGE);
47+
48+
return EXIT_FAILURE;
49+
}
4350

4451
// Tell the window to use vsync when capping fps and work on high DPI displays
4552
if (uncapped) {

0 commit comments

Comments
 (0)