make the game more tolerant of DOS limitations
This commit is contained in:
parent
3ce64b9984
commit
8bf21c3efd
@ -17,10 +17,10 @@
|
||||
|
||||
/* DOS path definitions */
|
||||
#define PATH_SEP "\\"
|
||||
#define WORDLIST_PATH_1 "words"
|
||||
#define WORDLIST_PATH_2 "C:\\CORDLE\\words"
|
||||
#define WORDLIST_PATH_4 "D:\\CORDLE\\words"
|
||||
#define WORDLIST_PATH_3 NULL
|
||||
#define WORDLIST_PATH_1 "WORDS"
|
||||
#define WORDLIST_PATH_2 "D:\\CORDLE\\WORDS"
|
||||
#define WORDLIST_PATH_3 "C:\\CORDLE\\WORDS"
|
||||
#define WORDLIST_PATH_4 NULL
|
||||
|
||||
/* DOS doesn't have HOME environment variable */
|
||||
#define HAS_HOME_ENV 0
|
||||
@ -30,9 +30,10 @@
|
||||
|
||||
/* Unix path definitions */
|
||||
#define PATH_SEP "/"
|
||||
#define WORDLIST_PATH_1 "words"
|
||||
#define WORDLIST_PATH_2 "/usr/local/share/cordle/words"
|
||||
#define WORDLIST_PATH_3_FMT "%s/.local/share/cordle/words"
|
||||
#define WORDLIST_PATH_1 "WORDS"
|
||||
#define WORDLIST_PATH_2 "/usr/local/share/cordle/WORDS"
|
||||
#define WORDLIST_PATH_3 "%s/.local/share/cordle/WORDS""
|
||||
#define WORDLIST_PATH_3_FMT "%s/.local/share/cordle/WORDS"
|
||||
|
||||
#define HAS_HOME_ENV 1
|
||||
#endif
|
||||
|
||||
22
src/main.c
22
src/main.c
@ -19,30 +19,30 @@ static void parse_arguments(int argc, char **argv, char *filename, char *difficu
|
||||
int i;
|
||||
|
||||
/* Default values */
|
||||
strcpy(filename, "cordle_words_easy.txt");
|
||||
strcpy(difficulty, "EASY");
|
||||
strcpy(filename, "default.txt");
|
||||
strcpy(difficulty, "DEFAULT");
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (strcmp(argv[i], "--easy") == 0) {
|
||||
strcpy(filename, "cordle_words_easy.txt");
|
||||
strcpy(filename, "easy.txt");
|
||||
strcpy(difficulty, "EASY");
|
||||
} else if (strcmp(argv[i], "--medium") == 0) {
|
||||
strcpy(filename, "cordle_words_medium.txt");
|
||||
strcpy(filename, "medium.txt");
|
||||
strcpy(difficulty, "MEDIUM");
|
||||
} else if (strcmp(argv[i], "--hard") == 0) {
|
||||
strcpy(filename, "cordle_words_hard.txt");
|
||||
strcpy(filename, "hard.txt");
|
||||
strcpy(difficulty, "HARD");
|
||||
} else if (strcmp(argv[i], "--techy") == 0) {
|
||||
strcpy(filename, "cordle_words_techy.txt");
|
||||
strcpy(filename, "techy.txt");
|
||||
strcpy(difficulty, "TECHNICAL");
|
||||
} else if (strcmp(argv[i], "--literary") == 0) {
|
||||
strcpy(filename, "cordle_words_literary.txt");
|
||||
strcpy(filename, "literary.txt");
|
||||
strcpy(difficulty, "LITERARY");
|
||||
} else if (strcmp(argv[i], "--cultural") == 0) {
|
||||
strcpy(filename, "cordle_words_cultural.txt");
|
||||
strcpy(filename, "cultural.txt");
|
||||
strcpy(difficulty, "CULTURAL");
|
||||
} else if (strcmp(argv[i], "--full") == 0) {
|
||||
strcpy(filename, "cordle_words_full.txt");
|
||||
strcpy(filename, "full.txt");
|
||||
strcpy(difficulty, "FULL");
|
||||
} else if (strcmp(argv[i], "--wordlist") == 0 && i + 1 < argc) {
|
||||
strcpy(filename, argv[i + 1]);
|
||||
@ -90,8 +90,8 @@ static int main_game_loop(int argc, char *argv[]) {
|
||||
|
||||
if (!load_words(&game, filename)) {
|
||||
/* Try fallback */
|
||||
if (strcmp(filename, "cordle_words.txt") != 0 &&
|
||||
load_words(&game, "cordle_words.txt")) {
|
||||
if (strcmp(filename, "default.txt") != 0 &&
|
||||
load_words(&game, "default.txt")) {
|
||||
strcpy(difficulty, "DEFAULT");
|
||||
} else {
|
||||
mvaddstr(0, 0, "Error: Could not load word list");
|
||||
|
||||
10
src/words.c
10
src/words.c
@ -18,16 +18,22 @@ static FILE *open_wordlist(const char *filename) {
|
||||
const char *home;
|
||||
#endif
|
||||
|
||||
/* Try 1: wordlists/ relative to the current directory (for development) */
|
||||
/* Try 1: WORDS/ relative to the current directory (for development) */
|
||||
sprintf(filepath, "%s%s%s", WORDLIST_PATH_1, PATH_SEP, filename);
|
||||
file = fopen(filepath, "r");
|
||||
if (file) return file;
|
||||
|
||||
/* Try 2: system installation path */
|
||||
/* Try 2: D drive installation path */
|
||||
sprintf(filepath, "%s%s%s", WORDLIST_PATH_2, PATH_SEP, filename);
|
||||
file = fopen(filepath, "r");
|
||||
if (file) return file;
|
||||
|
||||
/* Try 2: C drive installation path */
|
||||
sprintf(filepath, "%s%s%s", WORDLIST_PATH_3, PATH_SEP, filename);
|
||||
file = fopen(filepath, "r");
|
||||
if (file) return file;
|
||||
|
||||
|
||||
#if HAS_HOME_ENV
|
||||
/* Try 3: ${HOME}/.local/share/cordle/wordlists/ (Unix user installation) */
|
||||
home = getenv("HOME");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user