# # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License, Version 1.0 only # (the "License"). You may not use this file except in compliance # with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright (c) 1989 by Sun Microsystems, Inc. # # include global definitions include ../../Makefile.master SUBDIRS= form menu panel HDRSUBDIRS= form menu panel all: TARGET= all clean: TARGET= clean clobber: TARGET= clobber install: TARGET= install install_h: TARGET= install_h check: TARGET= check # definitions for install_h target HDRS= eti.h ROOTHDRDIR= $(ROOT)/usr/include ROOTHDRS= $(HDRS:%=$(ROOTHDRDIR)/%) CHECKHDRS= $(HDRS:%.h=%.check) # install rule for install_h target $(ROOTHDRDIR)/%: % $(INS.file) .KEEP_STATE: all clean clobber install: $(SUBDIRS) install_h: $(ROOTHDRS) $(HDRSUBDIRS) check: $(CHECKHDRS) $(HDRSUBDIRS) xxx: @cd form; pwd; $(MAKE) $(TARGET) @cd menu; pwd; $(MAKE) $(TARGET) @cd panel; pwd; $(MAKE) $(TARGET) $(SUBDIRS): FRC @cd $@; pwd; $(MAKE) $(TARGET) FRC: /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ #ifndef _ETI_H #define _ETI_H #ifdef __cplusplus extern "C" { #endif #define MAX_COMMAND (KEY_MAX + 512) typedef int OPTIONS; typedef char * (* PTF_charP) (); typedef void (* PTF_void) (); typedef int (* PTF_int) (); #define E_OK 0 #define E_SYSTEM_ERROR -1 #define E_BAD_ARGUMENT -2 #define E_POSTED -3 #define E_CONNECTED -4 #define E_BAD_STATE -5 #define E_NO_ROOM -6 #define E_NOT_POSTED -7 #define E_UNKNOWN_COMMAND -8 #define E_NO_MATCH -9 #define E_NOT_SELECTABLE -10 #define E_NOT_CONNECTED -11 #define E_REQUEST_DENIED -12 #define E_INVALID_FIELD -13 #define E_CURRENT -14 #ifdef __cplusplus } #endif #endif /* _ETI_H */ # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2006 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # include ../../Makefile.lib # Hammerhead: amd64-only SUBDIRS= $(MACH64) all : TARGET= all clean : TARGET= clean clobber : TARGET= clobber install : TARGET= install .KEEP_STATE: all clean clobber install: $(SUBDIRS) # definitions for install_h target HDRS= form.h utility.h ROOTHDRDIR= $(ROOT)/usr/include ROOTHDRS= $(HDRS:%=$(ROOTHDRDIR)/%) CHECKHDRS= $(HDRS:%.h=inc/%.check) # install rule for install_h target $(ROOTHDRDIR)/%: inc/% $(INS.file) install_h: $(ROOTHDRS) check: $(CHECKHDRS) $(SUBDIRS): FRC @cd $@; pwd; $(MAKE) $(TARGET) FRC: # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2006 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # LIBRARY= libform.a VERS= .1 OBJECTS= \ chg_char.o \ chg_data.o \ chg_field.o \ chg_page.o \ driver.o \ field.o \ field_back.o \ field_buf.o \ field_fore.o \ field_init.o \ field_just.o \ field_opts.o \ field_pad.o \ field_stat.o \ field_term.o \ field_user.o \ fieldtype.o \ form.o \ form_init.o \ form_opts.o \ form_sub.o \ form_term.o \ form_user.o \ form_win.o \ post.o \ regcmp.o \ regex.o \ ty_alnum.o \ ty_alpha.o \ ty_enum.o \ ty_int.o \ ty_num.o \ ty_regexp.o \ utility.o # include library definitions include ../../../Makefile.lib LIBS = $(DYNLIB) SRCDIR= ../common CPPFLAGS += -I../inc CFLAGS += $(CCVERBOSE) LDLIBS += -lcurses -lc CERRWARN += -Wno-parentheses CERRWARN += $(CNOWARN_UNINIT) CERRWARN += -Wno-char-subscripts COMPATLINKS= usr/ccs/lib/libform.so # Hammerhead: flattened layout — no amd64 subdir COMPATLINKS64= $(COMPATLINKS) $(ROOT)/usr/ccs/lib/libform.so : COMPATLINKTARGET= ../../lib/libform.so.1 .KEEP_STATE: all: $(LIBS) # include library targets include ../../../Makefile.targ pics/%.o: ../common/%.c $(COMPILE.c) -o $@ $< $(POST_PROCESS_O) # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. # include ../Makefile.com include ../../../Makefile.lib.64 DYNFLAGS += $(DYNFLAGS64) .KEEP_STATE: install: all $(ROOTLIBS64) $(ROOTLINKS64) $(ROOTCOMPATLINKS64) /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "utility.h" #define SizePrev(f, v) ((v) - Buf(f)) /* from beginning to v */ #define SizeNext(f, v) (BufSize(f) - SizePrev(f, v)) /* from v through end */ #define OffscreenRows(c) ((c)->drows - (c)->rows) #define OffscreenCols(c) ((c)->dcols - (c)->cols) /* _next_char move to next char with wrap to next line at end of line */ int _next_char(FORM *f) { if (++X(f) == Xmax(f)) { if (++Y(f) == Ymax(f)) { --X(f); --Y(f); return (E_REQUEST_DENIED); /* at last char */ } X(f) = 0; } return (E_OK); } /* * _prev_char - move to previous char with * wrap to previous line at beginning of line */ int _prev_char(FORM *f) { if (--X(f) < 0) { if (--Y(f) < 0) { ++X(f); ++Y(f); return (E_REQUEST_DENIED); /* at first char */ } X(f) = Xmax(f) - 1; } return (E_OK); } /* _next_line - move to beginning of next line */ int _next_line(FORM *f) { if (++Y(f) == Ymax(f)) { --Y(f); return (E_REQUEST_DENIED); /* at last line */ } X(f) = 0; return (E_OK); } /* _prev_line - move to beginning of previous line */ int _prev_line(FORM *f) { if (--Y(f) < 0) { ++Y(f); return (E_REQUEST_DENIED); /* at first line */ } X(f) = 0; return (E_OK); } /* _next_word - move to beginning of next word */ int _next_word(FORM *f) { FIELD * c = C(f); char * v = LineBuf(c, Y(f)) + X(f); /* position in buffer */ char * t; _sync_buffer(f); t = _whsp_beg(v, (int) SizeNext(c, v)); v = _data_beg(t, (int) SizeNext(c, t)); if (v == t) return (E_REQUEST_DENIED); /* at last word */ if (OneRow(c) && c->dcols != c->cols) { /* one row and field has grown */ t = v; while (*t != ' ' && *t != '\0') /* find end of word + 1 */ t++; if (t - (Buf(c) + B(f)) > c->cols) { if (t - v > c->cols) { /* word longer than visible field */ B(f) = (int) (v - Buf(c)); } else { B(f) = (int) (t - (Buf(c) + c->cols)); } X(f) = (int) (v - Buf(c)); return (E_OK); } } _adjust_cursor(f, v); return (E_OK); } /* _prev_word - move to beginning of previous word */ int _prev_word(FORM *f) { FIELD * c = C(f); char * v = LineBuf(c, Y(f)) + X(f); /* position in buffer */ char * t; _sync_buffer(f); t = _data_end(Buf(c), (int) SizePrev(c, v)); v = _whsp_end(Buf(c), (int) SizePrev(c, t)); if (v == t) return (E_REQUEST_DENIED); /* at first word */ _adjust_cursor(f, v); return (E_OK); } /* _beg_field - move to first non-pad char in field */ int _beg_field(FORM *f) { FIELD * c = C(f); _sync_buffer(f); _adjust_cursor(f, _data_beg(Buf(c), BufSize(c))); return (E_OK); } /* _end_field - move after last non-pad char in field */ int _end_field(FORM *f) { FIELD * c = C(f); char * end; _sync_buffer(f); end = _data_end(Buf(c), BufSize(c)); if (end == Buf(c) + BufSize(c)) end--; _adjust_cursor(f, end); return (E_OK); } /* _beg_line - move to first non-pad char on current line */ int _beg_line(FORM *f) { FIELD *c = C(f); _sync_buffer(f); _adjust_cursor(f, _data_beg(LineBuf(c, Y(f)), Xmax(f))); return (E_OK); } /* _end_line - move after last non-pad char on current line */ int _end_line(FORM *f) { FIELD *c = C(f); char *end; _sync_buffer(f); end = _data_end(LineBuf(c, Y(f)), Xmax(f)); if (end == LineBuf(c, Y(f)) + Xmax(f)) end--; _adjust_cursor(f, end); return (E_OK); } /* _left_char - move left */ int _left_char(FORM *f) { if (--X(f) < 0) { ++X(f); return (E_REQUEST_DENIED); /* at left side */ } return (E_OK); } /* _right_char - move right */ int _right_char(FORM *f) { if (++X(f) == Xmax(f)) { --X(f); return (E_REQUEST_DENIED); /* at right side */ } return (E_OK); } /* _up_char - move up */ int _up_char(FORM *f) { if (--Y(f) < 0) { ++Y(f); return (E_REQUEST_DENIED); /* at top */ } return (E_OK); } /* _down_char - move down */ int _down_char(FORM *f) { if (++Y(f) == Ymax(f)) { --Y(f); return (E_REQUEST_DENIED); /* at bottom */ } return (E_OK); } /* _scr_fline - scroll forward one line */ int _scr_fline(FORM *f) { FIELD *c = C(f); if (++T(f) > OffscreenRows(c)) { --T(f); return (E_REQUEST_DENIED); /* at bottom */ } ++Y(f); Set(c, TOP_CHG); return (E_OK); } /* _scr_bline - scroll backward one line */ int _scr_bline(FORM *f) { FIELD *c = C(f); if (--T(f) < 0) { ++T(f); return (E_REQUEST_DENIED); /* at top */ } --Y(f); Set(c, TOP_CHG); return (E_OK); } /* _scr_fpage - scroll forward one page(C(f) -> rows) */ int _scr_fpage(FORM *f) { FIELD * c = C(f); int m = OffscreenRows(c) - T(f); int n = c -> rows < m ? c -> rows : m; if (n) { Y(f) += n; T(f) += n; Set(c, TOP_CHG); return (E_OK); } return (E_REQUEST_DENIED); /* at bottom */ } /* _scr_bpage - scroll backward one page(C(f) -> rows) */ int _scr_bpage(FORM *f) { FIELD * c = C(f); int m = T(f); int n = c -> rows < m ? c -> rows : m; if (n) { Y(f) -= n; T(f) -= n; Set(c, TOP_CHG); return (E_OK); } return (E_REQUEST_DENIED); /* at top */ } /* _scr_fhpage - scroll forward one half page(C(f)->rows + 1)/2) */ int _scr_fhpage(FORM *f) { FIELD * c = C(f); int m = OffscreenRows(c) - T(f); int h = (c->rows + 1)/2; int n = h < m ? h : m; if (n) { Y(f) += n; T(f) += n; Set(c, TOP_CHG); return (E_OK); } return (E_REQUEST_DENIED); /* at bottom */ } /* _scr_bhpage - scroll backward one half page(C(f)->rows + 1)/2) */ int _scr_bhpage(FORM *f) { FIELD * c = C(f); int m = T(f); int h = (c->rows + 1)/2; int n = h < m ? h : m; if (n) { Y(f) -= n; T(f) -= n; Set(c, TOP_CHG); return (E_OK); } return (E_REQUEST_DENIED); /* at top */ } /* _scr_fchar - horizontal scroll forward one char */ int _scr_fchar(FORM *f) { FIELD *c = C(f); if (++B(f) > OffscreenCols(c)) { --B(f); return (E_REQUEST_DENIED); /* at end */ } ++X(f); return (E_OK); } /* _scr_bchar - horizontal scroll backward one char */ int _scr_bchar(FORM *f) { if (--B(f) < 0) { ++B(f); return (E_REQUEST_DENIED); /* at beginning */ } --X(f); return (E_OK); } /* _scr_hfline - horizontal scroll forward one line(C(f)->cols) */ int _scr_hfline(FORM *f) { FIELD *c = C(f); int m = OffscreenCols(c) - B(f); int n = c -> cols < m ? c -> cols : m; if (n) { X(f) += n; B(f) += n; return (E_OK); } return (E_REQUEST_DENIED); /* at end */ } /* _scr_hbline - horizontal scroll backward one line(C(f)->cols) */ int _scr_hbline(FORM *f) { FIELD *c = C(f); int m = B(f); int n = c -> cols < m ? c -> cols : m; if (n) { X(f) -= n; B(f) -= n; return (E_OK); } return (E_REQUEST_DENIED); /* at end */ } /* _scr_hfhalf - horizontal scroll forward one half line(C(f)->cols/2) */ int _scr_hfhalf(FORM *f) { FIELD *c = C(f); int m = OffscreenCols(c) - B(f); int h = (c->cols + 1)/2; int n = h < m ? h : m; if (n) { X(f) += n; B(f) += n; return (E_OK); } return (E_REQUEST_DENIED); /* at end */ } /* _scr_hbhalf - horizontal scroll backward one half line(C(f)->cols/2) */ int _scr_hbhalf(FORM *f) { FIELD *c = C(f); int m = B(f); int h = (c->cols + 1)/2; int n = h < m ? h : m; if (n) { X(f) -= n; B(f) -= n; return (E_OK); } return (E_REQUEST_DENIED); /* at top */ } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include #include "utility.h" #define AT_BOTTOM(f) (Y(f) == Ymax(f) - 1) /* last line */ #define AT_END(f) (Y(f) == Ymax(f) - 1 && X(f) == Xmax(f) - 1) /* last char */ #define AT_BEGINNING(f) (Y(f) == 0 && X(f) == 0) /* first char */ static int room_for_line(FORM *f) { char *v; _sync_buffer(f); v = LineBuf(C(f), Ymax(f) - 1); return (v == _data_end(v, Xmax(f))); /* check for empty line */ } static int room_for_char(FORM *f) { WINDOW * w = W(f); int c; (void) wmove(w, Y(f), Xmax(f) - 1); c = (int)(winch(w) & A_CHARTEXT); (void) wmove(w, Y(f), X(f)); return (c == Pad(C(f))); /* check for empty char */ } static int extra_padding(char *str, int nstr) /* used for word wrapping */ { int c = *(str + nstr - 1); if (c == '"' || c == '\'') c = *(str + nstr - 2); return ((c == '.' || c == '?' || c == '!' || c == ':') ? 2 : 1); } BOOLEAN _grow_field(FIELD *c, int chunks) { /* This function handles the growth of dymanically growable fields */ /* Returns TRUE if successful, FALSE otherwise */ FORM *f = c->form; WINDOW *w = W(f); BOOLEAN current = Status(f, POSTED) && c == C(f); char *old_buf; char *new_buf; char *save; int old_len = BufSize(c); int grow; int lcv; int max = c->maxgrow; int i; if (current && Status(f, WIN_CHG)) { _win_to_buf(w, c); Clr(f, WIN_CHG); Set(f, BUF_CHG); } if (OneRow(c)) { grow = chunks * c->cols; if (max) grow = MIN(max - c->dcols, grow); c->dcols += grow; if (c->dcols == max) Clr(c, GROWABLE); } else { grow = chunks * (c->rows + c->nrow); if (max) grow = MIN(max - c->drows, grow); c->drows += grow; grow *= c->cols; if (c->drows == max) Clr(c, GROWABLE); } save = old_buf = Buf(c); new_buf = Buf(c) = malloc(TotalBuf(c)); if (!new_buf) return (FALSE); lcv = c->nbuf + 1; for (i = 0; i < lcv; i++) { (void) memcpy(new_buf, old_buf, old_len); (void) memset(new_buf + old_len, ' ', grow); old_buf += old_len + 1; new_buf += old_len + grow; *new_buf++ = '\0'; } free(save); /* delete old buffer */ if (current) { (void) delwin(w); W(f) = w = newwin(c->drows, c->dcols, 0, 0); if (!w) return (FALSE); wbkgdset(w, Pad(c) | Back(c)); (void) wattrset(w, Fore(c)); (void) werase(w); _buf_to_win(c, w); (void) untouchwin(w); (void) wmove(w, Y(f), X(f)); } if (c->link != c) { FIELD *p = c->link; while (p != c) { Buf(p) = Buf(c); p->drows = c->drows; p->dcols = c->dcols; /* _sync_field(p) */ p = p->link; } } return (TRUE); } static int insert_str(FORM *f, int y, int off, int nstr) /* used for word wrapping */ { WINDOW *w = W(f); FIELD *c = C(f); char *vbeg = LineBuf(c, y); char *v = _data_end(vbeg, Xmax(f)); int x = (int)(v - vbeg); int n = Xmax(f) - x; int pad = extra_padding(Buf(c) + off, nstr); int siz = nstr + 1 + pad; int ret = E_REQUEST_DENIED; if (n >= siz) { /* check for fit on this line */ (void) wmove(w, y, 0); (void) winsnstr(w, Buf(c) + off, nstr); (void) wmove(w, y, nstr); (void) winsnstr(w, " ", pad); } else { /* wrap */ if (y == Ymax(f) - 1 && Status(c, GROWABLE)) { if (!_grow_field(c, 1)) return (E_SYSTEM_ERROR); vbeg = LineBuf(c, y); /* grow changes buffer */ w = W(f); /* grow changes window */ } v = _data_beg(vbeg + Xmax(f) - siz, siz); v = _whsp_end(vbeg, (int)(v - vbeg)); x = (int)(v - vbeg); n = Xmax(f) - x - n; if (y < Ymax(f) - 1 && (ret = insert_str(f, y+1, (int)(v - Buf(c)), n)) == E_OK) { (void) wmove(w, y, x); (void) wclrtoeol(w); (void) wmove(w, y, 0); (void) winsnstr(w, Buf(c) + off, nstr); (void) wmove(w, y, nstr); (void) winsnstr(w, " ", pad); } else return (ret); /* no room for wrap */ } return (E_OK); } static int wrap_ok(FORM *f) /* used for word wrapping */ { /* * when this routine is called a char has already been added/inserted * on the screen at Y(f), X(f). this routine checks to see if the current * line needs wrapping and if so attempts the wrap. if unsuccessful * it deletes the char at Y(f), X(f) and returns FALSE. */ FIELD *c = C(f); BOOLEAN at_bottom = AT_BOTTOM(f); int ret = E_REQUEST_DENIED; if (Opt(c, O_WRAP) && !OneRow(c) && !room_for_char(f) && (!at_bottom || Status(c, GROWABLE))) { WINDOW *w; char *vbeg; char *v; int x, n; if (at_bottom && !_grow_field(c, 1)) return (E_SYSTEM_ERROR); vbeg = LineBuf(c, Y(f)); w = W(f); _win_to_buf(w, c); /* sync buffer without changing flags */ v = _whsp_end(vbeg, Xmax(f)); x = (int)(v - vbeg); n = Xmax(f) - x; if (x && (ret = insert_str(f, Y(f)+1, (int)(v - Buf(c)), n)) == E_OK) { w = W(f); /* window may change in insert_str */ (void) wmove(w, Y(f), x); (void) wclrtoeol(w); if (X(f) >= x) { ++Y(f); X(f) = X(f) - x; } } else { /* error condition */ if (ret == E_SYSTEM_ERROR) return (E_SYSTEM_ERROR); (void) wmove(w, Y(f), X(f)); (void) wdelch(w); /* delete the char */ _win_to_buf(w, c); /* restore buffer */ return (E_REQUEST_DENIED); } } return (E_OK); } int _new_line(FORM *f) { /* * overloaded operation * * if at beginning of field * move to next field * * else if in OVERLAY mode * if on last line of field * clear to eol and move to next field * else * clear to eol and move to beginning of next line * * else if in INSERT mode * if on last line of field * move to next field * else * move text from cursor to eol to new line */ BOOLEAN at_bottom = AT_BOTTOM(f); FIELD * c = C(f); if (Opt(f, O_NL_OVERLOAD) && AT_BEGINNING(f)) return (_field_navigation(_next_field, f)); if (!Opt(c, O_EDIT)) return (E_REQUEST_DENIED); if (Status(f, OVERLAY)) { /* OVERLAY mode */ if (at_bottom && (!Status(c, GROWABLE) || OneRow(c))) { if (Opt(f, O_NL_OVERLOAD)) { (void) wclrtoeol(W(f)); Set(f, WIN_CHG); return (_field_navigation(_next_field, f)); } else return (E_REQUEST_DENIED); } if (at_bottom && !_grow_field(c, 1)) return (E_SYSTEM_ERROR); (void) wclrtoeol(W(f)); ++Y(f); X(f) = 0; } else { /* INSERT mode */ BOOLEAN room; if (at_bottom && (!Status(c, GROWABLE) || OneRow(c))) { if (Opt(f, O_NL_OVERLOAD)) return (_field_navigation(_next_field, f)); else return (E_REQUEST_DENIED); } room = !at_bottom && room_for_line(f); if (room || Status(c, GROWABLE)) { WINDOW *w; char *v; char *vend; if (!room && !_grow_field(c, 1)) return (E_SYSTEM_ERROR); w = W(f); v = LineBuf(c, Y(f)) + X(f); vend = _data_end(v, Xmax(f) - X(f)); (void) wclrtoeol(w); ++Y(f); X(f) = 0; (void) wmove(w, Y(f), X(f)); (void) winsertln(w); (void) waddnstr(w, v, (int)(vend - v)); } else return (E_REQUEST_DENIED); } Set(f, WIN_CHG); return (E_OK); } /* _ins_char - insert blank char with error on overflow */ int _ins_char(FORM *f) { FIELD *c = C(f); BOOLEAN room = room_for_char(f); if (CheckChar(c, ' ') && (room || (OneRow(c) && Status(c, GROWABLE)))) { if (!room && !_grow_field(c, 1)) return (E_SYSTEM_ERROR); (void) winsch(W(f), ' '); return (wrap_ok(f)); } return (E_REQUEST_DENIED); } /* _ins_line - insert blank line with error on overflow */ int _ins_line(FORM *f) { BOOLEAN room = !AT_BOTTOM(f) && room_for_line(f); FIELD *c = C(f); if (CheckChar(c, ' ') && !OneRow(c) && (room || Status(c, GROWABLE))) { if (!room && !_grow_field(c, 1)) return (E_SYSTEM_ERROR); X(f) = 0; (void) winsertln(W(f)); return (E_OK); } return (E_REQUEST_DENIED); } /* _del_char - delete char at cursor */ int _del_char(FORM *f) { (void) wdelch(W(f)); return (E_OK); } int _del_prev(FORM *f) { /* * overloaded operation * * if at beginning of field * move to previous field * * else if in OVERLAY mode * if at beginning of line * error * else * delete previous char * * else if in INSERT mode * if at beginning of line * if current line can fit on preceding * join current line with preceding line * else * error * else * delete previous char */ WINDOW * w = W(f); FIELD * c = C(f); if (AT_BEGINNING(f)) { if (Opt(f, O_BS_OVERLOAD)) return (_field_navigation(_prev_field, f)); else return (E_REQUEST_DENIED); } if (!Opt(c, O_EDIT)) return (E_REQUEST_DENIED); if (--X(f) < 0) { ++X(f); if (Status(f, OVERLAY)) /* OVERLAY mode */ return (E_REQUEST_DENIED); else { /* INSERT mode */ char *p = LineBuf(c, Y(f) - 1); char *v = LineBuf(c, Y(f)); char *pend; char *vend; _sync_buffer(f); pend = _data_end(p, Xmax(f)); vend = _data_end(v, Xmax(f)); if ((vend - v) > (Xmax(f) - (pend - p))) return (E_REQUEST_DENIED); else { (void) wdeleteln(w); _adjust_cursor(f, pend); (void) wmove(w, Y(f), X(f)); (void) waddnstr(w, v, (int)(vend - v)); } } } else { (void) wmove(w, Y(f), X(f)); (void) wdelch(w); } Set(f, WIN_CHG); return (E_OK); } /* _del_line - delete current line */ int _del_line(FORM *f) { X(f) = 0; (void) wdeleteln(W(f)); return (E_OK); } /* _del_word - delete word under cursor plus trailing blanks */ int _del_word(FORM *f) { FIELD *c = C(f); WINDOW *w = W(f); char *y = LineBuf(c, Y(f)); char *t = y + Xmax(f); char *v = y + X(f); char *x = v; _sync_buffer(f); if (*v == ' ') return (E_REQUEST_DENIED); _adjust_cursor(f, _whsp_end(y, X(f))); (void) wmove(w, Y(f), X(f)); (void) wclrtoeol(w); v = _whsp_beg(v, (int)(t - v)); v = _data_beg(v, (int)(t - v)); if (v != x && *v != ' ') (void) waddnstr(w, v, (int)(_data_end(v, (int)(t - v)) - v)); return (E_OK); } /* _clr_eol - clear to end of line */ int _clr_eol(FORM *f) { (void) wclrtoeol(W(f)); return (E_OK); } /* _clr_eof - clear to end of field */ int _clr_eof(FORM *f) { (void) wclrtobot(W(f)); return (E_OK); } /* _clr_field - clear entire field */ int _clr_field(FORM *f) { X(f) = 0; Y(f) = 0; (void) werase(W(f)); return (E_OK); } /* _ovl_mode - go into overlay mode */ int _ovl_mode(FORM *f) { Set(f, OVERLAY); return (E_OK); } /* _ins_mode - go into insert mode */ int _ins_mode(FORM *f) { Clr(f, OVERLAY); return (E_OK); } /* _validation - apply validation function associated with field type */ int _validation(FORM *f) { return (_validate(f) ? E_OK : E_INVALID_FIELD); } /* _next_choice - apply next choice function associated with field type */ int _next_choice(FORM *f) { _sync_buffer(f); return (NextChoice(C(f)) ? E_OK : E_REQUEST_DENIED); } /* _prev_choice - apply previous choice function associated with field type */ int _prev_choice(FORM *f) { _sync_buffer(f); return (PrevChoice(C(f)) ? E_OK : E_REQUEST_DENIED); } /* * _data_entry - enter printable ascii char ch * in current field at cursor position */ int _data_entry(FORM *f, int ch) { FIELD * c = C(f); /* current field */ WINDOW * w = W(f); /* field window */ BOOLEAN at_end; int ret; if (!Opt(c, O_EDIT)) return (E_REQUEST_DENIED); if (AT_BEGINNING(f) && Opt(c, O_BLANK) && ! Status(f, BUF_CHG) && !Status(f, WIN_CHG)) (void) werase(w); if (Status(f, OVERLAY)) /* OVERLAY mode */ (void) waddch(w, (chtype) ch); else { /* INSERT mode */ BOOLEAN room = room_for_char(f); if (room || (OneRow(c) && Status(c, GROWABLE))) { if (!room && !_grow_field(c, 1)) return (E_SYSTEM_ERROR); (void) winsch(w, (chtype) ch); } else return (E_REQUEST_DENIED); } if ((ret = wrap_ok(f)) != E_OK) return (ret); Set(f, WIN_CHG); at_end = AT_END(f); if (at_end && !Status(c, GROWABLE) && Opt(c, O_AUTOSKIP)) return (_field_navigation(_next_field, f)); if (at_end && Status(c, GROWABLE) && !_grow_field(c, 1)) return (E_SYSTEM_ERROR); (void) _next_char(f); return (E_OK); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "utility.h" #define first(f) (f->field [Pmin(f, P(f))]) #define last(f) (f->field [Pmax(f, P(f))]) #define sfirst(f) (f->field [Smin(f, P(f))]) #define slast(f) (f->field [Smax(f, P(f))]) #define Active(f) (Opt(f, O_ACTIVE) && Opt(f, O_VISIBLE)) /* next - return next active field on page after f(user defined order) */ static FIELD * next(FIELD *f) { FORM *t = f->form; FIELD **p = t->field + f->index; FIELD **pmin = t->field + Pmin(t, P(t)); FIELD **pmax = t->field + Pmax(t, P(t)); do p = p == pmax ? pmin : p+1; while ((!Active(*p)) && (*p != f)); return (*p); } /* prev - return previous active field on page before f */ static FIELD * prev(FIELD *f) { FORM *t = f->form; FIELD **p = t->field + f->index; FIELD **pmin = t->field + Pmin(t, P(t)); FIELD **pmax = t->field + Pmax(t, P(t)); do p = p == pmin ? pmax : p-1; while ((!Active(*p)) && (*p != f)); return (*p); } /* snext - return next active field on page after f(sorted order) */ static FIELD * snext(FIELD *f) { FIELD *x = f; do f = f->snext; while ((!Active(f)) && (f != x)); return (f); } /* sprev - return previous active field on page before f(sorted order) */ static FIELD * sprev(FIELD *f) { FIELD *x = f; do f = f->sprev; while ((!Active(f)) && (f != x)); return (f); } /* left - return active field on page left of f */ static FIELD * left(FIELD *f) { int row = f->frow; do f = sprev(f); while (f->frow != row); return (f); } /* right - return active field on page right of f */ static FIELD * right(FIELD *f) { int row = f->frow; do f = snext(f); while (f->frow != row); return (f); } /* up - return active field on page above f */ static FIELD * up(FIELD *f) { int row = f->frow; int col = f->fcol; do f = sprev(f); while (f->frow == row && f->fcol != col); if (f->frow != row) { row = f->frow; while (f->frow == row && f->fcol > col) f = sprev(f); if (f->frow != row) f = snext(f); } return (f); } /* down - return active field on page below f */ static FIELD * down(FIELD *f) { int row = f->frow; int col = f->fcol; do f = snext(f); while (f->frow == row && f->fcol != col); if (f->frow != row) { row = f->frow; while (f->frow == row && f->fcol < col) f = snext(f); if (f ->frow != row) f = sprev(f); } return (f); } /* * _next_field */ int _next_field(FORM *f) { return (_set_current_field(f, next(C(f)))); } int _prev_field(FORM *f) { return (_set_current_field(f, prev(C(f)))); } int _first_field(FORM *f) { return (_set_current_field(f, next(last(f)))); } int _last_field(FORM *f) { return (_set_current_field(f, prev(first(f)))); } int _snext_field(FORM *f) { return (_set_current_field(f, snext(C(f)))); } int _sprev_field(FORM *f) { return (_set_current_field(f, sprev(C(f)))); } int _sfirst_field(FORM *f) { return (_set_current_field(f, snext(slast(f)))); } int _slast_field(FORM *f) { return (_set_current_field(f, sprev(sfirst(f)))); } int _left_field(FORM *f) { return (_set_current_field(f, left(C(f)))); } int _right_field(FORM *f) { return (_set_current_field(f, right(C(f)))); } int _up_field(FORM *f) { return (_set_current_field(f, up(C(f)))); } int _down_field(FORM *f) { return (_set_current_field(f, down(C(f)))); } FIELD * _first_active(FORM *f) { return (next(last(f))); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "utility.h" #define first(f) (0) #define last(f) (f->maxpage - 1) /* next - return next page after current page(cyclic) */ static int next(FORM *f) { int p = P(f); if (++p > last(f)) p = first(f); return (p); } /* prev - return previous page before current page(cyclic) */ static int prev(FORM *f) { int p = P(f); if (--p < first(f)) p = last(f); return (p); } int _next_page(FORM *f) { return (_set_form_page(f, next(f), (FIELD *) 0)); } int _prev_page(FORM *f) { return (_set_form_page(f, prev(f), (FIELD *) 0)); } int _first_page(FORM *f) { return (_set_form_page(f, first(f), (FIELD *) 0)); } int _last_page(FORM *f) { return (_set_form_page(f, last(f), (FIELD *) 0)); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "utility.h" typedef struct { PTF_int class; PTF_int act; } REQUEST; static REQUEST parse(int); #define COMMAND(x) (x.class) #define CALL(x, f) (x.class ? (*x.class) (x.act, f) : E_SYSTEM_ERROR) /* command array(carray) order is significant(see form.h REQ_*) */ static REQUEST carray [MAX_FORM_COMMAND - MIN_FORM_COMMAND + 1] = { _page_navigation, _next_page, /* REQ_NEXT_PAGE */ _page_navigation, _prev_page, /* REQ_PREV_PAGE */ _page_navigation, _first_page, /* REQ_FIRST_PAGE */ _page_navigation, _last_page, /* REQ_LAST_PAGE */ _field_navigation, _next_field, /* REQ_NEXT_FIELD */ _field_navigation, _prev_field, /* REQ_PREV_FIELD */ _field_navigation, _first_field, /* REQ_FIRST_FIELD */ _field_navigation, _last_field, /* REQ_LAST_FIELD */ _field_navigation, _snext_field, /* REQ_SNEXT_FIELD */ _field_navigation, _sprev_field, /* REQ_SPREV_FIELD */ _field_navigation, _sfirst_field, /* REQ_SFIRST_FIELD */ _field_navigation, _slast_field, /* REQ_SLAST_FIELD */ _field_navigation, _left_field, /* REQ_LEFT_FIELD */ _field_navigation, _right_field, /* REQ_RIGHT_FIELD */ _field_navigation, _up_field, /* REQ_UP_FIELD */ _field_navigation, _down_field, /* REQ_DOWN_FIELD */ _data_navigation, _next_char, /* REQ_NEXT_CHAR */ _data_navigation, _prev_char, /* REQ_PREV_CHAR */ _data_navigation, _next_line, /* REQ_NEXT_LINE */ _data_navigation, _prev_line, /* REQ_PREV_LINE */ _data_navigation, _next_word, /* REQ_NEXT_WORD */ _data_navigation, _prev_word, /* REQ_PREV_WORD */ _data_navigation, _beg_field, /* REQ_BEG_FIELD */ _data_navigation, _end_field, /* REQ_END_FIELD */ _data_navigation, _beg_line, /* REQ_BEG_LINE */ _data_navigation, _end_line, /* REQ_END_LINE */ _data_navigation, _left_char, /* REQ_LEFT_CHAR */ _data_navigation, _right_char, /* REQ_RIGHT_CHAR */ _data_navigation, _up_char, /* REQ_UP_CHAR */ _data_navigation, _down_char, /* REQ_DOWN_CHAR */ _misc_request, _new_line, /* REQ_NEW_LINE */ _data_manipulation, _ins_char, /* REQ_INS_CHAR */ _data_manipulation, _ins_line, /* REQ_INS_LINE */ _data_manipulation, _del_char, /* REQ_DEL_CHAR */ _misc_request, _del_prev, /* REQ_DEL_PREV */ _data_manipulation, _del_line, /* REQ_DEL_LINE */ _data_manipulation, _del_word, /* REQ_DEL_WORD */ _data_manipulation, _clr_eol, /* REQ_CLR_EOL */ _data_manipulation, _clr_eof, /* REQ_CLR_EOF */ _data_manipulation, _clr_field, /* REQ_CLR_FIELD */ _misc_request, _ovl_mode, /* REQ_OVL_MODE */ _misc_request, _ins_mode, /* REQ_INS_MODE */ _data_navigation, _scr_fline, /* REQ_SCR_FLINE */ _data_navigation, _scr_bline, /* REQ_SCR_BLINE */ _data_navigation, _scr_fpage, /* REQ_SCR_FPAGE */ _data_navigation, _scr_bpage, /* REQ_SCR_BPAGE */ _data_navigation, _scr_fhpage, /* REQ_SCR_FHPAGE */ _data_navigation, _scr_bhpage, /* REQ_SCR_BHPAGE */ _data_navigation, _scr_fchar, /* REQ_SCR_FCHAR */ _data_navigation, _scr_bchar, /* REQ_SCR_BCHAR */ _data_navigation, _scr_hfline, /* REQ_SCR_HFLINE */ _data_navigation, _scr_hbline, /* REQ_SCR_HBLINE */ _data_navigation, _scr_hfhalf, /* REQ_SCR_HFHALF */ _data_navigation, _scr_hbhalf, /* REQ_SCR_HBHALF */ _misc_request, _validation, /* REQ_VALIDATION */ _misc_request, _next_choice, /* REQ_NEXT_CHOICE */ _misc_request, _prev_choice, /* REQ_PREV_CHOICE */ }; static REQUEST FAIL = { (PTF_int) 0, (PTF_int) 0 }; /* _page_navigation - service page navigation request */ int _page_navigation(PTF_int act, FORM *f) { int v; if (_validate(f)) { term_field(f); term_form(f); v = (*act) (f); init_form(f); init_field(f); } else v = E_INVALID_FIELD; return (v); } /* _field_navigation - service inter-field navigation request */ int _field_navigation(PTF_int act, FORM *f) { int v; if (_validate(f)) { term_field(f); v = (*act) (f); init_field(f); } else v = E_INVALID_FIELD; return (v); } /* _data_navigation - service intra-field navagation request */ int _data_navigation(PTF_int act, FORM *f) { return ((*act) (f)); } /* _data_manipulation - service data modification request */ int _data_manipulation(PTF_int act, FORM *f) { int v = E_REQUEST_DENIED; FIELD * c = C(f); if (Opt(c, O_EDIT)) if ((v = (*act) (f)) == E_OK) Set(f, WIN_CHG); return (v); } int _misc_request(PTF_int act, FORM *f) { return ((*act) (f)); } int form_driver(FORM *f, int c) { int v; REQUEST x; if (f) { if (Status(f, DRIVER)) v = E_BAD_STATE; else if (Status(f, POSTED)) { x = parse(c); if (COMMAND(x)) v = CALL(x, f); else { if (isascii(c) && isprint(c) && CheckChar(C(f), c)) v = _data_entry(f, c); else v = E_UNKNOWN_COMMAND; } (void) _update_current(f); } else v = E_NOT_POSTED; } else v = E_BAD_ARGUMENT; return (v); } static REQUEST parse(int c) { if (c < MIN_FORM_COMMAND || c > MAX_FORM_COMMAND) return (FAIL); return (carray[c - MIN_FORM_COMMAND]); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /* * Copyright (c) 2018, Joyent, Inc. */ /*LINTLIBRARY*/ #include #include #include "utility.h" /* * default field */ static FIELD default_field = { 0, /* status */ 0, /* rows */ 0, /* cols */ 0, /* frow */ 0, /* fcol */ 0, /* drows */ 0, /* dcols */ 0, /* maxgrow */ 0, /* nrow */ 0, /* nbuf */ NO_JUSTIFICATION, /* just */ 0, /* page */ 0, /* index */ ' ', /* pad */ A_NORMAL, /* fore */ A_NORMAL, /* back */ O_VISIBLE | O_ACTIVE | O_PUBLIC | O_EDIT | O_WRAP | O_BLANK | O_AUTOSKIP | O_NULLOK | O_PASSOK | O_STATIC, /* opts */ (FIELD *)0, /* snext */ (FIELD *)0, /* sprev */ (FIELD *)0, /* link */ (FORM *)0, /* form */ (FIELDTYPE *)0, /* type */ (char *)0, /* arg */ (char *)0, /* buf */ (char *)0, /* usrptr */ }; FIELD * _DEFAULT_FIELD = &default_field; /* * MakeType */ static int MakeType(FIELD *f, va_list *ap) { int err = 0; f->arg = MakeArg(f, ap, &err); /* pick off type specific args */ if (err) { FreeArg(f); /* release type specific args */ f->type = (FIELDTYPE *)0; f->arg = (char *)0; return (FALSE); } IncrType(f->type); /* increment reference count */ return (TRUE); } /* * CopyType */ static int CopyType(FIELD *f, FIELD *fsrc) { int err = 0; f->type = fsrc->type; /* copy field type */ f->arg = CopyArg(fsrc, &err); /* copy type specific info */ if (err) { FreeArg(f); /* release type specific args */ f->type = (FIELDTYPE *)0; f->arg = (char *)0; return (FALSE); } IncrType(f->type); /* increment reference count */ return (TRUE); } /* * FreeType */ static void FreeType(FIELD *f) { DecrType(f->type); /* decrement reference count */ FreeArg(f); /* release type specific args */ } /* * new_field */ FIELD * new_field(int rows, int cols, int frow, int fcol, int nrow, int nbuf) /* int rows; number of visible rows */ /* int cols; number of visible cols */ /* int frow; first row relative to form origin */ /* int fcol; first col relative to form origin */ /* int nrow; number of off screen rows */ /* int nbuf; number of additional buffers */ { FIELD *f = (FIELD *) 0; int i, size; if (rows > 0 && cols > 0 && frow >= 0 && fcol >= 0 && nrow >= 0 && nbuf >= 0 && Alloc(f, FIELD)) { *f = *_DEFAULT_FIELD; f->rows = rows; f->cols = cols; f->frow = frow; f->fcol = fcol; f->drows = rows + nrow; f->dcols = cols; f->nrow = nrow; f->nbuf = nbuf; f->link = f; if (CopyType(f, _DEFAULT_FIELD)) { size = TotalBuf(f); if (arrayAlloc(Buf(f), size, char)) { (void) memset(Buf(f), ' ', size); for (i = 0; i <= f->nbuf; ++i) *(Buffer(f, i + 1) - 1) = '\0'; return (f); } } } (void) free_field(f); return ((FIELD *) 0); } /* * dup_field */ FIELD * dup_field(FIELD *field, int frow, int fcol) /* FIELD * field; field to duplicate */ /* int frow; first row relative to form origin */ /* int fcol; first col relative to form origin */ { FIELD *f = (FIELD *) 0; int size; if (field && frow >= 0 && fcol >= 0 && Alloc(f, FIELD)) { *f = *_DEFAULT_FIELD; f->frow = frow; f->fcol = fcol; f->link = f; f->rows = field->rows; f->cols = field->cols; f->drows = field->drows; f->dcols = field->dcols; f->maxgrow = field->maxgrow; f->nrow = field->nrow; f->nbuf = field->nbuf; f->just = field->just; f->fore = field->fore; f->back = field->back; f->pad = field->pad; f->opts = field->opts; f->usrptr = field->usrptr; f->status = Status(field, GROWABLE); if (CopyType(f, field)) { size = TotalBuf(f); if (arrayAlloc(Buf(f), size, char)) { (void) memcpy(Buf(f), Buf(field), size); return (f); } } } (void) free_field(f); return ((FIELD *) 0); } /* * link_field */ FIELD * link_field(FIELD *field, int frow, int fcol) /* FIELD * field; field to link to */ /* int frow; first row relative to form origin */ /* int fcol; first col relative to form origin */ { FIELD *f = (FIELD *) 0; if (field && frow >= 0 && fcol >= 0 && Alloc(f, FIELD)) { *f = *_DEFAULT_FIELD; f->frow = frow; f->fcol = fcol; f->link = field->link; field->link = f; /* add field to linked list */ f->buf = field->buf; f->rows = field->rows; f->cols = field->cols; f->drows = field->drows; f->dcols = field->dcols; f->maxgrow = field->maxgrow; f->nrow = field->nrow; f->nbuf = field->nbuf; f->just = field->just; f->fore = field->fore; f->back = field->back; f->pad = field->pad; f->opts = field->opts; f->usrptr = field->usrptr; f->status = Status(field, GROWABLE); if (CopyType(f, field)) return (f); } (void) free_field(f); return ((FIELD *) 0); } /* * free_field */ int free_field(FIELD *f) { FIELD *p; if (!f) return (E_BAD_ARGUMENT); if (f->form) return (E_CONNECTED); if (f->link != f) { /* check for linked field */ for (p = f->link; p->link != f; p = p->link) ; p->link = f->link; /* delete from list */ } else Free(Buf(f)); /* free buffer space */ FreeType(f); Free(f); return (E_OK); } /* * field_info */ int field_info(FIELD *f, int *rows, int *cols, int *frow, int *fcol, int *nrow, int *nbuf) /* FIELD *f; field whose information is wanted */ /* int *rows; number of visible rows */ /* int *cols; number of visible cols */ /* int *frow; first row relative to form origin */ /* int *fcol; first col relative to form origin */ /* int *nrow; number of off screen rows */ /* int *nbuf; number of additional buffers */ { if (!f) return (E_BAD_ARGUMENT); *rows = f->rows; *cols = f->cols; *frow = f->frow; *fcol = f->fcol; *nrow = f->nrow; *nbuf = f->nbuf; return (E_OK); } /* * set_max_field */ int set_max_field(FIELD *f, int max) { BOOLEAN onerow; if (f == NULL) return (E_BAD_ARGUMENT); onerow = OneRow(f); if (max && ((onerow && f->dcols > max) || (!onerow && f->drows > max))) return (E_BAD_ARGUMENT); f->maxgrow = max; Clr(f, GROWABLE); if (!Opt(f, O_STATIC) && ((!max || onerow && f->dcols < max) || (!onerow && f->drows < max))) { Set(f, GROWABLE); } return (E_OK); } /* * dynamic_field_info */ int dynamic_field_info(FIELD *f, int *drows, int *dcols, int *max) /* FIELD *f; field whose information is wanted */ /* int *drows; number of actual rows */ /* int *dcols; number of actual cols */ /* int *max; maximum growth allowable, else -1 */ { if (!f) return (E_BAD_ARGUMENT); *drows = f->drows; *dcols = f->dcols; *max = f->maxgrow; return (E_OK); } /* * move_field */ int move_field(FIELD *f, int frow, int fcol) /* FIELD *f; field to move */ /* int frow; first row relative to form origin */ /* int fcol; first col relative to form origin */ { if (! f || frow < 0 || fcol < 0) return (E_BAD_ARGUMENT); if (f->form) return (E_CONNECTED); f->frow = frow; f->fcol = fcol; return (E_OK); } /* * set_field_type */ int set_field_type(FIELD *f, FIELDTYPE *ft, ...) { va_list ap; int v = E_SYSTEM_ERROR; va_start(ap, ft); f = Field(f); FreeType(f); /* free old type */ f->type = ft; if (MakeType(f, &ap)) /* set up new type */ v = E_OK; va_end(ap); return (v); } FIELDTYPE * field_type(FIELD *f) { return (Field(f)->type); } char * field_arg(FIELD *f) { return (Field(f)->arg); } /* * set_new_page */ int set_new_page(FIELD *f, int flag) { f = Field(f); if (f->form) return (E_CONNECTED); if (flag) Set(f, NEW_PAGE); else Clr(f, NEW_PAGE); return (E_OK); } int new_page(FIELD *f) { if (Status(Field(f), NEW_PAGE)) return (TRUE); else return (FALSE); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "utility.h" int set_field_back(FIELD *f, chtype back) { f = Field(f); if ((back & (chtype) A_ATTRIBUTES) != back) return (E_BAD_ARGUMENT); if (Back(f) != back) { Back(f) = back; return (_sync_attrs(f)); } return (E_OK); } chtype field_back(FIELD *f) { return (Back(Field(f))); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "utility.h" int set_field_buffer(FIELD *f, int n, char *v) { char *p; char *x; size_t s; int err = 0; int len; int size; if (!f || !v || n < 0 || n > f->nbuf) return (E_BAD_ARGUMENT); len = (int) strlen(v); size = BufSize(f); if (Status(f, GROWABLE) && len > size) if (!_grow_field(f, (len - size - 1)/GrowSize(f) + 1)) return (E_SYSTEM_ERROR); x = Buffer(f, n); s = BufSize(f); p = memccpy(x, v, '\0', s); if (p) (void) memset(p - 1, ' ', (size_t) (s - (p - x) + 1)); if (n == 0) { if (_sync_field(f) != E_OK) ++err; if (_sync_linked(f) != E_OK) ++err; } return (err ? E_SYSTEM_ERROR : E_OK); } char * field_buffer(FIELD *f, int n) { /* * field_buffer may not be accurate on the current field unless * called from within the check validation function or the * form/field init/term functions. * field_buffer is always accurate on validated fields. */ if (f && n >= 0 && n <= f -> nbuf) return (Buffer(f, n)); else return ((char *) 0); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "utility.h" int set_field_fore(FIELD *f, chtype fore) { f = Field(f); if ((fore & (chtype) A_ATTRIBUTES) != fore) return (E_BAD_ARGUMENT); if (Fore(f) != fore) { Fore(f) = fore; return (_sync_attrs(f)); } return (E_OK); } chtype field_fore(FIELD *f) { return (Fore(Field(f))); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "utility.h" int set_field_init(FORM *f, PTF_void func) { Form(f)->fieldinit = func; return (E_OK); } PTF_void field_init(FORM *f) { return (Form(f)->fieldinit); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "utility.h" int set_field_just(FIELD *f, int just) { if (just != NO_JUSTIFICATION && just != JUSTIFY_LEFT && just != JUSTIFY_CENTER &&just != JUSTIFY_RIGHT) return (E_BAD_ARGUMENT); f = Field(f); if (Just(f) != just) { Just(f) = just; return (_sync_attrs(f)); } return (E_OK); } int field_just(FIELD *f) { return (Just(Field(f))); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "utility.h" int set_field_opts(FIELD *f, OPTIONS opts) { return (_sync_opts(Field(f), opts)); } OPTIONS field_opts(FIELD *f) { return (Field(f) -> opts); } int field_opts_on(FIELD *f, OPTIONS opts) { FIELD *x = Field(f); return (_sync_opts(x, x->opts | opts)); } int field_opts_off(FIELD *f, OPTIONS opts) { FIELD *x = Field(f); return (_sync_opts(x, x->opts & ~opts)); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "utility.h" int set_field_pad(FIELD *f, int pad) { if (!(isascii(pad) && isprint(pad))) return (E_BAD_ARGUMENT); f = Field(f); if (Pad(f) != pad) { Pad(f) = pad; return (_sync_attrs(f)); } return (E_OK); } int field_pad(FIELD *f) { return (Pad(Field(f))); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "utility.h" int set_field_status(FIELD *f, int status) { f = Field(f); if (status) Set(f, USR_CHG); else Clr(f, USR_CHG); return (E_OK); } int field_status(FIELD *f) { /* * field_status may not be accurate on the current field unless * called from within the check validation function or the * form/field init/term functions. * field_status is always accurate on validated fields. */ if (Status(Field(f), USR_CHG)) return (TRUE); else return (FALSE); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "utility.h" int set_field_term(FORM *f, PTF_void func) { Form(f)->fieldterm = func; return (E_OK); } PTF_void field_term(FORM *f) { return (Form(f)->fieldterm); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "utility.h" int set_field_userptr(FIELD *f, char *userptr) { Field(f)-> usrptr = userptr; return (E_OK); } char * field_userptr(FIELD *f) { return (Field(f)->usrptr); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include #include "utility.h" typedef struct { char *leftarg; char *rightarg; } LINK; #define ArgL(n) (((LINK *)(n))->leftarg) #define ArgR(n) (((LINK *)(n))->rightarg) #define Ref(t) ((t)->ref) #define TypeL(t) ((t)->left) #define TypeR(t) ((t)->right) #define MakeA(t) ((t)->makearg) #define CopyA(t) ((t)->copyarg) #define FreeA(t) ((t)->freearg) #define Fcheck(t) ((t)->fcheck) #define Ccheck(t) ((t)->ccheck) #define Next(t) ((t)->next) #define Prev(t) ((t)->prev) /* * default fieldtype */ static FIELDTYPE default_fieldtype = { 0, /* status */ 0, /* ref */ (FIELDTYPE *) 0, /* left */ (FIELDTYPE *) 0, /* right */ (PTF_charP) 0, /* makearg */ (PTF_charP) 0, /* copyarg */ (PTF_void) 0, /* freearg */ (PTF_int) 0, /* fcheck */ (PTF_int) 0, /* ccheck */ (PTF_int) 0, /* next */ (PTF_int) 0, /* prev */ }; FIELDTYPE * _DEFAULT_FIELDTYPE = &default_fieldtype; /* new_fieldtype - field & character validation function */ FIELDTYPE * new_fieldtype(PTF_int fcheck, PTF_int ccheck) { FIELDTYPE *t = (FIELDTYPE *) 0; if ((fcheck || ccheck) && Alloc(t, FIELDTYPE)) { *t = *_DEFAULT_FIELDTYPE; Fcheck(t) = fcheck; Ccheck(t) = ccheck; } return (t); } FIELDTYPE * link_fieldtype(FIELDTYPE *left, FIELDTYPE *right) { FIELDTYPE *t = (FIELDTYPE *) 0; if ((left || right) && Alloc(t, FIELDTYPE)) { *t = *_DEFAULT_FIELDTYPE; Set(t, LINKED); if (Status(left, ARGS) || Status(right, ARGS)) Set(t, ARGS); if (Status(left, CHOICE) || Status(right, CHOICE)) Set(t, CHOICE); TypeL(t) = left; TypeR(t) = right; IncrType(left); /* increment reference count */ IncrType(right); /* increment reference count */ } return (t); } int free_fieldtype(FIELDTYPE *t) { if (!t) return (E_BAD_ARGUMENT); if (Ref(t)) return (E_CONNECTED); if (Status(t, LINKED)) { DecrType(TypeL(t)); /* decrement reference count */ DecrType(TypeR(t)); /* decrement reference count */ } Free(t); return (E_OK); } int set_fieldtype_arg(FIELDTYPE *t, PTF_charP makearg, PTF_charP copyarg, PTF_void freearg) { if (t && makearg && copyarg && freearg) { Set(t, ARGS); MakeA(t) = makearg; CopyA(t) = copyarg; FreeA(t) = freearg; return (E_OK); } return (E_BAD_ARGUMENT); } /* set_fieldtype_choice next & prev choice function */ int set_fieldtype_choice(FIELDTYPE *t, PTF_int next, PTF_int prev) { if (t && next && prev) { Set(t, CHOICE); Next(t) = next; Prev(t) = prev; return (E_OK); } return (E_BAD_ARGUMENT); } char * _makearg(FIELDTYPE *t, va_list *ap, int *err) { /* * invoke make_arg function associated with field type t. * return pointer to argument information or null if none. * increment err if an error is encountered. */ char *p = (char *)0; if (! t || ! Status(t, ARGS)) return (p); if (Status(t, LINKED)) { LINK *n = (LINK *) 0; if (Alloc(n, LINK)) { ArgL(n) = _makearg(TypeL(t), ap, err); ArgR(n) = _makearg(TypeR(t), ap, err); p = (char *)n; } else ++(*err); /* out of space */ } else if (!(p = (*MakeA(t)) (ap))) ++(*err); /* make_arg had problem */ return (p); } char * _copyarg(FIELDTYPE *t, char *arg, int *err) { /* * invoke copy_arg function associated with field type t. * return pointer to argument information or null if none. * increment err if an error is encountered. */ char *p = (char *)0; if (!t || !Status(t, ARGS)) return (p); if (Status(t, LINKED)) { LINK *n = (LINK *) 0; if (Alloc(n, LINK)) { ArgL(n) = _copyarg(TypeL(t), ArgL(arg), err); ArgR(n) = _copyarg(TypeR(t), ArgR(arg), err); p = (char *)n; } else ++(*err); /* out of space */ } else if (!(p = (*CopyA(t)) (arg))) ++(*err); /* copy_arg had problem */ return (p); } /* _freearg - invoke free_arg function associated with field type t. */ void _freearg(FIELDTYPE *t, char *arg) { if (!t || !Status(t, ARGS)) return; if (Status(t, LINKED)) { _freearg(TypeL(t), ArgL(arg)); _freearg(TypeR(t), ArgR(arg)); Free(arg); } else (*FreeA(t)) (arg); } /* _checkfield - invoke check_field function associated with field type t. */ int _checkfield(FIELDTYPE *t, FIELD *f, char *arg) { if (!t) return (TRUE); if (Opt(f, O_NULLOK)) { char *v = Buf(f); while (*v && *v == ' ') ++v; if (!*v) return (TRUE); /* empty field */ } if (Status(t, LINKED)) return (_checkfield(TypeL(t), f, ArgL(arg)) || _checkfield(TypeR(t), f, ArgR(arg))); else if (Fcheck(t)) return ((*Fcheck(t)) (f, arg)); return (TRUE); } /* _checkchar - invoke check_char function associated with field type t. */ int _checkchar(FIELDTYPE *t, int c, char *arg) { if (!t) return (TRUE); if (Status(t, LINKED)) return (_checkchar(TypeL(t), c, ArgL(arg)) || _checkchar(TypeR(t), c, ArgR(arg))); else if (Ccheck(t)) return ((*Ccheck(t)) (c, arg)); return (TRUE); } /* _nextchoice - invoke next_choice function associated with field type t. */ int _nextchoice(FIELDTYPE *t, FIELD *f, char *arg) { if (!t || !Status(t, CHOICE)) return (FALSE); if (Status(t, LINKED)) return (_nextchoice(TypeL(t), f, ArgL(arg)) || _nextchoice(TypeR(t), f, ArgR(arg))); else return ((*Next(t)) (f, arg)); } /* _prevchoice - invoke prev_choice function associated with field type t. */ int _prevchoice(FIELDTYPE *t, FIELD *f, char *arg) { if (!t || !Status(t, CHOICE)) return (FALSE); if (Status(t, LINKED)) return (_prevchoice(TypeL(t), f, ArgL(arg)) || _prevchoice(TypeR(t), f, ArgR(arg))); else return ((*Prev(t)) (f, arg)); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include #include "utility.h" #define MAX_BUF 81 /* default form */ static FORM default_form = { 0, /* status */ 0, /* rows */ 0, /* cols */ 0, /* currow */ 0, /* curcol */ 0, /* toprow */ 0, /* begincol */ -1, /* maxfield */ -1, /* maxpage */ -1, /* curpage */ O_NL_OVERLOAD | O_BS_OVERLOAD, /* opts */ (WINDOW *) 0, /* win */ (WINDOW *) 0, /* sub */ (WINDOW *) 0, /* w */ (FIELD **) 0, /* field */ (FIELD *) 0, /* current */ (_PAGE *) 0, /* page */ (char *) 0, /* usrptr */ (PTF_void) 0, /* forminit */ (PTF_void) 0, /* formterm */ (PTF_void) 0, /* fieldinit */ (PTF_void) 0, /* fieldterm */ }; FORM * _DEFAULT_FORM = &default_form; /* * insert - insert field f into sorted list pointed * to by head. return (possibly new) head of list. */ static FIELD * insert(FIELD *f, FIELD *head) { FIELD *p; FIELD *newhead; int frow, fcol; if (head) { p = newhead = head; frow = f->frow; fcol = f->fcol; while ((p->frow < frow) || (p->frow == frow && p->fcol < fcol)) { p = p->snext; if (p == head) { head = (FIELD *) 0; break; } } f->snext = p; f->sprev = p->sprev; f->snext->sprev = f; f->sprev->snext = f; if (p == head) newhead = f; /* insert at head of list */ } else newhead = f->sprev = f->snext = f; /* initialize new list */ return (newhead); } /* sort_form - sort fields on form(per page) */ static void sort_form(FORM *f) { FIELD **field; FIELD *p; int i, page, pmin, pmax; field = f->field; for (page = 0; page < f->maxpage; ++page) { /* for each page */ p = (FIELD *) 0; pmin = Pmin(f, page); pmax = Pmax(f, page); for (i = pmin; i <= pmax; ++i) { /* for each field */ field[i]->index = i; field[i]->page = page; p = insert(field[i], p); } Smin(f, page) = p->index; /* set sorted min */ Smax(f, page) = p->sprev->index; /* set sorted max */ } } /* merge - xmax/ymax is the minimum window size to hold field f */ static void merge(FIELD *f, FORM *form) /* adjust form dimensions to include field f */ { int xmax = f->fcol + f->cols; int ymax = f->frow + f->rows; if (form->rows < ymax) form->rows = ymax; if (form->cols < xmax) form->cols = xmax; } /* disconnect_fields - disconnect fields from form */ static void disconnect_fields(FORM *form) { FIELD **f = form->field; if (f) while (*f) { if ((*f)->form == form) (*f)->form = (FORM *) 0; ++f; } form->rows = 0; form->cols = 0; form->maxfield = -1; form->maxpage = -1; form->field = (FIELD **) 0; } /* connect_fields - connect fields to form */ static int connect_fields(FORM *f, FIELD **x) { _PAGE * page; int nf, /* number of fields */ np; /* number of pages */ int i; f->field = x; f->maxfield = 0; f->maxpage = 0; if (!x) return (E_OK); /* null field array */ for (nf = 0, np = 0; x[nf]; ++nf) { if (nf == 0 || Status(x[nf], NEW_PAGE)) ++np; /* count pages */ if (x[nf]->form) return (E_CONNECTED); else x[nf]->form = f; /* connect field to form */ } if (nf == 0) return (E_BAD_ARGUMENT); /* no fields */ if (arrayAlloc(f->page, np, _PAGE)) { page = f->page; for (i = 0; i < nf; ++i) { if (i == 0) page->pmin = i; else if (Status(x[i], NEW_PAGE)) { page->pmax = i - 1; ++page; page->pmin = i; } merge(x[i], f); } page->pmax = nf - 1; f->maxfield = nf; f->maxpage = np; sort_form(f); return (E_OK); } return (E_SYSTEM_ERROR); } FORM * new_form(FIELD **field) { FORM *f; if (Alloc(f, FORM)) { *f = *_DEFAULT_FORM; if (connect_fields(f, field) == E_OK) { if (f->maxpage) { P(f) = 0; C(f) = _first_active(f); } else { P(f) = -1; C(f) = (FIELD *) 0; } return (f); } } (void) free_form(f); return ((FORM *) 0); } int free_form(FORM *f) { if (!f) return (E_BAD_ARGUMENT); if (Status(f, POSTED)) return (E_POSTED); disconnect_fields(f); Free(f->page); Free(f); return (E_OK); } int set_form_fields(FORM *f, FIELD **fields) { FIELD **p; int v; if (!f) return (E_BAD_ARGUMENT); if (Status(f, POSTED)) return (E_POSTED); p = f->field; disconnect_fields(f); if ((v = connect_fields(f, fields)) == E_OK) { if (f->maxpage) { P(f) = 0; C(f) = _first_active(f); } else { P(f) = -1; C(f) = (FIELD *) 0; } } else (void) connect_fields(f, p); /* reconnect original fields */ return (v); } FIELD ** form_fields(FORM *f) { return (Form(f)->field); } int field_count(FORM *f) { return (Form(f)->maxfield); } int scale_form(FORM *f, int *rows, int *cols) { if (!f) return (E_BAD_ARGUMENT); if (!f->field) return (E_NOT_CONNECTED); *rows = f->rows; *cols = f->cols; return (E_OK); } BOOLEAN data_behind(FORM *f) { return (OneRow(C(f)) ? B(f) != 0 : T(f) != 0); } /* _data_ahead - return ptr to last non-pad char in v[n] (v on failure) */ static char * _data_ahead(char *v, int pad, int n) { char *vend = v + n; while (vend > v && *(vend - 1) == pad) --vend; return (vend); } BOOLEAN data_ahead(FORM *f) { static char buf[ MAX_BUF ]; char *bptr = buf; WINDOW *w = W(f); FIELD *c = C(f); int ret = FALSE; int pad = Pad(c); int cols = c->cols; int dcols; int drows; int flag = cols > MAX_BUF - 1; int start; int chunk; if (flag) bptr = malloc(cols + 1); if (OneRow(c)) { dcols = c->dcols; start = B(f) + cols; while (start < dcols) { chunk = MIN(cols, dcols - start); (void) wmove(w, 0, start); (void) winnstr(w, bptr, chunk); if (bptr != _data_ahead(bptr, pad, chunk)) { ret = (TRUE); break; } start += cols; } } else { /* else multi-line field */ drows = c->drows; start = T(f) + c->rows; while (start < drows) { (void) wmove(w, start++, 0); (void) winnstr(w, bptr, cols); if (bptr != _data_ahead(bptr, pad, cols)) { ret = TRUE; break; } } } if (flag) (void) free(bptr); (void) wmove(w, Y(f), X(f)); return (ret); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "utility.h" int set_form_init(FORM *f, PTF_void func) { Form(f)->forminit = func; return (E_OK); } PTF_void form_init(FORM *f) { return (Form(f)->forminit); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "utility.h" int set_form_opts(FORM *f, OPTIONS opts) { Form(f)->opts = opts; return (E_OK); } OPTIONS form_opts(FORM *f) { return (Form(f) -> opts); } int form_opts_on(FORM *f, OPTIONS opts) { Form(f)->opts |= opts; return (E_OK); } int form_opts_off(FORM *f, OPTIONS opts) { Form(f)-> opts &= ~opts; return (E_OK); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "utility.h" int set_form_sub(FORM *f, WINDOW *window) { if (Status(f, POSTED)) return (E_POSTED); Form(f)->sub = window; return (E_OK); } WINDOW * form_sub(FORM *f) { return (Form(f)->sub); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "utility.h" /* * set_form_term */ int set_form_term(FORM *f, PTF_void func) { Form(f)->formterm = func; return (E_OK); } PTF_void form_term(FORM *f) { return (Form(f)->formterm); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "utility.h" int set_form_userptr(FORM *f, char *userptr) { Form(f)->usrptr = userptr; return (E_OK); } char * form_userptr(FORM *f) { return (Form(f)->usrptr); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "utility.h" int set_form_win(FORM *f, WINDOW *window) { if (Status(f, POSTED)) return (E_POSTED); Form(f)->win = window; return (E_OK); } WINDOW * form_win(FORM *f) { return (Form(f)->win); } # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. # # # MAPFILE HEADER START # # WARNING: STOP NOW. DO NOT MODIFY THIS FILE. # Object versioning must comply with the rules detailed in # # usr/src/lib/README.mapfiles # # You should not be making modifications here until you've read the most current # copy of that file. If you need help, contact a gatekeeper for guidance. # # MAPFILE HEADER END # $mapfile_version 2 SYMBOL_VERSION SUNW_1.1 { global: current_field; data_ahead; data_behind; dup_field; dynamic_field_info; field_arg; field_back; field_buffer; field_count; field_fore; field_index; field_info; field_init; field_just; field_opts; field_opts_off; field_opts_on; field_pad; field_status; field_term; field_type; field_userptr; form_driver; form_fields; form_init; form_opts; form_opts_off; form_opts_on; form_page; form_sub; form_term; form_userptr; form_win; free_field; free_fieldtype; free_form; link_field; link_fieldtype; move_field; new_field; new_fieldtype; new_form; new_page; pos_form_cursor; post_form; scale_form; set_current_field; set_field_back; set_field_buffer; set_field_fore; set_field_init; set_field_just; set_field_opts; set_field_pad; set_field_status; set_field_term; set_field_type; set_fieldtype_arg; set_fieldtype_choice; set_field_userptr; set_form_fields; set_form_init; set_form_opts; set_form_page; set_form_sub; set_form_term; set_form_userptr; set_form_win; set_max_field; set_new_page; unpost_form; }; SYMBOL_VERSION SUNWprivate_1.1 { global: _adjust_cursor; __advance; _beg_field; _beg_line; __braelist { ASSERT = { TYPE = OBJECT; SIZE = addrsize[10]; }; }; __braslist { ASSERT = { TYPE = OBJECT; SIZE = addrsize[10]; }; }; __bravar { ASSERT = { TYPE = OBJECT; SIZE = addrsize[10]; }; }; _buf_to_win; __cclass; __cflg { ASSERT = { TYPE = OBJECT; SIZE = addrsize; }; }; _checkchar; _checkfield; _clr_eof; _clr_eol; _clr_field; _copyarg; _data_beg; _data_end; _data_entry; _data_manipulation; _data_navigation; _DEFAULT_FIELD { ASSERT = { TYPE = OBJECT; SIZE = addrsize; }; }; _DEFAULT_FIELDTYPE { ASSERT = { TYPE = OBJECT; SIZE = addrsize; }; }; _DEFAULT_FORM { ASSERT = { TYPE = OBJECT; SIZE = addrsize; }; }; _del_char; _del_line; _del_prev; _del_word; _down_char; _down_field; _end_field; _end_line; __eptr_ { ASSERT = { TYPE = OBJECT; SIZE = addrsize; }; }; __execute; _field_navigation; _first_active; _first_field; _first_page; _freearg; __getrnge; _grow_field; _ins_char; _ins_line; _ins_mode; __i_size { TYPE = DATA; FILTER = libc.so.1; SIZE = 0x4; }; _last_field; _last_page; _left_char; _left_field; __lptr_ { ASSERT = { TYPE = OBJECT; SIZE = addrsize; }; }; _makearg; _misc_request; _new_line; _next_char; _next_choice; _nextchoice; _next_field; _next_line; _next_page; _next_word; _ovl_mode; _page_navigation; _pos_form_cursor; _prev_char; _prev_choice; _prevchoice; _prev_field; _prev_line; _prev_page; _prev_word; _right_char; _right_field; __rpop; __rpush; _scr_bchar; _scr_bhpage; _scr_bline; _scr_bpage; _scr_fchar; _scr_fhpage; _scr_fline; _scr_fpage; _scr_hbhalf; _scr_hbline; _scr_hfhalf; _scr_hfline; _set_current_field; _set_form_page; _sfirst_field; __size; _slast_field; _snext_field; __sp_ { ASSERT = { TYPE = OBJECT; SIZE = addrsize; }; }; _sprev_field; __st { ASSERT = { TYPE = OBJECT; SIZE = addrsize[51]; }; }; __stmax { ASSERT = { TYPE = OBJECT; SIZE = addrsize; }; }; _sync_attrs; _sync_buffer; _sync_field; _sync_linked; _sync_opts; TYPE_ALNUM { ASSERT = { TYPE = OBJECT; SIZE = addrsize; }; }; TYPE_ALPHA { ASSERT = { TYPE = OBJECT; SIZE = addrsize; }; }; TYPE_ENUM { ASSERT = { TYPE = OBJECT; SIZE = addrsize; }; }; TYPE_INTEGER { ASSERT = { TYPE = OBJECT; SIZE = addrsize; }; }; TYPE_NUMERIC { ASSERT = { TYPE = OBJECT; SIZE = addrsize; }; }; TYPE_REGEXP { ASSERT = { TYPE = OBJECT; SIZE = addrsize; }; }; _up_char; _update_current; _up_field; _validate; _validation; _whsp_beg; _whsp_end; _win_to_buf; __xpop; __xpush; __loc1 { TYPE = DATA; FILTER = libc.so.1; SIZE = addrsize; }; local: *; }; /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "utility.h" int post_form(FORM *f) { int x, y, v; if (!f) return (E_BAD_ARGUMENT); if (Status(f, POSTED)) return (E_POSTED); if (!f->field) return (E_NOT_CONNECTED); getmaxyx(Sub(f), y, x); if (f->rows > y || f->cols > x) return (E_NO_ROOM); v = _set_form_page(f, P(f), C(f)); if (v != E_OK) return (v); Set(f, POSTED); init_form(f); init_field(f); (void) _update_current(f); return (E_OK); } int unpost_form(FORM *f) { if (!f) return (E_BAD_ARGUMENT); if (!Status(f, POSTED)) return (E_NOT_POSTED); if (Status(f, DRIVER)) return (E_BAD_STATE); term_field(f); term_form(f); (void) werase(Sub(f)); (void) delwin(W(f)); W(f) = (WINDOW *) 0; Clr(f, POSTED); return (E_OK); } /* pos_form_cursor - move to cursor position and sync up */ int pos_form_cursor(FORM *f) { if (!f) return (E_BAD_ARGUMENT); if (!Status(f, POSTED)) return (E_NOT_POSTED); return (_pos_form_cursor(f)); } int set_current_field(FORM *f, FIELD *c) { if (!f || !c || c->form != f) return (E_BAD_ARGUMENT); if (!Opt(c, O_ACTIVE) || !Opt(c, O_VISIBLE)) return (E_REQUEST_DENIED); if (!Status(f, POSTED)) { C(f) = c; P(f) = c->page; return (E_OK); } if (Status(f, DRIVER)) return (E_BAD_STATE); if (c != C(f)) { if (_validate(f)) { int v; term_field(f); if (c -> page != P(f)) { /* page change */ term_form(f); v = _set_form_page(f, c->page, c); init_form(f); } else v = _set_current_field(f, c); init_field(f); (void) _update_current(f); return (v); } else return (E_INVALID_FIELD); } return (E_OK); } FIELD * current_field(FORM *f) { return (C(Form(f))); } int field_index(FIELD *f) { if (f && f->form) return (f->index); else return (-1); } int set_form_page(FORM *f, int page) { if (!f || !ValidPage(f, page)) return (E_BAD_ARGUMENT); if (!Status(f, POSTED)) { P(f) = page; C(f) = _first_active(f); return (E_OK); } if (Status(f, DRIVER)) return (E_BAD_STATE); if (page != P(f)) { if (_validate(f)) { int v; term_field(f); term_form(f); v = _set_form_page(f, page, (FIELD *) 0); init_form(f); init_field(f); (void) _update_current(f); return (v); } else return (E_INVALID_FIELD); } return (E_OK); } /* * form_page */ int form_page(FORM *f) { return (P(Form(f))); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* * Copyright (c) 2018, Joyent, Inc. */ #include #include #include "utility.h" /* this code was taken from regcmp(3C) */ #define SSIZE 16 #define TGRP 48 #define A256 02 #define ZERO 01 #define NBRA 10 #define CIRCFL 32; #define SLOP 5 #define FEOF 0 /* This was originally EOF but it clashes with the header */ /* definition so it was changed to FEOF */ #define CBRA 60 #define GRP 40 #define SGRP 56 #define PGRP 68 #define EGRP 44 #define RNGE 03 #define CCHR 20 #define CDOT 64 #define CCL 24 #define NCCL 8 #define CDOL 28 #define FCEOF 52 /* This was originally CEOF but it clashes with the header */ /* definition so it was changed to FCEOF */ #define CKET 12 #define STAR 01 #define PLUS 02 #define MINUS 16 intptr_t *__sp_; intptr_t *__stmax; extern int __i_size; /*ARGSUSED2*/ char * libform_regcmp(char *cs1, char *cs2) { char c; char *ep, *sp; int *adx; int i, cflg; char *lastep, *sep, *eptr; int nbra, ngrp; int cclcnt; intptr_t stack[SSIZE]; __sp_ = stack; *__sp_ = -1; __stmax = &stack[SSIZE]; adx = (int *)&cs1; i = nbra = ngrp = 0; while (*adx) i += __size((char *)(intptr_t)*adx++); adx = (int *)&cs1; sp = (char *)(intptr_t)*adx++; if ((sep = ep = malloc((unsigned)(2 * i + SLOP))) == NULL) return (NULL); if ((c = *sp++) == FEOF) goto cerror; if (c == '^') { c = *sp++; *ep++ = CIRCFL; } if ((c == '*') || (c == '+') || (c == '{')) goto cerror; sp--; for (;;) { if ((c = *sp++) == FEOF) { if (*adx) { sp = (char *)(intptr_t)*adx++; continue; } *ep++ = FCEOF; if (--nbra > NBRA || *__sp_ != -1) goto cerror; __i_size = (int)(ep - sep); return (sep); } if ((c != '*') && (c != '{') && (c != '+')) lastep = ep; switch (c) { case '(': if (!__rpush(ep)) goto cerror; *ep++ = CBRA; *ep++ = -1; continue; case ')': if (!(eptr = (char *)__rpop())) goto cerror; if ((c = *sp++) == '$') { if ('0' > (c = *sp++) || c > '9') goto cerror; *ep++ = CKET; *ep++ = *++eptr = nbra++; *ep++ = (c-'0'); continue; } *ep++ = EGRP; *ep++ = ngrp++; sp--; switch (c) { case '+': *eptr = PGRP; break; case '*': *eptr = SGRP; break; case '{': *eptr = TGRP; break; default: *eptr = GRP; continue; } i = (int)(ep - eptr - 2); for (cclcnt = 0; i >= 256; cclcnt++) i -= 256; if (cclcnt > 3) goto cerror; *eptr |= cclcnt; *++eptr = (char)i; continue; case '\\': *ep++ = CCHR; if ((c = *sp++) == FEOF) goto cerror; *ep++ = c; continue; case '{': *lastep |= RNGE; cflg = 0; nlim: if ((c = *sp++) == '}') goto cerror; i = 0; do { if ('0' <= c && c <= '9') i = (i*10+(c-'0')); else goto cerror; } while (((c = *sp++) != '}') && (c != ',')); if (i > 255) goto cerror; *ep++ = (char)i; if (c == ',') { if (cflg++) goto cerror; if ((c = *sp++) == '}') { *ep++ = -1; continue; } else { sp--; goto nlim; } } if (!cflg) *ep++ = (char)i; else if ((ep[-1]&0377) < (ep[-2]&0377)) goto cerror; continue; case '.': *ep++ = CDOT; continue; case '+': if (*lastep == CBRA || *lastep == CKET) goto cerror; *lastep |= PLUS; continue; case '*': if (*lastep == CBRA || *lastep == CKET) goto cerror; *lastep |= STAR; continue; case '$': if ((*sp != FEOF) || (*adx)) goto defchar; *ep++ = CDOL; continue; case '[': *ep++ = CCL; *ep++ = 0; cclcnt = 1; if ((c = *sp++) == '^') { c = *sp++; ep[-2] = NCCL; } do { if (c == FEOF) goto cerror; if ((c == '-') && (cclcnt > 1) && (*sp != ']')) { *ep = ep[-1]; ep++; ep[-2] = MINUS; cclcnt++; continue; } *ep++ = c; cclcnt++; } while ((c = *sp++) != ']'); lastep[1] = (char)cclcnt; continue; defchar: default: *ep++ = CCHR; *ep++ = c; } } cerror: free(sep); return (0); } int __size(char *strg) { int i; i = 1; while (*strg++) i++; return (i); } intptr_t __rpop(void) { return ((*__sp_ == -1)?0:*__sp_--); } int __rpush(char *ptr) { if (__sp_ >= __stmax) return (0); *++__sp_ = (intptr_t)ptr; return (1); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* * Copyright (c) 2018, Joyent, Inc. */ #include #include #include #include "utility.h" /* * this code was taken from regcmp(3C) */ /*VARARGS*/ /*ARGSUSED*/ #define SSIZE 50 #define TGRP 48 #define A256 01 #define A512 02 #define A768 03 #define NBRA 10 #define CIRCFL 32 #define CBRA 60 #define GRP 40 #define SGRP 56 #define PGRP 68 #define EGRP 44 #define RNGE 03 #define CCHR 20 #define CDOT 64 #define CCL 24 #define NCCL 8 #define CDOL 28 #define FCEOF 52 /* This was originally CEOF but it clashes with the header */ /* definition so it was changed to FCEOF */ #define CKET 12 #define STAR 01 #define PLUS 02 #define MINUS 16 char *__braslist[NBRA]; char *__braelist[NBRA]; extern char *__loc1; intptr_t __bravar[NBRA]; intptr_t *__st[SSIZE + 1]; intptr_t *__eptr_, *__lptr_; intptr_t __cflg; char * libform_regex(char *addrc, char *addrl, char *a1) { intptr_t cur, in; intptr_t *adx; char *p1, *p2; for (in = 0; in < NBRA; in++) { __braslist[in] = 0; __bravar[in] = -1; } __cflg = 0; cur = __execute(addrc, addrl); adx = (intptr_t *)&a1; for (in = 0; in < NBRA; in++) { if (((p1 = __braslist[in]) != 0) && (__bravar[in] >= 0)) { p2 = (char *)adx[__bravar[in]]; while (p1 < __braelist[in]) *p2++ = *p1++; *p2 = '\0'; } } if (!__cflg) return ((addrl == (char *)cur) ? (char *)0 : (char *)cur); else return ((char *)cur); } intptr_t __execute(char *addrc, char *addrl) { char *p1, *p2, c; intptr_t i; p1 = addrl; p2 = addrc; __eptr_ = (intptr_t *)&__st[SSIZE]; __lptr_ = (intptr_t *)&__st[0]; if (*p2 == CIRCFL) { __loc1 = p1; return ((i = __advance(p1, ++p2)) ? i : (intptr_t)addrl); } /* fast check for first character */ if (*p2 == CCHR) { c = p2[1]; do { if (*p1 != c) continue; __eptr_ = (intptr_t *)&__st[SSIZE]; __lptr_ = (intptr_t *)&__st[0]; if (i = __advance(p1, p2)) { __loc1 = p1; return (i); } } while (*p1++); return ((intptr_t)addrl); } /* regular algorithm */ do { __eptr_ = (intptr_t *)&__st[SSIZE]; __lptr_ = (intptr_t *)&__st[0]; if (i = __advance(p1, p2)) { __loc1 = p1; return (i); } } while (*p1++); return ((intptr_t)addrl); } intptr_t __advance(char *alp, char *aep) { char *lp, *ep, *curlp; char *sep, *dp; intptr_t i, lcnt, dcnt, gflg; lp = alp; ep = aep; gflg = 0; for (; ; ) { switch (*ep++) { case CCHR: if (*ep++ == *lp++) continue; return (0); case EGRP|RNGE: return ((intptr_t)lp); case EGRP: case GRP: ep++; continue; case EGRP|STAR: (void) __xpop(0); /* FALLTHROUGH */ case EGRP|PLUS: (void) __xpush(0, ++ep); return ((intptr_t)lp); case CDOT: if (*lp++) continue; return (0); case CDOL: if (*lp == 0) continue; lp++; return (0); case FCEOF: __cflg = 1; return ((intptr_t)lp); case TGRP: case TGRP|A768: case TGRP|A512: case TGRP|A256: i = (((ep[-1] & 03) << 8) + (*ep) & 0377); ep++; (void) __xpush(0, ep + i + 2); (void) __xpush(0, ++ep); (void) __xpush(0, ++ep); gflg = 1; (void) __getrnge(&lcnt, &dcnt, &ep[i]); while (lcnt--) if (!(lp = (char *)__advance(lp, ep))) return (0); (void) __xpush(1, curlp = lp); while (dcnt--) if (!(dp = (char *)__advance(lp, ep))) break; else (void) __xpush(1, lp = dp); ep = (char *)__xpop(0); goto star; case CCHR|RNGE: sep = ep++; (void) __getrnge(&lcnt, &dcnt, ep); while (lcnt--) if (*lp++ != *sep) return (0); curlp = lp; while (dcnt--) if (*lp++ != *sep) break; if (dcnt < 0) lp++; ep += 2; goto star; case CDOT|RNGE: (void) __getrnge(&lcnt, &dcnt, ep); while (lcnt--) if (*lp++ == '\0') return (0); curlp = lp; while (dcnt--) if (*lp++ == '\0') break; if (dcnt < 0) lp++; ep += 2; goto star; case CCL|RNGE: case NCCL|RNGE: (void) __getrnge(&lcnt, &dcnt, (ep + (*ep & 0377))); while (lcnt--) if (!__cclass(ep, *lp++, ep[-1] == (CCL | RNGE))) return (0); curlp = lp; while (dcnt--) if (!__cclass(ep, *lp++, ep[-1] == (CCL|RNGE))) break; if (dcnt < 0) lp++; ep += (*ep + 2); goto star; case CCL: if (__cclass(ep, *lp++, 1)) { ep += *ep; continue; } return (0); case NCCL: if (__cclass(ep, *lp++, 0)) { ep += *ep; continue; } return (0); case CBRA: __braslist[*ep++] = lp; continue; case CKET: __braelist[*ep] = lp; __bravar[*ep] = ep[1]; ep += 2; continue; case CDOT|PLUS: if (*lp++ == '\0') return (0); /* FALLTHROUGH */ case CDOT|STAR: curlp = lp; while (*lp++) ; goto star; case CCHR|PLUS: if (*lp++ != *ep) return (0); /* FALLTHROUGH */ case CCHR|STAR: curlp = lp; while (*lp++ == *ep) ; ep++; goto star; case PGRP: case PGRP|A256: case PGRP|A512: case PGRP|A768: if (!(lp = (char *)__advance(lp, ep+1))) return (0); /* FALLTHROUGH */ case SGRP|A768: case SGRP|A512: case SGRP|A256: case SGRP: i = (((ep[-1]&03) << 8) + (*ep & 0377)); ep++; (void) __xpush(0, ep + i); (void) __xpush(1, curlp = lp); while (i = __advance(lp, ep)) (void) __xpush(1, lp = (char *)i); ep = (char *)__xpop(0); gflg = 1; goto star; case CCL|PLUS: case NCCL|PLUS: if (!__cclass(ep, *lp++, ep[-1] == (CCL | PLUS))) return (0); /* FALLTHROUGH */ case CCL|STAR: case NCCL|STAR: curlp = lp; while (__cclass(ep, *lp++, ((ep[-1] == (CCL | STAR)) || (ep[-1] == (CCL | PLUS))))) ; ep += *ep; goto star; star: do { if (!gflg) lp--; else if (!(lp = (char *)__xpop(1))) break; if (i = __advance(lp, ep)) return (i); } while (lp > curlp); return (0); default: return (0); } } } intptr_t __cclass(char *aset, char ac, intptr_t af) { char *set, c; intptr_t n; set = (char *)aset; if ((c = ac) == 0) return (0); n = *set++; while (--n) { if (*set == MINUS) { if ((set[2] - set[1]) < 0) return (0); if (*++set <= c) { if (c <= *++set) return (af); } else ++set; ++set; n -= 2; continue; } if (*set++ == c) return (af); } return (!af); } intptr_t __xpush(intptr_t i, char *p) { if (__lptr_ >= __eptr_) { (void) write(2, "stack overflow\n", 15); (void) exit(1); } if (i) *__lptr_++ = (intptr_t)p; else *__eptr_-- = (intptr_t)p; return (1); } intptr_t __xpop(intptr_t i) { if (i) return ((__lptr_ < (intptr_t *)&__st[0]) ? 0 : *--__lptr_); else return ((__eptr_ > (intptr_t *)&__st[SSIZE]) ? 0 : *++__eptr_); } intptr_t __getrnge(intptr_t *i, intptr_t *j, char *k) { *i = (*k++&0377); if (*k == (char)-1) *j = 20000; else *j = ((*k&0377) - *i); return (1); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include #include "utility.h" /* * TYPE_ALNUM * * usage: * set_field_type(f, TYPE_ALNUM, width); * * int width; minimum token width */ static char * make_alnum(va_list *); static char * copy_alnum(char *); static void free_alnum(char *); static int fcheck_alnum(FIELD *, char *); static int ccheck_alnum(int, char *); static FIELDTYPE typeALNUM = { ARGS, /* status */ 1, /* ref */ (FIELDTYPE *) 0, /* left */ (FIELDTYPE *) 0, /* right */ make_alnum, /* makearg */ copy_alnum, /* copyarg */ free_alnum, /* freearg */ fcheck_alnum, /* fcheck */ ccheck_alnum, /* ccheck */ (PTF_int) 0, /* next */ (PTF_int) 0, /* prev */ }; FIELDTYPE * TYPE_ALNUM = &typeALNUM; static char * make_alnum(va_list *ap) { int * width; if (Alloc(width, int)) *width = va_arg(*ap, int); return ((char *) width); } static char * copy_alnum(char *arg) { int * width; if (Alloc(width, int)) *width = *((int *) arg); return ((char *) width); } static void free_alnum(char *arg) { Free(arg); } static int fcheck_alnum(FIELD *f, char *arg) { int width = *((int *) arg); int n = 0; char *v = field_buffer(f, 0); while (*v && *v == ' ') ++v; if (*v) { char * vbeg = v; while (*v && isalnum(*v)) ++v; n = (int) (v - vbeg); while (*v && *v == ' ') ++v; } return (*v || n < width ? FALSE : TRUE); } /*ARGSUSED*/ static int ccheck_alnum(int c, char *arg) { return (isalnum(c)); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include #include "utility.h" /* * TYPE_ALPHA standard type * * usage: * set_field_type(f, TYPE_ALPHA, width); * * int width; minimum token width */ static char *make_alpha(va_list *); static char *copy_alpha(char *); static void free_alpha(char *); static int fcheck_alpha(FIELD *, char *); static int ccheck_alpha(int, char *); static FIELDTYPE typeALPHA = { ARGS, /* status */ 1, /* ref */ (FIELDTYPE *) 0, /* left */ (FIELDTYPE *) 0, /* right */ make_alpha, /* makearg */ copy_alpha, /* copyarg */ free_alpha, /* freearg */ fcheck_alpha, /* fcheck */ ccheck_alpha, /* ccheck */ (PTF_int) 0, /* next */ (PTF_int) 0, /* prev */ }; FIELDTYPE * TYPE_ALPHA = &typeALPHA; static char * make_alpha(va_list *ap) { int * width; if (Alloc(width, int)) *width = va_arg(*ap, int); return ((char *) width); } static char * copy_alpha(char *arg) { int * width; if (Alloc(width, int)) *width = *((int *) arg); return ((char *) width); } static void free_alpha(char *arg) { Free(arg); } static int fcheck_alpha(FIELD *f, char *arg) { int width = *((int *) arg); int n = 0; char * v = field_buffer(f, 0); while (*v && *v == ' ') ++v; if (*v) { char * vbeg = v; while (*v && isalpha(*v)) ++v; n = v - vbeg; while (*v && *v == ' ') ++v; } return (*v || n < width ? FALSE : TRUE); } /*ARGSUSED*/ static int ccheck_alpha(int c, char *arg) { return (isalpha(c)); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include #include "utility.h" /* * TYPE_ENUM standard type * * usage: * set_field_type(f, TYPE_ENUM, list, checkcase, checkuniq); * * char ** list; list of acceptable strings * int checkcase; TRUE - upper/lower case is significant * int checkuniq; TRUE - unique match required * */ typedef struct { char ** list; int checkcase; int checkuniq; int count; } ENUM; static char * make_enum(va_list *); static char * copy_enum(char *); static void free_enum(char *); static int fcheck_enum(FIELD *, char *); static int next_enum(FIELD *, char *); static int prev_enum(FIELD *, char *); static FIELDTYPE typeENUM = { ARGS | CHOICE, /* status */ 1, /* ref */ (FIELDTYPE *) 0, /* left */ (FIELDTYPE *) 0, /* right */ make_enum, /* makearg */ copy_enum, /* copyarg */ free_enum, /* freearg */ fcheck_enum, /* fcheck */ (PTF_int) 0, /* ccheck */ next_enum, /* next */ prev_enum, /* prev */ }; FIELDTYPE * TYPE_ENUM = &typeENUM; static char * make_enum(va_list *ap) { ENUM * n; if (Alloc(n, ENUM)) { char ** v; n -> list = va_arg(*ap, char **); n -> checkcase = va_arg(*ap, int); n -> checkuniq = va_arg(*ap, int); for (v = n -> list; *v; ++v) ; n -> count = (int) (v - n -> list); } return ((char *) n); } static char * copy_enum(char *arg) { ENUM * n; if (Alloc(n, ENUM)) *n = *((ENUM *) arg); return ((char *) n); } static void free_enum(char *arg) { Free(arg); } #define NO_MATCH 0 #define PARTIAL_MATCH 1 #define EXACT_MATCH 2 static int cmp(char *x, char *v, int checkcase) { while (*v && *v == ' ') /* remove leading blanks */ ++v; while (*x && *x == ' ') /* remove leading blanks */ ++x; if (*v == '\0') return (*x == '\0' ? EXACT_MATCH : NO_MATCH); if (checkcase) { /* case is significant */ while (*x++ == *v) if (*v++ == '\0') return (EXACT_MATCH); } else { /* ignore case */ while (toupper (*x++) == toupper (*v)) if (*v++ == '\0') return (EXACT_MATCH); } while (*v && *v == ' ') /* remove trailing blanks */ ++v; if (*v) return (NO_MATCH); else return (*--x ? PARTIAL_MATCH : EXACT_MATCH); } static int fcheck_enum(FIELD *f, char *arg) { ENUM * n = (ENUM *) arg; char ** list = n -> list; int checkcase = n -> checkcase; int checkuniq = n -> checkuniq; int m; char * v = field_buffer(f, 0); char * x; while (x = *list++) if (m = cmp(x, v, checkcase)) { char * value = x; if (checkuniq && m != EXACT_MATCH) while (x = *list++) if (m = cmp(x, v, checkcase)) { if (m == EXACT_MATCH) { value = x; break; } else value = (char *) 0; } if (! value) return (FALSE); (void) set_field_buffer(f, 0, value); return (TRUE); } return (FALSE); } static int next_enum(FIELD *f, char *arg) { ENUM * n = (ENUM *) arg; char ** list = n -> list; int checkcase = n -> checkcase; int count = n -> count; char * v = field_buffer(f, 0); while (count--) if (cmp(*list++, v, checkcase) == EXACT_MATCH) break; if (count <= 0) list = n -> list; if (count >= 0 || cmp("", v, checkcase) == EXACT_MATCH) { (void) set_field_buffer(f, 0, *list); return (TRUE); } return (FALSE); } static int prev_enum(FIELD *f, char *arg) { ENUM * n = (ENUM *) arg; char ** list = n -> list + n -> count - 1; int checkcase = n -> checkcase; int count = n -> count; char * v = field_buffer(f, 0); while (count--) if (cmp(*list--, v, checkcase) == EXACT_MATCH) break; if (count <= 0) list = n -> list + n -> count - 1; if (count >= 0 || cmp("", v, checkcase) == EXACT_MATCH) { (void) set_field_buffer(f, 0, *list); return (TRUE); } return (FALSE); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include #include "utility.h" /* * TYPE_INTEGER standard type * * usage: * set_field_type(f, TYPE_INTEGER, precision, vmin, vmax); * * int precision; for padding with leading zeros * double vmin; minimum acceptable value * double vmax; maximum acceptable value */ static char *make_int(va_list *); static char *copy_int(char *); static void free_int(char *); static int fcheck_int(FIELD *, char *); static int ccheck_int(int, char *); typedef struct { int prec; long vmin; long vmax; } INTEGER; static FIELDTYPE typeINTEGER = { ARGS, /* status */ 1, /* ref */ (FIELDTYPE *) 0, /* left */ (FIELDTYPE *) 0, /* right */ make_int, /* makearg */ copy_int, /* copyarg */ free_int, /* freearg */ fcheck_int, /* fcheck */ ccheck_int, /* ccheck */ (PTF_int) 0, /* next */ (PTF_int) 0, /* prev */ }; FIELDTYPE * TYPE_INTEGER = &typeINTEGER; static char * make_int(va_list *ap) { INTEGER * n; if (Alloc(n, INTEGER)) { n -> prec = va_arg(*ap, int); n -> vmin = va_arg(*ap, long); n -> vmax = va_arg(*ap, long); } return ((char *) n); } static char * copy_int(char *arg) { INTEGER *n; if (Alloc(n, INTEGER)) *n = *((INTEGER *) arg); return ((char *) n); } static void free_int(char *arg) { Free(arg); } static int fcheck_int(FIELD *f, char *arg) { INTEGER * n = (INTEGER *) arg; long vmin = n -> vmin; long vmax = n -> vmax; int prec = n -> prec; char * x = field_buffer(f, 0); char buf[80]; while (*x && *x == ' ') ++x; if (*x) { char * t = x; if (*x == '-') ++x; while (*x && isdigit(*x)) ++x; while (*x && *x == ' ') ++x; if (! *x) { long v = atol(t); if (vmin >= vmax || (v >= vmin && v <= vmax)) { (void) sprintf(buf, "%.*ld", prec, v); (void) set_field_buffer(f, 0, buf); return (TRUE); } } } return (FALSE); } #define charok(c) (isdigit(c) || c == '-') /*ARGSUSED*/ static int ccheck_int(int c, char *arg) { return (charok(c)); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include #include "utility.h" /* * TYPE_NUMERIC standard type * * usage: * set_field_type(f, TYPE_NUMERIC, precision, vmin, vmax); * * int precision; digits to right of decimal point * double vmin; minimum acceptable value * double vmax; maximum acceptable value */ static char *make_num(va_list *); static char *copy_num(char *); static void free_num(char *); static int fcheck_num(FIELD *, char *); static int ccheck_num(int, char *); typedef struct { int prec; double vmin; double vmax; } NUMERIC; static FIELDTYPE typeNUMERIC = { ARGS, /* status */ 1, /* ref */ (FIELDTYPE *) 0, /* left */ (FIELDTYPE *) 0, /* right */ make_num, /* makearg */ copy_num, /* copyarg */ free_num, /* freearg */ fcheck_num, /* fcheck */ ccheck_num, /* ccheck */ (PTF_int) 0, /* next */ (PTF_int) 0, /* prev */ }; FIELDTYPE * TYPE_NUMERIC = &typeNUMERIC; static char * make_num(va_list *ap) { NUMERIC * n; if (Alloc(n, NUMERIC)) { n -> prec = va_arg(*ap, int); n -> vmin = va_arg(*ap, double); n -> vmax = va_arg(*ap, double); } return ((char *) n); } static char * copy_num(char *arg) { NUMERIC *n; if (Alloc(n, NUMERIC)) *n = *((NUMERIC *) arg); return ((char *) n); } static void free_num(char *arg) { Free(arg); } static int fcheck_num(FIELD *f, char *arg) { NUMERIC * n = (NUMERIC *) arg; double vmin = n -> vmin; double vmax = n -> vmax; int prec = n -> prec; char * x = field_buffer(f, 0); char buf[80]; while (*x && *x == ' ') ++x; if (*x) { char * t = x; if (*x == '-') ++x; while (*x && isdigit(*x)) ++x; if (*x == '.') { ++x; while (*x && isdigit(*x)) ++x; } while (*x && *x == ' ') ++x; if (! *x) { double v = atof(t); if (vmin >= vmax || (v >= vmin && v <= vmax)) { (void) sprintf(buf, "%.*f", prec, v); (void) set_field_buffer(f, 0, buf); return (TRUE); } } } return (FALSE); } #define charok(c) (isdigit(c) || c == '-' || c == '.') /*ARGSUSED*/ static int ccheck_num(int c, char *arg) { return (charok(c)); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /*LINTLIBRARY*/ #include #include #include "utility.h" /* * TYPE_REGEXP standard type * * usage: * set_field_type(f, TYPE_REGEXP, expression); * * char * expression; regular expression regcmp(3C) */ extern char *libform_regcmp(char *, char *); extern char *libform_regex(char *, char *, char *); static char *make_rexp(va_list *); static char *copy_rexp(char *); static void free_rexp(char *); static int fcheck_rexp(FIELD *, char *); static FIELDTYPE typeREGEXP = { ARGS, /* status */ 1, /* ref */ (FIELDTYPE *) 0, /* left */ (FIELDTYPE *) 0, /* right */ make_rexp, /* makearg */ copy_rexp, /* copyarg */ free_rexp, /* freearg */ fcheck_rexp, /* fcheck */ (PTF_int) 0, /* ccheck */ (PTF_int) 0, /* next */ (PTF_int) 0, /* prev */ }; FIELDTYPE * TYPE_REGEXP = &typeREGEXP; static char * make_rexp(va_list *ap) { return (libform_regcmp(va_arg(*ap, char *), NULL)); /* (...)$n will dump core */ } static char * copy_rexp(char *arg) { char *rexp; if (arrayAlloc(rexp, (strlen(arg) + 1), char)) (void) strcpy(rexp, arg); return (rexp); } static void free_rexp(char *arg) { Free(arg); } static int fcheck_rexp(FIELD *f, char *arg) { return (libform_regex(arg, field_buffer(f, 0), NULL) ? TRUE : FALSE); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "utility.h" #define Scrollable(f) ((f)->drows > (f)->rows || \ (f)->dcols > (f)->cols) #define Connected(f) ((f) -> form != (FORM *) 0) #define OnPage(f) ((f) -> page == P((f) -> form)) #define Posted(f) (Status((f) -> form, POSTED)) #define Visible(f) (Opt(f, O_VISIBLE) && OnPage(f)) #define isCurrent(f) ((f) == C((f) -> form)) #define Justified(f) (Just(f) != NO_JUSTIFICATION && \ OneRow(f) && Opt(f, O_STATIC) && \ f->dcols == f->cols) /* _data_beg - return ptr to first non-blank char in v[n] (v on failure) */ char * _data_beg(char *v, int n) { char *vend = v + n; while (v < vend && *v == ' ') ++v; return (v == vend ? v - n : v); } /* * _data_end - return ptr to char after last * non-blank char in v[n] (v on failure) */ char * _data_end(char *v, int n) { char *vend = v + n; while (vend > v && *(vend - 1) == ' ') --vend; return (vend); } /* _whsp_beg - return ptr to first blank in v[n] (v on failure) */ char * _whsp_beg(char *v, int n) { char * vend = v + n; while (v < vend && *v != ' ') ++v; return (v == vend ? v - n : v); } /* _whsp_end - return ptr to char after last blank in v[n] (v on failure) */ char * _whsp_end(char *v, int n) { char * vend = v + n; while (vend > v && *(vend - 1) != ' ') --vend; return (vend); } /* * _adjust_cursor - adjust cursor based on * offset of v from beginning of field buffer */ void _adjust_cursor(FORM *f, char *v) { int pos = (int) (v - Buf(C(f))); Y(f) = pos / Xmax(f); X(f) = pos - Y(f) * Xmax(f); if (Y(f) >= Ymax(f)) Y(f) = 0; } /* * _buf_to_win - copy buffer to window(trailing * blanks on each line are not copied) */ void _buf_to_win(FIELD *f, WINDOW *w) { char * v = Buf(f); int xmax, ymax, y, n; getmaxyx(w, ymax, xmax); for (y = 0; y < ymax; ++y) { if ((n = (int) (_data_end(v, xmax) - v)) != 0) { (void) wmove(w, y, 0); (void) waddnstr(w, v, n); } v += xmax; } } /* _win_to_buf - copy window to buffer */ void _win_to_buf(WINDOW *w, FIELD *f) { int i; int size = BufSize(f); int pad = Pad(f); char * v = Buf(f); (void) wmove(w, 0, 0); (void) winnstr(w, v, size); if (pad != ' ') for (i = 0; i < size; ++i, ++v) if (*v == pad) *v = ' '; /* replace pad char with blank */ } /* _pos_form_cursor - move to cursor position and sync up cursor */ int _pos_form_cursor(FORM *f) { WINDOW * w = W(f); FIELD * c = C(f); if (!w) return (E_SYSTEM_ERROR); (void) wmove(w, Y(f), X(f)); if (Opt(c, O_PUBLIC)) { if (Scrollable(c)) { int row, col; if (OneRow(c)) { row = c->frow; col = c->fcol + X(f) - B(f); } else { row = c -> frow + Y(f) - T(f); col = c -> fcol + X(f); } (void) wmove(Sub(f), row, col); wcursyncup(Sub(f)); } else wcursyncup(w); } else { (void) wmove(Sub(f), c -> frow, c -> fcol); wcursyncup(Sub(f)); } return (E_OK); } /* _update_current - sync up current field */ int _update_current(FORM *f) { WINDOW * w = W(f); FIELD * c = C(f); if (!w) return (E_SYSTEM_ERROR); if (Opt(c, O_PUBLIC)) { if (Scrollable(c)) { if (OneRow(c)) { int xmax = B(f) + c->cols; if (X(f) < B(f)) B(f) = X(f); else if (X(f) >= xmax) B(f) = X(f) - c->cols + 1; (void) copywin(w, Sub(f), 0, B(f), c->frow, c->fcol, c->frow, c->fcol + c->cols - 1, FALSE); } else { int ymax = T(f) + c -> rows; int ys, ye; if (Y(f) < T(f)) { T(f) = Y(f); Set(c, TOP_CHG); } if (Y(f) >= ymax) { T(f) = Y(f) - c -> rows + 1; Set(c, TOP_CHG); } if (Status(c, TOP_CHG)) { ys = T(f); ye = ys + c -> rows; Clr(c, TOP_CHG); } else { /* intersect changed lines with visible lines */ for (ys = T(f); ys < ymax; ++ys) if (is_linetouched(w, ys)) break; for (ye = ys; ye < ymax; ++ye) if (! is_linetouched(w, ye)) break; } if (ye - ys) { (void) copywin(w, Sub(f), ys, 0, c -> frow + ys - T(f), c -> fcol, c -> frow + ye - T(f) - 1, c -> fcol + c -> cols - 1, FALSE); } } wsyncup(Sub(f)); } else wsyncup(w); } (void) untouchwin(w); return (_pos_form_cursor(f)); } /* justify - justify field f in window w as given by Just(f) */ static void justify(FIELD *f, WINDOW *w) { char * v = _data_beg(Buf(f), BufSize(f)); char * vend = _data_end(Buf(f), BufSize(f)); int n = (int) (vend - v); int x = 0; if (n) { switch (Just(f)) { case JUSTIFY_LEFT: break; case JUSTIFY_CENTER: x = (f -> cols - n) / 2; break; case JUSTIFY_RIGHT: x = f -> cols - n; break; } (void) wmove(w, 0, x); (void) waddnstr(w, v, n); } } /* unjustify - left justify field f in window w for editing */ static void unjustify(FIELD *f, WINDOW *w) { char * v = _data_beg(Buf(f), BufSize(f)); char * vend = _data_end(Buf(f), BufSize(f)); int n = (int) (vend - v); if (n) { (void) wmove(w, 0, 0); (void) waddnstr(w, v, n); } } /* _sync_buffer - sync current field with characters in window */ void _sync_buffer(FORM *f) { if (Status(f, WIN_CHG)) { Clr(f, WIN_CHG); Set(f, BUF_CHG); _win_to_buf(W(f), C(f)); (void) wmove(W(f), Y(f), X(f)); } } /* _sync_linked - sync fields linked to field f */ int _sync_linked(FIELD *f) { FIELD * p = f -> link; int err = 0; while (p != f) { if (_sync_field(p) != E_OK) ++err; p = p -> link; } return (err ? E_SYSTEM_ERROR : E_OK); } /* display_field - display field f */ static int display_field(FIELD *f) { WINDOW * w = derwin(Sub(f -> form), f -> rows, f -> cols, f -> frow, f -> fcol); if (!w) return (FALSE); wbkgdset(w, Pad(f) | Back(f)); (void) wattrset(w, Fore(f)); (void) werase(w); if (Opt(f, O_PUBLIC)) { if (Justified(f)) justify(f, w); else _buf_to_win(f, w); } wsyncup(w); (void) delwin(w); Clr(f, TOP_CHG); return (TRUE); } /* erase_field - erase field f */ static int erase_field(FIELD *f) { WINDOW * w = derwin(Sub(f -> form), f -> rows, f -> cols, f -> frow, f -> fcol); if (!w) return (FALSE); (void) werase(w); wsyncup(w); (void) delwin(w); return (TRUE); } /* _sync_field - sync the field after a change to the field buffer */ int _sync_field(FIELD *f) { int v = TRUE; if (Connected(f) && Posted(f) && Visible(f)) { if (isCurrent(f)) { FORM * p = f -> form; WINDOW * w = W(p); Clr(p, WIN_CHG | BUF_CHG); Y(p) = 0; X(p) = 0; T(p) = 0; B(p) = 0; (void) werase(w); if (Opt(f, O_PUBLIC) && Justified(f)) unjustify(f, w); else _buf_to_win(f, w); Set(f, TOP_CHG); (void) _update_current(p); } else v = display_field(f); } Set(f, USR_CHG); return (v ? E_OK : E_SYSTEM_ERROR); } /* _sync_attrs - sync the field after a change to a field attribute */ int _sync_attrs(FIELD *f) { int v = TRUE; if (Connected(f) && Posted(f) && Visible(f)) { if (isCurrent(f)) { FORM * p = f -> form; WINDOW * w = W(p); _sync_buffer(p); wbkgdset(w, Pad(f) | Back(f)); (void) wattrset(w, Fore(f)); (void) werase(w); if (Opt(f, O_PUBLIC)) { if (Justified(f)) unjustify(f, w); else _buf_to_win(f, w); } else { (void) copywin(w, Sub(p), 0, 0, f -> frow, f -> fcol, f -> rows - 1, f -> cols - 1, FALSE); wsyncup(Sub(p)); _buf_to_win(f, w); } Set(f, TOP_CHG); (void) _update_current(p); } else v = display_field(f); } return (v ? E_OK : E_SYSTEM_ERROR); } int _sync_opts(FIELD *f, OPTIONS opts) { int v = TRUE; OPTIONS oldopts = f -> opts; OPTIONS x = opts ^ oldopts; /* x & opt indicates option opt has changed state */ f -> opts = opts; if (Connected(f)) { if (isCurrent(f)) { f -> opts = oldopts; return (E_CURRENT); } if (Posted(f) && OnPage(f)) { if (x & O_VISIBLE) { if (Opt(f, O_VISIBLE)) v = display_field(f); else v = erase_field(f); } else if (x & O_PUBLIC) { if (Opt(f, O_VISIBLE)) v = display_field(f); } } } if (x & O_STATIC) { BOOLEAN onerow = OneRow(f); int max = f->maxgrow; if (Opt(f, O_STATIC)) { /* growth being turned off */ Clr(f, GROWABLE); if (onerow && f->cols == f->dcols && Just(f) != NO_JUSTIFICATION && Posted(f) && OnPage(f) && Opt(f, O_VISIBLE)) { (void) display_field(f); } } else if (!max || (onerow && f->dcols < max) || (!onerow && f->drows < max)) { Set(f, GROWABLE); if (onerow && Just(f) != NO_JUSTIFICATION && Posted(f) && OnPage(f) && Opt(f, O_VISIBLE)) { (void) display_field(f); } } } return (v ? E_OK : E_SYSTEM_ERROR); } /* _validate - validate current field */ int _validate(FORM *f) { FIELD * c = C(f); _sync_buffer(f); if (Status(f, BUF_CHG) || !Opt(c, O_PASSOK)) { if (CheckField(c)) { Clr(f, BUF_CHG); Set(c, USR_CHG); (void) _sync_linked(c); } else return (FALSE); } return (TRUE); } /* * _set_current_field - change current field on form f to given field. * POSTED flag is set unless this is called from post_form(). */ int _set_current_field(FORM *f, FIELD *field) { WINDOW * w = W(f); FIELD * c = C(f); if (c != field || ! Status(f, POSTED)) { if (w) { if (Visible(c)) { (void) _update_current(f); if (Opt(c, O_PUBLIC)) { if (Scrollable(c)) { if (T(f) == 0) Clr(c, TOP_CHG); else Set(c, TOP_CHG); } else if (Justified(c)) { (void) werase(w); justify(c, w); wsyncup(w); } } } (void) delwin(w); } c = field; if (!Opt(c, O_PUBLIC) || Scrollable(c)) w = newwin(c -> drows, c -> dcols, 0, 0); else w = derwin(Sub(f), c -> rows, c -> cols, c -> frow, c -> fcol); if (!w) return (E_SYSTEM_ERROR); C(f) = c; W(f) = w; wbkgdset(w, Pad(c) | Back(c)); (void) wattrset(w, Fore(c)); if (!Opt(c, O_PUBLIC) || Scrollable(c)) { (void) werase(w); _buf_to_win(c, w); } else if (Justified(c)) { (void) werase(w); unjustify(c, w); wsyncup(w); } (void) untouchwin(w); Clr(f, WIN_CHG | BUF_CHG); } Y(f) = 0; X(f) = 0; T(f) = 0; B(f) = 0; return (E_OK); } /* * _set_form_page - display given page and set current field to c. * if c is null, then set current field to first field on page. * POSTED flag is set unless this is called from post_form(). */ int _set_form_page(FORM *f, int page, FIELD *c) { if (P(f) != page || ! Status(f, POSTED)) { FIELD * x = f -> field [Smin(f, page)]; FIELD * p = x; (void) werase(Sub(f)); P(f) = page; do { if (Opt(p, O_VISIBLE)) if (!display_field(p)) return (E_SYSTEM_ERROR); p = p -> snext; } while (p != x); return (c ? _set_current_field(f, c) : _first_field(f)); } return (E_OK); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ #ifndef _FORM_H #define _FORM_H #include #include #ifdef __cplusplus extern "C" { #endif /* * FIELDTYPE */ typedef struct typenode { int status; /* flags */ int ref; /* reference count */ struct typenode * left; /* ptr to operand for | */ struct typenode * right; /* ptr to operand for | */ PTF_charP makearg; /* make fieldtype arg */ PTF_charP copyarg; /* copy fieldtype arg */ PTF_void freearg; /* free fieldtype arg */ PTF_int fcheck; /* field validation */ PTF_int ccheck; /* character validation */ PTF_int next; /* enumerate next value */ PTF_int prev; /* enumerate prev value */ } FIELDTYPE; /* * _PAGE */ typedef struct { int pmin; /* first field on page */ int pmax; /* last field on page */ int smin; /* top leftmost field */ int smax; /* bottom rightmost */ } _PAGE; /* * FIELD */ typedef struct fieldnode { int status; /* flags */ int rows; /* size in rows */ int cols; /* size in cols */ int frow; /* first row */ int fcol; /* first col */ int drows; /* dynamic rows */ int dcols; /* dynamic cols */ int maxgrow; /* maximum field growth */ int nrow; /* offscreen rows */ int nbuf; /* additional buffers */ int just; /* justification */ int page; /* page on form */ int index; /* into form -> field */ int pad; /* pad character */ chtype fore; /* foreground attribute */ chtype back; /* background attribute */ OPTIONS opts; /* options */ struct fieldnode * snext; /* sorted order pointer */ struct fieldnode * sprev; /* sorted order pointer */ struct fieldnode * link; /* linked field chain */ struct formnode * form; /* containing form */ FIELDTYPE * type; /* field type */ char * arg; /* argument for type */ char * buf; /* field buffers */ char * usrptr; /* user pointer */ } FIELD; /* * FORM */ typedef struct formnode { int status; /* flags */ int rows; /* size in rows */ int cols; /* size in cols */ int currow; /* current row */ int curcol; /* current col */ int toprow; /* in vertically */ /* scrollable field */ int begincol; /* in horizontally */ /* scrollable field */ int maxfield; /* number of fields */ int maxpage; /* number of pages */ int curpage; /* index into page */ OPTIONS opts; /* options */ WINDOW * win; /* window */ WINDOW * sub; /* subwindow */ WINDOW * w; /* window */ FIELD ** field; /* field [maxfield] */ FIELD * current; /* current field */ _PAGE * page; /* page [maxpage] */ char * usrptr; /* user pointer */ PTF_void forminit; /* user function */ PTF_void formterm; /* user function */ PTF_void fieldinit; /* user function */ PTF_void fieldterm; /* user function */ } FORM; /* * miscellaneous #defines */ /* * field justification */ #define NO_JUSTIFICATION 0 #define JUSTIFY_LEFT 1 #define JUSTIFY_CENTER 2 #define JUSTIFY_RIGHT 3 /* * field options */ #define O_VISIBLE 0x0001 #define O_ACTIVE 0x0002 #define O_PUBLIC 0x0004 #define O_EDIT 0x0008 #define O_WRAP 0x0010 #define O_BLANK 0x0020 #define O_AUTOSKIP 0x0040 #define O_NULLOK 0x0080 #define O_PASSOK 0x0100 #define O_STATIC 0x0200 /* * form options */ #define O_NL_OVERLOAD 0x0001 #define O_BS_OVERLOAD 0x0002 /* * form driver commands */ #define REQ_NEXT_PAGE (KEY_MAX + 1) /* move to next page */ #define REQ_PREV_PAGE (KEY_MAX + 2) /* move to previous page */ #define REQ_FIRST_PAGE (KEY_MAX + 3) /* move to first page */ #define REQ_LAST_PAGE (KEY_MAX + 4) /* move to last page */ #define REQ_NEXT_FIELD (KEY_MAX + 5) /* move to next field */ #define REQ_PREV_FIELD (KEY_MAX + 6) /* move to previous field */ #define REQ_FIRST_FIELD (KEY_MAX + 7) /* move to first field */ #define REQ_LAST_FIELD (KEY_MAX + 8) /* move to last field */ #define REQ_SNEXT_FIELD (KEY_MAX + 9) /* move to sorted next field */ #define REQ_SPREV_FIELD (KEY_MAX + 10) /* move to sorted prev field */ #define REQ_SFIRST_FIELD (KEY_MAX + 11) /* move to sorted first field */ #define REQ_SLAST_FIELD (KEY_MAX + 12) /* move to sorted last field */ #define REQ_LEFT_FIELD (KEY_MAX + 13) /* move to left to field */ #define REQ_RIGHT_FIELD (KEY_MAX + 14) /* move to right to field */ #define REQ_UP_FIELD (KEY_MAX + 15) /* move to up to field */ #define REQ_DOWN_FIELD (KEY_MAX + 16) /* move to down to field */ #define REQ_NEXT_CHAR (KEY_MAX + 17) /* move to next char in field */ #define REQ_PREV_CHAR (KEY_MAX + 18) /* move to prev char in field */ #define REQ_NEXT_LINE (KEY_MAX + 19) /* move to next line in field */ #define REQ_PREV_LINE (KEY_MAX + 20) /* move to prev line in field */ #define REQ_NEXT_WORD (KEY_MAX + 21) /* move to next word in field */ #define REQ_PREV_WORD (KEY_MAX + 22) /* move to prev word in field */ #define REQ_BEG_FIELD (KEY_MAX + 23) /* move to first char in field */ #define REQ_END_FIELD (KEY_MAX + 24) /* move after last char in fld */ #define REQ_BEG_LINE (KEY_MAX + 25) /* move to beginning of line */ #define REQ_END_LINE (KEY_MAX + 26) /* move after last char in line */ #define REQ_LEFT_CHAR (KEY_MAX + 27) /* move left in field */ #define REQ_RIGHT_CHAR (KEY_MAX + 28) /* move right in field */ #define REQ_UP_CHAR (KEY_MAX + 29) /* move up in field */ #define REQ_DOWN_CHAR (KEY_MAX + 30) /* move down in field */ #define REQ_NEW_LINE (KEY_MAX + 31) /* insert/overlay new line */ #define REQ_INS_CHAR (KEY_MAX + 32) /* insert blank char at cursor */ #define REQ_INS_LINE (KEY_MAX + 33) /* insert blank line at cursor */ #define REQ_DEL_CHAR (KEY_MAX + 34) /* delete char at cursor */ #define REQ_DEL_PREV (KEY_MAX + 35) /* delete char before cursor */ #define REQ_DEL_LINE (KEY_MAX + 36) /* delete line at cursor */ #define REQ_DEL_WORD (KEY_MAX + 37) /* delete line at cursor */ #define REQ_CLR_EOL (KEY_MAX + 38) /* clear to end of line */ #define REQ_CLR_EOF (KEY_MAX + 39) /* clear to end of field */ #define REQ_CLR_FIELD (KEY_MAX + 40) /* clear entire field */ #define REQ_OVL_MODE (KEY_MAX + 41) /* begin overlay mode */ #define REQ_INS_MODE (KEY_MAX + 42) /* begin insert mode */ #define REQ_SCR_FLINE (KEY_MAX + 43) /* scroll field forward a line */ #define REQ_SCR_BLINE (KEY_MAX + 44) /* scroll field backward a line */ #define REQ_SCR_FPAGE (KEY_MAX + 45) /* scroll field forward a page */ #define REQ_SCR_BPAGE (KEY_MAX + 46) /* scroll field backward a page */ #define REQ_SCR_FHPAGE (KEY_MAX + 47) /* scroll field forward half page */ #define REQ_SCR_BHPAGE (KEY_MAX + 48) /* scroll field backward half page */ #define REQ_SCR_FCHAR (KEY_MAX + 49) /* horizontal scroll char */ #define REQ_SCR_BCHAR (KEY_MAX + 50) /* horizontal scroll char */ #define REQ_SCR_HFLINE (KEY_MAX + 51) /* horizontal scroll line */ #define REQ_SCR_HBLINE (KEY_MAX + 52) /* horizontal scroll line */ #define REQ_SCR_HFHALF (KEY_MAX + 53) /* horizontal scroll half line */ #define REQ_SCR_HBHALF (KEY_MAX + 54) /* horizontal scroll half line */ #define REQ_VALIDATION (KEY_MAX + 55) /* validate field */ #define REQ_NEXT_CHOICE (KEY_MAX + 56) /* display next field choice */ #define REQ_PREV_CHOICE (KEY_MAX + 57) /* display prev field choice */ #define MIN_FORM_COMMAND (KEY_MAX + 1) /* used by form_driver */ #define MAX_FORM_COMMAND (KEY_MAX + 57) /* used by form_driver */ /* * standard field types */ extern FIELDTYPE * TYPE_ALPHA; extern FIELDTYPE * TYPE_ALNUM; extern FIELDTYPE * TYPE_ENUM; extern FIELDTYPE * TYPE_INTEGER; extern FIELDTYPE * TYPE_NUMERIC; extern FIELDTYPE * TYPE_REGEXP; /* * default objects */ extern FORM * _DEFAULT_FORM; extern FIELD * _DEFAULT_FIELD; #ifdef __STDC__ /* * FIELDTYPE routines */ extern FIELDTYPE * new_fieldtype(PTF_int, PTF_int); extern FIELDTYPE * link_fieldtype(FIELDTYPE *, FIELDTYPE *); extern int free_fieldtype(FIELDTYPE *); extern int set_fieldtype_arg(FIELDTYPE *, PTF_charP, PTF_charP, PTF_void); extern int set_fieldtype_choice(FIELDTYPE *, PTF_int, PTF_int); /* * FIELD routines */ extern FIELD * new_field(int, int, int, int, int, int); extern FIELD * dup_field(FIELD *, int, int); extern FIELD * link_field(FIELD *, int, int); extern int free_field(FIELD *); extern int field_info(FIELD *, int *, int *, int *, int *, int *, int *); extern int dynamic_field_info(FIELD *, int *, int *, int *); extern int set_max_field(FIELD *, int); extern int move_field(FIELD *, int, int); extern int set_field_type(FIELD *, FIELDTYPE *, ...); extern FIELDTYPE * field_type(FIELD *); extern char * field_arg(FIELD *); extern int set_new_page(FIELD *, int); extern int new_page(FIELD *); extern int set_field_just(FIELD *, int); extern int field_just(FIELD *); extern int set_field_fore(FIELD *, chtype); extern chtype field_fore(FIELD *); extern int set_field_back(FIELD *, chtype); extern chtype field_back(FIELD *); extern int set_field_pad(FIELD *, int); extern int field_pad(FIELD *); extern int set_field_buffer(FIELD *, int, char *); extern char * field_buffer(FIELD *, int); extern int set_field_status(FIELD *, int); extern int field_status(FIELD *); extern int set_field_userptr(FIELD *, char *); extern char * field_userptr(FIELD *); extern int set_field_opts(FIELD *, OPTIONS); extern OPTIONS field_opts(FIELD *); extern int field_opts_on(FIELD *, OPTIONS); extern int field_opts_off(FIELD *, OPTIONS); extern int field_index(FIELD *); /* * FORM routines */ extern FORM * new_form(FIELD **); extern int free_form(FORM *); extern int set_form_fields(FORM *, FIELD **); extern FIELD ** form_fields(FORM *); extern int field_count(FORM *); extern int set_form_win(FORM *, WINDOW *); extern WINDOW * form_win(FORM *); extern int set_form_sub(FORM *, WINDOW *); extern WINDOW * form_sub(FORM *); extern int set_current_field(FORM *, FIELD *); extern FIELD * current_field(FORM *); extern int set_form_page(FORM *, int); extern int form_page(FORM *); extern int scale_form(FORM *, int *, int *); extern int set_form_init(FORM *, PTF_void); extern PTF_void form_init(FORM *); extern int set_form_term(FORM *, PTF_void); extern PTF_void form_term(FORM *); extern int set_field_init(FORM *, PTF_void); extern PTF_void field_init(FORM *); extern int set_field_term(FORM *, PTF_void); extern PTF_void field_term(FORM *); extern int post_form(FORM *); extern int unpost_form(FORM *); extern int pos_form_cursor(FORM *); extern int form_driver(FORM *, int); extern int set_form_userptr(FORM *, char *); extern char * form_userptr(FORM *); extern int set_form_opts(FORM *, OPTIONS); extern OPTIONS form_opts(FORM *); extern int form_opts_on(FORM *, OPTIONS); extern int form_opts_off(FORM *, OPTIONS); extern int data_ahead(FORM *); extern int data_behind(FORM *); #else /* old style extern's */ /* * FIELDTYPE routines */ extern FIELDTYPE * new_fieldtype(); extern FIELDTYPE * link_fieldtype(); extern int free_fieldtype(); extern int set_fieldtype_arg(); extern int set_fieldtype_choice(); /* * FIELD routines */ extern FIELD * new_field(); extern FIELD * dup_field(); extern FIELD * link_field(); extern int free_field(); extern int field_info(); extern int dynamic_field_info(); extern int set_max_field(); extern int move_field(); extern int set_field_type(); extern FIELDTYPE * field_type(); extern char * field_arg(); extern int set_new_page(); extern int new_page(); extern int set_field_just(); extern int field_just(); extern int set_field_fore(); extern chtype field_fore(); extern int set_field_back(); extern chtype field_back(); extern int set_field_pad(); extern int field_pad(); extern int set_field_buffer(); extern char * field_buffer(); extern int set_field_status(); extern int field_status(); extern int set_field_userptr(); extern char * field_userptr(); extern int set_field_opts(); extern OPTIONS field_opts(); extern int field_opts_on(); extern int field_opts_off(); extern int field_index(); /* * FORM routines */ extern FORM * new_form(); extern int free_form(); extern int set_form_fields(); extern FIELD ** form_fields(); extern int field_count(); extern int set_form_win(); extern WINDOW * form_win(); extern int set_form_sub(); extern WINDOW * form_sub(); extern int set_current_field(); extern FIELD * current_field(); extern int set_form_page(); extern int form_page(); extern int scale_form(); extern int set_form_init(); extern PTF_void form_init(); extern int set_form_term(); extern PTF_void form_term(); extern int set_field_init(); extern PTF_void field_init(); extern int set_field_term(); extern PTF_void field_term(); extern int post_form(); extern int unpost_form(); extern int pos_form_cursor(); extern int form_driver(); extern int set_form_userptr(); extern char * form_userptr(); extern int set_form_opts(); extern OPTIONS form_opts(); extern int form_opts_on(); extern int form_opts_off(); extern int data_ahead(); extern int data_behind(); #endif /* __STDC__ */ #ifdef __cplusplus } #endif #endif /* _FORM_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #ifndef _UTILITY_H #define _UTILITY_H #include #include #include #include #include #include #ifdef __cplusplus extern "C" { #endif /* miscellaneous #defines */ typedef int BOOLEAN; #define MIN(x, y) ((x) < (y) ? (x) : (y)) /* form status flags */ #define POSTED 0x0001 /* posted flag */ #define DRIVER 0x0002 /* inside init/term routine */ #define OVERLAY 0x0004 /* insert/overlay mode */ #define WIN_CHG 0x0010 /* window change (system flag) */ #define BUF_CHG 0x0020 /* buffer change (system flag) */ /* field status flags */ #define USR_CHG 0x0001 /* buffer change (user's flag) */ #define TOP_CHG 0x0002 /* toprow change (system flag) */ #define NEW_PAGE 0x0004 /* new page (system flag) */ #define GROWABLE 0x0008 /* growable page (system flag) */ /* field type status flags */ #define LINKED 0x0001 /* conjunctive field type */ #define ARGS 0x0002 /* has additional arguments */ #define CHOICE 0x0004 /* has choice functions */ /* form/field/fieldtype status manipulation macros */ #define Status(f, s) ((f) -> status & (s)) #define Set(f, s) ((f) -> status |= (s)) #define Clr(f, s) ((f) -> status &= ~(s)) /* form/field option manipulation macros */ #define Opt(f, x) ((f) -> opts & (x)) /* alloc/free with check */ #define Alloc(x, t) ((x = (t *) malloc(sizeof (t))) != (t *)0) #define arrayAlloc(x, n, t) ((x = (t *) malloc((n) * sizeof (t))) != \ (t *)0) #define Free(x) { if (x) free(x); } /* field type macros */ #define MakeArg(f, p, err) (_makearg((f) -> type, p, err)) #define CopyArg(f, err) (_copyarg((f) -> type, (f) -> arg, err)) #define FreeArg(f) (_freearg((f) -> type, (f) -> arg)) #define CheckField(f) (_checkfield((f) -> type, (f), (f) -> arg)) #define CheckChar(f, c) (_checkchar((f) -> type, (c), (f) -> arg)) #define NextChoice(f) (_nextchoice((f) -> type, (f), (f) -> arg)) #define PrevChoice(f) (_prevchoice((f) -> type, (f), (f) -> arg)) #define IncrType(type) { if (type) ++(type -> ref); } #define DecrType(type) { if (type) --(type -> ref); } /* form/field init/term calls */ #define init_field(f) { \ if ((f) -> fieldinit) \ { \ Set(f, DRIVER); \ (*(f) -> fieldinit)(f); \ Clr(f, DRIVER); \ } \ } #define term_field(f) { \ if ((f) -> fieldterm) \ { \ Set(f, DRIVER); \ (*(f) -> fieldterm)(f); \ Clr(f, DRIVER); \ } \ } #define init_form(f) { \ if ((f) -> forminit) \ { \ Set(f, DRIVER); \ (*(f) -> forminit)(f); \ Clr(f, DRIVER); \ } \ } #define term_form(f) { \ if ((f) -> formterm) \ { \ Set(f, DRIVER); \ (*(f) -> formterm)(f); \ Clr(f, DRIVER); \ } \ } /* page macros */ #define P(f) ((f) -> curpage) #define Pmin(f, p) ((f) -> page [p].pmin) #define Pmax(f, p) ((f) -> page [p].pmax) #define Smin(f, p) ((f) -> page [p].smin) #define Smax(f, p) ((f) -> page [p].smax) /* form macros */ #define Form(f) ((f) ? (f) : _DEFAULT_FORM) #define ValidIndex(f, i) ((i) >= 0 && (i) < (f) -> maxfield) #define ValidPage(f, i) ((i) >= 0 && (i) < (f) -> maxpage) #define C(f) ((f) -> current) #define W(f) ((f) -> w) #define X(f) ((f) -> curcol) #define Y(f) ((f) -> currow) #define T(f) ((f) -> toprow) #define B(f) ((f) -> begincol) #define Xmax(f) (C(f) -> dcols) #define Ymax(f) (C(f) -> drows) #define Win(f) ((f) -> win ? (f) -> win : stdscr) #define Sub(f) ((f) -> sub ? (f) -> sub : Win(f)) /* field macros */ #define Field(f) ((f) ? (f) : _DEFAULT_FIELD) #define Buf(f) ((f) -> buf) #define OneRow(f) ((f)->rows + (f)->nrow == 1) #define GrowSize(f) (((f) -> rows + (f) -> nrow) * (f) -> cols) #define BufSize(f) ((f) -> drows * (f) -> dcols) #define Buffer(f, n) (Buf(f) + (n) * (BufSize(f) + 1)) #define LineBuf(f, n) (Buf(f) + (n) * (f) -> dcols) #define TotalBuf(f) ((BufSize(f) + 1) * ((f) -> nbuf + 1)) #define Just(f) ((f) -> just) #define Fore(f) ((f) -> fore) #define Back(f) ((f) -> back) #define Pad(f) ((f) -> pad) /* system externs */ extern int _next_page(FORM *); /* REQ_NEXT_PAGE */ extern int _prev_page(FORM *); /* REQ_PREV_PAGE */ extern int _first_page(FORM *); /* REQ_FIRST_PAGE */ extern int _last_page(FORM *); /* REQ_LAST_PAGE */ extern int _next_field(FORM *); /* REQ_NEXT_FIELD */ extern int _prev_field(FORM *); /* REQ_PREV_FIELD */ extern int _first_field(FORM *); /* REQ_FIRST_FIELD */ extern int _last_field(FORM *); /* REQ_LAST_FIELD */ extern int _snext_field(FORM *); /* REQ_SNEXT_FIELD */ extern int _sprev_field(FORM *); /* REQ_SPREV_FIELD */ extern int _sfirst_field(FORM *); /* REQ_SFIRST_FIELD */ extern int _slast_field(FORM *); /* REQ_SLAST_FIELD */ extern int _left_field(FORM *); /* REQ_LEFT_FIELD */ extern int _right_field(FORM *); /* REQ_RIGHT_FIELD */ extern int _up_field(FORM *); /* REQ_UP_FIELD */ extern int _down_field(FORM *); /* REQ_DOWN_FIELD */ extern int _next_char(FORM *); /* REQ_NEXT_CHAR */ extern int _prev_char(FORM *); /* REQ_PREV_CHAR */ extern int _next_line(FORM *); /* REQ_NEXT_LINE */ extern int _prev_line(FORM *); /* REQ_PREV_LINE */ extern int _next_word(FORM *); /* REQ_NEXT_WORD */ extern int _prev_word(FORM *); /* REQ_PREV_WORD */ extern int _beg_field(FORM *); /* REQ_BEG_FIELD */ extern int _end_field(FORM *); /* REQ_END_FIELD */ extern int _beg_line(FORM *); /* REQ_BEG_LINE */ extern int _end_line(FORM *); /* REQ_END_LINE */ extern int _left_char(FORM *); /* REQ_LEFT_CHAR */ extern int _right_char(FORM *); /* REQ_RIGHT_CHAR */ extern int _up_char(FORM *); /* REQ_UP_CHAR */ extern int _down_char(FORM *); /* REQ_DOWN_CHAR */ extern int _new_line(FORM *); /* REQ_NEW_LINE */ extern int _ins_char(FORM *); /* REQ_INS_CHAR */ extern int _ins_line(FORM *); /* REQ_INS_LINE */ extern int _del_char(FORM *); /* REQ_DEL_CHAR */ extern int _del_prev(FORM *); /* REQ_DEL_PREV */ extern int _del_line(FORM *); /* REQ_DEL_LINE */ extern int _del_word(FORM *); /* REQ_DEL_WORD */ extern int _clr_eol(FORM *); /* REQ_CLR_EOL */ extern int _clr_eof(FORM *); /* REQ_CLR_EOF */ extern int _clr_field(FORM *); /* REQ_CLR_FIELD */ extern int _ovl_mode(FORM *); /* REQ_OVL_MODE */ extern int _ins_mode(FORM *); /* REQ_INS_MODE */ extern int _scr_fline(FORM *); /* REQ_SCR_FLINE */ extern int _scr_bline(FORM *); /* REQ_SCR_BLINE */ extern int _scr_fpage(FORM *); /* REQ_SCR_FPAGE */ extern int _scr_fhpage(FORM *); /* REQ_SCR_FHPAGE */ extern int _scr_bpage(FORM *); /* REQ_SCR_BPAGE */ extern int _scr_bhpage(FORM *); /* REQ_SCR_BHPAGE */ extern int _scr_fchar(FORM *); /* REQ_SCR_FCHAR */ extern int _scr_bchar(FORM *); /* REQ_SCR_BCHAR */ extern int _scr_hfline(FORM *); /* REQ_SCR_HFLINE */ extern int _scr_hbline(FORM *); /* REQ_SCR_HBLINE */ extern int _scr_hfhalf(FORM *); /* REQ_SCR_HFHALF */ extern int _scr_hbhalf(FORM *); /* REQ_SCR_HBHALF */ extern int _validation(FORM *); /* REQ_VALIDATION */ extern int _next_choice(FORM *); /* REQ_NEXT_CHOICE */ extern int _prev_choice(FORM *); /* REQ_PREV_CHOICE */ extern char * _makearg(FIELDTYPE *, va_list *, int *); extern char * _copyarg(FIELDTYPE *, char *, int *); extern void _freearg(FIELDTYPE *, char *); extern int _checkfield(FIELDTYPE *, FIELD *, char *); extern int _checkchar(FIELDTYPE *, int, char *); extern int _nextchoice(FIELDTYPE *, FIELD *, char *); extern int _prevchoice(FIELDTYPE *, FIELD *, char *); extern BOOLEAN _grow_field(FIELD *, int); extern FIELD * _first_active(FORM *); extern char * _data_beg(char *, int); extern char * _data_end(char *, int); extern char * _whsp_beg(char *, int); extern char * _whsp_end(char *, int); extern void _buf_to_win(FIELD *, WINDOW *); extern void _win_to_buf(WINDOW *, FIELD *); extern void _adjust_cursor(FORM *, char *); extern void _sync_buffer(FORM *); extern int _sync_linked(FIELD *); extern int _sync_field(FIELD *); extern int _sync_attrs(FIELD *); extern int _sync_opts(FIELD *, OPTIONS); extern int _validate(FORM *); extern int _set_current_field(FORM *, FIELD *); extern int _set_form_page(FORM *, int, FIELD *); extern int _pos_form_cursor(FORM *); extern int _update_current(FORM *); extern int _data_entry(FORM *, int); extern int _page_navigation(PTF_int, FORM *); extern int _field_navigation(PTF_int, FORM *); extern int _data_navigation(PTF_int, FORM *); extern int _data_manipulation(PTF_int, FORM *); extern int _misc_request(PTF_int, FORM *); extern intptr_t __execute(char *, char *); extern intptr_t __advance(char *, char *); extern intptr_t __xpop(intptr_t); extern intptr_t __xpush(intptr_t, char *); extern intptr_t __getrnge(intptr_t *, intptr_t *, char *); extern intptr_t __cclass(char *, char, intptr_t); extern int __size(char *); extern int __rpush(char *); extern intptr_t __rpop(void); #ifdef __cplusplus } #endif #endif /* _UTILITY_H */ # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2006 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # include ../../Makefile.lib # Hammerhead: amd64-only SUBDIRS= $(MACH64) all : TARGET= all clean : TARGET= clean clobber : TARGET= clobber install : TARGET= install .KEEP_STATE: all clean clobber install: $(SUBDIRS) # definitions for install_h target HDRS= menu.h ROOTHDRDIR= $(ROOT)/usr/include ROOTHDRS= $(HDRS:%=$(ROOTHDRDIR)/%) CHECKHDRS= $(HDRS:%.h=inc/%.check) # install rule for install_h target $(ROOTHDRDIR)/%: inc/% $(INS.file) install_h: $(ROOTHDRS) check: $(CHECKHDRS) $(SUBDIRS): FRC @cd $@; pwd; $(MAKE) $(TARGET) FRC: # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # LIBRARY= libmenu.a VERS= .1 OBJECTS= \ affect.o \ chk.o \ connect.o \ curitem.o \ driver.o \ global.o \ itemcount.o \ itemopts.o \ itemusrptr.o \ itemvalue.o \ link.o \ menuback.o \ menucursor.o \ menufore.o \ menuformat.o \ menugrey.o \ menuitems.o \ menumark.o \ menuopts.o \ menupad.o \ menuserptr.o \ menusub.o \ menuwin.o \ newitem.o \ newmenu.o \ pattern.o \ post.o \ scale.o \ show.o \ terminit.o \ topitem.o \ visible.o # include library definitions include ../../../Makefile.lib LIBS = $(DYNLIB) SRCDIR= ../common CPPFLAGS += -I../inc CFLAGS += $(CCVERBOSE) LDLIBS += -lcurses -lc CERRWARN += -Wno-parentheses COMPATLINKS= usr/ccs/lib/libmenu.so # Hammerhead: flattened layout — no amd64 subdir COMPATLINKS64= $(COMPATLINKS) $(ROOT)/usr/ccs/lib/libmenu.so : COMPATLINKTARGET= ../../lib/libmenu.so.1 .KEEP_STATE: all: $(LIBS) # include library targets include ../../../Makefile.targ pics/%.o: ../common/%.c $(COMPILE.c) -o $@ $< $(POST_PROCESS_O) # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2006 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # include ../Makefile.com include ../../../Makefile.lib.64 DYNFLAGS += $(DYNFLAGS64) .KEEP_STATE: install: all $(ROOTLIBS64) $(ROOTLINKS64) $(ROOTCOMPATLINKS64) /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "private.h" /* * This routine checks the supplied values against the values of * current and top items. If a value has changed then one of * terminate routines is called. Following the actual change of * the value is the calling of the initialize routines. */ void _affect_change(MENU *m, int newtop, ITEM *newcurrent) { ITEM *oldcur; int topchange = FALSE, curchange = FALSE; /* Call term and init routines if posted */ if (Posted(m)) { /* If current has changed terminate the old item. */ if (newcurrent != Current(m)) { Iterm(m); curchange = TRUE; } /* If top has changed then call menu init function */ if (newtop != Top(m)) { Mterm(m); topchange = TRUE; } oldcur = Current(m); Top(m) = newtop; Current(m) = newcurrent; if (topchange) { /* Init the new page if top has changed */ Minit(m); } if (curchange) { /* Unmark the old item and mark the new one */ _movecurrent(m, oldcur); /* Init the new item if current changed */ Iinit(m); } /* If anything changed go change user's copy of menu */ if (topchange || curchange) { _show(m); } else { _position_cursor(m); } } else { /* Just change Top and Current if not posted */ Top(m) = newtop; Current(m) = newcurrent; } } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "private.h" /* Make sure top is not within a page of the end of the menu */ void _chk_top(MENU *m, int *top, ITEM *current) { if (Y(current) < *top) { *top = Y(current); } if (Y(current) >= *top + Height(m)) { *top = Y(current) - Height(m) + 1; } } /* * This routine makes sure top is in the correct position * relative to current. It is only used when current is * explicitly set. */ void _chk_current(MENU *m, int *top, ITEM *current) { if (Y(current) < *top) { *top = Y(current); } if (Y(current) >= *top + Height(m)) { *top = min(Y(current), Rows(m) - Height(m)); } } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include #include "private.h" /* Connect and disconnect an item list from a menu */ /* Find the maximum length name and description */ static void maxlengths(MENU *m) { int maxn, maxd; ITEM **ip; maxn = maxd = 0; for (ip = Items(m); *ip; ip++) { if (NameLen(*ip) > maxn) { maxn = NameLen(*ip); } if (DescriptionLen(*ip) > maxd) { maxd = DescriptionLen(*ip); } } MaxName(m) = maxn; MaxDesc(m) = maxd; } int _connect(MENU *m, ITEM **items) { ITEM **ip; int i; /* Is the list of items connected to any other menu? */ for (ip = items; *ip; ip++) { /* Return Null if item points to a menu */ if (Imenu(*ip)) { return (FALSE); } } for (i = 0, ip = items; *ip; ip++) { /* Return FALSE if this item is a prevoious item */ if (Imenu(*ip)) { for (ip = items; *ip; ip++) { /* Reset index and menu pointers */ Index(*ip) = 0; Imenu(*ip) = (MENU *) NULL; } return (FALSE); } if (OneValue(m)) { /* Set all values to FALSE if selection not allowed */ Value(*ip) = FALSE; } Index(*ip) = i++; Imenu(*ip) = m; } Nitems(m) = i; Items(m) = items; /* Go pick up the sizes of names and descriptions */ maxlengths(m); /* Set up match buffer */ if ((Pattern(m) = (char *)malloc((unsigned)MaxName(m)+1)) == (char *)0) { return (FALSE); } IthPattern(m, 0) = '\0'; Pindex(m) = 0; (void) set_menu_format(m, FRows(m), FCols(m)); Current(m) = IthItem(m, 0); Top(m) = 0; return (TRUE); } void _disconnect(MENU *m) { ITEM **ip; for (ip = Items(m); *ip; ip++) { /* Release items for another menu */ Imenu(*ip) = (MENU *) NULL; } free(Pattern(m)); Pattern(m) = NULL; Items(m) = (ITEM **) NULL; Nitems(m) = 0; } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "private.h" int set_current_item(MENU *m, ITEM *current) { int top; if (m && current && Imenu(current) == m) { if (Indriver(m)) { return (E_BAD_STATE); } if (current != Current(m)) { if (LinkNeeded(m)) { _link_items(m); } top = Top(m); _chk_current(m, &top, current); /* Next clear the pattern buffer. */ Pindex(m) = 0; IthPattern(m, Pindex(m)) = '\0'; _affect_change(m, top, current); } } else { return (E_BAD_ARGUMENT); } return (E_OK); } ITEM * current_item(MENU *m) { if (m && Items(m)) { return (Current(m)); } else { return ((ITEM *)0); } } int item_index(ITEM *i) { if (i && Imenu(i)) { return (Index(i)); } else { return (-1); } } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "private.h" int menu_driver(MENU *m, int c) { int i, n; int top; ITEM *current; int ret; if (!m) { return (E_BAD_ARGUMENT); } ret = E_OK; if (Indriver(m)) { return (E_BAD_STATE); } if (!Posted(m)) { return (E_NOT_POSTED); } top = Top(m); current = Current(m); if (c > KEY_MAX && c < MAX_COMMAND) { /* Clear the pattern buffer if not one of these requests */ if (c != REQ_BACK_PATTERN && c != REQ_NEXT_MATCH && c != REQ_PREV_MATCH) { Pindex(m) = 0; IthPattern(m, 0) = '\0'; } switch (c) { case REQ_RIGHT_ITEM: { if (Right(current) == (ITEM *)0) { ret = E_REQUEST_DENIED; break; } current = Right(current); break; } case REQ_LEFT_ITEM: { if (Left(current) == (ITEM *)0) { ret = E_REQUEST_DENIED; break; } current = Left(current); break; } case REQ_UP_ITEM: { if (Up(current) == (ITEM *)0) { ret = E_REQUEST_DENIED; break; } current = Up(current); break; } case REQ_DOWN_ITEM: { if (Down(current) == (ITEM *)0) { ret = E_REQUEST_DENIED; break; } current = Down(current); break; } case REQ_SCR_ULINE: { if (--top < 0) { ++top; ret = E_REQUEST_DENIED; break; } current = Up(current); break; } case REQ_SCR_DLINE: { if (++top > Rows(m) - Height(m)) { --top; ret = E_REQUEST_DENIED; break; } current = Down(current); break; } case REQ_SCR_UPAGE: { n = min(Height(m), top); if (n) { top -= n; for (i = n; i--; ) { current = Up(current); } } else { ret = E_REQUEST_DENIED; break; } break; } case REQ_SCR_DPAGE: { n = min(Height(m), Rows(m) - Height(m) - top); if (n) { top += n; for (i = n; i--; ) { current = Down(current); } } else { ret = E_REQUEST_DENIED; break; } break; } case REQ_FIRST_ITEM: { current = IthItem(m, 0); break; } case REQ_LAST_ITEM: { current = IthItem(m, Nitems(m)-1); break; } case REQ_NEXT_MATCH: { if (IthPattern(m, 0) != '\0') { ret = _match(m, '\0', ¤t); } else { if (Index(current)+1 >= Nitems(m)) { current = IthItem(m, 0); } else { current = IthItem(m, Index(current)+1); } } break; } case REQ_NEXT_ITEM: { if (Index(current)+1 >= Nitems(m)) { if (Cyclic(m)) { current = IthItem(m, 0); } else { ret = E_REQUEST_DENIED; } } else { current = IthItem(m, Index(current)+1); } break; } case REQ_PREV_MATCH: { if (IthPattern(m, 0) != '\0') { ret = _match(m, '\b', ¤t); } else { /* This differs from PREV_ITEM in that */ /* it is cyclic */ if (Index(current)-1 < 0) { current = IthItem(m, Nitems(m)-1); } else { current = IthItem(m, Index(current)-1); } } break; } case REQ_PREV_ITEM: { if (Index(current)-1 < 0) { if (Cyclic(m)) { current = IthItem(m, Nitems(m)-1); } else { ret = E_REQUEST_DENIED; } } else { current = IthItem(m, Index(current)-1); } break; } case REQ_TOGGLE_ITEM: { if (!OneValue(m)) { if (Selectable(Current(m))) { Value(Current(m)) ^= TRUE; _move_post_item(m, Current(m)); _show(m); } else { ret = E_NOT_SELECTABLE; } } else { ret = E_REQUEST_DENIED; } break; } case REQ_BACK_PATTERN: { if (Pindex(m) > 0) { Pindex(m) -= 1; IthPattern(m, Pindex(m)) = '\0'; _position_cursor(m); } else { ret = E_REQUEST_DENIED; } break; } case REQ_CLEAR_PATTERN: { /* This was already done at the top */ break; } default: { ret = E_UNKNOWN_COMMAND; } } } else { if (c > 037 && c < 0177) { /*LINTED [E_PASS_INT_TO_SMALL_INT]*/ ret = _match(m, c, ¤t); } else { ret = E_UNKNOWN_COMMAND; } } /* Verify the location of the top row */ _chk_top(m, &top, current); /* Go change the actual values of Top and Current and do init/term */ _affect_change(m, top, current); return (ret); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "menu.h" MENU _Default_Menu = { 16, /* height */ 1, /* width */ 16, /* rows */ 1, /* cols */ 16, /* frows */ 1, /* fcols */ 0, /* namelen */ 0, /* desclen */ 1, /* marklen */ 1, /* itemlen */ (char *) NULL, /* pattern */ 0, /* pindex */ (WINDOW *) NULL, /* win */ (WINDOW *) NULL, /* sub */ (WINDOW *) NULL, /* userwin */ (WINDOW *) NULL, /* usersub */ (ITEM **) NULL, /* items */ 0, /* nitems */ (ITEM *) NULL, /* curitem */ 0, /* toprow */ ' ', /* pad */ A_STANDOUT, /* fore */ A_NORMAL, /* back */ A_UNDERLINE, /* grey */ (PTF_void) NULL, /* menuinit */ (PTF_void) NULL, /* menuterm */ (PTF_void) NULL, /* iteminit */ (PTF_void) NULL, /* itemterm */ (char *) NULL, /* userptr */ "-", /* mark */ O_ONEVALUE|O_SHOWDESC| O_ROWMAJOR|O_IGNORECASE| O_SHOWMATCH|O_NONCYCLIC, /* opt */ 0 /* status */ }; ITEM _Default_Item = { (char *) NULL, /* name.str */ 0, /* name.length */ (char *) NULL, /* description.str */ 0, /* description.length */ 0, /* index */ 0, /* imenu */ FALSE, /* value */ (char *) NULL, /* userptr */ O_SELECTABLE, /* opt */ 0, /* status */ 0, /* y */ 0, /* x */ 0, /* up */ 0, /* down */ 0, /* left */ 0 /* right */ }; /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "private.h" int item_count(MENU *m) { if (m) { return (Nitems(m)); } return (-1); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "private.h" int set_item_opts(ITEM *i, OPTIONS opt) { if (i) { if (Iopt(i) != opt) { Iopt(i) = opt; /* If the item is being deactivated then unselect it */ if ((opt & O_SELECTABLE) == 0) { if (Value(i)) { Value(i) = FALSE; } } if (Imenu(i) && Posted(Imenu(i))) { _move_post_item(Imenu(i), i); _show(Imenu(i)); } } } else { Iopt(Dfl_Item) = opt; } return (E_OK); } int item_opts_off(ITEM *i, OPTIONS opt) { return (set_item_opts(i, (Iopt(i ? i : Dfl_Item)) & ~opt)); } int item_opts_on(ITEM *i, OPTIONS opt) { return (set_item_opts(i, (Iopt(i ? i : Dfl_Item)) | opt)); } int item_opts(ITEM *i) { return (Iopt(i ? i : Dfl_Item)); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "private.h" int set_item_userptr(ITEM *i, char *u) { if (i) { Iuserptr(i) = u; } else { Iuserptr(Dfl_Item) = u; } return (E_OK); } char * item_userptr(ITEM *i) { return (Iuserptr(i ? i : Dfl_Item)); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "private.h" int set_item_value(ITEM *i, int v) { /* Values can only be set on active values */ if (i) { if (!Selectable(i) || (Imenu(i) && OneValue(Imenu(i)))) { return (E_REQUEST_DENIED); } if (Value(i) != v) { Value(i) = v; if (Imenu(i) && Posted(Imenu(i))) { _move_post_item(Imenu(i), i); _show(Imenu(i)); } } } else { Value(Dfl_Item) = v; } return (E_OK); } int item_value(ITEM *i) { return (Value(i ? i : Dfl_Item)); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "private.h" static void link_col_major(MENU *m) { ITEM *i; int n; short c, r; int left, up; r = 0; c = 0; for (i = IthItem(m, 0), n = 0; i; i = IthItem(m, ++n)) { X(i) = c; Y(i) = r; Left(i) = c ? IthItem(m, n-Rows(m)) : (ITEM *) NULL; if (n + Rows(m) >= Nitems(m)) { Right(i) = (ITEM *) NULL; } else { Right(i) = IthItem(m, n + Rows(m)); } Up(i) = r ? IthItem(m, n-1) : (ITEM *) NULL; Down(i) = (r == Rows(m)-1) ? (ITEM *)0 : IthItem(m, n+1); if (++r == Rows(m)) { r = 0; c += 1; } } if (r) { Down(IthItem(m, n-1)) = IthItem(m, n - Rows(m)); } if (Cyclic(m)) { /* Set up left and right links at edge of menu */ r = Rows(m) * (Nitems(m)/Rows(m)); for (n = 0; n < Rows(m); n++) { left = n + r; if (left >= Nitems(m)) { left -= Rows(m); } Left(IthItem(m, n)) = IthItem(m, left); Right(IthItem(m, left)) = IthItem(m, n); } /* Setup up and down links at edge of menu */ for (n = 0; n < Nitems(m); n += Rows(m)) { up = n + Rows(m) - 1; if (up >= Nitems(m)) { Up(IthItem(m, n)) = IthItem(m, n-1); } else { Up(IthItem(m, n)) = IthItem(m, up); Down(IthItem(m, up)) = IthItem(m, n); } } } } static void link_row_major(MENU *m) { int n; short c, r; ITEM *i; int left, up; r = 0; c = 0; for (i = IthItem(m, 0), n = 0; i; i = IthItem(m, ++n)) { X(i) = c; Y(i) = r; Left(i) = c ? IthItem(m, n-1) : (ITEM *) NULL; Right(i) = (c == Cols(m)-1 || n == Nitems(m)-1) ? (ITEM *)0 : IthItem(m, n+1); Up(i) = r ? IthItem(m, n-Cols(m)) : (ITEM *) NULL; if (n+Cols(m) < Nitems(m)) { Down(i) = IthItem(m, n + Cols(m)); } else { if (r == Rows(m)-1) { /* Down is undefined if this is a complete */ /* last column */ Down(i) = (ITEM *) NULL; } else { /* Down is set to last item if the last */ /* column isn't full */ Down(i) = IthItem(m, Nitems(m)-1); } } if (++c == Cols(m)) { c = 0; r += 1; } } if (Cyclic(m)) { /* Setup left and right links at edge of menu */ for (n = 0; n < Nitems(m); n += Cols(m)) { left = n + Cols(m) - 1; if (left >= Nitems(m)) { left = Nitems(m) - 1; } Left(IthItem(m, n)) = IthItem(m, left); Right(IthItem(m, left)) = IthItem(m, n); } /* Setup up and down links at edge of menu */ r = (Rows(m) - 1) * Cols(m); for (n = 0; n < Cols(m); n++) { up = n + r; /* If there is an incomplete line below this one */ /* the point to the last item in the menu. */ if (up >= Nitems(m)) { Up(IthItem(m, n)) = IthItem(m, Nitems(m)-1); } else { Up(IthItem(m, n)) = IthItem(m, up); Down(IthItem(m, up)) = IthItem(m, n); } } } } void _link_items(MENU *m) { if (Items(m) && IthItem(m, 0)) { ResetLink(m); if (RowMajor(m)) { link_row_major(m); } else { link_col_major(m); } } } # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. # # # MAPFILE HEADER START # # WARNING: STOP NOW. DO NOT MODIFY THIS FILE. # Object versioning must comply with the rules detailed in # # usr/src/lib/README.mapfiles # # You should not be making modifications here until you've read the most current # copy of that file. If you need help, contact a gatekeeper for guidance. # # MAPFILE HEADER END # $mapfile_version 2 SYMBOL_VERSION SUNW_1.1 { global: current_item; free_item; free_menu; item_count; item_description; item_index; item_init; item_name; item_opts; item_opts_off; item_opts_on; item_term; item_userptr; item_value; item_visible; menu_back; menu_driver; menu_fore; menu_format; menu_grey; menu_init; menu_items; menu_mark; menu_opts; menu_opts_off; menu_opts_on; menu_pad; menu_pattern; menu_sub; menu_term; menu_userptr; menu_win; new_item; new_menu; pos_menu_cursor; post_menu; scale_menu; set_current_item; set_item_init; set_item_opts; set_item_term; set_item_userptr; set_item_value; set_menu_back; set_menu_fore; set_menu_format; set_menu_grey; set_menu_init; set_menu_items; set_menu_mark; set_menu_opts; set_menu_pad; set_menu_pattern; set_menu_sub; set_menu_term; set_menu_userptr; set_menu_win; set_top_row; top_row; unpost_menu; }; SYMBOL_VERSION SUNWprivate_1.1 { global: _affect_change; _chk_current; _chk_top; _connect; $if _ELF64 _Default_Item { ASSERT = { TYPE = OBJECT; SIZE = 112; }; }; _Default_Menu { ASSERT = { TYPE = OBJECT; SIZE = 192; }; }; $elif _ELF32 _Default_Item { ASSERT = { TYPE = OBJECT; SIZE = 60; }; }; _Default_Menu { ASSERT = { TYPE = OBJECT; SIZE = 128; }; }; $else $error unknown ELFCLASS $endif _disconnect; _draw; _link_items; _match; _movecurrent; _move_post_item; _position_cursor; _post_item; _scale; _show; local: *; }; /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "private.h" int set_menu_back(MENU *m, chtype attr) { /*LINTED [E_CONST_PROMOTED_UNSIGNED_LONG]*/ if (InvalidAttr(attr)) { return (E_BAD_ARGUMENT); } if (m) { Back(m) = attr; if (Posted(m)) { _draw(m); /* Redraw menu */ _show(m); /* Redisplay menu */ } } else { Back(Dfl_Menu) = attr; } return (E_OK); } chtype menu_back(MENU *m) { return (Back(m ? m : Dfl_Menu)); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "private.h" /* Position the cursor in the user's subwindow. */ void _position_cursor(MENU *m) { int y, x; WINDOW *us, *uw; if (Posted(m)) { /* x and y represent the position in our subwindow */ y = Y(Current(m)) - Top(m); x = X(Current(m))*(Itemlen(m)+1); if (ShowMatch(m)) { if (Pindex(m)) { x += Pindex(m) + Marklen(m) - 1; } } uw = UW(m); us = US(m); (void) wmove(us, y, x); if (us != uw) { wcursyncup(us); wsyncup(us); /* * The next statement gets around some aberrant * behavior in curses. The subwindow is never being * untouched and this results in the parent window * being touched every time a syncup is done. */ (void) untouchwin(us); } } } int pos_menu_cursor(MENU *m) { if (!m) { return (E_BAD_ARGUMENT); } if (!Posted(m)) { return (E_NOT_POSTED); } _position_cursor(m); return (E_OK); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "private.h" int set_menu_fore(MENU *m, chtype attr) { /*LINTED [E_CONST_PROMOTED_UNSIGNED_LONG]*/ if (InvalidAttr(attr)) { return (E_BAD_ARGUMENT); } if (m) { Fore(m) = attr; if (Posted(m)) { _draw(m); /* Go redraw the menu and */ _show(m); /* redisplay it. */ } } else { Fore(Dfl_Menu) = attr; } return (E_OK); } chtype menu_fore(MENU *m) { return (Fore(m ? m : Dfl_Menu)); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "private.h" int set_menu_format(MENU *m, int rows, int cols) { if (rows < 0 || cols < 0) { return (E_BAD_ARGUMENT); } if (m) { if (Posted(m)) { return (E_POSTED); } if (rows == 0) { rows = FRows(m); } if (cols == 0) { cols = FCols(m); } /* The pattern buffer is allocated after items have been */ /* connected */ if (Pattern(m)) { IthPattern(m, 0) = '\0'; Pindex(m) = 0; } FRows(m) = rows; FCols(m) = cols; Cols(m) = min(cols, Nitems(m)); Rows(m) = (Nitems(m)-1) / cols + 1; Height(m) = min(rows, Rows(m)); Top(m) = 0; Current(m) = IthItem(m, 0); SetLink(m); _scale(m); } else { if (rows > 0) { FRows(Dfl_Menu) = rows; } if (cols > 0) { FCols(Dfl_Menu) = cols; } } return (E_OK); } void menu_format(MENU *m, int *rows, int *cols) { if (m) { *rows = FRows(m); *cols = FCols(m); } else { *rows = FRows(Dfl_Menu); *cols = FCols(Dfl_Menu); } } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "private.h" int set_menu_grey(MENU *m, chtype attr) { /*LINTED [E_CONST_PROMOTED_UNSIGNED_LONG]*/ if (InvalidAttr(attr)) { return (E_BAD_ARGUMENT); } if (m) { Grey(m) = attr; if (Posted(m)) { _draw(m); /* Redraw the menu */ _show(m); /* Redisplay menu */ } } else { Grey(Dfl_Menu) = attr; } return (E_OK); } chtype menu_grey(MENU *m) { return (Grey(m ? m : Dfl_Menu)); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "private.h" int set_menu_items(MENU *m, ITEM **i) { if (!m) { return (E_BAD_ARGUMENT); } if (i && *i == (ITEM *) NULL) { return (E_BAD_ARGUMENT); } if (Posted(m)) { return (E_POSTED); } if (Items(m)) { _disconnect(m); } if (i) { /* Go test the item and make sure its not already connected */ /* to another menu and then connect it to this one. */ if (!_connect(m, i)) { return (E_CONNECTED); } } else { Items(m) = i; } return (E_OK); } ITEM ** menu_items(MENU *m) { if (!m) { return ((ITEM **) NULL); } return (Items(m)); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include #include "private.h" int set_menu_mark(MENU *m, char *mark) { int len; /* Length of mark */ if (mark && *mark) { /*LINTED [E_ASSIGN_INT_TO_SMALL_INT]*/ len = strlen(mark); } else { return (E_BAD_ARGUMENT); } if (m) { if (Posted(m) && len != Marklen(m)) { return (E_BAD_ARGUMENT); } Mark(m) = mark; Marklen(m) = len; if (Posted(m)) { _draw(m); /* Redraw menu */ _show(m); /* Redisplay menu */ } else { _scale(m); /* Redo sizing information */ } } else { Mark(Dfl_Menu) = mark; Marklen(Dfl_Menu) = len; } return (E_OK); } char * menu_mark(MENU *m) { return (Mark(m ? m : Dfl_Menu)); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "private.h" int set_menu_opts(MENU *m, int opt) { ITEM **ip; if (m) { if (Posted(m)) { return (E_POSTED); } /* Check to see if the ROWMAJOR option is changing. If so, */ /* set top and current to 0. */ if ((opt & O_ROWMAJOR) != RowMajor(m)) { Top(m) = 0; Current(m) = IthItem(m, 0); (void) set_menu_format(m, FRows(m), FCols(m)); } /* if O_NONCYCLIC option changed, set bit to re-link items */ if ((opt & O_NONCYCLIC) != (Mopt(m) & O_NONCYCLIC)) { SetLink(m); } Mopt(m) = opt; if (OneValue(m) && Items(m)) { for (ip = Items(m); *ip; ip++) { /* Unset values if selection not allowed. */ Value(*ip) = FALSE; } } _scale(m); /* Redo sizing information */ } else { Mopt(Dfl_Menu) = opt; } return (E_OK); } int menu_opts_off(MENU *m, OPTIONS opt) { return (set_menu_opts(m, (Mopt(m ? m : Dfl_Menu)) & ~opt)); } int menu_opts_on(MENU *m, OPTIONS opt) { return (set_menu_opts(m, (Mopt(m ? m : Dfl_Menu)) | opt)); } OPTIONS menu_opts(MENU *m) { return (Mopt(m ? m : Dfl_Menu)); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include #include "private.h" int set_menu_pad(MENU *m, int pad) { if (!isprint(pad)) { return (E_BAD_ARGUMENT); } if (m) { Pad(m) = pad; if (Posted(m)) { _draw(m); /* Redraw menu */ _show(m); /* Display menu */ } } else { Pad(Dfl_Menu) = pad; } return (E_OK); } int menu_pad(MENU *m) { return (Pad(m ? m : Dfl_Menu)); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "private.h" int set_menu_userptr(MENU *m, char *c) { if (m) { Muserptr(m) = c; } else { Muserptr(Dfl_Menu) = c; } return (E_OK); } char * menu_userptr(MENU *m) { return (Muserptr(m ? m : Dfl_Menu)); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "private.h" int set_menu_sub(MENU *m, WINDOW *sub) { if (m) { if (Posted(m)) { return (E_POSTED); } UserSub(m) = sub; /* Since window size has changed go recalculate sizes */ _scale(m); } else { UserSub(Dfl_Menu) = sub; } return (E_OK); } WINDOW * menu_sub(MENU *m) { return (UserSub((m) ? m : Dfl_Menu)); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "private.h" int set_menu_win(MENU *m, WINDOW *win) { if (m) { if (Posted(m)) { return (E_POSTED); } UserWin(m) = win; /* Call scale because the menu subwindow may not be defined */ _scale(m); } else { UserWin(Dfl_Menu) = win; } return (E_OK); } WINDOW * menu_win(MENU *m) { return (UserWin((m) ? m : Dfl_Menu)); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include #include #include "private.h" ITEM * new_item(char *name, char *desc) { ITEM *item; if (item = (ITEM *) calloc(1, sizeof (ITEM))) { /* Set all default values */ *item = *Dfl_Item; /* And set user values */ Name(item) = name; Description(item) = desc; if (name && *name != '\0') { NameLen(item) = strlen(name); } else { free(item); /* Can't have a null name */ return ((ITEM *) NULL); } if (desc && *desc != '\0') { DescriptionLen(item) = strlen(desc); } else { DescriptionLen(item) = 0; } } return (item); } int free_item(ITEM *i) { if (!i) { return (E_BAD_ARGUMENT); } /* Make sure none of the items have pointers to menus. */ if (Imenu(i)) { return (E_CONNECTED); } free(i); return (E_OK); } char * item_name(ITEM *i) { if (i) { return (Name(i)); } return (NULL); } char * item_description(ITEM *i) { if (i) { return (Description(i)); } return (NULL); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include #include "private.h" MENU * new_menu(ITEM **items) { MENU *m; if ((m = (MENU *) calloc(1, sizeof (MENU))) != (MENU *)0) { *m = *Dfl_Menu; Rows(m) = FRows(m); Cols(m) = FCols(m); if (items) { if (*items == (ITEM *)0 || !_connect(m, items)) { free(m); return ((MENU *)0); } } return (m); } return ((MENU *)0); } int free_menu(MENU *m) { if (!m) { return (E_BAD_ARGUMENT); } if (Posted(m)) { return (E_POSTED); } if (Items(m)) { _disconnect(m); } free(m); return (E_OK); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include #include "private.h" static int substr(MENU *m, char *s1, char *s2) { if (IgnoreCase(m)) { while (*s1 && *s2) { if (toupper(*s1++) != toupper(*s2++)) { return (FALSE); } } } else { while (*s1 && *s2) { if (*s1++ != *s2++) { return (FALSE); } } } if (*s1) { return (FALSE); } return (TRUE); } int _match(MENU *m, char c, ITEM **current) { int i, j; int found; /* * Indicates search has cycled past the current item. If the current * item is matched after cycled is true then NO_MATCH results. */ int cycled; /* If a backspace is encountered then search backward from the */ /* current item. Otherwise, search forward from the current item. */ i = Index(*current); if (c && c != '\b') { /* c could be null */ if (Pindex(m)+1 > MaxName(m)) { return (E_NO_MATCH); } IthPattern(m, Pindex(m)) = c; IthPattern(m, ++Pindex(m)) = '\0'; if (--i < 0) { i = Nitems(m)-1; } } j = i; found = FALSE; cycled = FALSE; do { if (c == '\b') { if (--i < 0) { i = Nitems(m)-1; } } else { if (++i >= Nitems(m)) { i = 0; } } if (substr(m, Pattern(m), Name(IthItem(m, i)))) { found = TRUE; break; } cycled = TRUE; } while (i != j); if (found) { if (i == Index(*current) && cycled) { return (E_NO_MATCH); } *current = IthItem(m, i); } else { if (c && c != '\b') { Pindex(m) -= 1; IthPattern(m, Pindex(m)) = '\0'; } return (E_NO_MATCH); } return (E_OK); } char * menu_pattern(MENU *m) { if (m) { if (Pattern(m)) { return (Pattern(m)); } else { return (""); } } else { return (NULL); } } int set_menu_pattern(MENU *m, char *s) { int top; ITEM *current; if (!m || !s) { return (E_BAD_ARGUMENT); } if (!Items(m)) { return (E_NOT_CONNECTED); } if (Indriver(m)) { return (E_BAD_STATE); } IthPattern(m, 0) = '\0'; Pindex(m) = 0; if (*s == '\0') { _position_cursor(m); return (E_OK); } if (LinkNeeded(m)) { _link_items(m); } top = Top(m); current = Current(m); for (; *s; s++) { if (_match(m, *s, ¤t) != E_OK) { IthPattern(m, 0) = '\0'; Pindex(m) = 0; _position_cursor(m); return (E_NO_MATCH); } } _chk_current(m, &top, current); _affect_change(m, top, current); return (E_OK); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "private.h" void _post_item(MENU *m, ITEM *k) { int foreon = FALSE; int backon = FALSE; int greyon = FALSE; chtype c; int i; /* Display the mark region of the item */ if (!Selectable(k)) { (void) wattron(Win(m), Grey(m)); greyon = TRUE; for (i = Marklen(m); i > 0; i--) { (void) waddch(Win(m), ' '); } } else { if (Value(k) || k == Current(m)) { (void) wattron(Win(m), Fore(m)); foreon = TRUE; } else { (void) wattron(Win(m), Back(m)); backon = TRUE; } /* Display the mark */ if (Value(k) || (OneValue(m) && k == Current(m))) { if (Marklen(m)) { (void) waddstr(Win(m), Mark(m)); } } else { for (i = Marklen(m); i > 0; i--) { (void) waddch(Win(m), ' '); } } } /* Display the name */ (void) waddnstr(Win(m), Name(k), MaxName(m)); if (ShowDesc(m) && MaxDesc(m) != 0) { c = Pad(m); } else { c = ' '; } for (i = MaxName(m) - NameLen(k); i > 0; i--) { (void) waddch(Win(m), c); } /* Display the description */ if (ShowDesc(m) && MaxDesc(m) != 0) { (void) waddch(Win(m), Pad(m)); if (DescriptionLen(k) != 0) { (void) waddstr(Win(m), Description(k)); } for (i = MaxDesc(m) - DescriptionLen(k); i > 0; i--) { (void) waddch(Win(m), ' '); } } if (foreon) { (void) wattroff(Win(m), Fore(m)); } if (backon) { (void) wattroff(Win(m), Back(m)); } if (greyon) { (void) wattroff(Win(m), Grey(m)); } } void _move_post_item(MENU *m, ITEM *k) { (void) wmove(Win(m), Y(k), X(k) * (Itemlen(m)+1)); _post_item(m, k); } int unpost_menu(MENU *m) { if (!m) { return (E_BAD_ARGUMENT); } if (Indriver(m)) { return (E_BAD_STATE); } if (!Posted(m)) { return (E_NOT_POSTED); } Iterm(m); Mterm(m); (void) werase(US(m)); wsyncup(US(m)); (void) delwin(Sub(m)); Sub(m) = (WINDOW *) NULL; (void) delwin(Win(m)); Win(m) = (WINDOW *) NULL; ResetPost(m); return (E_OK); } /* * This routine draws the item indicated by oldcur first and then * draws the item indicated by Current. This will have the affect * of unselecting the first item and selecting the next. */ void _movecurrent(MENU *m, ITEM *oldcur) { if (oldcur != Current(m)) { _move_post_item(m, oldcur); _move_post_item(m, Current(m)); } } /* * Draw the entire menu into the super window * This routine assumes all items have been linked and * that the menu is in at least a pre-post state. */ void _draw(MENU *m) { int k; ITEM *i, *j; ITEM *si, *sj; k = 0; /* Line number */ i = IthItem(m, 0); si = Cyclic(m) ? i : (ITEM *) NULL; do { (void) wmove(Win(m), k++, 0); j = i; sj = Cyclic(m) ? j : (ITEM *) NULL; do { _post_item(m, j); if ((j = Right(j)) != sj) { (void) waddch(Win(m), ' '); } } while (j != sj); } while ((i = Down(i)) != si); } int post_menu(MENU *m) { ITEM **ip; int r, c; /* visible # of rows and cols */ if (!m) { return (E_BAD_ARGUMENT); } if (Indriver(m)) { return (E_BAD_STATE); } if (Posted(m)) { return (E_POSTED); } /* Make sure there is at least one item present */ if (Items(m) && IthItem(m, 0)) { getmaxyx(US(m), r, c); /* Make sure the menu fits into the window horizontally */ if (c < Width(m) || r < Height(m)) { return (E_NO_ROOM); } /* Create the menu window and derived windows */ if ((Win(m) = newwin(Rows(m), Width(m), 0, 0)) == (WINDOW *) NULL) { return (E_SYSTEM_ERROR); } /* * Take the minimum of the height of the menu (Height), the * physical height of the window (r), and the number of rows * in the menu (Rows). */ r = min(min(r, Rows(m)), Height(m)); if ((Sub(m) = derwin(Win(m), r, Width(m), 0, 0)) == (WINDOW *) NULL) { return (E_SYSTEM_ERROR); } /* If needed, link all items in the menu */ if (LinkNeeded(m)) { _link_items(m); } SetPost(m); /* If only one value can be set then unset all values */ /* to start. */ if (OneValue(m)) { for (ip = Items(m); *ip; ip++) { Value(*ip) = FALSE; } } /* Go do the drawing of the menu */ _draw(m); Minit(m); Iinit(m); _show(m); /* Display the menu */ return (E_OK); } return (E_NOT_CONNECTED); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "private.h" /* Calculate the numbers of rows and columns needed to display the menu */ void _scale(MENU *m) { int width; if (Items(m) && IthItem(m, 0)) { /* Get the width of one column */ width = MaxName(m) + Marklen(m); if (ShowDesc(m) && MaxDesc(m)) { width += MaxDesc(m) + 1; } Itemlen(m) = width; /* Multiply this by the number of columns */ width = width * Cols(m); /* Add in the number of spaces between columns */ width += Cols(m) - 1; Width(m) = width; } } int scale_menu(MENU *m, int *r, int *c) { if (!m) { return (E_BAD_ARGUMENT); } if (Items(m) && IthItem(m, 0)) { *r = Height(m); *c = Width(m); return (E_OK); } return (E_NOT_CONNECTED); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "private.h" /* Display that portion of the menu visable to the user */ void _show(MENU *m) { int r, c; WINDOW *us; if (Posted(m) || Indriver(m)) { (void) mvderwin(Sub(m), Top(m), 0); us = US(m); getmaxyx(us, r, c); r = min(Height(m), r); c = min(Width(m), c); (void) copywin(Sub(m), us, 0, 0, 0, 0, r-1, c-1, FALSE); _position_cursor(m); } } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "private.h" int set_menu_init(MENU *m, PTF_void mi) { if (m) { SMinit(m) = mi; } else { SMinit(Dfl_Menu) = mi; } return (E_OK); } PTF_void menu_init(MENU *m) { return (SMinit(m ? m : Dfl_Menu)); } int set_menu_term(MENU *m, PTF_void mt) { if (m) { SMterm(m) = mt; } else { SMterm(Dfl_Menu) = mt; } return (E_OK); } PTF_void menu_term(MENU *m) { return (SMterm(m ? m : Dfl_Menu)); } int set_item_init(MENU *m, PTF_void ii) { if (m) { SIinit(m) = ii; } else { SIinit(Dfl_Menu) = ii; } return (E_OK); } PTF_void item_init(MENU *m) { return (SIinit(m ? m : Dfl_Menu)); } int set_item_term(MENU *m, PTF_void it) { if (m) { SIterm(m) = it; } else { SIterm(Dfl_Menu) = it; } return (E_OK); } PTF_void item_term(MENU *m) { return (SIterm(m ? m : Dfl_Menu)); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "private.h" int set_top_row(MENU *m, int top) { ITEM *current; if (m) { if (Indriver(m)) { return (E_BAD_STATE); } if (!Items(m)) { return (E_NOT_CONNECTED); } if (top < 0 || top > Rows(m) - Height(m)) { return (E_BAD_ARGUMENT); } if (top != Top(m)) { /* Get linking information if not already there */ if (LinkNeeded(m)) { _link_items(m); } /* Set current to toprow */ current = IthItem(m, RowMajor(m) ? top * Cols(m) : top); Pindex(m) = 0; /* Clear the pattern buffer */ IthPattern(m, Pindex(m)) = '\0'; _affect_change(m, top, current); } } else { return (E_BAD_ARGUMENT); } return (E_OK); } int top_row(MENU *m) { if (m && Items(m) && IthItem(m, 0)) { return (Top(m)); } else { return (-1); } } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ /*LINTLIBRARY*/ #include #include "private.h" /* Check to see if an item is being displayed on the current page */ int item_visible(ITEM *i) { int bottom; MENU *m; if (!i || !Imenu(i)) { return (FALSE); } m = Imenu(i); if (Posted(m)) { bottom = Top(m) + Height(m) - 1; if (Y(i) >= Top(m) && Y(i) <= bottom) { return (TRUE); } } return (FALSE); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MENU_H #define _MENU_H #include #include #ifdef __cplusplus extern "C" { #endif /* Menu options: */ #define O_ONEVALUE 0x01 #define O_SHOWDESC 0x02 #define O_ROWMAJOR 0x04 #define O_IGNORECASE 0x08 #define O_SHOWMATCH 0x10 #define O_NONCYCLIC 0x20 /* Item options: */ #define O_SELECTABLE 0x01 typedef struct { char *str; int length; } TEXT; typedef struct ITEM { TEXT name; TEXT description; int index; /* Item number */ struct MENU *imenu; /* Pointer to parent menu */ int value; char *userptr; OPTIONS opt; int status; short y; /* y and x location of item in menu */ short x; struct ITEM *left; struct ITEM *right; struct ITEM *up; struct ITEM *down; } ITEM; #define _POSTED 0x1 #define _IN_DRIVER 0x2 #define _LINK_NEEDED 0x4 typedef struct MENU { int height; /* Number of chars high */ int width; /* Number of chars wide */ int rows; /* Number of items high */ int cols; /* Number of items wide */ int frows; /* Number of formated items high */ int fcols; /* Number of formated items wide */ int namelen; /* Length of widest name */ int desclen; /* Length of widest description */ int marklen; /* Length of mark */ int itemlen; /* Length of an one item */ char *pattern; /* Buffer used to store match chars */ int pindex; /* Index into pattern buffer */ WINDOW *win; /* Window containing entire menu */ WINDOW *sub; /* Portion of menu displayed */ WINDOW *userwin; /* User's window */ WINDOW *usersub; /* User's subwindow */ ITEM **items; int nitems; /* Total number of items in menu */ ITEM *curitem; /* Current item */ int toprow; /* Top row of menu */ int pad; /* Pad character */ chtype fore; /* Attribute for selection */ chtype back; /* Attribute for nonselection */ chtype grey; /* Attribute for inactive */ PTF_void menuinit; PTF_void menuterm; PTF_void iteminit; PTF_void itemterm; char *userptr; char *mark; OPTIONS opt; int status; } MENU; /* Define keys */ #define REQ_LEFT_ITEM KEY_MAX+1 #define REQ_RIGHT_ITEM KEY_MAX+2 #define REQ_UP_ITEM KEY_MAX+3 #define REQ_DOWN_ITEM KEY_MAX+4 #define REQ_SCR_ULINE KEY_MAX+5 #define REQ_SCR_DLINE KEY_MAX+6 #define REQ_SCR_DPAGE KEY_MAX+7 #define REQ_SCR_UPAGE KEY_MAX+8 #define REQ_FIRST_ITEM KEY_MAX+9 #define REQ_LAST_ITEM KEY_MAX+10 #define REQ_NEXT_ITEM KEY_MAX+11 #define REQ_PREV_ITEM KEY_MAX+12 #define REQ_TOGGLE_ITEM KEY_MAX+13 #define REQ_CLEAR_PATTERN KEY_MAX+14 #define REQ_BACK_PATTERN KEY_MAX+15 #define REQ_NEXT_MATCH KEY_MAX+16 #define REQ_PREV_MATCH KEY_MAX+17 #ifdef __STDC__ extern ITEM **menu_items(MENU *), *current_item(MENU *), *new_item(char *, char *); extern MENU *new_menu(ITEM **); extern OPTIONS item_opts(ITEM *), menu_opts(MENU *); extern PTF_void item_init(MENU *), item_term(MENU *), menu_init(MENU *), menu_term(MENU *); extern WINDOW *menu_sub(MENU *), *menu_win(MENU *); extern char *item_description(ITEM *), *item_name(ITEM *), *item_userptr(ITEM *), *menu_mark(MENU *), *menu_pattern(MENU *), *menu_userptr(MENU *); extern chtype menu_back(MENU *), menu_fore(MENU *), menu_grey(MENU *); extern int free_item(ITEM *), free_menu(MENU *), item_count(MENU *), item_index(ITEM *), item_opts_off(ITEM *, OPTIONS), item_opts_on(ITEM *, OPTIONS), item_value(ITEM *), item_visible(ITEM *), menu_driver(MENU *, int), menu_opts_off(MENU *, OPTIONS), menu_opts_on(MENU *, OPTIONS), menu_pad(MENU *), pos_menu_cursor(MENU *), post_menu(MENU *), scale_menu(MENU *, int *, int *), set_current_item(MENU *, ITEM *), set_item_init(MENU *, PTF_void), set_item_opts(ITEM *, OPTIONS), set_item_term(MENU *, PTF_void), set_item_userptr(ITEM *, char *), set_item_value(ITEM *, int), set_menu_back(MENU *, chtype), set_menu_fore(MENU *, chtype), set_menu_format(MENU *, int, int), set_menu_grey(MENU *, chtype), set_menu_init(MENU *, PTF_void), set_menu_items(MENU *, ITEM **), set_menu_mark(MENU *, char *), set_menu_opts(MENU *, OPTIONS), set_menu_pad(MENU *, int), set_menu_pattern(MENU *, char *), set_menu_sub(MENU *, WINDOW *), set_menu_term(MENU *, PTF_void), set_menu_userptr(MENU *, char *), set_menu_win(MENU *, WINDOW *), set_top_row(MENU *, int), top_row(MENU *), unpost_menu(MENU *); void menu_format(MENU *, int *, int *); #else /* old style extern's */ extern ITEM **menu_items(), *current_item(), *new_item(); extern MENU *new_menu(); extern OPTIONS item_opts(), menu_opts(); extern PTF_void item_init(), item_term(), menu_init(), menu_term(); extern WINDOW *menu_sub(), *menu_win(); extern char *item_description(), *item_name(), *item_userptr(), *menu_mark(), *menu_pattern(), *menu_userptr(); extern chtype menu_back(), menu_fore(), menu_grey(); extern int free_item(), free_menu(), item_count(), item_index(), item_opts_off(), item_opts_on(), item_value(), item_visible(), menu_driver(), menu_opts_off(), menu_opts_on(), menu_pad(), pos_menu_cursor(), post_menu(), scale_menu(), set_current_item(), set_item_init(), set_item_opts(), set_item_term(), set_item_userptr(), set_item_value(), set_menu_back(), set_menu_fore(), set_menu_format(), set_menu_grey(), set_menu_init(), set_menu_items(), set_menu_mark(), set_menu_opts(), set_menu_pad(), set_menu_pattern(), set_menu_sub(), set_menu_term(), set_menu_userptr(), set_menu_win(), set_top_row(), top_row(), unpost_menu(); void menu_format(); #endif /* __STDC__ */ #ifdef __cplusplus } #endif #endif /* _MENU_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Mircrosystems, Inc. * All rights reserved. */ #ifndef _MENU_PRIVATE_H #define _MENU_PRIVATE_H #include #ifdef __cplusplus extern "C" { #endif /* Menu macros to access menu structure */ #define Height(m) (m)->height #define Width(m) (m)->width #define Rows(m) (m)->rows #define Cols(m) (m)->cols #define FRows(m) (m)->frows #define FCols(m) (m)->fcols #define MaxName(m) (m)->namelen #define MaxDesc(m) (m)->desclen #define Marklen(m) (m)->marklen #define Itemlen(m) (m)->itemlen #define Pattern(m) (m)->pattern #define Pindex(m) (m)->pindex #define IthPattern(m, i) (m)->pattern[i] #define Win(m) (m)->win #define Sub(m) (m)->sub #define UserWin(m) (m)->userwin #define UserSub(m) (m)->usersub #define UW(m) (UserWin(m) ? UserWin(m) : stdscr) #define US(m) (UserSub(m) ? UserSub(m) : UW(m)) #define Items(m) (m)->items #define IthItem(m, i) (m)->items[i] #define Nitems(m) (m)->nitems #define Current(m) (m)->curitem #define Top(m) (m)->toprow #define Pad(m) (m)->pad #define Fore(m) (m)->fore #define Back(m) (m)->back #define Grey(m) (m)->grey #define InvalidAttr(a) (((a) & (chtype) A_ATTRIBUTES) != (a)) #define Mhelp(m) (m)->help #define Muserptr(m) (m)->userptr #define Mopt(m) (m)->opt #define Mark(m) (m)->mark #define Mstatus(m) (m)->status #define Posted(m) (Mstatus(m) & _POSTED) #define Indriver(m) (Mstatus(m) & _IN_DRIVER) #define LinkNeeded(m) (Mstatus(m) & _LINK_NEEDED) #define SetPost(m) (Mstatus(m) |= _POSTED) #define SetDriver(m) (Mstatus(m) |= _IN_DRIVER) #define SetLink(m) (Mstatus(m) |= _LINK_NEEDED) #define ResetPost(m) (Mstatus(m) &= ~_POSTED) #define ResetDriver(m) (Mstatus(m) &= ~_IN_DRIVER) #define ResetLink(m) (Mstatus(m) &= ~_LINK_NEEDED) #define SMinit(m) (m)->menuinit #define SMterm(m) (m)->menuterm #define SIinit(m) (m)->iteminit #define SIterm(m) (m)->itemterm #define Minit(m) if (m->menuinit) { \ SetDriver(m); \ (m)->menuinit(m); \ ResetDriver(m); \ } #define Mterm(m) if (m->menuterm) { \ SetDriver(m); \ (m)->menuterm(m); \ ResetDriver(m); \ } #define Iinit(m) if (m->iteminit) { \ SetDriver(m); \ (m)->iteminit(m); \ ResetDriver(m); \ } #define Iterm(m) if (m->itemterm) { \ SetDriver(m); \ (m)->itemterm(m); \ ResetDriver(m); \ } /* Define access to Mopt */ #define OneValue(m) (Mopt(m) & O_ONEVALUE) #define ShowDesc(m) (Mopt(m) & O_SHOWDESC) #define RowMajor(m) (Mopt(m) & O_ROWMAJOR) #define IgnoreCase(m) (Mopt(m) & O_IGNORECASE) #define ShowMatch(m) (Mopt(m) & O_SHOWMATCH) #define Cyclic(m) (!(Mopt(m) & O_NONCYCLIC)) /* Item macros to access item structure */ #define Name(i) (i)->name.str #define NameLen(i) (i)->name.length #define Description(i) (i)->description.str #define DescriptionLen(i) (i)->description.length #define Index(i) (i)->index #define Y(i) (i)->y #define X(i) (i)->x #define Imenu(i) (i)->imenu #define Value(i) (i)->value #define Ihelp(i) (i)->help #define Iuserptr(i) (i)->userptr #define Iopt(i) (i)->opt #define Istatus(i) (i)->status #define Up(i) (i)->up #define Down(i) (i)->down #define Left(i) (i)->left #define Right(i) (i)->right #define Selectable(i) (Iopt(i) & O_SELECTABLE) /* Default menu macros */ #define Dfl_Menu (&_Default_Menu) #define Dfl_Item (&_Default_Item) #define max(a, b) ((a) > (b)) ? (a) : (b) #define min(a, b) ((a) < (b)) ? (a) : (b) extern MENU _Default_Menu; extern ITEM _Default_Item; extern void _affect_change(MENU *, int, ITEM *); extern void _chk_current(MENU *, int *, ITEM *); extern void _chk_top(MENU *, int *, ITEM *); extern void _disconnect(MENU *); extern void _draw(MENU *); extern void _link_items(MENU *); extern void _move_post_item(MENU *, ITEM *); extern void _movecurrent(MENU *, ITEM *); extern void _position_cursor(MENU *); extern void _scale(MENU *); extern void _show(MENU *); extern int _match(MENU *, char, ITEM **); extern int _connect(MENU *, ITEM **); #ifdef __cplusplus } #endif #endif /* _MENU_PRIVATE_H */ # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2006 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # include ../../Makefile.lib # Hammerhead: amd64-only SUBDIRS= $(MACH64) all : TARGET= all clean : TARGET= clean clobber : TARGET= clobber install : TARGET= install .KEEP_STATE: all clean clobber install: $(SUBDIRS) # definitions for install_h target HDRS= panel.h ROOTHDRDIR= $(ROOT)/usr/include ROOTHDRS= $(HDRS:%=$(ROOTHDRDIR)/%) CHECKHDRS= $(HDRS:%.h=inc/%.check) # install rule for install_h target $(ROOTHDRDIR)/%: inc/% $(INS.file) install_h: $(ROOTHDRS) check: $(CHECKHDRS) $(SUBDIRS): FRC @cd $@; pwd; $(MAKE) $(TARGET) FRC: # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # LIBRARY= libpanel.a VERS= .1 OBJECTS= \ bottom.o \ move.o \ replace.o \ update.o \ delete.o \ misc.o \ new.o \ top.o # include library definitions include ../../../Makefile.lib LIBS = $(DYNLIB) SRCDIR= ../common CPPFLAGS += -I../inc CFLAGS += $(CCVERBOSE) LDLIBS += -lcurses -lc CERRWARN += -Wno-parentheses COMPATLINKS= usr/ccs/lib/libpanel.so # Hammerhead: flattened layout — no amd64 subdir COMPATLINKS64= $(COMPATLINKS) $(ROOT)/usr/ccs/lib/libpanel.so: COMPATLINKTARGET=../../lib/libpanel.so.1 .KEEP_STATE: all: $(LIBS) # include library targets include ../../../Makefile.targ pics/%.o: ../common/%.c $(COMPILE.c) -o $@ $< $(POST_PROCESS_O) # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2006 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # include ../Makefile.com include ../../../Makefile.lib.64 DYNFLAGS += $(DYNFLAGS64) .KEEP_STATE: install: all $(ROOTLIBS64) $(ROOTLINKS64) $(ROOTCOMPATLINKS64) /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /* A panels subsystem built on curses--Move a panel to the bottom */ /*LINTLIBRARY*/ #include #include #include "private.h" /* bottom_panel */ int bottom_panel(PANEL *panel) { PANEL *pnl; _obscured_list *obs; if (!panel || panel == panel -> below) return (ERR); /* If the panel is already on bottom, there is nothing to do */ if (_Bottom_panel == panel) return (OK); /* * All the panels that this panel used to obscure now * obscure this panel. */ for (pnl = panel->below; pnl; pnl = pnl->below) { if (obs = _unlink_obs(pnl, panel)) { obs -> panel_p = pnl; if (panel -> obscured) { obs -> next = panel -> obscured -> next; panel->obscured = panel->obscured->next = obs; } else obs -> next = panel -> obscured = obs; } } /* Move the panel to the bottom */ if (panel == _Top_panel) (_Top_panel = panel -> below) -> above = 0; else { panel -> above -> below = panel -> below; panel -> below -> above = panel -> above; } panel -> below = 0; panel -> above = _Bottom_panel; _Bottom_panel = _Bottom_panel -> below = panel; (void) touchwin(panel -> win); return (OK); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /* A panels subsystem built on curses--Delete panel routines */ /*LINTLIBRARY*/ #include #include #include #include "private.h" /* hide_panel - Unlink a panel from the pile and remove it from the screen. */ int hide_panel(PANEL *panel) { if (!panel) return (ERR); /* It is ok to hide a panel that is already hidden. */ if (panel == panel -> below) return (OK); /* unlink panel */ _remove_overlap(panel); if (panel == _Bottom_panel) _Bottom_panel = panel -> above; else panel -> below -> above = panel -> above; if (panel == _Top_panel) _Top_panel = panel -> below; else panel -> above -> below = panel -> below; _Panel_cnt--; panel -> below = panel; return (OK); } /* * del_panel - Delete a panel from the pile * and free all memory associated with it. */ int del_panel(PANEL *panel) { return ((hide_panel(panel) == OK) ? free(panel), OK : ERR); } /* * _remove_overlap * Remove all references to a panel from the obscured lists of all panels. * Also remove all obscured nodes from the given panel. This routine * touches the appropriate places to ensure that everybody is properly * updated. */ void _remove_overlap(PANEL *panel) { PANEL *pnl; _obscured_list *obs; _obscured_list *prev_obs; /* Make sure that the background gets updated */ (void) touchline(stdscr, panel->wstarty, panel->wendy - panel->wstarty + 1); /* Remove all references to the panel from the remaining panels */ for (pnl = _Bottom_panel; pnl != panel; pnl = pnl->above) { if (obs = _unlink_obs(pnl, panel)) _free_overlap(obs); } /* delete the obscured list from the panel */ if ((obs = panel -> obscured) != 0) { do { prev_obs = obs; obs = obs -> next; _free_overlap(prev_obs); } while (obs != panel -> obscured); panel -> obscured = 0; } } # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. # # # MAPFILE HEADER START # # WARNING: STOP NOW. DO NOT MODIFY THIS FILE. # Object versioning must comply with the rules detailed in # # usr/src/lib/README.mapfiles # # You should not be making modifications here until you've read the most current # copy of that file. If you need help, contact a gatekeeper for guidance. # # MAPFILE HEADER END # $mapfile_version 2 SYMBOL_VERSION SUNW_1.1 { global: bottom_panel; del_panel; hide_panel; move_panel; new_panel; panel_above; panel_below; panel_hidden; panel_userptr; panel_window; replace_panel; set_panel_userptr; show_panel; top_panel; update_panels; }; SYMBOL_VERSION SUNWprivate_1.1 { global: _alloc_overlap; _Bottom_panel { ASSERT = { TYPE = OBJECT; SIZE = addrsize; }; }; _free_overlap; _intersect_panel; _Panel_cnt { ASSERT = { TYPE = OBJECT; SIZE = 4; }; }; _remove_overlap; _Top_panel { ASSERT = { TYPE = OBJECT; SIZE = addrsize; }; }; _unlink_obs; local: *; }; /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /* A panels subsystem built on curses--Miscellaneous routines */ /*LINTLIBRARY*/ #include #include #include #include "private.h" PANEL *_Bottom_panel; PANEL *_Top_panel; int _Panel_cnt; static _obscured_list *_Free_list; static int _Free_list_cnt; /* panel_window - Return the window pointer */ WINDOW * panel_window(PANEL *panel) { return (panel ? panel -> win : 0); } /* panel_userptr - Return the user pointer */ char * panel_userptr(PANEL *panel) { return (panel ? panel -> user : 0); } /* set_panel_userptr - set the user pointer */ int set_panel_userptr(PANEL *panel, char *ptr) { if (panel) { panel -> user = ptr; return (OK); } else return (ERR); } /* * panel_above - Return the panel above the * given panel (or the bottom panel in 0) */ PANEL * panel_above(PANEL *panel) { if (!panel) return (_Bottom_panel); return ((panel == panel -> below) ? ((PANEL *) 0) : panel -> above); } /* * panel_below - Return the panel below the * given panel (or the top panel in 0) */ PANEL * panel_below(PANEL *panel) { if (!panel) return (_Top_panel); return ((panel == panel -> below) ? ((PANEL *) 0) : panel -> below); } /* panel_hidden - Return TRUE if the panel is hidden, FALSE if not. */ int panel_hidden(PANEL *panel) { return ((!panel || (panel != panel -> below)) ? FALSE : TRUE); } /* _get_overlap - Get an overlap node from the free list. */ static _obscured_list * _get_overlap(void) { _obscured_list *overlap; if (_Free_list_cnt-- > 0) { overlap = _Free_list; _Free_list = _Free_list -> next; } else { _Free_list_cnt = 0; overlap = 0; } return (overlap); } /* * _unlink_obs - Find the obscured node, if any, * in the first panel which refers the second panel. */ _obscured_list * _unlink_obs(PANEL *pnl, PANEL *panel) { _obscured_list *obs; _obscured_list *prev_obs; if (!pnl -> obscured || !_panels_intersect(pnl, panel)) return ((_obscured_list *) 0); obs = pnl -> obscured; do { prev_obs = obs; obs = obs -> next; } while (obs->panel_p != panel && obs != pnl->obscured); if (obs -> panel_p != panel) { #ifdef DEBUG fprintf(stderr, "_unlink_obs: Obscured panel lost\n"); #endif return ((_obscured_list *) 0); } if (obs == prev_obs) pnl -> obscured = 0; else { prev_obs -> next = obs -> next; if (obs == pnl -> obscured) pnl -> obscured = prev_obs; } return (obs); } /* * add_obs - Add an obscured node to a panel, ensuring * that the obscured list is ordered from top to bottom. */ static void add_obs(PANEL *panel, _obscured_list *obs) { PANEL *pnl; _obscured_list *curr_obs; _obscured_list *prev_obs; if ((prev_obs = panel -> obscured) == 0) { panel -> obscured = obs -> next = obs; return; } curr_obs = prev_obs -> next; for (pnl = _Top_panel; pnl != panel; pnl = pnl->below) { if (curr_obs -> panel_p == pnl) { prev_obs = curr_obs; curr_obs = curr_obs -> next; if (prev_obs == panel -> obscured) { panel -> obscured = obs; break; } } } obs -> next = curr_obs; prev_obs -> next = obs; } /* * _intersect_panel * Create an obscured node for each panel that the given panel intersects. * The overlap record is always attached to the panel which is covered up. * * This routine assumes that _alloc_overlap() has been called to ensure * that there are enough overlap nodes to satisfy the requests. */ void _intersect_panel(PANEL *panel) { PANEL *pnl; _obscured_list *obs; int above_panel; above_panel = FALSE; for (pnl = _Bottom_panel; pnl; pnl = pnl -> above) { if (pnl == panel) { above_panel = TRUE; continue; } if (!_panels_intersect(pnl, panel)) continue; /* no overlap */ obs = _get_overlap(); obs->start = (panel->wstarty >= pnl->wstarty) ? panel->wstarty : pnl->wstarty; obs->end = (panel->wendy <= pnl->wendy) ? panel->wendy : pnl->wendy; if (above_panel) { obs -> panel_p = pnl; if (panel -> obscured) { obs -> next = panel -> obscured -> next; panel -> obscured -> next = obs; } else obs -> next = panel -> obscured = obs; } else { obs -> panel_p = panel; add_obs(pnl, obs); } } } /* * _alloc_overlap * Create enough obscured nodes to record all overlaps of a given * panel. The obscured nodes must be pre-allocated by this routine * to preserve the integrity of the pile during move. * If the move operation fails, the pile is supposed to remain * unchanged. If the obscured nodes are not allocated in advance, * then an allocation failure in the middle of a move could * leave the pile in a corrupted state with possibly no way to * restore the pile to its original state. * * The cnt parameter is the(worst case) number of overlap nodes which * are required to satisfy any request. Return 0 on error, else non-zero */ int _alloc_overlap(int cnt) { _obscured_list *overlap; int i; for (i = cnt-_Free_list_cnt; i > 0; i--) { if (!(overlap = (_obscured_list *) malloc(sizeof (_obscured_list)))) return (0); overlap -> next = _Free_list; _Free_list = overlap; _Free_list_cnt++; } return (1); } /* * _free_overlap - Free a single overlap node. Don't * really free it; just save it on a list. */ void _free_overlap(_obscured_list *overlap) { overlap -> next = _Free_list; _Free_list = overlap; _Free_list_cnt++; } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /* A panels subsystem built on curses--Move a panel */ /*LINTLIBRARY*/ #include #include #include "private.h" /* move_panel */ int move_panel(PANEL *panel, int starty, int startx) { if (!panel) return (ERR); /* Check for hidden panels and move the window */ if (panel == panel -> below) { if (mvwin(panel -> win, starty, startx) == ERR) return (ERR); } else { /* * allocate nodes for overlap of new panel and move * the curses window, removing it from the old location. */ if (!_alloc_overlap(_Panel_cnt - 1) || mvwin(panel -> win, starty, startx) == ERR) return (ERR); _remove_overlap(panel); } /* Make sure we know where the window is */ getbegyx(panel -> win, panel -> wstarty, panel -> wstartx); getmaxyx(panel -> win, panel -> wendy, panel -> wendx); panel -> wendy += panel -> wstarty - 1; panel -> wendx += panel -> wstartx - 1; /* Determine which panels the new panel obscures (if not hidden) */ if (panel != panel -> below) _intersect_panel(panel); return (OK); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /* A panels subsystem built on curses--create a new panel */ /*LINTLIBRARY*/ #include #include #include #include "private.h" /* add_top - Put a new or hidden panel on top of the pile */ static void add_top(PANEL *panel) { if (!_Top_panel) { panel-> below = 0; _Bottom_panel = panel; } else { _Top_panel -> above = panel; panel -> below = _Top_panel; } _Top_panel = panel; panel -> above = 0; panel -> obscured = 0; _Panel_cnt++; /* Determine which panels the new panel obscures */ _intersect_panel(panel); } /* new_panel */ PANEL * new_panel(WINDOW *window) { PANEL *panel; int lines, cols; /* create a panel */ if (!window || !_alloc_overlap(_Panel_cnt) || !(panel = (PANEL *) malloc(sizeof (PANEL)))) return ((PANEL *) 0); panel -> win = window; getbegyx(window, panel -> wstarty, panel -> wstartx); getmaxyx(window, lines, cols); panel -> wendy = panel->wstarty + lines - 1; panel -> wendx = panel->wstartx + cols - 1; panel -> user = 0; /* put the new panel on top of the pile */ add_top(panel); return (panel); } /* show_panel */ int show_panel(PANEL *panel) { /* Allocate the obscured nodes for the new panel */ if (!panel || panel != panel -> below || !_alloc_overlap(_Panel_cnt)) return (ERR); /* put the new panel on top of the pile */ add_top(panel); (void) touchwin(panel -> win); return (OK); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /* A panels subsystem built on curses--Replace the window in a panel */ /*LINTLIBRARY*/ #include #include #include "private.h" /* replace_panel */ int replace_panel(PANEL *panel, WINDOW *window) { if (!panel || !window) return (ERR); /* pre-allocate the overlap nodes if the panel is not hidden */ if (panel != panel -> below) { if (!_alloc_overlap(_Panel_cnt - 1)) return (ERR); /* Remove the window from the old location. */ _remove_overlap(panel); } /* Find the size of the new window */ getbegyx(window, panel -> wstarty, panel -> wstartx); getmaxyx(window, panel -> wendy, panel -> wendx); panel -> win = window; panel -> wendy += panel -> wstarty - 1; panel -> wendx += panel -> wstartx - 1; /* Determine which panels the new panel obscures (if not hidden) */ if (panel != panel -> below) _intersect_panel(panel); (void) touchwin(window); return (OK); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /* A panels subsystem built on curses--Move a panel to the top */ /*LINTLIBRARY*/ #include #include #include "private.h" /* top_panel */ int top_panel(PANEL *panel) { _obscured_list *obs; _obscured_list *prev_obs, *tmp; if (!panel || panel == panel -> below) return (ERR); /* If the panel is already on top, there is nothing to do */ if (_Top_panel == panel) return (OK); /* * All the panels that used to obscure this panel are * now obscured by this panel. */ if ((obs = panel -> obscured) != 0) { do { prev_obs = obs; obs = obs -> next; if ((tmp = prev_obs -> panel_p -> obscured) != 0) { prev_obs->next = tmp->next; tmp->next = prev_obs; } else prev_obs->next = prev_obs->panel_p->obscured = prev_obs; prev_obs -> panel_p = panel; } while (obs != panel -> obscured); panel -> obscured = 0; } /* Move the panel to the top */ if (panel == _Bottom_panel) (_Bottom_panel = panel -> above) -> below = 0; else { panel -> above -> below = panel -> below; panel -> below -> above = panel -> above; } panel -> above = 0; panel -> below = _Top_panel; _Top_panel = _Top_panel -> above = panel; (void) touchwin(panel -> win); return (OK); } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /* A panels subsystem built on curses--Update the pile of panels */ /*LINTLIBRARY*/ #include #include #include #include "private.h" /* * touch_top - Touch the line in all windows * which is visible above a given line */ static void touch_top(PANEL *panel, int line, _obscured_list *obs, int start_x, int end_x) { PANEL *pnl; _obscured_list *next_obs; do { pnl = obs -> panel_p; if ((next_obs = obs->next) == panel -> obscured -> next) next_obs = 0; if (line >= obs -> start && line <= obs -> end && pnl->wstartx <= end_x && pnl->wendx >= start_x) { (void) touchline(pnl->win, line - pnl->wstarty, 1); if (pnl->wstartx > start_x && pnl->wendx < end_x) { if (next_obs) touch_top(panel, line, next_obs, pnl->wendx+1, end_x); end_x = pnl -> wstartx - 1; } else { if (pnl->wstartx <= start_x) start_x = pnl -> wendx + 1; if (pnl->wendx >= end_x) end_x = pnl -> wstartx - 1; if (start_x > end_x) return; } } } while ((obs = next_obs) != 0); } /* * std_touch_top * Touch the line in all windows which is visible above a given line. * This routine is almost identical to touch_top, except that the "panel" * is stdscr in this case. The "obscured" list is the list of panels. */ static void std_touch_top(int line, PANEL *obs_pnl, int start_x, int end_x) { PANEL *next_obs; do { next_obs = obs_pnl -> below; if (line >= obs_pnl->wstarty && line <= obs_pnl->wendy && obs_pnl->wstartx <= end_x && obs_pnl->wendx >= start_x) { (void) touchline(obs_pnl->win, line - obs_pnl->wstarty, 1); if (obs_pnl->wstartx > start_x && obs_pnl->wendx < end_x) { if (next_obs) std_touch_top(line, next_obs, obs_pnl->wendx+1, end_x); end_x = obs_pnl -> wstartx - 1; } else { if (obs_pnl->wstartx <= start_x) start_x = obs_pnl -> wendx + 1; if (obs_pnl->wendx >= end_x) end_x = obs_pnl -> wstartx - 1; if (start_x > end_x) return; } } } while ((obs_pnl = next_obs) != 0); } /* touchup - Touch lines in obscuring panals as necessary */ static void touchup(PANEL *panel) { int screen_y, i; /* * for each line in the window which has been touched, * touch lines in panals above it. */ screen_y = panel->wendy; for (i = panel->wendy - panel->wstarty; i >= 0; screen_y--, i--) { if (is_linetouched(panel -> win, i) == TRUE) touch_top(panel, screen_y, panel->obscured->next, panel->wstartx, panel->wendx); } } /* * std_touchup * Touch lines in obscuring panals as necessary. This routine is * almost exactly like touchup, except that the "panel" is stdscr, * and the obscured list is the list of panels. */ static void std_touchup(void) { int screen_y; /* * for each line in stdscr which has been touched, * touch lines in panals above it. */ for (screen_y = LINES - 1; screen_y >= 0; screen_y--) { if (is_linetouched(stdscr, screen_y) == TRUE) std_touch_top(screen_y, _Top_panel, 0, COLS - 1); } } /* update_panels - Refresh the pile of panels */ void update_panels(void) { PANEL *panel; /* * if stdscr has been touched, touch the visible lines * in each panel. */ if (is_wintouched(stdscr)) { if (_Bottom_panel) std_touchup(); (void) wnoutrefresh(stdscr); } /* * Refresh panals starting at the bottom of the pile. * If a line in a window has been touched, touch all * corresponding lines in the obscuring windows. */ for (panel = _Bottom_panel; panel; panel = panel -> above) { if (is_wintouched(panel -> win)) { if (panel -> obscured) touchup(panel); (void) wnoutrefresh(panel -> win); } } } /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ #ifndef _PANEL_H #define _PANEL_H #include #ifdef __cplusplus extern "C" { #endif typedef struct _obscured_list { struct PANEL *panel_p; int start, end; struct _obscured_list *next; } _obscured_list; typedef struct PANEL { WINDOW *win; int wstarty; int wendy; int wstartx; int wendx; struct _obscured_list *obscured; struct PANEL *below, *above; char *user; } PANEL; #ifdef __STDC__ extern PANEL *new_panel(WINDOW *); extern int del_panel(PANEL *); extern int hide_panel(PANEL *); extern int show_panel(PANEL *); extern int panel_hidden(PANEL *); extern int move_panel(PANEL *, int, int); extern int replace_panel(PANEL *, WINDOW *); extern int top_panel(PANEL *); extern int bottom_panel(PANEL *); extern void update_panels(void); extern WINDOW *panel_window(PANEL *); extern int set_panel_userptr(PANEL *, char *); extern char *panel_userptr(PANEL *); extern PANEL *panel_above(PANEL *); extern PANEL *panel_below(PANEL *); #else /* old style extern's */ extern PANEL *new_panel(); extern int del_panel(); extern int hide_panel(); extern int show_panel(); extern int panel_hidden(); extern int move_panel(); extern int replace_panel(); extern int top_panel(); extern int bottom_panel(); extern void update_panels(); extern WINDOW *panel_window(); extern int set_panel_userptr(); extern char *panel_userptr(); extern PANEL *panel_above(); extern PANEL *panel_below(); #endif /* __STDC__ */ #ifdef __cplusplus } #endif #endif /* _PANEL_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _PRIVATE_H #define _PRIVATE_H #ifdef __cplusplus extern "C" { #endif #ifndef PANELS_H #define PANELS_H #include "panel.h" #define _panels_intersect(p1, p2) (!((p1)->wstarty > (p2)->wendy || \ (p1)->wendy < (p2)->wstarty || \ (p1)->wstartx > (p2)->wendx || \ (p1)->wendx < (p2)->wstartx)) extern PANEL *_Bottom_panel; extern PANEL *_Top_panel; extern int _Panel_cnt; extern void _intersect_panel(PANEL *); extern void _remove_overlap(PANEL *); extern int _alloc_overlap(int); extern void _free_overlap(_obscured_list *); extern _obscured_list *_unlink_obs(PANEL *, PANEL *); #endif #ifdef __cplusplus } #endif #endif /* _PRIVATE_H */