]> git.sur5r.net Git - cc65/blob - libsrc/common/sscanf.c
Working on the ..scanf functions
[cc65] / libsrc / common / sscanf.c
1 /*
2  * sscanf.c
3  *
4  * (C) Copyright 2001 Ullrich von Bassewitz (uz@cc65.org)
5  *
6  */
7
8
9
10 #include <stdio.h>
11 #include <string.h>
12 #include "_scanf.h"
13
14
15
16 /*****************************************************************************/
17 /*                                   Code                                    */
18 /*****************************************************************************/
19
20
21
22 static char get (struct indesc* d)
23 /* Read a character from the input string and return it */
24 {
25     char C;
26     if (C = d->buf[d->ridx]) {
27         /* Increment index only if end not reached */
28         ++d->ridx;
29     }
30     return C;
31 }
32
33
34
35 int sscanf (const char* str, const char* format, ...)
36 /* Standard C function */
37 {
38     struct indesc id;
39     va_list ap;
40
41     /* Initialize the indesc struct. We leave all fields uninitialized that we
42      * don't need
43      */
44     id.fin  = (infunc) get;
45     id.buf  = (char*) str;
46     id.ridx = 0;
47
48     /* Setup for variable arguments */
49     va_start (ap, format);
50
51     /* Call the internal function. Since we know that va_end won't do anything,
52      * we will save the call and return the value directly.
53      */
54     return _scanf (&id, format, ap);
55 }
56
57
58