]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.options.c
1 /* $NetBSD: hack.options.c,v 1.7 2004/01/01 16:02:51 jsm 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.7 2004/01/01 16:02:51 jsm Exp $");
79 flags
.time
= flags
.nonews
= flags
.notombstone
= flags
.end_own
=
80 flags
.standout
= flags
.nonull
= FALSE
;
81 flags
.no_rest_on_space
= TRUE
;
82 flags
.invlet_constant
= TRUE
;
85 flags
.female
= FALSE
; /* players are usually male */
87 if ((opts
= getenv("HACKOPTIONS")) != NULL
)
88 parseoptions(opts
, TRUE
);
92 parseoptions(opts
, 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\""
244 pline("What options do you want to set? ");
246 if (!buf
[0] || buf
[0] == '\033') {
247 (void) strcpy(buf
, "HACKOPTIONS=");
248 (void) strcat(buf
, flags
.female
? "female," : "male,");
250 (void) strcat(buf
, "standout,");
252 (void) strcat(buf
, "nonull,");
254 (void) strcat(buf
, "nonews,");
256 (void) strcat(buf
, "time,");
257 if (flags
.notombstone
)
258 (void) strcat(buf
, "notombstone,");
259 if (flags
.no_rest_on_space
)
260 (void) strcat(buf
, "!rest_on_space,");
261 if (flags
.end_top
!= 5 || flags
.end_around
!= 4 || flags
.end_own
) {
262 (void) sprintf(eos(buf
), "endgame: %u topscores/%u around me",
263 flags
.end_top
, flags
.end_around
);
265 (void) strcat(buf
, "/own scores");
267 char *eop
= eos(buf
);
273 parseoptions(buf
, FALSE
);