2021-04-27 18:33:31 +02:00
|
|
|
#include <stdio.h>
|
2021-05-10 00:12:43 +02:00
|
|
|
#include <stdarg.h>
|
2021-04-27 18:33:31 +02:00
|
|
|
|
2021-05-10 00:12:43 +02:00
|
|
|
int virtual_getc_str(void *sp, const void *obj)
|
|
|
|
// get next chat from string obj, save point is ptr to string char ptr
|
2021-04-27 18:33:31 +02:00
|
|
|
{
|
2021-05-10 00:12:43 +02:00
|
|
|
int ch;
|
|
|
|
const char *s = (const char *)obj;
|
|
|
|
const char**spc= (const char**)sp;
|
|
|
|
if (!s || !spc) return EOF; // error
|
|
|
|
|
|
|
|
if (!*spc) *spc = s; // first call, init savepoint
|
|
|
|
|
|
|
|
if (!**spc) return EOF; // EOS
|
|
|
|
|
|
|
|
ch = **spc; (*spc)++ ;
|
|
|
|
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
void virtual_ungetc_str(void *sp, int c, const void *obj)
|
|
|
|
// if can, one step back savepoint in s
|
|
|
|
{
|
|
|
|
const char *s = (const char *)obj;
|
|
|
|
const char**spc= (const char**)sp;
|
|
|
|
|
|
|
|
if (s && spc && *spc > s) (*spc)--;
|
|
|
|
}
|
|
|
|
|
|
|
|
int vsscanf ( const char * s, const char * format, va_list arg )
|
|
|
|
{
|
|
|
|
return format_scan(s, format, arg, &virtual_getc_str, &virtual_ungetc_str);
|
|
|
|
};
|
|
|
|
|
|
|
|
int sscanf ( const char * s, const char * format, ...)
|
|
|
|
{
|
|
|
|
va_list arg;
|
2021-04-27 18:33:31 +02:00
|
|
|
int n;
|
|
|
|
va_start(arg, format);
|
2021-05-10 00:12:43 +02:00
|
|
|
|
2021-04-27 18:33:31 +02:00
|
|
|
n = vsscanf(s, format, arg);
|
2021-05-10 00:12:43 +02:00
|
|
|
|
2021-04-27 18:33:31 +02:00
|
|
|
va_end(arg);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|