1
0
mirror of https://github.com/cc65/cc65.git synced 2024-11-19 06:31:31 +00:00
cc65/libsrc/common/vsscanf.c
cuz b1d4e1613b Rewrote _scanf. It does need some tests and improvements, but it's a more
standard version than before, and it does support the necessary functionality
to support scanf functions for files.
Added vfscanf, fscanf and vfscanf.


git-svn-id: svn://svn.cc65.org/cc65/trunk@3301 b7a2c559-68d2-44c3-8de9-860c34a00d81
2004-11-26 22:16:54 +00:00

82 lines
1.7 KiB
C

/*
* vsscanf.c
*
* (C) Copyright 2002 Ullrich von Bassewitz (uz@cc65.org)
*
*/
#include <stdio.h>
#include "_scanf.h"
/*****************************************************************************/
/* Data */
/*****************************************************************************/
struct sscanfdata {
const char* str; /* Pointer to input string */
unsigned index; /* Read index */
};
/*****************************************************************************/
/* Code */
/*****************************************************************************/
static int __fastcall__ get (struct sscanfdata* d)
/* Read a character from the input string and return it */
{
char C;
if (C = d->str[d->index]) {
/* Increment index only if end not reached */
++d->index;
return C;
} else {
return EOF;
}
}
static int __fastcall__ unget (int c, struct sscanfdata* d)
/* Push back a character onto the input stream */
{
/* We do assume here that the _scanf routine will not push back anything
* not read, so we can ignore c safely and won't check the index.
*/
--d->index;
return c;
}
int __fastcall__ vsscanf (const char* str, const char* format, va_list ap)
/* Standard C function */
{
struct sscanfdata sd;
struct scanfdata d;
/* Initialize the data structs. The sscanfdata struct will be passed back
* to the get and unget functions by _scanf.
*/
d.get = (getfunc) get;
d.unget = (ungetfunc) unget,
d.data = &sd;
sd.str = str;
sd.index = 0;
/* Call the internal function and return the result */
return _scanf (&d, format, ap);
}