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 typedef struct {
37*7c478bd9Sstevel@tonic-gate 	PTF_int		class;
38*7c478bd9Sstevel@tonic-gate 	PTF_int		act;
39*7c478bd9Sstevel@tonic-gate } REQUEST;
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate static REQUEST parse(int);
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate #define	COMMAND(x)	(x.class)
44*7c478bd9Sstevel@tonic-gate #define	CALL(x, f)	(x.class ? (*x.class) (x.act, f) : E_SYSTEM_ERROR)
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate /* command array(carray) order is significant(see form.h REQ_*) */
47*7c478bd9Sstevel@tonic-gate static REQUEST carray [MAX_FORM_COMMAND - MIN_FORM_COMMAND + 1] =
48*7c478bd9Sstevel@tonic-gate {
49*7c478bd9Sstevel@tonic-gate 	_page_navigation,	_next_page,	/* REQ_NEXT_PAGE	*/
50*7c478bd9Sstevel@tonic-gate 	_page_navigation,	_prev_page,	/* REQ_PREV_PAGE	*/
51*7c478bd9Sstevel@tonic-gate 	_page_navigation,	_first_page,	/* REQ_FIRST_PAGE	*/
52*7c478bd9Sstevel@tonic-gate 	_page_navigation,	_last_page,	/* REQ_LAST_PAGE	*/
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate 	_field_navigation,	_next_field,	/* REQ_NEXT_FIELD	*/
55*7c478bd9Sstevel@tonic-gate 	_field_navigation,	_prev_field,	/* REQ_PREV_FIELD	*/
56*7c478bd9Sstevel@tonic-gate 	_field_navigation,	_first_field,	/* REQ_FIRST_FIELD	*/
57*7c478bd9Sstevel@tonic-gate 	_field_navigation,	_last_field,	/* REQ_LAST_FIELD	*/
58*7c478bd9Sstevel@tonic-gate 	_field_navigation,	_snext_field,	/* REQ_SNEXT_FIELD	*/
59*7c478bd9Sstevel@tonic-gate 	_field_navigation,	_sprev_field,	/* REQ_SPREV_FIELD	*/
60*7c478bd9Sstevel@tonic-gate 	_field_navigation,	_sfirst_field,	/* REQ_SFIRST_FIELD	*/
61*7c478bd9Sstevel@tonic-gate 	_field_navigation,	_slast_field,	/* REQ_SLAST_FIELD	*/
62*7c478bd9Sstevel@tonic-gate 	_field_navigation,	_left_field,	/* REQ_LEFT_FIELD	*/
63*7c478bd9Sstevel@tonic-gate 	_field_navigation,	_right_field,	/* REQ_RIGHT_FIELD	*/
64*7c478bd9Sstevel@tonic-gate 	_field_navigation,	_up_field,	/* REQ_UP_FIELD		*/
65*7c478bd9Sstevel@tonic-gate 	_field_navigation,	_down_field,	/* REQ_DOWN_FIELD	*/
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate 	_data_navigation,	_next_char,	/* REQ_NEXT_CHAR	*/
68*7c478bd9Sstevel@tonic-gate 	_data_navigation,	_prev_char,	/* REQ_PREV_CHAR	*/
69*7c478bd9Sstevel@tonic-gate 	_data_navigation,	_next_line,	/* REQ_NEXT_LINE	*/
70*7c478bd9Sstevel@tonic-gate 	_data_navigation,	_prev_line,	/* REQ_PREV_LINE	*/
71*7c478bd9Sstevel@tonic-gate 	_data_navigation,	_next_word,	/* REQ_NEXT_WORD	*/
72*7c478bd9Sstevel@tonic-gate 	_data_navigation,	_prev_word,	/* REQ_PREV_WORD	*/
73*7c478bd9Sstevel@tonic-gate 	_data_navigation,	_beg_field,	/* REQ_BEG_FIELD	*/
74*7c478bd9Sstevel@tonic-gate 	_data_navigation,	_end_field,	/* REQ_END_FIELD	*/
75*7c478bd9Sstevel@tonic-gate 	_data_navigation,	_beg_line,	/* REQ_BEG_LINE		*/
76*7c478bd9Sstevel@tonic-gate 	_data_navigation,	_end_line,	/* REQ_END_LINE		*/
77*7c478bd9Sstevel@tonic-gate 	_data_navigation,	_left_char,	/* REQ_LEFT_CHAR	*/
78*7c478bd9Sstevel@tonic-gate 	_data_navigation,	_right_char,	/* REQ_RIGHT_CHAR	*/
79*7c478bd9Sstevel@tonic-gate 	_data_navigation,	_up_char,	/* REQ_UP_CHAR		*/
80*7c478bd9Sstevel@tonic-gate 	_data_navigation,	_down_char,	/* REQ_DOWN_CHAR	*/
81*7c478bd9Sstevel@tonic-gate 
82*7c478bd9Sstevel@tonic-gate 	_misc_request,		_new_line,	/* REQ_NEW_LINE		*/
83*7c478bd9Sstevel@tonic-gate 	_data_manipulation,	_ins_char,	/* REQ_INS_CHAR		*/
84*7c478bd9Sstevel@tonic-gate 	_data_manipulation,	_ins_line,	/* REQ_INS_LINE		*/
85*7c478bd9Sstevel@tonic-gate 	_data_manipulation,	_del_char,	/* REQ_DEL_CHAR		*/
86*7c478bd9Sstevel@tonic-gate 	_misc_request,		_del_prev,	/* REQ_DEL_PREV		*/
87*7c478bd9Sstevel@tonic-gate 	_data_manipulation,	_del_line,	/* REQ_DEL_LINE		*/
88*7c478bd9Sstevel@tonic-gate 	_data_manipulation,	_del_word,	/* REQ_DEL_WORD		*/
89*7c478bd9Sstevel@tonic-gate 	_data_manipulation,	_clr_eol,	/* REQ_CLR_EOL		*/
90*7c478bd9Sstevel@tonic-gate 	_data_manipulation,	_clr_eof,	/* REQ_CLR_EOF		*/
91*7c478bd9Sstevel@tonic-gate 	_data_manipulation,	_clr_field,	/* REQ_CLR_FIELD	*/
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate 	_misc_request,		_ovl_mode,	/* REQ_OVL_MODE		*/
94*7c478bd9Sstevel@tonic-gate 	_misc_request,		_ins_mode,	/* REQ_INS_MODE		*/
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate 	_data_navigation,	_scr_fline,	/* REQ_SCR_FLINE	*/
97*7c478bd9Sstevel@tonic-gate 	_data_navigation,	_scr_bline,	/* REQ_SCR_BLINE	*/
98*7c478bd9Sstevel@tonic-gate 	_data_navigation,	_scr_fpage,	/* REQ_SCR_FPAGE	*/
99*7c478bd9Sstevel@tonic-gate 	_data_navigation,	_scr_bpage,	/* REQ_SCR_BPAGE	*/
100*7c478bd9Sstevel@tonic-gate 	_data_navigation,	_scr_fhpage,	/* REQ_SCR_FHPAGE	*/
101*7c478bd9Sstevel@tonic-gate 	_data_navigation,	_scr_bhpage,	/* REQ_SCR_BHPAGE	*/
102*7c478bd9Sstevel@tonic-gate 
103*7c478bd9Sstevel@tonic-gate 	_data_navigation,	_scr_fchar,	/* REQ_SCR_FCHAR	*/
104*7c478bd9Sstevel@tonic-gate 	_data_navigation,	_scr_bchar,	/* REQ_SCR_BCHAR	*/
105*7c478bd9Sstevel@tonic-gate 	_data_navigation,	_scr_hfline,	/* REQ_SCR_HFLINE	*/
106*7c478bd9Sstevel@tonic-gate 	_data_navigation,	_scr_hbline,	/* REQ_SCR_HBLINE	*/
107*7c478bd9Sstevel@tonic-gate 	_data_navigation,	_scr_hfhalf,	/* REQ_SCR_HFHALF	*/
108*7c478bd9Sstevel@tonic-gate 	_data_navigation,	_scr_hbhalf,	/* REQ_SCR_HBHALF	*/
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate 	_misc_request,		_validation,	/* REQ_VALIDATION	*/
111*7c478bd9Sstevel@tonic-gate 	_misc_request,		_next_choice,	/* REQ_NEXT_CHOICE	*/
112*7c478bd9Sstevel@tonic-gate 	_misc_request,		_prev_choice,	/* REQ_PREV_CHOICE	*/
113*7c478bd9Sstevel@tonic-gate };
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate static REQUEST FAIL = { (PTF_int) 0, (PTF_int) 0 };
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate /* _page_navigation - service page navigation request */
118*7c478bd9Sstevel@tonic-gate int
_page_navigation(PTF_int act,FORM * f)119*7c478bd9Sstevel@tonic-gate _page_navigation(PTF_int act, FORM *f)
120*7c478bd9Sstevel@tonic-gate {
121*7c478bd9Sstevel@tonic-gate 	int v;
122*7c478bd9Sstevel@tonic-gate 
123*7c478bd9Sstevel@tonic-gate 	if (_validate(f)) {
124*7c478bd9Sstevel@tonic-gate 		term_field(f);
125*7c478bd9Sstevel@tonic-gate 		term_form(f);
126*7c478bd9Sstevel@tonic-gate 		v = (*act) (f);
127*7c478bd9Sstevel@tonic-gate 		init_form(f);
128*7c478bd9Sstevel@tonic-gate 		init_field(f);
129*7c478bd9Sstevel@tonic-gate 	} else
130*7c478bd9Sstevel@tonic-gate 		v = E_INVALID_FIELD;
131*7c478bd9Sstevel@tonic-gate 
132*7c478bd9Sstevel@tonic-gate 	return (v);
133*7c478bd9Sstevel@tonic-gate }
134*7c478bd9Sstevel@tonic-gate 
135*7c478bd9Sstevel@tonic-gate /* _field_navigation - service inter-field navigation request */
136*7c478bd9Sstevel@tonic-gate int
_field_navigation(PTF_int act,FORM * f)137*7c478bd9Sstevel@tonic-gate _field_navigation(PTF_int act, FORM *f)
138*7c478bd9Sstevel@tonic-gate {
139*7c478bd9Sstevel@tonic-gate 	int v;
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate 	if (_validate(f)) {
142*7c478bd9Sstevel@tonic-gate 		term_field(f);
143*7c478bd9Sstevel@tonic-gate 		v = (*act) (f);
144*7c478bd9Sstevel@tonic-gate 		init_field(f);
145*7c478bd9Sstevel@tonic-gate 	} else
146*7c478bd9Sstevel@tonic-gate 		v = E_INVALID_FIELD;
147*7c478bd9Sstevel@tonic-gate 
148*7c478bd9Sstevel@tonic-gate 	return (v);
149*7c478bd9Sstevel@tonic-gate }
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate /* _data_navigation - service intra-field navagation request */
152*7c478bd9Sstevel@tonic-gate int
_data_navigation(PTF_int act,FORM * f)153*7c478bd9Sstevel@tonic-gate _data_navigation(PTF_int act, FORM *f)
154*7c478bd9Sstevel@tonic-gate {
155*7c478bd9Sstevel@tonic-gate 	return ((*act) (f));
156*7c478bd9Sstevel@tonic-gate }
157*7c478bd9Sstevel@tonic-gate 
158*7c478bd9Sstevel@tonic-gate /* _data_manipulation - service data modification request */
159*7c478bd9Sstevel@tonic-gate int
_data_manipulation(PTF_int act,FORM * f)160*7c478bd9Sstevel@tonic-gate _data_manipulation(PTF_int act, FORM *f)
161*7c478bd9Sstevel@tonic-gate {
162*7c478bd9Sstevel@tonic-gate 	int		v = E_REQUEST_DENIED;
163*7c478bd9Sstevel@tonic-gate 	FIELD *		c = C(f);
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate 	if (Opt(c, O_EDIT))
166*7c478bd9Sstevel@tonic-gate 		if ((v = (*act) (f)) == E_OK)
167*7c478bd9Sstevel@tonic-gate 			Set(f, WIN_CHG);
168*7c478bd9Sstevel@tonic-gate 	return (v);
169*7c478bd9Sstevel@tonic-gate }
170*7c478bd9Sstevel@tonic-gate 
171*7c478bd9Sstevel@tonic-gate int
_misc_request(PTF_int act,FORM * f)172*7c478bd9Sstevel@tonic-gate _misc_request(PTF_int act, FORM *f)
173*7c478bd9Sstevel@tonic-gate {
174*7c478bd9Sstevel@tonic-gate 	return ((*act) (f));
175*7c478bd9Sstevel@tonic-gate }
176*7c478bd9Sstevel@tonic-gate 
177*7c478bd9Sstevel@tonic-gate int
form_driver(FORM * f,int c)178*7c478bd9Sstevel@tonic-gate form_driver(FORM *f, int c)
179*7c478bd9Sstevel@tonic-gate {
180*7c478bd9Sstevel@tonic-gate 	int		v;
181*7c478bd9Sstevel@tonic-gate 	REQUEST		x;
182*7c478bd9Sstevel@tonic-gate 
183*7c478bd9Sstevel@tonic-gate 	if (f) {
184*7c478bd9Sstevel@tonic-gate 		if (Status(f, DRIVER))
185*7c478bd9Sstevel@tonic-gate 
186*7c478bd9Sstevel@tonic-gate 			v = E_BAD_STATE;
187*7c478bd9Sstevel@tonic-gate 
188*7c478bd9Sstevel@tonic-gate 		else if (Status(f, POSTED)) {
189*7c478bd9Sstevel@tonic-gate 			x = parse(c);
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate 			if (COMMAND(x))
192*7c478bd9Sstevel@tonic-gate 				v = CALL(x, f);
193*7c478bd9Sstevel@tonic-gate 			else {
194*7c478bd9Sstevel@tonic-gate 				if (isascii(c) && isprint(c) &&
195*7c478bd9Sstevel@tonic-gate 				    CheckChar(C(f), c))
196*7c478bd9Sstevel@tonic-gate 					v = _data_entry(f, c);
197*7c478bd9Sstevel@tonic-gate 				else
198*7c478bd9Sstevel@tonic-gate 					v = E_UNKNOWN_COMMAND;
199*7c478bd9Sstevel@tonic-gate 			}
200*7c478bd9Sstevel@tonic-gate 			(void) _update_current(f);
201*7c478bd9Sstevel@tonic-gate 		} else
202*7c478bd9Sstevel@tonic-gate 			v = E_NOT_POSTED;
203*7c478bd9Sstevel@tonic-gate 	} else
204*7c478bd9Sstevel@tonic-gate 		v = E_BAD_ARGUMENT;
205*7c478bd9Sstevel@tonic-gate 
206*7c478bd9Sstevel@tonic-gate 	return (v);
207*7c478bd9Sstevel@tonic-gate }
208*7c478bd9Sstevel@tonic-gate 
209*7c478bd9Sstevel@tonic-gate static REQUEST
parse(int c)210*7c478bd9Sstevel@tonic-gate parse(int c)
211*7c478bd9Sstevel@tonic-gate {
212*7c478bd9Sstevel@tonic-gate 	if (c < MIN_FORM_COMMAND || c > MAX_FORM_COMMAND)
213*7c478bd9Sstevel@tonic-gate 		return (FAIL);
214*7c478bd9Sstevel@tonic-gate 
215*7c478bd9Sstevel@tonic-gate 	return (carray[c - MIN_FORM_COMMAND]);
216*7c478bd9Sstevel@tonic-gate }
217