1*ea059eabSbostic /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2*ea059eabSbostic /* hack.options.c - version 1.0.3 */
3*ea059eabSbostic
4*ea059eabSbostic #include "config.h"
5*ea059eabSbostic #include "hack.h"
6*ea059eabSbostic extern char *eos();
7*ea059eabSbostic
initoptions()8*ea059eabSbostic initoptions()
9*ea059eabSbostic {
10*ea059eabSbostic register char *opts;
11*ea059eabSbostic extern char *getenv();
12*ea059eabSbostic
13*ea059eabSbostic flags.time = flags.nonews = flags.notombstone = flags.end_own =
14*ea059eabSbostic flags.standout = flags.nonull = FALSE;
15*ea059eabSbostic flags.no_rest_on_space = TRUE;
16*ea059eabSbostic flags.invlet_constant = TRUE;
17*ea059eabSbostic flags.end_top = 5;
18*ea059eabSbostic flags.end_around = 4;
19*ea059eabSbostic flags.female = FALSE; /* players are usually male */
20*ea059eabSbostic
21*ea059eabSbostic if(opts = getenv("HACKOPTIONS"))
22*ea059eabSbostic parseoptions(opts,TRUE);
23*ea059eabSbostic }
24*ea059eabSbostic
parseoptions(opts,from_env)25*ea059eabSbostic parseoptions(opts, from_env)
26*ea059eabSbostic register char *opts;
27*ea059eabSbostic boolean from_env;
28*ea059eabSbostic {
29*ea059eabSbostic register char *op,*op2;
30*ea059eabSbostic unsigned num;
31*ea059eabSbostic boolean negated;
32*ea059eabSbostic
33*ea059eabSbostic if(op = index(opts, ',')) {
34*ea059eabSbostic *op++ = 0;
35*ea059eabSbostic parseoptions(op, from_env);
36*ea059eabSbostic }
37*ea059eabSbostic if(op = index(opts, ' ')) {
38*ea059eabSbostic op2 = op;
39*ea059eabSbostic while(*op++)
40*ea059eabSbostic if(*op != ' ') *op2++ = *op;
41*ea059eabSbostic }
42*ea059eabSbostic if(!*opts) return;
43*ea059eabSbostic negated = FALSE;
44*ea059eabSbostic while((*opts == '!') || !strncmp(opts, "no", 2)) {
45*ea059eabSbostic if(*opts == '!') opts++; else opts += 2;
46*ea059eabSbostic negated = !negated;
47*ea059eabSbostic }
48*ea059eabSbostic
49*ea059eabSbostic if(!strncmp(opts,"standout",8)) {
50*ea059eabSbostic flags.standout = !negated;
51*ea059eabSbostic return;
52*ea059eabSbostic }
53*ea059eabSbostic
54*ea059eabSbostic if(!strncmp(opts,"null",3)) {
55*ea059eabSbostic flags.nonull = negated;
56*ea059eabSbostic return;
57*ea059eabSbostic }
58*ea059eabSbostic
59*ea059eabSbostic if(!strncmp(opts,"tombstone",4)) {
60*ea059eabSbostic flags.notombstone = negated;
61*ea059eabSbostic return;
62*ea059eabSbostic }
63*ea059eabSbostic
64*ea059eabSbostic if(!strncmp(opts,"news",4)) {
65*ea059eabSbostic flags.nonews = negated;
66*ea059eabSbostic return;
67*ea059eabSbostic }
68*ea059eabSbostic
69*ea059eabSbostic if(!strncmp(opts,"time",4)) {
70*ea059eabSbostic flags.time = !negated;
71*ea059eabSbostic flags.botl = 1;
72*ea059eabSbostic return;
73*ea059eabSbostic }
74*ea059eabSbostic
75*ea059eabSbostic if(!strncmp(opts,"restonspace",4)) {
76*ea059eabSbostic flags.no_rest_on_space = negated;
77*ea059eabSbostic return;
78*ea059eabSbostic }
79*ea059eabSbostic
80*ea059eabSbostic if(!strncmp(opts,"fixinv",4)) {
81*ea059eabSbostic if(from_env)
82*ea059eabSbostic flags.invlet_constant = !negated;
83*ea059eabSbostic else
84*ea059eabSbostic pline("The fixinvlet option must be in HACKOPTIONS.");
85*ea059eabSbostic return;
86*ea059eabSbostic }
87*ea059eabSbostic
88*ea059eabSbostic if(!strncmp(opts,"male",4)) {
89*ea059eabSbostic flags.female = negated;
90*ea059eabSbostic return;
91*ea059eabSbostic }
92*ea059eabSbostic if(!strncmp(opts,"female",6)) {
93*ea059eabSbostic flags.female = !negated;
94*ea059eabSbostic return;
95*ea059eabSbostic }
96*ea059eabSbostic
97*ea059eabSbostic /* name:string */
98*ea059eabSbostic if(!strncmp(opts,"name",4)) {
99*ea059eabSbostic extern char plname[PL_NSIZ];
100*ea059eabSbostic if(!from_env) {
101*ea059eabSbostic pline("The playername can be set only from HACKOPTIONS.");
102*ea059eabSbostic return;
103*ea059eabSbostic }
104*ea059eabSbostic op = index(opts,':');
105*ea059eabSbostic if(!op) goto bad;
106*ea059eabSbostic (void) strncpy(plname, op+1, sizeof(plname)-1);
107*ea059eabSbostic return;
108*ea059eabSbostic }
109*ea059eabSbostic
110*ea059eabSbostic /* endgame:5t[op] 5a[round] o[wn] */
111*ea059eabSbostic if(!strncmp(opts,"endgame",3)) {
112*ea059eabSbostic op = index(opts,':');
113*ea059eabSbostic if(!op) goto bad;
114*ea059eabSbostic op++;
115*ea059eabSbostic while(*op) {
116*ea059eabSbostic num = 1;
117*ea059eabSbostic if(digit(*op)) {
118*ea059eabSbostic num = atoi(op);
119*ea059eabSbostic while(digit(*op)) op++;
120*ea059eabSbostic } else
121*ea059eabSbostic if(*op == '!') {
122*ea059eabSbostic negated = !negated;
123*ea059eabSbostic op++;
124*ea059eabSbostic }
125*ea059eabSbostic switch(*op) {
126*ea059eabSbostic case 't':
127*ea059eabSbostic flags.end_top = num;
128*ea059eabSbostic break;
129*ea059eabSbostic case 'a':
130*ea059eabSbostic flags.end_around = num;
131*ea059eabSbostic break;
132*ea059eabSbostic case 'o':
133*ea059eabSbostic flags.end_own = !negated;
134*ea059eabSbostic break;
135*ea059eabSbostic default:
136*ea059eabSbostic goto bad;
137*ea059eabSbostic }
138*ea059eabSbostic while(letter(*++op)) ;
139*ea059eabSbostic if(*op == '/') op++;
140*ea059eabSbostic }
141*ea059eabSbostic return;
142*ea059eabSbostic }
143*ea059eabSbostic bad:
144*ea059eabSbostic if(!from_env) {
145*ea059eabSbostic if(!strncmp(opts, "help", 4)) {
146*ea059eabSbostic pline("%s%s%s",
147*ea059eabSbostic "To set options use `HACKOPTIONS=\"<options>\"' in your environment, or ",
148*ea059eabSbostic "give the command 'o' followed by the line `<options>' while playing. ",
149*ea059eabSbostic "Here <options> is a list of <option>s separated by commas." );
150*ea059eabSbostic pline("%s%s%s",
151*ea059eabSbostic "Simple (boolean) options are rest_on_space, news, time, ",
152*ea059eabSbostic "null, tombstone, (fe)male. ",
153*ea059eabSbostic "These can be negated by prefixing them with '!' or \"no\"." );
154*ea059eabSbostic pline("%s",
155*ea059eabSbostic "A string option is name, as in HACKOPTIONS=\"name:Merlin-W\"." );
156*ea059eabSbostic pline("%s%s%s",
157*ea059eabSbostic "A compound option is endgame; it is followed by a description of what ",
158*ea059eabSbostic "parts of the scorelist you want to see. You might for example say: ",
159*ea059eabSbostic "`endgame:own scores/5 top scores/4 around my score'." );
160*ea059eabSbostic return;
161*ea059eabSbostic }
162*ea059eabSbostic pline("Bad option: %s.", opts);
163*ea059eabSbostic pline("Type `o help<cr>' for help.");
164*ea059eabSbostic return;
165*ea059eabSbostic }
166*ea059eabSbostic puts("Bad syntax in HACKOPTIONS.");
167*ea059eabSbostic puts("Use for example:");
168*ea059eabSbostic puts(
169*ea059eabSbostic "HACKOPTIONS=\"!restonspace,notombstone,endgame:own/5 topscorers/4 around me\""
170*ea059eabSbostic );
171*ea059eabSbostic getret();
172*ea059eabSbostic }
173*ea059eabSbostic
doset()174*ea059eabSbostic doset()
175*ea059eabSbostic {
176*ea059eabSbostic char buf[BUFSZ];
177*ea059eabSbostic
178*ea059eabSbostic pline("What options do you want to set? ");
179*ea059eabSbostic getlin(buf);
180*ea059eabSbostic if(!buf[0] || buf[0] == '\033') {
181*ea059eabSbostic (void) strcpy(buf,"HACKOPTIONS=");
182*ea059eabSbostic (void) strcat(buf, flags.female ? "female," : "male,");
183*ea059eabSbostic if(flags.standout) (void) strcat(buf,"standout,");
184*ea059eabSbostic if(flags.nonull) (void) strcat(buf,"nonull,");
185*ea059eabSbostic if(flags.nonews) (void) strcat(buf,"nonews,");
186*ea059eabSbostic if(flags.time) (void) strcat(buf,"time,");
187*ea059eabSbostic if(flags.notombstone) (void) strcat(buf,"notombstone,");
188*ea059eabSbostic if(flags.no_rest_on_space)
189*ea059eabSbostic (void) strcat(buf,"!rest_on_space,");
190*ea059eabSbostic if(flags.end_top != 5 || flags.end_around != 4 || flags.end_own){
191*ea059eabSbostic (void) sprintf(eos(buf), "endgame: %u topscores/%u around me",
192*ea059eabSbostic flags.end_top, flags.end_around);
193*ea059eabSbostic if(flags.end_own) (void) strcat(buf, "/own scores");
194*ea059eabSbostic } else {
195*ea059eabSbostic register char *eop = eos(buf);
196*ea059eabSbostic if(*--eop == ',') *eop = 0;
197*ea059eabSbostic }
198*ea059eabSbostic pline(buf);
199*ea059eabSbostic } else
200*ea059eabSbostic parseoptions(buf, FALSE);
201*ea059eabSbostic
202*ea059eabSbostic return(0);
203*ea059eabSbostic }
204