1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.options.c - version 1.0.3 */
3 /* $FreeBSD: src/games/hack/hack.options.c,v 1.5 1999/11/16 02:57:08 billf Exp $ */
4 /* $DragonFly: src/games/hack/hack.options.c,v 1.3 2006/08/21 19:45:32 pavalos Exp $ */
8 static void parseoptions(char *, bool);
15 flags.time = flags.nonews = flags.notombstone = flags.end_own =
16 flags.standout = flags.nonull = FALSE;
17 flags.no_rest_on_space = TRUE;
18 flags.invlet_constant = TRUE;
21 flags.female = FALSE; /* players are usually male */
23 if((opts = getenv("HACKOPTIONS")))
24 parseoptions(opts,TRUE);
28 parseoptions(char *opts, bool from_env)
34 if((op = index(opts, ','))) {
36 parseoptions(op, from_env);
38 if((op = index(opts, ' '))) {
41 if(*op != ' ') *op2++ = *op;
45 while((*opts == '!') || !strncmp(opts, "no", 2)) {
46 if(*opts == '!') opts++; else opts += 2;
50 if(!strncmp(opts,"standout",8)) {
51 flags.standout = !negated;
55 if(!strncmp(opts,"null",3)) {
56 flags.nonull = negated;
60 if(!strncmp(opts,"tombstone",4)) {
61 flags.notombstone = negated;
65 if(!strncmp(opts,"news",4)) {
66 flags.nonews = negated;
70 if(!strncmp(opts,"time",4)) {
71 flags.time = !negated;
76 if(!strncmp(opts,"restonspace",4)) {
77 flags.no_rest_on_space = negated;
81 if(!strncmp(opts,"fixinv",4)) {
83 flags.invlet_constant = !negated;
85 pline("The fixinvlet option must be in HACKOPTIONS.");
89 if(!strncmp(opts,"male",4)) {
90 flags.female = negated;
93 if(!strncmp(opts,"female",6)) {
94 flags.female = !negated;
99 if(!strncmp(opts,"name",4)) {
101 pline("The playername can be set only from HACKOPTIONS.");
104 op = index(opts,':');
106 strncpy(plname, op+1, sizeof(plname)-1);
110 /* endgame:5t[op] 5a[round] o[wn] */
111 if(!strncmp(opts,"endgame",3)) {
112 op = index(opts,':');
119 while(digit(*op)) op++;
130 flags.end_around = num;
133 flags.end_own = !negated;
138 while(letter(*++op)) ;
145 if(!strncmp(opts, "help", 4)) {
147 "To set options use `HACKOPTIONS=\"<options>\"' in your environment, or ",
148 "give the command 'o' followed by the line `<options>' while playing. ",
149 "Here <options> is a list of <option>s separated by commas." );
151 "Simple (boolean) options are rest_on_space, news, time, ",
152 "null, tombstone, (fe)male. ",
153 "These can be negated by prefixing them with '!' or \"no\"." );
155 "A string option is name, as in HACKOPTIONS=\"name:Merlin-W\"." );
157 "A compound option is endgame; it is followed by a description of what ",
158 "parts of the scorelist you want to see. You might for example say: ",
159 "`endgame:own scores/5 top scores/4 around my score'." );
162 pline("Bad option: %s.", opts);
163 pline("Type `o help<cr>' for help.");
166 puts("Bad syntax in HACKOPTIONS.");
167 puts("Use for example:");
169 "HACKOPTIONS=\"!restonspace,notombstone,endgame:own/5 topscorers/4 around me\""
179 pline("What options do you want to set? ");
181 if(!buf[0] || buf[0] == '\033') {
182 strcpy(buf,"HACKOPTIONS=");
183 strcat(buf, flags.female ? "female," : "male,");
184 if(flags.standout) strcat(buf,"standout,");
185 if(flags.nonull) strcat(buf,"nonull,");
186 if(flags.nonews) strcat(buf,"nonews,");
187 if(flags.time) strcat(buf,"time,");
188 if(flags.notombstone) strcat(buf,"notombstone,");
189 if(flags.no_rest_on_space)
190 strcat(buf,"!rest_on_space,");
191 if(flags.end_top != 5 || flags.end_around != 4 || flags.end_own){
192 sprintf(eos(buf), "endgame: %u topscores/%u around me",
193 flags.end_top, flags.end_around);
194 if(flags.end_own) strcat(buf, "/own scores");
196 char *eop = eos(buf);
197 if(*--eop == ',') *eop = 0;
201 parseoptions(buf, FALSE);