|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T n
Length: 1882 (0x75a)
Types: TextFile
Names: »number.c«
└─⟦db229ac7e⟧ Bits:30007240 EUUGD20: SSBA 1.2 / AFW Benchmarks
└─⟦this⟧ »EUUGD20/AFUU-ssba1.21/ssba1.21E/musbus/number.c«
└─⟦this⟧ »EUUGD20/AFUU-ssba1.21/ssba1.21F/musbus/number.c«
/* Copyright (c) 1982, 1985 Gary Perlman */
/* Copies can be made if not for material gain */
#include <ctype.h>
#ifndef lint
static char sccsfid[] = "@(#) number.c 5.2 (unix|stat) 9/1/85";
#endif
#define IS_NOT 0 /* not a number */
#define IS_INT 1 /* an integer */
#define IS_REAL 2 /* a real number */
#define EOS '\0'
/*LINTLIBRARY*/
number (string)
char *string; /* the string to be tested */
{
int answer = IS_INT; /* start by assuming it is an integer */
int before = 0; /* anything before the decimal? */
int after = 0; /* anything after the decimal? */
while (isspace (*string)) /* skip over blank space */
string++;
if (*string == EOS) /* empty string not allowed */
return (IS_NOT);
if (*string == '+' || *string == '-') /* old atoi didn't allow '+' */
{
string++;
if (!isdigit (*string) && *string != '.')
return (IS_NOT);
}
if (isdigit (*string)) /* note that there was a digit before . */
{
before = 1;
while (isdigit (*string))
string++;
}
if (*string == '.') /* found a decimal point, parse for real */
{
answer = IS_REAL;
string++;
if (isdigit (*string)) /* note that there was a digit after . */
{
after = 1;
while (isdigit (*string))
string++;
}
}
if (!before && !after) /* must be digit somewhere */
return (IS_NOT);
if (*string == 'E' || *string == 'e') /* exponent */
{
answer = IS_REAL;
string++;
if (*string == '+' || *string == '-') /* optional sign */
string++;
if (!isdigit (*string)) /* missing exponent */
return (IS_NOT);
while (isdigit (*string))
string++;
}
while (isspace (*string)) /* skip optional spaces */
string++;
/* should now have exhausted the input string */
return (*string == EOS ? answer : IS_NOT);
}