1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 #pragma weak file_to_decimal = _file_to_decimal 30 31 #include "synonyms.h" 32 #include "file64.h" 33 #include "mtlib.h" 34 #include <sys/types.h> 35 #include <ctype.h> 36 #include <stdio.h> 37 #include "base_conversion.h" 38 #include <locale.h> 39 #include <thread.h> 40 #include <synch.h> 41 #include "stdiom.h" 42 #include "libc.h" 43 44 /* if the _IOWRT flag is set, this must be a call from sscanf */ 45 #define mygetc(iop) ((iop->_flag & _IOWRT) ? \ 46 ((*iop->_ptr == '\0') ? EOF : *iop->_ptr++) : \ 47 GETC(iop)) 48 49 #define myungetc(x, iop) ((iop->_flag & _IOWRT) ? *(--iop->_ptr) : \ 50 UNGETC(x, iop)) 51 52 53 void 54 file_to_decimal(char **ppc, int nmax, int fortran_conventions, 55 decimal_record *pd, enum decimal_string_form *pform, 56 char **pechar, FILE *pf, int *pnread) 57 { 58 char *cp = *ppc - 1; /* last character seen */ 59 char *good = cp; /* last character accepted */ 60 int current; /* *cp or EOF */ 61 int nread = 0; /* number of characters read so far */ 62 63 /* if the _IOWRT flag is set, this must be a call from sscanf */ 64 #define NEXT \ 65 if (nread < nmax) { \ 66 current = ((pf->_flag & _IOWRT) ? \ 67 ((*pf->_ptr == '\0') ? EOF : *pf->_ptr++) : \ 68 GETC(pf)); \ 69 if (current != EOF) { \ 70 *++cp = (char)current; \ 71 nread++; \ 72 } \ 73 } else { \ 74 current = EOF; \ 75 } 76 77 NEXT; 78 79 #include "char_to_decimal.h" 80 81 /* 82 * If we read any characters beyond the end of the accepted 83 * token, try to push them back. 84 */ 85 if (fortran_conventions < 0) { 86 /* in C99 mode, push back at most one character */ 87 if (cp >= *ppc && current != EOF && myungetc(current, pf) 88 != EOF) { 89 cp--; 90 nread--; 91 } 92 } else { 93 while (cp >= *ppc) { 94 if (myungetc((int)(unsigned char)*cp, pf) == EOF) 95 break; 96 cp--; 97 nread--; 98 } 99 } 100 101 *++cp = '\0'; 102 *pnread = nread; 103 } 104