2011-05-24 02:53:25 +04:00
|
|
|
/* $NetBSD: hack.options.c,v 1.11 2011/05/23 22:53:25 joerg Exp $ */
|
1997-10-19 20:56:41 +04:00
|
|
|
|
1993-08-02 21:18:41 +04:00
|
|
|
/*
|
2003-04-02 22:36:33 +04:00
|
|
|
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
|
|
|
|
* Amsterdam
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
|
|
|
*
|
|
|
|
* - Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* - Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* - Neither the name of the Stichting Centrum voor Wiskunde en
|
|
|
|
* Informatica, nor the names of its contributors may be used to endorse or
|
|
|
|
* promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
|
|
|
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
|
|
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
|
|
|
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
|
|
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1993-08-02 21:18:41 +04:00
|
|
|
*/
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-08-02 21:18:41 +04:00
|
|
|
#ifndef lint
|
2011-05-24 02:53:25 +04:00
|
|
|
__RCSID("$NetBSD: hack.options.c,v 1.11 2011/05/23 22:53:25 joerg Exp $");
|
1997-10-19 20:56:41 +04:00
|
|
|
#endif /* not lint */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
#include <stdlib.h>
|
2001-02-05 03:37:43 +03:00
|
|
|
#include <unistd.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include "hack.h"
|
1997-10-19 20:56:41 +04:00
|
|
|
#include "extern.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2009-08-12 11:28:40 +04:00
|
|
|
static void parseoptions(char *, boolean);
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
2009-06-07 22:30:39 +04:00
|
|
|
initoptions(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
char *opts;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
flags.time = flags.nonews = flags.notombstone = flags.end_own =
|
1997-10-19 20:56:41 +04:00
|
|
|
flags.standout = flags.nonull = FALSE;
|
1993-03-21 12:45:37 +03:00
|
|
|
flags.no_rest_on_space = TRUE;
|
|
|
|
flags.invlet_constant = TRUE;
|
|
|
|
flags.end_top = 5;
|
|
|
|
flags.end_around = 4;
|
1997-10-19 20:56:41 +04:00
|
|
|
flags.female = FALSE; /* players are usually male */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
if ((opts = getenv("HACKOPTIONS")) != NULL)
|
|
|
|
parseoptions(opts, TRUE);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2009-08-12 11:28:40 +04:00
|
|
|
static void
|
2009-06-07 22:30:39 +04:00
|
|
|
parseoptions(char *opts, boolean from_env)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
char *op, *op2;
|
|
|
|
unsigned num;
|
|
|
|
boolean negated;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
if ((op = strchr(opts, ',')) != NULL) {
|
1993-03-21 12:45:37 +03:00
|
|
|
*op++ = 0;
|
|
|
|
parseoptions(op, from_env);
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if ((op = strchr(opts, ' ')) != NULL) {
|
1993-03-21 12:45:37 +03:00
|
|
|
op2 = op;
|
1997-10-19 20:56:41 +04:00
|
|
|
while (*op++)
|
|
|
|
if (*op != ' ')
|
|
|
|
*op2++ = *op;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!*opts)
|
|
|
|
return;
|
1993-03-21 12:45:37 +03:00
|
|
|
negated = FALSE;
|
1997-10-19 20:56:41 +04:00
|
|
|
while ((*opts == '!') || !strncmp(opts, "no", 2)) {
|
|
|
|
if (*opts == '!')
|
|
|
|
opts++;
|
|
|
|
else
|
|
|
|
opts += 2;
|
1993-03-21 12:45:37 +03:00
|
|
|
negated = !negated;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
|
|
|
|
if (!strncmp(opts, "standout", 8)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
flags.standout = !negated;
|
|
|
|
return;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!strncmp(opts, "null", 3)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
flags.nonull = negated;
|
|
|
|
return;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!strncmp(opts, "tombstone", 4)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
flags.notombstone = negated;
|
|
|
|
return;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!strncmp(opts, "news", 4)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
flags.nonews = negated;
|
|
|
|
return;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!strncmp(opts, "time", 4)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
flags.time = !negated;
|
|
|
|
flags.botl = 1;
|
|
|
|
return;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!strncmp(opts, "restonspace", 4)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
flags.no_rest_on_space = negated;
|
|
|
|
return;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!strncmp(opts, "fixinv", 4)) {
|
|
|
|
if (from_env)
|
1993-03-21 12:45:37 +03:00
|
|
|
flags.invlet_constant = !negated;
|
|
|
|
else
|
|
|
|
pline("The fixinvlet option must be in HACKOPTIONS.");
|
|
|
|
return;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!strncmp(opts, "male", 4)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
flags.female = negated;
|
|
|
|
return;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!strncmp(opts, "female", 6)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
flags.female = !negated;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* name:string */
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!strncmp(opts, "name", 4)) {
|
|
|
|
if (!from_env) {
|
|
|
|
pline("The playername can be set only from HACKOPTIONS.");
|
|
|
|
return;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
op = strchr(opts, ':');
|
|
|
|
if (!op)
|
|
|
|
goto bad;
|
|
|
|
(void) strncpy(plname, op + 1, sizeof(plname) - 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* endgame:5t[op] 5a[round] o[wn] */
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!strncmp(opts, "endgame", 3)) {
|
|
|
|
op = strchr(opts, ':');
|
|
|
|
if (!op)
|
|
|
|
goto bad;
|
1993-03-21 12:45:37 +03:00
|
|
|
op++;
|
1997-10-19 20:56:41 +04:00
|
|
|
while (*op) {
|
1993-03-21 12:45:37 +03:00
|
|
|
num = 1;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (digit(*op)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
num = atoi(op);
|
1997-10-19 20:56:41 +04:00
|
|
|
while (digit(*op))
|
|
|
|
op++;
|
|
|
|
} else if (*op == '!') {
|
1993-03-21 12:45:37 +03:00
|
|
|
negated = !negated;
|
|
|
|
op++;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
switch (*op) {
|
1993-03-21 12:45:37 +03:00
|
|
|
case 't':
|
|
|
|
flags.end_top = num;
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
flags.end_around = num;
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
flags.end_own = !negated;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto bad;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
while (letter(*++op));
|
|
|
|
if (*op == '/')
|
|
|
|
op++;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bad:
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!from_env) {
|
|
|
|
if (!strncmp(opts, "help", 4)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("%s%s%s",
|
1997-10-19 20:56:41 +04:00
|
|
|
"To set options use `HACKOPTIONS=\"<options>\"' in your environment, or ",
|
2004-01-01 19:02:51 +03:00
|
|
|
"give the command 'O' followed by the line `<options>' while playing. ",
|
1997-10-19 20:56:41 +04:00
|
|
|
"Here <options> is a list of <option>s separated by commas.");
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("%s%s%s",
|
1997-10-19 20:56:41 +04:00
|
|
|
"Simple (boolean) options are rest_on_space, news, time, ",
|
|
|
|
"null, tombstone, (fe)male. ",
|
|
|
|
"These can be negated by prefixing them with '!' or \"no\".");
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("%s",
|
1997-10-19 20:56:41 +04:00
|
|
|
"A string option is name, as in HACKOPTIONS=\"name:Merlin-W\".");
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("%s%s%s",
|
1997-10-19 20:56:41 +04:00
|
|
|
"A compound option is endgame; it is followed by a description of what ",
|
|
|
|
"parts of the scorelist you want to see. You might for example say: ",
|
|
|
|
"`endgame:own scores/5 top scores/4 around my score'.");
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
pline("Bad option: %s.", opts);
|
2004-01-01 19:02:51 +03:00
|
|
|
pline("Type `O help<cr>' for help.");
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
puts("Bad syntax in HACKOPTIONS.");
|
|
|
|
puts("Use for example:");
|
|
|
|
puts(
|
1997-10-19 20:56:41 +04:00
|
|
|
"HACKOPTIONS=\"!restonspace,notombstone,endgame:own/5 topscorers/4 around me\""
|
|
|
|
);
|
1993-03-21 12:45:37 +03:00
|
|
|
getret();
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
int
|
2009-06-07 22:30:39 +04:00
|
|
|
doset(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2009-06-08 00:13:18 +04:00
|
|
|
char buf[BUFSZ];
|
|
|
|
size_t pos;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
pline("What options do you want to set? ");
|
|
|
|
getlin(buf);
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!buf[0] || buf[0] == '\033') {
|
|
|
|
(void) strcpy(buf, "HACKOPTIONS=");
|
|
|
|
(void) strcat(buf, flags.female ? "female," : "male,");
|
|
|
|
if (flags.standout)
|
2009-06-08 00:13:18 +04:00
|
|
|
(void) strlcat(buf, "standout,", sizeof(buf));
|
1997-10-19 20:56:41 +04:00
|
|
|
if (flags.nonull)
|
2009-06-08 00:13:18 +04:00
|
|
|
(void) strlcat(buf, "nonull,", sizeof(buf));
|
1997-10-19 20:56:41 +04:00
|
|
|
if (flags.nonews)
|
2009-06-08 00:13:18 +04:00
|
|
|
(void) strlcat(buf, "nonews,", sizeof(buf));
|
1997-10-19 20:56:41 +04:00
|
|
|
if (flags.time)
|
2009-06-08 00:13:18 +04:00
|
|
|
(void) strlcat(buf, "time,", sizeof(buf));
|
1997-10-19 20:56:41 +04:00
|
|
|
if (flags.notombstone)
|
2009-06-08 00:13:18 +04:00
|
|
|
(void) strlcat(buf, "notombstone,", sizeof(buf));
|
1997-10-19 20:56:41 +04:00
|
|
|
if (flags.no_rest_on_space)
|
2009-06-08 00:13:18 +04:00
|
|
|
(void) strlcat(buf, "!rest_on_space,", sizeof(buf));
|
1997-10-19 20:56:41 +04:00
|
|
|
if (flags.end_top != 5 || flags.end_around != 4 || flags.end_own) {
|
2009-06-08 00:13:18 +04:00
|
|
|
pos = strlen(buf);
|
|
|
|
(void) snprintf(buf+pos, sizeof(buf)-pos,
|
|
|
|
"endgame: %u topscores/%u around me",
|
1997-10-19 20:56:41 +04:00
|
|
|
flags.end_top, flags.end_around);
|
|
|
|
if (flags.end_own)
|
2009-06-08 00:13:18 +04:00
|
|
|
(void) strlcat(buf, "/own scores", sizeof(buf));
|
1997-10-19 20:56:41 +04:00
|
|
|
} else {
|
|
|
|
char *eop = eos(buf);
|
|
|
|
if (*--eop == ',')
|
|
|
|
*eop = 0;
|
|
|
|
}
|
2011-05-24 02:53:25 +04:00
|
|
|
pline("%s", buf);
|
1993-03-21 12:45:37 +03:00
|
|
|
} else
|
1997-10-19 20:56:41 +04:00
|
|
|
parseoptions(buf, FALSE);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|