GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.bin/vi/build/../common/options_f.c Lines: 0 78 0.0 %
Date: 2017-11-13 Branches: 0 62 0.0 %

Line Branch Exec Source
1
/*	$OpenBSD: options_f.c,v 1.12 2017/07/03 07:01:14 bentley Exp $	*/
2
3
/*-
4
 * Copyright (c) 1993, 1994
5
 *	The Regents of the University of California.  All rights reserved.
6
 * Copyright (c) 1993, 1994, 1995, 1996
7
 *	Keith Bostic.  All rights reserved.
8
 *
9
 * See the LICENSE file for redistribution information.
10
 */
11
12
#include "config.h"
13
14
#include <sys/types.h>
15
#include <sys/queue.h>
16
#include <sys/stat.h>
17
18
#include <bitstring.h>
19
#include <ctype.h>
20
#include <errno.h>
21
#include <limits.h>
22
#include <stdio.h>
23
#include <stdlib.h>
24
#include <string.h>
25
#include <unistd.h>
26
27
#include "common.h"
28
29
/*
30
 * PUBLIC: int f_altwerase(SCR *, OPTION *, char *, u_long *);
31
 */
32
int
33
f_altwerase(SCR *sp, OPTION *op, char *str, u_long *valp)
34
{
35
	if (!*valp)
36
		O_CLR(sp, O_TTYWERASE);
37
	return (0);
38
}
39
40
/*
41
 * PUBLIC: int f_columns(SCR *, OPTION *, char *, u_long *);
42
 */
43
int
44
f_columns(SCR *sp, OPTION *op, char *str, u_long *valp)
45
{
46
	/* Validate the number. */
47
	if (*valp < MINIMUM_SCREEN_COLS) {
48
		msgq(sp, M_ERR, "Screen columns too small, less than %d",
49
		    MINIMUM_SCREEN_COLS);
50
		return (1);
51
	}
52
53
	/*
54
	 * !!!
55
	 * It's not uncommon for allocation of huge chunks of memory to cause
56
	 * core dumps on various systems.  So, we prune out numbers that are
57
	 * "obviously" wrong.  Vi will not work correctly if it has the wrong
58
	 * number of lines/columns for the screen, but at least we don't drop
59
	 * core.
60
	 */
61
#define	MAXIMUM_SCREEN_COLS	768
62
	if (*valp > MAXIMUM_SCREEN_COLS) {
63
		msgq(sp, M_ERR, "Screen columns too large, greater than %d",
64
		    MAXIMUM_SCREEN_COLS);
65
		return (1);
66
	}
67
	return (0);
68
}
69
70
/*
71
 * PUBLIC: int f_lines(SCR *, OPTION *, char *, u_long *);
72
 */
73
int
74
f_lines(SCR *sp, OPTION *op, char *str, u_long *valp)
75
{
76
	/* Validate the number. */
77
	if (*valp < MINIMUM_SCREEN_ROWS) {
78
		msgq(sp, M_ERR, "Screen lines too small, less than %d",
79
		    MINIMUM_SCREEN_ROWS);
80
		return (1);
81
	}
82
83
	/*
84
	 * !!!
85
	 * It's not uncommon for allocation of huge chunks of memory to cause
86
	 * core dumps on various systems.  So, we prune out numbers that are
87
	 * "obviously" wrong.  Vi will not work correctly if it has the wrong
88
	 * number of lines/columns for the screen, but at least we don't drop
89
	 * core.
90
	 */
91
#define	MAXIMUM_SCREEN_ROWS	500
92
	if (*valp > MAXIMUM_SCREEN_ROWS) {
93
		msgq(sp, M_ERR, "Screen lines too large, greater than %d",
94
		    MAXIMUM_SCREEN_ROWS);
95
		return (1);
96
	}
97
98
	/*
99
	 * Set the value, and the related scroll value.  If no window
100
	 * value set, set a new default window.
101
	 */
102
	o_set(sp, O_LINES, 0, NULL, *valp);
103
	if (*valp == 1) {
104
		sp->defscroll = 1;
105
106
		if (O_VAL(sp, O_WINDOW) == O_D_VAL(sp, O_WINDOW) ||
107
		    O_VAL(sp, O_WINDOW) > *valp) {
108
			o_set(sp, O_WINDOW, 0, NULL, 1);
109
			o_set(sp, O_WINDOW, OS_DEF, NULL, 1);
110
		}
111
	} else {
112
		sp->defscroll = (*valp - 1) / 2;
113
114
		if (O_VAL(sp, O_WINDOW) == O_D_VAL(sp, O_WINDOW) ||
115
		    O_VAL(sp, O_WINDOW) > *valp) {
116
			o_set(sp, O_WINDOW, 0, NULL, *valp - 1);
117
			o_set(sp, O_WINDOW, OS_DEF, NULL, *valp - 1);
118
		}
119
	}
120
	return (0);
121
}
122
123
/*
124
 * PUBLIC: int f_paragraph(SCR *, OPTION *, char *, u_long *);
125
 */
126
int
127
f_paragraph(SCR *sp, OPTION *op, char *str, u_long *valp)
128
{
129
	if (strlen(str) & 1) {
130
		msgq(sp, M_ERR,
131
		    "The paragraph option must be in two character groups");
132
		return (1);
133
	}
134
	return (0);
135
}
136
137
/*
138
 * PUBLIC: int f_print(SCR *, OPTION *, char *, u_long *);
139
 */
140
int
141
f_print(SCR *sp, OPTION *op, char *str, u_long *valp)
142
{
143
	/* Reinitialize the key fast lookup table. */
144
	v_key_ilookup(sp);
145
146
	/* Reformat the screen. */
147
	F_SET(sp, SC_SCR_REFORMAT);
148
	return (0);
149
}
150
151
/*
152
 * PUBLIC: int f_readonly(SCR *, OPTION *, char *, u_long *);
153
 */
154
int
155
f_readonly(SCR *sp, OPTION *op, char *str, u_long *valp)
156
{
157
	/*
158
	 * !!!
159
	 * See the comment in exf.c.
160
	 */
161
	if (*valp)
162
		F_CLR(sp, SC_READONLY);
163
	else
164
		F_SET(sp, SC_READONLY);
165
	return (0);
166
}
167
168
/*
169
 * PUBLIC: int f_recompile(SCR *, OPTION *, char *, u_long *);
170
 */
171
int
172
f_recompile(SCR *sp, OPTION *op, char *str, u_long *valp)
173
{
174
	if (F_ISSET(sp, SC_RE_SEARCH)) {
175
		regfree(&sp->re_c);
176
		F_CLR(sp, SC_RE_SEARCH);
177
	}
178
	if (F_ISSET(sp, SC_RE_SUBST)) {
179
		regfree(&sp->subre_c);
180
		F_CLR(sp, SC_RE_SUBST);
181
	}
182
	return (0);
183
}
184
185
/*
186
 * PUBLIC: int f_reformat(SCR *, OPTION *, char *, u_long *);
187
 */
188
int
189
f_reformat(SCR *sp, OPTION *op, char *str, u_long *valp)
190
{
191
	F_SET(sp, SC_SCR_REFORMAT);
192
	return (0);
193
}
194
195
/*
196
 * PUBLIC: int f_section(SCR *, OPTION *, char *, u_long *);
197
 */
198
int
199
f_section(SCR *sp, OPTION *op, char *str, u_long *valp)
200
{
201
	if (strlen(str) & 1) {
202
		msgq(sp, M_ERR,
203
		    "The section option must be in two character groups");
204
		return (1);
205
	}
206
	return (0);
207
}
208
209
/*
210
 * PUBLIC: int f_ttywerase(SCR *, OPTION *, char *, u_long *);
211
 */
212
int
213
f_ttywerase(SCR *sp, OPTION *op, char *str, u_long *valp)
214
{
215
	if (!*valp)
216
		O_CLR(sp, O_ALTWERASE);
217
	return (0);
218
}
219
220
/*
221
 * PUBLIC: int f_w300(SCR *, OPTION *, char *, u_long *);
222
 */
223
int
224
f_w300(SCR *sp, OPTION *op, char *str, u_long *valp)
225
{
226
	u_long v;
227
228
	/* Historical behavior for w300 was < 1200. */
229
	if (sp->gp->scr_baud(sp, &v))
230
		return (1);
231
	if (v >= 1200)
232
		return (0);
233
234
	return (f_window(sp, op, str, valp));
235
}
236
237
/*
238
 * PUBLIC: int f_w1200(SCR *, OPTION *, char *, u_long *);
239
 */
240
int
241
f_w1200(SCR *sp, OPTION *op, char *str, u_long *valp)
242
{
243
	u_long v;
244
245
	/* Historical behavior for w1200 was == 1200. */
246
	if (sp->gp->scr_baud(sp, &v))
247
		return (1);
248
	if (v < 1200 || v > 4800)
249
		return (0);
250
251
	return (f_window(sp, op, str, valp));
252
}
253
254
/*
255
 * PUBLIC: int f_w9600(SCR *, OPTION *, char *, u_long *);
256
 */
257
int
258
f_w9600(SCR *sp, OPTION *op, char *str, u_long *valp)
259
{
260
	u_long v;
261
262
	/* Historical behavior for w9600 was > 1200. */
263
	if (sp->gp->scr_baud(sp, &v))
264
		return (1);
265
	if (v <= 4800)
266
		return (0);
267
268
	return (f_window(sp, op, str, valp));
269
}
270
271
/*
272
 * PUBLIC: int f_window(SCR *, OPTION *, char *, u_long *);
273
 */
274
int
275
f_window(SCR *sp, OPTION *op, char *str, u_long *valp)
276
{
277
	if (*valp >= O_VAL(sp, O_LINES) - 1 &&
278
	    (*valp = O_VAL(sp, O_LINES) - 1) == 0)
279
		*valp = 1;
280
	return (0);
281
}