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