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:     extern short ospeed;
  17: 
  18:     setnoaddr();
  19:     if (skipend()) {
  20:         if (peekchar() != EOF)
  21:             ignchar();
  22:         propts();
  23:         return;
  24:     }
  25:     do {
  26:         cp = optname;
  27:         do {
  28:             if (cp < &optname[ONMSZ - 2])
  29:                 *cp++ = getchar();
  30:         } while (isalnum(peekchar()));
  31:         *cp = 0;
  32:         cp = optname;
  33:         if (eq("all", cp)) {
  34:             if (inopen)
  35:                 pofix();
  36:             prall();
  37:             goto next;
  38:         }
  39:         no = 0;
  40:         if (cp[0] == 'n' && cp[1] == 'o') {
  41:             cp += 2;
  42:             no++;
  43:         }
  44:         /* Implement w300, w1200, and w9600 specially */
  45:         if (eq(cp, "w300")) {
  46:             if (ospeed >= B1200) {
  47: dontset:
  48:                 ignore(getchar());  /* = */
  49:                 ignore(getnum());   /* value */
  50:                 continue;
  51:             }
  52:             cp = "window";
  53:         } else if (eq(cp, "w1200")) {
  54:             if (ospeed < B1200 || ospeed >= B2400)
  55:                 goto dontset;
  56:             cp = "window";
  57:         } else if (eq(cp, "w9600")) {
  58:             if (ospeed < B2400)
  59:                 goto dontset;
  60:             cp = "window";
  61:         }
  62:         for (op = options; op < &options[NOPTS]; op++)
  63:             if (eq(op->oname, cp) || op->oabbrev && eq(op->oabbrev, cp))
  64:                 break;
  65:         if (op->oname == 0)
  66:             serror("%s: No such option@- 'set all' gives all option values", cp);
  67:         c = skipwh();
  68:         if (peekchar() == '?') {
  69:             ignchar();
  70: printone:
  71:             propt(op);
  72:             noonl();
  73:             goto next;
  74:         }
  75:         if (op->otype == ONOFF) {
  76:             op->ovalue = 1 - no;
  77:             if (op == &options[PROMPT])
  78:                 oprompt = 1 - no;
  79:             goto next;
  80:         }
  81:         if (no)
  82:             serror("Option %s is not a toggle", op->oname);
  83:         if (c != 0 || setend())
  84:             goto printone;
  85:         if (getchar() != '=')
  86:             serror("Missing =@in assignment to option %s", op->oname);
  87:         switch (op->otype) {
  88: 
  89:         case NUMERIC:
  90:             if (!isdigit(peekchar()))
  91:                 error("Digits required@after =");
  92:             op->ovalue = getnum();
  93:             if (value(TABSTOP) <= 0)
  94:                 value(TABSTOP) = TABS;
  95:             break;
  96: 
  97:         case STRING:
  98:         case OTERM:
  99:             cp = optname;
 100:             while (!setend()) {
 101:                 if (cp >= &optname[ONMSZ])
 102:                     error("String too long@in option assignment");
 103:                 /* adb change:  allow whitepace in strings */
 104:                 if( (*cp = getchar()) == '\\')
 105:                     if( peekchar() != EOF)
 106:                         *cp = getchar();
 107:                 cp++;
 108:             }
 109:             *cp = 0;
 110:             if (op->otype == OTERM) {
 111: /*
 112:  * At first glance it seems like we shouldn't care if the terminal type
 113:  * is changed inside visual mode, as long as we assume the screen is
 114:  * a mess and redraw it. However, it's a much harder problem than that.
 115:  * If you happen to change from 1 crt to another that both have the same
 116:  * size screen, it's OK. But if the screen size if different, the stuff
 117:  * that gets initialized in vop() will be wrong. This could be overcome
 118:  * by redoing the initialization, e.g. making the first 90% of vop into
 119:  * a subroutine. However, the most useful case is where you forgot to do
 120:  * a setenv before you went into the editor and it thinks you're on a dumb
 121:  * terminal. Ex treats this like hardcopy and goes into HARDOPEN mode.
 122:  * This loses because the first part of vop calls oop in this case.
 123:  * The problem is so hard I gave up. I'm not saying it can't be done,
 124:  * but I am saying it probably isn't worth the effort.
 125:  */
 126:                 if (inopen)
 127: error("Can't change type of terminal from within open/visual");
 128:                 setterm(optname);
 129:             } else {
 130:                 CP(op->osvalue, optname);
 131:                 op->odefault = 1;
 132:             }
 133:             break;
 134:         }
 135: next:
 136:         flush();
 137:     } while (!skipend());
 138:     eol();
 139: }
 140: 
 141: setend()
 142: {
 143: 
 144:     return (iswhite(peekchar()) || endcmd(peekchar()));
 145: }
 146: 
 147: prall()
 148: {
 149:     register int incr = (NOPTS + 2) / 3;
 150:     register int rows = incr;
 151:     register struct option *op = options;
 152: 
 153:     for (; rows; rows--, op++) {
 154:         propt(op);
 155:         tab(24);
 156:         propt(&op[incr]);
 157:         if (&op[2*incr] < &options[NOPTS]) {
 158:             tab(56);
 159:             propt(&op[2 * incr]);
 160:         }
 161:         putNFL();
 162:     }
 163: }
 164: 
 165: propts()
 166: {
 167:     register struct option *op;
 168: 
 169:     for (op = options; op < &options[NOPTS]; op++) {
 170: #ifdef V6
 171:         if (op == &options[TERM])
 172: #else
 173:         if (op == &options[TTYTYPE])
 174: #endif
 175:             continue;
 176:         switch (op->otype) {
 177: 
 178:         case ONOFF:
 179:         case NUMERIC:
 180:             if (op->ovalue == op->odefault)
 181:                 continue;
 182:             break;
 183: 
 184:         case STRING:
 185:             if (op->odefault == 0)
 186:                 continue;
 187:             break;
 188:         }
 189:         propt(op);
 190:         putchar(' ');
 191:     }
 192:     noonl();
 193:     flush();
 194: }
 195: 
 196: propt(op)
 197:     register struct option *op;
 198: {
 199:     register char *name;
 200: 
 201:     name = op->oname;
 202: 
 203:     switch (op->otype) {
 204: 
 205:     case ONOFF:
 206:         printf("%s%s", op->ovalue ? "" : "no", name);
 207:         break;
 208: 
 209:     case NUMERIC:
 210:         printf("%s=%d", name, op->ovalue);
 211:         break;
 212: 
 213:     case STRING:
 214:     case OTERM:
 215:         printf("%s=%s", name, op->osvalue);
 216:         break;
 217:     }
 218: }

Defined functions

prall defined in line 147; used 1 times
  • in line 36
propt defined in line 196; used 5 times
propts defined in line 165; used 1 times
  • in line 22
set defined in line 10; used 1 times
setend defined in line 141; used 2 times

Defined variables

optname defined in line 8; used 7 times
Last modified: 1980-09-13
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 853
Valid CSS Valid XHTML 1.0 Strict