1 1.24 blymn /* $NetBSD: scanw.c,v 1.24 2024/12/23 02:58:04 blymn Exp $ */ 2 1.8 mikel 3 1.1 cgd /* 4 1.7 cgd * Copyright (c) 1981, 1993, 1994 5 1.4 cgd * The Regents of the University of California. All rights reserved. 6 1.1 cgd * 7 1.1 cgd * Redistribution and use in source and binary forms, with or without 8 1.1 cgd * modification, are permitted provided that the following conditions 9 1.1 cgd * are met: 10 1.1 cgd * 1. Redistributions of source code must retain the above copyright 11 1.1 cgd * notice, this list of conditions and the following disclaimer. 12 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright 13 1.1 cgd * notice, this list of conditions and the following disclaimer in the 14 1.1 cgd * documentation and/or other materials provided with the distribution. 15 1.18 agc * 3. Neither the name of the University nor the names of its contributors 16 1.1 cgd * may be used to endorse or promote products derived from this software 17 1.1 cgd * without specific prior written permission. 18 1.1 cgd * 19 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 1.1 cgd * SUCH DAMAGE. 30 1.1 cgd */ 31 1.1 cgd 32 1.8 mikel #include <sys/cdefs.h> 33 1.1 cgd #ifndef lint 34 1.8 mikel #if 0 35 1.7 cgd static char sccsid[] = "@(#)scanw.c 8.3 (Berkeley) 5/4/94"; 36 1.8 mikel #else 37 1.24 blymn __RCSID("$NetBSD: scanw.c,v 1.24 2024/12/23 02:58:04 blymn Exp $"); 38 1.8 mikel #endif 39 1.10 mrg #endif /* not lint */ 40 1.1 cgd 41 1.1 cgd /* 42 1.3 mycroft * scanw and friends. 43 1.1 cgd */ 44 1.1 cgd 45 1.1 cgd #include <stdarg.h> 46 1.7 cgd 47 1.7 cgd #include "curses.h" 48 1.3 mycroft 49 1.1 cgd /* 50 1.3 mycroft * scanw -- 51 1.3 mycroft * Implement a scanf on the standard screen. 52 1.1 cgd */ 53 1.3 mycroft int 54 1.12 jdc scanw(const char *fmt,...) 55 1.1 cgd { 56 1.1 cgd va_list ap; 57 1.10 mrg int ret; 58 1.1 cgd 59 1.1 cgd va_start(ap, fmt); 60 1.20 joerg ret = vw_scanw(stdscr, fmt, ap); 61 1.1 cgd va_end(ap); 62 1.22 roy return ret; 63 1.1 cgd } 64 1.1 cgd /* 65 1.3 mycroft * wscanw -- 66 1.3 mycroft * Implements a scanf on the given window. 67 1.1 cgd */ 68 1.3 mycroft int 69 1.14 blymn wscanw(WINDOW *win, const char *fmt,...) 70 1.1 cgd { 71 1.1 cgd va_list ap; 72 1.10 mrg int ret; 73 1.1 cgd 74 1.24 blymn if (__predict_false(win == NULL)) 75 1.24 blymn return ERR; 76 1.24 blymn 77 1.1 cgd va_start(ap, fmt); 78 1.20 joerg ret = vw_scanw(win, fmt, ap); 79 1.3 mycroft va_end(ap); 80 1.22 roy return ret; 81 1.3 mycroft } 82 1.3 mycroft /* 83 1.10 mrg * mvscanw, mvwscanw -- 84 1.3 mycroft * Implement the mvscanw commands. Due to the variable number of 85 1.3 mycroft * arguments, they cannot be macros. Another sigh.... 86 1.3 mycroft */ 87 1.3 mycroft int 88 1.12 jdc mvscanw(int y, int x, const char *fmt,...) 89 1.3 mycroft { 90 1.3 mycroft va_list ap; 91 1.10 mrg int ret; 92 1.3 mycroft 93 1.3 mycroft if (move(y, x) != OK) 94 1.22 roy return ERR; 95 1.3 mycroft va_start(ap, fmt); 96 1.20 joerg ret = vw_scanw(stdscr, fmt, ap); 97 1.3 mycroft va_end(ap); 98 1.22 roy return ret; 99 1.3 mycroft } 100 1.3 mycroft 101 1.3 mycroft int 102 1.13 simonb mvwscanw(WINDOW * win, int y, int x, const char *fmt,...) 103 1.3 mycroft { 104 1.3 mycroft va_list ap; 105 1.10 mrg int ret; 106 1.3 mycroft 107 1.3 mycroft if (move(y, x) != OK) 108 1.22 roy return ERR; 109 1.3 mycroft va_start(ap, fmt); 110 1.20 joerg ret = vw_scanw(win, fmt, ap); 111 1.1 cgd va_end(ap); 112 1.22 roy return ret; 113 1.1 cgd } 114 1.1 cgd /* 115 1.4 cgd * vwscanw -- 116 1.1 cgd * This routine actually executes the scanf from the window. 117 1.1 cgd */ 118 1.4 cgd int 119 1.21 joerg vw_scanw(WINDOW *win, const char *fmt, va_list ap) 120 1.1 cgd { 121 1.10 mrg char buf[1024]; 122 1.23 blymn int ret; 123 1.1 cgd 124 1.24 blymn if (__predict_false(win == NULL)) 125 1.24 blymn return ERR; 126 1.24 blymn 127 1.23 blymn ret = ERR; 128 1.23 blymn if (wgetnstr(win, buf, (int) sizeof(buf)) == OK) { 129 1.23 blymn if (vsscanf(buf, fmt, ap) > 0) { 130 1.23 blymn ret = OK; 131 1.23 blymn } 132 1.23 blymn } 133 1.23 blymn 134 1.23 blymn return ret; 135 1.1 cgd } 136 1.20 joerg 137 1.20 joerg __strong_alias(vwscanw, vw_scanw) 138