xref: /titanic_41/usr/src/lib/libeti/form/common/driver.c (revision c2580b931007758eab8cb5ae8726ebe1588e259b)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1988 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 /*
27  *      Copyright (c) 1997, by Sun Microsystems, Inc.
28  *      All rights reserved.
29  */
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI" /* SVr4.0 1.4 */
32 
33 /*LINTLIBRARY*/
34 
35 #include <sys/types.h>
36 #include "utility.h"
37 
38 typedef struct {
39 	PTF_int		class;
40 	PTF_int		act;
41 } REQUEST;
42 
43 static REQUEST parse(int);
44 
45 #define	COMMAND(x)	(x.class)
46 #define	CALL(x, f)	(x.class ? (*x.class) (x.act, f) : E_SYSTEM_ERROR)
47 
48 /* command array(carray) order is significant(see form.h REQ_*) */
49 static REQUEST carray [MAX_FORM_COMMAND - MIN_FORM_COMMAND + 1] =
50 {
51 	_page_navigation,	_next_page,	/* REQ_NEXT_PAGE	*/
52 	_page_navigation,	_prev_page,	/* REQ_PREV_PAGE	*/
53 	_page_navigation,	_first_page,	/* REQ_FIRST_PAGE	*/
54 	_page_navigation,	_last_page,	/* REQ_LAST_PAGE	*/
55 
56 	_field_navigation,	_next_field,	/* REQ_NEXT_FIELD	*/
57 	_field_navigation,	_prev_field,	/* REQ_PREV_FIELD	*/
58 	_field_navigation,	_first_field,	/* REQ_FIRST_FIELD	*/
59 	_field_navigation,	_last_field,	/* REQ_LAST_FIELD	*/
60 	_field_navigation,	_snext_field,	/* REQ_SNEXT_FIELD	*/
61 	_field_navigation,	_sprev_field,	/* REQ_SPREV_FIELD	*/
62 	_field_navigation,	_sfirst_field,	/* REQ_SFIRST_FIELD	*/
63 	_field_navigation,	_slast_field,	/* REQ_SLAST_FIELD	*/
64 	_field_navigation,	_left_field,	/* REQ_LEFT_FIELD	*/
65 	_field_navigation,	_right_field,	/* REQ_RIGHT_FIELD	*/
66 	_field_navigation,	_up_field,	/* REQ_UP_FIELD		*/
67 	_field_navigation,	_down_field,	/* REQ_DOWN_FIELD	*/
68 
69 	_data_navigation,	_next_char,	/* REQ_NEXT_CHAR	*/
70 	_data_navigation,	_prev_char,	/* REQ_PREV_CHAR	*/
71 	_data_navigation,	_next_line,	/* REQ_NEXT_LINE	*/
72 	_data_navigation,	_prev_line,	/* REQ_PREV_LINE	*/
73 	_data_navigation,	_next_word,	/* REQ_NEXT_WORD	*/
74 	_data_navigation,	_prev_word,	/* REQ_PREV_WORD	*/
75 	_data_navigation,	_beg_field,	/* REQ_BEG_FIELD	*/
76 	_data_navigation,	_end_field,	/* REQ_END_FIELD	*/
77 	_data_navigation,	_beg_line,	/* REQ_BEG_LINE		*/
78 	_data_navigation,	_end_line,	/* REQ_END_LINE		*/
79 	_data_navigation,	_left_char,	/* REQ_LEFT_CHAR	*/
80 	_data_navigation,	_right_char,	/* REQ_RIGHT_CHAR	*/
81 	_data_navigation,	_up_char,	/* REQ_UP_CHAR		*/
82 	_data_navigation,	_down_char,	/* REQ_DOWN_CHAR	*/
83 
84 	_misc_request,		_new_line,	/* REQ_NEW_LINE		*/
85 	_data_manipulation,	_ins_char,	/* REQ_INS_CHAR		*/
86 	_data_manipulation,	_ins_line,	/* REQ_INS_LINE		*/
87 	_data_manipulation,	_del_char,	/* REQ_DEL_CHAR		*/
88 	_misc_request,		_del_prev,	/* REQ_DEL_PREV		*/
89 	_data_manipulation,	_del_line,	/* REQ_DEL_LINE		*/
90 	_data_manipulation,	_del_word,	/* REQ_DEL_WORD		*/
91 	_data_manipulation,	_clr_eol,	/* REQ_CLR_EOL		*/
92 	_data_manipulation,	_clr_eof,	/* REQ_CLR_EOF		*/
93 	_data_manipulation,	_clr_field,	/* REQ_CLR_FIELD	*/
94 
95 	_misc_request,		_ovl_mode,	/* REQ_OVL_MODE		*/
96 	_misc_request,		_ins_mode,	/* REQ_INS_MODE		*/
97 
98 	_data_navigation,	_scr_fline,	/* REQ_SCR_FLINE	*/
99 	_data_navigation,	_scr_bline,	/* REQ_SCR_BLINE	*/
100 	_data_navigation,	_scr_fpage,	/* REQ_SCR_FPAGE	*/
101 	_data_navigation,	_scr_bpage,	/* REQ_SCR_BPAGE	*/
102 	_data_navigation,	_scr_fhpage,	/* REQ_SCR_FHPAGE	*/
103 	_data_navigation,	_scr_bhpage,	/* REQ_SCR_BHPAGE	*/
104 
105 	_data_navigation,	_scr_fchar,	/* REQ_SCR_FCHAR	*/
106 	_data_navigation,	_scr_bchar,	/* REQ_SCR_BCHAR	*/
107 	_data_navigation,	_scr_hfline,	/* REQ_SCR_HFLINE	*/
108 	_data_navigation,	_scr_hbline,	/* REQ_SCR_HBLINE	*/
109 	_data_navigation,	_scr_hfhalf,	/* REQ_SCR_HFHALF	*/
110 	_data_navigation,	_scr_hbhalf,	/* REQ_SCR_HBHALF	*/
111 
112 	_misc_request,		_validation,	/* REQ_VALIDATION	*/
113 	_misc_request,		_next_choice,	/* REQ_NEXT_CHOICE	*/
114 	_misc_request,		_prev_choice,	/* REQ_PREV_CHOICE	*/
115 };
116 
117 static REQUEST FAIL = { (PTF_int) 0, (PTF_int) 0 };
118 
119 /* _page_navigation - service page navigation request */
120 int
121 _page_navigation(PTF_int act, FORM *f)
122 {
123 	int v;
124 
125 	if (_validate(f)) {
126 		term_field(f);
127 		term_form(f);
128 		v = (*act) (f);
129 		init_form(f);
130 		init_field(f);
131 	} else
132 		v = E_INVALID_FIELD;
133 
134 	return (v);
135 }
136 
137 /* _field_navigation - service inter-field navigation request */
138 int
139 _field_navigation(PTF_int act, FORM *f)
140 {
141 	int v;
142 
143 	if (_validate(f)) {
144 		term_field(f);
145 		v = (*act) (f);
146 		init_field(f);
147 	} else
148 		v = E_INVALID_FIELD;
149 
150 	return (v);
151 }
152 
153 /* _data_navigation - service intra-field navagation request */
154 int
155 _data_navigation(PTF_int act, FORM *f)
156 {
157 	return ((*act) (f));
158 }
159 
160 /* _data_manipulation - service data modification request */
161 int
162 _data_manipulation(PTF_int act, FORM *f)
163 {
164 	int		v = E_REQUEST_DENIED;
165 	FIELD *		c = C(f);
166 
167 	if (Opt(c, O_EDIT))
168 		if ((v = (*act) (f)) == E_OK)
169 			Set(f, WIN_CHG);
170 	return (v);
171 }
172 
173 int
174 _misc_request(PTF_int act, FORM *f)
175 {
176 	return ((*act) (f));
177 }
178 
179 int
180 form_driver(FORM *f, int c)
181 {
182 	int		v;
183 	REQUEST		x;
184 
185 	if (f) {
186 		if (Status(f, DRIVER))
187 
188 			v = E_BAD_STATE;
189 
190 		else if (Status(f, POSTED)) {
191 			x = parse(c);
192 
193 			if (COMMAND(x))
194 				v = CALL(x, f);
195 			else {
196 				if (isascii(c) && isprint(c) &&
197 				    CheckChar(C(f), c))
198 					v = _data_entry(f, c);
199 				else
200 					v = E_UNKNOWN_COMMAND;
201 			}
202 			(void) _update_current(f);
203 		} else
204 			v = E_NOT_POSTED;
205 	} else
206 		v = E_BAD_ARGUMENT;
207 
208 	return (v);
209 }
210 
211 static REQUEST
212 parse(int c)
213 {
214 	if (c < MIN_FORM_COMMAND || c > MAX_FORM_COMMAND)
215 		return (FAIL);
216 
217 	return (carray[c - MIN_FORM_COMMAND]);
218 }
219