1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
23*0Sstevel@tonic-gate /* All Rights Reserved */
24*0Sstevel@tonic-gate
25*0Sstevel@tonic-gate
26*0Sstevel@tonic-gate /*
27*0Sstevel@tonic-gate * Copyright (c) 1997, by Sun Microsystems, Inc.
28*0Sstevel@tonic-gate * All rights reserved.
29*0Sstevel@tonic-gate */
30*0Sstevel@tonic-gate
31*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
32*0Sstevel@tonic-gate
33*0Sstevel@tonic-gate /*LINTLIBRARY*/
34*0Sstevel@tonic-gate
35*0Sstevel@tonic-gate #include <sys/types.h>
36*0Sstevel@tonic-gate #include "utility.h"
37*0Sstevel@tonic-gate
38*0Sstevel@tonic-gate #define first(f) (f->field [Pmin(f, P(f))])
39*0Sstevel@tonic-gate #define last(f) (f->field [Pmax(f, P(f))])
40*0Sstevel@tonic-gate #define sfirst(f) (f->field [Smin(f, P(f))])
41*0Sstevel@tonic-gate #define slast(f) (f->field [Smax(f, P(f))])
42*0Sstevel@tonic-gate
43*0Sstevel@tonic-gate #define Active(f) (Opt(f, O_ACTIVE) && Opt(f, O_VISIBLE))
44*0Sstevel@tonic-gate
45*0Sstevel@tonic-gate /* next - return next active field on page after f(user defined order) */
46*0Sstevel@tonic-gate static FIELD *
next(FIELD * f)47*0Sstevel@tonic-gate next(FIELD *f)
48*0Sstevel@tonic-gate {
49*0Sstevel@tonic-gate FORM *t = f->form;
50*0Sstevel@tonic-gate FIELD **p = t->field + f->index;
51*0Sstevel@tonic-gate FIELD **pmin = t->field + Pmin(t, P(t));
52*0Sstevel@tonic-gate FIELD **pmax = t->field + Pmax(t, P(t));
53*0Sstevel@tonic-gate
54*0Sstevel@tonic-gate do
55*0Sstevel@tonic-gate p = p == pmax ? pmin : p+1;
56*0Sstevel@tonic-gate
57*0Sstevel@tonic-gate while ((!Active(*p)) && (*p != f));
58*0Sstevel@tonic-gate
59*0Sstevel@tonic-gate return (*p);
60*0Sstevel@tonic-gate }
61*0Sstevel@tonic-gate
62*0Sstevel@tonic-gate /* prev - return previous active field on page before f */
63*0Sstevel@tonic-gate static FIELD *
prev(FIELD * f)64*0Sstevel@tonic-gate prev(FIELD *f)
65*0Sstevel@tonic-gate {
66*0Sstevel@tonic-gate FORM *t = f->form;
67*0Sstevel@tonic-gate FIELD **p = t->field + f->index;
68*0Sstevel@tonic-gate FIELD **pmin = t->field + Pmin(t, P(t));
69*0Sstevel@tonic-gate FIELD **pmax = t->field + Pmax(t, P(t));
70*0Sstevel@tonic-gate
71*0Sstevel@tonic-gate do
72*0Sstevel@tonic-gate p = p == pmin ? pmax : p-1;
73*0Sstevel@tonic-gate
74*0Sstevel@tonic-gate while ((!Active(*p)) && (*p != f));
75*0Sstevel@tonic-gate
76*0Sstevel@tonic-gate return (*p);
77*0Sstevel@tonic-gate }
78*0Sstevel@tonic-gate
79*0Sstevel@tonic-gate /* snext - return next active field on page after f(sorted order) */
80*0Sstevel@tonic-gate static FIELD *
snext(FIELD * f)81*0Sstevel@tonic-gate snext(FIELD *f)
82*0Sstevel@tonic-gate {
83*0Sstevel@tonic-gate FIELD *x = f;
84*0Sstevel@tonic-gate
85*0Sstevel@tonic-gate do
86*0Sstevel@tonic-gate f = f->snext;
87*0Sstevel@tonic-gate
88*0Sstevel@tonic-gate while ((!Active(f)) && (f != x));
89*0Sstevel@tonic-gate
90*0Sstevel@tonic-gate return (f);
91*0Sstevel@tonic-gate }
92*0Sstevel@tonic-gate
93*0Sstevel@tonic-gate /* sprev - return previous active field on page before f(sorted order) */
94*0Sstevel@tonic-gate static FIELD *
sprev(FIELD * f)95*0Sstevel@tonic-gate sprev(FIELD *f)
96*0Sstevel@tonic-gate {
97*0Sstevel@tonic-gate FIELD *x = f;
98*0Sstevel@tonic-gate
99*0Sstevel@tonic-gate do
100*0Sstevel@tonic-gate f = f->sprev;
101*0Sstevel@tonic-gate
102*0Sstevel@tonic-gate while ((!Active(f)) && (f != x));
103*0Sstevel@tonic-gate
104*0Sstevel@tonic-gate return (f);
105*0Sstevel@tonic-gate }
106*0Sstevel@tonic-gate
107*0Sstevel@tonic-gate /* left - return active field on page left of f */
108*0Sstevel@tonic-gate static FIELD *
left(FIELD * f)109*0Sstevel@tonic-gate left(FIELD *f)
110*0Sstevel@tonic-gate {
111*0Sstevel@tonic-gate int row = f->frow;
112*0Sstevel@tonic-gate
113*0Sstevel@tonic-gate do
114*0Sstevel@tonic-gate f = sprev(f);
115*0Sstevel@tonic-gate
116*0Sstevel@tonic-gate while (f->frow != row);
117*0Sstevel@tonic-gate
118*0Sstevel@tonic-gate return (f);
119*0Sstevel@tonic-gate }
120*0Sstevel@tonic-gate
121*0Sstevel@tonic-gate /* right - return active field on page right of f */
122*0Sstevel@tonic-gate static FIELD *
right(FIELD * f)123*0Sstevel@tonic-gate right(FIELD *f)
124*0Sstevel@tonic-gate {
125*0Sstevel@tonic-gate int row = f->frow;
126*0Sstevel@tonic-gate
127*0Sstevel@tonic-gate do
128*0Sstevel@tonic-gate f = snext(f);
129*0Sstevel@tonic-gate
130*0Sstevel@tonic-gate while (f->frow != row);
131*0Sstevel@tonic-gate
132*0Sstevel@tonic-gate return (f);
133*0Sstevel@tonic-gate }
134*0Sstevel@tonic-gate
135*0Sstevel@tonic-gate /* up - return active field on page above f */
136*0Sstevel@tonic-gate static FIELD *
up(FIELD * f)137*0Sstevel@tonic-gate up(FIELD *f)
138*0Sstevel@tonic-gate {
139*0Sstevel@tonic-gate int row = f->frow;
140*0Sstevel@tonic-gate int col = f->fcol;
141*0Sstevel@tonic-gate
142*0Sstevel@tonic-gate do
143*0Sstevel@tonic-gate f = sprev(f);
144*0Sstevel@tonic-gate
145*0Sstevel@tonic-gate while (f->frow == row && f->fcol != col);
146*0Sstevel@tonic-gate
147*0Sstevel@tonic-gate if (f->frow != row) {
148*0Sstevel@tonic-gate row = f->frow;
149*0Sstevel@tonic-gate
150*0Sstevel@tonic-gate while (f->frow == row && f->fcol > col)
151*0Sstevel@tonic-gate f = sprev(f);
152*0Sstevel@tonic-gate
153*0Sstevel@tonic-gate if (f->frow != row)
154*0Sstevel@tonic-gate f = snext(f);
155*0Sstevel@tonic-gate }
156*0Sstevel@tonic-gate return (f);
157*0Sstevel@tonic-gate }
158*0Sstevel@tonic-gate
159*0Sstevel@tonic-gate /* down - return active field on page below f */
160*0Sstevel@tonic-gate static FIELD *
down(FIELD * f)161*0Sstevel@tonic-gate down(FIELD *f)
162*0Sstevel@tonic-gate {
163*0Sstevel@tonic-gate int row = f->frow;
164*0Sstevel@tonic-gate int col = f->fcol;
165*0Sstevel@tonic-gate
166*0Sstevel@tonic-gate do
167*0Sstevel@tonic-gate f = snext(f);
168*0Sstevel@tonic-gate
169*0Sstevel@tonic-gate while (f->frow == row && f->fcol != col);
170*0Sstevel@tonic-gate
171*0Sstevel@tonic-gate if (f->frow != row) {
172*0Sstevel@tonic-gate row = f->frow;
173*0Sstevel@tonic-gate
174*0Sstevel@tonic-gate while (f->frow == row && f->fcol < col)
175*0Sstevel@tonic-gate f = snext(f);
176*0Sstevel@tonic-gate
177*0Sstevel@tonic-gate if (f ->frow != row)
178*0Sstevel@tonic-gate f = sprev(f);
179*0Sstevel@tonic-gate }
180*0Sstevel@tonic-gate return (f);
181*0Sstevel@tonic-gate }
182*0Sstevel@tonic-gate
183*0Sstevel@tonic-gate /*
184*0Sstevel@tonic-gate * _next_field
185*0Sstevel@tonic-gate */
186*0Sstevel@tonic-gate
187*0Sstevel@tonic-gate int
_next_field(FORM * f)188*0Sstevel@tonic-gate _next_field(FORM *f)
189*0Sstevel@tonic-gate {
190*0Sstevel@tonic-gate return (_set_current_field(f, next(C(f))));
191*0Sstevel@tonic-gate }
192*0Sstevel@tonic-gate
193*0Sstevel@tonic-gate int
_prev_field(FORM * f)194*0Sstevel@tonic-gate _prev_field(FORM *f)
195*0Sstevel@tonic-gate {
196*0Sstevel@tonic-gate return (_set_current_field(f, prev(C(f))));
197*0Sstevel@tonic-gate }
198*0Sstevel@tonic-gate
199*0Sstevel@tonic-gate int
_first_field(FORM * f)200*0Sstevel@tonic-gate _first_field(FORM *f)
201*0Sstevel@tonic-gate {
202*0Sstevel@tonic-gate return (_set_current_field(f, next(last(f))));
203*0Sstevel@tonic-gate }
204*0Sstevel@tonic-gate
205*0Sstevel@tonic-gate int
_last_field(FORM * f)206*0Sstevel@tonic-gate _last_field(FORM *f)
207*0Sstevel@tonic-gate {
208*0Sstevel@tonic-gate return (_set_current_field(f, prev(first(f))));
209*0Sstevel@tonic-gate }
210*0Sstevel@tonic-gate
211*0Sstevel@tonic-gate int
_snext_field(FORM * f)212*0Sstevel@tonic-gate _snext_field(FORM *f)
213*0Sstevel@tonic-gate {
214*0Sstevel@tonic-gate return (_set_current_field(f, snext(C(f))));
215*0Sstevel@tonic-gate }
216*0Sstevel@tonic-gate
217*0Sstevel@tonic-gate int
_sprev_field(FORM * f)218*0Sstevel@tonic-gate _sprev_field(FORM *f)
219*0Sstevel@tonic-gate {
220*0Sstevel@tonic-gate return (_set_current_field(f, sprev(C(f))));
221*0Sstevel@tonic-gate }
222*0Sstevel@tonic-gate
223*0Sstevel@tonic-gate int
_sfirst_field(FORM * f)224*0Sstevel@tonic-gate _sfirst_field(FORM *f)
225*0Sstevel@tonic-gate {
226*0Sstevel@tonic-gate return (_set_current_field(f, snext(slast(f))));
227*0Sstevel@tonic-gate }
228*0Sstevel@tonic-gate
229*0Sstevel@tonic-gate int
_slast_field(FORM * f)230*0Sstevel@tonic-gate _slast_field(FORM *f)
231*0Sstevel@tonic-gate {
232*0Sstevel@tonic-gate return (_set_current_field(f, sprev(sfirst(f))));
233*0Sstevel@tonic-gate }
234*0Sstevel@tonic-gate
235*0Sstevel@tonic-gate int
_left_field(FORM * f)236*0Sstevel@tonic-gate _left_field(FORM *f)
237*0Sstevel@tonic-gate {
238*0Sstevel@tonic-gate return (_set_current_field(f, left(C(f))));
239*0Sstevel@tonic-gate }
240*0Sstevel@tonic-gate
241*0Sstevel@tonic-gate int
_right_field(FORM * f)242*0Sstevel@tonic-gate _right_field(FORM *f)
243*0Sstevel@tonic-gate {
244*0Sstevel@tonic-gate return (_set_current_field(f, right(C(f))));
245*0Sstevel@tonic-gate }
246*0Sstevel@tonic-gate
247*0Sstevel@tonic-gate int
_up_field(FORM * f)248*0Sstevel@tonic-gate _up_field(FORM *f)
249*0Sstevel@tonic-gate {
250*0Sstevel@tonic-gate return (_set_current_field(f, up(C(f))));
251*0Sstevel@tonic-gate }
252*0Sstevel@tonic-gate
253*0Sstevel@tonic-gate int
_down_field(FORM * f)254*0Sstevel@tonic-gate _down_field(FORM *f)
255*0Sstevel@tonic-gate {
256*0Sstevel@tonic-gate return (_set_current_field(f, down(C(f))));
257*0Sstevel@tonic-gate }
258*0Sstevel@tonic-gate
259*0Sstevel@tonic-gate FIELD *
_first_active(FORM * f)260*0Sstevel@tonic-gate _first_active(FORM *f)
261*0Sstevel@tonic-gate {
262*0Sstevel@tonic-gate return (next(last(f)));
263*0Sstevel@tonic-gate }
264