Mercurial > hg > forks > yadex
changeset 12:cc5de2dcf008
Clean up the option checking code slightly.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 24 Sep 2011 08:43:19 +0300 |
parents | b37408bf0064 |
children | 40c5d2879627 |
files | src/yadex.cc |
diffstat | 1 files changed, 43 insertions(+), 114 deletions(-) [+] |
line wrap: on
line diff
--- a/src/yadex.cc Sat Sep 24 08:10:11 2011 +0300 +++ b/src/yadex.cc Sat Sep 24 08:43:19 2011 +0300 @@ -168,6 +168,26 @@ static const Wad_file *wad_by_name (const char *pathname); static bool wad_already_loaded (const char *pathname); +typedef struct { + const char *game, *wadname; + const char **pwadloc; +} GameInfo; + +GameInfo gameList[] = { + { "doom", "doom.wad", &Iwad1 }, + { "doom2", "doom2.wad", &Iwad2 }, + { "heretic", "heretic.wad", &Iwad3 }, + { "hexen", "hexen.wad", &Iwad4 }, + { "strife", "strife1.wad", &Iwad5 }, + { "doom02", "Doom alpha 0.2 IWAD", &Iwad6 }, + { "doom04", "Doom alpha 0.4 IWAD", &Iwad7 }, + { "doom05", "Doom alpha 0.5 IWAD", &Iwad8 }, + { "doompr", "Doom Press Release IWAD", &Iwad9 }, + { "strife10", "strife1.wad", &Iwad10 } +}; + +const int ngameList = sizeof(gameList) / sizeof(gameList[0]); + /* * main @@ -248,127 +268,36 @@ exit (1); } -if (Game != NULL && strcmp (Game, "doom") == 0) - { - if (Iwad1 == NULL) - { - err ("You have to tell me where doom.wad is."); - fprintf (stderr, - "Use \"-i1 <file>\" or put \"iwad1=<file>\" in yadex.cfg.\n"); - exit (1); - } - MainWad = Iwad1; - } -else if (Game != NULL && strcmp (Game, "doom2") == 0) - { - if (Iwad2 == NULL) - { - err ("You have to tell me where doom2.wad is."); - fprintf (stderr, - "Use \"-i2 <file>\" or put \"iwad2=<file>\" in yadex.cfg.\n"); - exit (1); +if (Game != NULL) { + int n; + for (n = 0; n < ngameList; n++) { + GameInfo *info = &gameList[n]; + if (strcmp(Game, info->game) == 0) { + if (*(info->pwadloc) == NULL) { + err("You have to tell me where %s is.", info->wadname); + fprintf(stderr, + "Use \"-i%d <file>\" or put \"iwad%d=<file>\" in yadex.cfg\n", + n+1, n+1); + exit(1); + } + MainWad = *(info->pwadloc); } - MainWad = Iwad2; - } -else if (Game != NULL && strcmp (Game, "heretic") == 0) - { - if (Iwad3 == NULL) - { - err ("You have to tell me where heretic.wad is."); - fprintf (stderr, - "Use \"-i3 <file>\" or put \"iwad3=<file>\" in yadex.cfg.\n"); - exit (1); - } - MainWad = Iwad3; - } -else if (Game != NULL && strcmp (Game, "hexen") == 0) - { - if (Iwad4 == NULL) - { - err ("You have to tell me where hexen.wad is."); - fprintf (stderr, - "Use \"-i4 <file>\" or put \"iwad4=<file>\" in yadex.cfg.\n"); - exit (1); - } - MainWad = Iwad4; - } -else if (Game != NULL && strcmp (Game, "strife") == 0) - { - if (Iwad5 == NULL) - { - err ("You have to tell me where strife1.wad is."); - fprintf (stderr, - "Use \"-i5 <file>\" or put \"iwad5=<file>\" in yadex.cfg.\n"); - exit (1); - } - MainWad = Iwad5; } -else if (Game != NULL && strcmp (Game, "doom02") == 0) - { - if (Iwad6 == NULL) - { - err ("You have to tell me where the Doom alpha 0.2 iwad is."); - fprintf (stderr, - "Use \"-i6 <file>\" or put \"iwad6=<file>\" in yadex.cfg.\n"); - exit (1); - } - MainWad = Iwad6; - } -else if (Game != NULL && strcmp (Game, "doom04") == 0) - { - if (Iwad7 == NULL) - { - err ("You have to tell me where the Doom alpha 0.4 iwad is."); - fprintf (stderr, - "Use \"-i7 <file>\" or put \"iwad7=<file>\" in yadex.cfg.\n"); - exit (1); - } - MainWad = Iwad7; - } -else if (Game != NULL && strcmp (Game, "doom05") == 0) - { - if (Iwad8 == NULL) - { - err ("You have to tell me where the Doom alpha 0.5 iwad is."); - fprintf (stderr, - "Use \"-i8 <file>\" or put \"iwad8=<file>\" in yadex.cfg.\n"); - exit (1); - } - MainWad = Iwad8; - } -else if (Game != NULL && strcmp (Game, "doompr") == 0) - { - if (Iwad9 == NULL) - { - err ("You have to tell me where the Doom press release iwad is."); - fprintf (stderr, - "Use \"-i9 <file>\" or put \"iwad9=<file>\" in yadex.cfg.\n"); - exit (1); - } - MainWad = Iwad9; - } -else if (Game != NULL && strcmp (Game, "strife10") == 0) - { - if (Iwad10 == NULL) - { - err ("You have to tell me where strife1.wad is."); - fprintf (stderr, - "Use \"-i10 <file>\" or put \"iwad10=<file>\" in yadex.cfg.\n"); - exit (1); - } - MainWad = Iwad10; - } -else - { +} + +if (MainWad == NULL) { + int n; if (Game == NULL) err ("You didn't say for which game you want to edit."); else err ("Unknown game \"%s\"", Game); fprintf (stderr, - "Use \"-g <game>\" on the command line or put \"game=<game>\" in yadex.cfg\n" - "where <game> is one of \"doom\", \"doom02\", \"doom04\", \"doom05\"," - " \"doom2\",\n\"doompr\", \"heretic\", \"hexen\", \"strife\" and " - "\"strife10\".\n"); + "Use \"-g <game>\" on the command line or put \"game=<game>\" in yadex.cfg\n" + "where <game> is one of: "); + for (n = 0; n < ngameList; n++) { + fprintf(stderr, "%s\"%s\"", n > 0 ? ", " : "", gameList[n].game); + } + fprintf(stderr, ".\n"); exit (1); } if (Debug)