home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 313_01 / param.c < prev    next >
C/C++ Source or Header  |  1990-04-22  |  4KB  |  163 lines

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