Ejemplo n.º 1
0
static int icvt_s(FILE *f, va_list *args, int store, int width, int type){
#pragma ref type
	int c, nn;
	register char *s;
	if(store) s=va_arg(*args, char *);
	do
		c=ngetc(f);
	while(isspace(c));
	if(width--==0){
		nungetc(c, f);
		goto Done;
	}
	nn=0;
	while(!isspace(c)){
		if(c==EOF){
			if(nn==0) return 0;
			else goto Done;
		}
		nn++;
		if(store) *s++=c;
		wgetc(c, f, Done);
	}
	nungetc(c, f);
Done:
	if(store) *s='\0';
	return 1;
}
Ejemplo n.º 2
0
int vfscanf(FILE *f, const char *s, va_list args){
	int c, width, type, store;
	nread=0;
	ncvt=0;
	fmtp=s;
	for(;*fmtp;fmtp++) switch(*fmtp){
	default:
		if(isspace(*fmtp)){
			do
				c=ngetc(f);
			while(isspace(c));
			if(c==EOF) return ncvt?ncvt:EOF;
			nungetc(c, f);
			break;
		}
	NonSpecial:
		c=ngetc(f);
		if(c==EOF) return ncvt?ncvt:EOF;
		if(c!=*fmtp){
			nungetc(c, f);
			return ncvt;
		}
		break;
	case '%':
		fmtp++;
		if(*fmtp!='*') store=1;
		else{
			store=0;
			fmtp++;
		}
		if('0'<=*fmtp && *fmtp<='9'){
			width=0;
			while('0'<=*fmtp && *fmtp<='9') width=width*10 + *fmtp++ - '0';
		}
		else
			width=-1;
		type=*fmtp=='h' || *fmtp=='l' || *fmtp=='L'?*fmtp++:'n';
		if(!icvt[*fmtp]) goto NonSpecial;
		if(!(*icvt[*fmtp])(f, &args, store, width, type))
			return ncvt?ncvt:EOF;
		if(*fmtp=='\0') break;
		if(store) ncvt++;
	}
	return ncvt;	
}
Ejemplo n.º 3
0
extern	PacketClass
GL_RecvPacketClass(
	NETFILE	*fp)
{
	PacketClass	c;

	c = ngetc(fp);
	return	(c);
}
Ejemplo n.º 4
0
extern	PacketDataType
GL_RecvDataType(
	NETFILE	*fp)
{
	PacketClass	c;

	c = ngetc(fp);
	return	(c);
}
Ejemplo n.º 5
0
extern PacketClass RecvPacketClass(NETFILE *fp) {
  int tc;
  PacketClass c = (PacketClass)0x00;

  tc = ngetc(fp);
  if (tc >= 0) {
    c = tc;
  } else {
    Message("error RecvPacket");
  }
  return (c);
}
Ejemplo n.º 6
0
bool retKey( void)
{
	memset( key, '\0', 1);

	ssize_t size;

	if( (size = ngetc( key)) < 0 || *key == '\n'){
		ROS_DEBUG("Nothing key input\n");
		return false;
	}

	ROS_DEBUG("key = %c, size = %zd", *key, size);
	return true;
}
Ejemplo n.º 7
0
static int icvt_f(FILE *f, va_list *args, int store, int width, int type){
	char buf[NBUF+1];
	char *s=buf;
	int c, ndig=0, ndpt=0, nexp=1;
	if(width<0 || NBUF<width) width=NBUF;	/* bug -- no limit specified in ansi */
	do
		c=ngetc(f);
	while(isspace(c));
	if(width--==0){
		nungetc(c, f);
		goto Done;
	}
	if(c=='+' || c=='-'){
		*s++=c;
		wgetc(c, f, Done);
	}
	while('0'<=c && c<='9' || ndpt==0 && c=='.'){
		if(c=='.') ndpt++;
		else ndig++;
		*s++=c;
		wgetc(c, f, Done);
	}
	if(c=='e' || c=='E'){
		*s++=c;
		nexp=0;
		wgetc(c, f, Done);
		if(c=='+' || c=='-'){
			*s++=c;
			wgetc(c, f, Done);
		}
		while('0'<=c && c<='9'){
			*s++=c;
			nexp++;
			wgetc(c, f, Done);
		}
	}
	nungetc(c, f);
Done:
	if(ndig==0 || nexp==0) return 0;
	*s='\0';
	if(store) switch(type){
	case 'h':
	case 'n': *va_arg(*args, float *)=atof(buf); break;
	case 'L': /* bug -- should store in a long double */
	case 'l': *va_arg(*args, double *)=atof(buf); break;
	}
	return 1;
}
Ejemplo n.º 8
0
/*
 * Generic fixed-point conversion
 *	f is the input FILE *;
 *	args is the va_list * into which to store the number;
 *	store is a flag to enable storing;
 *	width is the maximum field width;
 *	type is 'h' 'l' or 'L', the scanf type modifier;
 *	unsgned is SIGNED, UNSIGNED or POINTER, giving part of the type to store in;
 *	base is the number base -- if 0, C number syntax is used.
 */
static int icvt_fixed(FILE *f, va_list *args,
				int store, int width, int type, int unsgned, int base){
	unsigned long int num=0;
	int sign=1, ndig=0, dig;
	int c;
	do
		c=ngetc(f);
	while(isspace(c));
	if(width--==0){
		nungetc(c, f);
		goto Done;
	}
	if(c=='+'){
		wgetc(c, f, Done);
	}
	else if(c=='-'){
		sign=-1;
		wgetc(c, f, Done);
	}
	switch(base){
	case 0:
		if(c=='0'){
			wgetc(c, f, Done);
			if(c=='x' || c=='X'){
				wgetc(c, f, Done);
				base=16;
			}
			else{
				ndig=1;
				base=8;
			}
		}
		else
			base=10;
		break;
	case 16:
		if(c=='0'){
			wgetc(c, f, Done);
			if(c=='x' || c=='X'){
				wgetc(c, f, Done);
			}
			else ndig=1;
		}
		break;
	}
	while('0'<=c && c<='9' || 'a'<=c && c<='f' || 'A'<=c && c<='F'){
		dig='0'<=c && c<='9'?c-'0':'a'<=c && c<='f'?c-'a'+10:c-'A'+10;
		if(dig>=base) break;
		ndig++;
		num=num*base+dig;
		wgetc(c, f, Done);
	}
	nungetc(c, f);
Done:
	if(ndig==0) return 0;
	if(store){
		switch(unsgned){
		case SIGNED:
			switch(type){
			case 'h': *va_arg(*args,  short *)=num*sign; break;
			case 'n': *va_arg(*args,  int *)=num*sign; break;
			case 'l':
			case 'L': *va_arg(*args,  long *)=num*sign; break;
			}
			break;
		case UNSIGNED:
			switch(type){
			case 'h': *va_arg(*args, unsigned short *)=num*sign; break;
			case 'n': *va_arg(*args, unsigned int *)=num*sign; break;
			case 'l':
			case 'L': *va_arg(*args, unsigned long *)=num*sign; break;
			}
			break;
		case POINTER:
			*va_arg(*args, void **)=(void *)(num*sign); break;
		}
	}
	return 1;
}
Ejemplo n.º 9
0
/* if not, set *psp to the first character beyond the number and return 1. */
int
scan_number(register const byte *sp, const byte *end, int sign,
  ref *pref, const byte **psp)
{	/* Powers of 10 up to 6 can be represented accurately as */
	/* a single-precision float. */
#define num_powers_10 6
	static const float powers_10[num_powers_10+1] =
	{	1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6	};
	static const double neg_powers_10[num_powers_10+1] =
	{	1e0, 1e-1, 1e-2, 1e-3, 1e-4, 1e-5, 1e-6	};
	int ival;
	long lval;
	double dval;
	int exp10;
	int code = 0;
	register int c, d;
	register const byte _ds *decoder = scan_char_decoder;
	ngetc(c, sp, return_error(e_syntaxerror));
#define would_overflow(val, d, maxv)\
  (val >= maxv / 10 && (val > maxv / 10 || d > (int)(maxv % 10)))
	if ( !is_digit(d, c) )
	{	if ( c != '.' )
			return_error(e_syntaxerror);
		/* Might be a number starting with '.'. */
		ngetc(c, sp, return_error(e_syntaxerror));
		if ( !is_digit(d, c) )
			return_error(e_syntaxerror);
		ival = 0;
		goto i2r;
	}

	/* Accumulate an integer in ival. */
	/* Do up to 4 digits without a loop, */
	/* since we know this can't overflow and since */
	/* most numbers have 4 (integer) digits or fewer. */
	ival = d;
	if ( end - sp >= 3 )		/* just check once */
	{	if ( !is_digit(d, (c = *sp)) )
		{	sp++;
			goto ind;
		}
		ival = ival * 10 + d;
		if ( !is_digit(d, (c = sp[1])) )
		{	sp += 2;
			goto ind;
		}
		ival = ival * 10 + d;
		sp += 3;
		if ( !is_digit(d, (c = sp[-1])) )
			goto ind;
		ival = ival * 10 + d;
	}
	for ( ; ; ival = ival * 10 + d )
	{	ngetc(c, sp, goto iret);
		if ( !is_digit(d, c) )
			break;
		if ( would_overflow(ival, d, max_int) )
			goto i2l;
	}
ind:	switch ( c )
	{
	case '.':
		ngetc(c, sp, c = EOFC);
		goto i2r;
	default:
		*psp = sp;
		code = 1;
		break;
	case 'e': case 'E':
		if ( sign < 0 )
			ival = -ival;
		dval = ival;
		exp10 = 0;
		goto fe;
	case '#':
	{	ulong uval = 0, lmax;
#define radix (uint)ival
		if ( sign || radix < min_radix || radix > max_radix )
			return_error(e_syntaxerror);
		/* Avoid multiplies for power-of-2 radix. */
		if ( !(radix & (radix - 1)) )
		{	int shift;
			switch ( radix )
			{
#define set_shift(n)\
  shift = n; lmax = max_ulong >> n
			case 2: set_shift(1); break;
			case 4: set_shift(2); break;
			case 8: set_shift(3); break;
			case 16: set_shift(4); break;
			case 32: set_shift(5); break;
#undef set_shift
			default:		/* can't happen */
			  return_error(e_rangecheck);
			}
			for ( ; ; uval = (uval << shift) + d )
			{	ngetc(c, sp, break);
				d = decoder[c];
				if ( d >= radix )
				{	*psp = sp;
					code = 1;
					break;
				}
				if ( uval > lmax )
					return_error(e_limitcheck);
			}
		}
		else
		{	int lrem = max_ulong % radix;
			lmax = max_ulong / radix;
			for ( ; ; uval = uval * radix + d )
			{	ngetc(c, sp, break);
				d = decoder[c];
				if ( d >= radix )
				{	*psp = sp;
					code = 1;
					break;
				}
				if ( uval >= lmax &&
				     (uval > lmax || d > lrem)
				   )
					return_error(e_limitcheck);
			}
		}
#undef radix
		make_int_new(pref, uval);
		return code;
	}