1 /* $NetBSD: hack.options.c,v 1.9 2009/06/07 20:13:18 dholland Exp $ */
4 * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * - Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * - Neither the name of the Stichting Centrum voor Wiskunde en
20 * Informatica, nor the names of its contributors may be used to endorse or
21 * promote products derived from this software without specific prior
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
28 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
39 * All rights reserved.
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. The name of the author may not be used to endorse or promote products
50 * derived from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
53 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
54 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
55 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
56 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
57 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
58 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
59 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
60 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
61 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 #include <sys/cdefs.h>
66 __RCSID("$NetBSD: hack.options.c,v 1.9 2009/06/07 20:13:18 dholland Exp $");
74 static void parseoptions(char *, boolean
);
81 flags
.time
= flags
.nonews
= flags
.notombstone
= flags
.end_own
=
82 flags
.standout
= flags
.nonull
= FALSE
;
83 flags
.no_rest_on_space
= TRUE
;
84 flags
.invlet_constant
= TRUE
;
87 flags
.female
= FALSE
; /* players are usually male */
89 if ((opts
= getenv("HACKOPTIONS")) != NULL
)
90 parseoptions(opts
, TRUE
);
94 parseoptions(char *opts
, boolean from_env
)
100 if ((op
= strchr(opts
, ',')) != NULL
) {
102 parseoptions(op
, from_env
);
104 if ((op
= strchr(opts
, ' ')) != NULL
) {
113 while ((*opts
== '!') || !strncmp(opts
, "no", 2)) {
121 if (!strncmp(opts
, "standout", 8)) {
122 flags
.standout
= !negated
;
125 if (!strncmp(opts
, "null", 3)) {
126 flags
.nonull
= negated
;
129 if (!strncmp(opts
, "tombstone", 4)) {
130 flags
.notombstone
= negated
;
133 if (!strncmp(opts
, "news", 4)) {
134 flags
.nonews
= negated
;
137 if (!strncmp(opts
, "time", 4)) {
138 flags
.time
= !negated
;
142 if (!strncmp(opts
, "restonspace", 4)) {
143 flags
.no_rest_on_space
= negated
;
146 if (!strncmp(opts
, "fixinv", 4)) {
148 flags
.invlet_constant
= !negated
;
150 pline("The fixinvlet option must be in HACKOPTIONS.");
153 if (!strncmp(opts
, "male", 4)) {
154 flags
.female
= negated
;
157 if (!strncmp(opts
, "female", 6)) {
158 flags
.female
= !negated
;
162 if (!strncmp(opts
, "name", 4)) {
164 pline("The playername can be set only from HACKOPTIONS.");
167 op
= strchr(opts
, ':');
170 (void) strncpy(plname
, op
+ 1, sizeof(plname
) - 1);
173 /* endgame:5t[op] 5a[round] o[wn] */
174 if (!strncmp(opts
, "endgame", 3)) {
175 op
= strchr(opts
, ':');
185 } else if (*op
== '!') {
194 flags
.end_around
= num
;
197 flags
.end_own
= !negated
;
202 while (letter(*++op
));
210 if (!strncmp(opts
, "help", 4)) {
212 "To set options use `HACKOPTIONS=\"<options>\"' in your environment, or ",
213 "give the command 'O' followed by the line `<options>' while playing. ",
214 "Here <options> is a list of <option>s separated by commas.");
216 "Simple (boolean) options are rest_on_space, news, time, ",
217 "null, tombstone, (fe)male. ",
218 "These can be negated by prefixing them with '!' or \"no\".");
220 "A string option is name, as in HACKOPTIONS=\"name:Merlin-W\".");
222 "A compound option is endgame; it is followed by a description of what ",
223 "parts of the scorelist you want to see. You might for example say: ",
224 "`endgame:own scores/5 top scores/4 around my score'.");
227 pline("Bad option: %s.", opts
);
228 pline("Type `O help<cr>' for help.");
231 puts("Bad syntax in HACKOPTIONS.");
232 puts("Use for example:");
234 "HACKOPTIONS=\"!restonspace,notombstone,endgame:own/5 topscorers/4 around me\""
245 pline("What options do you want to set? ");
247 if (!buf
[0] || buf
[0] == '\033') {
248 (void) strcpy(buf
, "HACKOPTIONS=");
249 (void) strcat(buf
, flags
.female
? "female," : "male,");
251 (void) strlcat(buf
, "standout,", sizeof(buf
));
253 (void) strlcat(buf
, "nonull,", sizeof(buf
));
255 (void) strlcat(buf
, "nonews,", sizeof(buf
));
257 (void) strlcat(buf
, "time,", sizeof(buf
));
258 if (flags
.notombstone
)
259 (void) strlcat(buf
, "notombstone,", sizeof(buf
));
260 if (flags
.no_rest_on_space
)
261 (void) strlcat(buf
, "!rest_on_space,", sizeof(buf
));
262 if (flags
.end_top
!= 5 || flags
.end_around
!= 4 || flags
.end_own
) {
264 (void) snprintf(buf
+pos
, sizeof(buf
)-pos
,
265 "endgame: %u topscores/%u around me",
266 flags
.end_top
, flags
.end_around
);
268 (void) strlcat(buf
, "/own scores", sizeof(buf
));
270 char *eop
= eos(buf
);
276 parseoptions(buf
, FALSE
);