1/* $OpenBSD: lib_scanw.c,v 1.4 2023/10/17 09:52:09 nicm Exp $ */ 2 3/**************************************************************************** 4 * Copyright 2018-2019,2020 Thomas E. Dickey * 5 * Copyright 1998-2009,2011 Free Software Foundation, Inc. * 6 * * 7 * Permission is hereby granted, free of charge, to any person obtaining a * 8 * copy of this software and associated documentation files (the * 9 * "Software"), to deal in the Software without restriction, including * 10 * without limitation the rights to use, copy, modify, merge, publish, * 11 * distribute, distribute with modifications, sublicense, and/or sell * 12 * copies of the Software, and to permit persons to whom the Software is * 13 * furnished to do so, subject to the following conditions: * 14 * * 15 * The above copyright notice and this permission notice shall be included * 16 * in all copies or substantial portions of the Software. * 17 * * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 21 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 24 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 25 * * 26 * Except as contained in this notice, the name(s) of the above copyright * 27 * holders shall not be used in advertising or otherwise to promote the * 28 * sale, use or other dealings in this Software without prior written * 29 * authorization. * 30 ****************************************************************************/ 31 32/**************************************************************************** 33 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * 34 * and: Eric S. Raymond <esr@snark.thyrsus.com> * 35 ****************************************************************************/ 36 37/* 38** lib_scanw.c 39** 40** The routines scanw(), wscanw() and friends. 41** 42*/ 43 44#include <curses.priv.h> 45 46MODULE_ID("$Id: lib_scanw.c,v 1.4 2023/10/17 09:52:09 nicm Exp $") 47 48NCURSES_EXPORT(int) 49vwscanw(WINDOW *win, const char *fmt, va_list argp) 50{ 51 char buf[BUFSIZ]; 52 int code = ERR; 53 54 if (wgetnstr(win, buf, (int) sizeof(buf) - 1) != ERR) { 55 if ((code = vsscanf(buf, fmt, argp)) == EOF) { 56 code = ERR; 57 } 58 } 59 60 return code; 61} 62 63NCURSES_EXPORT(int) 64vw_scanw(WINDOW *win, const char *fmt, va_list argp) 65{ 66 char buf[BUFSIZ]; 67 int code = ERR; 68 69 if (wgetnstr(win, buf, (int) sizeof(buf) - 1) != ERR) { 70 if ((code = vsscanf(buf, fmt, argp)) == EOF) { 71 code = ERR; 72 } 73 } 74 75 return code; 76} 77 78NCURSES_EXPORT(int) 79scanw(const char *fmt, ...) 80{ 81 int code; 82 va_list ap; 83 84 T(("scanw(\"%s\",...) called", fmt)); 85 86 va_start(ap, fmt); 87 code = vw_scanw(stdscr, fmt, ap); 88 va_end(ap); 89 return (code); 90} 91 92NCURSES_EXPORT(int) 93wscanw(WINDOW *win, const char *fmt, ...) 94{ 95 int code; 96 va_list ap; 97 98 T(("wscanw(%p,\"%s\",...) called", (void *) win, fmt)); 99 100 va_start(ap, fmt); 101 code = vw_scanw(win, fmt, ap); 102 va_end(ap); 103 return (code); 104} 105 106NCURSES_EXPORT(int) 107mvscanw(int y, int x, const char *fmt, ...) 108{ 109 int code; 110 va_list ap; 111 112 va_start(ap, fmt); 113 code = (move(y, x) == OK) ? vw_scanw(stdscr, fmt, ap) : ERR; 114 va_end(ap); 115 return (code); 116} 117 118NCURSES_EXPORT(int) 119mvwscanw(WINDOW *win, int y, int x, const char *fmt, ...) 120{ 121 int code; 122 va_list ap; 123 124 va_start(ap, fmt); 125 code = (wmove(win, y, x) == OK) ? vw_scanw(win, fmt, ap) : ERR; 126 va_end(ap); 127 return (code); 128} 129