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	first(f)	(f->field [Pmin(f, P(f))])
37*7c478bd9Sstevel@tonic-gate #define	last(f)		(f->field [Pmax(f, P(f))])
38*7c478bd9Sstevel@tonic-gate #define	sfirst(f)	(f->field [Smin(f, P(f))])
39*7c478bd9Sstevel@tonic-gate #define	slast(f)	(f->field [Smax(f, P(f))])
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate #define	Active(f)	(Opt(f, O_ACTIVE) && Opt(f, O_VISIBLE))
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate /* next - return next active field on page after f(user defined order) */
44*7c478bd9Sstevel@tonic-gate static FIELD *
next(FIELD * f)45*7c478bd9Sstevel@tonic-gate next(FIELD *f)
46*7c478bd9Sstevel@tonic-gate {
47*7c478bd9Sstevel@tonic-gate 	FORM	*t	= f->form;
48*7c478bd9Sstevel@tonic-gate 	FIELD	**p	= t->field + f->index;
49*7c478bd9Sstevel@tonic-gate 	FIELD	**pmin	= t->field + Pmin(t, P(t));
50*7c478bd9Sstevel@tonic-gate 	FIELD	**pmax	= t->field + Pmax(t, P(t));
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate 	do
53*7c478bd9Sstevel@tonic-gate 		p = p == pmax ? pmin : p+1;
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate 	while ((!Active(*p)) && (*p != f));
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate 	return (*p);
58*7c478bd9Sstevel@tonic-gate }
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate /* prev - return previous active field on page before f */
61*7c478bd9Sstevel@tonic-gate static FIELD *
prev(FIELD * f)62*7c478bd9Sstevel@tonic-gate prev(FIELD *f)
63*7c478bd9Sstevel@tonic-gate {
64*7c478bd9Sstevel@tonic-gate 	FORM  *t	= f->form;
65*7c478bd9Sstevel@tonic-gate 	FIELD **p	= t->field + f->index;
66*7c478bd9Sstevel@tonic-gate 	FIELD **pmin	= t->field + Pmin(t, P(t));
67*7c478bd9Sstevel@tonic-gate 	FIELD **pmax	= t->field + Pmax(t, P(t));
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate 	do
70*7c478bd9Sstevel@tonic-gate 		p = p == pmin ? pmax : p-1;
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate 	while ((!Active(*p)) && (*p != f));
73*7c478bd9Sstevel@tonic-gate 
74*7c478bd9Sstevel@tonic-gate 	return (*p);
75*7c478bd9Sstevel@tonic-gate }
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate /* snext - return next active field on page after f(sorted order) */
78*7c478bd9Sstevel@tonic-gate static FIELD *
snext(FIELD * f)79*7c478bd9Sstevel@tonic-gate snext(FIELD *f)
80*7c478bd9Sstevel@tonic-gate {
81*7c478bd9Sstevel@tonic-gate 	FIELD *x = f;
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate 	do
84*7c478bd9Sstevel@tonic-gate 		f = f->snext;
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate 	while ((!Active(f)) && (f != x));
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate 	return (f);
89*7c478bd9Sstevel@tonic-gate }
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate /* sprev - return previous active field on page before f(sorted order) */
92*7c478bd9Sstevel@tonic-gate static FIELD *
sprev(FIELD * f)93*7c478bd9Sstevel@tonic-gate sprev(FIELD *f)
94*7c478bd9Sstevel@tonic-gate {
95*7c478bd9Sstevel@tonic-gate 	FIELD *x = f;
96*7c478bd9Sstevel@tonic-gate 
97*7c478bd9Sstevel@tonic-gate 	do
98*7c478bd9Sstevel@tonic-gate 		f = f->sprev;
99*7c478bd9Sstevel@tonic-gate 
100*7c478bd9Sstevel@tonic-gate 	while ((!Active(f)) && (f != x));
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate 	return (f);
103*7c478bd9Sstevel@tonic-gate }
104*7c478bd9Sstevel@tonic-gate 
105*7c478bd9Sstevel@tonic-gate /* left - return active field on page left of f */
106*7c478bd9Sstevel@tonic-gate static FIELD *
left(FIELD * f)107*7c478bd9Sstevel@tonic-gate left(FIELD *f)
108*7c478bd9Sstevel@tonic-gate {
109*7c478bd9Sstevel@tonic-gate 	int row = f->frow;
110*7c478bd9Sstevel@tonic-gate 
111*7c478bd9Sstevel@tonic-gate 	do
112*7c478bd9Sstevel@tonic-gate 		f = sprev(f);
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate 	while (f->frow != row);
115*7c478bd9Sstevel@tonic-gate 
116*7c478bd9Sstevel@tonic-gate 	return (f);
117*7c478bd9Sstevel@tonic-gate }
118*7c478bd9Sstevel@tonic-gate 
119*7c478bd9Sstevel@tonic-gate /* right - return active field on page right of f */
120*7c478bd9Sstevel@tonic-gate static FIELD *
right(FIELD * f)121*7c478bd9Sstevel@tonic-gate right(FIELD *f)
122*7c478bd9Sstevel@tonic-gate {
123*7c478bd9Sstevel@tonic-gate 	int row = f->frow;
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate 	do
126*7c478bd9Sstevel@tonic-gate 		f = snext(f);
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate 	while (f->frow != row);
129*7c478bd9Sstevel@tonic-gate 
130*7c478bd9Sstevel@tonic-gate 	return (f);
131*7c478bd9Sstevel@tonic-gate }
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate /* up - return active field on page above f */
134*7c478bd9Sstevel@tonic-gate static FIELD *
up(FIELD * f)135*7c478bd9Sstevel@tonic-gate up(FIELD *f)
136*7c478bd9Sstevel@tonic-gate {
137*7c478bd9Sstevel@tonic-gate 	int row = f->frow;
138*7c478bd9Sstevel@tonic-gate 	int col = f->fcol;
139*7c478bd9Sstevel@tonic-gate 
140*7c478bd9Sstevel@tonic-gate 	do
141*7c478bd9Sstevel@tonic-gate 		f = sprev(f);
142*7c478bd9Sstevel@tonic-gate 
143*7c478bd9Sstevel@tonic-gate 	while (f->frow == row && f->fcol != col);
144*7c478bd9Sstevel@tonic-gate 
145*7c478bd9Sstevel@tonic-gate 	if (f->frow != row) {
146*7c478bd9Sstevel@tonic-gate 		row = f->frow;
147*7c478bd9Sstevel@tonic-gate 
148*7c478bd9Sstevel@tonic-gate 		while (f->frow == row && f->fcol > col)
149*7c478bd9Sstevel@tonic-gate 			f = sprev(f);
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate 		if (f->frow != row)
152*7c478bd9Sstevel@tonic-gate 			f = snext(f);
153*7c478bd9Sstevel@tonic-gate 	}
154*7c478bd9Sstevel@tonic-gate 	return (f);
155*7c478bd9Sstevel@tonic-gate }
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate /* down - return active field on page below f */
158*7c478bd9Sstevel@tonic-gate static FIELD *
down(FIELD * f)159*7c478bd9Sstevel@tonic-gate down(FIELD *f)
160*7c478bd9Sstevel@tonic-gate {
161*7c478bd9Sstevel@tonic-gate 	int row = f->frow;
162*7c478bd9Sstevel@tonic-gate 	int col = f->fcol;
163*7c478bd9Sstevel@tonic-gate 
164*7c478bd9Sstevel@tonic-gate 	do
165*7c478bd9Sstevel@tonic-gate 		f = snext(f);
166*7c478bd9Sstevel@tonic-gate 
167*7c478bd9Sstevel@tonic-gate 	while (f->frow == row && f->fcol != col);
168*7c478bd9Sstevel@tonic-gate 
169*7c478bd9Sstevel@tonic-gate 	if (f->frow != row) {
170*7c478bd9Sstevel@tonic-gate 		row = f->frow;
171*7c478bd9Sstevel@tonic-gate 
172*7c478bd9Sstevel@tonic-gate 		while (f->frow == row && f->fcol < col)
173*7c478bd9Sstevel@tonic-gate 			f = snext(f);
174*7c478bd9Sstevel@tonic-gate 
175*7c478bd9Sstevel@tonic-gate 		if (f ->frow != row)
176*7c478bd9Sstevel@tonic-gate 			f = sprev(f);
177*7c478bd9Sstevel@tonic-gate 	}
178*7c478bd9Sstevel@tonic-gate 	return (f);
179*7c478bd9Sstevel@tonic-gate }
180*7c478bd9Sstevel@tonic-gate 
181*7c478bd9Sstevel@tonic-gate 	/*
182*7c478bd9Sstevel@tonic-gate 	 *  _next_field
183*7c478bd9Sstevel@tonic-gate 	 */
184*7c478bd9Sstevel@tonic-gate 
185*7c478bd9Sstevel@tonic-gate int
_next_field(FORM * f)186*7c478bd9Sstevel@tonic-gate _next_field(FORM *f)
187*7c478bd9Sstevel@tonic-gate {
188*7c478bd9Sstevel@tonic-gate 	return (_set_current_field(f, next(C(f))));
189*7c478bd9Sstevel@tonic-gate }
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate int
_prev_field(FORM * f)192*7c478bd9Sstevel@tonic-gate _prev_field(FORM *f)
193*7c478bd9Sstevel@tonic-gate {
194*7c478bd9Sstevel@tonic-gate 	return (_set_current_field(f, prev(C(f))));
195*7c478bd9Sstevel@tonic-gate }
196*7c478bd9Sstevel@tonic-gate 
197*7c478bd9Sstevel@tonic-gate int
_first_field(FORM * f)198*7c478bd9Sstevel@tonic-gate _first_field(FORM *f)
199*7c478bd9Sstevel@tonic-gate {
200*7c478bd9Sstevel@tonic-gate 	return (_set_current_field(f, next(last(f))));
201*7c478bd9Sstevel@tonic-gate }
202*7c478bd9Sstevel@tonic-gate 
203*7c478bd9Sstevel@tonic-gate int
_last_field(FORM * f)204*7c478bd9Sstevel@tonic-gate _last_field(FORM *f)
205*7c478bd9Sstevel@tonic-gate {
206*7c478bd9Sstevel@tonic-gate 	return (_set_current_field(f, prev(first(f))));
207*7c478bd9Sstevel@tonic-gate }
208*7c478bd9Sstevel@tonic-gate 
209*7c478bd9Sstevel@tonic-gate int
_snext_field(FORM * f)210*7c478bd9Sstevel@tonic-gate _snext_field(FORM *f)
211*7c478bd9Sstevel@tonic-gate {
212*7c478bd9Sstevel@tonic-gate 	return (_set_current_field(f, snext(C(f))));
213*7c478bd9Sstevel@tonic-gate }
214*7c478bd9Sstevel@tonic-gate 
215*7c478bd9Sstevel@tonic-gate int
_sprev_field(FORM * f)216*7c478bd9Sstevel@tonic-gate _sprev_field(FORM *f)
217*7c478bd9Sstevel@tonic-gate {
218*7c478bd9Sstevel@tonic-gate 	return (_set_current_field(f, sprev(C(f))));
219*7c478bd9Sstevel@tonic-gate }
220*7c478bd9Sstevel@tonic-gate 
221*7c478bd9Sstevel@tonic-gate int
_sfirst_field(FORM * f)222*7c478bd9Sstevel@tonic-gate _sfirst_field(FORM *f)
223*7c478bd9Sstevel@tonic-gate {
224*7c478bd9Sstevel@tonic-gate 	return (_set_current_field(f, snext(slast(f))));
225*7c478bd9Sstevel@tonic-gate }
226*7c478bd9Sstevel@tonic-gate 
227*7c478bd9Sstevel@tonic-gate int
_slast_field(FORM * f)228*7c478bd9Sstevel@tonic-gate _slast_field(FORM *f)
229*7c478bd9Sstevel@tonic-gate {
230*7c478bd9Sstevel@tonic-gate 	return (_set_current_field(f, sprev(sfirst(f))));
231*7c478bd9Sstevel@tonic-gate }
232*7c478bd9Sstevel@tonic-gate 
233*7c478bd9Sstevel@tonic-gate int
_left_field(FORM * f)234*7c478bd9Sstevel@tonic-gate _left_field(FORM *f)
235*7c478bd9Sstevel@tonic-gate {
236*7c478bd9Sstevel@tonic-gate 	return (_set_current_field(f, left(C(f))));
237*7c478bd9Sstevel@tonic-gate }
238*7c478bd9Sstevel@tonic-gate 
239*7c478bd9Sstevel@tonic-gate int
_right_field(FORM * f)240*7c478bd9Sstevel@tonic-gate _right_field(FORM *f)
241*7c478bd9Sstevel@tonic-gate {
242*7c478bd9Sstevel@tonic-gate 	return (_set_current_field(f, right(C(f))));
243*7c478bd9Sstevel@tonic-gate }
244*7c478bd9Sstevel@tonic-gate 
245*7c478bd9Sstevel@tonic-gate int
_up_field(FORM * f)246*7c478bd9Sstevel@tonic-gate _up_field(FORM *f)
247*7c478bd9Sstevel@tonic-gate {
248*7c478bd9Sstevel@tonic-gate 	return (_set_current_field(f, up(C(f))));
249*7c478bd9Sstevel@tonic-gate }
250*7c478bd9Sstevel@tonic-gate 
251*7c478bd9Sstevel@tonic-gate int
_down_field(FORM * f)252*7c478bd9Sstevel@tonic-gate _down_field(FORM *f)
253*7c478bd9Sstevel@tonic-gate {
254*7c478bd9Sstevel@tonic-gate 	return (_set_current_field(f, down(C(f))));
255*7c478bd9Sstevel@tonic-gate }
256*7c478bd9Sstevel@tonic-gate 
257*7c478bd9Sstevel@tonic-gate FIELD *
_first_active(FORM * f)258*7c478bd9Sstevel@tonic-gate _first_active(FORM *f)
259*7c478bd9Sstevel@tonic-gate {
260*7c478bd9Sstevel@tonic-gate 	return (next(last(f)));
261*7c478bd9Sstevel@tonic-gate }
262