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