Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 8621 → Rev 8622

/contrib/kolibri-libc/source/stdio/vscanf.c
0,0 → 1,44
#include "format_scan.h"
#include <string.h>
 
char *__scanf_buffer=NULL;
 
static int __virtual_getc_con(void *sp, const void *obj)
// get next chat from string obj, save point is ptr to string char ptr
{
int ch;
const char**spc= (const char**)sp;
if (!spc) return EOF; // error
if (!*spc) *spc = __scanf_buffer; // first call, init savepoint
 
while (!**spc) // need to read more
{
if(!gets(__scanf_buffer)) return EOF;
*spc = __scanf_buffer;
strcat(__scanf_buffer,"\n"); // imitate delimiter
}
if (**spc == 26 || **spc == 3) // ^C ^Z end of scan, clear buffer
{
*spc = __scanf_buffer;
*__scanf_buffer = 0;
return EOF; // ^C ^Z
}
 
ch = **spc; (*spc)++ ;
return ch;
}
 
static void __virtual_ungetc_con(void *sp, int c, const void *obj)
// if can, one step back savepoint in s
{
const char**spc= (const char**)sp;
 
if (spc && *spc > __scanf_buffer) (*spc)--;
//printf("Ungetc '%c'[%d];", c, c);
}
 
 
int vscanf(const char * format, va_list arg)
{
return _format_scan(NULL, format, arg, &__virtual_getc_con, &__virtual_ungetc_con);
}