Mercurial > hg > early-roguelike
comparison urogue/options.c @ 293:9dcf3344d3fd
UltraRogue: fix changing the score option.
Changing the score file now works again, if use_savedir is not set. If
it is, an error message is shown.
| author | John "Elwin" Edwards |
|---|---|
| date | Fri, 29 Dec 2017 17:38:08 -0500 |
| parents | 2b452dbf0138 |
| children | 0250220d8cdd |
comparison
equal
deleted
inserted
replaced
| 292:ebf49a933e51 | 293:9dcf3344d3fd |
|---|---|
| 22 | 22 |
| 23 #define NUM_OPTS (sizeof optlist / sizeof (OPTION)) | 23 #define NUM_OPTS (sizeof optlist / sizeof (OPTION)) |
| 24 #define EQSTR(a, b, c) (strncmp(a, b, c) == 0) | 24 #define EQSTR(a, b, c) (strncmp(a, b, c) == 0) |
| 25 | 25 |
| 26 int get_restr(opt_arg *opt, WINDOW *win); | 26 int get_restr(opt_arg *opt, WINDOW *win); |
| 27 int get_score(opt_arg *opt, WINDOW *win); | |
| 27 | 28 |
| 28 /* description of an option and what to do with it */ | 29 /* description of an option and what to do with it */ |
| 29 static OPTION optlist[] = | 30 static OPTION optlist[] = |
| 30 { | 31 { |
| 31 {"jump","Show position only at end of run (jump): ", &jump,put_bool,get_bool}, | 32 {"jump","Show position only at end of run (jump): ", &jump,put_bool,get_bool}, |
| 33 {"askme","Ask me about unidentified things (askme): ",&askme,put_bool,get_bool}, | 34 {"askme","Ask me about unidentified things (askme): ",&askme,put_bool,get_bool}, |
| 34 {"doorstop","Stop running when adjacent (doorstop): ",&doorstop,put_bool,get_bool}, | 35 {"doorstop","Stop running when adjacent (doorstop): ",&doorstop,put_bool,get_bool}, |
| 35 {"name", "Name (name): ", &whoami, put_str, get_restr}, | 36 {"name", "Name (name): ", &whoami, put_str, get_restr}, |
| 36 {"fruit", "Fruit (fruit): ", &fruit, put_str, get_str}, | 37 {"fruit", "Fruit (fruit): ", &fruit, put_str, get_str}, |
| 37 {"file", "Save file (file): ", &file_name, put_str, get_restr}, | 38 {"file", "Save file (file): ", &file_name, put_str, get_restr}, |
| 38 {"score", "Score file (score): ", &score_file, put_str, get_restr}, | 39 {"score", "Score file (score): ", &score_file, put_str, get_score}, |
| 39 {"class", "Character class (class): ",&char_type, put_abil, get_abil} | 40 {"class", "Character class (class): ",&char_type, put_abil, get_abil} |
| 40 }; | 41 }; |
| 41 | 42 |
| 42 /* | 43 /* |
| 43 option() | 44 option() |
| 581 wmove(win, ny, nx); | 582 wmove(win, ny, nx); |
| 582 waddch(win, '\n'); | 583 waddch(win, '\n'); |
| 583 | 584 |
| 584 return(NORM); | 585 return(NORM); |
| 585 } | 586 } |
| 587 | |
| 588 int | |
| 589 get_score(opt_arg *opt, WINDOW *win) | |
| 590 { | |
| 591 char old_score_file[2*LINELEN]; | |
| 592 int status; | |
| 593 | |
| 594 if (use_savedir) | |
| 595 return get_restr(opt, win); | |
| 596 | |
| 597 strncpy(old_score_file, opt->str, 2*LINELEN); | |
| 598 old_score_file[2*LINELEN - 1] = '\0'; | |
| 599 status = get_str(opt, win); | |
| 600 if (status == NORM && strcmp(old_score_file, opt->str)) { | |
| 601 fclose(fd_score); | |
| 602 fd_score = fopen(score_file, "r+"); | |
| 603 if (fd_score == NULL) | |
| 604 fd_score = fopen(score_file, "a+"); | |
| 605 } | |
| 606 return status; | |
| 607 } |
