2 * This file has all the code for the option command.
3 * I would rather this command were not necessary, but
4 * it is the only way to keep the wolves off of my back.
6 * @(#)options.c 3.3 (Berkeley) 5/25/81
8 * Rogue: Exploring the Dungeons of Doom
9 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
10 * All rights reserved.
12 * See the file LICENSE.TXT for full copyright and licensing information.
20 #define NUM_OPTS (sizeof optlist / sizeof (OPTION))
23 * description of an option and what to do with it
26 char *o_name
; /* option name */
27 char *o_prompt
; /* prompt for interactive entry */
28 int *o_opt
; /* pointer to thing to set */
29 int (*o_putfunc
)(); /* function to print value */
30 int (*o_getfunc
)(); /* function to get value interactively */
33 typedef struct optstruct OPTION
;
35 int put_bool(), get_bool(), put_str(), get_str();
38 {"terse", "Terse output: ",
39 (int *) &terse
, put_bool
, get_bool
},
40 {"flush", "Flush typeahead during battle: ",
41 (int *) &fight_flush
, put_bool
, get_bool
},
42 {"jump", "Show position only at end of run: ",
43 (int *) &jump
, put_bool
, get_bool
},
44 {"step", "Do inventories one line at a time: ",
45 (int *) &slow_invent
, put_bool
, get_bool
},
46 {"askme", "Ask me about unidentified things: ",
47 (int *) &askme
, put_bool
, get_bool
},
49 (int *) whoami
, put_str
, get_str
},
51 (int *) fruit
, put_str
, get_str
},
52 {"file", "Save file: ",
53 (int *) file_name
, put_str
, get_str
}
57 * print and then set options from the terminal
67 * Display current values of options
69 for (op
= optlist
; op
<= &optlist
[NUM_OPTS
-1]; op
++)
71 waddstr(hw
, op
->o_prompt
);
72 (*op
->o_putfunc
)(op
->o_opt
);
79 for (op
= optlist
; op
<= &optlist
[NUM_OPTS
-1]; op
++)
81 waddstr(hw
, op
->o_prompt
);
82 if ((retval
= (*op
->o_getfunc
)(op
->o_opt
, hw
)))
85 else if (op
> optlist
) { /* MINUS */
86 wmove(hw
, (op
- optlist
) - 1, 0);
89 else /* trying to back up beyond the top */
97 * Switch back to original screen
99 mvwaddstr(hw
, LINES
-1, 0, "--Press space to continue--");
113 waddstr(hw
, *b
? "True" : "False");
126 * allow changing a boolean option and print it out
134 register bool op_bad
;
138 waddstr(win
, *bp
? "True" : "False");
143 switch (readchar(win
))
165 mvwaddstr(win
, oy
, ox
+ 10, "(T or F)");
169 waddstr(win
, *bp
? "True" : "False");
175 * set a string option
182 register int c
, oy
, ox
;
188 * loop reading in the string, and put it in a temporary buffer
191 (c
= readchar(win
)) != '\n' && c
!= '\r' && c
!= '\033' && c
!= '\007';
192 wclrtoeol(win
), draw(win
))
196 else if (c
== md_erasechar()) /* process erase character */
205 for (i
= (int) strlen(unctrl(*sp
)); i
; i
--)
208 if ((myx
== 0)&& (myy
> 0))
210 wmove(win
,myy
-1,getmaxx(win
)-1);
212 wmove(win
,myy
-1,getmaxx(win
)-1);
220 else if (c
== md_killchar()) /* process kill character */
237 if ((sp
- buf
) < 78) /* Avoid overflow */
240 waddstr(win
, unctrl(c
));
244 if (sp
> buf
) /* only change option if something has been typed */
245 strucpy(opt
, buf
, strlen(buf
));
254 else if (c
== '\033' || c
== '\007')
261 * parse options from string, usually taken from the environment.
262 * the string is a series of comma seperated values, with booleans
263 * being stated as "name" (true) or "noname" (false), and strings
264 * being "name=....", with the string being defined up to a comma
265 * or the end of the entire option string.
280 for (sp
= str
; isalpha(*sp
); sp
++)
284 * Look it up and deal with it
286 for (op
= optlist
; op
<= &optlist
[NUM_OPTS
-1]; op
++)
287 if (EQSTR(str
, op
->o_name
, len
))
289 if (op
->o_putfunc
== put_bool
) /* if option is a boolean */
290 *(bool *)op
->o_opt
= TRUE
;
291 else /* string option */
293 register char *start
;
295 * Skip to start of string value
297 for (str
= sp
+ 1; *str
== '='; str
++)
301 strcpy((char *) op
->o_opt
, home
);
302 start
= (char *) op
->o_opt
+ strlen(home
);
303 while (*++str
== '/')
307 start
= (char *) op
->o_opt
;
309 * Skip to end of string value
311 for (sp
= str
+ 1; *sp
&& *sp
!= ','; sp
++)
313 strucpy(start
, str
, sp
- str
);
318 * check for "noname" for booleans
320 else if (op
->o_putfunc
== put_bool
321 && EQSTR(str
, "no", 2) && EQSTR(str
+ 2, op
->o_name
, len
- 2))
323 *(bool *)op
->o_opt
= FALSE
;
328 * skip to start of next option name
330 while (*sp
&& !isalpha(*sp
))
337 * copy string using unctrl for things
340 register char *s1
, *s2
;
347 strcpy(s1
, (sp
= unctrl(*s2
)));