Annotation of 43BSDReno/games/hack/hack.options.c, revision 1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.