home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / HACKSRC.ZIP / OPTIONS.C < prev    next >
C/C++ Source or Header  |  1985-10-16  |  8KB  |  328 lines

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