home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff256.lzh / Stevie / param.c < prev    next >
C/C++ Source or Header  |  1989-10-19  |  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!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.  
  37.                 {"", "", 0, 0}    /* end marker */
  38. };
  39.  
  40. static void     showparms();
  41.  
  42. void
  43. doset(arg, inter)
  44.     char           *arg;    /* parameter string */
  45.     bool_t          inter;    /* TRUE if called interactively */
  46. {
  47.     int             i;
  48.     char           *s;
  49.     bool_t          did_lines = FALSE;
  50.  
  51.     bool_t          state = TRUE;    /* new state of boolean parms. */
  52.  
  53.     if (arg == NULL) {
  54.     showparms(FALSE);
  55.     return;
  56.     }
  57.     if (strncmp(arg, "all", 3) == 0) {
  58.     showparms(TRUE);
  59.     return;
  60.     }
  61.     if (strncmp(arg, "no", 2) == 0) {
  62.     state = FALSE;
  63.     arg += 2;
  64.     }
  65.     for (i = 0; params[i].fullname[0] != NUL; i++) {
  66.     s = params[i].fullname;
  67.     if (strncmp(arg, s, strlen(s)) == 0)    /* matched full name */
  68.         break;
  69.     s = params[i].shortname;
  70.     if (strncmp(arg, s, strlen(s)) == 0)    /* matched short name */
  71.         break;
  72.     }
  73.  
  74.     if (params[i].fullname[0] != NUL) {    /* found a match */
  75.     if (params[i].flags & P_NUM) {
  76.         did_lines = (i == P_LI);
  77.         if (inter && (arg[strlen(s)] != '=' || state == FALSE))
  78.         emsg("Invalid set of numeric parameter");
  79.         else {
  80.         params[i].value = atoi(arg + strlen(s) + 1);
  81.         params[i].flags |= P_CHANGED;
  82.         }
  83.     } else {        /* boolean */
  84.         if (inter && (arg[strlen(s)] == '='))
  85.         emsg("Invalid set of boolean parameter");
  86.         else {
  87.         params[i].value = state;
  88.         params[i].flags |= P_CHANGED;
  89.         }
  90.     }
  91.     } else {
  92.     if (inter)
  93.         emsg("Unrecognized 'set' option");
  94.     }
  95.  
  96.     if (did_lines) {
  97.     Rows = P(P_LI);
  98.     screenalloc();        /* allocate new screen buffers */
  99.     s_clear();
  100.     }
  101.     /*
  102.      * Mark the screen contents as not valid in case we changed something
  103.      * like "tabstop" or "list" that will change its appearance. 
  104.      */
  105.     if (inter)
  106.     S_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.