doscan.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1988-1995, by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/* Copyright (c) 1984 AT&T */
/* All Rights Reserved */
/*LINTLIBRARY*/
#include <stdio.h>
#include <ctype.h>
#include <varargs.h>
#include <values.h>
#include <floatingpoint.h>
#include <errno.h>
extern char *memset();
#ifdef S5EMUL
#else
/*
* _sptab[c+1] is 1 iff 'c' is a white space character according to the
* 4.2BSD "scanf" definition - namely, SP, TAB, and NL are the only
* whitespace characters.
*/
0, /* EOF - not a whitespace char */
0,0,0,0,0,0,0,0,
0,1,1,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
1,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
};
#endif
int
register unsigned char *fmt;
{
extern unsigned char *setup();
register int ch;
/*******************************************************
* Main loop: reads format to determine a pattern,
* and then goes to read input stream
* in attempt to match the pattern.
*******************************************************/
for ( ; ; )
{
return(nmatch); /* end of format */
{
if (!flag_eof)
{
;
chcount--;
flag_eof = 1;
}
flag_eof = 1;
}
continue;
}
{
continue;
return(nmatch); /* failed to match input */
} else {
chcount--;
}
break;
}
if (ch == '*')
{
stow = 0;
}
else
stow = 1;
if (len == 0)
if (ch == '\0' ||
return(EOF); /* unexpected end of format */
{
/*
* The rationale behind excluding the size
* of 'L' is that the 'L' size specifier was
* specifies a format of %LG, it can mean
* nothing other than "long double", be the
* code ANSI or not. Mapping it to "double"
* makes no sense.
*/
if (size != 'L')
size = 'l';
#ifdef S5EMUL
#else
#endif
}
switch(ch)
{
case 'c':
case 's':
case '[':
goto out; /* EOF seen, nothing converted */
break;
case 'n':
if (stow == 0)
continue;
if (size == 'h')
else if (size == 'l')
else
continue;
default:
goto out; /* EOF seen, nothing converted */
break;
}
if (size)
else
continue;
}
out:
}
/***************************************************************
* Functions to read the input stream in an attempt to match incoming
* data to the current pattern from the main loop of _doscan().
***************************************************************/
static int
{
register int c, base;
long lcval = 0;
switch(type)
{
case 'e':
case 'f':
case 'g':
floater++;
case 'd':
case 'u':
case 'i':
base = 10;
break;
case 'o':
base = 8;
break;
case 'x':
base = 16;
break;
default:
return(0); /* unrecognized conversion character */
}
if (!flag_eof)
{
;
}
else
c = locgetc();
if (c == EOF) {
chcount--;
return(-1); /* EOF before match */
}
if (floater != 0) { /* Handle floating point with
* file_to_decimal. */
enum decimal_string_form form;
char *echar;
char buffer[1024];
locungetc(c);
if (len > 1024)
len = 1024;
} else {/* single */
}
}
}
}
c = *nb; /* Get first unused character. */
ic = c;
if (c == NULL) {
c = ic;
/*
* If null, first unused may have been put back
* already.
*/
}
chcount--;
flag_eof = 1;
flag_eof = 1;
* non-zero */
}
switch(c) {
case '-':
negflg++;
if (type == 'u')
break;
case '+': /* fall-through */
if (--len <= 0)
break;
if ( (c = locgetc()) != '0')
break;
case '0':
break;
{
/* If not using sscanf and *
* at the buffer's end *
* then LOOK ahead */
else
{
else
chcount += 1;
}
{
base =16;
if ( len <= 2)
{
}
else
{
c = lookahead;
}
}
else
{
}
}
else
{
base = 8;
}
}
{
{
return(0);
}
if (isdigit(c))
{
register int digit;
digit = c - '0';
if (base == 8)
{
if (digit >= 8)
break;
if (stow)
}
else
{
if (stow)
{
if (base == 10)
else /* base == 16 */
}
}
digitseen++;
continue;
}
{
register int digit;
if (stow)
digitseen++;
continue;
}
break;
}
{
/* suppress possible overflow on 2's-comp negation */
if (size == 'l')
else if (size == 'h')
else
}
if (c == EOF) {
chcount--;
flag_eof=1;
flag_eof=1;
return (digitseen); /* successful match if non-zero */
}
static int
register char *tab;
{
register int ch;
register char *ptr;
char *start;
if (type == 's')
{
if (!flag_eof)
{
;
}
else
return(-1); /* EOF before match */
{
if (stow)
ptr++;
if (--len <= 0)
break;
}
} else if (type == 'c') {
len = 1;
{
if (stow)
ptr++;
if (--len <= 0)
break;
}
} else { /* type == '[' */
{
if (stow)
ptr++;
if (--len <= 0)
break;
}
}
{
chcount-=1;
flag_eof = 1;
}
flag_eof = 1;
return(0); /* no match */
*ptr = '\0';
return (1); /* successful match */
}
static unsigned char *
register unsigned char *fmt;
register char *tab;
{
register int b, c, d, t = 0;
if (*fmt == '^')
{
t++;
fmt++;
}
{
tab[c] = t;
fmt++;
}
while ( (c = *fmt++) != ']')
{
if (c == '\0')
return(NULL); /* unexpected end of format */
{
fmt++;
}
else
tab[c] = t;
}
return (fmt);
}