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