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