Importing lib/libmenu

No Minix-specific changes needed.

Change-Id: Ifab9a44bd401aebf99ab019697937620d88d47de
This commit is contained in:
Thomas Cort 2013-11-12 07:39:59 -05:00
parent 37fc2fa18f
commit b618a1ee0b
36 changed files with 5038 additions and 1 deletions

View file

@ -670,6 +670,7 @@
./usr/include/env.h minix-sys ./usr/include/env.h minix-sys
./usr/include/err.h minix-sys ./usr/include/err.h minix-sys
./usr/include/errno.h minix-sys ./usr/include/errno.h minix-sys
./usr/include/eti.h minix-sys
./usr/include/fcntl.h minix-sys ./usr/include/fcntl.h minix-sys
./usr/include/fenv.h minix-sys ./usr/include/fenv.h minix-sys
./usr/include/fetch.h minix-sys ./usr/include/fetch.h minix-sys
@ -1138,6 +1139,7 @@
./usr/include/md4.h minix-sys ./usr/include/md4.h minix-sys
./usr/include/md5.h minix-sys ./usr/include/md5.h minix-sys
./usr/include/memory.h minix-sys ./usr/include/memory.h minix-sys
./usr/include/menu.h minix-sys
./usr/include/minix minix-sys ./usr/include/minix minix-sys
./usr/include/minix/acpi.h minix-sys ./usr/include/minix/acpi.h minix-sys
./usr/include/minix/audio_fw.h minix-sys ./usr/include/minix/audio_fw.h minix-sys
@ -1686,6 +1688,11 @@
./usr/lib/libmagic.so.0.0 minix-sys ./usr/lib/libmagic.so.0.0 minix-sys
./usr/lib/libmagic.so.0 minix-sys ./usr/lib/libmagic.so.0 minix-sys
./usr/lib/libmagic.so minix-sys ./usr/lib/libmagic.so minix-sys
./usr/lib/libmenu.a minix-sys
./usr/lib/libmenu.so minix-sys
./usr/lib/libmenu.so.6 minix-sys
./usr/lib/libmenu.so.6.0 minix-sys
./usr/lib/libmenu_pic.a minix-sys
./usr/lib/libminc.a minix-sys ./usr/lib/libminc.a minix-sys
./usr/lib/libminc_pic.a minix-sys ./usr/lib/libminc_pic.a minix-sys
./usr/lib/libminixfs.a minix-sys ./usr/lib/libminixfs.a minix-sys
@ -2692,6 +2699,7 @@
./usr/man/man3/ctime_r.3 minix-sys ./usr/man/man3/ctime_r.3 minix-sys
./usr/man/man3/ctime_rz.3 minix-sys ./usr/man/man3/ctime_rz.3 minix-sys
./usr/man/man3/ctype.3 minix-sys ./usr/man/man3/ctype.3 minix-sys
./usr/man/man3/current_item.3 minix-sys
./usr/man/man3/curses.3 minix-sys ./usr/man/man3/curses.3 minix-sys
./usr/man/man3/curses_addch.3 minix-sys ./usr/man/man3/curses_addch.3 minix-sys
./usr/man/man3/curses_addchstr.3 minix-sys ./usr/man/man3/curses_addchstr.3 minix-sys
@ -2980,6 +2988,8 @@
./usr/man/man3/fputws.3 minix-sys ./usr/man/man3/fputws.3 minix-sys
./usr/man/man3/fread.3 minix-sys ./usr/man/man3/fread.3 minix-sys
./usr/man/man3/free.3 minix-sys ./usr/man/man3/free.3 minix-sys
./usr/man/man3/free_item.3 minix-sys
./usr/man/man3/free_menu.3 minix-sys
./usr/man/man3/freeaddrinfo.3 minix-sys ./usr/man/man3/freeaddrinfo.3 minix-sys
./usr/man/man3/freeifaddrs.3 minix-sys ./usr/man/man3/freeifaddrs.3 minix-sys
./usr/man/man3/freopen.3 minix-sys ./usr/man/man3/freopen.3 minix-sys
@ -3295,6 +3305,19 @@
./usr/man/man3/iswupper.3 minix-sys ./usr/man/man3/iswupper.3 minix-sys
./usr/man/man3/iswxdigit.3 minix-sys ./usr/man/man3/iswxdigit.3 minix-sys
./usr/man/man3/isxdigit.3 minix-sys ./usr/man/man3/isxdigit.3 minix-sys
./usr/man/man3/item_count.3 minix-sys
./usr/man/man3/item_description.3 minix-sys
./usr/man/man3/item_index.3 minix-sys
./usr/man/man3/item_init.3 minix-sys
./usr/man/man3/item_name.3 minix-sys
./usr/man/man3/item_opts.3 minix-sys
./usr/man/man3/item_opts_off.3 minix-sys
./usr/man/man3/item_opts_on.3 minix-sys
./usr/man/man3/item_selected.3 minix-sys
./usr/man/man3/item_term.3 minix-sys
./usr/man/man3/item_userptr.3 minix-sys
./usr/man/man3/item_value.3 minix-sys
./usr/man/man3/item_visible.3 minix-sys
./usr/man/man3/j0.3 minix-sys ./usr/man/man3/j0.3 minix-sys
./usr/man/man3/j0f.3 minix-sys ./usr/man/man3/j0f.3 minix-sys
./usr/man/man3/j1.3 minix-sys ./usr/man/man3/j1.3 minix-sys
@ -3429,6 +3452,37 @@
./usr/man/man3/memory.3 minix-sys ./usr/man/man3/memory.3 minix-sys
./usr/man/man3/memrchr.3 minix-sys ./usr/man/man3/memrchr.3 minix-sys
./usr/man/man3/memset.3 minix-sys ./usr/man/man3/memset.3 minix-sys
./usr/man/man3/menu_attributes.3 minix-sys
./usr/man/man3/menu_back.3 minix-sys
./usr/man/man3/menu_cursor.3 minix-sys
./usr/man/man3/menu_driver.3 minix-sys
./usr/man/man3/menu_fore.3 minix-sys
./usr/man/man3/menu_format.3 minix-sys
./usr/man/man3/menu_grey.3 minix-sys
./usr/man/man3/menu_hook.3 minix-sys
./usr/man/man3/menu_init.3 minix-sys
./usr/man/man3/menu_item_current.3 minix-sys
./usr/man/man3/menu_item_name.3 minix-sys
./usr/man/man3/menu_item_new.3 minix-sys
./usr/man/man3/menu_item_opts.3 minix-sys
./usr/man/man3/menu_item_userptr.3 minix-sys
./usr/man/man3/menu_item_value.3 minix-sys
./usr/man/man3/menu_item_visible.3 minix-sys
./usr/man/man3/menu_items.3 minix-sys
./usr/man/man3/menu_mark.3 minix-sys
./usr/man/man3/menu_new.3 minix-sys
./usr/man/man3/menu_opts.3 minix-sys
./usr/man/man3/menu_opts_off.3 minix-sys
./usr/man/man3/menu_opts_on.3 minix-sys
./usr/man/man3/menu_pad.3 minix-sys
./usr/man/man3/menu_pattern.3 minix-sys
./usr/man/man3/menu_post.3 minix-sys
./usr/man/man3/menu_sub.3 minix-sys
./usr/man/man3/menu_term.3 minix-sys
./usr/man/man3/menu_unmark.3 minix-sys
./usr/man/man3/menu_userptr.3 minix-sys
./usr/man/man3/menu_win.3 minix-sys
./usr/man/man3/menus.3 minix-sys
./usr/man/man3/mergesort.3 minix-sys ./usr/man/man3/mergesort.3 minix-sys
./usr/man/man3/meta.3 minix-sys ./usr/man/man3/meta.3 minix-sys
./usr/man/man3/mi_vector_hash.3 minix-sys ./usr/man/man3/mi_vector_hash.3 minix-sys
@ -3489,6 +3543,8 @@
./usr/man/man3/napms.3 minix-sys ./usr/man/man3/napms.3 minix-sys
./usr/man/man3/ndbm.3 minix-sys ./usr/man/man3/ndbm.3 minix-sys
./usr/man/man3/network.3 minix-sys ./usr/man/man3/network.3 minix-sys
./usr/man/man3/new_item.3 minix-sys
./usr/man/man3/new_menu.3 minix-sys
./usr/man/man3/newpad.3 minix-sys ./usr/man/man3/newpad.3 minix-sys
./usr/man/man3/newterm.3 minix-sys ./usr/man/man3/newterm.3 minix-sys
./usr/man/man3/newwin.3 minix-sys ./usr/man/man3/newwin.3 minix-sys
@ -3539,6 +3595,7 @@
./usr/man/man3/popcountl.3 minix-sys ./usr/man/man3/popcountl.3 minix-sys
./usr/man/man3/popcountll.3 minix-sys ./usr/man/man3/popcountll.3 minix-sys
./usr/man/man3/popen.3 minix-sys ./usr/man/man3/popen.3 minix-sys
./usr/man/man3/pos_menu_cursor.3 minix-sys
./usr/man/man3/posix2time.3 minix-sys ./usr/man/man3/posix2time.3 minix-sys
./usr/man/man3/posix2time_z.3 minix-sys ./usr/man/man3/posix2time_z.3 minix-sys
./usr/man/man3/posix_memalign.3 minix-sys ./usr/man/man3/posix_memalign.3 minix-sys
@ -3564,6 +3621,7 @@
./usr/man/man3/posix_spawn_file_actions_destroy.3 minix-sys ./usr/man/man3/posix_spawn_file_actions_destroy.3 minix-sys
./usr/man/man3/posix_spawn_file_actions_init.3 minix-sys ./usr/man/man3/posix_spawn_file_actions_init.3 minix-sys
./usr/man/man3/posix_spawnp.3 minix-sys ./usr/man/man3/posix_spawnp.3 minix-sys
./usr/man/man3/post_menu.3 minix-sys
./usr/man/man3/pow.3 minix-sys ./usr/man/man3/pow.3 minix-sys
./usr/man/man3/powf.3 minix-sys ./usr/man/man3/powf.3 minix-sys
./usr/man/man3/p_query.3 minix-sys ./usr/man/man3/p_query.3 minix-sys
@ -3858,6 +3916,7 @@
./usr/man/man3/scalbf.3 minix-sys ./usr/man/man3/scalbf.3 minix-sys
./usr/man/man3/scalbn.3 minix-sys ./usr/man/man3/scalbn.3 minix-sys
./usr/man/man3/scalbnf.3 minix-sys ./usr/man/man3/scalbnf.3 minix-sys
./usr/man/man3/scale_menu.3 minix-sys
./usr/man/man3/scandir.3 minix-sys ./usr/man/man3/scandir.3 minix-sys
./usr/man/man3/scanf.3 minix-sys ./usr/man/man3/scanf.3 minix-sys
./usr/man/man3/scanw.3 minix-sys ./usr/man/man3/scanw.3 minix-sys
@ -3867,6 +3926,26 @@
./usr/man/man3/secure_path.3 minix-sys ./usr/man/man3/secure_path.3 minix-sys
./usr/man/man3/seed48.3 minix-sys ./usr/man/man3/seed48.3 minix-sys
./usr/man/man3/seekdir.3 minix-sys ./usr/man/man3/seekdir.3 minix-sys
./usr/man/man3/set_current_item.3 minix-sys
./usr/man/man3/set_item_init.3 minix-sys
./usr/man/man3/set_item_term.3 minix-sys
./usr/man/man3/set_item_userptr.3 minix-sys
./usr/man/man3/set_item_value.3 minix-sys
./usr/man/man3/set_menu_back.3 minix-sys
./usr/man/man3/set_menu_fore.3 minix-sys
./usr/man/man3/set_menu_format.3 minix-sys
./usr/man/man3/set_menu_grey.3 minix-sys
./usr/man/man3/set_menu_init.3 minix-sys
./usr/man/man3/set_menu_items.3 minix-sys
./usr/man/man3/set_menu_mark.3 minix-sys
./usr/man/man3/set_menu_opts.3 minix-sys
./usr/man/man3/set_menu_pad.3 minix-sys
./usr/man/man3/set_menu_sub.3 minix-sys
./usr/man/man3/set_menu_term.3 minix-sys
./usr/man/man3/set_menu_unmark.3 minix-sys
./usr/man/man3/set_menu_userptr.3 minix-sys
./usr/man/man3/set_menu_win.3 minix-sys
./usr/man/man3/set_top_row.3 minix-sys
./usr/man/man3/setbuf.3 minix-sys ./usr/man/man3/setbuf.3 minix-sys
./usr/man/man3/setbuffer.3 minix-sys ./usr/man/man3/setbuffer.3 minix-sys
./usr/man/man3/setclasscontext.3 minix-sys ./usr/man/man3/setclasscontext.3 minix-sys
@ -4143,6 +4222,7 @@
./usr/man/man3/tok_reset.3 minix-sys ./usr/man/man3/tok_reset.3 minix-sys
./usr/man/man3/tok_str.3 minix-sys ./usr/man/man3/tok_str.3 minix-sys
./usr/man/man3/tolower.3 minix-sys ./usr/man/man3/tolower.3 minix-sys
./usr/man/man3/top_row.3 minix-sys
./usr/man/man3/touchline.3 minix-sys ./usr/man/man3/touchline.3 minix-sys
./usr/man/man3/touchoverlap.3 minix-sys ./usr/man/man3/touchoverlap.3 minix-sys
./usr/man/man3/touchwin.3 minix-sys ./usr/man/man3/touchwin.3 minix-sys
@ -4180,6 +4260,7 @@
./usr/man/man3/ungetch.3 minix-sys ./usr/man/man3/ungetch.3 minix-sys
./usr/man/man3/ungetwc.3 minix-sys ./usr/man/man3/ungetwc.3 minix-sys
./usr/man/man3/unlockpt.3 minix-sys ./usr/man/man3/unlockpt.3 minix-sys
./usr/man/man3/unpost_menu.3 minix-sys
./usr/man/man3/unsetenv.3 minix-sys ./usr/man/man3/unsetenv.3 minix-sys
./usr/man/man3/untouchwin.3 minix-sys ./usr/man/man3/untouchwin.3 minix-sys
./usr/man/man3/unvis.3 minix-sys ./usr/man/man3/unvis.3 minix-sys

View file

@ -180,7 +180,7 @@ SUBDIR+= ../external/bsd/lutok/lib # depends on lua and libstdc++
.endif # (defined(__MINIX) && ${MKGCCCMDS} == "yes") .endif # (defined(__MINIX) && ${MKGCCCMDS} == "yes")
#SUBDIR+= libform # depends on libcurses #SUBDIR+= libform # depends on libcurses
#SUBDIR+= libmenu # depends on libcurses SUBDIR+= libmenu # depends on libcurses
#SUBDIR+= libradius # depends on libcrypto if (${MKCRYPTO} != "no") #SUBDIR+= libradius # depends on libcrypto if (${MKCRYPTO} != "no")
.if (${MKRUMP} != "no") .if (${MKRUMP} != "no")
SUBDIR+= librump # depends on librumpuser SUBDIR+= librump # depends on librumpuser

77
lib/libmenu/Makefile Normal file
View file

@ -0,0 +1,77 @@
# $NetBSD: Makefile,v 1.9 2012/06/27 22:18:07 jdf Exp $
#
CPPFLAGS+=-I${.CURDIR}
.if defined(DEBUG_MENUS)
CFLAGS+=-g
CPPFLAGS+=-DDEBUG
LDFLAGS+=-g
.endif
LIB= menu
LIBDPLIBS+= curses ${.CURDIR}/../libcurses
SRCS= menu.c item.c userptr.c internals.c driver.c post.c attributes.c
MAN= menu_attributes.3 menu_item_name.3 menu_items.3 menu_userptr.3 \
menu_cursor.3 menu_item_new.3 menu_mark.3 menu_win.3 menu_driver.3 \
menu_item_opts.3 menu_new.3 menus.3 menu_format.3 menu_item_userptr.3 \
menu_opts.3 menu_hook.3 menu_item_value.3 menu_pattern.3 \
menu_item_current.3 menu_item_visible.3 menu_post.3
MLINKS+= menu_attributes.3 menu_back.3 \
menu_attributes.3 menu_fore.3 \
menu_attributes.3 menu_grey.3 \
menu_attributes.3 menu_pad.3 \
menu_attributes.3 set_menu_back.3 \
menu_attributes.3 set_menu_fore.3 \
menu_attributes.3 set_menu_grey.3 \
menu_attributes.3 set_menu_pad.3 \
menu_item_name.3 item_description.3 \
menu_item_name.3 item_name.3 \
menu_items.3 item_count.3 \
menu_items.3 set_menu_items.3 \
menu_userptr.3 set_menu_userptr.3 \
menu_cursor.3 pos_menu_cursor.3 \
menu_item_new.3 free_item.3 \
menu_item_new.3 new_item.3 \
menu_mark.3 menu_unmark.3 \
menu_mark.3 set_menu_mark.3 \
menu_mark.3 set_menu_unmark.3 \
menu_win.3 menu_sub.3 \
menu_win.3 scale_menu.3 \
menu_win.3 set_menu_sub.3 \
menu_win.3 set_menu_win.3 \
menu_item_opts.3 item_opts.3 \
menu_item_opts.3 item_opts_off.3 \
menu_item_opts.3 item_opts_on.3 \
menu_new.3 new_menu.3 \
menu_new.3 free_menu.3 \
menu_format.3 set_menu_format.3 \
menu_item_userptr.3 item_userptr.3 \
menu_item_userptr.3 set_item_userptr.3 \
menu_opts.3 menu_opts_off.3 \
menu_opts.3 menu_opts_on.3 \
menu_opts.3 set_menu_opts.3 \
menu_hook.3 item_init.3 \
menu_hook.3 item_term.3 \
menu_hook.3 menu_init.3 \
menu_hook.3 menu_term.3 \
menu_hook.3 set_item_init.3 \
menu_hook.3 set_item_term.3 \
menu_hook.3 set_menu_init.3 \
menu_hook.3 set_menu_term.3 \
menu_item_value.3 item_value.3 \
menu_item_value.3 set_item_value.3 \
menu_item_value.3 item_selected.3 \
menu_item_current.3 current_item.3 \
menu_item_current.3 item_index.3 \
menu_item_current.3 set_current_item.3 \
menu_item_current.3 set_top_row.3 \
menu_item_current.3 top_row.3 \
menu_item_visible.3 item_visible.3 \
menu_post.3 post_menu.3 \
menu_post.3 unpost_menu.3
INCS= menu.h eti.h
INCSDIR=/usr/include
.include <bsd.lib.mk>
.include <bsd.subdir.mk>

135
lib/libmenu/attributes.c Normal file
View file

@ -0,0 +1,135 @@
/* $NetBSD: attributes.c,v 1.7 2003/03/09 01:08:47 lukem Exp $ */
/*-
* Copyright (c) 1998-1999 Brett Lymn (blymn@baea.com.au, brett_lymn@yahoo.com.au)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: attributes.c,v 1.7 2003/03/09 01:08:47 lukem Exp $");
#include <menu.h>
/* defined in menu.c - the default menu struct */
extern MENU _menui_default_menu;
/*
* Set the menu foreground attribute
*/
int
set_menu_fore(MENU *menu, attr_t attr)
{
if (menu == NULL)
_menui_default_menu.fore = attr;
else
menu->fore = attr;
return E_OK;
}
/*
* Return the menu foreground attribute
*/
char
menu_fore(MENU *menu)
{
if (menu == NULL)
return _menui_default_menu.fore;
else
return menu->fore;
}
/*
* Set the menu background attribute
*/
int
set_menu_back(MENU *menu, attr_t attr)
{
if (menu == NULL)
_menui_default_menu.back = attr;
else
menu->back = attr;
return E_OK;
}
/*
* Return the menu background attribute
*/
char
menu_back(MENU *menu)
{
if (menu == NULL)
return _menui_default_menu.back;
else
return menu->back;
}
/*
* Set the menu greyed out attribute
*/
int
set_menu_grey(MENU *menu, attr_t attr)
{
if (menu == NULL)
_menui_default_menu.grey = attr;
else
menu->grey = attr;
return E_OK;
}
/*
* Return the menu greyed out attribute
*/
char
menu_grey(MENU *menu)
{
if (menu == NULL)
return _menui_default_menu.grey;
else
return menu->grey;
}
/*
* Set the menu pad character - the filler char between name and description
*/
int
set_menu_pad(MENU *menu, int pad)
{
if (menu == NULL)
_menui_default_menu.pad = pad;
else
menu->pad = pad;
return E_OK;
}
/*
* Return the menu pad character
*/
int
menu_pad(MENU *menu)
{
if (menu == NULL)
return _menui_default_menu.pad;
else
return menu->pad;
}

288
lib/libmenu/driver.c Normal file
View file

@ -0,0 +1,288 @@
/* $NetBSD: driver.c,v 1.9 2003/03/09 01:08:48 lukem Exp $ */
/*-
* Copyright (c) 1998-1999 Brett Lymn (blymn@baea.com.au, brett_lymn@yahoo.com.au)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: driver.c,v 1.9 2003/03/09 01:08:48 lukem Exp $");
#include <menu.h>
#include <ctype.h>
#include <stdlib.h>
#include "internals.h"
/*
* The guts of the menu library. This function processes the character
* in c and performs actions based on the value of the character. If the
* character is a normal one then the driver attempts to match the character
* against the items. If the character is a recognised request then the
* request is processed by the driver, if the character is not a recognised
* request and is not printable then it assumed to be a user defined command.
*/
int
menu_driver(MENU *menu, int c)
{
int drv_top_row, drv_scroll, i, it, status = E_OK;
ITEM *drv_new_item;
i = 0;
if (menu == NULL)
return E_BAD_ARGUMENT;
if (menu->posted == 0)
return E_NOT_POSTED;
if (menu->items == NULL)
return E_NOT_CONNECTED;
if (*menu->items == NULL)
return E_NOT_CONNECTED;
if (menu->in_init == 1)
return E_BAD_STATE;
/* this one should never happen but just in case.... */
if (menu->items[menu->cur_item] == NULL)
return E_SYSTEM_ERROR;
drv_new_item = menu->items[menu->cur_item];
it = menu->cur_item;
drv_top_row = menu->top_row;
if ((c > REQ_BASE_NUM) && (c <= MAX_COMMAND)) {
/* is a known driver request - first check if the pattern
* buffer needs to be cleared, we do this on non-search
* type requests.
*/
if (! ((c == REQ_BACK_PATTERN) || (c == REQ_NEXT_MATCH) ||
(c == REQ_PREV_MATCH))) {
if ((c == REQ_CLEAR_PATTERN)
&& (menu->pattern == NULL))
return E_REQUEST_DENIED;
free(menu->pattern);
menu->pattern = NULL;
menu->plen = 0;
menu->match_len = 0;
}
switch (c) {
case REQ_LEFT_ITEM:
drv_new_item = drv_new_item->left;
break;
case REQ_RIGHT_ITEM:
drv_new_item = drv_new_item->right;
break;
case REQ_UP_ITEM:
drv_new_item = drv_new_item->up;
break;
case REQ_DOWN_ITEM:
drv_new_item = drv_new_item->down;
break;
case REQ_SCR_ULINE:
if (drv_top_row == 0)
return E_REQUEST_DENIED;
drv_top_row--;
drv_new_item = drv_new_item->up;
break;
case REQ_SCR_DLINE:
drv_top_row++;
if ((drv_top_row + menu->rows - 1)> menu->item_rows)
return E_REQUEST_DENIED;
drv_new_item = drv_new_item->down;
break;
case REQ_SCR_DPAGE:
drv_scroll = menu->item_rows - menu->rows
- menu->top_row;
if (drv_scroll > menu->rows) {
drv_scroll = menu->rows;
}
if (drv_scroll <= 0) {
return E_REQUEST_DENIED;
} else {
drv_top_row += drv_scroll;
while (drv_scroll-- > 0)
drv_new_item = drv_new_item->down;
}
break;
case REQ_SCR_UPAGE:
if (menu->rows < menu->top_row) {
drv_scroll = menu->rows;
} else {
drv_scroll = menu->top_row;
}
if (drv_scroll == 0)
return E_REQUEST_DENIED;
drv_top_row -= drv_scroll;
while (drv_scroll-- > 0)
drv_new_item = drv_new_item->up;
break;
case REQ_FIRST_ITEM:
drv_new_item = menu->items[0];
break;
case REQ_LAST_ITEM:
drv_new_item = menu->items[menu->item_count - 1];
break;
case REQ_NEXT_ITEM:
if ((menu->cur_item + 1) >= menu->item_count) {
if ((menu->opts & O_NONCYCLIC)
== O_NONCYCLIC) {
return E_REQUEST_DENIED;
} else {
drv_new_item = menu->items[0];
}
} else {
drv_new_item =
menu->items[menu->cur_item + 1];
}
break;
case REQ_PREV_ITEM:
if (menu->cur_item == 0) {
if ((menu->opts & O_NONCYCLIC)
== O_NONCYCLIC) {
return E_REQUEST_DENIED;
} else {
drv_new_item = menu->items[
menu->item_count - 1];
}
} else {
drv_new_item =
menu->items[menu->cur_item - 1];
}
break;
case REQ_TOGGLE_ITEM:
if ((menu->opts & (O_RADIO | O_ONEVALUE)) != 0) {
if ((menu->opts & O_RADIO) == O_RADIO) {
if ((drv_new_item->opts & O_SELECTABLE)
!= O_SELECTABLE)
return E_NOT_SELECTABLE;
/* don't deselect selected item */
if (drv_new_item->selected == 1)
return E_REQUEST_DENIED;
/* deselect all items */
for (i = 0; i < menu->item_count; i++) {
if ((menu->items[i]->selected) &&
(drv_new_item->index != i)) {
menu->items[i]->selected ^= 1;
_menui_draw_item(menu,
menu->items[i]->index);
}
}
/* turn on selected item */
drv_new_item->selected ^= 1;
_menui_draw_item(menu, drv_new_item->index);
} else {
return E_REQUEST_DENIED;
}
} else {
if ((drv_new_item->opts
& O_SELECTABLE) == O_SELECTABLE) {
/* toggle select flag */
drv_new_item->selected ^= 1;
/* update item in menu */
_menui_draw_item(menu,
drv_new_item->index);
} else {
return E_NOT_SELECTABLE;
}
}
break;
case REQ_CLEAR_PATTERN:
/* this action is taken before the
case statement */
break;
case REQ_BACK_PATTERN:
if (menu->pattern == NULL)
return E_REQUEST_DENIED;
if (menu->plen == 0)
return E_REQUEST_DENIED;
menu->pattern[menu->plen--] = '\0';
break;
case REQ_NEXT_MATCH:
if (menu->pattern == NULL)
return E_REQUEST_DENIED;
status = _menui_match_pattern(menu, 0,
MATCH_NEXT_FORWARD,
&it);
drv_new_item = menu->items[it];
break;
case REQ_PREV_MATCH:
if (menu->pattern == NULL)
return E_REQUEST_DENIED;
status = _menui_match_pattern(menu, 0,
MATCH_NEXT_REVERSE,
&it);
drv_new_item = menu->items[it];
break;
}
} else if (c > MAX_COMMAND) {
/* must be a user command */
return E_UNKNOWN_COMMAND;
} else if (isprint((unsigned char) c)) {
/* otherwise search items for the character. */
status = _menui_match_pattern(menu, (unsigned char) c,
MATCH_FORWARD, &it);
drv_new_item = menu->items[it];
/* update the position of the cursor if we are doing
* show match and the current item has not changed. If
* we don't do this here it won't get done since the
* display will not be updated due to the current item
* not changing.
*/
if ((drv_new_item->index == menu->cur_item)
&& ((menu->opts & O_SHOWMATCH) == O_SHOWMATCH)) {
pos_menu_cursor(menu);
}
} else {
/* bad character */
return E_BAD_ARGUMENT;
}
if (drv_new_item == NULL)
return E_REQUEST_DENIED;
if (drv_new_item->row < drv_top_row) drv_top_row = drv_new_item->row;
if (drv_new_item->row >= (drv_top_row + menu->rows))
drv_top_row = drv_new_item->row - menu->rows + 1;
if ((drv_new_item->index != menu->cur_item)
|| (drv_top_row != menu->top_row))
_menui_goto_item(menu, drv_new_item, drv_top_row);
return status;
}

50
lib/libmenu/eti.h Normal file
View file

@ -0,0 +1,50 @@
/* $NetBSD: eti.h,v 1.8 2001/06/13 10:45:59 wiz Exp $ */
/*-
* Copyright (c) 1998-1999 Brett Lymn (blymn@baea.com.au, brett_lymn@yahoo.com.au)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
#ifndef _ETI_H_
#define _ETI_H_
/* common return codes for libmenu and libpanel functions */
#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)
#endif /* !_ETI_H_ */

635
lib/libmenu/internals.c Normal file
View file

@ -0,0 +1,635 @@
/* $NetBSD: internals.c,v 1.15 2012/06/27 11:53:36 blymn Exp $ */
/*-
* Copyright (c) 1998-1999 Brett Lymn (blymn@baea.com.au, brett_lymn@yahoo.com.au)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: internals.c,v 1.15 2012/06/27 11:53:36 blymn Exp $");
#include <menu.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "internals.h"
/* internal function prototypes */
static void
_menui_calc_neighbours(MENU *menu, int item_no);
static void _menui_redraw_menu(MENU *menu, int old_top_row, int old_cur_item);
/*
* Link all the menu items together to speed up navigation. We need
* to calculate the widest item entry, then work out how many columns
* of items the window will accommodate and then how many rows there will
* be. Once the layout is determined the neighbours of each item is
* calculated and the item structures updated.
*/
int
_menui_stitch_items(MENU *menu)
{
int i, row_major;
row_major = ((menu->opts & O_ROWMAJOR) == O_ROWMAJOR);
if (menu->posted == 1)
return E_POSTED;
if (menu->items == NULL)
return E_BAD_ARGUMENT;
menu->item_rows = menu->item_count / menu->cols;
menu->item_cols = menu->cols;
if (menu->item_count > (menu->item_rows * menu->item_cols))
menu->item_rows += 1;
_menui_max_item_size(menu);
for (i = 0; i < menu->item_count; i++) {
/* fill in the row and column value of the item */
if (row_major) {
menu->items[i]->row = i / menu->item_cols;
menu->items[i]->col = i % menu->item_cols;
} else {
menu->items[i]->row = i % menu->item_rows;
menu->items[i]->col = i / menu->item_rows;
}
_menui_calc_neighbours(menu, i);
}
return E_OK;
}
/*
* Calculate the neighbours for an item in menu.
*/
static void
_menui_calc_neighbours(MENU *menu, int item_no)
{
int neighbour, cycle, row_major, edge;
ITEM *item;
row_major = ((menu->opts & O_ROWMAJOR) == O_ROWMAJOR);
cycle = ((menu->opts & O_NONCYCLIC) != O_NONCYCLIC);
item = menu->items[item_no];
if (menu->item_rows < 2) {
if (cycle) {
item->up = item;
item->down = item;
} else {
item->up = NULL;
item->down = NULL;
}
} else {
/* up */
if (menu->item_cols < 2) {
if (item_no == 0) {
if (cycle)
item->up =
menu->items[menu->item_count - 1];
else
item->up = NULL;
} else
item->up = menu->items[item_no - 1];
} else {
edge = 0;
if (row_major) {
if (item->row == 0) {
neighbour =
(menu->item_rows - 1) * menu->item_cols
+ item->col;
if (neighbour >= menu->item_count)
neighbour -= menu->item_cols;
edge = 1;
} else
neighbour = item_no - menu->item_cols;
} else {
if (item->row == 0) {
neighbour = menu->item_rows * item->col
+ menu->item_rows - 1;
if (neighbour >= menu->item_count)
neighbour = menu->item_count - 1;
edge = 1;
} else
neighbour = item_no - 1;
}
item->up = menu->items[neighbour];
if ((!cycle) && (edge == 1))
item->up = NULL;
}
/* Down */
if (menu->item_cols < 2) {
if (item_no == (menu->item_count - 1)) {
if (cycle)
item->down = menu->items[0];
else
item->down = NULL;
} else
item->down = menu->items[item_no + 1];
} else {
edge = 0;
if (row_major) {
if (item->row == menu->item_rows - 1) {
neighbour = item->col;
edge = 1;
} else {
neighbour = item_no + menu->item_cols;
if (neighbour >= menu->item_count) {
neighbour = item->col;
edge = 1;
}
}
} else {
if (item->row == menu->item_rows - 1) {
neighbour = item->col * menu->item_rows;
edge = 1;
} else {
neighbour = item_no + 1;
if (neighbour >= menu->item_count) {
neighbour = item->col
* menu->item_rows;
edge = 1;
}
}
}
item->down = menu->items[neighbour];
if ((!cycle) && (edge == 1))
item->down = NULL;
}
}
if (menu->item_cols < 2) {
if (cycle) {
item->left = item;
item->right = item;
} else {
item->left = NULL;
item->right = NULL;
}
} else {
/* left */
if (menu->item_rows < 2) {
if (item_no == 0) {
if (cycle)
item->left =
menu->items[menu->item_count - 1];
else
item->left = NULL;
} else
item->left = menu->items[item_no - 1];
} else {
edge = 0;
if (row_major) {
if (item->col == 0) {
neighbour = item_no + menu->cols - 1;
if (neighbour >= menu->item_count)
neighbour = menu->item_count - 1;
edge = 1;
} else
neighbour = item_no - 1;
} else {
if (item->col == 0) {
neighbour = menu->item_rows
* (menu->item_cols - 1) + item->row;
if (neighbour >= menu->item_count)
neighbour -= menu->item_rows;
edge = 1;
} else
neighbour = item_no - menu->item_rows;
}
item->left = menu->items[neighbour];
if ((!cycle) && (edge == 1))
item->left = NULL;
}
/* right */
if (menu->item_rows < 2) {
if (item_no == menu->item_count - 1) {
if (cycle)
item->right = menu->items[0];
else
item->right = NULL;
} else
item->right = menu->items[item_no + 1];
} else {
edge = 0;
if (row_major) {
if (item->col == menu->item_cols - 1) {
neighbour = item_no - menu->item_cols
+ 1;
edge = 1;
} else if (item_no == menu->item_count - 1) {
neighbour = item->row * menu->item_cols;
edge = 1;
} else
neighbour = item_no + 1;
} else {
if (item->col == menu->item_cols - 1) {
neighbour = item->row;
edge = 1;
} else {
neighbour = item_no + menu->item_rows;
if (neighbour >= menu->item_count) {
neighbour = item->row;
edge = 1;
}
}
}
item->right = menu->items[neighbour];
if ((!cycle) && (edge == 1))
item->right = NULL;
}
}
}
/*
* Goto the item pointed to by item and adjust the menu structure
* accordingly. Call the term and init functions if required.
*/
int
_menui_goto_item(MENU *menu, ITEM *item, int new_top_row)
{
int old_top_row = menu->top_row, old_cur_item = menu->cur_item;
/* If we get a null then the menu is not cyclic so deny request */
if (item == NULL)
return E_REQUEST_DENIED;
menu->in_init = 1;
if (menu->top_row != new_top_row) {
if ((menu->posted == 1) && (menu->menu_term != NULL))
menu->menu_term(menu);
menu->top_row = new_top_row;
if ((menu->posted == 1) && (menu->menu_init != NULL))
menu->menu_init(menu);
}
/* this looks like wasted effort but it can happen.... */
if (menu->cur_item != item->index) {
if ((menu->posted == 1) && (menu->item_term != NULL))
menu->item_term(menu);
menu->cur_item = item->index;
menu->cur_row = item->row;
menu->cur_col = item->col;
if (menu->posted == 1)
_menui_redraw_menu(menu, old_top_row, old_cur_item);
if ((menu->posted == 1) && (menu->item_init != NULL))
menu->item_init(menu);
}
menu->in_init = 0;
return E_OK;
}
/*
* Attempt to match items with the pattern buffer in the direction given
* by iterating over the menu items. If a match is found return E_OK
* otherwise return E_NO_MATCH
*/
int
_menui_match_items(MENU *menu, int direction, int *item_matched)
{
int i, caseless;
caseless = ((menu->opts & O_IGNORECASE) == O_IGNORECASE);
i = menu->cur_item;
if (direction == MATCH_NEXT_FORWARD) {
if (++i >= menu->item_count) i = 0;
} else if (direction == MATCH_NEXT_REVERSE) {
if (--i < 0) i = menu->item_count - 1;
}
do {
if (menu->items[i]->name.length >= menu->plen) {
/* no chance if pattern is longer */
if (caseless) {
if (strncasecmp(menu->items[i]->name.string,
menu->pattern,
(size_t) menu->plen) == 0) {
*item_matched = i;
menu->match_len = menu->plen;
return E_OK;
}
} else {
if (strncmp(menu->items[i]->name.string,
menu->pattern,
(size_t) menu->plen) == 0) {
*item_matched = i;
menu->match_len = menu->plen;
return E_OK;
}
}
}
if ((direction == MATCH_FORWARD) ||
(direction == MATCH_NEXT_FORWARD)) {
if (++i >= menu->item_count) i = 0;
} else {
if (--i <= 0) i = menu->item_count - 1;
}
} while (i != menu->cur_item);
menu->match_len = 0; /* match did not succeed - kill the match len. */
return E_NO_MATCH;
}
/*
* Attempt to match the pattern buffer against the items. If c is a
* printable character then add it to the pattern buffer prior to
* performing the match. Direction determines the direction of matching.
* If the match is successful update the item_matched variable with the
* index of the item that matched the pattern.
*/
int
_menui_match_pattern(MENU *menu, int c, int direction, int *item_matched)
{
if (menu == NULL)
return E_BAD_ARGUMENT;
if (menu->items == NULL)
return E_BAD_ARGUMENT;
if (*menu->items == NULL)
return E_BAD_ARGUMENT;
if (isprint(c)) {
/* add char to buffer - first allocate room for it */
if ((menu->pattern = (char *)
realloc(menu->pattern,
menu->plen + sizeof(char) +
((menu->plen > 0)? 0 : 1)))
== NULL)
return E_SYSTEM_ERROR;
menu->pattern[menu->plen] = c;
menu->pattern[++menu->plen] = '\0';
/* there is no chance of a match if pattern is longer
than all the items */
if (menu->plen >= menu->max_item_width) {
menu->pattern[--menu->plen] = '\0';
return E_NO_MATCH;
}
if (_menui_match_items(menu, direction,
item_matched) == E_NO_MATCH) {
menu->pattern[--menu->plen] = '\0';
return E_NO_MATCH;
} else
return E_OK;
} else {
if (_menui_match_items(menu, direction,
item_matched) == E_OK) {
return E_OK;
} else {
return E_NO_MATCH;
}
}
}
/*
* Draw an item in the subwindow complete with appropriate highlighting.
*/
void
_menui_draw_item(MENU *menu, int item)
{
int j, pad_len, mark_len;
mark_len = max(menu->mark.length, menu->unmark.length);
wmove(menu->scrwin,
menu->items[item]->row - menu->top_row,
menu->items[item]->col * (menu->col_width + 1));
if (menu->cur_item == item)
wattrset(menu->scrwin, menu->fore);
if ((menu->items[item]->opts & O_SELECTABLE) != O_SELECTABLE)
wattron(menu->scrwin, menu->grey);
/* deal with the menu mark, if one is set.
* We mark the selected items and write blanks for
* all others unless the menu unmark string is set in which
* case the unmark string is written.
*/
if (menu->items[item]->selected == 1) {
if (menu->mark.string != NULL) {
for (j = 0; j < menu->mark.length; j++) {
waddch(menu->scrwin,
menu->mark.string[j]);
}
}
/* blank any length difference between mark & unmark */
for (j = menu->mark.length; j < mark_len; j++)
waddch(menu->scrwin, ' ');
} else {
if (menu->unmark.string != NULL) {
for (j = 0; j < menu->unmark.length; j++) {
waddch(menu->scrwin,
menu->unmark.string[j]);
}
}
/* blank any length difference between mark & unmark */
for (j = menu->unmark.length; j < mark_len; j++)
waddch(menu->scrwin, ' ');
}
/* add the menu name */
for (j=0; j < menu->items[item]->name.length; j++)
waddch(menu->scrwin,
menu->items[item]->name.string[j]);
pad_len = menu->col_width - menu->items[item]->name.length
- mark_len - 1;
if ((menu->opts & O_SHOWDESC) == O_SHOWDESC) {
pad_len -= menu->items[item]->description.length - 1;
for (j = 0; j < pad_len; j++)
waddch(menu->scrwin, menu->pad);
for (j = 0; j < menu->items[item]->description.length; j++) {
waddch(menu->scrwin,
menu->items[item]->description.string[j]);
}
} else {
for (j = 0; j < pad_len; j++)
waddch(menu->scrwin, ' ');
}
menu->items[item]->visible = 1;
/* kill any special attributes... */
wattrset(menu->scrwin, menu->back);
/*
* Fill in the spacing between items, annoying but it looks
* odd if the menu items are inverse because the spacings do not
* have the same attributes as the items.
*/
if ((menu->items[item]->col > 0) &&
(menu->items[item]->col < (menu->item_cols - 1))) {
wmove(menu->scrwin,
menu->items[item]->row - menu->top_row,
menu->items[item]->col * (menu->col_width + 1) - 1);
waddch(menu->scrwin, ' ');
}
/* and position the cursor nicely */
pos_menu_cursor(menu);
}
/*
* Draw the menu in the subwindow provided.
*/
int
_menui_draw_menu(MENU *menu)
{
int rowmajor, i, j, k, row = -1, col = -1, stride;
int incr, cur_row, offset, row_count;
rowmajor = ((menu->opts & O_ROWMAJOR) == O_ROWMAJOR);
if (rowmajor) {
stride = 1;
incr = menu->item_cols;
} else {
stride = menu->item_rows;
incr = 1;
}
row_count = 0;
for (i = 0; i < menu->item_count; i += incr) {
if (menu->items[i]->row == menu->top_row)
break;
row_count++;
for (j = 0; j < menu->item_cols; j++) {
offset = j * stride + i;
if (offset >= menu->item_count)
break; /* done */
menu->items[offset]->visible = 0;
}
}
wmove(menu->scrwin, 0, 0);
menu->col_width = getmaxx(menu->scrwin) / menu->cols;
for (cur_row = 0; cur_row < menu->rows; cur_row++) {
for (j = 0; j < menu->cols; j++) {
offset = j * stride + i;
if (offset >= menu->item_count) {
/* no more items to draw, write background blanks */
wattrset(menu->scrwin, menu->back);
if (row < 0) {
row = menu->items[menu->item_count - 1]->row;
col = menu->items[menu->item_count - 1]->col;
}
wmove(menu->scrwin, cur_row,
j * (menu->col_width + 1));
for (k = 0; k < menu->col_width; k++)
waddch(menu->scrwin, ' ');
} else {
_menui_draw_item(menu, offset);
}
}
i += incr;
row_count++;
}
if (row_count < menu->item_rows) {
for (cur_row = row_count; cur_row < menu->item_rows; cur_row++) {
for (j = 0; j < menu->item_cols; j++) {
offset = j * stride + i;
if (offset >= menu->item_count)
break; /* done */
menu->items[offset]->visible = 0;
}
i += incr;
}
}
return E_OK;
}
/*
* Calculate the widest menu item and stash it in the menu struct.
*
*/
void
_menui_max_item_size(MENU *menu)
{
int i, with_desc, width;
with_desc = ((menu->opts & O_SHOWDESC) == O_SHOWDESC);
for (i = 0; i < menu->item_count; i++) {
width = menu->items[i]->name.length
+ max(menu->mark.length, menu->unmark.length);
if (with_desc)
width += menu->items[i]->description.length + 1;
menu->max_item_width = max(menu->max_item_width, width);
}
}
/*
* Redraw the menu on the screen. If the current item has changed then
* unhighlight the old item and highlight the new one.
*/
static void
_menui_redraw_menu(MENU *menu, int old_top_row, int old_cur_item)
{
if (menu->top_row != old_top_row) {
/* top row changed - redo the whole menu
* XXXX this could be improved if we had wscrl implemented.
* XXXX we could scroll the window and just fill in the
* XXXX changed lines.
*/
wclear(menu->scrwin);
_menui_draw_menu(menu);
} else {
if (menu->cur_item != old_cur_item) {
/* redo the old item as a normal one. */
_menui_draw_item(menu, old_cur_item);
}
/* and then redraw the current item */
_menui_draw_item(menu, menu->cur_item);
}
}

53
lib/libmenu/internals.h Normal file
View file

@ -0,0 +1,53 @@
/* $NetBSD: internals.h,v 1.8 2001/06/13 10:45:59 wiz Exp $ */
/*-
* Copyright (c) 1998-1999 Brett Lymn (blymn@baea.com.au, brett_lymn@yahoo.com.au)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
#include <menu.h>
#ifndef INTERNALS_H
#define INTERNALS_H
#define MATCH_FORWARD 1
#define MATCH_REVERSE 2
#define MATCH_NEXT_FORWARD 3
#define MATCH_NEXT_REVERSE 4
/* stole this from curses.h */
#define max(a,b) ((a) > (b) ? a : b)
/* function prototypes */
void _menui_draw_item(MENU *menu, int item);
int _menui_draw_menu(MENU *menu);
int _menui_goto_item(MENU *menu, ITEM *item, int new_top_row);
int _menui_match_pattern(MENU *menu, int c, int direction ,
int *item_matched);
int _menui_match_items(MENU *menu, int direction, int *item_matched);
void _menui_max_item_size(MENU *menu);
int _menui_stitch_items(MENU *menu);
#endif

404
lib/libmenu/item.c Normal file
View file

@ -0,0 +1,404 @@
/* $NetBSD: item.c,v 1.12 2012/03/21 05:33:27 matt Exp $ */
/*-
* Copyright (c) 1998-1999 Brett Lymn (blymn@baea.com.au, brett_lymn@yahoo.com.au)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: item.c,v 1.12 2012/03/21 05:33:27 matt Exp $");
#include <menu.h>
#include <stdlib.h>
#include <string.h>
#include "internals.h"
/* the following is defined in menu.c - it is the default menu struct */
extern MENU _menui_default_menu;
/* keep default item options for setting in new_item */
ITEM _menui_default_item = {
{NULL, 0}, /* item name struct */
{NULL, 0}, /* item description struct */
NULL, /* user pointer */
0, /* is item visible? */
0, /* is item selected? */
0, /* row item is on */
0, /* column item is on */
O_SELECTABLE, /* item options */
NULL, /* parent menu item is bound to */
-1, /* index number if item attached to a menu */
NULL, /* left neighbour */
NULL, /* right neighbour */
NULL, /* up neighbour */
NULL /* down neighbour */
};
/*
* Return the item visibility flag
*/
int
item_visible(ITEM *item)
{
if (item == NULL)
return E_BAD_ARGUMENT;
if (item->parent == NULL)
return E_NOT_CONNECTED;
return item->visible;
}
/*
* Return the pointer to the item name
*/
char *
item_name(ITEM *item)
{
if (item == NULL)
return NULL;
return item->name.string;
}
/*
* Return the pointer to the item description
*/
char *
item_description(ITEM *item)
{
if (item == NULL)
return NULL;
return item->description.string;
}
/*
* Set the application defined function called when the menu is posted or
* just after the current item changes.
*/
int
set_item_init(MENU *menu, Menu_Hook func)
{
if (menu == NULL)
_menui_default_menu.item_init = func;
else
menu->item_init = func;
return E_OK;
}
/*
* Return a pointer to the item initialisation routine.
*/
Menu_Hook
item_init(MENU *menu)
{
if (menu == NULL)
return _menui_default_menu.item_init;
else
return menu->item_init;
}
/*
* Set the user defined function to be called when menu is unposted or just
* before the current item changes.
*/
int
set_item_term(MENU *menu, Menu_Hook func)
{
if (menu == NULL)
_menui_default_menu.item_term = func;
else
menu->item_term = func;
return E_OK;
}
/*
* Return a pointer to the termination function
*/
Menu_Hook
item_term(MENU *menu)
{
if (menu == NULL)
return _menui_default_menu.item_term;
else
return menu->item_term;
}
/*
* Returns the number of items that are selected.
* The index numbers of the items are placed in the dynamically allocated
* int array *sel.
*/
int
item_selected(MENU *menu, int **sel)
{
int i, j;
if (menu == NULL)
return E_BAD_ARGUMENT;
/* count selected */
for (i = 0, j = 0; i < menu->item_count; i++)
if (menu->items[i]->selected)
j++;
if (j == 0) {
*sel = NULL;
return 0;
}
if ( (*sel = malloc(sizeof(int) * j)) == NULL)
return E_SYSTEM_ERROR;
for (i = 0, j = 0; i < menu->item_count; i++)
if (menu->items[i]->selected)
(*sel)[j++] = i;
return j;
}
/*
* Set the item options. We keep a global copy of the current item options
* as subsequent new_item calls will use the updated options as their
* defaults.
*/
int
set_item_opts(ITEM *item, OPTIONS opts)
{
/* selectable seems to be the only allowable item opt! */
if (opts != O_SELECTABLE)
return E_SYSTEM_ERROR;
if (item == NULL)
_menui_default_item.opts = opts;
else
item->opts = opts;
return E_OK;
}
/*
* Set item options on.
*/
int
item_opts_on(ITEM *item, OPTIONS opts)
{
if (opts != O_SELECTABLE)
return E_SYSTEM_ERROR;
if (item == NULL)
_menui_default_item.opts |= opts;
else
item->opts |= opts;
return E_OK;
}
/*
* Turn off the named options.
*/
int
item_opts_off(ITEM *item, OPTIONS opts)
{
if (opts != O_SELECTABLE)
return E_SYSTEM_ERROR;
if (item == NULL)
_menui_default_item.opts &= ~(opts);
else
item->opts &= ~(opts);
return E_OK;
}
/*
* Return the current options set in item.
*/
OPTIONS
item_opts(ITEM *item)
{
if (item == NULL)
return _menui_default_item.opts;
else
return item->opts;
}
/*
* Set the selected flag of the item iff the menu options allow it.
*/
int
set_item_value(ITEM *param_item, int flag)
{
ITEM *item = (param_item != NULL) ? param_item : &_menui_default_item;
/* not bound to a menu */
if (item->parent == NULL)
return E_NOT_CONNECTED;
/* menu options do not allow multi-selection */
if ((item->parent->opts & O_ONEVALUE) == O_ONEVALUE)
return E_REQUEST_DENIED;
item->selected = flag;
_menui_draw_item(item->parent, item->index);
return E_OK;
}
/*
* Return the item value of the item.
*/
int
item_value(ITEM *item)
{
if (item == NULL)
return _menui_default_item.selected;
else
return item->selected;
}
/*
* Allocate a new item and return the pointer to the newly allocated
* structure.
*/
ITEM *
new_item(char *name, char *description)
{
ITEM *new_one;
if (name == NULL)
return NULL;
/* allocate a new item structure for ourselves */
if ((new_one = (ITEM *)malloc(sizeof(ITEM))) == NULL)
return NULL;
/* copy in the defaults for the item */
(void)memcpy(new_one, &_menui_default_item, sizeof(ITEM));
/* fill in the name structure - first the length and then
allocate room for the string & copy that. */
new_one->name.length = strlen(name);
if ((new_one->name.string = (char *)
malloc(sizeof(char) * new_one->name.length + 1)) == NULL) {
/* uh oh malloc failed - clean up & exit */
free(new_one);
return NULL;
}
strcpy(new_one->name.string, name);
if (description == NULL)
new_one->description.length = 0;
else {
/* fill in the description structure, stash the length then
allocate room for description string and copy it in */
new_one->description.length = strlen(description);
if ((new_one->description.string =
(char *) malloc(sizeof(char) *
new_one->description.length + 1)) == NULL) {
/*
* malloc has failed
* - free up allocated memory and return
*/
free(new_one->name.string);
free(new_one);
return NULL;
}
strcpy(new_one->description.string, description);
}
return new_one;
}
/*
* Free the allocated storage associated with item.
*/
int
free_item(ITEM *item)
{
if (item == NULL)
return E_BAD_ARGUMENT;
/* check for connection to menu */
if (item->parent != NULL)
return E_CONNECTED;
/* no connections, so free storage starting with the strings */
free(item->name.string);
if (item->description.length)
free(item->description.string);
free(item);
return E_OK;
}
/*
* Set the menu's current item to the one given.
*/
int
set_current_item(MENU *param_menu, ITEM *item)
{
MENU *menu = (param_menu != NULL) ? param_menu : &_menui_default_menu;
int i = 0;
/* check if we have been called from an init type function */
if (menu->in_init == 1)
return E_BAD_STATE;
/* check we have items in the menu */
if (menu->items == NULL)
return E_NOT_CONNECTED;
if ((i = item_index(item)) < 0)
/* item must not be a part of this menu */
return E_BAD_ARGUMENT;
menu->cur_item = i;
return E_OK;
}
/*
* Return a pointer to the current item for the menu
*/
ITEM *
current_item(MENU *menu)
{
if (menu == NULL)
return NULL;
if (menu->items == NULL)
return NULL;
return menu->items[menu->cur_item];
}
/*
* Return the index into the item array that matches item.
*/
int
item_index(ITEM *item)
{
if (item == NULL)
return _menui_default_item.index;
else
return item->index;
}

743
lib/libmenu/menu.c Normal file
View file

@ -0,0 +1,743 @@
/* $NetBSD: menu.c,v 1.17 2012/03/21 05:33:27 matt Exp $ */
/*-
* Copyright (c) 1998-1999 Brett Lymn (blymn@baea.com.au, brett_lymn@yahoo.com.au)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: menu.c,v 1.17 2012/03/21 05:33:27 matt Exp $");
#include <ctype.h>
#include <menu.h>
#include <string.h>
#include <stdlib.h>
#include "internals.h"
MENU _menui_default_menu = {
16, /* number of item rows that will fit in window */
1, /* number of columns of items that will fit in window */
0, /* number of rows of items we have */
0, /* number of columns of items we have */
0, /* current cursor row */
0, /* current cursor column */
{NULL, 0}, /* mark string */
{NULL, 0}, /* unmark string */
O_ONEVALUE, /* menu options */
NULL, /* the pattern buffer */
0, /* length of pattern buffer */
0, /* the length of matched buffer */
0, /* is the menu posted? */
A_REVERSE, /* menu foreground */
A_NORMAL, /* menu background */
A_UNDERLINE, /* unselectable menu item */
' ', /* filler between name and description */
NULL, /* user defined pointer */
0, /* top row of menu */
0, /* widest item in the menu */
0, /* the width of a menu column */
0, /* number of items attached to the menu */
NULL, /* items in the menu */
0, /* current menu item */
0, /* currently in a hook function */
NULL, /* function called when menu posted */
NULL, /* function called when menu is unposted */
NULL, /* function called when current item changes */
NULL, /* function called when current item changes */
NULL, /* the menu window */
NULL, /* the menu subwindow */
NULL, /* the window to write to */
};
/*
* Set the menu mark character
*/
int
set_menu_mark(MENU *m, char *mark)
{
MENU *menu = m;
if (m == NULL) menu = &_menui_default_menu;
/* if there was an old mark string, free it first */
if (menu->mark.string != NULL) free(menu->mark.string);
if ((menu->mark.string = (char *) malloc(strlen(mark) + 1)) == NULL)
return E_SYSTEM_ERROR;
strcpy(menu->mark.string, mark);
menu->mark.length = strlen(mark);
/* max item size may have changed - recalculate. */
_menui_max_item_size(menu);
return E_OK;
}
/*
* Return the menu mark string for the menu.
*/
char *
menu_mark(MENU *menu)
{
if (menu == NULL)
return _menui_default_menu.mark.string;
else
return menu->mark.string;
}
/*
* Set the menu unmark character
*/
int
set_menu_unmark(MENU *m, char *mark)
{
MENU *menu = m;
if (m == NULL) menu = &_menui_default_menu;
/* if there was an old mark string, free it first */
if (menu->unmark.string != NULL) free(menu->unmark.string);
if ((menu->unmark.string = (char *) malloc(strlen(mark) + 1)) == NULL)
return E_SYSTEM_ERROR;
strcpy(menu->unmark.string, mark);
menu->unmark.length = strlen(mark);
/* max item size may have changed - recalculate. */
_menui_max_item_size(menu);
return E_OK;
}
/*
* Return the menu unmark string for the menu.
*/
char *
menu_unmark(MENU *menu)
{
if (menu == NULL)
return _menui_default_menu.unmark.string;
else
return menu->unmark.string;
}
/*
* Set the menu window to the window passed.
*/
int
set_menu_win(MENU *menu, WINDOW *win)
{
if (menu == NULL) {
_menui_default_menu.menu_win = win;
_menui_default_menu.scrwin = win;
} else {
if (menu->posted == TRUE) {
return E_POSTED;
} else {
menu->menu_win = win;
menu->scrwin = win;
}
}
return E_OK;
}
/*
* Return the pointer to the menu window
*/
WINDOW *
menu_win(MENU *menu)
{
if (menu == NULL)
return _menui_default_menu.menu_win;
else
return menu->menu_win;
}
/*
* Set the menu subwindow for the menu.
*/
int
set_menu_sub(MENU *menu, WINDOW *sub)
{
if (menu == NULL) {
_menui_default_menu.menu_subwin = sub;
_menui_default_menu.scrwin = sub;
} else {
if (menu->posted == TRUE)
return E_POSTED;
menu->menu_subwin = sub;
menu->scrwin = sub;
}
return E_OK;
}
/*
* Return the subwindow pointer for the menu
*/
WINDOW *
menu_sub(MENU *menu)
{
if (menu == NULL)
return _menui_default_menu.menu_subwin;
else
return menu->menu_subwin;
}
/*
* Set the maximum number of rows and columns of items that may be displayed.
*/
int
set_menu_format(MENU *param_menu, int rows, int cols)
{
MENU *menu = (param_menu != NULL) ? param_menu : &_menui_default_menu;
menu->rows = rows;
menu->cols = cols;
if (menu->items != NULL)
/* recalculate the item neighbours */
return _menui_stitch_items(menu);
return E_OK;
}
/*
* Return the max number of rows and cols that may be displayed.
*/
void
menu_format(MENU *param_menu, int *rows, int *cols)
{
MENU *menu = (param_menu != NULL) ? param_menu : &_menui_default_menu;
*rows = menu->rows;
*cols = menu->cols;
}
/*
* Set the user defined function to call when a menu is posted.
*/
int
set_menu_init(MENU *menu, Menu_Hook func)
{
if (menu == NULL)
_menui_default_menu.menu_init = func;
else
menu->menu_init = func;
return E_OK;
}
/*
* Return the pointer to the menu init function.
*/
Menu_Hook
menu_init(MENU *menu)
{
if (menu == NULL)
return _menui_default_menu.menu_init;
else
return menu->menu_init;
}
/*
* Set the user defined function called when a menu is unposted.
*/
int
set_menu_term(MENU *menu, Menu_Hook func)
{
if (menu == NULL)
_menui_default_menu.menu_term = func;
else
menu->menu_term = func;
return E_OK;
}
/*
* Return the user defined menu termination function pointer.
*/
Menu_Hook
menu_term(MENU *menu)
{
if (menu == NULL)
return _menui_default_menu.menu_term;
else
return menu->menu_term;
}
/*
* Return the current menu options set.
*/
OPTIONS
menu_opts(MENU *menu)
{
if (menu == NULL)
return _menui_default_menu.opts;
else
return menu->opts;
}
/*
* Set the menu options to the given options.
*/
int
set_menu_opts(MENU *param_menu, OPTIONS opts)
{
int i, seen;
MENU *menu = (param_menu != NULL) ? param_menu : &_menui_default_menu;
OPTIONS old_opts = menu->opts;
menu->opts = opts;
/*
* If the radio option is selected then make sure only one
* item is actually selected in the items.
*/
if (((opts & O_RADIO) == O_RADIO) && (menu->items != NULL) &&
(menu->items[0] != NULL)) {
seen = 0;
for (i = 0; i < menu->item_count; i++) {
if (menu->items[i]->selected == 1) {
if (seen == 0) {
seen = 1;
} else {
menu->items[i]->selected = 0;
}
}
}
/* if none selected, select the first item */
if (seen == 0)
menu->items[0]->selected = 1;
}
if ((menu->opts & O_ROWMAJOR) != (old_opts & O_ROWMAJOR))
/* changed menu layout - need to recalc neighbours */
_menui_stitch_items(menu);
return E_OK;
}
/*
* Turn on the options in menu given by opts.
*/
int
menu_opts_on(MENU *param_menu, OPTIONS opts)
{
int i, seen;
MENU *menu = (param_menu != NULL) ? param_menu : &_menui_default_menu;
OPTIONS old_opts = menu->opts;
menu->opts |= opts;
/*
* If the radio option is selected then make sure only one
* item is actually selected in the items.
*/
if (((opts & O_RADIO) == O_RADIO) && (menu->items != NULL) &&
(menu->items[0] != NULL)) {
seen = 0;
for (i = 0; i < menu->item_count; i++) {
if (menu->items[i]->selected == 1) {
if (seen == 0) {
seen = 1;
} else {
menu->items[i]->selected = 0;
}
}
}
/* if none selected then select the top item */
if (seen == 0)
menu->items[0]->selected = 1;
}
if ((menu->items != NULL) &&
(menu->opts & O_ROWMAJOR) != (old_opts & O_ROWMAJOR))
/* changed menu layout - need to recalc neighbours */
_menui_stitch_items(menu);
return E_OK;
}
/*
* Turn off the menu options given in opts.
*/
int
menu_opts_off(MENU *param_menu, OPTIONS opts)
{
MENU *menu = (param_menu != NULL) ? param_menu : &_menui_default_menu;
OPTIONS old_opts = menu->opts;
menu->opts &= ~(opts);
if ((menu->items != NULL ) &&
(menu->opts & O_ROWMAJOR) != (old_opts & O_ROWMAJOR))
/* changed menu layout - need to recalc neighbours */
_menui_stitch_items(menu);
return E_OK;
}
/*
* Return the menu pattern buffer.
*/
char *
menu_pattern(MENU *menu)
{
if (menu == NULL)
return _menui_default_menu.pattern;
else
return menu->pattern;
}
/*
* Set the menu pattern buffer to pat and attempt to match the pattern in
* the item list.
*/
int
set_menu_pattern(MENU *param_menu, char *pat)
{
MENU *menu = (param_menu != NULL) ? param_menu : &_menui_default_menu;
char *p = pat;
/* check pattern is all printable characters */
while (*p)
if (!isprint((unsigned char) *p++)) return E_BAD_ARGUMENT;
if ((menu->pattern = (char *) realloc(menu->pattern,
sizeof(char) * strlen(pat) + 1)) == NULL)
return E_SYSTEM_ERROR;
strcpy(menu->pattern, pat);
menu->plen = strlen(pat);
/* search item list for pat here */
return _menui_match_items(menu, MATCH_FORWARD, &menu->cur_item);
}
/*
* Allocate a new menu structure and fill it in.
*/
MENU *
new_menu(ITEM **items)
{
MENU *the_menu;
if ((the_menu = (MENU *)malloc(sizeof(MENU))) == NULL)
return NULL;
/* copy the defaults */
(void)memcpy(the_menu, &_menui_default_menu, sizeof(MENU));
/* set a default window if none already set. */
if (the_menu->menu_win == NULL)
the_menu->scrwin = stdscr;
/* make a private copy of the mark string */
if (_menui_default_menu.mark.string != NULL) {
if ((the_menu->mark.string =
(char *) malloc((unsigned) _menui_default_menu.mark.length + 1))
== NULL) {
free(the_menu);
return NULL;
}
strlcpy(the_menu->mark.string, _menui_default_menu.mark.string,
(unsigned) _menui_default_menu.mark.length + 1);
}
/* make a private copy of the unmark string too */
if (_menui_default_menu.unmark.string != NULL) {
if ((the_menu->unmark.string =
(char *) malloc((unsigned) _menui_default_menu.unmark.length + 1))
== NULL) {
free(the_menu);
return NULL;
}
strlcpy(the_menu->unmark.string,
_menui_default_menu.unmark.string,
(unsigned) _menui_default_menu.unmark.length+ 1 );
}
/* now attach the items, if any */
if (items != NULL) {
if(set_menu_items(the_menu, items) < 0) {
if (the_menu->mark.string != NULL)
free(the_menu->mark.string);
if (the_menu->unmark.string != NULL)
free(the_menu->unmark.string);
free(the_menu);
return NULL;
}
}
return the_menu;
}
/*
* Free up storage allocated to the menu object and destroy it.
*/
int
free_menu(MENU *menu)
{
int i;
if (menu == NULL)
return E_BAD_ARGUMENT;
if (menu->posted != 0)
return E_POSTED;
if (menu->pattern != NULL)
free(menu->pattern);
if (menu->mark.string != NULL)
free(menu->mark.string);
if (menu->items != NULL) {
/* disconnect the items from this menu */
for (i = 0; i < menu->item_count; i++) {
menu->items[i]->parent = NULL;
}
}
free(menu);
return E_OK;
}
/*
* Calculate the minimum window size for the menu.
*/
int
scale_menu(MENU *param_menu, int *rows, int *cols)
{
MENU *menu = (param_menu != NULL) ? param_menu : &_menui_default_menu;
if (menu->items == NULL)
return E_BAD_ARGUMENT;
/* calculate the max item size */
_menui_max_item_size(menu);
*rows = menu->rows;
*cols = menu->cols * menu->max_item_width;
/*
* allow for spacing between columns...
*/
*cols += (menu->cols - 1);
return E_OK;
}
/*
* Set the menu item list to the one given.
*/
int
set_menu_items(MENU *param_menu, ITEM **items)
{
MENU *menu = (param_menu != NULL) ? param_menu : &_menui_default_menu;
int i, new_count = 0, sel_count = 0;
/* don't change if menu is posted */
if (menu->posted == 1)
return E_POSTED;
/* count the new items and validate none are connected already */
while (items[new_count] != NULL) {
if ((items[new_count]->parent != NULL) &&
(items[new_count]->parent != menu))
return E_CONNECTED;
if (items[new_count]->selected == 1)
sel_count++;
new_count++;
}
/*
* don't allow multiple selected items if menu is radio
* button style.
*/
if (((menu->opts & O_RADIO) == O_RADIO) &&
(sel_count > 1))
return E_BAD_ARGUMENT;
/* if there were items connected then disconnect them. */
if (menu->items != NULL) {
for (i = 0; i < menu->item_count; i++) {
menu->items[i]->parent = NULL;
menu->items[i]->index = -1;
}
}
menu->item_count = new_count;
/* connect the new items to the menu */
for (i = 0; i < new_count; i++) {
items[i]->parent = menu;
items[i]->index = i;
}
menu->items = items;
menu->cur_item = 0; /* reset current item just in case */
menu->top_row = 0; /* and the top row too */
if (menu->pattern != NULL) { /* and the pattern buffer....sigh */
free(menu->pattern);
menu->plen = 0;
menu->match_len = 0;
}
/*
* make sure at least one item is selected on a radio
* button style menu.
*/
if (((menu->opts & O_RADIO) == O_RADIO) && (sel_count == 0))
menu->items[0]->selected = 1;
_menui_stitch_items(menu); /* recalculate the item neighbours */
return E_OK;
}
/*
* Return the pointer to the menu items array.
*/
ITEM **
menu_items(MENU *menu)
{
if (menu == NULL)
return _menui_default_menu.items;
else
return menu->items;
}
/*
* Return the count of items connected to the menu
*/
int
item_count(MENU *menu)
{
if (menu == NULL)
return _menui_default_menu.item_count;
else
return menu->item_count;
}
/*
* Set the menu top row to be the given row. The current item becomes the
* leftmost item on that row in the menu.
*/
int
set_top_row(MENU *param_menu, int row)
{
MENU *menu = (param_menu != NULL) ? param_menu : &_menui_default_menu;
int i, cur_item, state = E_SYSTEM_ERROR;
if (row > menu->item_rows)
return E_BAD_ARGUMENT;
if (menu->items == NULL)
return E_NOT_CONNECTED;
if (menu->in_init == 1)
return E_BAD_STATE;
cur_item = 0;
for (i = 0; i < menu->item_count; i++) {
/* search for first item that matches row - this will be
the current item. */
if (row == menu->items[i]->row) {
cur_item = i;
state = E_OK;
break; /* found what we want - no need to go further */
}
}
menu->in_init = 1; /* just in case we call the init/term routines */
if (menu->posted == 1) {
if (menu->menu_term != NULL)
menu->menu_term(menu);
if (menu->item_term != NULL)
menu->item_term(menu);
}
menu->cur_item = cur_item;
menu->top_row = row;
if (menu->posted == 1) {
if (menu->menu_init != NULL)
menu->menu_init(menu);
if (menu->item_init != NULL)
menu->item_init(menu);
}
menu->in_init = 0;
/* this should always be E_OK unless we are really screwed up */
return state;
}
/*
* Return the current top row number.
*/
int
top_row(MENU *param_menu)
{
MENU *menu = (param_menu != NULL) ? param_menu : &_menui_default_menu;
if (menu->items == NULL)
return E_NOT_CONNECTED;
return menu->top_row;
}
/*
* Position the cursor at the correct place in the menu.
*
*/
int
pos_menu_cursor(MENU *menu)
{
int movx, maxmark;
if (menu == NULL)
return E_BAD_ARGUMENT;
maxmark = max(menu->mark.length, menu->unmark.length);
movx = maxmark + (menu->items[menu->cur_item]->col
* (menu->col_width + 1));
if (menu->match_len > 0)
movx += menu->match_len - 1;
wmove(menu->scrwin,
menu->items[menu->cur_item]->row - menu->top_row, movx);
return E_OK;
}

210
lib/libmenu/menu.h Normal file
View file

@ -0,0 +1,210 @@
/* $NetBSD: menu.h,v 1.13 2004/03/22 19:01:09 jdc Exp $ */
/*-
* Copyright (c) 1998-1999 Brett Lymn (blymn@baea.com.au, brett_lymn@yahoo.com.au)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
#ifndef _MENU_H_
#define _MENU_H_
#include <curses.h>
#include <eti.h>
/* requests for the menu_driver call */
#define REQ_BASE_NUM (KEY_MAX + 0x200)
#define REQ_LEFT_ITEM (KEY_MAX + 0x201)
#define REQ_RIGHT_ITEM (KEY_MAX + 0x202)
#define REQ_UP_ITEM (KEY_MAX + 0x203)
#define REQ_DOWN_ITEM (KEY_MAX + 0x204)
#define REQ_SCR_ULINE (KEY_MAX + 0x205)
#define REQ_SCR_DLINE (KEY_MAX + 0x206)
#define REQ_SCR_DPAGE (KEY_MAX + 0x207)
#define REQ_SCR_UPAGE (KEY_MAX + 0x208)
#define REQ_FIRST_ITEM (KEY_MAX + 0x209)
#define REQ_LAST_ITEM (KEY_MAX + 0x20a)
#define REQ_NEXT_ITEM (KEY_MAX + 0x20b)
#define REQ_PREV_ITEM (KEY_MAX + 0x20c)
#define REQ_TOGGLE_ITEM (KEY_MAX + 0x20d)
#define REQ_CLEAR_PATTERN (KEY_MAX + 0x20e)
#define REQ_BACK_PATTERN (KEY_MAX + 0x20f)
#define REQ_NEXT_MATCH (KEY_MAX + 0x210)
#define REQ_PREV_MATCH (KEY_MAX + 0x211)
#define MAX_COMMAND (KEY_MAX + 0x211) /* last menu driver request
- for application defined
commands */
/* Menu options */
typedef unsigned int OPTIONS;
/* and the values they can have */
#define O_ONEVALUE (0x1)
#define O_SHOWDESC (0x2)
#define O_ROWMAJOR (0x4)
#define O_IGNORECASE (0x8)
#define O_SHOWMATCH (0x10)
#define O_NONCYCLIC (0x20)
#define O_SELECTABLE (0x40)
#define O_RADIO (0x80)
typedef struct __menu_str {
char *string;
int length;
} MENU_STR;
typedef struct __menu MENU;
typedef struct __item ITEM;
typedef void (*Menu_Hook) (MENU *);
struct __item {
MENU_STR name;
MENU_STR description;
char *userptr;
int visible; /* set if item is visible */
int selected; /* set if item has been selected */
int row; /* menu row this item is on */
int col; /* menu column this item is on */
OPTIONS opts;
MENU *parent; /* menu this item is bound to */
int index; /* index number for this item, if attached */
/* The following are the item's neighbours - makes menu
navigation easier */
ITEM *left;
ITEM *right;
ITEM *up;
ITEM *down;
};
struct __menu {
int rows; /* max number of rows to be displayed */
int cols; /* max number of columns to be displayed */
int item_rows; /* number of item rows we have */
int item_cols; /* number of item columns we have */
int cur_row; /* current cursor row */
int cur_col; /* current cursor column */
MENU_STR mark; /* menu mark string */
MENU_STR unmark; /* menu unmark string */
OPTIONS opts; /* options for the menu */
char *pattern; /* the pattern buffer */
int plen; /* pattern buffer length */
int match_len; /* length of pattern matched */
int posted; /* set if menu is posted */
attr_t fore; /* menu foreground */
attr_t back; /* menu background */
attr_t grey; /* greyed out (nonselectable) menu item */
int pad; /* filler char between name and description */
char *userptr;
int top_row; /* the row that is at the top of the menu */
int max_item_width; /* widest item */
int col_width; /* width of the menu columns - this is not always
the same as the widest item */
int item_count; /* number of items attached */
ITEM **items; /* items associated with this menu */
int cur_item; /* item cursor is currently positioned at */
int in_init; /* set when processing an init or term function call */
Menu_Hook menu_init; /* call this when menu is posted */
Menu_Hook menu_term; /* call this when menu is unposted */
Menu_Hook item_init; /* call this when menu posted & after
current item changes */
Menu_Hook item_term; /* call this when menu unposted & just
before current item changes */
WINDOW *menu_win; /* the menu window */
WINDOW *menu_subwin; /* the menu subwindow */
WINDOW *scrwin; /* the window to write to */
};
/* Public function prototypes. */
__BEGIN_DECLS
int menu_driver(MENU *, int);
int scale_menu(MENU *, int *, int *);
int set_top_row(MENU *, int);
int pos_menu_cursor(MENU *);
int top_row(MENU *);
int free_menu(MENU *);
char menu_back(MENU *);
char menu_fore(MENU *);
void menu_format(MENU *, int *, int *);
char menu_grey(MENU *);
Menu_Hook menu_init(MENU *);
char *menu_mark(MENU *);
OPTIONS menu_opts(MENU *);
int menu_opts_off(MENU *, OPTIONS);
int menu_opts_on(MENU *, OPTIONS);
int menu_pad(MENU *);
char *menu_pattern(MENU *);
WINDOW *menu_sub(MENU *);
Menu_Hook menu_term(MENU *);
char *menu_unmark (MENU *);
char *menu_userptr(MENU *);
WINDOW *menu_win(MENU *);
MENU *new_menu(ITEM **);
int post_menu(MENU *);
int set_menu_back(MENU *, attr_t);
int set_menu_fore(MENU *, attr_t);
int set_menu_format(MENU *, int, int);
int set_menu_grey(MENU *, attr_t);
int set_menu_init(MENU *, Menu_Hook);
int set_menu_items(MENU *, ITEM **);
int set_menu_mark(MENU *, char *);
int set_menu_opts(MENU *, OPTIONS);
int set_menu_pad(MENU *, int);
int set_menu_pattern(MENU *, char *);
int set_menu_sub(MENU *, WINDOW *);
int set_menu_term(MENU *, Menu_Hook);
int set_menu_unmark(MENU *, char *);
int set_menu_userptr(MENU *, char *);
int set_menu_win(MENU *, WINDOW *);
int unpost_menu(MENU *);
ITEM *current_item(MENU *);
int free_item(ITEM *);
int item_count(MENU *);
char *item_description(ITEM *);
int item_index(ITEM *);
Menu_Hook item_init(MENU *);
char *item_name(ITEM *);
OPTIONS item_opts(ITEM *);
int item_opts_off(ITEM *, OPTIONS);
int item_opts_on(ITEM *, OPTIONS);
int item_selected(MENU *, int **); /* return the item index of selected */
Menu_Hook item_term(MENU *);
char *item_userptr(ITEM *);
int item_value(ITEM *);
int item_visible(ITEM *);
ITEM **menu_items(MENU *);
ITEM *new_item(char *, char *);
int set_current_item(MENU *, ITEM *);
int set_item_init(MENU *, Menu_Hook);
int set_item_opts(ITEM *, OPTIONS);
int set_item_term(MENU *, Menu_Hook);
int set_item_userptr(ITEM *, char *);
int set_item_value(ITEM *, int);
__END_DECLS
#endif /* !_MENU_H_ */

View file

@ -0,0 +1,135 @@
.\" $NetBSD: menu_attributes.3,v 1.10 2003/04/16 13:35:10 wiz Exp $
.\"
.\" Copyright (c) 1999
.\" Brett Lymn - blymn@baea.com.au, brett_lymn@yahoo.com.au
.\"
.\" This code is donated to The NetBSD Foundation by the author.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the Author may not be used to endorse or promote
.\" products derived from this software without specific prior written
.\" permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd September 10, 1999
.Dt MENU_ATTRIBUTES 3
.Os
.Sh NAME
.Nm menu_back ,
.Nm menu_fore ,
.Nm menu_grey ,
.Nm menu_pad ,
.Nm set_menu_back ,
.Nm set_menu_fore ,
.Nm set_menu_grey ,
.Nm set_menu_pad
.Nd get and set menu attributes
.Sh LIBRARY
.Lb libmenu
.Sh SYNOPSIS
.In menu.h
.Ft char
.Fn menu_back "MENU *menu"
.Ft char
.Fn menu_fore "MENU *menu"
.Ft char
.Fn menu_grey "MENU *menu"
.Ft int
.Fn menu_pad "MENU *menu"
.Ft int
.Fn set_menu_back "MENU *menu" "char attr"
.Ft int
.Fn set_menu_fore "MENU *menu" "char attr"
.Ft int
.Fn set_menu_grey "MENU *menu" "char attr"
.Ft int
.Fn set_menu_pad "MENU *menu" "int pad"
.Sh DESCRIPTION
The
.Fn menu_back
function returns the value of the background attribute for the menu
passed.
This attribute is set by the
.Fn set_menu_back
call.
The
.Fn menu_fore
function returns the value of the foreground character attribute for
the menu passed.
This attribute is set by the
.Fn set_menu_fore
function.
The
.Fn menu_grey
function returns the value of the grey or unselectable character
attribute for the menu passed.
This attribute is set by the
.Fn set_menu_grey
function.
The
.Fn menu_pad
function returns the padding character that will be used between the
item name and its description.
The value of the pad character is set by the
.Fn set_menu_pad
function.
.Sh RETURN VALUES
The functions return one of the following error values:
.Pp
.Bl -tag -width E_UNKNOWN_COMMAND -compact
.It Er E_OK
The function was successful.
.It Er E_SYSTEM_ERROR
There was a system error during the call.
.It Er E_BAD_ARGUMENT
One or more of the arguments passed to the function was incorrect.
.It Er E_POSTED
The menu is already posted.
.It Er E_CONNECTED
An item was already connected to a menu.
.It Er E_BAD_STATE
The function was called from within an initialization or termination
routine.
.It Er E_NO_ROOM
The menu does not fit within the subwindow.
.It Er E_NOT_POSTED
The menu is not posted.
.It Er E_UNKNOWN_COMMAND
The menu driver does not recognize the request passed to it.
.It Er E_NO_MATCH
The character search failed to find a match.
.It Er E_NOT_SELECTABLE
The item could not be selected.
.It Er E_NOT_CONNECTED
The item is not connected to a menu.
.It Er E_REQUEST_DENIED
The menu driver could not process the request.
.El
.Sh SEE ALSO
.Xr curses 3 ,
.Xr menus 3
.Sh NOTES
The header
.Pa \*[Lt]menu.h\*[Gt]
automatically includes both
.Pa \*[Lt]curses.h\*[Gt]
and
.Pa \*[Lt]eti.h\*[Gt] .

91
lib/libmenu/menu_cursor.3 Normal file
View file

@ -0,0 +1,91 @@
.\" $NetBSD: menu_cursor.3,v 1.9 2003/04/16 13:35:10 wiz Exp $
.\"
.\" Copyright (c) 1999
.\" Brett Lymn - blymn@baea.com.au, brett_lymn@yahoo.com.au
.\"
.\" This code is donated to The NetBSD Foundation by the author.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the Author may not be used to endorse or promote
.\" products derived from this software without specific prior written
.\" permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd September 10, 1999
.Dt MENU_CURSOR 3
.Os
.Sh NAME
.Nm pos_menu_cursor
.Nd position cursor in menu window
.Sh LIBRARY
.Lb libmenu
.Sh SYNOPSIS
.In menu.h
.Ft int
.Fn pos_menu_cursor "MENU *menu"
.Sh DESCRIPTION
The
.Fn pos_menu_cursor
function positions the cursor in the menu window.
This function can be called after other curses calls to restore the cursor
to its correct position in the menu.
.Sh RETURN VALUES
The functions return one of the following error values:
.Pp
.Bl -tag -width E_UNKNOWN_COMMAND -compact
.It Er E_OK
The function was successful.
.It Er E_SYSTEM_ERROR
There was a system error during the call.
.It Er E_BAD_ARGUMENT
One or more of the arguments passed to the function was incorrect.
.It Er E_POSTED
The menu is already posted.
.It Er E_CONNECTED
An item was already connected to a menu.
.It Er E_BAD_STATE
The function was called from within an initialization or termination
routine.
.It Er E_NO_ROOM
The menu does not fit within the subwindow.
.It Er E_NOT_POSTED
The menu is not posted.
.It Er E_UNKNOWN_COMMAND
The menu driver does not recognize the request passed to it.
.It Er E_NO_MATCH
The character search failed to find a match.
.It Er E_NOT_SELECTABLE
The item could not be selected.
.It Er E_NOT_CONNECTED
The item is not connected to a menu.
.It Er E_REQUEST_DENIED
The menu driver could not process the request.
.El
.Sh SEE ALSO
.Xr curses 3 ,
.Xr menus 3
.Sh NOTES
The header
.Pa \*[Lt]menu.h\*[Gt]
automatically includes both
.Pa \*[Lt]curses.h\*[Gt]
and
.Pa \*[Lt]eti.h\*[Gt] .

136
lib/libmenu/menu_driver.3 Normal file
View file

@ -0,0 +1,136 @@
.\" $NetBSD: menu_driver.3,v 1.8 2003/04/16 13:35:10 wiz Exp $
.\"
.\" Copyright (c) 1999
.\" Brett Lymn - blymn@baea.com.au, brett_lymn@yahoo.com.au
.\"
.\" This code is donated to The NetBSD Foundation by the author.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the Author may not be used to endorse or promote
.\" products derived from this software without specific prior written
.\" permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd September 10, 1999
.Dt MENU_DRIVER 3
.Os
.Sh NAME
.Nm menu_driver
.Nd main menu handling function
.Sh LIBRARY
.Lb libmenu
.Sh SYNOPSIS
.In menu.h
.Ft int
.Fn menu_driver "MENU *menu" "int c"
.Sh DESCRIPTION
The
.Fn menu_driver
function is the guts of the menu system.
It takes the commands passed
by c parameter and performs the requested action on the menu given.
The following commands may be given to the menu driver:
.Pp
.Bl -tag -width REQ_CLEAR_PATTERN -compact
.It Command
Action
.It REQ_LEFT_ITEM
Sets the new current item to be the item to the left of the current
item.
.It REQ_RIGHT_ITEM
Sets the new current item to be the item to the rights of the current
item.
.It REQ_UP_ITEM
Sets the new current item to be the item above the current item.
.It REQ_DOWN_ITEM
Sets the new current item to be the item below the current item.
.It REQ_SCR_ULINE
Scroll the menu one line towards the bottom of the menu window.
The new current item becomes the item immediately above the current item.
.It REQ_SCR_DLINE
Scroll the menu one line towards the top of the menu window.
The new current item becomes the item immediately below the current item.
.It REQ_SCR_DPAGE
Scroll the menu one page towards the bottom of the menu window.
.It REQ_SCR_UPAGE
Scroll the menu one page towards the top of the menu window.
.It REQ_FIRST_ITEM
Set the current item to be the first item in the menu.
.It REQ_LAST_ITEM
Set the current item to be the last item in the menu.
.It REQ_NEXT_ITEM
Set the new current item to be the next item in the item array after
the current item.
.It REQ_PREV_ITEM
Set the new current item to be the item before the current item in the
items array.
.It REQ_TOGGLE_ITEM
If the item is selectable then toggle the item's value.
.It REQ_CLEAR_PATTERN
Clear all the characters currently in the menu's pattern buffer.
.It REQ_BACK_PATTERN
Remove the last character from the pattern buffer.
.It REQ_NEXT_MATCH
Attempt to find the next item that matches the pattern buffer.
.It REQ_PREV_MATCH
Attempt to find the previous item that matches the pattern buffer.
.El
If
.Fn menu_driver
is passed a command that is greater than MAX_COMMAND then the command
passed is assumed to be a user defined command and
.Fn menu_driver
returns E_UNKNOWN_COMMAND.
Otherwise if the command is a printable
character then the character represented by the command is placed at
the end of the pattern buffer and an attempt is made to match the
pattern buffer against the items in the menu.
.Sh RETURN VALUES
The functions return one of the following error values:
.Pp
.Bl -tag -width E_UNKNOWN_COMMAND -compact
.It Er E_OK
The function was successful.
.It Er E_SYSTEM_ERROR
There was a system error during the call.
.It Er E_BAD_ARGUMENT
One or more of the arguments passed to the function was incorrect.
.It Er E_NOT_POSTED
The menu is not posted.
.It Er E_UNKNOWN_COMMAND
The menu driver does not recognize the request passed to it.
.It Er E_NO_MATCH
The character search failed to find a match.
.It Er E_NOT_CONNECTED
The item is not connected to a menu.
.It Er E_REQUEST_DENIED
The menu driver could not process the request.
.El
.Sh SEE ALSO
.Xr curses 3 ,
.Xr menus 3
.Sh NOTES
The header
.Pa \*[Lt]menu.h\*[Gt]
automatically includes both
.Pa \*[Lt]curses.h\*[Gt]
and
.Pa \*[Lt]eti.h\*[Gt] .

77
lib/libmenu/menu_format.3 Normal file
View file

@ -0,0 +1,77 @@
.\" $NetBSD: menu_format.3,v 1.9 2003/04/16 13:35:10 wiz Exp $
.\"
.\" Copyright (c) 1999
.\" Brett Lymn - blymn@baea.com.au, brett_lymn@yahoo.com.au
.\"
.\" This code is donated to The NetBSD Foundation by the author.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the Author may not be used to endorse or promote
.\" products derived from this software without specific prior written
.\" permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd September 10, 1999
.Dt MENU_FORMAT 3
.Os
.Sh NAME
.Nm menu_format ,
.Nm set_menu_format
.Nd get or set number of rows and columns of items
.Sh LIBRARY
.Lb libmenu
.Sh SYNOPSIS
.In menu.h
.Ft void
.Fn menu_format "MENU *menu" "int *rows" "int *cols"
.Ft int
.Fn set_menu_format "MENU *menu" "int rows" "int cols"
.Sh DESCRIPTION
The
.Fn menu_format
returns the number of rows and columns of items that can be displayed
by the menu.
The format is set by the
.Fn set_menu_format
function call.
Note that the rows and columns defined here are not the size of the
window but rather the number of rows and columns of items.
.Sh RETURN VALUES
The functions return one of the following error values:
.Pp
.Bl -tag -width E_BAD_ARGUMENT -compact
.It Er E_OK
The function was successful.
.It Er E_BAD_ARGUMENT
One or more of the arguments passed to the function was incorrect.
.It Er E_POSTED
The menu is already posted.
.El
.Sh SEE ALSO
.Xr curses 3 ,
.Xr menus 3
.Sh NOTES
The header
.Pa \*[Lt]menu.h\*[Gt]
automatically includes both
.Pa \*[Lt]curses.h\*[Gt]
and
.Pa \*[Lt]eti.h\*[Gt] .

103
lib/libmenu/menu_hook.3 Normal file
View file

@ -0,0 +1,103 @@
.\" $NetBSD: menu_hook.3,v 1.8 2003/04/16 13:35:10 wiz Exp $
.\"
.\" Copyright (c) 1999
.\" Brett Lymn - blymn@baea.com.au, brett_lymn@yahoo.com.au
.\"
.\" This code is donated to The NetBSD Foundation by the author.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the Author may not be used to endorse or promote
.\" products derived from this software without specific prior written
.\" permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd September 10, 1999
.Dt MENU_HOOK 3
.Os
.Sh NAME
.Nm item_init ,
.Nm item_term ,
.Nm menu_init ,
.Nm menu_term ,
.Nm set_item_init ,
.Nm set_item_term ,
.Nm set_menu_init ,
.Nm set_menu_term
.Nd get or set handler functions for menu post/unpost or item change
.Sh LIBRARY
.Lb libmenu
.Sh SYNOPSIS
.In menu.h
.Ft void (*hook)()
.Fn item_init "MENU *menu"
.Ft void (*hook)()
.Fn item_term "MENU *menu"
.Ft void (*hook)()
.Fn menu_init "MENU *menu"
.Ft void (*hook)()
.Fn menu_term "MENU *menu"
.Ft int
.Fn set_item_init "MENU *menu" "void (*hook)())"
.Ft int
.Fn set_item_term "MENU *menu" "void (*hook)())"
.Ft int
.Fn set_menu_init "MENU *menu" "void (*hook)())"
.Ft int
.Fn set_menu_term "MENU *menu" "void (*hook)())"
.Sh DESCRIPTION
The
.Fn item_init
function returns a pointer to the function that will be called
whenever the menu is posted and also just after the current item
changes.
This is set by the
.Fn set_item_init
call.
The
.Fn item_term
function returns a pointer to the function that will be called before
the menu is unposted and just before the current item changes, this
pointer is set by the
.Fn set_item_term
call.
The
.Fn menu_init
functions returns a pointer to the function that will be called just
before the menu is posted to the screen.
This pointer is set by the
.Fn set_menu_init
function call.
The
.Fn menu_term
function returns a pointer to the function that will be called just
after the menu has been unposted, this pointer is set by the
.Fn set_menu_term
function.
.Sh SEE ALSO
.Xr curses 3 ,
.Xr menus 3
.Sh NOTES
The header
.Pa \*[Lt]menu.h\*[Gt]
automatically includes both
.Pa \*[Lt]curses.h\*[Gt]
and
.Pa \*[Lt]eti.h\*[Gt] .

View file

@ -0,0 +1,101 @@
.\" $NetBSD: menu_item_current.3,v 1.9 2003/04/16 13:35:10 wiz Exp $
.\"
.\" Copyright (c) 1999
.\" Brett Lymn - blymn@baea.com.au, brett_lymn@yahoo.com.au
.\"
.\" This code is donated to The NetBSD Foundation by the author.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the Author may not be used to endorse or promote
.\" products derived from this software without specific prior written
.\" permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd September 10, 1999
.Dt MENU_ITEM_CURRENT 3
.Os
.Sh NAME
.Nm current_item ,
.Nm item_index ,
.Nm set_current_item ,
.Nm set_top_row
.Nm top_row
.Nd get or set item pointers or top row
.Sh LIBRARY
.Lb libmenu
.Sh SYNOPSIS
.In menu.h
.Ft ITEM *
.Fn current_item "MENU *menu"
.Ft int
.Fn item_index "ITEM *item"
.Ft int
.Fn set_current_item "MENU *menu" "ITEM *item"
.Ft int
.Fn set_top_row "MENU *menu" "int row"
.Ft int
.Fn top_row "MENU *menu"
.Sh DESCRIPTION
The
.Fn current_item
returns a pointer to the current menu item.
The
.Fn set_current_item
can be used to set this to the item give.
The
.Fn item_index
function returns the index number in the array of items for the item
pointed to by the
.Fa item
parameter.
The
.Fn set_top_row
function sets the top row of the menu displayed to be the row given.
The current item becomes the leftmost item of the top row.
The
.Fn top_row
call returns the row number that is currently at the top of the
displayed menu.
.Sh RETURN VALUES
.Fn current_item
returns NULL if no items are attached to the menu.
.Pp
.Bl -tag -width E_NOT_CONNECTED -compact
.It Er E_OK
The function was successful.
.It Er E_BAD_ARGUMENT
One or more of the arguments passed to the function was incorrect.
.It Er E_BAD_STATE
The function was called from within an initialization or termination
routine.
.It Er E_NOT_CONNECTED
The item is not connected to a menu.
.El
.Sh SEE ALSO
.Xr curses 3 ,
.Xr menus 3
.Sh NOTES
The header
.Pa \*[Lt]menu.h\*[Gt]
automatically includes both
.Pa \*[Lt]curses.h\*[Gt]
and
.Pa \*[Lt]eti.h\*[Gt] .

View file

@ -0,0 +1,71 @@
.\" $NetBSD: menu_item_name.3,v 1.9 2003/04/16 13:35:10 wiz Exp $
.\"
.\" Copyright (c) 1999
.\" Brett Lymn - blymn@baea.com.au, brett_lymn@yahoo.com.au
.\"
.\" This code is donated to The NetBSD Foundation by the author.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the Author may not be used to endorse or promote
.\" products derived from this software without specific prior written
.\" permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd September 10, 1999
.Dt MENU_ITEM_NAME 3
.Os
.Sh NAME
.Nm item_description ,
.Nm item_name
.Nd get item name or description
.Sh LIBRARY
.Lb libmenu
.Sh SYNOPSIS
.In menu.h
.Ft char *
.Fn item_description "ITEM *item"
.Ft char *
.Fn item_name "ITEM *item"
.Sh DESCRIPTION
The
.Fn item_description
.Fa menu
function returns the description string associated with the passed
item.
The
.Fn item_name
function returns the name string associated with the passed item.
.Sh RETURN VALUES
The function
.Fn item_description
and
.Fn item_name
functions return NULL if the item pointer is not valid.
.Sh SEE ALSO
.Xr curses 3 ,
.Xr menus 3
.Sh NOTES
The header
.Pa \*[Lt]menu.h\*[Gt]
automatically includes both
.Pa \*[Lt]curses.h\*[Gt]
and
.Pa \*[Lt]eti.h\*[Gt] .

View file

@ -0,0 +1,79 @@
.\" $NetBSD: menu_item_new.3,v 1.8 2003/04/16 13:35:10 wiz Exp $
.\"
.\" Copyright (c) 1999
.\" Brett Lymn - blymn@baea.com.au, brett_lymn@yahoo.com.au
.\"
.\" This code is donated to The NetBSD Foundation by the author.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the Author may not be used to endorse or promote
.\" products derived from this software without specific prior written
.\" permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd September 10, 1999
.Dt MENU_ITEM_NEW 3
.Os
.Sh NAME
.Nm free_item ,
.Nm new_item
.Nd create or delete menu item
.Sh LIBRARY
.Lb libmenu
.Sh SYNOPSIS
.In menu.h
.Ft int
.Fn free_item "ITEM *item"
.Ft ITEM *
.Fn new_item "char *name" "char *description"
.Sh DESCRIPTION
The
.Fn free_item
function destroys the item and frees all allocated storage for that
item.
The
.Fn new_item
allocates storage for a new item then copies in the item name and
description for the new item.
A pointer to the newly created item is returned to the caller.
.Sh RETURN VALUES
The
.Fn new_item
function returns NULL on failure, the
.Fn free_item
returns one of the following error values:
.Pp
.Bl -tag -width E_BAD_ARGUMENT -compact
.It Er E_OK
The function was successful.
.It Er E_BAD_ARGUMENT
One or more of the arguments passed to the function was incorrect.
.El
.Sh SEE ALSO
.Xr curses 3 ,
.Xr menus 3
.Sh NOTES
The header
.Pa \*[Lt]menu.h\*[Gt]
automatically includes both
.Pa \*[Lt]curses.h\*[Gt]
and
.Pa \*[Lt]eti.h\*[Gt] .

View file

@ -0,0 +1,82 @@
.\" $NetBSD: menu_item_opts.3,v 1.8 2003/04/16 13:35:11 wiz Exp $
.\"
.\" Copyright (c) 1999
.\" Brett Lymn - blymn@baea.com.au, brett_lymn@yahoo.com.au
.\"
.\" This code is donated to The NetBSD Foundation by the author.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the Author may not be used to endorse or promote
.\" products derived from this software without specific prior written
.\" permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd September 10, 1999
.Dt MENU_ITEM_OPTS 3
.Os
.Sh NAME
.Nm item_opts ,
.Nm item_opts_off ,
.Nm item_opts_on
.Nd get or modify options for an item
.Sh LIBRARY
.Lb libmenu
.Sh SYNOPSIS
.In menu.h
.Ft OPTIONS
.Fn item_opts "ITEM *item"
.Ft int
.Fn item_opts_off "ITEM *item" "OPTIONS opts"
.Ft int
.Fn item_opts_on "ITEM *item" "OPTIONS opts"
.Sh DESCRIPTION
The
.Fn item_opts
function returns the options currently set for the given item.
The
.Fn item_opts_off
function turns off the options passed in
.Fa opts
for the item passed.
The
.Fn item_opts_on
function turns on the options passed in
.Fa opts
for the item given.
.Sh RETURN VALUES
The functions return one of the following error values:
.Pp
.Bl -tag -width E_SYSTEM_ERROR -compact
.It Er E_OK
The function was successful.
.It Er E_SYSTEM_ERROR
There was a system error during the call.
.El
.Sh SEE ALSO
.Xr curses 3 ,
.Xr menus 3
.Sh NOTES
The header
.Pa \*[Lt]menu.h\*[Gt]
automatically includes both
.Pa \*[Lt]curses.h\*[Gt]
and
.Pa \*[Lt]eti.h\*[Gt] .

View file

@ -0,0 +1,72 @@
.\" $NetBSD: menu_item_userptr.3,v 1.7 2003/04/16 13:35:11 wiz Exp $
.\"
.\" Copyright (c) 1999
.\" Brett Lymn - blymn@baea.com.au, brett_lymn@yahoo.com.au
.\"
.\" This code is donated to The NetBSD Foundation by the author.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the Author may not be used to endorse or promote
.\" products derived from this software without specific prior written
.\" permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd September 10, 1999
.Dt MENU_ITEM_USERPTR 3
.Os
.Sh NAME
.Nm item_userptr ,
.Nm set_item_userptr
.Nd get or set user pointer for an item
.Sh LIBRARY
.Lb libmenu
.Sh SYNOPSIS
.In menu.h
.Ft char *
.Fn item_userptr "ITEM *item"
.Ft int
.Fn set_item_userptr "ITEM *item" "char *userptr"
.Sh DESCRIPTION
The
.Fn item_userptr
function returns the value of the user defined pointer for the given
item, this pointer is defined by the
.Fn set_item_userptr
function.
.Sh RETURN VALUES
The functions return one of the following error values:
.Pp
.Bl -tag -width E_SYSTEM_ERROR -compact
.It Er E_OK
The function was successful.
.It Er E_SYSTEM_ERROR
There was a system error during the call.
.El
.Sh SEE ALSO
.Xr curses 3 ,
.Xr menus 3
.Sh NOTES
The header
.Pa \*[Lt]menu.h\*[Gt]
automatically includes both
.Pa \*[Lt]curses.h\*[Gt]
and
.Pa \*[Lt]eti.h\*[Gt] .

View file

@ -0,0 +1,106 @@
.\" $NetBSD: menu_item_value.3,v 1.11 2003/04/16 13:35:11 wiz Exp $ .\"
.\" Copyright (c) 1999
.\" Brett Lymn - blymn@baea.com.au, brett_lymn@yahoo.com.au
.\"
.\" This code is donated to The NetBSD Foundation by the author.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the Author may not be used to endorse or promote
.\" products derived from this software without specific prior written
.\" permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd September 10, 1999
.Dt MENU_ITEM_VALUE 3
.Os
.Sh NAME
.Nm item_value ,
.Nm set_item_value ,
.Nm item_selected
.Nd get or set value for an item
.Sh LIBRARY
.Lb libmenu
.Sh SYNOPSIS
.In menu.h
.Ft int
.Fn item_value "ITEM *item"
.Ft int
.Fn set_item_value "ITEM *item" "int flag"
.Ft int
.Fn item_selected "MENU *menu" "int **array"
.Sh DESCRIPTION
The
.Fn item_value
function returns value of the item.
If the item has been selected then this value will be TRUE.
The value can also be set by calling
.Fn set_item_value
to set the value to a defined state.
Setting the value to a value
other than TRUE or FALSE will have undefined results.
The
.Fn item_selected
function returns the number of items that are selected in the menu, that
is the number of items whose value is TRUE.
The indexes of the selected
items will be returned in
.Fa array
which will be dynamically allocated to hold the number of indexes.
It is the responsibility of the caller to release this storage by calling
.Xr free 3
when the storage is no longer required.
If there are no elements selected in the items array then
.Fn item_selected
will return 0 and
.Fa array
will be NULL.
If an error occurs
.Fn item_selected
will return one of the below return values which are less than 0.
.Sh RETURN VALUES
The functions return one of the following error values:
.Pp
.Bl -tag -width E_REQUEST_DENIED -compact
.It Er E_OK
The function was successful.
.It Er E_NOT_CONNECTED
The item is not connected to a menu.
.It Er E_REQUEST_DENIED
The menu driver could not process the request.
.It Er E_SYSTEM_ERROR
A system error occurred whilst processing the request.
.El
.Sh SEE ALSO
.Xr curses 3 ,
.Xr menus 3
.Sh NOTES
The header
.Pa \*[Lt]menu.h\*[Gt]
automatically includes both
.Pa \*[Lt]curses.h\*[Gt]
and
.Pa \*[Lt]eti.h\*[Gt] .
.Pp
The function
.Fn item_selected
is a
.Nx
extension and must not be used in portable code.

View file

@ -0,0 +1,67 @@
.\" $NetBSD: menu_item_visible.3,v 1.7 2003/04/16 13:35:11 wiz Exp $
.\"
.\" Copyright (c) 1999
.\" Brett Lymn - blymn@baea.com.au, brett_lymn@yahoo.com.au
.\"
.\" This code is donated to The NetBSD Foundation by the author.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the Author may not be used to endorse or promote
.\" products derived from this software without specific prior written
.\" permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd September 10, 1999
.Dt MENU_ITEM_VISIBLE 3
.Os
.Sh NAME
.Nm item_visible
.Nd get visibility status of an item
.Sh LIBRARY
.Lb libmenu
.Sh SYNOPSIS
.In menu.h
.Ft int
.Fn item_visible "ITEM *item"
.Sh DESCRIPTION
The
.Fn item_visible
function returns TRUE if the item passed is currently visible in a
menu.
.Sh RETURN VALUES
The functions return one of the following error values:
.Pp
.Bl -tag -width E_NOT_CONNECTED -compact
.It Er E_BAD_ARGUMENT
One or more of the arguments passed to the function was incorrect.
.It Er E_NOT_CONNECTED
The item is not connected to a menu.
.El
.Sh SEE ALSO
.Xr curses 3 ,
.Xr menus 3
.Sh NOTES
The header
.Pa \*[Lt]menu.h\*[Gt]
automatically includes both
.Pa \*[Lt]curses.h\*[Gt]
and
.Pa \*[Lt]eti.h\*[Gt] .

90
lib/libmenu/menu_items.3 Normal file
View file

@ -0,0 +1,90 @@
.\" $NetBSD: menu_items.3,v 1.10 2012/06/30 09:25:55 jdf Exp $
.\"
.\" Copyright (c) 1999
.\" Brett Lymn - blymn@baea.com.au, brett_lymn@yahoo.com.au
.\"
.\" This code is donated to The NetBSD Foundation by the author.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the Author may not be used to endorse or promote
.\" products derived from this software without specific prior written
.\" permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd September 10, 1999
.Dt MENU_ITEMS 3
.Os
.Sh NAME
.Nm item_count ,
.Nm menu_items ,
.Nm set_menu_items
.Nd attach items to menus or check correspondences
.Sh LIBRARY
.Lb libmenu
.Sh SYNOPSIS
.In menu.h
.Ft int
.Fn item_count "MENU *menu"
.Ft ITEM **
.Fn menu_items "MENU *menu"
.Ft int
.Fn set_menu_items "MENU *menu" "ITEM **items"
.Sh DESCRIPTION
The
.Fn item_count
.Fa menu
function returns the number of items currently attached to the menu
passed.
The
.Fn menu_items
function returns a pointer to an array of item pointers that represent
the menu items currently attached to the given menu.
Apart from using
.Fn new_menu
(see
.Xr menu_new 3 )
menu items may be attached to a menu by calling
.Fn set_menu_items
any items currently attached to the menu will be detached and the NULL
terminated array of new items will be attached to the menu.
.Sh RETURN VALUES
Any function returning a string pointer will return NULL if an error
occurs.
Functions returning an integer will return one of the following:
.Pp
.Bl -tag -width E_CONNECTED -compact
.It Er E_OK
The function was successful.
.It Er E_POSTED
The menu is already posted.
.It Er E_CONNECTED
An item was already connected to a menu.
.El
.Sh SEE ALSO
.Xr curses 3 ,
.Xr menus 3
.Sh NOTES
The header
.Pa \*[Lt]menu.h\*[Gt]
automatically includes both
.Pa \*[Lt]curses.h\*[Gt]
and
.Pa \*[Lt]eti.h\*[Gt] .

112
lib/libmenu/menu_mark.3 Normal file
View file

@ -0,0 +1,112 @@
.\" $NetBSD: menu_mark.3,v 1.9 2003/04/16 13:35:11 wiz Exp $
.\"
.\" Copyright (c) 1999
.\" Brett Lymn - blymn@baea.com.au, brett_lymn@yahoo.com.au
.\"
.\" This code is donated to The NetBSD Foundation by the author.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the Author may not be used to endorse or promote
.\" products derived from this software without specific prior written
.\" permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd September 10, 1999
.Dt MENU_MARK 3
.Os
.Sh NAME
.Nm menu_mark ,
.Nm menu_unmark ,
.Nm set_menu_mark ,
.Nm set_menu_unmark
.Nd get or set strings that show mark status for a menu
.Sh LIBRARY
.Lb libmenu
.Sh SYNOPSIS
.In menu.h
.Ft char *
.Fn menu_mark "MENU *menu"
.Ft char *
.Fn menu_unmark "MENU *menu"
.Ft int
.Fn set_menu_mark "MENU *menu" "char *mark"
.Ft int
.Fn set_menu_unmark "MENU *menu" "char *mark"
.Sh DESCRIPTION
The
.Fn menu_mark
function returns a pointer to the character string that is used to
mark selected items in the menu.
The mark string is set by the
.Fn set_menu_mark
function.
The
.Fn menu_unmark
function returns a pointer to the character string that is used to
indicate a menu items is not selected, this string is set by the
.Fn set_menu_unmark
function.
The mark and unmark strings may be of differing lengths, the room
allocated to drawing the mark will be the maximum of the lengths of
both the mark and unmark strings.
The shorter of the two strings will be left justified and space padded.
.Sh RETURN VALUES
The functions return one of the following error values:
.Pp
.Bl -tag -width E_UNKNOWN_COMMAND -compact
.It Er E_OK
The function was successful.
.It Er E_SYSTEM_ERROR
There was a system error during the call.
.It Er E_BAD_ARGUMENT
One or more of the arguments passed to the function was incorrect.
.It Er E_POSTED
The menu is already posted.
.It Er E_CONNECTED
An item was already connected to a menu.
.It Er E_BAD_STATE
The function was called from within an initialization or termination
routine.
.It Er E_NO_ROOM
The menu does not fit within the subwindow.
.It Er E_NOT_POSTED
The menu is not posted.
.It Er E_UNKNOWN_COMMAND
The menu driver does not recognize the request passed to it.
.It Er E_NO_MATCH
The character search failed to find a match.
.It Er E_NOT_SELECTABLE
The item could not be selected.
.It Er E_NOT_CONNECTED
The item is not connected to a menu.
.It Er E_REQUEST_DENIED
The menu driver could not process the request.
.El
.Sh SEE ALSO
.Xr curses 3 ,
.Xr menus 3
.Sh NOTES
The header
.Pa \*[Lt]menu.h\*[Gt]
automatically includes both
.Pa \*[Lt]curses.h\*[Gt]
and
.Pa \*[Lt]eti.h\*[Gt] .

85
lib/libmenu/menu_new.3 Normal file
View file

@ -0,0 +1,85 @@
.\" $NetBSD: menu_new.3,v 1.10 2012/06/30 09:25:55 jdf Exp $
.\"
.\" Copyright (c) 1999
.\" Brett Lymn - blymn@baea.com.au, brett_lymn@yahoo.com.au
.\"
.\" This code is donated to The NetBSD Foundation by the author.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the Author may not be used to endorse or promote
.\" products derived from this software without specific prior written
.\" permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd September 10, 1999
.Dt MENU_NEW 3
.Os
.Sh NAME
.Nm free_menu ,
.Nm new_menu
.Nd create or delete a menu
.Sh LIBRARY
.Lb libmenu
.Sh SYNOPSIS
.In menu.h
.Ft int
.Fn free_menu "MENU *menu"
.Ft MENU *
.Fn new_menu "ITEM **items"
.Sh DESCRIPTION
The
.Fn free_menu
.Fa menu
function destroys the given menu and frees all allocated storage
associated with the menu.
All items associated with the menu are
detached from the menu before it is destroyed.
The
.Fn new_menu
function allocates storage for a new menu and initializes all the
values to the defined defaults.
If the items pointer passed is not a NULL then the given NULL terminated
array of items is attached to the new menu.
.Sh RETURN VALUES
The
.Fn new_menu
function returns NULL on error, while the
.Fn free_menu
function returns one of the following error values:
.Pp
.Bl -tag -width E_BAD_ARGUMENT -compact
.It Er E_OK
The function was successful.
.It Er E_BAD_ARGUMENT
One or more of the arguments passed to the function was incorrect.
.It Er E_POSTED
The menu is already posted.
.El
.Sh SEE ALSO
.Xr curses 3 ,
.Xr menus 3
.Sh NOTES
The header
.Pa \*[Lt]menu.h\*[Gt]
automatically includes both
.Pa \*[Lt]curses.h\*[Gt]
and
.Pa \*[Lt]eti.h\*[Gt] .

88
lib/libmenu/menu_opts.3 Normal file
View file

@ -0,0 +1,88 @@
.\" $NetBSD: menu_opts.3,v 1.8 2003/04/16 13:35:11 wiz Exp $
.\"
.\" Copyright (c) 1999
.\" Brett Lymn - blymn@baea.com.au, brett_lymn@yahoo.com.au
.\"
.\" This code is donated to The NetBSD Foundation by the author.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the Author may not be used to endorse or promote
.\" products derived from this software without specific prior written
.\" permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd September 10, 1999
.Dt MENU_OPTS 3
.Os
.Sh NAME
.Nm menu_opts ,
.Nm menu_opts_off ,
.Nm menu_opts_on ,
.Nm set_menu_opts
.Nd get or modify options for a menu
.Sh LIBRARY
.Lb libmenu
.Sh SYNOPSIS
.In menu.h
.Ft OPTIONS
.Fn menu_opts "MENU *menu"
.Ft int
.Fn menu_opts_off "MENU *menu" "OPTIONS opts"
.Ft int
.Fn menu_opts_on "MENU *menu" "OPTIONS opts"
.Ft int
.Fn set_menu_opts "MENU *menu" "OPTIONS opts"
.Sh DESCRIPTION
The
.Fn menu_opts
function returns the current options set for the menu given.
The
.Fn menu_opts_off
function turns off the menu options given by the opts parameter for
the menu.
The
.Fn menu_opts_on
function turns on the menu options given by the opts parameter for the
menu passed.
The
.Fn set_menu_opts
sets the menu options to the value given in opts.
.Sh RETURN VALUES
The functions return one of the following error values:
.Pp
.Bl -tag -width E_BAD_ARGUMENT -compact
.It Er E_OK
The function was successful.
.It Er E_BAD_ARGUMENT
One or more of the arguments passed to the function was incorrect.
.It Er E_POSTED
The menu is already posted.
.El
.Sh SEE ALSO
.Xr curses 3 ,
.Xr menus 3
.Sh NOTES
The header
.Pa \*[Lt]menu.h\*[Gt]
automatically includes both
.Pa \*[Lt]curses.h\*[Gt]
and
.Pa \*[Lt]eti.h\*[Gt] .

View file

@ -0,0 +1,77 @@
.\" $NetBSD: menu_pattern.3,v 1.8 2003/04/16 13:35:11 wiz Exp $
.\"
.\" Copyright (c) 1999
.\" Brett Lymn - blymn@baea.com.au, brett_lymn@yahoo.com.au
.\"
.\" This code is donated to The NetBSD Foundation by the author.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the Author may not be used to endorse or promote
.\" products derived from this software without specific prior written
.\" permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd September 10, 1999
.Dt MENU_PATTERN 3
.Os
.Sh NAME
.Nm menu_pattern ,
.Nm set_menu_pattern
.Nd get or set menu pattern
.Sh LIBRARY
.Lb libmenu
.Sh SYNOPSIS
.In menu.h
.Ft char *
.Fn menu_pattern "MENU *menu"
.Sh DESCRIPTION
The
.Fn menu_pattern
function returns a pointer to the string that is currently in the menu
pattern buffer.
The menu pattern buffer can be set by calling
.Fn set_menu_pattern
which will set the pattern buffer to the string passed and then
attempt to match that string against the names of the items in the
attached items.
.Sh RETURN VALUES
The functions return one of the following error values:
.Pp
.Bl -tag -width E_BAD_ARGUMENT -compact
.It Er E_OK
The function was successful.
.It Er E_SYSTEM_ERROR
There was a system error during the call.
.It Er E_BAD_ARGUMENT
One or more of the arguments passed to the function was incorrect.
.It Er E_NO_MATCH
The character search failed to find a match.
.El
.Sh SEE ALSO
.Xr curses 3 ,
.Xr menus 3
.Sh NOTES
The header
.Pa \*[Lt]menu.h\*[Gt]
automatically includes both
.Pa \*[Lt]curses.h\*[Gt]
and
.Pa \*[Lt]eti.h\*[Gt] .

98
lib/libmenu/menu_post.3 Normal file
View file

@ -0,0 +1,98 @@
.\" $NetBSD: menu_post.3,v 1.10 2009/10/24 11:17:13 reed Exp $
.\"
.\" Copyright (c) 1999
.\" Brett Lymn - blymn@baea.com.au, brett_lymn@yahoo.com.au
.\"
.\" This code is donated to The NetBSD Foundation by the author.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the Author may not be used to endorse or promote
.\" products derived from this software without specific prior written
.\" permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd September 10, 1999
.Dt MENU_POST 3
.Os
.Sh NAME
.Nm post_menu ,
.Nm unpost_menu
.Nd post (draw) or unpost a menu
.Sh LIBRARY
.Lb libmenu
.Sh SYNOPSIS
.In menu.h
.Ft int
.Fn post_menu "MENU *menu"
.Ft int
.Fn unpost_menu "MENU *menu"
.Sh DESCRIPTION
The
.Fn post_menu
function causes the menu to be drawn on the screen.
Any functions defined by either
.Fn set_menu_init
or
.Fn set_item_init
(see
.Xr menu_hook 3 )
are called before the menu is placed on the screen.
The
.Fn unpost_menu
does the opposite, it removes a menu from the screen.
Any functions defined by both
.Fn set_menu_term
and
.Fn set_item_term
(see
.Xr menu_hook 3 )
are called prior to the menu's removal.
.Sh RETURN VALUES
The functions return one of the following error values:
.Pp
.Bl -tag -width E_NOT_CONNECTED -compact
.It Er E_OK
The function was successful.
.It Er E_SYSTEM_ERROR
There was a system error during the call.
.It Er E_BAD_ARGUMENT
One or more of the arguments passed to the function was incorrect.
.It Er E_POSTED
The menu is already posted.
.It Er E_BAD_STATE
The function was called from within an initialization or termination
routine.
.It Er E_NO_ROOM
The menu does not fit within the subwindow.
.It Er E_NOT_CONNECTED
The item is not connected to a menu.
.El
.Sh SEE ALSO
.Xr curses 3 ,
.Xr menu_hook 3 ,
.Xr menus 3
.Sh NOTES
The header
.Pa \*[Lt]menu.h\*[Gt]
automatically includes both
.Pa \*[Lt]curses.h\*[Gt]
and
.Pa \*[Lt]eti.h\*[Gt] .

View file

@ -0,0 +1,73 @@
.\" $NetBSD: menu_userptr.3,v 1.8 2003/04/16 13:35:11 wiz Exp $
.\"
.\" Copyright (c) 1999
.\" Brett Lymn - blymn@baea.com.au, brett_lymn@yahoo.com.au
.\"
.\" This code is donated to The NetBSD Foundation by the author.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the Author may not be used to endorse or promote
.\" products derived from this software without specific prior written
.\" permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd September 10, 1999
.Dt MENU_USERPTR 3
.Os
.Sh NAME
.Nm menu_userptr ,
.Nm set_menu_userptr
.Nd get or set user pointer for a menu
.Sh LIBRARY
.Lb libmenu
.Sh SYNOPSIS
.In menu.h
.Ft char *
.Fn menu_userptr "MENU *menu"
.Ft int
.Fn set_menu_userptr "MENU *menu" "char *ptr"
.Sh DESCRIPTION
The
.Fn menu_userptr
function returns the pointer to the user defined pointer for the given
menu.
This pointer is set by the
.Fn set_menu_userptr
function.
.Sh RETURN VALUES
The functions return one of the following error values:
.Pp
.Bl -tag -width E_SYSTEM_ERROR -compact
.It Er E_OK
The function was successful.
.It Er E_SYSTEM_ERROR
There was a system error during the call.
.El
.Sh SEE ALSO
.Xr curses 3 ,
.Xr menus 3
.Sh NOTES
The header
.Pa \*[Lt]menu.h\*[Gt]
automatically includes both
.Pa \*[Lt]curses.h\*[Gt]
and
.Pa \*[Lt]eti.h\*[Gt] .

115
lib/libmenu/menu_win.3 Normal file
View file

@ -0,0 +1,115 @@
.\" $NetBSD: menu_win.3,v 1.10 2003/04/16 13:35:11 wiz Exp $
.\"
.\" Copyright (c) 1999
.\" Brett Lymn - blymn@baea.com.au, brett_lymn@yahoo.com.au
.\"
.\" This code is donated to The NetBSD Foundation by the author.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the Author may not be used to endorse or promote
.\" products derived from this software without specific prior written
.\" permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd September 10, 1999
.Dt MENU_WIN 3
.Os
.Sh NAME
.Nm menu_sub ,
.Nm menu_win ,
.Nm scale_menu ,
.Nm set_menu_sub ,
.Nm set_menu_win
.Nd sub-menu handling
.Sh LIBRARY
.Lb libmenu
.Sh SYNOPSIS
.In menu.h
.Ft WINDOW *
.Fn menu_sub "MENU *menu"
.Ft WINDOW *
.Fn menu_win "MENU *menu"
.Ft int
.Fn scale_menu "MENU *menu" "int *rows" "int *cols"
.Ft int
.Fn set_menu_sub "MENU *menu" "WINDOW *sub"
.Ft int
.Fn set_menu_win "MENU *menu" "WINDOW *win"
.Sh DESCRIPTION
The
.Fn menu_sub
function returns a pointer to the window that will be used to post a
menu into, this pointer is set by the
.Fn set_menu_sub
function.
The
.Fn menu_win
function returns a pointer to the window in which the menu subwindow
will be created when the menu is posted, this pointer is set by the
.Fn set_menu_win
function.
The
.Fn scale_menu
function calculates the minimum size a window needs to be to hold the
items for a given menu, the parameters rows and cols are set to the
required number of rows and columns respectively.
.Sh RETURN VALUES
The functions return one of the following error values:
.Pp
.Bl -tag -width E_UNKNOWN_COMMAND -compact
.It Er E_OK
The function was successful.
.It Er E_SYSTEM_ERROR
There was a system error during the call.
.It Er E_BAD_ARGUMENT
One or more of the arguments passed to the function was incorrect.
.It Er E_POSTED
The menu is already posted.
.It Er E_CONNECTED
An item was already connected to a menu.
.It Er E_BAD_STATE
The function was called from within an initialization or termination
routine.
.It Er E_NO_ROOM
The menu does not fit within the subwindow.
.It Er E_NOT_POSTED
The menu is not posted
.It Er E_UNKNOWN_COMMAND
The menu driver does not recognize the request passed to it.
.It Er E_NO_MATCH
The character search failed to find a match.
.It Er E_NOT_SELECTABLE
The item could not be selected.
.It Er E_NOT_CONNECTED
The item is not connected to a menu.
.It Er E_REQUEST_DENIED
The menu driver could not process the request.
.El
.Sh SEE ALSO
.Xr curses 3 ,
.Xr menus 3
.Sh NOTES
The header
.Pa \*[Lt]menu.h\*[Gt]
automatically includes both
.Pa \*[Lt]curses.h\*[Gt]
and
.Pa \*[Lt]eti.h\*[Gt] .

299
lib/libmenu/menus.3 Normal file
View file

@ -0,0 +1,299 @@
.\" $NetBSD: menus.3,v 1.15 2003/04/16 13:35:12 wiz Exp $
.\"
.\" Copyright (c) 1999
.\" Brett Lymn - blymn@baea.com.au, brett_lymn@yahoo.com.au
.\"
.\" This code is donated to The NetBSD Foundation by the author.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the Author may not be used to endorse or promote
.\" products derived from this software without specific prior written
.\" permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd September 10, 1999
.Dt MENUS 3
.Os
.Sh NAME
.Nm menus
.Nd menu library
.Sh LIBRARY
.Lb libmenu
.Sh SYNOPSIS
.In menu.h
.Sh DESCRIPTION
The
.Nm
library provides a terminal independent menu system using the
.Xr curses 3
library.
Before using the
.Nm
functions the terminal must be set up by
.Xr curses 3
using the
.Fn initscr
function or similar.
Programs using
.Nm
functions must be linked with the
.Xr curses 3
library.
.Pp
The
.Nm
library provides facilities for defining menu items, placing a menu on the
terminal screen, assign pre- and post-change operations and setting the
attributes of both the menu and its items.
.Ss Defining default attributes for menus and items
The
.Nm
library allows any settable attribute or option of both the menu and item
objects to be defined such that any new menu or item automatically inherits
the value as default.
Setting the default value will not affect any item or
menu that has already been created but will be applied to subsequent objects.
To set the default attribute or option the set routine is passed a NULL
pointer in the item or menu parameter when calling the set routine.
The current default value can be retrieved by calling the get routine with a
NULL pointer for the item or menu parameter.
.Pp
.Bl -tag -width item_description -compact
.It function name
manual page name
.It current_item
.Xr menu_item_current 3
.It free_item
.Xr menu_item_new 3
.It free_menu
.Xr menu_new 3
.It item_count
.Xr menu_items 3
.It item_description
.Xr menu_item_name 3
.It item_index
.Xr menu_item_current 3
.It item_init
.Xr menu_hook 3
.It item_name
.Xr menu_item_name 3
.It item_opts
.Xr menu_item_opts 3
.It item_opts_off
.Xr menu_item_opts 3
.It item_opts_on
.Xr menu_item_opts 3
.It item_selected
.Xr menu_item_value 3
.It item_term
.Xr menu_hook 3
.It item_userptr
.Xr menu_item_userptr 3
.It item_value
.Xr menu_item_value 3
.It item_visible
.Xr menu_item_visible 3
.It menu_back
.Xr menu_attributes 3
.It menu_driver
.Xr menu_driver 3
.It menu_fore
.Xr menu_attributes 3
.It menu_format
.Xr menu_format 3
.It menu_grey
.Xr menu_attributes 3
.It menu_init
.Xr menu_hook 3
.It menu_items
.Xr menu_items 3
.It menu_mark
.Xr menu_mark 3
.It menu_opts
.Xr menu_opts 3
.It menu_opts_off
.Xr menu_opts 3
.It menu_opts_on
.Xr menu_opts 3
.It menu_pad
.Xr menu_attributes 3
.It menu_pattern
.Xr menu_pattern 3
.It menu_sub
.Xr menu_win 3
.It menu_term
.Xr menu_hook 3
.It menu_unmark
.Xr menu_mark 3
.It menu_userptr
.Xr menu_userptr 3
.It men_win
.Xr menu_win 3
.It new_item
.Xr menu_item_new 3
.It new_menu
.Xr menu_new 3
.It pos_menu_cursor
.Xr menu_cursor 3
.It post_menu
.Xr menu_post 3
.It scale_menu
.Xr menu_win 3
.It set_current_item
.Xr menu_item_current 3
.It set_item_init
.Xr menu_hook 3
.It set_item_opts
.Xr menu_item_opts 3
.It set_item_term
.Xr menu_hook 3
.It set_item_userptr
.Xr menu_item_userptr 3
.It set_item_value
.Xr menu_item_value 3
.It set_menu_back
.Xr menu_attributes 3
.It set_menu_fore
.Xr menu_attributes 3
.It set_menu_format
.Xr menu_format 3
.It set_menu_grey
.Xr menu_attributes 3
.It set_menu_init
.Xr menu_hook 3
.It set_menu_items
.Xr menu_items 3
.It set_menu_mark
.Xr menu_mark 3
.It set_menu_opts
.Xr menu_opts 3
.It set_menu_pad
.Xr menu_attributes 3
.It set_menu_pattern
.Xr menu_pattern 3
.It set_menu_sub
.Xr menu_win 3
.It set_menu_term
.Xr menu_hook 3
.It set_menu_unmark
.Xr menu_mark 3
.It set_menu_userptr
.Xr menu_userptr 3
.It set_menu_win
.Xr menu_win 3
.It set_top_row
.Xr menu_item_current 3
.It top_row
.Xr menu_item_current 3
.It unpost_menu
.Xr menu_post 3
.El
.Sh RETURN VALUES
Any function returning a string pointer will return NULL if an error
occurs.
Functions returning an integer will return one of the following:
.Pp
.Bl -tag -width E_UNKNOWN_COMMAND -compact
.It Er E_OK
The function was successful.
.It Er E_SYSTEM_ERROR
There was a system error during the call.
.It Er E_BAD_ARGUMENT
One or more of the arguments passed to the function was incorrect.
.It Er E_POSTED
The menu is already posted.
.It Er E_CONNECTED
An item was already connected to a menu.
.It Er E_BAD_STATE
The function was called from within an initialization or termination
routine.
.It Er E_NO_ROOM
The menu does not fit within the subwindow.
.It Er E_NOT_POSTED
The menu is not posted.
.It Er E_UNKNOWN_COMMAND
The menu driver does not recognize the request passed to it.
.It Er E_NO_MATCH
The character search failed to find a match.
.It Er E_NOT_SELECTABLE
The item could not be selected.
.It Er E_NOT_CONNECTED
The item is not connected to a menu.
.It Er E_REQUEST_DENIED
The menu driver could not process the request.
.El
.Sh SEE ALSO
.Xr curses 3 ,
.Xr menu_attributes 3 ,
.Xr menu_cursor 3 ,
.Xr menu_driver 3 ,
.Xr menu_format 3 ,
.Xr menu_hook 3 ,
.Xr menu_item_current 3 ,
.Xr menu_item_name 3 ,
.Xr menu_item_new 3 ,
.Xr menu_item_opts 3 ,
.Xr menu_item_userptr 3 ,
.Xr menu_item_value 3 ,
.Xr menu_item_visible 3 ,
.Xr menu_items 3 ,
.Xr menu_mark 3 ,
.Xr menu_new 3 ,
.Xr menu_opts 3 ,
.Xr menu_pattern 3 ,
.Xr menu_post 3 ,
.Xr menu_userptr 3 ,
.Xr menu_win 3
.Sh NOTES
This implementation of the menus library does depart in behaviour
subtly from the original AT \*[Am] T implementation.
Some of the more notable departures are:
.Pp
.Bl -tag -width "item marking" -compact
.It unmark
The original implementation did not have a marker for an unmarked field
the mark was only displayed next to a field when it had been marked using
the REQ_TOGGLE_ITEM.
In this implementation a separate marker can be used
to indicate an unmarked item.
This can be set using set_menu_unmark function.
There is no requirement for the mark and unmark strings to be the same
length.
Room will be left for the longest of the two.
The unmark string
is optional, if it is not set then menus defaults to the old behaviour.
.It item marking
In the original implementation the current item was considered selected
and hence had the mark string displayed next to it.
This implementation does not do this because the Author considers the
effect too confusing.
Especially in the case of a multiple selection menu because there was no
way to tell if the current item is selected or not without shifting off
of it.
Since the current item is displayed using the foreground attribute it was
deemed unnecessary to also display the mark string against the current item.
.El
.Pp
The option O_RADIO and the function
.Fn item_selected
are
.Nx
extensions and must not be used in portable code.

107
lib/libmenu/post.c Normal file
View file

@ -0,0 +1,107 @@
/* $NetBSD: post.c,v 1.12 2003/04/19 12:52:39 blymn Exp $ */
/*-
* Copyright (c) 1998-1999 Brett Lymn (blymn@baea.com.au, brett_lymn@yahoo.com.au)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: post.c,v 1.12 2003/04/19 12:52:39 blymn Exp $");
#include <menu.h>
#include <stdlib.h>
#include "internals.h"
/*
* Post the menu to the screen. Call any defined init routines and then
* draw the menu on the screen.
*/
int
post_menu(MENU *menu)
{
int maxx, maxy, i;
if (menu == NULL)
return E_BAD_ARGUMENT;
if (menu->posted == 1)
return E_POSTED;
if (menu->in_init == 1)
return E_BAD_STATE;
if (menu->items == NULL)
return E_NOT_CONNECTED;
if (*menu->items == NULL)
return E_NOT_CONNECTED;
menu->in_init = 1;
if (menu->menu_init != NULL)
menu->menu_init(menu);
if (menu->item_init != NULL)
menu->item_init(menu);
menu->in_init = 0;
getmaxyx(menu->scrwin, maxy, maxx);
if ((maxx == ERR) || (maxy == ERR)) return E_SYSTEM_ERROR;
if ((menu->cols * menu->max_item_width + menu->cols - 1) > maxx)
return E_NO_ROOM;
if ((menu->opts & O_RADIO) != O_RADIO) {
for (i = 0; i < menu->item_count; i++) {
menu->items[i]->selected = 0;
}
}
menu->posted = 1;
return _menui_draw_menu(menu);
}
/*
* Unpost the menu. Call any defined termination routines and remove the
* menu from the screen.
*/
int
unpost_menu(MENU *menu)
{
if (menu == NULL)
return E_BAD_ARGUMENT;
if (menu->posted != 1)
return E_NOT_POSTED;
if (menu->in_init == 1)
return E_BAD_STATE;
if (menu->item_term != NULL)
menu->item_term(menu);
if (menu->menu_term != NULL)
menu->menu_term(menu);
menu->posted = 0;
werase(menu->scrwin);
wrefresh(menu->scrwin);
return E_OK;
}

View file

@ -0,0 +1,5 @@
# $NetBSD: shlib_version,v 1.11 2009/01/11 03:07:48 christos Exp $
# Remember to update distrib/sets/lists/base/shl.* when changing
#
major=6
minor=0

91
lib/libmenu/userptr.c Normal file
View file

@ -0,0 +1,91 @@
/* $NetBSD: userptr.c,v 1.9 2003/03/09 01:08:48 lukem Exp $ */
/*-
* Copyright (c) 1998-1999 Brett Lymn (blymn@baea.com.au, brett_lymn@yahoo.com.au)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: userptr.c,v 1.9 2003/03/09 01:08:48 lukem Exp $");
#include <menu.h>
#include <stdlib.h>
#include <string.h>
/* the following is defined in menu.c */
extern MENU _menui_default_menu;
/* the following is defined in item.c */
extern ITEM _menui_default_item;
/*
* Set the item user pointer data
*/
int
set_item_userptr(ITEM *param_item, char *userptr)
{
ITEM *item = (param_item != NULL) ? param_item : &_menui_default_item;
item->userptr = userptr;
return E_OK;
}
/*
* Return the item user pointer
*/
char *
item_userptr(ITEM *item)
{
if (item == NULL)
return _menui_default_item.userptr;
else
return item->userptr;
}
/*
* Return the user pointer for the given menu
*/
char *
menu_userptr(MENU *menu)
{
if (menu == NULL)
return _menui_default_menu.userptr;
else
return menu->userptr;
}
/*
* Set the user pointer for the given menu
*/
int
set_menu_userptr(MENU *param_menu, char *userptr)
{
MENU *menu = (param_menu != NULL) ? param_menu : &_menui_default_menu;
menu->userptr = userptr;
return E_OK;
}

View file

@ -83,6 +83,7 @@
2012/10/17 12:00:00,lib/libcurses 2012/10/17 12:00:00,lib/libcurses
2012/10/17 12:00:00,lib/libedit 2012/10/17 12:00:00,lib/libedit
2012/10/17 12:00:00,lib/libm 2012/10/17 12:00:00,lib/libm
2012/10/17 12:00:00,lib/libmenu
2011/09/30 22:08:19,lib/libprop 2011/09/30 22:08:19,lib/libprop
2012/10/17 12:00:00,lib/libpuffs 2012/10/17 12:00:00,lib/libpuffs
2012/10/17 12:00:00,lib/librmt 2012/10/17 12:00:00,lib/librmt