home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / STVI369G.ZIP / PARAM.C < prev    next >
C/C++ Source or Header  |  1990-05-01  |  4KB  |  171 lines

  1. /* $Header: /nw/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.     { "tagstack",    "tg",        FALSE,    P_BOOL },
  33.     { "color",    "co",        -1,    P_NUM  },
  34.     { "",        "",        0,    0, }        /* end marker */
  35.  
  36. };
  37.  
  38. static    void    showparms();
  39.  
  40. void
  41. doset(arg)
  42. char    *arg;        /* parameter string */
  43. {
  44.     register int    i;
  45.     register char    *s;
  46.     bool_t    did_lines = FALSE;
  47.     bool_t    state = TRUE;        /* new state of boolean parms. */
  48.  
  49.     if (arg == NULL) {
  50.         showparms(FALSE);
  51.         return;
  52.     }
  53.     if (strncmp(arg, "all", 3) == 0) {
  54.         showparms(TRUE);
  55.         return;
  56.     }
  57.     if (strncmp(arg, "no", 2) == 0) {
  58.         state = FALSE;
  59.         arg += 2;
  60.     }
  61.  
  62.     for (i=0; params[i].fullname[0] != NUL ;i++) {
  63.         s = params[i].fullname;
  64.         if (strncmp(arg, s, strlen(s)) == 0)    /* matched full name */
  65.             break;
  66.         s = params[i].shortname;
  67.         if (strncmp(arg, s, strlen(s)) == 0)    /* matched short name */
  68.             break;
  69.     }
  70.  
  71.     if (params[i].fullname[0] != NUL) {    /* found a match */
  72.         if (params[i].flags & P_NUM) {
  73.             did_lines = (i == P_LI);
  74.             if (arg[strlen(s)] != '=' || state == FALSE)
  75.                 emsg("Invalid set of numeric parameter");
  76.             else {
  77.                 params[i].value = atoi(arg+strlen(s)+1);
  78.                 params[i].flags |= P_CHANGED;
  79.                 if (i==P_CO)  setcolor (P(P_CO));
  80.             }
  81.         } else /* boolean */ {
  82.             if (arg[strlen(s)] == '=')
  83.                 emsg("Invalid set of boolean parameter");
  84.             else {
  85.                 params[i].value = state;
  86.                 params[i].flags |= P_CHANGED;
  87.             }
  88.         }
  89.     } else
  90.         emsg("Unrecognized 'set' option");
  91.  
  92.     /*
  93.      * Update the screen in case we changed something like "tabstop"
  94.      * or "list" that will change its appearance.
  95.      */
  96.     updatescreen();
  97.  
  98.     if (did_lines) {
  99.         Rows = P(P_LI);
  100.         P(P_LI) = Rows = setrows( Rows );
  101.                     /* setrows() is system-dependent.
  102.                      * This assures no impossible values
  103.                      * will be set.
  104.                      */
  105.         if (screenalloc() == -1) return;    /* allocate new screen buffers */
  106.         screenclear();
  107.         updatescreen();
  108.     }
  109.     /*
  110.      * Check the bounds for numeric parameters here
  111.      */
  112.     if (P(P_TS) <= 0 || P(P_TS) > 32) {
  113.         emsg("Invalid tab size specified");
  114.         P(P_TS) = 8;
  115.         return;
  116.     }
  117.  
  118.     if (P(P_SS) <= 0 || P(P_SS) > Rows) {
  119.         emsg("Invalid scroll size specified");
  120.         P(P_SS) = 12;
  121.         return;
  122.     }
  123.  
  124. #ifndef    TILDEOP
  125.     if (P(P_TO)) {
  126.         emsg("Tilde-operator not enabled");
  127.         P(P_TO) = FALSE;
  128.         return;
  129.     }
  130. #endif
  131.     /*
  132.      * Check for another argument, and call doset() recursively, if
  133.      * found. If any argument results in an error, no further
  134.      * parameters are processed.
  135.      */
  136.     while (*arg != ' ' && *arg != '\t') {    /* skip to next white space */
  137.         if (*arg == NUL)
  138.             return;            /* end of parameter list */
  139.         arg++;
  140.     }
  141.     while (*arg == ' ' || *arg == '\t')    /* skip to next non-white */
  142.         arg++;
  143.  
  144.     if (*arg)
  145.         doset(arg);    /* recurse on next parameter */
  146. }
  147.  
  148. static    void
  149. showparms(all)
  150. bool_t    all;    /* show ALL parameters */
  151. {
  152.     register struct    param    *p;
  153.     char    buf[64];
  154.  
  155.     gotocmd(TRUE, 0);
  156.     outstr("Parameters:\r\n");
  157.  
  158.     for (p = ¶ms[0]; p->fullname[0] != NUL ;p++) {
  159.         if (!all && ((p->flags & P_CHANGED) == 0))
  160.             continue;
  161.         if (p->flags & P_BOOL)
  162.             sprintf(buf, "\t%s%s\r\n",
  163.                 (p->value ? "" : "no"), p->fullname);
  164.         else
  165.             sprintf(buf, "\t%s=%d\r\n", p->fullname, p->value);
  166.  
  167.         outstr(buf);
  168.     }
  169.     wait_return();
  170. }
  171.