Add the instr and inchstr families of functions.
This commit is contained in:
parent
ad6af0a61b
commit
e6fa1cbf79
@ -1,4 +1,4 @@
|
||||
# $NetBSD: Makefile,v 1.30 2000/08/13 03:20:07 itojun Exp $
|
||||
# $NetBSD: Makefile,v 1.31 2001/01/01 10:36:12 simonb Exp $
|
||||
# @(#)Makefile 8.2 (Berkeley) 1/2/94
|
||||
|
||||
CPPFLAGS+=#-DTFILE=\"/dev/ttyp0\"
|
||||
@ -8,22 +8,23 @@ CPPFLAGS+=-D_CURSES_PRIVATE -I${.CURDIR} -I${.CURDIR}/../libterm
|
||||
#CPPFLAGS+=-DDEBUG
|
||||
#.endif
|
||||
LIB= curses
|
||||
SRCS= addbytes.c addch.c addnstr.c acs.c attributes.c background.c bell.c \
|
||||
SRCS= acs.c addbytes.c addch.c addnstr.c attributes.c background.c bell.c \
|
||||
border.c box.c clear.c clearok.c clrtobot.c clrtoeol.c color.c \
|
||||
copywin.c cr_put.c ctrace.c cur_hash.c curses.c curs_set.c delch.c \
|
||||
deleteln.c delwin.c erase.c flushok.c fullname.c getch.c getstr.c \
|
||||
getyx.c id_subwins.c idlok.c inch.c initscr.c insch.c insdelln.c \
|
||||
insertln.c keypad.c leaveok.c line.c longname.c meta.c move.c mvwin.c \
|
||||
newwin.c nodelay.c notimeout.c overlay.c overwrite.c pause.c printw.c \
|
||||
putchar.c refresh.c scanw.c scroll.c scrollok.c setterm.c standout.c \
|
||||
timeout.c toucholap.c touchwin.c tscroll.c tstp.c tty.c unctrl.c \
|
||||
underscore.c
|
||||
copywin.c cr_put.c ctrace.c cur_hash.c curs_set.c curses.c delch.c \
|
||||
deleteln.c delwin.c erase.c flushok.c fullname.c getch.c getstr.c \
|
||||
getyx.c id_subwins.c idlok.c inch.c inchstr.c initscr.c insch.c \
|
||||
insdelln.c insertln.c instr.c keypad.c leaveok.c line.c longname.c \
|
||||
meta.c move.c mvwin.c newwin.c nodelay.c notimeout.c overlay.c \
|
||||
overwrite.c pause.c printw.c putchar.c refresh.c scanw.c scroll.c \
|
||||
scrollok.c setterm.c standout.c timeout.c toucholap.c touchwin.c \
|
||||
tscroll.c tstp.c tty.c unctrl.c underscore.c
|
||||
|
||||
MAN= curses.3
|
||||
INCS= curses.h unctrl.h
|
||||
INCSDIR=/usr/include
|
||||
|
||||
CPPFLAGS+=-DCM_N -DCM_GT -DCM_B -DCM_D
|
||||
SRCS+= termcap.c tgoto.c tputs.c
|
||||
SRCS+= termcap.c tgoto.c tputs.c
|
||||
.PATH: ${.CURDIR}/../libterm
|
||||
|
||||
.if make(install)
|
||||
|
@ -559,6 +559,30 @@ when updating the window.
|
||||
Returns the character at the current position on the given window.
|
||||
This does not make any changes to the window.
|
||||
.Ds
|
||||
.Fn inchnstr "chtype *chstr" "int n"
|
||||
.De
|
||||
Get an array of at most
|
||||
.Vn n
|
||||
characters and renditions starting at the current cursor position and
|
||||
ending at the end of the line and put it in the location pointed to by
|
||||
.Vn chstr .
|
||||
.Ds
|
||||
.Fn inchstr "chtype *chstr"
|
||||
.De
|
||||
Get an array of characters and renditions starting at the current cursor
|
||||
position and ending at the end of the line and put it in the location
|
||||
pointed to by
|
||||
.Vn chstr ,
|
||||
which is assumed to be large enough to handle it.
|
||||
.Ds
|
||||
.Fn innstr "char *str" "int n"
|
||||
.De
|
||||
Get a string of at most
|
||||
.Vn n
|
||||
characters starting at the current cursor position and ending at the end
|
||||
of the line and put it in the location pointed to by
|
||||
.Vn str .
|
||||
.Ds
|
||||
.Fn init_color "short color" "short red" "short green" "short blue"
|
||||
.De
|
||||
Set the red, green and blue values of color
|
||||
@ -634,6 +658,13 @@ and the bottom line will disappear.
|
||||
The current line will become blank,
|
||||
and the current \*y will remain unchanged.
|
||||
.Ds
|
||||
.Fn instr "char *str"
|
||||
.De
|
||||
Get an string starting at the current cursor position and ending at the
|
||||
end of the line and put it in the location pointed to by
|
||||
.Vn str ,
|
||||
which is assumed to be large enough to handle it.
|
||||
.Ds
|
||||
.Fn is_linetouched "WINDOW *win" "int line"
|
||||
.De
|
||||
Returns TRUE if
|
||||
@ -1310,10 +1341,10 @@ specification of a window, rather than the use of the default
|
||||
.Vn stdscr.\fP
|
||||
.Ds
|
||||
.Fn waddch "WINDOW *win" "chtype ch"
|
||||
.Fn waddstr "WINDOW *win" "char *str"
|
||||
.Fn waddnstr "WINDOW *win" "char *str" "int len"
|
||||
.Fn wattron "WINDOW *win" "int attr"
|
||||
.Fn waddstr "WINDOW *win" "char *str"
|
||||
.Fn wattroff "WINDOW *win" "int attr"
|
||||
.Fn wattron "WINDOW *win" "int attr"
|
||||
.Fn wattrset "WINDOW *win" "int attr"
|
||||
.Fn wbkgd "WINDOW *win" "chtype ch"
|
||||
.Fn wbkgdset "WINDOW *win" "chtype ch"
|
||||
@ -1328,9 +1359,13 @@ specification of a window, rather than the use of the default
|
||||
.Fn wgetstr "WINDOW *win" "char *str"
|
||||
.Fn whline "WINDOW *win" "chtype ch" "int count"
|
||||
.Fn winch "WINDOW *win" \(dg
|
||||
.Fn winchnstr "WINDOW *win" "chtype *chstr" "int n"
|
||||
.Fn winchstr "WINDOW *win" "chtype *chstr"
|
||||
.Fn winnstr "WINDOW *win" "char *str" "int n"
|
||||
.Fn winsch "WINDOW *win" "char c"
|
||||
.Fn winsdelln "WINDOW *win" "int n"
|
||||
.Fn winsertln "WINDOW *win"
|
||||
.Fn winstr "WINDOW *win" "char *str"
|
||||
.Fn wmove "WINDOW *win" "int y" int x"
|
||||
.Fn wprintw "WINDOW *win" "char *fmt" "..."
|
||||
.Fn wrefresh "WINDOW *win"
|
||||
@ -1342,4 +1377,5 @@ specification of a window, rather than the use of the default
|
||||
.Fn wunderend "WINDOW *win"
|
||||
.Fn wunderscore "WINDOW *win"
|
||||
.Fn wvline "WINDOW *win" "chtype ch" "int count"
|
||||
|
||||
.Dg
|
||||
|
@ -1,4 +1,4 @@
|
||||
.\" $NetBSD: curses.3,v 1.29 2000/06/04 21:07:22 simonb Exp $
|
||||
.\" $NetBSD: curses.3,v 1.30 2001/01/01 10:36:12 simonb Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1985, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
@ -106,7 +106,7 @@ and applies this rendition to
|
||||
.It clrtoeol() clear to end of line on
|
||||
.Em stdscr
|
||||
.It color_content(c, r, g, b) get rgb values of color
|
||||
.It copywin(srcwin,dstwin,sminrow,smincol,dminrow,dmincol,dmaxrow,dmaxcol,overlay)
|
||||
.It copywin(srcwin, dstwin, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol, overlay)
|
||||
Copy rectangle from
|
||||
.Em srcwin
|
||||
to
|
||||
@ -169,6 +169,12 @@ relative to
|
||||
.It idlok(win,boolf) set insert/deleteln flags for
|
||||
.Em win
|
||||
.It inch() get char at current (y,x) co-ordinates
|
||||
.It inchnstr(chstr, n) get an array of characters from
|
||||
.Em stdscr
|
||||
.It inchstr(chstr) get an array of characters from
|
||||
.Em stdscr
|
||||
.It innstr(str, n) get a string of characters from
|
||||
.Em stdscr
|
||||
.It init_color(c, r, g, b) set rgb values of color
|
||||
.It init_pair(p, f, b) set foreground and background colors of pair
|
||||
.It initscr() initialize screens
|
||||
@ -176,6 +182,8 @@ relative to
|
||||
.It insdelln(n) insert/delete n lines on
|
||||
.Em stdstr
|
||||
.It insertln() insert a line
|
||||
.It instr(str) get a string of characters from
|
||||
.Em stdscr
|
||||
.It intrflush(win,boolf) set flush on interrupt terminal mode
|
||||
.It is_linetouched(win, line) check if line has been modified since
|
||||
last refresh.
|
||||
@ -331,12 +339,20 @@ on window
|
||||
.Em win .
|
||||
.It winch(win) get char at current (y,x) in
|
||||
.Em win
|
||||
.It winchnstr(win, chstr, n) get an array of characters from
|
||||
.Em win
|
||||
.It winchstr(win, chstr) get an array of characters from
|
||||
.Em win
|
||||
.It winnstr(win, str, n) get a string of characters from
|
||||
.Em win
|
||||
.It winsch(win,c) insert char into
|
||||
.Em win
|
||||
.It winsdelln(win,n) insert/delete n lines on
|
||||
.Em win
|
||||
.It winsertln(win) insert line into
|
||||
.Em win
|
||||
.It winstr(win,str) get a string of characters from
|
||||
.Em win
|
||||
.It wmove(win,y,x) set current (y,x) co-ordinates on
|
||||
.Em win
|
||||
.It wnoutrefresh(win) add
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: curses.h,v 1.51 2000/12/31 12:33:02 jdc Exp $ */
|
||||
/* $NetBSD: curses.h,v 1.52 2001/01/01 10:36:12 simonb Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
@ -463,9 +463,13 @@ extern char *ttytype; /* Full name of current terminal. */
|
||||
#define getch() wgetch(stdscr)
|
||||
#define getstr(s) wgetstr(stdscr, s)
|
||||
#define inch() winch(stdscr)
|
||||
#define inchnstr(c) winchnstr(stdscr, c)
|
||||
#define inchstr(c) winchstr(stdscr, c)
|
||||
#define innstr(s, n) winnstr(stdscr, s, n)
|
||||
#define insch(ch) winsch(stdscr, ch)
|
||||
#define insdelln(n) winsdelln(stdscr, n)
|
||||
#define insertln() winsertln(stdscr)
|
||||
#define instr(s) winstr(stdscr, s)
|
||||
#define move(y, x) wmove(stdscr, y, x)
|
||||
#define refresh() wrefresh(stdscr)
|
||||
#define scrl(n) wscrl(stdscr, n)
|
||||
@ -489,7 +493,11 @@ extern char *ttytype; /* Full name of current terminal. */
|
||||
#define mvgetch(y, x) mvwgetch(stdscr, y, x)
|
||||
#define mvgetstr(y, x, s) mvwgetstr(stdscr, y, x, s)
|
||||
#define mvinch(y, x) mvwinch(stdscr, y, x)
|
||||
#define mvinchnstr(y, x, c, n) mvwinchnstr(stdscr, y, x, c, n)
|
||||
#define mvinchstr(y, x, c) mvwinchstr(stdscr, y, x, c)
|
||||
#define mvinnstr(y, x, s, n) mvwinnstr(stdscr, y, x, s, n)
|
||||
#define mvinsch(y, x, c) mvwinsch(stdscr, y, x, c)
|
||||
#define mvinstr(y, x, s) mvwinstr(stdscr, y, x, s)
|
||||
#define mvwaddbytes(w, y, x, s, n) \
|
||||
(wmove(w, y, x) == ERR ? ERR : __waddbytes(w, s, n, 0))
|
||||
#define mvwaddch(w, y, x, ch) \
|
||||
@ -506,8 +514,16 @@ extern char *ttytype; /* Full name of current terminal. */
|
||||
(wmove(w, y, x) == ERR ? ERR : wgetstr(w, s))
|
||||
#define mvwinch(w, y, x) \
|
||||
(wmove(w, y, x) == ERR ? ERR : winch(w))
|
||||
#define mvwinchnstr(w, y, x, c, n) \
|
||||
(wmove(w, y, x) == ERR ? ERR : winchnstr(w, c, n))
|
||||
#define mvwinchstr(w, y, x, s) \
|
||||
(wmove(w, y, x) == ERR ? ERR : winchstr(w, c))
|
||||
#define mvwinnstr(w, y, x, s, n) \
|
||||
(wmove(w, y, x) == ERR ? ERR : winnstr(w, s, n))
|
||||
#define mvwinsch(w, y, x, c) \
|
||||
(wmove(w, y, x) == ERR ? ERR : winsch(w, c))
|
||||
#define mvwinstr(w, y, x, s) \
|
||||
(wmove(w, y, x) == ERR ? ERR : winstr(w, s))
|
||||
|
||||
#define getyx(w, y, x) (y) = getcury(w), (x) = getcurx(w)
|
||||
#define getbegyx(w, y, x) (y) = getbegy(w), (x) = getbegx(w)
|
||||
@ -533,9 +549,13 @@ int erase(void);
|
||||
int getch(void);
|
||||
int getstr(char *);
|
||||
chtype inch(void);
|
||||
int inchnstr(chtype *, int);
|
||||
int inchstr(chtype *);
|
||||
int innstr(char *, int);
|
||||
int insch(chtype);
|
||||
int insdelln(int);
|
||||
int insertln(void);
|
||||
int instr(char *);
|
||||
int move(int, int);
|
||||
int refresh(void);
|
||||
int scrl(int);
|
||||
@ -559,7 +579,11 @@ int mvdelch(int, int);
|
||||
int mvgetch(int, int);
|
||||
int mvgetstr(int, int, char *);
|
||||
chtype mvinch(int, int);
|
||||
int mvinchnstr(int, int, chtype *, int);
|
||||
int mvinchstr(int, int, chtype *);
|
||||
int mvinnstr(int, int, char *, int);
|
||||
int mvinsch(int, int, chtype);
|
||||
int mvinstr(int, int, char *);
|
||||
|
||||
int mvwaddbytes(WINDOW *, int, int, const char *, int);
|
||||
int mvwaddch(WINDOW *, int, int, chtype);
|
||||
@ -636,6 +660,10 @@ int mvvline(int, int, chtype, int);
|
||||
int mvwhline(WINDOW *, int, int, chtype, int);
|
||||
int mvwvline(WINDOW *, int, int, chtype, int);
|
||||
int mvwin(WINDOW *, int, int);
|
||||
int mvwinchnstr(WINDOW *, int, int, chtype *, int);
|
||||
int mvwinchstr(WINDOW *, int, int, chtype *);
|
||||
int mvwinnstr(WINDOW *, int, int, char *, int);
|
||||
int mvwinstr(WINDOW *, int, int, char *);
|
||||
int mvwprintw(WINDOW *, int, int, const char *, ...)
|
||||
__attribute__((__format__(__printf__, 4, 5)));
|
||||
int mvwscanw(WINDOW *, int, int, const char *, ...)
|
||||
@ -695,9 +723,13 @@ int wgetch(WINDOW *);
|
||||
int wgetstr(WINDOW *, char *);
|
||||
int whline(WINDOW *, chtype, int);
|
||||
chtype winch(WINDOW *);
|
||||
int winchnstr(WINDOW *, chtype *, int);
|
||||
int winchstr(WINDOW *, chtype *);
|
||||
int winnstr(WINDOW *, char *, int);
|
||||
int winsch(WINDOW *, chtype);
|
||||
int winsdelln(WINDOW *, int);
|
||||
int winsertln(WINDOW *);
|
||||
int winstr(WINDOW *, char *);
|
||||
int wmove(WINDOW *, int, int);
|
||||
int wnoutrefresh(WINDOW *);
|
||||
int wprintw(WINDOW *, const char *, ...)
|
||||
|
154
lib/libcurses/inchstr.c
Normal file
154
lib/libcurses/inchstr.c
Normal file
@ -0,0 +1,154 @@
|
||||
/* $NetBSD: inchstr.c,v 1.1 2001/01/01 10:36:12 simonb Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 2001 Wasabi Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Written by Simon Burge for Wasabi Systems, Inc.
|
||||
*
|
||||
* 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. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed for the NetBSD Project by
|
||||
* Wasabi Systems, Inc.
|
||||
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
|
||||
* or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC. 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>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: inchstr.c,v 1.1 2001/01/01 10:36:12 simonb Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include "curses.h"
|
||||
#include "curses_private.h"
|
||||
|
||||
#ifndef _CURSES_USE_MACROS
|
||||
|
||||
/*
|
||||
* inchstr, inchnstr --
|
||||
* Return an array of characters at cursor position from stdscr.
|
||||
*/
|
||||
__warn_references(inchstr,
|
||||
"warning: this program uses inchstr(), which is unsafe.")
|
||||
int
|
||||
inchstr(chtype *chstr)
|
||||
{
|
||||
return winchstr(stdscr, chstr);
|
||||
}
|
||||
|
||||
int
|
||||
inchnstr(chtype *chstr, int n)
|
||||
{
|
||||
return winchnstr(stdscr, chstr, n);
|
||||
}
|
||||
|
||||
/*
|
||||
* mvinchstr, mvinchnstr --
|
||||
* Return an array of characters at position (y, x) from stdscr.
|
||||
*/
|
||||
__warn_references(mvinchstr,
|
||||
"warning: this program uses mvinchstr(), which is unsafe.")
|
||||
int
|
||||
mvinchstr(int y, int x, chtype *chstr)
|
||||
{
|
||||
return mvwinchstr(stdscr, y, x, chstr);
|
||||
}
|
||||
|
||||
int
|
||||
mvinchnstr(int y, int x, chtype *chstr, int n)
|
||||
{
|
||||
return mvwinchnstr(stdscr, y, x, chstr, n);
|
||||
}
|
||||
|
||||
/*
|
||||
* mvwinchstr, mvwinchnstr --
|
||||
* Return an array characters at position (y, x) from the given window.
|
||||
*/
|
||||
__warn_references(mvwinchstr,
|
||||
"warning: this program uses mvwinchstr(), which is unsafe.")
|
||||
int
|
||||
mvwinchstr(WINDOW *win, int y, int x, chtype *chstr)
|
||||
{
|
||||
if (wmove(win, y, x) == ERR)
|
||||
return ERR;
|
||||
|
||||
return winchstr(win, chstr);
|
||||
}
|
||||
|
||||
int
|
||||
mvwinchnstr(WINDOW *win, int y, int x, chtype *chstr, int n)
|
||||
{
|
||||
if (wmove(win, y, x) == ERR)
|
||||
return ERR;
|
||||
|
||||
return winchnstr(win, chstr, n);
|
||||
}
|
||||
|
||||
#endif /* _CURSES_USE_MACROS */
|
||||
|
||||
/*
|
||||
* winchstr, winchnstr --
|
||||
* Return an array of characters at cursor position.
|
||||
*/
|
||||
__warn_references(winchstr,
|
||||
"warning: this program uses winchstr(), which is unsafe.")
|
||||
int
|
||||
winchstr(WINDOW *win, chtype *chstr)
|
||||
{
|
||||
|
||||
return winchnstr(win, chstr, -1);
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX: This should go in a manpage!
|
||||
* - SUSv2/xcurses doesn't document whether the trailing 0 is included
|
||||
* in the length count or not. For safety's sake it _is_ included.
|
||||
*/
|
||||
int
|
||||
winchnstr(WINDOW *win, chtype *chstr, int n)
|
||||
{
|
||||
__LDATA *end, *start;
|
||||
int epos;
|
||||
|
||||
if (chstr == NULL)
|
||||
return ERR;
|
||||
|
||||
start = &win->lines[win->cury]->line[win->curx];
|
||||
/* (n - 1) to leave room for the trailing 0 element */
|
||||
if (n < 0 || (n - 1) > win->maxx - win->curx - 1)
|
||||
epos = win->maxx - 1;
|
||||
else
|
||||
/* extra -1 for trailing NUL */
|
||||
epos = win->curx + n -1 - 1;
|
||||
end = &win->lines[win->cury]->line[epos];
|
||||
|
||||
while (start <= end) {
|
||||
*chstr = start->ch;
|
||||
chstr++;
|
||||
start++;
|
||||
}
|
||||
*chstr = 0;
|
||||
|
||||
return OK;
|
||||
}
|
168
lib/libcurses/instr.c
Normal file
168
lib/libcurses/instr.c
Normal file
@ -0,0 +1,168 @@
|
||||
/* $NetBSD: instr.c,v 1.1 2001/01/01 10:36:12 simonb Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 2001 Wasabi Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Written by Simon Burge for Wasabi Systems, Inc.
|
||||
*
|
||||
* 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. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed for the NetBSD Project by
|
||||
* Wasabi Systems, Inc.
|
||||
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
|
||||
* or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC. 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>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: instr.c,v 1.1 2001/01/01 10:36:12 simonb Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include "curses.h"
|
||||
#include "curses_private.h"
|
||||
|
||||
#ifndef _CURSES_USE_MACROS
|
||||
|
||||
/*
|
||||
* instr, innstr --
|
||||
* Return a string of characters at cursor position from stdscr.
|
||||
*/
|
||||
__warn_references(instr,
|
||||
"warning: this program uses instr(), which is unsafe.")
|
||||
int
|
||||
instr(char *str)
|
||||
{
|
||||
return winstr(stdscr, str);
|
||||
}
|
||||
|
||||
int
|
||||
innstr(char *str, int n)
|
||||
{
|
||||
return winnstr(stdscr, str, n);
|
||||
}
|
||||
|
||||
/*
|
||||
* mvinstr, mvinnstr --
|
||||
* Return a string of characters at position (y, x) from stdscr.
|
||||
* XXX: should be multi-byte characters for SUSv2.
|
||||
*/
|
||||
__warn_references(mvinstr,
|
||||
"warning: this program uses mvinstr(), which is unsafe.")
|
||||
int
|
||||
mvinstr(int y, int x, char *str)
|
||||
{
|
||||
return mvwinstr(stdscr, y, x, str);
|
||||
}
|
||||
|
||||
int
|
||||
mvinnstr(int y, int x, char *str, int n)
|
||||
{
|
||||
return mvwinnstr(stdscr, y, x, str, n);
|
||||
}
|
||||
|
||||
/*
|
||||
* mvwinstr, mvwinnstr --
|
||||
* Return an array characters at position (y, x) from the given window.
|
||||
* XXX: should be multi-byte characters for SUSv2.
|
||||
*/
|
||||
__warn_references(mvwinstr,
|
||||
"warning: this program uses mvwinstr(), which is unsafe.")
|
||||
int
|
||||
mvwinstr(WINDOW *win, int y, int x, char *str)
|
||||
{
|
||||
if (wmove(win, y, x) == ERR)
|
||||
return ERR;
|
||||
|
||||
return winstr(win, str);
|
||||
}
|
||||
|
||||
int
|
||||
mvwinnstr(WINDOW *win, int y, int x, char *str, int n)
|
||||
{
|
||||
if (wmove(win, y, x) == ERR)
|
||||
return ERR;
|
||||
|
||||
return winnstr(win, str, n);
|
||||
}
|
||||
|
||||
#endif /* _CURSES_USE_MACROS */
|
||||
|
||||
/*
|
||||
* winstr, winnstr --
|
||||
* Return a string of characters at cursor position.
|
||||
* XXX: should be multi-byte characters for SUSv2.
|
||||
*/
|
||||
__warn_references(winstr,
|
||||
"warning: this program uses winstr(), which is unsafe.")
|
||||
int
|
||||
winstr(WINDOW *win, char *str)
|
||||
{
|
||||
|
||||
return winnstr(win, str, -1);
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX: This should go in a manpage!
|
||||
* - winnstr() returns the number of characters copied only of if it is
|
||||
* called with n >= 0 (ie, as inchnstr(), mvinchnstr(), mvwinchnstr()
|
||||
* or winchnstr()). If N < 0, it returns `OK'.
|
||||
* - SUSv2/xcurses doesn't document whether the trailing NUL is included
|
||||
* in the length count or not. For safety's sake it _is_ included.
|
||||
* - This implementation does not (yet) support multi-byte characters
|
||||
* strings.
|
||||
*/
|
||||
int
|
||||
winnstr(WINDOW *win, char *str, int n)
|
||||
{
|
||||
__LDATA *end, *start;
|
||||
int epos;
|
||||
|
||||
if (str == NULL)
|
||||
return ERR;
|
||||
|
||||
start = &win->lines[win->cury]->line[win->curx];
|
||||
/* (n - 1) to leave room for the trailing NUL */
|
||||
if (n < 0 || (n - 1) > win->maxx - win->curx - 1) {
|
||||
epos = win->maxx - 1;
|
||||
n = win->maxx - win->curx;
|
||||
} else {
|
||||
/* extra -1 for trailing NUL */
|
||||
epos = win->curx + n - 1 - 1;
|
||||
n--;
|
||||
}
|
||||
end = &win->lines[win->cury]->line[epos];
|
||||
|
||||
while (start <= end) {
|
||||
*str = start->ch & __CHARTEXT;
|
||||
str++;
|
||||
start++;
|
||||
}
|
||||
*str = '\0';
|
||||
|
||||
if (n < 0)
|
||||
return OK;
|
||||
else
|
||||
return n;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
# $NetBSD: shlib_version,v 1.18 2000/12/31 12:33:02 jdc Exp $
|
||||
# $NetBSD: shlib_version,v 1.19 2001/01/01 10:36:12 simonb Exp $
|
||||
# Remember to update distrib/sets/lists/base/shl.* when changing
|
||||
#
|
||||
major=4
|
||||
minor=0
|
||||
minor=1
|
||||
|
Loading…
x
Reference in New Issue
Block a user