xref: /illumos-gate/usr/src/lib/libeti/form/inc/utility.h (revision 1da57d551424de5a9d469760be7c4b4d4f10a755)
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 2004 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 #ifndef	_UTILITY_H
32 #define	_UTILITY_H
33 
34 #include <form.h>
35 #include <memory.h>
36 #include <string.h>
37 #include <ctype.h>
38 #include <stdarg.h>
39 #include <sys/types.h>
40 
41 #ifdef	__cplusplus
42 extern "C" {
43 #endif
44 
45 /* miscellaneous #defines */
46 typedef	int		BOOLEAN;
47 
48 #define	MIN(x, y)		((x) < (y) ? (x) : (y))
49 
50 /* form status flags */
51 #define	POSTED			0x0001	/* posted flag			*/
52 #define	DRIVER			0x0002	/* inside init/term routine	*/
53 #define	OVERLAY			0x0004	/* insert/overlay mode		*/
54 #define	WIN_CHG			0x0010	/* window change (system flag)	*/
55 #define	BUF_CHG			0x0020	/* buffer change (system flag)	*/
56 /* field status flags */
57 #define	USR_CHG			0x0001	/* buffer change (user's flag)	*/
58 #define	TOP_CHG			0x0002	/* toprow change (system flag)	*/
59 #define	NEW_PAGE		0x0004	/* new page (system flag)	*/
60 #define	GROWABLE		0x0008	/* growable page (system flag)	*/
61 /* field type status flags */
62 #define	LINKED			0x0001	/* conjunctive field type	*/
63 #define	ARGS			0x0002	/* has additional arguments	*/
64 #define	CHOICE			0x0004	/* has choice functions		*/
65 /* form/field/fieldtype status manipulation macros */
66 #define	Status(f, s)		((f) -> status & (s))
67 #define	Set(f, s)		((f) -> status |= (s))
68 #define	Clr(f, s)		((f) -> status &= ~(s))
69 /* form/field option manipulation macros */
70 #define	Opt(f, x)		((f) -> opts & (x))
71 /* alloc/free with check */
72 #define	Alloc(x, t)		((x = (t *) malloc(sizeof (t))) != (t *)0)
73 #define	arrayAlloc(x, n, t)	((x = (t *) malloc((n) * sizeof (t))) != \
74 				(t *)0)
75 #define	Free(x)			{ if (x) free(x); }
76 /* field type macros */
77 #define	MakeArg(f, p, err)	(_makearg((f) -> type, p, err))
78 #define	CopyArg(f, err)		(_copyarg((f) -> type, (f) -> arg, err))
79 #define	FreeArg(f)		(_freearg((f) -> type, (f) -> arg))
80 #define	CheckField(f)		(_checkfield((f) -> type, (f), (f) -> arg))
81 #define	CheckChar(f, c)		(_checkchar((f) -> type, (c), (f) -> arg))
82 #define	NextChoice(f)		(_nextchoice((f) -> type, (f), (f) -> arg))
83 #define	PrevChoice(f)		(_prevchoice((f) -> type, (f), (f) -> arg))
84 #define	IncrType(type)		{ if (type) ++(type -> ref); }
85 #define	DecrType(type)		{ if (type) --(type -> ref); }
86 /* form/field init/term calls */
87 #define	init_field(f)		{					\
88 					if ((f) -> fieldinit)		\
89 					{				\
90 						Set(f, DRIVER);	\
91 						(*(f) -> fieldinit)(f);	\
92 						Clr(f, DRIVER);	\
93 					}				\
94 				}
95 #define	term_field(f)		{					\
96 					if ((f) -> fieldterm)		\
97 					{				\
98 						Set(f, DRIVER);	\
99 						(*(f) -> fieldterm)(f);	\
100 						Clr(f, DRIVER);	\
101 					}				\
102 				}
103 #define	init_form(f)		{					\
104 					if ((f) -> forminit)		\
105 					{				\
106 						Set(f, DRIVER);	\
107 						(*(f) -> forminit)(f);	\
108 						Clr(f, DRIVER);	\
109 					}				\
110 				}
111 #define	term_form(f)		{					\
112 					if ((f) -> formterm)		\
113 					{				\
114 						Set(f, DRIVER);	\
115 						(*(f) -> formterm)(f);	\
116 						Clr(f, DRIVER);	\
117 					}				\
118 				}
119 /* page macros */
120 #define	P(f)			((f) -> curpage)
121 #define	Pmin(f, p)		((f) -> page [p].pmin)
122 #define	Pmax(f, p)		((f) -> page [p].pmax)
123 #define	Smin(f,	p)		((f) -> page [p].smin)
124 #define	Smax(f, p)		((f) -> page [p].smax)
125 /* form macros */
126 #define	Form(f)			((f) ? (f) : _DEFAULT_FORM)
127 #define	ValidIndex(f, i)	((i) >= 0 && (i) < (f) -> maxfield)
128 #define	ValidPage(f, i)		((i) >= 0 && (i) < (f) -> maxpage)
129 #define	C(f)			((f) -> current)
130 #define	W(f)			((f) -> w)
131 #define	X(f)			((f) -> curcol)
132 #define	Y(f)			((f) -> currow)
133 #define	T(f)			((f) -> toprow)
134 #define	B(f)			((f) -> begincol)
135 #define	Xmax(f)			(C(f) -> dcols)
136 #define	Ymax(f)			(C(f) -> drows)
137 #define	Win(f)			((f) -> win ? (f) -> win : stdscr)
138 #define	Sub(f)			((f) -> sub ? (f) -> sub : Win(f))
139 /* field macros */
140 #define	Field(f)		((f) ? (f) : _DEFAULT_FIELD)
141 #define	Buf(f)			((f) -> buf)
142 #define	OneRow(f)		((f)->rows + (f)->nrow == 1)
143 #define	GrowSize(f)		(((f) -> rows + (f) -> nrow) * (f) -> cols)
144 #define	BufSize(f)		((f) -> drows  * (f) -> dcols)
145 #define	Buffer(f, n)		(Buf(f) + (n) * (BufSize(f) + 1))
146 #define	LineBuf(f, n)		(Buf(f) + (n) * (f) -> dcols)
147 #define	TotalBuf(f)		((BufSize(f) + 1) * ((f) -> nbuf + 1))
148 #define	Just(f)			((f) -> just)
149 #define	Fore(f)			((f) -> fore)
150 #define	Back(f)			((f) -> back)
151 #define	Pad(f)			((f) -> pad)
152 /* system externs */
153 extern int	_next_page(FORM *);		/* REQ_NEXT_PAGE	*/
154 extern int	_prev_page(FORM *);		/* REQ_PREV_PAGE	*/
155 extern int	_first_page(FORM *);		/* REQ_FIRST_PAGE	*/
156 extern int	_last_page(FORM *);		/* REQ_LAST_PAGE	*/
157 
158 extern int	_next_field(FORM *);		/* REQ_NEXT_FIELD	*/
159 extern int	_prev_field(FORM *);		/* REQ_PREV_FIELD	*/
160 extern int	_first_field(FORM *);		/* REQ_FIRST_FIELD	*/
161 extern int	_last_field(FORM *);		/* REQ_LAST_FIELD	*/
162 extern int	_snext_field(FORM *);		/* REQ_SNEXT_FIELD	*/
163 extern int	_sprev_field(FORM *);		/* REQ_SPREV_FIELD	*/
164 extern int	_sfirst_field(FORM *);		/* REQ_SFIRST_FIELD	*/
165 extern int	_slast_field(FORM *);		/* REQ_SLAST_FIELD	*/
166 extern int	_left_field(FORM *);		/* REQ_LEFT_FIELD	*/
167 extern int	_right_field(FORM *);		/* REQ_RIGHT_FIELD	*/
168 extern int	_up_field(FORM *);		/* REQ_UP_FIELD		*/
169 extern int	_down_field(FORM *);		/* REQ_DOWN_FIELD	*/
170 
171 extern int	_next_char(FORM *);		/* REQ_NEXT_CHAR	*/
172 extern int	_prev_char(FORM *);		/* REQ_PREV_CHAR	*/
173 extern int	_next_line(FORM *);		/* REQ_NEXT_LINE	*/
174 extern int	_prev_line(FORM *);		/* REQ_PREV_LINE	*/
175 extern int	_next_word(FORM *);		/* REQ_NEXT_WORD	*/
176 extern int	_prev_word(FORM *);		/* REQ_PREV_WORD	*/
177 extern int	_beg_field(FORM *);		/* REQ_BEG_FIELD	*/
178 extern int	_end_field(FORM *);		/* REQ_END_FIELD	*/
179 extern int	_beg_line(FORM *);		/* REQ_BEG_LINE		*/
180 extern int	_end_line(FORM *);		/* REQ_END_LINE		*/
181 extern int	_left_char(FORM *);		/* REQ_LEFT_CHAR	*/
182 extern int	_right_char(FORM *);		/* REQ_RIGHT_CHAR	*/
183 extern int	_up_char(FORM *);		/* REQ_UP_CHAR		*/
184 extern int	_down_char(FORM *);		/* REQ_DOWN_CHAR	*/
185 
186 extern int	_new_line(FORM *);		/* REQ_NEW_LINE		*/
187 extern int	_ins_char(FORM *);		/* REQ_INS_CHAR		*/
188 extern int	_ins_line(FORM *);		/* REQ_INS_LINE		*/
189 extern int	_del_char(FORM *);		/* REQ_DEL_CHAR		*/
190 extern int	_del_prev(FORM *);		/* REQ_DEL_PREV		*/
191 extern int	_del_line(FORM *);		/* REQ_DEL_LINE		*/
192 extern int	_del_word(FORM *);		/* REQ_DEL_WORD		*/
193 extern int	_clr_eol(FORM *);		/* REQ_CLR_EOL		*/
194 extern int	_clr_eof(FORM *);		/* REQ_CLR_EOF		*/
195 extern int	_clr_field(FORM *);		/* REQ_CLR_FIELD	*/
196 extern int	_ovl_mode(FORM *);		/* REQ_OVL_MODE		*/
197 extern int	_ins_mode(FORM *);		/* REQ_INS_MODE		*/
198 extern int	_scr_fline(FORM *);		/* REQ_SCR_FLINE	*/
199 extern int	_scr_bline(FORM *);		/* REQ_SCR_BLINE	*/
200 extern int	_scr_fpage(FORM *);		/* REQ_SCR_FPAGE	*/
201 extern int	_scr_fhpage(FORM *);		/* REQ_SCR_FHPAGE	*/
202 extern int	_scr_bpage(FORM *);		/* REQ_SCR_BPAGE	*/
203 extern int	_scr_bhpage(FORM *);		/* REQ_SCR_BHPAGE	*/
204 
205 extern int	_scr_fchar(FORM *);		/* REQ_SCR_FCHAR	*/
206 extern int	_scr_bchar(FORM *);		/* REQ_SCR_BCHAR	*/
207 extern int	_scr_hfline(FORM *);		/* REQ_SCR_HFLINE	*/
208 extern int	_scr_hbline(FORM *);		/* REQ_SCR_HBLINE	*/
209 extern int	_scr_hfhalf(FORM *);		/* REQ_SCR_HFHALF	*/
210 extern int	_scr_hbhalf(FORM *);		/* REQ_SCR_HBHALF	*/
211 
212 extern int	_validation(FORM *);		/* REQ_VALIDATION	*/
213 extern int	_next_choice(FORM *);		/* REQ_NEXT_CHOICE	*/
214 extern int	_prev_choice(FORM *);		/* REQ_PREV_CHOICE	*/
215 
216 extern char *	_makearg(FIELDTYPE *, va_list *, int *);
217 extern char *	_copyarg(FIELDTYPE *, char *, int *);
218 extern void	_freearg(FIELDTYPE *,  char *);
219 extern int	_checkfield(FIELDTYPE *, FIELD *, char *);
220 extern int	_checkchar(FIELDTYPE *, int, char *);
221 extern int	_nextchoice(FIELDTYPE *, FIELD *, char *);
222 extern int	_prevchoice(FIELDTYPE *, FIELD *, char *);
223 
224 extern BOOLEAN	_grow_field(FIELD *, int);
225 extern FIELD *	_first_active(FORM *);
226 extern char *	_data_beg(char *, int);
227 extern char *	_data_end(char *, int);
228 extern char *	_whsp_beg(char *, int);
229 extern char *	_whsp_end(char *, int);
230 extern void	_buf_to_win(FIELD *, WINDOW *);
231 extern void	_win_to_buf(WINDOW *, FIELD *);
232 extern void	_adjust_cursor(FORM *, char *);
233 extern void	_sync_buffer(FORM *);
234 extern int	_sync_linked(FIELD *);
235 extern int	_sync_field(FIELD *);
236 extern int	_sync_attrs(FIELD *);
237 extern int	_sync_opts(FIELD *, OPTIONS);
238 extern int	_validate(FORM *);
239 extern int	_set_current_field(FORM *, FIELD *);
240 extern int	_set_form_page(FORM *, int, FIELD *);
241 extern int	_pos_form_cursor(FORM *);
242 extern int	_update_current(FORM *);
243 extern int	_data_entry(FORM *, int);
244 extern int	_page_navigation(PTF_int, FORM *);
245 extern int	_field_navigation(PTF_int, FORM *);
246 extern int	_data_navigation(PTF_int, FORM *);
247 extern int	_data_manipulation(PTF_int, FORM *);
248 extern int	_misc_request(PTF_int, FORM *);
249 
250 extern intptr_t	__execute(char *, char *);
251 extern intptr_t	__advance(char *, char *);
252 extern intptr_t	__xpop(intptr_t);
253 extern intptr_t	__xpush(intptr_t, char *);
254 extern intptr_t	__getrnge(intptr_t *, intptr_t *, char *);
255 extern intptr_t	__cclass(char *, char, intptr_t);
256 extern int	__size(char *);
257 extern int	__rpush(char *);
258 extern intptr_t	__rpop(void);
259 
260 #ifdef	__cplusplus
261 }
262 #endif
263 
264 #endif	/* _UTILITY_H */
265