1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
23*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
24*7c478bd9Sstevel@tonic-gate 
25*7c478bd9Sstevel@tonic-gate 
26*7c478bd9Sstevel@tonic-gate /*
27*7c478bd9Sstevel@tonic-gate  *      Copyright (c) 1997, by Sun Microsystems, Inc.
28*7c478bd9Sstevel@tonic-gate  *      All rights reserved.
29*7c478bd9Sstevel@tonic-gate  */
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
34*7c478bd9Sstevel@tonic-gate #include "utility.h"
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate #define	SizePrev(f, v)	((v) - Buf(f))		/* from beginning to v	*/
37*7c478bd9Sstevel@tonic-gate #define	SizeNext(f, v)	(BufSize(f) - SizePrev(f, v))
38*7c478bd9Sstevel@tonic-gate 					/* from v through end	*/
39*7c478bd9Sstevel@tonic-gate #define	OffscreenRows(c)	((c)->drows - (c)->rows)
40*7c478bd9Sstevel@tonic-gate #define	OffscreenCols(c)	((c)->dcols - (c)->cols)
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate /* _next_char move to next char with wrap to next line at end of line */
43*7c478bd9Sstevel@tonic-gate int
_next_char(FORM * f)44*7c478bd9Sstevel@tonic-gate _next_char(FORM *f)
45*7c478bd9Sstevel@tonic-gate {
46*7c478bd9Sstevel@tonic-gate 	if (++X(f) == Xmax(f)) {
47*7c478bd9Sstevel@tonic-gate 		if (++Y(f) == Ymax(f)) {
48*7c478bd9Sstevel@tonic-gate 			--X(f);
49*7c478bd9Sstevel@tonic-gate 			--Y(f);
50*7c478bd9Sstevel@tonic-gate 			return (E_REQUEST_DENIED);	/* at last char */
51*7c478bd9Sstevel@tonic-gate 		}
52*7c478bd9Sstevel@tonic-gate 		X(f) = 0;
53*7c478bd9Sstevel@tonic-gate 	}
54*7c478bd9Sstevel@tonic-gate 	return (E_OK);
55*7c478bd9Sstevel@tonic-gate }
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate /*
58*7c478bd9Sstevel@tonic-gate  * _prev_char - move to previous char with
59*7c478bd9Sstevel@tonic-gate  * wrap to previous line at beginning of line
60*7c478bd9Sstevel@tonic-gate  */
61*7c478bd9Sstevel@tonic-gate int
_prev_char(FORM * f)62*7c478bd9Sstevel@tonic-gate _prev_char(FORM *f)
63*7c478bd9Sstevel@tonic-gate {
64*7c478bd9Sstevel@tonic-gate 	if (--X(f) < 0) {
65*7c478bd9Sstevel@tonic-gate 		if (--Y(f) < 0) {
66*7c478bd9Sstevel@tonic-gate 			++X(f);
67*7c478bd9Sstevel@tonic-gate 			++Y(f);
68*7c478bd9Sstevel@tonic-gate 			return (E_REQUEST_DENIED);	/* at first char */
69*7c478bd9Sstevel@tonic-gate 		}
70*7c478bd9Sstevel@tonic-gate 		X(f) = Xmax(f) - 1;
71*7c478bd9Sstevel@tonic-gate 	}
72*7c478bd9Sstevel@tonic-gate 	return (E_OK);
73*7c478bd9Sstevel@tonic-gate }
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate /* _next_line - move to beginning of next line */
76*7c478bd9Sstevel@tonic-gate int
_next_line(FORM * f)77*7c478bd9Sstevel@tonic-gate _next_line(FORM *f)
78*7c478bd9Sstevel@tonic-gate {
79*7c478bd9Sstevel@tonic-gate 	if (++Y(f) == Ymax(f)) {
80*7c478bd9Sstevel@tonic-gate 		--Y(f);
81*7c478bd9Sstevel@tonic-gate 		return (E_REQUEST_DENIED);	/* at last line */
82*7c478bd9Sstevel@tonic-gate 	}
83*7c478bd9Sstevel@tonic-gate 	X(f) = 0;
84*7c478bd9Sstevel@tonic-gate 	return (E_OK);
85*7c478bd9Sstevel@tonic-gate }
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate /* _prev_line - move to beginning of previous line */
88*7c478bd9Sstevel@tonic-gate int
_prev_line(FORM * f)89*7c478bd9Sstevel@tonic-gate _prev_line(FORM *f)
90*7c478bd9Sstevel@tonic-gate {
91*7c478bd9Sstevel@tonic-gate 	if (--Y(f) < 0) {
92*7c478bd9Sstevel@tonic-gate 		++Y(f);
93*7c478bd9Sstevel@tonic-gate 		return (E_REQUEST_DENIED);	/* at first line */
94*7c478bd9Sstevel@tonic-gate 	}
95*7c478bd9Sstevel@tonic-gate 	X(f) = 0;
96*7c478bd9Sstevel@tonic-gate 	return (E_OK);
97*7c478bd9Sstevel@tonic-gate }
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate /* _next_word - move to beginning of next word */
100*7c478bd9Sstevel@tonic-gate int
_next_word(FORM * f)101*7c478bd9Sstevel@tonic-gate _next_word(FORM *f)
102*7c478bd9Sstevel@tonic-gate {
103*7c478bd9Sstevel@tonic-gate 	FIELD *		c = C(f);
104*7c478bd9Sstevel@tonic-gate 	char *		v = LineBuf(c, Y(f)) + X(f);	/* position in buffer */
105*7c478bd9Sstevel@tonic-gate 	char *		t;
106*7c478bd9Sstevel@tonic-gate 
107*7c478bd9Sstevel@tonic-gate 	_sync_buffer(f);
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate 	t = _whsp_beg(v, (int) SizeNext(c, v));
110*7c478bd9Sstevel@tonic-gate 	v = _data_beg(t, (int) SizeNext(c, t));
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate 	if (v == t)
113*7c478bd9Sstevel@tonic-gate 		return (E_REQUEST_DENIED);	/* at last word */
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate 	if (OneRow(c) && c->dcols != c->cols) {
116*7c478bd9Sstevel@tonic-gate 	/* one row and field has grown */
117*7c478bd9Sstevel@tonic-gate 		t = v;
118*7c478bd9Sstevel@tonic-gate 
119*7c478bd9Sstevel@tonic-gate 		while (*t != ' ' && *t != '\0')  /* find end of word + 1 */
120*7c478bd9Sstevel@tonic-gate 			t++;
121*7c478bd9Sstevel@tonic-gate 
122*7c478bd9Sstevel@tonic-gate 		if (t - (Buf(c) + B(f)) > c->cols) {
123*7c478bd9Sstevel@tonic-gate 			if (t - v > c->cols) {
124*7c478bd9Sstevel@tonic-gate 			/* word longer than visible field */
125*7c478bd9Sstevel@tonic-gate 				B(f) = (int) (v - Buf(c));
126*7c478bd9Sstevel@tonic-gate 			} else {
127*7c478bd9Sstevel@tonic-gate 				B(f) = (int) (t - (Buf(c) + c->cols));
128*7c478bd9Sstevel@tonic-gate 			}
129*7c478bd9Sstevel@tonic-gate 
130*7c478bd9Sstevel@tonic-gate 			X(f) = (int) (v - Buf(c));
131*7c478bd9Sstevel@tonic-gate 			return (E_OK);
132*7c478bd9Sstevel@tonic-gate 		}
133*7c478bd9Sstevel@tonic-gate 	}
134*7c478bd9Sstevel@tonic-gate 
135*7c478bd9Sstevel@tonic-gate 	_adjust_cursor(f, v);
136*7c478bd9Sstevel@tonic-gate 	return (E_OK);
137*7c478bd9Sstevel@tonic-gate }
138*7c478bd9Sstevel@tonic-gate 
139*7c478bd9Sstevel@tonic-gate /* _prev_word - move to beginning of previous word */
140*7c478bd9Sstevel@tonic-gate int
_prev_word(FORM * f)141*7c478bd9Sstevel@tonic-gate _prev_word(FORM *f)
142*7c478bd9Sstevel@tonic-gate {
143*7c478bd9Sstevel@tonic-gate 	FIELD *		c = C(f);
144*7c478bd9Sstevel@tonic-gate 	char *		v = LineBuf(c, Y(f)) + X(f);	/* position in buffer */
145*7c478bd9Sstevel@tonic-gate 	char *		t;
146*7c478bd9Sstevel@tonic-gate 
147*7c478bd9Sstevel@tonic-gate 	_sync_buffer(f);
148*7c478bd9Sstevel@tonic-gate 
149*7c478bd9Sstevel@tonic-gate 	t = _data_end(Buf(c), (int) SizePrev(c, v));
150*7c478bd9Sstevel@tonic-gate 	v = _whsp_end(Buf(c), (int) SizePrev(c, t));
151*7c478bd9Sstevel@tonic-gate 
152*7c478bd9Sstevel@tonic-gate 	if (v == t)
153*7c478bd9Sstevel@tonic-gate 		return (E_REQUEST_DENIED);	/* at first word */
154*7c478bd9Sstevel@tonic-gate 
155*7c478bd9Sstevel@tonic-gate 	_adjust_cursor(f, v);
156*7c478bd9Sstevel@tonic-gate 	return (E_OK);
157*7c478bd9Sstevel@tonic-gate }
158*7c478bd9Sstevel@tonic-gate 
159*7c478bd9Sstevel@tonic-gate /* _beg_field - move to first non-pad char in field */
160*7c478bd9Sstevel@tonic-gate int
_beg_field(FORM * f)161*7c478bd9Sstevel@tonic-gate _beg_field(FORM *f)
162*7c478bd9Sstevel@tonic-gate {
163*7c478bd9Sstevel@tonic-gate 	FIELD *	c = C(f);
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate 	_sync_buffer(f);
166*7c478bd9Sstevel@tonic-gate 	_adjust_cursor(f, _data_beg(Buf(c), BufSize(c)));
167*7c478bd9Sstevel@tonic-gate 	return (E_OK);
168*7c478bd9Sstevel@tonic-gate }
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate /* _end_field - move after last non-pad char in field */
171*7c478bd9Sstevel@tonic-gate int
_end_field(FORM * f)172*7c478bd9Sstevel@tonic-gate _end_field(FORM *f)
173*7c478bd9Sstevel@tonic-gate {
174*7c478bd9Sstevel@tonic-gate 	FIELD *	c = C(f);
175*7c478bd9Sstevel@tonic-gate 	char *	end;
176*7c478bd9Sstevel@tonic-gate 
177*7c478bd9Sstevel@tonic-gate 	_sync_buffer(f);
178*7c478bd9Sstevel@tonic-gate 	end = _data_end(Buf(c), BufSize(c));
179*7c478bd9Sstevel@tonic-gate 
180*7c478bd9Sstevel@tonic-gate 	if (end == Buf(c) + BufSize(c))
181*7c478bd9Sstevel@tonic-gate 		end--;
182*7c478bd9Sstevel@tonic-gate 
183*7c478bd9Sstevel@tonic-gate 	_adjust_cursor(f, end);
184*7c478bd9Sstevel@tonic-gate 	return (E_OK);
185*7c478bd9Sstevel@tonic-gate }
186*7c478bd9Sstevel@tonic-gate 
187*7c478bd9Sstevel@tonic-gate /* _beg_line - move to first non-pad char on current line */
188*7c478bd9Sstevel@tonic-gate int
_beg_line(FORM * f)189*7c478bd9Sstevel@tonic-gate _beg_line(FORM *f)
190*7c478bd9Sstevel@tonic-gate {
191*7c478bd9Sstevel@tonic-gate 	FIELD *c = C(f);
192*7c478bd9Sstevel@tonic-gate 
193*7c478bd9Sstevel@tonic-gate 	_sync_buffer(f);
194*7c478bd9Sstevel@tonic-gate 	_adjust_cursor(f, _data_beg(LineBuf(c, Y(f)), Xmax(f)));
195*7c478bd9Sstevel@tonic-gate 	return (E_OK);
196*7c478bd9Sstevel@tonic-gate }
197*7c478bd9Sstevel@tonic-gate 
198*7c478bd9Sstevel@tonic-gate /* _end_line - move after last non-pad char on current line */
199*7c478bd9Sstevel@tonic-gate int
_end_line(FORM * f)200*7c478bd9Sstevel@tonic-gate _end_line(FORM *f)
201*7c478bd9Sstevel@tonic-gate {
202*7c478bd9Sstevel@tonic-gate 	FIELD	*c = C(f);
203*7c478bd9Sstevel@tonic-gate 	char	*end;
204*7c478bd9Sstevel@tonic-gate 
205*7c478bd9Sstevel@tonic-gate 	_sync_buffer(f);
206*7c478bd9Sstevel@tonic-gate 	end = _data_end(LineBuf(c, Y(f)), Xmax(f));
207*7c478bd9Sstevel@tonic-gate 
208*7c478bd9Sstevel@tonic-gate 	if (end == LineBuf(c, Y(f)) + Xmax(f))
209*7c478bd9Sstevel@tonic-gate 		end--;
210*7c478bd9Sstevel@tonic-gate 
211*7c478bd9Sstevel@tonic-gate 	_adjust_cursor(f, end);
212*7c478bd9Sstevel@tonic-gate 	return (E_OK);
213*7c478bd9Sstevel@tonic-gate }
214*7c478bd9Sstevel@tonic-gate 
215*7c478bd9Sstevel@tonic-gate /* _left_char - move left */
216*7c478bd9Sstevel@tonic-gate int
_left_char(FORM * f)217*7c478bd9Sstevel@tonic-gate _left_char(FORM *f)
218*7c478bd9Sstevel@tonic-gate {
219*7c478bd9Sstevel@tonic-gate 	if (--X(f) < 0) {
220*7c478bd9Sstevel@tonic-gate 		++X(f);
221*7c478bd9Sstevel@tonic-gate 		return (E_REQUEST_DENIED);	/* at left side */
222*7c478bd9Sstevel@tonic-gate 	}
223*7c478bd9Sstevel@tonic-gate 	return (E_OK);
224*7c478bd9Sstevel@tonic-gate }
225*7c478bd9Sstevel@tonic-gate 
226*7c478bd9Sstevel@tonic-gate /* _right_char - move right */
227*7c478bd9Sstevel@tonic-gate int
_right_char(FORM * f)228*7c478bd9Sstevel@tonic-gate _right_char(FORM *f)
229*7c478bd9Sstevel@tonic-gate {
230*7c478bd9Sstevel@tonic-gate 	if (++X(f) == Xmax(f)) {
231*7c478bd9Sstevel@tonic-gate 		--X(f);
232*7c478bd9Sstevel@tonic-gate 		return (E_REQUEST_DENIED);	/* at right side */
233*7c478bd9Sstevel@tonic-gate 	}
234*7c478bd9Sstevel@tonic-gate 	return (E_OK);
235*7c478bd9Sstevel@tonic-gate }
236*7c478bd9Sstevel@tonic-gate 
237*7c478bd9Sstevel@tonic-gate /* _up_char - move up */
238*7c478bd9Sstevel@tonic-gate int
_up_char(FORM * f)239*7c478bd9Sstevel@tonic-gate _up_char(FORM *f)
240*7c478bd9Sstevel@tonic-gate {
241*7c478bd9Sstevel@tonic-gate 	if (--Y(f) < 0) {
242*7c478bd9Sstevel@tonic-gate 		++Y(f);
243*7c478bd9Sstevel@tonic-gate 		return (E_REQUEST_DENIED);	/* at top */
244*7c478bd9Sstevel@tonic-gate 	}
245*7c478bd9Sstevel@tonic-gate 	return (E_OK);
246*7c478bd9Sstevel@tonic-gate }
247*7c478bd9Sstevel@tonic-gate 
248*7c478bd9Sstevel@tonic-gate /* _down_char - move down */
249*7c478bd9Sstevel@tonic-gate int
_down_char(FORM * f)250*7c478bd9Sstevel@tonic-gate _down_char(FORM *f)
251*7c478bd9Sstevel@tonic-gate {
252*7c478bd9Sstevel@tonic-gate 	if (++Y(f) == Ymax(f)) {
253*7c478bd9Sstevel@tonic-gate 		--Y(f);
254*7c478bd9Sstevel@tonic-gate 		return (E_REQUEST_DENIED);	/* at bottom */
255*7c478bd9Sstevel@tonic-gate 	}
256*7c478bd9Sstevel@tonic-gate 	return (E_OK);
257*7c478bd9Sstevel@tonic-gate }
258*7c478bd9Sstevel@tonic-gate 
259*7c478bd9Sstevel@tonic-gate /* _scr_fline - scroll forward one line */
260*7c478bd9Sstevel@tonic-gate int
_scr_fline(FORM * f)261*7c478bd9Sstevel@tonic-gate _scr_fline(FORM *f)
262*7c478bd9Sstevel@tonic-gate {
263*7c478bd9Sstevel@tonic-gate 	FIELD	*c = C(f);
264*7c478bd9Sstevel@tonic-gate 
265*7c478bd9Sstevel@tonic-gate 	if (++T(f) > OffscreenRows(c)) {
266*7c478bd9Sstevel@tonic-gate 		--T(f);
267*7c478bd9Sstevel@tonic-gate 		return (E_REQUEST_DENIED);	/* at bottom */
268*7c478bd9Sstevel@tonic-gate 	}
269*7c478bd9Sstevel@tonic-gate 	++Y(f);
270*7c478bd9Sstevel@tonic-gate 	Set(c, TOP_CHG);
271*7c478bd9Sstevel@tonic-gate 	return (E_OK);
272*7c478bd9Sstevel@tonic-gate }
273*7c478bd9Sstevel@tonic-gate 
274*7c478bd9Sstevel@tonic-gate /* _scr_bline - scroll backward one line */
275*7c478bd9Sstevel@tonic-gate int
_scr_bline(FORM * f)276*7c478bd9Sstevel@tonic-gate _scr_bline(FORM *f)
277*7c478bd9Sstevel@tonic-gate {
278*7c478bd9Sstevel@tonic-gate 	FIELD	*c = C(f);
279*7c478bd9Sstevel@tonic-gate 
280*7c478bd9Sstevel@tonic-gate 	if (--T(f) < 0) {
281*7c478bd9Sstevel@tonic-gate 		++T(f);
282*7c478bd9Sstevel@tonic-gate 		return (E_REQUEST_DENIED);	/* at top */
283*7c478bd9Sstevel@tonic-gate 	}
284*7c478bd9Sstevel@tonic-gate 	--Y(f);
285*7c478bd9Sstevel@tonic-gate 	Set(c, TOP_CHG);
286*7c478bd9Sstevel@tonic-gate 	return (E_OK);
287*7c478bd9Sstevel@tonic-gate }
288*7c478bd9Sstevel@tonic-gate 
289*7c478bd9Sstevel@tonic-gate /* _scr_fpage - scroll forward one page(C(f) -> rows) */
290*7c478bd9Sstevel@tonic-gate int
_scr_fpage(FORM * f)291*7c478bd9Sstevel@tonic-gate _scr_fpage(FORM *f)
292*7c478bd9Sstevel@tonic-gate {
293*7c478bd9Sstevel@tonic-gate 	FIELD *		c = C(f);
294*7c478bd9Sstevel@tonic-gate 	int		m = OffscreenRows(c) - T(f);
295*7c478bd9Sstevel@tonic-gate 	int		n = c -> rows < m ? c -> rows : m;
296*7c478bd9Sstevel@tonic-gate 
297*7c478bd9Sstevel@tonic-gate 	if (n) {
298*7c478bd9Sstevel@tonic-gate 		Y(f) += n;
299*7c478bd9Sstevel@tonic-gate 		T(f) += n;
300*7c478bd9Sstevel@tonic-gate 		Set(c, TOP_CHG);
301*7c478bd9Sstevel@tonic-gate 		return (E_OK);
302*7c478bd9Sstevel@tonic-gate 	}
303*7c478bd9Sstevel@tonic-gate 	return (E_REQUEST_DENIED);	/* at bottom */
304*7c478bd9Sstevel@tonic-gate }
305*7c478bd9Sstevel@tonic-gate 
306*7c478bd9Sstevel@tonic-gate /* _scr_bpage - scroll backward one page(C(f) -> rows) */
307*7c478bd9Sstevel@tonic-gate int
_scr_bpage(FORM * f)308*7c478bd9Sstevel@tonic-gate _scr_bpage(FORM *f)
309*7c478bd9Sstevel@tonic-gate {
310*7c478bd9Sstevel@tonic-gate 	FIELD *		c = C(f);
311*7c478bd9Sstevel@tonic-gate 	int		m = T(f);
312*7c478bd9Sstevel@tonic-gate 	int		n = c -> rows < m ? c -> rows : m;
313*7c478bd9Sstevel@tonic-gate 
314*7c478bd9Sstevel@tonic-gate 	if (n) {
315*7c478bd9Sstevel@tonic-gate 		Y(f) -= n;
316*7c478bd9Sstevel@tonic-gate 		T(f) -= n;
317*7c478bd9Sstevel@tonic-gate 		Set(c, TOP_CHG);
318*7c478bd9Sstevel@tonic-gate 		return (E_OK);
319*7c478bd9Sstevel@tonic-gate 	}
320*7c478bd9Sstevel@tonic-gate 	return (E_REQUEST_DENIED);	/* at top */
321*7c478bd9Sstevel@tonic-gate }
322*7c478bd9Sstevel@tonic-gate 
323*7c478bd9Sstevel@tonic-gate /* _scr_fhpage - scroll forward one half page(C(f)->rows + 1)/2) */
324*7c478bd9Sstevel@tonic-gate int
_scr_fhpage(FORM * f)325*7c478bd9Sstevel@tonic-gate _scr_fhpage(FORM *f)
326*7c478bd9Sstevel@tonic-gate {
327*7c478bd9Sstevel@tonic-gate 	FIELD *		c = C(f);
328*7c478bd9Sstevel@tonic-gate 	int		m = OffscreenRows(c) - T(f);
329*7c478bd9Sstevel@tonic-gate 	int		h = (c->rows + 1)/2;
330*7c478bd9Sstevel@tonic-gate 	int		n = h < m ? h : m;
331*7c478bd9Sstevel@tonic-gate 
332*7c478bd9Sstevel@tonic-gate 	if (n) {
333*7c478bd9Sstevel@tonic-gate 		Y(f) += n;
334*7c478bd9Sstevel@tonic-gate 		T(f) += n;
335*7c478bd9Sstevel@tonic-gate 		Set(c, TOP_CHG);
336*7c478bd9Sstevel@tonic-gate 		return (E_OK);
337*7c478bd9Sstevel@tonic-gate 	}
338*7c478bd9Sstevel@tonic-gate 	return (E_REQUEST_DENIED);	/* at bottom */
339*7c478bd9Sstevel@tonic-gate }
340*7c478bd9Sstevel@tonic-gate 
341*7c478bd9Sstevel@tonic-gate /* _scr_bhpage - scroll backward one half page(C(f)->rows + 1)/2) */
342*7c478bd9Sstevel@tonic-gate int
_scr_bhpage(FORM * f)343*7c478bd9Sstevel@tonic-gate _scr_bhpage(FORM *f)
344*7c478bd9Sstevel@tonic-gate {
345*7c478bd9Sstevel@tonic-gate 	FIELD *		c = C(f);
346*7c478bd9Sstevel@tonic-gate 	int		m = T(f);
347*7c478bd9Sstevel@tonic-gate 	int		h = (c->rows + 1)/2;
348*7c478bd9Sstevel@tonic-gate 	int		n = h < m ? h : m;
349*7c478bd9Sstevel@tonic-gate 
350*7c478bd9Sstevel@tonic-gate 	if (n) {
351*7c478bd9Sstevel@tonic-gate 		Y(f) -= n;
352*7c478bd9Sstevel@tonic-gate 		T(f) -= n;
353*7c478bd9Sstevel@tonic-gate 		Set(c, TOP_CHG);
354*7c478bd9Sstevel@tonic-gate 		return (E_OK);
355*7c478bd9Sstevel@tonic-gate 	}
356*7c478bd9Sstevel@tonic-gate 	return (E_REQUEST_DENIED);	/* at top */
357*7c478bd9Sstevel@tonic-gate }
358*7c478bd9Sstevel@tonic-gate 
359*7c478bd9Sstevel@tonic-gate /* _scr_fchar - horizontal scroll forward one char */
360*7c478bd9Sstevel@tonic-gate int
_scr_fchar(FORM * f)361*7c478bd9Sstevel@tonic-gate _scr_fchar(FORM *f)
362*7c478bd9Sstevel@tonic-gate {
363*7c478bd9Sstevel@tonic-gate 	FIELD	*c = C(f);
364*7c478bd9Sstevel@tonic-gate 
365*7c478bd9Sstevel@tonic-gate 	if (++B(f) > OffscreenCols(c)) {
366*7c478bd9Sstevel@tonic-gate 		--B(f);
367*7c478bd9Sstevel@tonic-gate 		return (E_REQUEST_DENIED);	/* at end */
368*7c478bd9Sstevel@tonic-gate 	}
369*7c478bd9Sstevel@tonic-gate 	++X(f);
370*7c478bd9Sstevel@tonic-gate 	return (E_OK);
371*7c478bd9Sstevel@tonic-gate }
372*7c478bd9Sstevel@tonic-gate 
373*7c478bd9Sstevel@tonic-gate /* _scr_bchar - horizontal scroll backward one char */
374*7c478bd9Sstevel@tonic-gate int
_scr_bchar(FORM * f)375*7c478bd9Sstevel@tonic-gate _scr_bchar(FORM *f)
376*7c478bd9Sstevel@tonic-gate {
377*7c478bd9Sstevel@tonic-gate 
378*7c478bd9Sstevel@tonic-gate 	if (--B(f) < 0) {
379*7c478bd9Sstevel@tonic-gate 		++B(f);
380*7c478bd9Sstevel@tonic-gate 		return (E_REQUEST_DENIED);	/* at beginning */
381*7c478bd9Sstevel@tonic-gate 	}
382*7c478bd9Sstevel@tonic-gate 	--X(f);
383*7c478bd9Sstevel@tonic-gate 	return (E_OK);
384*7c478bd9Sstevel@tonic-gate }
385*7c478bd9Sstevel@tonic-gate 
386*7c478bd9Sstevel@tonic-gate /* _scr_hfline - horizontal scroll forward one line(C(f)->cols) */
387*7c478bd9Sstevel@tonic-gate int
_scr_hfline(FORM * f)388*7c478bd9Sstevel@tonic-gate _scr_hfline(FORM *f)
389*7c478bd9Sstevel@tonic-gate {
390*7c478bd9Sstevel@tonic-gate 	FIELD	*c = C(f);
391*7c478bd9Sstevel@tonic-gate 	int	m = OffscreenCols(c) - B(f);
392*7c478bd9Sstevel@tonic-gate 	int	n = c -> cols < m ? c -> cols : m;
393*7c478bd9Sstevel@tonic-gate 
394*7c478bd9Sstevel@tonic-gate 	if (n) {
395*7c478bd9Sstevel@tonic-gate 		X(f) += n;
396*7c478bd9Sstevel@tonic-gate 		B(f) += n;
397*7c478bd9Sstevel@tonic-gate 		return (E_OK);
398*7c478bd9Sstevel@tonic-gate 	}
399*7c478bd9Sstevel@tonic-gate 	return (E_REQUEST_DENIED);	/* at end */
400*7c478bd9Sstevel@tonic-gate }
401*7c478bd9Sstevel@tonic-gate 
402*7c478bd9Sstevel@tonic-gate /* _scr_hbline - horizontal scroll backward one line(C(f)->cols) */
403*7c478bd9Sstevel@tonic-gate int
_scr_hbline(FORM * f)404*7c478bd9Sstevel@tonic-gate _scr_hbline(FORM *f)
405*7c478bd9Sstevel@tonic-gate {
406*7c478bd9Sstevel@tonic-gate 	FIELD	*c = C(f);
407*7c478bd9Sstevel@tonic-gate 	int	m = B(f);
408*7c478bd9Sstevel@tonic-gate 	int	n = c -> cols < m ? c -> cols : m;
409*7c478bd9Sstevel@tonic-gate 
410*7c478bd9Sstevel@tonic-gate 	if (n) {
411*7c478bd9Sstevel@tonic-gate 		X(f) -= n;
412*7c478bd9Sstevel@tonic-gate 		B(f) -= n;
413*7c478bd9Sstevel@tonic-gate 		return (E_OK);
414*7c478bd9Sstevel@tonic-gate 	}
415*7c478bd9Sstevel@tonic-gate 	return (E_REQUEST_DENIED);	/* at end */
416*7c478bd9Sstevel@tonic-gate }
417*7c478bd9Sstevel@tonic-gate 
418*7c478bd9Sstevel@tonic-gate /* _scr_hfhalf - horizontal scroll forward one half line(C(f)->cols/2) */
419*7c478bd9Sstevel@tonic-gate int
_scr_hfhalf(FORM * f)420*7c478bd9Sstevel@tonic-gate _scr_hfhalf(FORM *f)
421*7c478bd9Sstevel@tonic-gate {
422*7c478bd9Sstevel@tonic-gate 	FIELD	*c = C(f);
423*7c478bd9Sstevel@tonic-gate 	int	m = OffscreenCols(c) - B(f);
424*7c478bd9Sstevel@tonic-gate 	int	h = (c->cols + 1)/2;
425*7c478bd9Sstevel@tonic-gate 	int	n = h < m ? h : m;
426*7c478bd9Sstevel@tonic-gate 
427*7c478bd9Sstevel@tonic-gate 	if (n) {
428*7c478bd9Sstevel@tonic-gate 		X(f) += n;
429*7c478bd9Sstevel@tonic-gate 		B(f) += n;
430*7c478bd9Sstevel@tonic-gate 		return (E_OK);
431*7c478bd9Sstevel@tonic-gate 	}
432*7c478bd9Sstevel@tonic-gate 	return (E_REQUEST_DENIED);	/* at end */
433*7c478bd9Sstevel@tonic-gate }
434*7c478bd9Sstevel@tonic-gate 
435*7c478bd9Sstevel@tonic-gate /* _scr_hbhalf - horizontal scroll backward one half line(C(f)->cols/2) */
436*7c478bd9Sstevel@tonic-gate int
_scr_hbhalf(FORM * f)437*7c478bd9Sstevel@tonic-gate _scr_hbhalf(FORM *f)
438*7c478bd9Sstevel@tonic-gate {
439*7c478bd9Sstevel@tonic-gate 	FIELD	*c = C(f);
440*7c478bd9Sstevel@tonic-gate 	int	m = B(f);
441*7c478bd9Sstevel@tonic-gate 	int	h = (c->cols + 1)/2;
442*7c478bd9Sstevel@tonic-gate 	int	n = h < m ? h : m;
443*7c478bd9Sstevel@tonic-gate 
444*7c478bd9Sstevel@tonic-gate 	if (n) {
445*7c478bd9Sstevel@tonic-gate 		X(f) -= n;
446*7c478bd9Sstevel@tonic-gate 		B(f) -= n;
447*7c478bd9Sstevel@tonic-gate 		return (E_OK);
448*7c478bd9Sstevel@tonic-gate 	}
449*7c478bd9Sstevel@tonic-gate 	return (E_REQUEST_DENIED);	/* at top */
450*7c478bd9Sstevel@tonic-gate }
451