Mercurial > hg > early-roguelike
annotate rogue3/options.c @ 317:aab761616489 default tip
Rearrange some Autoconf files.
Autoconf was failing to detect install-sh at the top level and needed
some explicit directions. It also wants config.guess and config.sub to
be provided too.
A few other macros have also been updated.
author | John "Elwin" Edwards |
---|---|
date | Tue, 05 Sep 2023 20:05:24 -0400 |
parents | e52a8a7ad4c5 |
children |
rev | line source |
---|---|
0
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
1 /* |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
2 * This file has all the code for the option command. |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
3 * I would rather this command were not necessary, but |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
4 * it is the only way to keep the wolves off of my back. |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
5 * |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
6 * @(#)options.c 3.3 (Berkeley) 5/25/81 |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
7 * |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
8 * Rogue: Exploring the Dungeons of Doom |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
9 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
10 * All rights reserved. |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
11 * |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
12 * See the file LICENSE.TXT for full copyright and licensing information. |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
13 */ |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
14 |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
15 #include <stdlib.h> |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
16 #include "curses.h" |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
17 #include <ctype.h> |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
18 #include <string.h> |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
19 #include "machdep.h" |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
20 #include "rogue.h" |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
21 |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
22 #define NUM_OPTS (sizeof optlist / sizeof (OPTION)) |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
23 |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
24 /* |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
25 * description of an option and what to do with it |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
26 */ |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
27 struct optstruct { |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
28 char *o_name; /* option name */ |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
29 char *o_prompt; /* prompt for interactive entry */ |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
30 void *o_opt; /* pointer to thing to set */ |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
31 void (*o_putfunc)(); /* function to print value */ |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
32 int (*o_getfunc)(); /* function to get value interactively */ |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
33 }; |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
34 |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
35 typedef struct optstruct OPTION; |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
36 |
2
e676d52b5d09
Prevent changing name or save file when using system savedir
edwarj4
parents:
0
diff
changeset
|
37 int allowchange(OPTION *opt); /* doesn't need to be externally visible */ |
e676d52b5d09
Prevent changing name or save file when using system savedir
edwarj4
parents:
0
diff
changeset
|
38 |
0
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
39 OPTION optlist[] = { |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
40 {"terse", "Terse output: ", |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
41 (int *) &terse, put_bool, get_bool }, |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
42 {"flush", "Flush typeahead during battle: ", |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
43 (int *) &fight_flush, put_bool, get_bool }, |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
44 {"jump", "Show position only at end of run: ", |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
45 (int *) &jump, put_bool, get_bool }, |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
46 {"step", "Do inventories one line at a time: ", |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
47 (int *) &slow_invent, put_bool, get_bool }, |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
48 {"askme", "Ask me about unidentified things: ", |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
49 (int *) &askme, put_bool, get_bool }, |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
50 {"name", "Name: ", |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
51 (int *) whoami, put_str, get_str }, |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
52 {"fruit", "Fruit: ", |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
53 (int *) fruit, put_str, get_str }, |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
54 {"file", "Save file: ", |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
55 (int *) file_name, put_str, get_str } |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
56 }; |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
57 |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
58 /* |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
59 * print and then set options from the terminal |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
60 */ |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
61 void |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
62 option() |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
63 { |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
64 OPTION *op; |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
65 int retval; |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
66 |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
67 wclear(hw); |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
68 touchwin(hw); |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
69 /* |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
70 * Display current values of options |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
71 */ |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
72 for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++) |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
73 { |
2
e676d52b5d09
Prevent changing name or save file when using system savedir
edwarj4
parents:
0
diff
changeset
|
74 if (allowchange(op)) |
e676d52b5d09
Prevent changing name or save file when using system savedir
edwarj4
parents:
0
diff
changeset
|
75 { |
e676d52b5d09
Prevent changing name or save file when using system savedir
edwarj4
parents:
0
diff
changeset
|
76 waddstr(hw, op->o_prompt); |
e676d52b5d09
Prevent changing name or save file when using system savedir
edwarj4
parents:
0
diff
changeset
|
77 (*op->o_putfunc)(op->o_opt); |
e676d52b5d09
Prevent changing name or save file when using system savedir
edwarj4
parents:
0
diff
changeset
|
78 waddch(hw, '\n'); |
e676d52b5d09
Prevent changing name or save file when using system savedir
edwarj4
parents:
0
diff
changeset
|
79 } |
0
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
80 } |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
81 /* |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
82 * Set values |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
83 */ |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
84 wmove(hw, 0, 0); |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
85 for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++) |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
86 { |
2
e676d52b5d09
Prevent changing name or save file when using system savedir
edwarj4
parents:
0
diff
changeset
|
87 if (!allowchange(op)) |
e676d52b5d09
Prevent changing name or save file when using system savedir
edwarj4
parents:
0
diff
changeset
|
88 continue; |
0
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
89 waddstr(hw, op->o_prompt); |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
90 if ((retval = (*op->o_getfunc)(op->o_opt, hw))) |
2
e676d52b5d09
Prevent changing name or save file when using system savedir
edwarj4
parents:
0
diff
changeset
|
91 { |
0
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
92 if (retval == QUIT) |
527e2150eaf0
Import Rogue 3.6 from the Roguelike Restoration Project (r1490)
edwarj4
parents:
diff
changeset
|
93 break; |
2
e676d52b5d09
Prevent changing name or save file when using system savedir
edwarj4
parents:
0
diff
changeset
|
94 #if 0 |
e676d52b5d09
Prevent changing name or save file when using system savedir
edwarj4
parents:
0
diff
changeset
|
95 /* Support for MINUS has been removed because making it work with |
e676d52b5d09
Prevent changing name or save file when using system savedir
edwarj4
parents:
0
diff
changeset
|
96 * hidden unchangable options without underflowing optlist will |
e676d52b5d09
Prevent changing name or save file when using system savedir
edwarj4
parents:
0
diff
changeset
|
97 * require a complete rewrite. And it should also be rewritten |
e676d52b5d09
Prevent changing name or save file when using system savedir
edwarj4
parents:
0
diff
changeset
|
98 * so option() doesn't count on get_str() to put the cursor in the |
e676d52b5d09
Prevent changing name or save file when using system savedir
edwarj4
parents:
0
diff
changeset
|
99 * right place, because that makes it a pain to understand. |
e676d52b5d09
Prevent changing name or save file when using system savedir
edwarj4
parents:
0
diff
changeset
|
100 */ |