2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/* Copyright (c) 1988 AT&T */
2N/A/* All Rights Reserved */
2N/A
2N/A
2N/A/*
2N/A * Copyright (c) 1990, 2004, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#ifndef _UTILITY_H
2N/A#define _UTILITY_H
2N/A
2N/A#include <form.h>
2N/A#include <memory.h>
2N/A#include <string.h>
2N/A#include <ctype.h>
2N/A#include <stdarg.h>
2N/A#include <sys/types.h>
2N/A
2N/A#ifdef __cplusplus
2N/Aextern "C" {
2N/A#endif
2N/A
2N/A/* miscellaneous #defines */
2N/Atypedef int BOOLEAN;
2N/A
2N/A#define MIN(x, y) ((x) < (y) ? (x) : (y))
2N/A
2N/A/* form status flags */
2N/A#define POSTED 0x0001 /* posted flag */
2N/A#define DRIVER 0x0002 /* inside init/term routine */
2N/A#define OVERLAY 0x0004 /* insert/overlay mode */
2N/A#define WIN_CHG 0x0010 /* window change (system flag) */
2N/A#define BUF_CHG 0x0020 /* buffer change (system flag) */
2N/A/* field status flags */
2N/A#define USR_CHG 0x0001 /* buffer change (user's flag) */
2N/A#define TOP_CHG 0x0002 /* toprow change (system flag) */
2N/A#define NEW_PAGE 0x0004 /* new page (system flag) */
2N/A#define GROWABLE 0x0008 /* growable page (system flag) */
2N/A/* field type status flags */
2N/A#define LINKED 0x0001 /* conjunctive field type */
2N/A#define ARGS 0x0002 /* has additional arguments */
2N/A#define CHOICE 0x0004 /* has choice functions */
2N/A/* form/field/fieldtype status manipulation macros */
2N/A#define Status(f, s) ((f) -> status & (s))
2N/A#define Set(f, s) ((f) -> status |= (s))
2N/A#define Clr(f, s) ((f) -> status &= ~(s))
2N/A/* form/field option manipulation macros */
2N/A#define Opt(f, x) ((f) -> opts & (x))
2N/A/* alloc/free with check */
2N/A#define Alloc(x, t) ((x = (t *) malloc(sizeof (t))) != (t *)0)
2N/A#define arrayAlloc(x, n, t) ((x = (t *) malloc((n) * sizeof (t))) != \
2N/A (t *)0)
2N/A#define Free(x) { if (x) free(x); }
2N/A/* field type macros */
2N/A#define MakeArg(f, p, err) (_makearg((f) -> type, p, err))
2N/A#define CopyArg(f, err) (_copyarg((f) -> type, (f) -> arg, err))
2N/A#define FreeArg(f) (_freearg((f) -> type, (f) -> arg))
2N/A#define CheckField(f) (_checkfield((f) -> type, (f), (f) -> arg))
2N/A#define CheckChar(f, c) (_checkchar((f) -> type, (c), (f) -> arg))
2N/A#define NextChoice(f) (_nextchoice((f) -> type, (f), (f) -> arg))
2N/A#define PrevChoice(f) (_prevchoice((f) -> type, (f), (f) -> arg))
2N/A#define IncrType(type) { if (type) ++(type -> ref); }
2N/A#define DecrType(type) { if (type) --(type -> ref); }
2N/A/* form/field init/term calls */
2N/A#define init_field(f) { \
2N/A if ((f) -> fieldinit) \
2N/A { \
2N/A Set(f, DRIVER); \
2N/A (*(f) -> fieldinit)(f); \
2N/A Clr(f, DRIVER); \
2N/A } \
2N/A }
2N/A#define term_field(f) { \
2N/A if ((f) -> fieldterm) \
2N/A { \
2N/A Set(f, DRIVER); \
2N/A (*(f) -> fieldterm)(f); \
2N/A Clr(f, DRIVER); \
2N/A } \
2N/A }
2N/A#define init_form(f) { \
2N/A if ((f) -> forminit) \
2N/A { \
2N/A Set(f, DRIVER); \
2N/A (*(f) -> forminit)(f); \
2N/A Clr(f, DRIVER); \
2N/A } \
2N/A }
2N/A#define term_form(f) { \
2N/A if ((f) -> formterm) \
2N/A { \
2N/A Set(f, DRIVER); \
2N/A (*(f) -> formterm)(f); \
2N/A Clr(f, DRIVER); \
2N/A } \
2N/A }
2N/A/* page macros */
2N/A#define P(f) ((f) -> curpage)
2N/A#define Pmin(f, p) ((f) -> page [p].pmin)
2N/A#define Pmax(f, p) ((f) -> page [p].pmax)
2N/A#define Smin(f, p) ((f) -> page [p].smin)
2N/A#define Smax(f, p) ((f) -> page [p].smax)
2N/A/* form macros */
2N/A#define Form(f) ((f) ? (f) : _DEFAULT_FORM)
2N/A#define ValidIndex(f, i) ((i) >= 0 && (i) < (f) -> maxfield)
2N/A#define ValidPage(f, i) ((i) >= 0 && (i) < (f) -> maxpage)
2N/A#define C(f) ((f) -> current)
2N/A#define W(f) ((f) -> w)
2N/A#define X(f) ((f) -> curcol)
2N/A#define Y(f) ((f) -> currow)
2N/A#define T(f) ((f) -> toprow)
2N/A#define B(f) ((f) -> begincol)
2N/A#define Xmax(f) (C(f) -> dcols)
2N/A#define Ymax(f) (C(f) -> drows)
2N/A#define Win(f) ((f) -> win ? (f) -> win : stdscr)
2N/A#define Sub(f) ((f) -> sub ? (f) -> sub : Win(f))
2N/A/* field macros */
2N/A#define Field(f) ((f) ? (f) : _DEFAULT_FIELD)
2N/A#define Buf(f) ((f) -> buf)
2N/A#define OneRow(f) ((f)->rows + (f)->nrow == 1)
2N/A#define GrowSize(f) (((f) -> rows + (f) -> nrow) * (f) -> cols)
2N/A#define BufSize(f) ((f) -> drows * (f) -> dcols)
2N/A#define Buffer(f, n) (Buf(f) + (n) * (BufSize(f) + 1))
2N/A#define LineBuf(f, n) (Buf(f) + (n) * (f) -> dcols)
2N/A#define TotalBuf(f) ((BufSize(f) + 1) * ((f) -> nbuf + 1))
2N/A#define Just(f) ((f) -> just)
2N/A#define Fore(f) ((f) -> fore)
2N/A#define Back(f) ((f) -> back)
2N/A#define Pad(f) ((f) -> pad)
2N/A/* system externs */
2N/Aextern int _next_page(FORM *); /* REQ_NEXT_PAGE */
2N/Aextern int _prev_page(FORM *); /* REQ_PREV_PAGE */
2N/Aextern int _first_page(FORM *); /* REQ_FIRST_PAGE */
2N/Aextern int _last_page(FORM *); /* REQ_LAST_PAGE */
2N/A
2N/Aextern int _next_field(FORM *); /* REQ_NEXT_FIELD */
2N/Aextern int _prev_field(FORM *); /* REQ_PREV_FIELD */
2N/Aextern int _first_field(FORM *); /* REQ_FIRST_FIELD */
2N/Aextern int _last_field(FORM *); /* REQ_LAST_FIELD */
2N/Aextern int _snext_field(FORM *); /* REQ_SNEXT_FIELD */
2N/Aextern int _sprev_field(FORM *); /* REQ_SPREV_FIELD */
2N/Aextern int _sfirst_field(FORM *); /* REQ_SFIRST_FIELD */
2N/Aextern int _slast_field(FORM *); /* REQ_SLAST_FIELD */
2N/Aextern int _left_field(FORM *); /* REQ_LEFT_FIELD */
2N/Aextern int _right_field(FORM *); /* REQ_RIGHT_FIELD */
2N/Aextern int _up_field(FORM *); /* REQ_UP_FIELD */
2N/Aextern int _down_field(FORM *); /* REQ_DOWN_FIELD */
2N/A
2N/Aextern int _next_char(FORM *); /* REQ_NEXT_CHAR */
2N/Aextern int _prev_char(FORM *); /* REQ_PREV_CHAR */
2N/Aextern int _next_line(FORM *); /* REQ_NEXT_LINE */
2N/Aextern int _prev_line(FORM *); /* REQ_PREV_LINE */
2N/Aextern int _next_word(FORM *); /* REQ_NEXT_WORD */
2N/Aextern int _prev_word(FORM *); /* REQ_PREV_WORD */
2N/Aextern int _beg_field(FORM *); /* REQ_BEG_FIELD */
2N/Aextern int _end_field(FORM *); /* REQ_END_FIELD */
2N/Aextern int _beg_line(FORM *); /* REQ_BEG_LINE */
2N/Aextern int _end_line(FORM *); /* REQ_END_LINE */
2N/Aextern int _left_char(FORM *); /* REQ_LEFT_CHAR */
2N/Aextern int _right_char(FORM *); /* REQ_RIGHT_CHAR */
2N/Aextern int _up_char(FORM *); /* REQ_UP_CHAR */
2N/Aextern int _down_char(FORM *); /* REQ_DOWN_CHAR */
2N/A
2N/Aextern int _new_line(FORM *); /* REQ_NEW_LINE */
2N/Aextern int _ins_char(FORM *); /* REQ_INS_CHAR */
2N/Aextern int _ins_line(FORM *); /* REQ_INS_LINE */
2N/Aextern int _del_char(FORM *); /* REQ_DEL_CHAR */
2N/Aextern int _del_prev(FORM *); /* REQ_DEL_PREV */
2N/Aextern int _del_line(FORM *); /* REQ_DEL_LINE */
2N/Aextern int _del_word(FORM *); /* REQ_DEL_WORD */
2N/Aextern int _clr_eol(FORM *); /* REQ_CLR_EOL */
2N/Aextern int _clr_eof(FORM *); /* REQ_CLR_EOF */
2N/Aextern int _clr_field(FORM *); /* REQ_CLR_FIELD */
2N/Aextern int _ovl_mode(FORM *); /* REQ_OVL_MODE */
2N/Aextern int _ins_mode(FORM *); /* REQ_INS_MODE */
2N/Aextern int _scr_fline(FORM *); /* REQ_SCR_FLINE */
2N/Aextern int _scr_bline(FORM *); /* REQ_SCR_BLINE */
2N/Aextern int _scr_fpage(FORM *); /* REQ_SCR_FPAGE */
2N/Aextern int _scr_fhpage(FORM *); /* REQ_SCR_FHPAGE */
2N/Aextern int _scr_bpage(FORM *); /* REQ_SCR_BPAGE */
2N/Aextern int _scr_bhpage(FORM *); /* REQ_SCR_BHPAGE */
2N/A
2N/Aextern int _scr_fchar(FORM *); /* REQ_SCR_FCHAR */
2N/Aextern int _scr_bchar(FORM *); /* REQ_SCR_BCHAR */
2N/Aextern int _scr_hfline(FORM *); /* REQ_SCR_HFLINE */
2N/Aextern int _scr_hbline(FORM *); /* REQ_SCR_HBLINE */
2N/Aextern int _scr_hfhalf(FORM *); /* REQ_SCR_HFHALF */
2N/Aextern int _scr_hbhalf(FORM *); /* REQ_SCR_HBHALF */
2N/A
2N/Aextern int _validation(FORM *); /* REQ_VALIDATION */
2N/Aextern int _next_choice(FORM *); /* REQ_NEXT_CHOICE */
2N/Aextern int _prev_choice(FORM *); /* REQ_PREV_CHOICE */
2N/A
2N/Aextern char * _makearg(FIELDTYPE *, va_list *, int *);
2N/Aextern char * _copyarg(FIELDTYPE *, char *, int *);
2N/Aextern void _freearg(FIELDTYPE *, char *);
2N/Aextern int _checkfield(FIELDTYPE *, FIELD *, char *);
2N/Aextern int _checkchar(FIELDTYPE *, int, char *);
2N/Aextern int _nextchoice(FIELDTYPE *, FIELD *, char *);
2N/Aextern int _prevchoice(FIELDTYPE *, FIELD *, char *);
2N/A
2N/Aextern BOOLEAN _grow_field(FIELD *, int);
2N/Aextern FIELD * _first_active(FORM *);
2N/Aextern char * _data_beg(char *, int);
2N/Aextern char * _data_end(char *, int);
2N/Aextern char * _whsp_beg(char *, int);
2N/Aextern char * _whsp_end(char *, int);
2N/Aextern void _buf_to_win(FIELD *, WINDOW *);
2N/Aextern void _win_to_buf(WINDOW *, FIELD *);
2N/Aextern void _adjust_cursor(FORM *, char *);
2N/Aextern void _sync_buffer(FORM *);
2N/Aextern int _sync_linked(FIELD *);
2N/Aextern int _sync_field(FIELD *);
2N/Aextern int _sync_attrs(FIELD *);
2N/Aextern int _sync_opts(FIELD *, OPTIONS);
2N/Aextern int _validate(FORM *);
2N/Aextern int _set_current_field(FORM *, FIELD *);
2N/Aextern int _set_form_page(FORM *, int, FIELD *);
2N/Aextern int _pos_form_cursor(FORM *);
2N/Aextern int _update_current(FORM *);
2N/Aextern int _data_entry(FORM *, int);
2N/Aextern int _page_navigation(PTF_int, FORM *);
2N/Aextern int _field_navigation(PTF_int, FORM *);
2N/Aextern int _data_navigation(PTF_int, FORM *);
2N/Aextern int _data_manipulation(PTF_int, FORM *);
2N/Aextern int _misc_request(PTF_int, FORM *);
2N/A
2N/Aextern intptr_t __execute(char *, char *);
2N/Aextern intptr_t __advance(char *, char *);
2N/Aextern intptr_t __xpop(intptr_t);
2N/Aextern intptr_t __xpush(intptr_t, char *);
2N/Aextern intptr_t __getrnge(intptr_t *, intptr_t *, char *);
2N/Aextern intptr_t __cclass(char *, char, intptr_t);
2N/Aextern int __size(char *);
2N/Aextern int __rpush(char *);
2N/Aextern intptr_t __rpop(void);
2N/A
2N/A#ifdef __cplusplus
2N/A}
2N/A#endif
2N/A
2N/A#endif /* _UTILITY_H */