From 013ac7742311556022304e8b30ca170d48b3a016 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Thu, 7 May 2015 16:32:32 -0400 Subject: initial commit --- hack/hack.options.c | 217 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 217 insertions(+) create mode 100644 hack/hack.options.c (limited to 'hack/hack.options.c') diff --git a/hack/hack.options.c b/hack/hack.options.c new file mode 100644 index 0000000..63a8c2a --- /dev/null +++ b/hack/hack.options.c @@ -0,0 +1,217 @@ +/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ +/* hack.options.c - version 1.0.3 */ +/* $FreeBSD: src/games/hack/hack.options.c,v 1.5 1999/11/16 02:57:08 billf Exp $ */ + +#include "hack.h" + +static void parseoptions(char *, bool); + +void +initoptions(void) +{ + char *opts; + + flags.time = flags.nonews = flags.notombstone = flags.end_own = + flags.standout = flags.nonull = FALSE; + flags.no_rest_on_space = TRUE; + flags.invlet_constant = TRUE; + flags.end_top = 5; + flags.end_around = 4; + flags.female = FALSE; /* players are usually male */ + + if ((opts = getenv("HACKOPTIONS"))) + parseoptions(opts,TRUE); +} + +static void +parseoptions(char *opts, bool from_env) +{ + char *op, *op2; + unsigned num; + boolean negated; + + if ((op = strchr(opts, ',')) != NULL) { + *op++ = 0; + parseoptions(op, from_env); + } + if ((op = strchr(opts, ' ')) != NULL) { + op2 = op; + while (*op++) + if (*op != ' ') + *op2++ = *op; + } + if (!*opts) + return; + negated = FALSE; + while ((*opts == '!') || !strncmp(opts, "no", 2)) { + if (*opts == '!') + opts++; + else + opts += 2; + negated = !negated; + } + + if (!strncmp(opts, "standout", 8)) { + flags.standout = !negated; + return; + } + + if (!strncmp(opts, "null", 3)) { + flags.nonull = negated; + return; + } + + if (!strncmp(opts, "tombstone", 4)) { + flags.notombstone = negated; + return; + } + + if (!strncmp(opts, "news", 4)) { + flags.nonews = negated; + return; + } + + if (!strncmp(opts, "time", 4)) { + flags.time = !negated; + flags.botl = 1; + return; + } + + if (!strncmp(opts, "restonspace", 4)) { + flags.no_rest_on_space = negated; + return; + } + + if (!strncmp(opts, "fixinv", 4)) { + if (from_env) + flags.invlet_constant = !negated; + else + pline("The fixinvlet option must be in HACKOPTIONS."); + return; + } + + if (!strncmp(opts, "male", 4)) { + flags.female = negated; + return; + } + if (!strncmp(opts, "female", 6)) { + flags.female = !negated; + return; + } + + /* name:string */ + if (!strncmp(opts, "name", 4)) { + if (!from_env) { + pline("The playername can be set only from HACKOPTIONS."); + return; + } + op = strchr(opts, ':'); + if (!op) + goto bad; + strncpy(plname, op + 1, sizeof(plname) - 1); + return; + } + + /* endgame:5t[op] 5a[round] o[wn] */ + if (!strncmp(opts, "endgame", 3)) { + op = strchr(opts, ':'); + if (!op) + goto bad; + op++; + while (*op) { + num = 1; + if (digit(*op)) { + num = atoi(op); + while (digit(*op)) + op++; + } else if (*op == '!') { + negated = !negated; + op++; + } + switch (*op) { + case 't': + flags.end_top = num; + break; + case 'a': + flags.end_around = num; + break; + case 'o': + flags.end_own = !negated; + break; + default: + goto bad; + } + while (letter(*++op)) + ; /* nothing */ + if (*op == '/') + op++; + } + return; + } +bad: + if (!from_env) { + if (!strncmp(opts, "help", 4)) { + pline("%s%s%s", + "To set options use `HACKOPTIONS=\"\"' in your environment, or ", + "give the command 'o' followed by the line `' while playing. ", + "Here is a list of