Subversion Repositories planix.SVN

Rev

Rev 116 | Details | Compare with Previous | Last modification | View Log | RSS feed

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