home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / lib / libcurses / scanw.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-31  |  3.9 KB  |  178 lines

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