beta-0.89.2
[luatex.git] / source / libs / gmp / gmp-src / scanf / sscanffuns.c
blobed5bdf57d346332ac8f2f3c43d9d08e8383833f5
1 /* __gmp_sscanf_funs -- support for formatted input from a string.
3 THE FUNCTIONS IN THIS FILE ARE FOR INTERNAL USE ONLY. THEY'RE ALMOST
4 CERTAIN TO BE SUBJECT TO INCOMPATIBLE CHANGES OR DISAPPEAR COMPLETELY IN
5 FUTURE GNU MP RELEASES.
7 Copyright 2001-2003, 2009 Free Software Foundation, Inc.
9 This file is part of the GNU MP Library.
11 The GNU MP Library is free software; you can redistribute it and/or modify
12 it under the terms of either:
14 * the GNU Lesser General Public License as published by the Free
15 Software Foundation; either version 3 of the License, or (at your
16 option) any later version.
20 * the GNU General Public License as published by the Free Software
21 Foundation; either version 2 of the License, or (at your option) any
22 later version.
24 or both in parallel, as here.
26 The GNU MP Library is distributed in the hope that it will be useful, but
27 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
28 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
29 for more details.
31 You should have received copies of the GNU General Public License and the
32 GNU Lesser General Public License along with the GNU MP Library. If not,
33 see https://www.gnu.org/licenses/. */
35 #include <stdio.h>
36 #include <stdarg.h>
37 #include "gmp.h"
38 #include "gmp-impl.h"
41 #if 0
42 static int
43 scan (const char **sp, const char *fmt, ...)
45 va_list ap;
46 int ret;
48 va_start(ap, fmt);
49 ret = vsscanf(*sp, fmt, ap);
50 va_end(ap);
52 return ret;
54 #else
55 static int
56 scan (const char **sp, const char *fmt, ...)
58 va_list ap;
59 void *p1, *p2;
60 int ret;
62 va_start (ap, fmt);
63 p1 = va_arg (ap, void *);
64 p2 = va_arg (ap, void *);
66 ret = sscanf (*sp, fmt, p1, p2);
68 va_end (ap);
70 return ret;
72 #endif
74 static void
75 step (const char **sp, int n)
77 ASSERT (n >= 0);
79 /* shouldn't push us past the end of the string */
80 #if WANT_ASSERT
82 int i;
83 for (i = 0; i < n; i++)
84 ASSERT ((*sp)[i] != '\0');
86 #endif
88 (*sp) += n;
91 static int
92 get (const char **sp)
94 const char *s;
95 int c;
96 s = *sp;
97 c = (unsigned char) *s++;
98 if (c == '\0')
99 return EOF;
100 *sp = s;
101 return c;
104 static void
105 unget (int c, const char **sp)
107 const char *s;
108 s = *sp;
109 if (c == EOF)
111 ASSERT (*s == '\0');
112 return;
114 s--;
115 ASSERT ((unsigned char) *s == c);
116 *sp = s;
119 const struct gmp_doscan_funs_t __gmp_sscanf_funs = {
120 (gmp_doscan_scan_t) scan,
121 (gmp_doscan_step_t) step,
122 (gmp_doscan_get_t) get,
123 (gmp_doscan_unget_t) unget,