Mercurial > hg > forks > yadex
changeset 75:e6175d0a667b
Get rid of the mostly useless find_level() and associated logic.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 26 Sep 2011 13:44:40 +0300 |
parents | db03e604eea3 |
children | 042b44809e6e |
files | src/editlev.cc src/editlev.h src/yadex.cc |
diffstat | 3 files changed, 1 insertions(+), 120 deletions(-) [+] |
line wrap: on
line diff
--- a/src/editlev.cc Mon Sep 26 12:52:49 2011 +0300 +++ b/src/editlev.cc Mon Sep 26 13:44:40 2011 +0300 @@ -47,103 +47,6 @@ /* - * find_level - * Look in the master directory for levels that match - * the name in <name_given>. - * - * <name_given> can have one of the following formats : - * - * [Ee]n[Mm]m EnMm - * [Mm][Aa][Pp]nm MAPnm - * n MAP0n - * nm Either EnMn or MAPnm - * ijk EiMjk (Doom alpha 0.4 and 0.5) - * - * Return: - * - If <name_given> is either [Ee]n[Mm]m or [Mm][Aa][Pp]nm, - * - if the level was found, its canonical (uppercased) - * name in a freshly malloc'd buffer, - * - else, NULL. - * - If <name_given> is either n or nm, - * - if either EnMn or MAPnm was found, the canonical name - * of the level found, in a freshly malloc'd buffer, - * - if none was found, <error_none>, - * - if the <name_given> is invalid, <error_invalid>, - * - if several were found, <error_non_unique>. - */ -char *find_level(const char *name_given) -{ -// Is it a shorthand name ? ("1", "23", ...) - if (al_sisnum(name_given) - && (atoi(name_given) <= 99 - || atoi(name_given) <= 999 && yg_level_name == YGLN_E1M10)) - { - int n = atoi(name_given); - char *name1 = (char *) malloc(7); - char *name2 = (char *) malloc(6); - if (n > 99) - sprintf(name1, "E%dM%02d", n / 100, n % 100); - else - sprintf(name1, "E%dM%d", n / 10, n % 10); - sprintf(name2, "MAP%02d", n); - int match1 = FindMasterDir(MasterDir, name1) != NULL; - int match2 = FindMasterDir(MasterDir, name2) != NULL; - if (match1 && !match2) // Found only ExMy - { - free(name2); - return name1; - } - else if (match2 && !match1) // Found only MAPxy - { - free(name1); - return name2; - } - else if (match1 && match2) // Found both - { - free(name1); - free(name2); - return error_non_unique; - } - else // Found none - { - free(name1); - free(name2); - return error_none; - } - } - -#if 1 -// Else look for <name_given> - if (FindMasterDir(MasterDir, name_given)) - return al_sdup(name_given); - else - { - if (levelname2levelno(name_given)) - return NULL; - else - return error_invalid; - } -#else -// If <name_given> is "[Ee]n[Mm]m" or "[Mm][Aa][Pp]nm", look for that - if (levelname2levelno(name_given)) - { - char *canonical_name = strdup(name_given); - for (char *p = canonical_name; *p; p++) - *p = toupper(*p); // But shouldn't FindMasterDir() be case-insensitive ? - if (FindMasterDir(MasterDir, canonical_name)) - return canonical_name; - else - { - free(canonical_name); - return NULL; - } - } - return error_invalid; -#endif -} - - -/* the driving program */
--- a/src/editlev.h Mon Sep 26 12:52:49 2011 +0300 +++ b/src/editlev.h Mon Sep 26 13:44:40 2011 +0300 @@ -4,5 +4,4 @@ */ -char *find_level(const char *name_given); void EditLevel(const char *, bool);
--- a/src/yadex.cc Mon Sep 26 12:52:49 2011 +0300 +++ b/src/yadex.cc Mon Sep 26 13:44:40 2011 +0300 @@ -700,26 +700,7 @@ level_name = 0; else { - level_name = find_level(com); - if (level_name == error_invalid) - { - printf("\"%s\" is not a valid level name.\n", com); - continue; - } - else if (level_name == error_none) - { - printf("Neither E%dM%d nor MAP%02d exist.\n", - atoi(com) / 10, atoi(com) % 10, atoi(com)); - continue; - } - else if (level_name == error_non_unique) - { - printf - ("Both E%dM%d and MAP%02d exist. Use an unambiguous name.\n", - atoi(com) / 10, atoi(com) % 10, atoi(com)); - continue; - } - else if (level_name == NULL) + if (FindMasterDir(MasterDir, com)) { printf("Level %s not found.", com); // Hint absent-minded users @@ -733,8 +714,6 @@ } } EditLevel(level_name, newlevel); - if (level_name) - free(level_name); } /* user asked to build a new main wad file */