home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Distributions / ucb / spencer_2bsd.tar.gz / 2bsd.tar / src / ex / ex_set.c < prev    next >
C/C++ Source or Header  |  1980-02-17  |  3KB  |  179 lines

  1. /* Copyright (c) 1979 Regents of the University of California */
  2. #include "ex.h"
  3. #include "ex_temp.h"
  4.  
  5. /*
  6.  * Set command.
  7.  */
  8. char    optname[ONMSZ];
  9.  
  10. set()
  11. {
  12.     register char *cp;
  13.     register struct option *op;
  14.     register int c;
  15.     bool no;
  16.  
  17.     setnoaddr();
  18.     if (skipend()) {
  19.         if (peekchar() != EOF)
  20.             ignchar();
  21.         propts();
  22.         return;
  23.     }
  24.     do {
  25.         cp = optname;
  26.         do {
  27.             if (cp < &optname[ONMSZ - 2])
  28.                 *cp++ = getchar();
  29.         } while (isalpha(peekchar()));
  30.         *cp = 0;
  31.         cp = optname;
  32.         if (eq("all", cp)) {
  33.             if (inopen)
  34.                 pofix();
  35.             prall();
  36.             goto next;
  37.         }
  38.         no = 0;
  39.         if (cp[0] == 'n' && cp[1] == 'o') {
  40.             cp += 2;
  41.             no++;
  42.         }
  43.         for (op = options; op < &options[NOPTS]; op++)
  44.             if (eq(op->oname, cp) || op->oabbrev && eq(op->oabbrev, cp))
  45.                 break;
  46.         if (op->oname == 0)
  47.             serror("%s: No such option@- 'set all' gives all option values", cp);
  48.         c = skipwh();
  49.         if (peekchar() == '?') {
  50.             ignchar();
  51. printone:
  52.             propt(op);
  53.             noonl();
  54.             goto next;
  55.         }
  56.         if (op->otype == ONOFF) {
  57.             op->ovalue = 1 - no;
  58.             goto next;
  59.         }
  60.         if (no)
  61.             serror("Option %s is not a toggle", op->oname);
  62.         if (c != 0 || setend())
  63.             goto printone;
  64.         if (getchar() != '=')
  65.             serror("Missing =@in assignment to option %s", op->oname);
  66.         switch (op->otype) {
  67.  
  68.         case NUMERIC:
  69.             if (!isdigit(peekchar()))
  70.                 error("Digits required@after = when assigning numeric option");
  71.             op->ovalue = getnum();
  72.             if (value(TABSTOP) <= 0)
  73.                 value(TABSTOP) = TABS;
  74.             break;
  75.  
  76.         case STRING:
  77.         case OTERM:
  78.             cp = optname;
  79.             while (!setend()) {
  80.                 if (cp >= &optname[ONMSZ])
  81.                     error("String too long@in option assignment");
  82.                 *cp++ = getchar();
  83.             }
  84.             *cp = 0;
  85.             if (op->otype == OTERM) {
  86.                 if (inopen)
  87.                     error("Can't change type of terminal from within open/visual");
  88.                 setterm(optname);
  89.             } else {
  90.                 CP(op->osvalue, optname);
  91.                 op->odefault = 1;
  92.             }
  93.             break;
  94.         }
  95. next:
  96.         flush();
  97.     } while (!skipend());
  98.     eol();
  99. }
  100.  
  101. setend()
  102. {
  103.  
  104.     return (iswhite(peekchar()) || endcmd(peekchar()));
  105. }
  106.  
  107. prall()
  108. {
  109.     register int incr = (NOPTS + 2) / 3;
  110.     register int rows = incr;
  111.     register struct option *op = options;
  112.  
  113.     for (; rows; rows--, op++) {
  114.         propt(op);
  115.         tab(24);
  116.         propt(&op[incr]);
  117.         if (&op[2*incr] < &options[NOPTS]) {
  118.             tab(48);
  119.             propt(&op[2 * incr]);
  120.         }
  121.         putNFL();
  122.     }
  123. }
  124.  
  125. propts()
  126. {
  127.     register struct option *op;
  128.  
  129.     for (op = options; op < &options[NOPTS]; op++) {
  130. #ifdef V6
  131.         if (op == &options[TERM])
  132. #else
  133.         if (op == &options[TTYTYPE])
  134. #endif
  135.             continue;
  136.         switch (op->otype) {
  137.  
  138.         case ONOFF:
  139.         case NUMERIC:
  140.             if (op->ovalue == op->odefault)
  141.                 continue;
  142.             break;
  143.  
  144.         case STRING:
  145.             if (op->odefault == 0)
  146.                 continue;
  147.             break;
  148.         }
  149.         propt(op);
  150.         putchar(' ');
  151.     }
  152.     noonl();
  153.     flush();
  154. }
  155.  
  156. propt(op)
  157.     register struct option *op;
  158. {
  159.     register char *name;
  160.     
  161.     name = op->oname;
  162.  
  163.     switch (op->otype) {
  164.  
  165.     case ONOFF:
  166.         printf("%s%s", op->ovalue ? "" : "no", name);
  167.         break;
  168.  
  169.     case NUMERIC:
  170.         printf("%s=%d", name, op->ovalue);
  171.         break;
  172.  
  173.     case STRING:
  174.     case OTERM:
  175.         printf("%s=%s", name, op->osvalue);
  176.         break;
  177.     }
  178. }
  179.