Home | History | Annotate | Line # | Download | only in libcurses
scanw.c revision 1.14
      1 /*	$NetBSD: scanw.c,v 1.14 2000/04/15 13:17:04 blymn Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1981, 1993, 1994
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the University of
     18  *	California, Berkeley and its contributors.
     19  * 4. Neither the name of the University nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  */
     35 
     36 #include <sys/cdefs.h>
     37 #ifndef lint
     38 #if 0
     39 static char sccsid[] = "@(#)scanw.c	8.3 (Berkeley) 5/4/94";
     40 #else
     41 __RCSID("$NetBSD: scanw.c,v 1.14 2000/04/15 13:17:04 blymn Exp $");
     42 #endif
     43 #endif				/* not lint */
     44 
     45 /*
     46  * scanw and friends.
     47  */
     48 
     49 #ifdef __STDC__
     50 #include <stdarg.h>
     51 #else
     52 #include <varargs.h>
     53 #endif
     54 
     55 #include "curses.h"
     56 
     57 /*
     58  * scanw --
     59  *	Implement a scanf on the standard screen.
     60  */
     61 int
     62 #ifdef __STDC__
     63 scanw(const char *fmt,...)
     64 #else
     65 scanw(fmt, va_alist)
     66 	const char   *fmt;
     67 va_dcl
     68 #endif
     69 {
     70 	va_list ap;
     71 	int     ret;
     72 
     73 #ifdef __STDC__
     74 	va_start(ap, fmt);
     75 #else
     76 	va_start(ap);
     77 #endif
     78 	ret = vwscanw(stdscr, fmt, ap);
     79 	va_end(ap);
     80 	return (ret);
     81 }
     82 /*
     83  * wscanw --
     84  *	Implements a scanf on the given window.
     85  */
     86 int
     87 #ifdef __STDC__
     88 wscanw(WINDOW *win, const char *fmt,...)
     89 #else
     90 wscanw(win, fmt, va_alist)
     91 	WINDOW *win;
     92 	const char   *fmt;
     93 va_dcl
     94 #endif
     95 {
     96 	va_list ap;
     97 	int     ret;
     98 
     99 #ifdef __STDC__
    100 	va_start(ap, fmt);
    101 #else
    102 	va_start(ap);
    103 #endif
    104 	ret = vwscanw(win, fmt, ap);
    105 	va_end(ap);
    106 	return (ret);
    107 }
    108 /*
    109  * mvscanw, mvwscanw --
    110  *	Implement the mvscanw commands.  Due to the variable number of
    111  *	arguments, they cannot be macros.  Another sigh....
    112  */
    113 int
    114 #ifdef __STDC__
    115 mvscanw(int y, int x, const char *fmt,...)
    116 #else
    117 mvscanw(y, x, fmt, va_alist)
    118 	int     y, x;
    119 	const char   *fmt;
    120 va_dcl
    121 #endif
    122 {
    123 	va_list ap;
    124 	int     ret;
    125 
    126 	if (move(y, x) != OK)
    127 		return (ERR);
    128 #ifdef __STDC__
    129 	va_start(ap, fmt);
    130 #else
    131 	va_start(ap);
    132 #endif
    133 	ret = vwscanw(stdscr, fmt, ap);
    134 	va_end(ap);
    135 	return (ret);
    136 }
    137 
    138 int
    139 #ifdef __STDC__
    140 mvwscanw(WINDOW * win, int y, int x, const char *fmt,...)
    141 #else
    142 mvwscanw(win, y, x, fmt, va_alist)
    143 	WINDOW *win;
    144 	int     y, x;
    145 	const char   *fmt;
    146 va_dcl
    147 #endif
    148 {
    149 	va_list ap;
    150 	int     ret;
    151 
    152 	if (move(y, x) != OK)
    153 		return (ERR);
    154 #ifdef __STDC__
    155 	va_start(ap, fmt);
    156 #else
    157 	va_start(ap);
    158 #endif
    159 	ret = vwscanw(win, fmt, ap);
    160 	va_end(ap);
    161 	return (ret);
    162 }
    163 /*
    164  * vwscanw --
    165  *	This routine actually executes the scanf from the window.
    166  */
    167 int
    168 vwscanw(WINDOW *win, const char *fmt, va_list ap)
    169 {
    170 
    171 	char    buf[1024];
    172 
    173 	return (wgetstr(win, buf) == OK ?
    174 	    vsscanf(buf, fmt, ap) : ERR);
    175 }
    176