13 #define NEXT(c) ((c)=xgetc(opaque),size++,incount++)
14 #define PREV(c) do{if((c)!=EOF)xungetc(opaque,(c));size--;incount--;}while(0)
15 #define VAL(a) ((a)&&size<=width)
17 #ifdef NOFLOATINGPOINT
18 #undef FULL_SPECIFIERS
20 #define FULL_SPECIFIERS
25 #ifdef FULL_SPECIFIERS
26 static const unsigned char undef[3][
sizeof(double)]=
27 { { 0x7f,0xf0,0x00,0x00,0x00,0x00,0x00,0x00 },
28 { 0xff,0xf0,0x00,0x00,0x00,0x00,0x00,0x00 },
29 { 0x7f,0xf1,0x00,0x00,0x00,0x00,0x00,0x00 }
33 int vxscanf(
int (*xgetc)(
void *),
void (*xungetc)(
void*,
int),
void *opaque,
const char *format,va_list args)
35 size_t blocks=0,incount=0;
44 size_t width=ULONG_MAX;
45 char type,subtype=
'i',ignore=0;
46 const unsigned char *ptr=(
const unsigned char *)format+1;
52 width=width*10+(*ptr++-
'0'); }
54 while(*ptr==
'h'||*ptr==
'l'||*ptr==
'L'||*ptr==
'*')
64 if(type&&type!=
'%'&&type!=
'c'&&type!=
'n'&&type!=
'[')
78 bp=va_arg(args,
unsigned char *);
96 unsigned char tab[32],a,b;
102 for(i=0;i<
sizeof(tab);i++)
103 tab[i]=circflag?255:0;
108 if(*ptr==
'-'&&ptr[1]&&ptr[1]!=
']')
113 tab[i/8]&=~(1<<(i&7));
122 bp=va_arg(args,
unsigned char *);
127 while(
VAL(c!=EOF&&tab[c/8]&(1<<(c&7))))
143 bp=va_arg(args,
unsigned char *);
159 #ifdef FULL_SPECIFIERS
169 if(
VAL(c==
'-'||c==
'+'))
173 if(
VAL(tolower(c)==
'i'))
176 if(
VAL(tolower(d)==
'n'))
179 if(
VAL(tolower(e)==
'f'))
180 { v=*(
double *)&undef[min==
'-'];
186 else if(
VAL(toupper(c)==
'N'))
189 if(
VAL(tolower(d)==
'a'))
192 if(
VAL(toupper(e)==
'N'))
193 { v=*(
double *)&undef[2];
224 if(
VAL(tolower(c)==
'e'))
227 if(
VAL(d==
'-'||d==
'+'))
259 *va_arg(args,
double *)=v;
262 *va_arg(args,
float *)=v;
277 *va_arg(args,
int *)=incount;
293 if(
VAL((c==
'-'&&type!=
'u')||c==
'+'))
301 if(
VAL(tolower(d)==
'x'))
314 while(type==
'x'&&
VAL(c==
'0'))
317 if(
VAL(tolower(d)==
'x'))
329 base=type==
'x'||type==
'X'?16:(type==
'o'?8:10);
331 { v=v*base+(
isdigit(c)?c-
'0':0)+(isupper(c)?c-
'A'+10:0)+(
islower(c)?c-
'a'+10:0);
348 *va_arg(args,
unsigned long *)=v;
351 *va_arg(args,
unsigned int *)=v;
354 *va_arg(args,
unsigned short *)=v;
366 *va_arg(args,
signed long *)=v2;
369 *va_arg(args,
signed int *)=v2;
372 *va_arg(args,
signed short *)=v2;
380 format=(
const char *)ptr;