xref: /onnv-gate/usr/src/lib/libc/port/fp/file_decim.c (revision 6812:febeba71273d)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*6812Sraf  * Common Development and Distribution License (the "License").
6*6812Sraf  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
21*6812Sraf 
220Sstevel@tonic-gate /*
23*6812Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
29*6812Sraf #include "lint.h"
300Sstevel@tonic-gate #include "file64.h"
310Sstevel@tonic-gate #include "mtlib.h"
320Sstevel@tonic-gate #include <sys/types.h>
330Sstevel@tonic-gate #include <ctype.h>
340Sstevel@tonic-gate #include <stdio.h>
350Sstevel@tonic-gate #include "base_conversion.h"
360Sstevel@tonic-gate #include <locale.h>
370Sstevel@tonic-gate #include <thread.h>
380Sstevel@tonic-gate #include <synch.h>
390Sstevel@tonic-gate #include "stdiom.h"
400Sstevel@tonic-gate #include "libc.h"
410Sstevel@tonic-gate 
420Sstevel@tonic-gate /* if the _IOWRT flag is set, this must be a call from sscanf */
430Sstevel@tonic-gate #define	mygetc(iop)	((iop->_flag & _IOWRT) ? \
440Sstevel@tonic-gate 				((*iop->_ptr == '\0') ? EOF : *iop->_ptr++) : \
450Sstevel@tonic-gate 				GETC(iop))
460Sstevel@tonic-gate 
470Sstevel@tonic-gate #define	myungetc(x, iop)	((iop->_flag & _IOWRT) ? *(--iop->_ptr) : \
480Sstevel@tonic-gate 					UNGETC(x, iop))
490Sstevel@tonic-gate 
500Sstevel@tonic-gate 
510Sstevel@tonic-gate void
file_to_decimal(char ** ppc,int nmax,int fortran_conventions,decimal_record * pd,enum decimal_string_form * pform,char ** pechar,FILE * pf,int * pnread)520Sstevel@tonic-gate file_to_decimal(char **ppc, int nmax, int fortran_conventions,
530Sstevel@tonic-gate 		decimal_record *pd, enum decimal_string_form *pform,
540Sstevel@tonic-gate 		char **pechar, FILE *pf, int *pnread)
550Sstevel@tonic-gate {
560Sstevel@tonic-gate 	char	*cp = *ppc - 1;	/* last character seen */
570Sstevel@tonic-gate 	char	*good = cp;	/* last character accepted */
580Sstevel@tonic-gate 	int	current;	/* *cp or EOF */
590Sstevel@tonic-gate 	int	nread = 0;	/* number of characters read so far */
600Sstevel@tonic-gate 
610Sstevel@tonic-gate /* if the _IOWRT flag is set, this must be a call from sscanf */
620Sstevel@tonic-gate #define	NEXT \
630Sstevel@tonic-gate 	if (nread < nmax) { \
640Sstevel@tonic-gate 		current = ((pf->_flag & _IOWRT) ? \
650Sstevel@tonic-gate 		    ((*pf->_ptr == '\0') ? EOF : *pf->_ptr++) : \
660Sstevel@tonic-gate 		    GETC(pf)); \
670Sstevel@tonic-gate 		if (current != EOF) { \
680Sstevel@tonic-gate 			*++cp = (char)current; \
690Sstevel@tonic-gate 			nread++; \
700Sstevel@tonic-gate 		} \
710Sstevel@tonic-gate 	} else { \
720Sstevel@tonic-gate 		current = EOF; \
730Sstevel@tonic-gate 	}
740Sstevel@tonic-gate 
750Sstevel@tonic-gate 	NEXT;
760Sstevel@tonic-gate 
770Sstevel@tonic-gate #include "char_to_decimal.h"
780Sstevel@tonic-gate 
790Sstevel@tonic-gate 	/*
800Sstevel@tonic-gate 	 * If we read any characters beyond the end of the accepted
810Sstevel@tonic-gate 	 * token, try to push them back.
820Sstevel@tonic-gate 	 */
830Sstevel@tonic-gate 	if (fortran_conventions < 0) {
840Sstevel@tonic-gate 		/* in C99 mode, push back at most one character */
850Sstevel@tonic-gate 		if (cp >= *ppc && current != EOF && myungetc(current, pf)
860Sstevel@tonic-gate 		    != EOF) {
870Sstevel@tonic-gate 			cp--;
880Sstevel@tonic-gate 			nread--;
890Sstevel@tonic-gate 		}
900Sstevel@tonic-gate 	} else {
910Sstevel@tonic-gate 		while (cp >= *ppc) {
920Sstevel@tonic-gate 			if (myungetc((int)(unsigned char)*cp, pf) == EOF)
930Sstevel@tonic-gate 				break;
940Sstevel@tonic-gate 			cp--;
950Sstevel@tonic-gate 			nread--;
960Sstevel@tonic-gate 		}
970Sstevel@tonic-gate 	}
980Sstevel@tonic-gate 
990Sstevel@tonic-gate 	*++cp = '\0';
1000Sstevel@tonic-gate 	*pnread = nread;
1010Sstevel@tonic-gate }
102