Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright (c) 1990 The 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 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  16.  */
  17.  
  18. /*
  19. FUNCTION
  20. <<siscanf>>, <<fiscanf>>, <<iscanf>>---scan and format non-floating input
  21.  
  22. INDEX
  23.         iscanf
  24. INDEX
  25.         _iscanf_r
  26. INDEX
  27.         fiscanf
  28. INDEX
  29.         _fiscanf_r
  30. INDEX
  31.         siscanf
  32. INDEX
  33.         _siscanf_r
  34.  
  35. ANSI_SYNOPSIS
  36.         #include <stdio.h>
  37.  
  38.         int iscanf(const char *<[format]>, ...);
  39.         int fiscanf(FILE *<[fd]>, const char *<[format]>, ...);
  40.         int siscanf(const char *<[str]>, const char *<[format]>, ...);
  41.  
  42.         int _iscanf_r(struct _reent *<[ptr]>, const char *<[format]>, ...);
  43.         int _fiscanf_r(struct _reent *<[ptr]>, FILE *<[fd]>,
  44.                        const char *<[format]>, ...);
  45.         int _siscanf_r(struct _reent *<[ptr]>, const char *<[str]>,
  46.                    const char *<[format]>, ...);
  47.  
  48.  
  49. TRAD_SYNOPSIS
  50.         #include <stdio.h>
  51.  
  52.         int iscanf(<[format]> [, <[arg]>, ...])
  53.         char *<[format]>;
  54.  
  55.         int fiscanf(<[fd]>, <[format]> [, <[arg]>, ...]);
  56.         FILE *<[fd]>;
  57.         char *<[format]>;
  58.  
  59.         int siscanf(<[str]>, <[format]> [, <[arg]>, ...]);
  60.         char *<[str]>;
  61.         char *<[format]>;
  62.  
  63.         int _iscanf_r(<[ptr]>, <[format]> [, <[arg]>, ...])
  64.         struct _reent *<[ptr]>;
  65.         char *<[format]>;
  66.  
  67.         int _fiscanf_r(<[ptr]>, <[fd]>, <[format]> [, <[arg]>, ...]);
  68.         struct _reent *<[ptr]>;
  69.         FILE *<[fd]>;
  70.         char *<[format]>;
  71.  
  72.         int _siscanf_r(<[ptr]>, <[str]>, <[format]> [, <[arg]>, ...]);
  73.         struct _reent *<[ptr]>;
  74.         char *<[str]>;
  75.         char *<[format]>;
  76.  
  77.  
  78. DESCRIPTION
  79.         <<iscanf>>, <<fiscanf>>, and <<siscanf>> are the same as
  80.         <<scanf>>, <<fscanf>>, and <<sscanf>> respectively, only that
  81.         they restrict the available formats to non-floating-point
  82.         format specifiers.
  83.  
  84.         The routines <<_iscanf_r>>, <<_fiscanf_r>>, and <<_siscanf_r>> are reentrant
  85.         versions of <<iscanf>>, <<fiscanf>>, and <<siscanf>> that take an additional
  86.         first argument pointing to a reentrancy structure.
  87.  
  88. RETURNS
  89.         <<iscanf>> returns the number of input fields successfully
  90.         scanned, converted and stored; the return value does
  91.         not include scanned fields which were not stored.
  92.  
  93.         If <<iscanf>> attempts to read at end-of-file, the return
  94.         value is <<EOF>>.
  95.  
  96.         If no fields were stored, the return value is <<0>>.
  97.  
  98. PORTABILITY
  99. <<iscanf>>, <<fiscanf>>, and <<siscanf>> are newlib extensions.
  100.  
  101. Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
  102. <<lseek>>, <<read>>, <<sbrk>>, <<write>>.
  103. */
  104.  
  105. #include <_ansi.h>
  106. #include <reent.h>
  107. #include <stdio.h>
  108. #include <string.h>
  109. #ifdef _HAVE_STDC
  110. #include <stdarg.h>
  111. #else
  112. #include <varargs.h>
  113. #endif
  114. #include "local.h"
  115.  
  116. #ifndef _REENT_ONLY
  117.  
  118. #ifdef _HAVE_STDC
  119. int
  120. _DEFUN(siscanf, (str, fmt),
  121.        _CONST char *str _AND
  122.        _CONST char *fmt _DOTS)
  123. #else
  124. int
  125. siscanf(str, fmt, va_alist)
  126.        _CONST char *str;
  127.        _CONST char *fmt;
  128.        va_dcl
  129. #endif
  130. {
  131.   int ret;
  132.   va_list ap;
  133.   FILE f;
  134.  
  135.   f._flags = __SRD | __SSTR;
  136.   f._bf._base = f._p = (unsigned char *) str;
  137.   f._bf._size = f._r = strlen (str);
  138.   f._read = __seofread;
  139.   f._ub._base = NULL;
  140.   f._lb._base = NULL;
  141.   f._file = -1;  /* No file. */
  142. #ifdef _HAVE_STDC
  143.   va_start (ap, fmt);
  144. #else
  145.   va_start (ap);
  146. #endif
  147.   ret = __ssvfiscanf_r (_REENT, &f, fmt, ap);
  148.   va_end (ap);
  149.   return ret;
  150. }
  151.  
  152. #endif /* !_REENT_ONLY */
  153.  
  154. #ifdef _HAVE_STDC
  155. int
  156. _DEFUN(_siscanf_r, (ptr, str, fmt),
  157.        struct _reent *ptr _AND
  158.        _CONST char *str   _AND
  159.        _CONST char *fmt _DOTS)
  160. #else
  161. int
  162. _siscanf_r(ptr, str, fmt, va_alist)
  163.           struct _reent *ptr;
  164.           _CONST char *str;
  165.           _CONST char *fmt;
  166.           va_dcl
  167. #endif
  168. {
  169.   int ret;
  170.   va_list ap;
  171.   FILE f;
  172.  
  173.   f._flags = __SRD | __SSTR;
  174.   f._bf._base = f._p = (unsigned char *) str;
  175.   f._bf._size = f._r = strlen (str);
  176.   f._read = __seofread;
  177.   f._ub._base = NULL;
  178.   f._lb._base = NULL;
  179.   f._file = -1;  /* No file. */
  180. #ifdef _HAVE_STDC
  181.   va_start (ap, fmt);
  182. #else
  183.   va_start (ap);
  184. #endif
  185.   ret = __ssvfiscanf_r (ptr, &f, fmt, ap);
  186.   va_end (ap);
  187.   return ret;
  188. }
  189.