Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

ungetc(3S)

STRING_TO_DECIMAL(3)  —  C LIBRARY FUNCTIONS

NAME

string_to_decimal, file_to_decimal, func_to_decimal − parse characters into decimal record

SYNOPSIS

#include <floatingpoint.h>
#include <stdio.h>

void string_to_decimal(pc,nmax,fortran_conventions,pd,pform,pechar)
char ∗∗pc;
int nmax;
int fortran_conventions;
decimal_record ∗pd;
enum decimal_string_form ∗pform;
char ∗∗pechar;

void file_to_decimal(pc,nmax,fortran_conventions,pd,pform,pechar,pf,pnread)
char ∗∗pc;
int nmax;
int fortran_conventions;
decimal_record ∗pd;
enum decimal_string_form ∗pform;
char ∗∗pechar;
FILE ∗pf;
int ∗pnread;

void func_to_decimal(pc,nmax,fortran_conventions,pd,pform,pechar,pget,pnread,punget)
char ∗∗pc;
int nmax;
int fortran_conventions;
decimal_record ∗pd;
enum decimal_string_form ∗pform;
char ∗∗pechar;
int (∗pget)();
int ∗pnread;
int (∗punget)();

DESCRIPTION

The char_to_decimal functions parse a numeric token from at most nmax characters in a string ∗∗pc or file ∗pf or function (∗pget)() into a decimal record ∗pd, classifying the form of the string in ∗pform and ∗pechar.  The accepted syntax is intended to be sufficiently flexible to accomodate many languages:

<white space> <value>
or
<white space> <sign> <value>

where <whitespace> is any number of characters defined by isspace in /usr/include/ctype.h, <sign> is either of [+-], and <value> can be <number>, <nan>, or <inf>.  <inf> can be "INF" (inf_form) or "INFINITY" (infinity_form) without regard to case.  <nan> can be "NAN" (nan_form) or "NAN(<string>)" (nanstring_form) without regard to case; <string> is any string of characters not containing ’)’ or null; <string> is copied to pd->ds and, currently, not used subsequently.  <number> consists of

<significand>
or
<significand> <efield>

where <significand> must contain one or more digits and may contain one point; possible forms are

<digits>(int_form)
<digits>.(intdot_form)
.<digits>(dotfrac_form)
<digits>.<digits>(intdotfrac_form)

<efield> consists of

<echar> <digits>
or
<echar> <sign> <digits>

where <echar> is one of [Ee], and <digits> contains one or more digits. 

When fortran_conventions is nonzero, additional input forms are accepted according to various Fortran conventions:

0no Fortran conventions
1Fortran list-directed input conventions
2Fortran formatted input conventions, ignore blanks (BN)
3Fortran formatted input conventions, blanks are zeros (BZ)

When fortran_conventions is nonzero, <echar> may also be one of [Dd], and <efield> may also have the form

<sign> <digits>.

When fortran_conventions>= 2, blanks may appear in the <digits> strings for the integer, fraction, and exponent fields and may appear between <echar> and the exponent sign and after the infinity and NaN forms. If fortran_conventions== 2, the blanks are ignored. When fortran_conventions== 3, the blanks that appear in <digits> strings are interpreted as zeros, and other blanks are ignored.

The form of the accepted decimal string is placed in ∗peform.  If an <efield> is recognized, ∗pechar is set to point to the <echar>. 

On input, ∗pc points to the beginning of a character string buffer of length >= nmax.  On output, ∗pc points to a character in that buffer, one past the last accepted character.  String_to_decimal gets its characters from the buffer; file_to_decimal gets its characters from ∗pf and records them in the buffer, and places a null after the last character read.  func_to_decimal gets its characters from an int function (∗pget)(). 

The scan continues until no more characters could possibly fit the acceptable syntax or until nmax characters have been scanned.  If the nmax limit is not reached then at least one extra character will usually be scanned that is not part of the accepted syntax.  File_to_decimal and func_to_decimal set ∗pnread to the number of characters read from the file; if greater than nmax, some characters were lost.  If no characters were lost, file_to_decimal and func_to_decimal attempt to push back, with ungetc(3S) or (∗punget)(), as many as possible of the excess characters read, adjusting ∗pnread accordingly.  If all unget calls are successful, then ∗∗pc will be NULL. No push back will be attempted if (∗punget)() is NULL.

Typical declarations for ∗pget() and ∗punget() are:

 int xget()
{ ...  }
int (∗pget)() = xget ;
int xunget(c)
char c ;
{ ... }
int (∗punget)() = xunget ;

If no valid number was detected, pd->class is set to fp_signaling, ∗pc is unchanged, and ∗pform is set to invalid_form. 

atof(3) and strtod(3) use string_to_decimal.  scanf(3S) uses file_to_decimal. 

SEE ALSO

ungetc(3S)

Sun Release 3.2  —  Last change: 2 December 1986

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026