options.c (7843B)
1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 2 /* options.c - version 1.0.3 */ 3 4 #include "hack.h" 5 extern char *eos(); 6 boolean female; 7 #ifdef DGK 8 static boolean set_order; 9 #endif 10 11 initoptions() 12 { 13 register char *opts; 14 extern char *getenv(); 15 16 flags.time = flags.nonews = flags.notombstone = flags.end_own = 17 flags.standout = flags.nonull = FALSE; 18 flags.invlet_constant = TRUE; 19 flags.no_rest_on_space = TRUE; 20 flags.end_top = 5; 21 flags.end_around = 4; 22 female = FALSE; /* players are usually male */ 23 24 #ifdef DGK 25 flags.silent = flags.IBMBIOS = flags.DECRainbow = flags.rawio = FALSE; 26 flags.confirm = flags.pickup = flags.sortpack = TRUE; 27 read_config_file(); 28 #else 29 if(opts = getenv("HACKOPTIONS")) 30 parseoptions(opts,TRUE); 31 #endif 32 } 33 34 parseoptions(opts, from_env) 35 register char *opts; 36 boolean from_env; 37 { 38 register char *op,*op2; 39 unsigned num; 40 boolean negated; 41 42 if(op = index(opts, ',')) { 43 *op++ = 0; 44 parseoptions(op, from_env); 45 } 46 if(op = index(opts, ' ')) { 47 op2 = op; 48 while(*op++) 49 if(*op != ' ') *op2++ = *op; 50 } 51 if(!*opts) return; 52 negated = FALSE; 53 while((*opts == '!') || !strncmp(opts, "no", 2)) { 54 if(*opts == '!') opts++; else opts += 2; 55 negated = !negated; 56 } 57 58 #ifndef DGK 59 if(!strncmp(opts,"standout",4)) { 60 flags.standout = !negated; 61 return; 62 } 63 64 if(!strncmp(opts,"null",4)) { 65 flags.nonull = negated; 66 return; 67 } 68 69 if(!strncmp(opts,"tombstone",4)) { 70 flags.notombstone = negated; 71 return; 72 } 73 #endif 74 75 #ifdef DGK 76 if (!strncmp(opts, "sile", 4)) { 77 flags.silent = !negated; 78 return; 79 } 80 81 if (!strncmp(opts, "conf", 4)) { 82 flags.confirm = !negated; 83 return; 84 } 85 86 if (!strncmp(opts, "pick", 4)) { 87 flags.pickup = !negated; 88 return; 89 } 90 91 if (!strncmp(opts, "IBMB", 4)) { 92 flags.IBMBIOS = !negated; 93 return; 94 } 95 96 if (!strncmp(opts, "rawi", 4)) { 97 if (from_env) 98 flags.rawio = !negated; 99 else 100 pline("'rawio' only settable from %s.", configfile); 101 return; 102 } 103 104 if (!strncmp(opts, "DECR", 4)) { 105 flags.DECRainbow = !negated; 106 return; 107 } 108 109 if (!strncmp(opts, "sort", 4)) { 110 flags.sortpack = !negated; 111 return; 112 } 113 114 /* 115 * the order to list the pack 116 */ 117 if (!strncmp(opts,"packorder",4)) { 118 register char *sp, *tmp; 119 extern char inv_order[]; 120 int tmpend; 121 122 op = index(opts,':'); 123 if(!op) goto bad; 124 op++; /* skip : */ 125 126 /* Missing characters in new order are filled in at the end 127 * from inv_order. 128 */ 129 for (sp = op; *sp; sp++) 130 if (!index(inv_order, *sp)) 131 goto bad; /* bad char in order */ 132 else if (index(sp + 1, *sp)) 133 goto bad; /* dup char in order */ 134 tmp = (char *) alloc(strlen(inv_order) + 1); 135 (void) strcpy(tmp, op); 136 for (sp = inv_order, tmpend = strlen(tmp); *sp; sp++) 137 if (!index(tmp, *sp)) { 138 tmp[tmpend++] = *sp; 139 tmp[tmpend] = 0; 140 } 141 (void) strcpy(inv_order, tmp); 142 free(tmp); 143 set_order = TRUE; 144 return; 145 } 146 #endif 147 148 if(!strncmp(opts,"time",4)) { 149 flags.time = !negated; 150 flags.botl = 1; 151 return; 152 } 153 154 if(!strncmp(opts,"restonspace",4)) { 155 flags.no_rest_on_space = negated; 156 return; 157 } 158 159 #ifndef DGK 160 if(!strncmp(opts,"fixinv",4)) { 161 if(from_env) 162 flags.invlet_constant = !negated; 163 else 164 pline("The fixinvlet option must be in HACKOPTIONS."); 165 return; 166 } 167 #endif 168 169 if(!strncmp(opts,"male",4)) { 170 female = negated; 171 return; 172 } 173 if(!strncmp(opts,"female",4)) { 174 female = !negated; 175 return; 176 } 177 178 /* name:string */ 179 if(!strncmp(opts,"name",4)) { 180 extern char plname[PL_NSIZ]; 181 if(!from_env) { 182 #ifdef DGK 183 pline("'name' only settable from %s.", configfile); 184 #else 185 pline("The playername can be set only from HACKOPTIONS."); 186 #endif 187 return; 188 } 189 op = index(opts,':'); 190 if(!op) goto bad; 191 (void) strncpy(plname, op+1, sizeof(plname)-1); 192 return; 193 } 194 195 /* endgame:5t[op] 5a[round] o[wn] */ 196 if(!strncmp(opts,"endgame",3)) { 197 op = index(opts,':'); 198 if(!op) goto bad; 199 op++; 200 while(*op) { 201 num = 1; 202 if(digit(*op)) { 203 num = atoi(op); 204 while(digit(*op)) op++; 205 } else 206 if(*op == '!') { 207 negated = !negated; 208 op++; 209 } 210 switch(*op) { 211 case 't': 212 flags.end_top = num; 213 break; 214 case 'a': 215 flags.end_around = num; 216 break; 217 case 'o': 218 flags.end_own = !negated; 219 break; 220 default: 221 goto bad; 222 } 223 while(letter(*++op)) ; 224 if(*op == '/') op++; 225 } 226 return; 227 } 228 bad: 229 if(!from_env) { 230 if(!strncmp(opts, "help", 4)) { 231 pline("%s%s%s%s", 232 #ifdef DGK 233 234 "To set options use OPTIONS=<options> in ", configfile, 235 " or give the command \"O\" followed by the line <options> while playing. ", 236 "Here <options> is a list of options separated by commas." ); 237 pline("%s%s", 238 "Boolean options are confirm, pickup, rawio, silent, sortpack, time, IBMBIOS,", 239 " and DECRainbow. These can be negated by prefixing them with '!' or \"no\"." ); 240 pline("%s%s%s", 241 "The compound options are name, as in OPTIONS=name:Merlin-W, packorder, ", 242 "which lists the order that items should appear in your pack (the ", 243 "default is: packorder:\")[%?/=!(*0 ), and endgame." ); 244 pline("%s%s%s", 245 "Endgame is followed by a description of which parts of the scorelist ", 246 "you wish to see. You might for example say: ", 247 "\"endgame:own scores/5 top scores/4 around my score\"." ); 248 249 #else 250 251 "To set options use `HACKOPTIONS=\"<options>\"' in your environment, or ", 252 "give the command 'o' followed by the line `<options>' while playing. ", 253 "Here <options> is a list of <option>s separated by commas." ); 254 pline("%s%s%s", 255 "Simple (boolean) options are rest_on_space, news, time, ", 256 "null, tombstone, (fe)male. ", 257 "These can be negated by prefixing them with '!' or \"no\"." ); 258 pline("%s", 259 "A string option is name, as in HACKOPTIONS=\"name:Merlin-W\"." ); 260 pline("%s%s%s", 261 "A compound option is endgame; it is followed by a description of what ", 262 "parts of the scorelist you want to see. You might for example say: ", 263 "`endgame:own scores/5 top scores/4 around my score'." ); 264 265 #endif /* DGK /**/ 266 return; 267 } 268 pline("Bad option: %s.", opts); 269 pline("Type \"O help<cr>\" for help."); 270 return; 271 } 272 #ifdef DGK 273 printf("Bad syntax in OPTIONS in %s.", configfile); 274 #else 275 puts("Bad syntax in HACKOPTIONS."); 276 puts("Use for example:"); 277 puts( 278 "HACKOPTIONS=\"!restonspace,notombstone,endgame:own/5 topscorers/4 around me\"" 279 ); 280 #endif 281 getret(); 282 } 283 284 doset() 285 { 286 char buf[BUFSZ]; 287 #ifdef DGK 288 extern char inv_order[]; 289 #endif 290 291 pline("What options do you want to set? "); 292 getlin(buf); 293 if(!buf[0] || buf[0] == '\033') { 294 #ifdef DGK 295 (void) strcpy(buf,"OPTIONS="); 296 #else 297 (void) strcpy(buf,"HACKOPTIONS="); 298 #endif 299 #ifndef DGK 300 (void) strcat(buf,female ? "female," : "male,"); 301 if(flags.standout) (void) strcat(buf,"standout,"); 302 if(flags.nonull) (void) strcat(buf,"nonull,"); 303 #endif 304 if(flags.time) (void) strcat(buf,"time,"); 305 #ifndef DGK 306 if(flags.notombstone) (void) strcat(buf,"!tombstone,"); 307 if(flags.invlet_constant) (void) strcat(buf,"fixinv,"); 308 if(!flags.no_rest_on_space) (void) strcat(buf,"restonspace,"); 309 #endif 310 #ifdef DGK 311 if (flags.confirm) (void) strcat(buf,"confirm,"); 312 if (set_order){ 313 (void) strcat(buf, "packorder: "); 314 (void) strcat(buf, inv_order); 315 (void) strcat(buf, ","); 316 } 317 if (flags.pickup) (void) strcat(buf,"pickup,"); 318 if (flags.rawio) (void) strcat(buf,"rawio,"); 319 if (flags.silent) (void) strcat(buf,"silent,"); 320 if (flags.sortpack) (void) strcat(buf,"sortpack,"); 321 if (flags.IBMBIOS) (void) strcat(buf,"IBMBIOS,"); 322 if (flags.DECRainbow) (void) strcat(buf,"DECRainbow,"); 323 #endif 324 if(flags.end_top != 5 || flags.end_around != 4 || flags.end_own){ 325 (void) sprintf(eos(buf), "endgame: %u topscores/%u around me", 326 flags.end_top, flags.end_around); 327 if(flags.end_own) (void) strcat(buf, "/own scores"); 328 } else { 329 register char *eop = eos(buf); 330 if(*--eop == ',') *eop = 0; 331 } 332 pline(buf); 333 } else 334 parseoptions(buf, FALSE); 335 return(0); 336 }