comparison xrogue/options.c @ 145:aac28331e71d

Advanced Rogue family: fix the "score" option. Changing the score file (when permitted) now works again, closing the old score file and opening the new one.
author John "Elwin" Edwards
date Wed, 20 May 2015 08:42:17 -0400
parents 443c8bd3e290
children f54901b9c39b
comparison
equal deleted inserted replaced
144:708bb2dea17c 145:aac28331e71d
50 get_quest(), 50 get_quest(),
51 put_quest(), 51 put_quest(),
52 get_default(); 52 get_default();
53 53
54 int get_str_prot(char *opt, WINDOW *win); 54 int get_str_prot(char *opt, WINDOW *win);
55 int get_score(char *opt, WINDOW *win);
55 bool allowchange(OPTION *op); 56 bool allowchange(OPTION *op);
56 57
57 OPTION optlist[] = { 58 OPTION optlist[] = {
58 {"terse", "Terse output: ", 59 {"terse", "Terse output: ",
59 (int *) &terse, put_bool, get_bool }, 60 (int *) &terse, put_bool, get_bool },
72 {"name", "Name: ", 73 {"name", "Name: ",
73 (int *) whoami, put_str, get_str_prot }, 74 (int *) whoami, put_str, get_str_prot },
74 {"file", "Save file: ", 75 {"file", "Save file: ",
75 (int *) file_name, put_str, get_str_prot }, 76 (int *) file_name, put_str, get_str_prot },
76 {"score", "Score file: ", 77 {"score", "Score file: ",
77 (int *) score_file, put_str, get_str_prot }, 78 (int *) score_file, put_str, get_score },
78 {"class", "Character type: ", 79 {"class", "Character type: ",
79 (int *) &char_type, put_abil, get_abil }, 80 (int *) &char_type, put_abil, get_abil },
80 {"quest", "Quest item: ", 81 {"quest", "Quest item: ",
81 (int *) &quest_item, put_quest, get_quest }, 82 (int *) &quest_item, put_quest, get_quest },
82 {"default", "Default Attributes: ", 83 {"default", "Default Attributes: ",
519 else { 520 else {
520 return get_str(opt, win); 521 return get_str(opt, win);
521 } 522 }
522 } 523 }
523 524
525 /* When getting the scorefile, the new file must be opened. */
526 int
527 get_score(char *optstr, WINDOW *win)
528 {
529 char old_score_file[LINELEN];
530 int status;
531
532 if (use_savedir)
533 return get_str_prot(optstr, win);
534
535 strcpy(old_score_file, optstr);
536 status = get_str(optstr, win);
537 if (status == NORM && strcmp(old_score_file, optstr))
538 {
539 if (scorefi != NULL)
540 fclose(scorefi);
541 scorefi = fopen(score_file, "rb+");
542 if (scorefi == NULL)
543 scorefi = fopen(score_file, "wb+");
544 }
545 return status;
546 }
547
524 bool 548 bool
525 allowchange(OPTION *op) 549 allowchange(OPTION *op)
526 { 550 {
527 if (!use_savedir) 551 if (!use_savedir)
528 return TRUE; 552 return TRUE;