Mercurial > hg > early-roguelike
comparison xrogue/options.c @ 137:443c8bd3e290
xrogue: restrict changes to the save file location.
When using the -n option, disallow changing file_name or whoami via
options or dialogs.
| author | John "Elwin" Edwards |
|---|---|
| date | Sat, 02 May 2015 07:31:14 -0400 |
| parents | ce0cf824c192 |
| children | aac28331e71d |
comparison
equal
deleted
inserted
replaced
| 136:1fbdefa82533 | 137:443c8bd3e290 |
|---|---|
| 48 put_abil(), | 48 put_abil(), |
| 49 get_abil(), | 49 get_abil(), |
| 50 get_quest(), | 50 get_quest(), |
| 51 put_quest(), | 51 put_quest(), |
| 52 get_default(); | 52 get_default(); |
| 53 | |
| 54 int get_str_prot(char *opt, WINDOW *win); | |
| 55 bool allowchange(OPTION *op); | |
| 53 | 56 |
| 54 OPTION optlist[] = { | 57 OPTION optlist[] = { |
| 55 {"terse", "Terse output: ", | 58 {"terse", "Terse output: ", |
| 56 (int *) &terse, put_bool, get_bool }, | 59 (int *) &terse, put_bool, get_bool }, |
| 57 {"flush", "Flush typeahead during battle: ", | 60 {"flush", "Flush typeahead during battle: ", |
| 65 {"pickup", "Pick things up automatically: ", | 68 {"pickup", "Pick things up automatically: ", |
| 66 (int *) &auto_pickup, put_bool, get_bool }, | 69 (int *) &auto_pickup, put_bool, get_bool }, |
| 67 {"overlay", "Overlay menu: ", | 70 {"overlay", "Overlay menu: ", |
| 68 (int *) &menu_overlay, put_bool, get_bool }, | 71 (int *) &menu_overlay, put_bool, get_bool }, |
| 69 {"name", "Name: ", | 72 {"name", "Name: ", |
| 70 (int *) whoami, put_str, get_str }, | 73 (int *) whoami, put_str, get_str_prot }, |
| 71 {"file", "Save file: ", | 74 {"file", "Save file: ", |
| 72 (int *) file_name, put_str, get_str }, | 75 (int *) file_name, put_str, get_str_prot }, |
| 73 {"score", "Score file: ", | 76 {"score", "Score file: ", |
| 74 (int *) score_file, put_str, get_str }, | 77 (int *) score_file, put_str, get_str_prot }, |
| 75 {"class", "Character type: ", | 78 {"class", "Character type: ", |
| 76 (int *) &char_type, put_abil, get_abil }, | 79 (int *) &char_type, put_abil, get_abil }, |
| 77 {"quest", "Quest item: ", | 80 {"quest", "Quest item: ", |
| 78 (int *) &quest_item, put_quest, get_quest }, | 81 (int *) &quest_item, put_quest, get_quest }, |
| 79 {"default", "Default Attributes: ", | 82 {"default", "Default Attributes: ", |
| 405 for (sp = str + 1; *sp && *sp != ',' && *sp != '\"'; sp++) | 408 for (sp = str + 1; *sp && *sp != ',' && *sp != '\"'; sp++) |
| 406 continue; | 409 continue; |
| 407 strucpy(start, str, (char *) sp - str); | 410 strucpy(start, str, (char *) sp - str); |
| 408 | 411 |
| 409 /* Put the value into the option field */ | 412 /* Put the value into the option field */ |
| 410 if (op->o_putfunc != put_abil) | 413 if (op->o_putfunc != put_abil) { |
| 411 strcpy((char *)op->o_opt, value); | 414 if (allowchange(op)) |
| 415 strcpy((char *)op->o_opt, value); | |
| 416 } | |
| 412 | 417 |
| 413 else if (*op->o_opt == -1) { /* Only init ability once */ | 418 else if (*op->o_opt == -1) { /* Only init ability once */ |
| 414 register int len = strlen(value); | 419 register int len = strlen(value); |
| 415 register int i; | 420 register int i; |
| 416 | 421 |
| 498 WINDOW *win; | 503 WINDOW *win; |
| 499 { | 504 { |
| 500 waddstr(win, str); | 505 waddstr(win, str); |
| 501 } | 506 } |
| 502 | 507 |
| 508 /* Like get_str, but disallows changes when use_savedir is set. */ | |
| 509 int | |
| 510 get_str_prot(char *opt, WINDOW *win) | |
| 511 { | |
| 512 int oy, ox; | |
| 513 | |
| 514 if (use_savedir) { | |
| 515 getyx(win, oy, ox); | |
| 516 waddstr(win, opt); | |
| 517 return get_ro(win, oy, ox); | |
| 518 } | |
| 519 else { | |
| 520 return get_str(opt, win); | |
| 521 } | |
| 522 } | |
| 523 | |
| 524 bool | |
| 525 allowchange(OPTION *op) | |
| 526 { | |
| 527 if (!use_savedir) | |
| 528 return TRUE; | |
| 529 if (!strcmp(op->o_name, "name")) | |
| 530 return FALSE; | |
| 531 if (!strcmp(op->o_name, "file")) | |
| 532 return FALSE; | |
| 533 if (!strcmp(op->o_name, "score")) | |
| 534 return FALSE; | |
| 535 return TRUE; | |
| 536 } |
