|
|
1.1 root 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: /* adb change: allow whitepace in strings */
83: if( (*cp = getchar()) == '\\')
84: if( peekchar() != EOF)
85: *cp = getchar();
86: cp++;
87: }
88: *cp = 0;
89: if (op->otype == OTERM) {
90: /*
91: * At first glance it seems like we shouldn't care if the terminal type
92: * is changed inside visual mode, as long as we assume the screen is
93: * a mess and redraw it. However, it's a much harder problem than that.
94: * If you happen to change from 1 crt to another that both have the same
95: * size screen, it's OK. But if the screen size if different, the stuff
96: * that gets initialized in vop() will be wrong. This could be overcome
97: * by redoing the initialization, e.g. making the first 90% of vop into
98: * a subroutine. However, the most useful case is where you forgot to do
99: * a setenv before you went into the editor and it thinks you're on a dumb
100: * terminal. Ex treats this like hardcopy and goes into HARDOPEN mode.
101: * This loses because the first part of vop calls oop in this case.
102: * The problem is so hard I gave up. I'm not saying it can't be done,
103: * but I am saying it probably isn't worth the effort.
104: */
105: if (inopen)
106: error("Can't change type of terminal from within open/visual");
107: setterm(optname);
108: } else {
109: CP(op->osvalue, optname);
110: op->odefault = 1;
111: }
112: break;
113: }
114: next:
115: flush();
116: } while (!skipend());
117: eol();
118: }
119:
120: setend()
121: {
122:
123: return (iswhite(peekchar()) || endcmd(peekchar()));
124: }
125:
126: prall()
127: {
128: register int incr = (NOPTS + 2) / 3;
129: register int rows = incr;
130: register struct option *op = options;
131:
132: for (; rows; rows--, op++) {
133: propt(op);
134: tab(24);
135: propt(&op[incr]);
136: if (&op[2*incr] < &options[NOPTS]) {
137: tab(56);
138: propt(&op[2 * incr]);
139: }
140: putNFL();
141: }
142: }
143:
144: propts()
145: {
146: register struct option *op;
147:
148: for (op = options; op < &options[NOPTS]; op++) {
149: #ifdef V6
150: if (op == &options[TERM])
151: #else
152: if (op == &options[TTYTYPE])
153: #endif
154: continue;
155: switch (op->otype) {
156:
157: case ONOFF:
158: case NUMERIC:
159: if (op->ovalue == op->odefault)
160: continue;
161: break;
162:
163: case STRING:
164: if (op->odefault == 0)
165: continue;
166: break;
167: }
168: propt(op);
169: putchar(' ');
170: }
171: noonl();
172: flush();
173: }
174:
175: propt(op)
176: register struct option *op;
177: {
178: register char *name;
179:
180: name = op->oname;
181:
182: switch (op->otype) {
183:
184: case ONOFF:
185: printf("%s%s", op->ovalue ? "" : "no", name);
186: break;
187:
188: case NUMERIC:
189: printf("%s=%d", name, op->ovalue);
190: break;
191:
192: case STRING:
193: case OTERM:
194: printf("%s=%s", name, op->osvalue);
195: break;
196: }
197: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.