home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / swscanf.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  2KB  |  79 lines

  1. /***
  2. *swscanf.c - read formatted data from wide-character string
  3. *
  4. *       Copyright (c) 1991-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       defines _swscanf() - reads formatted data from wide-character string
  8. *
  9. *******************************************************************************/
  10.  
  11.  
  12. #include <cruntime.h>
  13. #include <stdio.h>
  14. #include <wchar.h>
  15. #include <dbgint.h>
  16. #include <stdarg.h>
  17. #include <string.h>
  18. #include <internal.h>
  19. #include <mtdll.h>
  20.  
  21. /***
  22. *int swscanf(string, format, ...) - read formatted data from wide-char string
  23. *
  24. *Purpose:
  25. *       Same as sscanf (described below) from reads from a wide-char string.
  26. *
  27. *       Reads formatted data from string into arguments.  _winput does the real
  28. *       work here.  Sets up a FILE so file i/o operations can be used, makes
  29. *       string look like a huge buffer to it, but _filbuf will refuse to refill
  30. *       it if it is exhausted.
  31. *
  32. *       Allocate the 'fake' _iob[] entryit statically instead of on
  33. *       the stack so that other routines can assume that _iob[] entries are in
  34. *       are in DGROUP and, thus, are near.
  35. *
  36. *       Multi-thread: (1) Since there is no stream, this routine must never try
  37. *       to get the stream lock (i.e., there is no stream lock either).  (2)
  38. *       Also, since there is only one staticly allocated 'fake' iob, we must
  39. *       lock/unlock to prevent collisions.
  40. *
  41. *Entry:
  42. *       wchar_t *string - wide-character string to read data from
  43. *       wchar_t *format - format string
  44. *       followed by list of pointers to storage for the data read.  The number
  45. *       and type are controlled by the format string.
  46. *
  47. *Exit:
  48. *       returns number of fields read and assigned
  49. *
  50. *Exceptions:
  51. *
  52. *******************************************************************************/
  53.  
  54. int __cdecl swscanf (
  55.         REG2 const wchar_t *string,
  56.         const wchar_t *format,
  57.         ...
  58.         )
  59. {
  60.         va_list arglist;
  61.         FILE str;
  62.         REG1 FILE *infile = &str;
  63.         REG2 int retval;
  64.  
  65.         va_start(arglist, format);
  66.  
  67.         _ASSERTE(string != NULL);
  68.         _ASSERTE(format != NULL);
  69.  
  70.         infile->_flag = _IOREAD|_IOSTRG|_IOMYBUF;
  71.         infile->_ptr = infile->_base = (char *) string;
  72.         infile->_cnt = wcslen(string)*sizeof(wchar_t);
  73.  
  74.         retval = (_winput(infile,format,arglist));
  75.  
  76.         return(retval);
  77. }
  78.  
  79.