home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib25.zoo / sscanf.c < prev    next >
C/C++ Source or Header  |  1992-09-05  |  1KB  |  63 lines

  1. #include <stdio.h>
  2. #include <stdarg.h>
  3. #include "lib.h"
  4.  
  5. typedef int (*gettype)(void *);
  6. typedef int (*ungettype)(int, void *);
  7.  
  8. static int sgetc __PROTO((unsigned char **s));
  9. static int sungetc __PROTO((int c, unsigned char **s));
  10.  
  11. static int sgetc(s)
  12.     unsigned char **s;
  13. {
  14.     register unsigned char c;
  15.  
  16.     c = *(*s)++;
  17.     return((c == '\0') ? EOF : c);
  18. }
  19.  
  20. static int sungetc(c, s)
  21.     int c;
  22.     unsigned char **s;
  23. {
  24.     if(c == EOF)
  25.         c = '\0';
  26.     return(*--(*s) = c);
  27. }
  28.  
  29. #ifdef __STDC__
  30. int sscanf(const char *buf, const char *fmt, ...)
  31. {
  32.     int retval;
  33.     va_list args;
  34.     
  35.     va_start (args, fmt);
  36.     retval = _scanf(&buf, (gettype) sgetc, (ungettype) sungetc,
  37.      (unsigned char *) fmt, args);
  38.     va_end (args);
  39.     return retval;
  40. }
  41. #else
  42. int
  43. sscanf(buf, fmt, arg)
  44.     const char *buf, *fmt;
  45.     int arg;
  46. {
  47.     return(_scanf(&buf, sgetc, sungetc, fmt, &arg));
  48. }
  49. #endif /* __STDC__ */
  50.  
  51. #ifdef __STDC__
  52. int vsscanf(const char *buf, const char *fmt, va_list arg)
  53. #else
  54. int
  55. vsscanf(buf, fmt, arg)
  56.     const char *buf, *fmt;
  57.     char *arg;
  58. #endif /* __STDC__ */
  59.     {
  60.     return(_scanf(&buf, (gettype) sgetc, (ungettype) sungetc,
  61.      (unsigned char *) fmt, arg));
  62.     }
  63.