home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 100-199 / ff197.lzh / Stevie / param.c < prev    next >
C/C++ Source or Header  |  1989-03-28  |  4KB  |  162 lines

  1. /*
  2.  * STEVIE - Simply Try this Editor for VI Enthusiasts
  3.  *
  4.  * Code Contributions By : Tim Thompson           twitch!tjt
  5.  *                         Tony Andrews           onecom!wldrdg!tony 
  6.  *                         G. R. (Fred) Walter    watmath!watcgl!grwalter 
  7.  */
  8.  
  9. /*
  10.  * Code to handle user-settable parameters. This is all pretty much table-
  11.  * driven. To add a new parameter, put it in the params array, and add a
  12.  * macro for it in param.h. If it's a numeric parameter, add any necessary
  13.  * bounds checks to doset(). String parameters aren't currently supported. 
  14.  */
  15.  
  16. #include "stevie.h"
  17.  
  18. struct param    params[] = {
  19.  
  20.                 {"tabstop", "ts", 8, P_NUM},
  21.                 {"scroll", "scroll", 12, P_NUM},
  22.                 {"report", "report", 5, P_NUM},
  23.                 {"lines", "lines", 25, P_NUM},
  24.  
  25.                 {"vbell", "vb", TRUE, P_BOOL},
  26.                 {"showmatch", "sm", FALSE, P_BOOL},
  27.                 {"wrapscan", "ws", TRUE, P_BOOL},
  28.                 {"errorbells", "eb", FALSE, P_BOOL},
  29.                 {"showmode", "mo", FALSE, P_BOOL},
  30.                 {"backup", "bk", FALSE, P_BOOL},
  31.                 {"return", "cr", TRUE, P_BOOL},
  32.                 {"list", "list", FALSE, P_BOOL},
  33.                 {"ignorecase", "ic", FALSE, P_BOOL},
  34.                 {"autoindent", "ai", FALSE, P_BOOL},
  35.                 {"number", "nu", FALSE, P_BOOL},
  36.                 {"", "", 0, 0}    /* end marker */
  37. };
  38.  
  39. static void     showparms();
  40.  
  41. void
  42. doset(arg, inter)
  43.     char           *arg;    /* parameter string */
  44.     bool_t          inter;    /* TRUE if called interactively */
  45. {
  46.     int             i;
  47.     char           *s;
  48.     bool_t          did_lines = FALSE;
  49.  
  50.     bool_t          state = TRUE;    /* new state of boolean parms. */
  51.  
  52.     if (arg == NULL) {
  53.     showparms(FALSE);
  54.     return;
  55.     }
  56.     if (strncmp(arg, "all", 3) == 0) {
  57.     showparms(TRUE);
  58.     return;
  59.     }
  60.     if (strncmp(arg, "no", 2) == 0) {
  61.     state = FALSE;
  62.     arg += 2;
  63.     }
  64.     for (i = 0; params[i].fullname[0] != NUL; i++) {
  65.     s = params[i].fullname;
  66.     if (strncmp(arg, s, strlen(s)) == 0)    /* matched full name */
  67.         break;
  68.     s = params[i].shortname;
  69.     if (strncmp(arg, s, strlen(s)) == 0)    /* matched short name */
  70.         break;
  71.     }
  72.  
  73.     if (params[i].fullname[0] != NUL) {    /* found a match */
  74.     if (params[i].flags & P_NUM) {
  75.         did_lines = (i == P_LI);
  76.         if (inter && (arg[strlen(s)] != '=' || state == FALSE))
  77.         emsg("Invalid set of numeric parameter");
  78.         else {
  79.         params[i].value = atoi(arg + strlen(s) + 1);
  80.         params[i].flags |= P_CHANGED;
  81.         }
  82.     } else {        /* boolean */
  83.         if (inter && (arg[strlen(s)] == '='))
  84.         emsg("Invalid set of boolean parameter");
  85.         else {
  86.         params[i].value = state;
  87.         params[i].flags |= P_CHANGED;
  88.         }
  89.     }
  90.     } else {
  91.     if (inter)
  92.         emsg("Unrecognized 'set' option");
  93.     }
  94.  
  95.     /*
  96.      * Update the screen in case we changed something like "tabstop" or
  97.      * "list" that will change its appearance. 
  98.      */
  99.     if (inter)
  100.     updateNextscreen(NOT_VALID);
  101.  
  102.     if (did_lines) {
  103.     Rows = P(P_LI);
  104.     screenalloc();        /* allocate new screen buffers */
  105.     screenclear();
  106.     updateNextscreen(NOT_VALID);
  107.     }
  108.     /*
  109.      * Check the bounds for numeric parameters here 
  110.      */
  111.     if (P(P_TS) <= 0 || P(P_TS) > 32) {
  112.     if (inter)
  113.         emsg("Invalid tab size specified");
  114.     P(P_TS) = 8;
  115.     return;
  116.     }
  117.     if (P(P_SS) <= 0 || P(P_SS) > Rows) {
  118.     if (inter)
  119.         emsg("Invalid scroll size specified");
  120.     P(P_SS) = 12;
  121.     return;
  122.     }
  123.     /*
  124.      * Check for another argument, and call doset() recursively, if found. If
  125.      * any argument results in an error, no further parameters are processed. 
  126.      */
  127.     while (*arg != ' ' && *arg != '\t') {    /* skip to next white space */
  128.     if (*arg == NUL)
  129.         return;        /* end of parameter list */
  130.     arg++;
  131.     }
  132.     while (*arg == ' ' || *arg == '\t')    /* skip to next non-white */
  133.     arg++;
  134.  
  135.     if (*arg)
  136.     doset(arg, TRUE);    /* recurse on next parameter, if present */
  137. }
  138.  
  139. static void
  140. showparms(all)
  141.     bool_t          all;    /* show ALL parameters */
  142. {
  143.     struct param   *p;
  144.     char            buf[64];
  145.  
  146.     gotocmdline(YES, NUL);
  147.     outstr("Parameters:\r\n");
  148.  
  149.     for (p = ¶ms[0]; p->fullname[0] != NUL; p++) {
  150.     if (!all && ((p->flags & P_CHANGED) == 0))
  151.         continue;
  152.     if (p->flags & P_BOOL)
  153.         sprintf(buf, "\t%s%s\r\n",
  154.             (p->value ? "" : "no"), p->fullname);
  155.     else
  156.         sprintf(buf, "\t%s=%d\r\n", p->fullname, p->value);
  157.  
  158.     outstr(buf);
  159.     }
  160.     wait_return();
  161. }
  162.