~ubuntu-branches/ubuntu/quantal/gclcvs/quantal

« back to all changes in this revision

Viewing changes to gmp3/scanf/sscanffuns.c

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2004-06-24 15:13:46 UTC
  • Revision ID: james.westby@ubuntu.com-20040624151346-xh0xaaktyyp7aorc
Tags: 2.7.0-26
C_GC_OFFSET is 2 on m68k-linux

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* __gmp_sscanf_funs -- support for formatted input from a string.
 
2
 
 
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.
 
6
 
 
7
Copyright 2001 Free Software Foundation, Inc.
 
8
 
 
9
This file is part of the GNU MP Library.
 
10
 
 
11
The GNU MP Library is free software; you can redistribute it and/or modify
 
12
it under the terms of the GNU Lesser General Public License as published by
 
13
the Free Software Foundation; either version 2.1 of the License, or (at your
 
14
option) any later version.
 
15
 
 
16
The GNU MP Library is distributed in the hope that it will be useful, but
 
17
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
18
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 
19
License for more details.
 
20
 
 
21
You should have received a copy of the GNU Lesser General Public License
 
22
along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
 
23
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 
24
MA 02111-1307, USA. */
 
25
 
 
26
#include <stdio.h>
 
27
#include "gmp.h"
 
28
#include "gmp-impl.h"
 
29
 
 
30
 
 
31
static int
 
32
scan (const char **sp, const char *fmt, void *p1, void *p2)
 
33
{
 
34
  return sscanf (*sp, fmt, p1, p2);
 
35
}
 
36
 
 
37
static void
 
38
step (const char **sp, int n)
 
39
{
 
40
  ASSERT (n >= 0);
 
41
 
 
42
  /* shouldn't push us past the the end of the string */
 
43
#if WANT_ASSERT
 
44
  {
 
45
    int  i;
 
46
    for (i = 0; i < n; i++)
 
47
      ASSERT ((*sp)[i] != '\0');
 
48
  }
 
49
#endif
 
50
 
 
51
  (*sp) += n;
 
52
}
 
53
 
 
54
static int
 
55
get (const char **sp)
 
56
{
 
57
  const char  *s;
 
58
  int  c;
 
59
  s = *sp;
 
60
  c = *s++;
 
61
  if (c == '\0')
 
62
    return EOF;
 
63
  *sp = s;
 
64
  return c;
 
65
}
 
66
 
 
67
static void
 
68
unget (int c, const char **sp)
 
69
{
 
70
  const char  *s;
 
71
  s = *sp;
 
72
  if (c == EOF)
 
73
    {
 
74
      ASSERT (*s == '\0');
 
75
      return;
 
76
    }
 
77
  s--;
 
78
  ASSERT (*s == c);
 
79
  *sp = s;
 
80
}
 
81
 
 
82
const struct gmp_doscan_funs_t  __gmp_sscanf_funs = {
 
83
  (gmp_doscan_scan_t)  scan,
 
84
  (gmp_doscan_step_t)  step,
 
85
  (gmp_doscan_get_t)   get,
 
86
  (gmp_doscan_unget_t) unget,
 
87
};