2017-11-17 20:12:59 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* apps/graphics/pdcurses/pdc_instr.c
|
|
|
|
* Public Domain Curses
|
|
|
|
* RCSID("$Id: instr.c,v 1.44 2008/07/13 16:08:18 wmcbrine Exp $")
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
|
|
|
* Adapted by: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
*
|
|
|
|
* Adapted from the original public domain pdcurses by Gregory Nutt and
|
|
|
|
* released as part of NuttX under the 3-clause BSD license:
|
|
|
|
*
|
|
|
|
* 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. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "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
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Name: instr
|
|
|
|
*
|
|
|
|
* Synopsis:
|
|
|
|
* int instr(char *str);
|
|
|
|
* int innstr(char *str, int n);
|
|
|
|
* int winstr(WINDOW *win, char *str);
|
|
|
|
* int winnstr(WINDOW *win, char *str, int n);
|
|
|
|
* int mvinstr(int y, int x, char *str);
|
|
|
|
* int mvinnstr(int y, int x, char *str, int n);
|
|
|
|
* int mvwinstr(WINDOW *win, int y, int x, char *str);
|
|
|
|
* int mvwinnstr(WINDOW *win, int y, int x, char *str, int n);
|
|
|
|
*
|
|
|
|
* int inwstr(wchar_t *wstr);
|
|
|
|
* int innwstr(wchar_t *wstr, int n);
|
|
|
|
* int winwstr(WINDOW *win, wchar_t *wstr);
|
|
|
|
* int winnwstr(WINDOW *win, wchar_t *wstr, int n);
|
|
|
|
* int mvinwstr(int y, int x, wchar_t *wstr);
|
|
|
|
* int mvinnwstr(int y, int x, wchar_t *wstr, int n);
|
|
|
|
* int mvwinwstr(WINDOW *win, int y, int x, wchar_t *wstr);
|
|
|
|
* int mvwinnwstr(WINDOW *win, int y, int x, wchar_t *wstr, int n);
|
|
|
|
*
|
|
|
|
* Description:
|
2017-11-17 20:23:02 +01:00
|
|
|
* These functions take characters (or wide characters) from the
|
|
|
|
* current or specified position in the window, and return them as
|
|
|
|
* a string in str (or wstr). Attributes are ignored. The functions
|
|
|
|
* with n as the last argument return a string at most n characters
|
2017-11-17 20:12:59 +01:00
|
|
|
* long.
|
|
|
|
*
|
|
|
|
* Return Value:
|
2017-11-17 20:23:02 +01:00
|
|
|
* Upon successful completion, innstr(), mvinnstr(), mvwinnstr()
|
2017-11-17 20:12:59 +01:00
|
|
|
* and winnstr() return the number of characters actually read into
|
2017-11-17 20:23:02 +01:00
|
|
|
* the string; instr(), mvinstr(), mvwinstr() and winstr() return
|
2017-11-17 20:12:59 +01:00
|
|
|
* OK. Otherwise, all these functions return ERR.
|
|
|
|
*
|
|
|
|
* Portability X/Open BSD SYS V
|
|
|
|
* instr Y - 4.0
|
|
|
|
* winstr Y - 4.0
|
|
|
|
* mvinstr Y - 4.0
|
|
|
|
* mvwinstr Y - 4.0
|
|
|
|
* innstr Y - 4.0
|
|
|
|
* winnstr Y - 4.0
|
|
|
|
* mvinnstr Y - 4.0
|
|
|
|
* mvwinnstr Y - 4.0
|
|
|
|
* inwstr Y
|
|
|
|
* winwstr Y
|
|
|
|
* mvinwstr Y
|
|
|
|
* mvwinwstr Y
|
|
|
|
* innwstr Y
|
|
|
|
* winnwstr Y
|
|
|
|
* mvinnwstr Y
|
|
|
|
* mvwinnwstr Y
|
|
|
|
*/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "curspriv.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int winnstr(WINDOW *win, char *str, int n)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_PDCURSES_WIDE
|
|
|
|
wchar_t wstr[513];
|
|
|
|
|
|
|
|
if (n < 0 || n > 512)
|
|
|
|
{
|
|
|
|
n = 512;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (winnwstr(win, wstr, n) == ERR)
|
|
|
|
{
|
|
|
|
return ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PDC_wcstombs(str, wstr, n);
|
|
|
|
#else
|
|
|
|
chtype *src;
|
|
|
|
int i;
|
|
|
|
|
2021-12-26 23:10:48 +01:00
|
|
|
PDC_LOG(("winnstr() - called: n %d\n", n));
|
2017-11-17 20:12:59 +01:00
|
|
|
|
|
|
|
if (!win || !str)
|
|
|
|
{
|
|
|
|
return ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n < 0 || (win->_curx + n) > win->_maxx)
|
|
|
|
{
|
|
|
|
n = win->_maxx - win->_curx;
|
|
|
|
}
|
|
|
|
|
|
|
|
src = win->_y[win->_cury] + win->_curx;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
str[i] = src[i] & A_CHARTEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
str[i] = '\0';
|
|
|
|
return i;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int instr(char *str)
|
|
|
|
{
|
2019-01-05 20:25:12 +01:00
|
|
|
#ifdef CONFIG_PDCURSES_MULTITHREAD
|
|
|
|
FAR struct pdc_context_s *ctx = PDC_ctx();
|
|
|
|
#endif
|
2017-11-17 20:12:59 +01:00
|
|
|
PDC_LOG(("instr() - called: string=\"%s\"\n", str));
|
|
|
|
|
|
|
|
return (ERR == winnstr(stdscr, str, stdscr->_maxx)) ? ERR : OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int winstr(WINDOW *win, char *str)
|
|
|
|
{
|
2021-12-26 23:10:48 +01:00
|
|
|
PDC_LOG(("winstr() - called:\n"));
|
2017-11-17 20:12:59 +01:00
|
|
|
|
|
|
|
return (ERR == winnstr(win, str, win->_maxx)) ? ERR : OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mvinstr(int y, int x, char *str)
|
|
|
|
{
|
2019-01-05 20:25:12 +01:00
|
|
|
#ifdef CONFIG_PDCURSES_MULTITHREAD
|
|
|
|
FAR struct pdc_context_s *ctx = PDC_ctx();
|
|
|
|
#endif
|
2021-12-26 23:10:48 +01:00
|
|
|
PDC_LOG(("mvinstr() - called: y %d x %d\n", y, x));
|
2017-11-17 20:12:59 +01:00
|
|
|
|
|
|
|
if (move(y, x) == ERR)
|
|
|
|
{
|
|
|
|
return ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ERR == winnstr(stdscr, str, stdscr->_maxx)) ? ERR : OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mvwinstr(WINDOW *win, int y, int x, char *str)
|
|
|
|
{
|
2021-12-26 23:10:48 +01:00
|
|
|
PDC_LOG(("mvwinstr() - called: y %d x %d\n", y, x));
|
2017-11-17 20:12:59 +01:00
|
|
|
|
|
|
|
if (wmove(win, y, x) == ERR)
|
|
|
|
{
|
|
|
|
return ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ERR == winnstr(win, str, win->_maxx)) ? ERR : OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int innstr(char *str, int n)
|
|
|
|
{
|
2019-01-05 20:25:12 +01:00
|
|
|
#ifdef CONFIG_PDCURSES_MULTITHREAD
|
|
|
|
FAR struct pdc_context_s *ctx = PDC_ctx();
|
|
|
|
#endif
|
2021-12-26 23:10:48 +01:00
|
|
|
PDC_LOG(("innstr() - called: n %d\n", n));
|
2017-11-17 20:12:59 +01:00
|
|
|
|
|
|
|
return winnstr(stdscr, str, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
int mvinnstr(int y, int x, char *str, int n)
|
|
|
|
{
|
2019-01-05 20:25:12 +01:00
|
|
|
#ifdef CONFIG_PDCURSES_MULTITHREAD
|
|
|
|
FAR struct pdc_context_s *ctx = PDC_ctx();
|
|
|
|
#endif
|
2021-12-26 23:10:48 +01:00
|
|
|
PDC_LOG(("mvinnstr() - called: y %d x %d n %d\n", y, x, n));
|
2017-11-17 20:12:59 +01:00
|
|
|
|
|
|
|
if (move(y, x) == ERR)
|
|
|
|
{
|
|
|
|
return ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return winnstr(stdscr, str, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
int mvwinnstr(WINDOW *win, int y, int x, char *str, int n)
|
|
|
|
{
|
2021-12-26 23:10:48 +01:00
|
|
|
PDC_LOG(("mvwinnstr() - called: y %d x %d n %d\n", y, x, n));
|
2017-11-17 20:12:59 +01:00
|
|
|
|
|
|
|
if (wmove(win, y, x) == ERR)
|
|
|
|
{
|
|
|
|
return ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return winnstr(win, str, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PDCURSES_WIDE
|
2017-11-18 01:23:23 +01:00
|
|
|
int winnwstr(WINDOW *win, wchar_t *wstr, int n)
|
2017-11-17 20:12:59 +01:00
|
|
|
{
|
|
|
|
chtype *src;
|
|
|
|
int i;
|
|
|
|
|
2021-12-26 23:10:48 +01:00
|
|
|
PDC_LOG(("winnstr() - called: n %d\n", n));
|
2017-11-17 20:12:59 +01:00
|
|
|
|
|
|
|
if (!win || !wstr)
|
|
|
|
{
|
|
|
|
return ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n < 0 || (win->_curx + n) > win->_maxx)
|
|
|
|
{
|
|
|
|
n = win->_maxx - win->_curx;
|
|
|
|
}
|
|
|
|
|
|
|
|
src = win->_y[win->_cury] + win->_curx;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
wstr[i] = src[i] & A_CHARTEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
wstr[i] = L'\0';
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2017-11-18 01:23:23 +01:00
|
|
|
int inwstr(wchar_t *wstr)
|
2017-11-17 20:12:59 +01:00
|
|
|
{
|
2019-01-05 20:25:12 +01:00
|
|
|
#ifdef CONFIG_PDCURSES_MULTITHREAD
|
|
|
|
FAR struct pdc_context_s *ctx = PDC_ctx();
|
|
|
|
#endif
|
2017-11-17 20:12:59 +01:00
|
|
|
PDC_LOG(("inwstr() - called\n"));
|
|
|
|
|
|
|
|
return (ERR == winnwstr(stdscr, wstr, stdscr->_maxx)) ? ERR : OK;
|
|
|
|
}
|
|
|
|
|
2017-11-18 01:23:23 +01:00
|
|
|
int winwstr(WINDOW *win, wchar_t *wstr)
|
2017-11-17 20:12:59 +01:00
|
|
|
{
|
|
|
|
PDC_LOG(("winwstr() - called\n"));
|
|
|
|
|
|
|
|
return (ERR == winnwstr(win, wstr, win->_maxx)) ? ERR : OK;
|
|
|
|
}
|
|
|
|
|
2017-11-18 01:23:23 +01:00
|
|
|
int mvinwstr(int y, int x, wchar_t *wstr)
|
2017-11-17 20:12:59 +01:00
|
|
|
{
|
2019-01-05 20:25:12 +01:00
|
|
|
#ifdef CONFIG_PDCURSES_MULTITHREAD
|
|
|
|
FAR struct pdc_context_s *ctx = PDC_ctx();
|
|
|
|
#endif
|
2017-11-17 20:12:59 +01:00
|
|
|
PDC_LOG(("mvinwstr() - called\n"));
|
|
|
|
|
|
|
|
if (move(y, x) == ERR)
|
|
|
|
{
|
|
|
|
return ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ERR == winnwstr(stdscr, wstr, stdscr->_maxx)) ? ERR : OK;
|
|
|
|
}
|
|
|
|
|
2017-11-18 01:23:23 +01:00
|
|
|
int mvwinwstr(WINDOW *win, int y, int x, wchar_t *wstr)
|
2017-11-17 20:12:59 +01:00
|
|
|
{
|
|
|
|
PDC_LOG(("mvwinstr() - called\n"));
|
|
|
|
|
|
|
|
if (wmove(win, y, x) == ERR)
|
|
|
|
{
|
|
|
|
return ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ERR == winnwstr(win, wstr, win->_maxx)) ? ERR : OK;
|
|
|
|
}
|
|
|
|
|
2017-11-18 01:23:23 +01:00
|
|
|
int innwstr(wchar_t *wstr, int n)
|
2017-11-17 20:12:59 +01:00
|
|
|
{
|
2019-01-05 20:25:12 +01:00
|
|
|
#ifdef CONFIG_PDCURSES_MULTITHREAD
|
|
|
|
FAR struct pdc_context_s *ctx = PDC_ctx();
|
|
|
|
#endif
|
2017-11-17 20:12:59 +01:00
|
|
|
PDC_LOG(("innwstr() - called\n"));
|
|
|
|
|
|
|
|
return winnwstr(stdscr, wstr, n);
|
|
|
|
}
|
|
|
|
|
2017-11-18 01:23:23 +01:00
|
|
|
int mvinnwstr(int y, int x, wchar_t *wstr, int n)
|
2017-11-17 20:12:59 +01:00
|
|
|
{
|
2019-01-05 20:25:12 +01:00
|
|
|
#ifdef CONFIG_PDCURSES_MULTITHREAD
|
|
|
|
FAR struct pdc_context_s *ctx = PDC_ctx();
|
|
|
|
#endif
|
2017-11-17 20:12:59 +01:00
|
|
|
PDC_LOG(("mvinnstr() - called\n"));
|
|
|
|
|
|
|
|
if (move(y, x) == ERR)
|
|
|
|
{
|
|
|
|
return ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return winnwstr(stdscr, wstr, n);
|
|
|
|
}
|
|
|
|
|
2017-11-18 01:23:23 +01:00
|
|
|
int mvwinnwstr(WINDOW *win, int y, int x, wchar_t *wstr, int n)
|
2017-11-17 20:12:59 +01:00
|
|
|
{
|
|
|
|
PDC_LOG(("mvwinnwstr() - called\n"));
|
|
|
|
|
|
|
|
if (wmove(win, y, x) == ERR)
|
|
|
|
{
|
|
|
|
return ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return winnwstr(win, wstr, n);
|
|
|
|
}
|
|
|
|
#endif
|