home *** CD-ROM | disk | FTP | other *** search
/ Computer Club Elmshorn Atari PD / CCE_PD.iso / pc / 0600 / CCE_0636.ZIP / CCE_0636 / CURSES / CRSSRC12.ZOO / src / scanw.c < prev    next >
C/C++ Source or Header  |  1991-09-27  |  3KB  |  139 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 are permitted
  6.  * provided that the above copyright notice and this paragraph are
  7.  * duplicated in all such forms and that any documentation,
  8.  * advertising materials, and other materials related to such
  9.  * distribution and use acknowledge that the software was developed
  10.  * by the University of California, Berkeley.  The name of the
  11.  * University may not be used to endorse or promote products derived
  12.  * from this software without specific prior written permission.
  13.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  14.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  15.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  16.  */
  17.  
  18. #ifndef lint
  19. static char sccsid[] = "@(#)scanw.c    5.3 (Berkeley) 6/30/88";
  20. #endif /* not lint */
  21.  
  22. /*
  23.  * scanw and friends
  24.  *
  25.  */
  26.  
  27. # include    "curses.ext"
  28. # include <string.h>
  29. # include <stdarg.h>
  30.  
  31. /*
  32.  *    This routine implements a scanf on the standard screen.
  33.  */
  34. #ifdef __STDC__
  35. int scanw(char *fmt, ...)
  36. #else
  37. scanw(fmt)
  38. char    *fmt;
  39. #endif
  40. {
  41.     va_list argp;
  42.  
  43.     va_start(argp, fmt);
  44.     return _sscans(stdscr, fmt, argp);
  45. }
  46. /*
  47.  *    This routine implements a scanf on the given window.
  48.  */
  49. #ifdef __STDC__
  50. int wscanw(WINDOW *win, char *fmt, ...)
  51. #else
  52. wscanw(win, fmt, args)
  53. WINDOW    *win;
  54. char    *fmt;
  55. #endif
  56. {
  57.     va_list argp;
  58.  
  59.     va_start(argp, fmt);
  60.     return _sscans(win, fmt, argp);
  61. }
  62.  
  63. #ifdef atarist
  64.  
  65. /* modelled on the code from the new GCC library (originally from Dale
  66.  * Schumacher's dLibs library).
  67.  */
  68.  
  69. static int sgetc(s)
  70.     unsigned char **s;
  71.     {
  72.     register unsigned char c;
  73.  
  74.     c = *(*s)++;
  75.     return((c == '\0') ? EOF : c);
  76.     }
  77.  
  78. static int sungetc(c, s)
  79.     int c;
  80.     unsigned char **s;
  81.     {
  82.     if(c == EOF)
  83.         c = '\0';
  84.     return(*--(*s) = c);
  85.     }
  86.  
  87. #ifdef __STDC__
  88. int _sscans(WINDOW *win, char *fmt, ...)
  89. #else
  90. int _sscans(win, fmt)
  91. WINDOW    *win;
  92. char    *fmt;
  93. #endif
  94. {
  95.     char buf[128], *junk;
  96.     extern int _scanf();
  97.     va_list argp;
  98.     
  99.     if (wgetstr(win, buf) < 0)
  100.         return ERR;
  101.     va_start(argp, fmt);
  102.     junk = buf;
  103.     return(_scanf(&junk, sgetc, sungetc, fmt, argp));
  104. }
  105.     
  106. #else /* original BSD routines */
  107.  
  108. /*
  109.  *    This routine actually executes the scanf from the window.
  110.  *
  111.  *    This is really a modified version of "sscanf".  As such,
  112.  * it assumes that sscanf interfaces with the other scanf functions
  113.  * in a certain way.  If this is not how your system works, you
  114.  * will have to modify this routine to use the interface that your
  115.  * "sscanf" uses.
  116.  */
  117. #ifdef __STDC__
  118. int _sscans(win, fmt, ...)
  119. #else
  120. int _sscans(win, fmt)
  121. WINDOW    *win;
  122. char    *fmt;
  123. #endif
  124. {
  125.  
  126.     char    buf[100];
  127.     FILE    junk;
  128.     va_list argp;
  129.     
  130.     junk._flag = _IOREAD|_IOSTRG;
  131.     junk._base = junk._ptr = buf;
  132.     if (wgetstr(win, buf) == ERR)
  133.         return ERR;
  134.     va_start(argp, fmt);
  135.     junk._cnt = strlen(buf);
  136.     return _doscan(&junk, fmt, argp);
  137. }
  138. #endif /* atarist */
  139.