Mercurial > hg > early-roguelike
annotate rogue5/options.c @ 189:7c552cbc6ad9
srogue: make checking directories slightly more portable.
MSVC sys/stat.h doesn't define S_ISDIR().
author | John "Elwin" Edwards |
---|---|
date | Mon, 03 Aug 2015 09:05:15 -0400 |
parents | 655c317b6237 |
children |
rev | line source |
---|---|
33
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
1 /* |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
2 * This file has all the code for the option command. I would rather |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
3 * this command were not necessary, but it is the only way to keep the |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
4 * wolves off of my back. |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
5 * |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
6 * @(#)options.c 4.24 (Berkeley) 05/10/83 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
7 * |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
8 * Rogue: Exploring the Dungeons of Doom |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
9 * Copyright (C) 1980-1983, 1985, 1999 Michael Toy, Ken Arnold and Glenn Wichman |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
10 * All rights reserved. |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
11 * |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
12 * See the file LICENSE.TXT for full copyright and licensing information. |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
13 */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
14 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
15 #include <stdlib.h> |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
16 #include <curses.h> |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
17 #include <ctype.h> |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
18 #include <string.h> |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
19 #include "rogue.h" |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
20 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
21 #define EQSTR(a, b, c) (strncmp(a, b, c) == 0) |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
22 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
23 #define NUM_OPTS (sizeof optlist / sizeof (OPTION)) |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
24 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
25 /* |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
26 * description of an option and what to do with it |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
27 */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
28 struct optstruct { |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
29 char *o_name; /* option name */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
30 char *o_prompt; /* prompt for interactive entry */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
31 void *o_opt; /* pointer to thing to set */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
32 /* function to print value */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
33 void (*o_putfunc)(void *opt); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
34 /* function to get value interactively */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
35 int (*o_getfunc)(void *opt, WINDOW *win); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
36 }; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
37 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
38 typedef struct optstruct OPTION; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
39 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
40 void pr_optname(const OPTION *op); |
34 | 41 int allowchange(const OPTION *op); |
33
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
42 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
43 static const OPTION optlist[] = { |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
44 {"terse", "Terse output", |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
45 &terse, put_bool, get_bool }, |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
46 {"flush", "Flush typeahead during battle", |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
47 &fight_flush, put_bool, get_bool }, |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
48 {"jump", "Show position only at end of run", |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
49 &jump, put_bool, get_bool }, |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
50 {"seefloor", "Show the lamp-illuminated floor", |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
51 &see_floor, put_bool, get_sf }, |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
52 {"passgo", "Follow turnings in passageways", |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
53 &passgo, put_bool, get_bool }, |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
54 {"tombstone", "Print out tombstone when killed", |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
55 &tombstone, put_bool, get_bool }, |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
56 {"inven", "Inventory style", |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
57 &inv_type, put_inv_t, get_inv_t }, |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
58 {"name", "Name", |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
59 whoami, put_str, get_str }, |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
60 {"fruit", "Fruit", |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
61 fruit, put_str, get_str }, |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
62 {"file", "Save file", |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
63 file_name, put_str, get_str } |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
64 }; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
65 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
66 /* |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
67 * option: |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
68 * Print and then set options from the terminal |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
69 */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
70 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
71 void |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
72 option(void) |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
73 { |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
74 const OPTION *op; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
75 int retval; |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
76 |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
77 wclear(hw); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
78 /* |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
79 * Display current values of options |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
80 */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
81 for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++) |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
82 { |
34 | 83 if (allowchange(op)) |
84 { | |
85 pr_optname(op); | |
86 (*op->o_putfunc)(op->o_opt); | |
87 waddch(hw, '\n'); | |
88 } | |
33
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
89 } |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
90 /* |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
91 * Set values |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
92 */ |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
93 wmove(hw, 0, 0); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
94 for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++) |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
95 { |
34 | 96 if (!allowchange(op)) |
97 continue; | |
33
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
98 pr_optname(op); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
99 retval = (*op->o_getfunc)(op->o_opt, hw); |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
100 if (retval) |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
101 { |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
102 if (retval == QUIT) |
f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
103 break; |
34 | 104 #if 0 |