Mercurial > hg > early-roguelike
annotate srogue/options.c @ 36:2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
author | elwin |
---|---|
date | Thu, 25 Nov 2010 12:21:41 +0000 |
parents | |
children | 34d7a614855e |
rev | line source |
---|---|
36
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
1 /* |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
2 * This file has all the code for the option command. |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
3 * |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
4 * @(#)options.c 9.0 (rdk) 7/17/84 |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
5 * |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
6 * Super-Rogue |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
7 * Copyright (C) 1984 Robert D. Kindelberger |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
8 * All rights reserved. |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
9 * |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
10 * Based on "Rogue: Exploring the Dungeons of Doom" |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
11 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
12 * All rights reserved. |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
13 * |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
14 * See the file LICENSE.TXT for full copyright and licensing information. |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
15 */ |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
16 |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
17 #include <termios.h> |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
18 #include <ctype.h> |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
19 #include "rogue.h" |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
20 #include "rogue.ext" |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
21 |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
22 extern struct termios terminal; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
23 |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
24 /* |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
25 * description of an option and what to do with it |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
26 */ |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
27 struct optstruct { |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
28 char *o_name; /* option name */ |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
29 char *o_prompt; /* prompt for interactive entry */ |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
30 char *o_opt; /* pointer to thing to set */ |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
31 }; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
32 |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
33 typedef struct optstruct OPTION; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
34 |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
35 int put_str(), get_str(); |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
36 |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
37 OPTION optlist[] = { |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
38 { "name", "Name: ", whoami }, |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
39 { "fruit", "Fruit: ", fruit }, |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
40 { "file", "Save file: ", file_name } |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
41 }; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
42 #define NUM_OPTS (sizeof optlist / sizeof (OPTION)) |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
43 |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
44 /* |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
45 * print and then set options from the terminal |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
46 */ |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
47 option() |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
48 { |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
49 reg OPTION *op; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
50 reg int wh; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
51 |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
52 wclear(hw); |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
53 touchwin(hw); |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
54 /* |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
55 * Display current values of options |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
56 */ |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
57 for (op = optlist; op < &optlist[NUM_OPTS]; op++) { |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
58 wh = op - optlist; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
59 mvwaddstr(hw, wh, 0, op->o_prompt); |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
60 mvwaddstr(hw, wh, 16, op->o_opt); |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
61 } |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
62 /* |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
63 * Set values |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
64 */ |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
65 wmove(hw, 0, 0); |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
66 for (op = optlist; op < &optlist[NUM_OPTS]; op++) { |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
67 wmove(hw, op - optlist, 16); |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
68 if ((wh = get_str(op->o_opt, hw))) { |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
69 if (wh == QUIT) |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
70 break; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
71 else if (op > optlist) { |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
72 wmove(hw, op - optlist, 0); |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
73 op -= 2; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
74 } |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
75 else { |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
76 putchar(7); |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
77 wmove(hw, 0, 0); |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
78 op -= 1; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
79 } |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
80 } |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
81 } |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
82 /* |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
83 * Switch back to original screen |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
84 */ |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
85 dbotline(hw,spacemsg); |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
86 restscr(cw); |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
87 after = FALSE; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
88 } |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
89 |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
90 |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
91 /* |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
92 * get_str: |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
93 * Set a string option |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
94 */ |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
95 #define CTRLB 2 |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
96 get_str(opt, awin) |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
97 char *opt; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
98 WINDOW *awin; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
99 { |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
100 reg char *sp; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
101 reg int c, oy, ox; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
102 char buf[LINLEN]; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
103 |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
104 draw(awin); |