2001-03-13 07:59:17 +00:00
|
|
|
/*
|
|
|
|
* sscanf.c
|
|
|
|
*
|
|
|
|
* (C) Copyright 2001 Ullrich von Bassewitz (uz@cc65.org)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "_scanf.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* Code */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-04-19 06:46:30 +00:00
|
|
|
static char get (struct indesc* d)
|
|
|
|
/* Read a character from the input string and return it */
|
|
|
|
{
|
|
|
|
char C;
|
|
|
|
if (C = d->buf[d->ridx]) {
|
|
|
|
/* Increment index only if end not reached */
|
|
|
|
++d->ridx;
|
|
|
|
}
|
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-03-13 07:59:17 +00:00
|
|
|
int sscanf (const char* str, const char* format, ...)
|
|
|
|
/* Standard C function */
|
|
|
|
{
|
|
|
|
struct indesc id;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
/* Initialize the indesc struct. We leave all fields uninitialized that we
|
|
|
|
* don't need
|
|
|
|
*/
|
2001-04-19 06:46:30 +00:00
|
|
|
id.fin = (infunc) get;
|
2001-03-23 19:21:27 +00:00
|
|
|
id.buf = (char*) str;
|
2001-04-19 06:46:30 +00:00
|
|
|
id.ridx = 0;
|
2001-03-13 07:59:17 +00:00
|
|
|
|
|
|
|
/* Setup for variable arguments */
|
|
|
|
va_start (ap, format);
|
|
|
|
|
|
|
|
/* Call the internal function. Since we know that va_end won't do anything,
|
|
|
|
* we will save the call and return the value directly.
|
|
|
|
*/
|
2001-03-23 19:21:27 +00:00
|
|
|
return _scanf (&id, format, ap);
|
2001-03-13 07:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|