sfvscanf.c revision 1
1N/A/*********************************************************************** 1N/A* This software is part of the ast package * 1N/A* Copyright (c) 1985-2011 AT&T Intellectual Property * 1N/A* and is licensed under the * 1N/A* Common Public License, Version 1.0 * 1N/A* by AT&T Intellectual Property * 1N/A* A copy of the License is available at * 1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 1N/A* Information and Software Systems Research * 1N/A* Glenn Fowler <gsf@research.att.com> * 1N/A* David Korn <dgk@research.att.com> * 1N/A* Phong Vo <kpv@research.att.com> * 1N/A***********************************************************************/ 1N/A/* The main engine for reading formatted data 1N/A** Written by Kiem-Phong Vo. 1N/A * pull in a private strtold() 1N/A {
if(*
peek)
/* try peeking for a share stream if possible */ 1N/A *
peek = 0;
/* can't peek, back to normal reads */ 1N/A/* buffer used during scanning of a double value or a multi-byte 1N/A character. the fields mirror certain local variables in sfvscanf. */ 1N/A{
int error;
/* get set by _sfdscan if no value specified */ 1N/A int inp;
/* last input character read */ 1N/A/* ds != 0 for scanning double values */ 1N/A /* if width >= 0, do not allow to exceed width number of bytes */ 1N/A else return ((
int)(*
sc->d++));
1N/A/* structure to match characters in a character class */ 1N/A if(*
form ==
'^')
/* complementing this set */ 1N/A if(*
form ==
']' || *
form ==
'-')
/* special first char */ 1N/A if(c >=
128 ||
endc >=
128 )
/* range must be ascii */ 1N/A if(c >=
128 ||
endc >=
128 )
/* range must be ascii */ 1N/A char b[
16];
/* assuming that SFMBMAX <= 16! */ 1N/A /* shift left data so that there will be more room to back up on error. 1N/A this won't help streams with small buffers - c'est la vie! */ 1N/A {
/* multi-byte char converted successfully */ 1N/A else /* if(fmt == '1') match a single wchar_t */ 1N/Ano_match:
/* this unget is lossy on a stream with small buffer */ 1N/A#
endif /*_has_multibyte*/ 1N/A /* local buffering system */ 1N/A SFinit(f);
/* initialize local buffering system */ 1N/A /* matching some pattern */ 1N/A case LEFTP :
/* get the type which is enclosed in balanced () */ 1N/A case 0 :
/* not balanceable, retract */ 1N/A case LEFTP :
/* increasing nested level */ 1N/A case '#' :
/* alternative format */ 1N/A case '.' :
/* width & base */ 1N/A case '0' :
case '1' :
case '2' :
case '3' :
case '4' :
1N/A case '5' :
case '6' :
case '7' :
case '8' :
case '9' :
1N/A case 'I' :
/* object size */ 1N/A if(
fp)
/* use position list */ 1N/A /* set object size for scalars */ 1N/A {
FMTSET(
ft,
form,
args,
fmt,
size,
flags,
width,0,
base,
t_str,
n_str);
1N/A else if(v > 0)
/* extf comsumed v input bytes */ 1N/A else /* if(v == 0): extf did not use input stream */ 1N/A else /* stack a new environment */ 1N/A /* get the address to assign value */ 1N/A if(
fmt ==
'n')
/* return length of consumed input */ 1N/A /* if get here, start scanning input */ 1N/A /* define the first input character */ 1N/A else if(
fmt ==
'i' &&
inp ==
'0')
/* self-described data */ 1N/A if(
width >
1)
/* peek to see if it's a base-16 */ 1N/A {
/* skip leading 0x or 0X */ 1N/A {
/* fast base 10 conversion */ 1N/A#
define TEN(x) (((x) <<
3) + ((x) <<
1) )
1N/A {
if((v && n !=
3) || (!v && n >
3) )
1N/A n = 0;
/* count number of scanned characters */ 1N/A else /* if(fmt == '[') */ 1N/A while((
fm =
fmstk) )
/* pop the format stack and continue */