- To make it easier to compile *printf() and *scanf() without
floating-point support, remove default definition of FLOATING_POINT from the source, and change the compile-time option to NO_FLOATING_POINT. - Remove the HEXFLOAT option. It saves an insignificant amount of space (<0.1% of the size of libc on i386) and complicates vfprintf() and checkfmt().
This commit is contained in:
parent
38d17374b2
commit
8de9e89719
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=128819
@ -66,10 +66,6 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include "local.h"
|
#include "local.h"
|
||||||
#include "fvwrite.h"
|
#include "fvwrite.h"
|
||||||
|
|
||||||
/* Define FLOATING_POINT to get floating point, HEXFLOAT to get %a. */
|
|
||||||
#define FLOATING_POINT
|
|
||||||
#define HEXFLOAT
|
|
||||||
|
|
||||||
union arg {
|
union arg {
|
||||||
int intarg;
|
int intarg;
|
||||||
u_int uintarg;
|
u_int uintarg;
|
||||||
@ -91,7 +87,7 @@ union arg {
|
|||||||
ptrdiff_t *pptrdiffarg;
|
ptrdiff_t *pptrdiffarg;
|
||||||
size_t *psizearg;
|
size_t *psizearg;
|
||||||
intmax_t *pintmaxarg;
|
intmax_t *pintmaxarg;
|
||||||
#ifdef FLOATING_POINT
|
#ifndef NO_FLOATING_POINT
|
||||||
double doublearg;
|
double doublearg;
|
||||||
long double longdoublearg;
|
long double longdoublearg;
|
||||||
#endif
|
#endif
|
||||||
@ -411,7 +407,7 @@ vfprintf(FILE * __restrict fp, const char * __restrict fmt0, va_list ap)
|
|||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FLOATING_POINT
|
#ifndef NO_FLOATING_POINT
|
||||||
|
|
||||||
#define dtoa __dtoa
|
#define dtoa __dtoa
|
||||||
#define freedtoa __freedtoa
|
#define freedtoa __freedtoa
|
||||||
@ -425,7 +421,7 @@ vfprintf(FILE * __restrict fp, const char * __restrict fmt0, va_list ap)
|
|||||||
|
|
||||||
static int exponent(char *, int, int);
|
static int exponent(char *, int, int);
|
||||||
|
|
||||||
#endif /* FLOATING_POINT */
|
#endif /* !NO_FLOATING_POINT */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The size of the buffer we use as scratch space for integer
|
* The size of the buffer we use as scratch space for integer
|
||||||
@ -474,7 +470,7 @@ __vfprintf(FILE *fp, const char *fmt0, va_list ap)
|
|||||||
char sign; /* sign prefix (' ', '+', '-', or \0) */
|
char sign; /* sign prefix (' ', '+', '-', or \0) */
|
||||||
char thousands_sep; /* locale specific thousands separator */
|
char thousands_sep; /* locale specific thousands separator */
|
||||||
const char *grouping; /* locale specific numeric grouping rules */
|
const char *grouping; /* locale specific numeric grouping rules */
|
||||||
#ifdef FLOATING_POINT
|
#ifndef NO_FLOATING_POINT
|
||||||
/*
|
/*
|
||||||
* We can decompose the printed representation of floating
|
* We can decompose the printed representation of floating
|
||||||
* point numbers into several parts, some of which may be empty:
|
* point numbers into several parts, some of which may be empty:
|
||||||
@ -641,7 +637,7 @@ __vfprintf(FILE *fp, const char *fmt0, va_list ap)
|
|||||||
thousands_sep = '\0';
|
thousands_sep = '\0';
|
||||||
grouping = NULL;
|
grouping = NULL;
|
||||||
convbuf = NULL;
|
convbuf = NULL;
|
||||||
#ifdef FLOATING_POINT
|
#ifndef NO_FLOATING_POINT
|
||||||
dtoaresult = NULL;
|
dtoaresult = NULL;
|
||||||
decimal_point = localeconv()->decimal_point;
|
decimal_point = localeconv()->decimal_point;
|
||||||
#endif
|
#endif
|
||||||
@ -762,7 +758,7 @@ reswitch: switch (ch) {
|
|||||||
}
|
}
|
||||||
width = n;
|
width = n;
|
||||||
goto reswitch;
|
goto reswitch;
|
||||||
#ifdef FLOATING_POINT
|
#ifndef NO_FLOATING_POINT
|
||||||
case 'L':
|
case 'L':
|
||||||
flags |= LONGDBL;
|
flags |= LONGDBL;
|
||||||
goto rflag;
|
goto rflag;
|
||||||
@ -836,8 +832,7 @@ reswitch: switch (ch) {
|
|||||||
}
|
}
|
||||||
base = 10;
|
base = 10;
|
||||||
goto number;
|
goto number;
|
||||||
#ifdef FLOATING_POINT
|
#ifndef NO_FLOATING_POINT
|
||||||
#ifdef HEXFLOAT
|
|
||||||
case 'a':
|
case 'a':
|
||||||
case 'A':
|
case 'A':
|
||||||
if (ch == 'a') {
|
if (ch == 'a') {
|
||||||
@ -869,7 +864,6 @@ reswitch: switch (ch) {
|
|||||||
if (expt == INT_MAX)
|
if (expt == INT_MAX)
|
||||||
ox[1] = '\0';
|
ox[1] = '\0';
|
||||||
goto fp_common;
|
goto fp_common;
|
||||||
#endif /* HEXFLOAT */
|
|
||||||
case 'e':
|
case 'e':
|
||||||
case 'E':
|
case 'E':
|
||||||
expchar = ch;
|
expchar = ch;
|
||||||
@ -971,7 +965,7 @@ reswitch: switch (ch) {
|
|||||||
lead = expt;
|
lead = expt;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif /* FLOATING_POINT */
|
#endif /* !NO_FLOATING_POINT */
|
||||||
case 'n':
|
case 'n':
|
||||||
/*
|
/*
|
||||||
* Assignment-like behavior is specified if the
|
* Assignment-like behavior is specified if the
|
||||||
@ -1176,7 +1170,7 @@ number: if ((dprec = prec) >= 0)
|
|||||||
PAD(dprec - size, zeroes);
|
PAD(dprec - size, zeroes);
|
||||||
|
|
||||||
/* the string or number proper */
|
/* the string or number proper */
|
||||||
#ifdef FLOATING_POINT
|
#ifndef NO_FLOATING_POINT
|
||||||
if ((flags & FPT) == 0) {
|
if ((flags & FPT) == 0) {
|
||||||
PRINT(cp, size);
|
PRINT(cp, size);
|
||||||
} else { /* glue together f_p fragments */
|
} else { /* glue together f_p fragments */
|
||||||
@ -1239,7 +1233,7 @@ number: if ((dprec = prec) >= 0)
|
|||||||
done:
|
done:
|
||||||
FLUSH();
|
FLUSH();
|
||||||
error:
|
error:
|
||||||
#ifdef FLOATING_POINT
|
#ifndef NO_FLOATING_POINT
|
||||||
if (dtoaresult != NULL)
|
if (dtoaresult != NULL)
|
||||||
freedtoa(dtoaresult);
|
freedtoa(dtoaresult);
|
||||||
#endif
|
#endif
|
||||||
@ -1373,7 +1367,7 @@ reswitch: switch (ch) {
|
|||||||
}
|
}
|
||||||
width = n;
|
width = n;
|
||||||
goto reswitch;
|
goto reswitch;
|
||||||
#ifdef FLOATING_POINT
|
#ifndef NO_FLOATING_POINT
|
||||||
case 'L':
|
case 'L':
|
||||||
flags |= LONGDBL;
|
flags |= LONGDBL;
|
||||||
goto rflag;
|
goto rflag;
|
||||||
@ -1420,11 +1414,9 @@ reswitch: switch (ch) {
|
|||||||
case 'i':
|
case 'i':
|
||||||
ADDSARG();
|
ADDSARG();
|
||||||
break;
|
break;
|
||||||
#ifdef FLOATING_POINT
|
#ifndef NO_FLOATING_POINT
|
||||||
#ifdef HEXFLOAT
|
|
||||||
case 'a':
|
case 'a':
|
||||||
case 'A':
|
case 'A':
|
||||||
#endif
|
|
||||||
case 'e':
|
case 'e':
|
||||||
case 'E':
|
case 'E':
|
||||||
case 'f':
|
case 'f':
|
||||||
@ -1435,7 +1427,7 @@ reswitch: switch (ch) {
|
|||||||
else
|
else
|
||||||
ADDTYPE(T_DOUBLE);
|
ADDTYPE(T_DOUBLE);
|
||||||
break;
|
break;
|
||||||
#endif /* FLOATING_POINT */
|
#endif /* !NO_FLOATING_POINT */
|
||||||
case 'n':
|
case 'n':
|
||||||
if (flags & INTMAXT)
|
if (flags & INTMAXT)
|
||||||
ADDTYPE(TP_INTMAXT);
|
ADDTYPE(TP_INTMAXT);
|
||||||
@ -1555,7 +1547,7 @@ reswitch: switch (ch) {
|
|||||||
case TP_INTMAXT:
|
case TP_INTMAXT:
|
||||||
(*argtable) [n].pintmaxarg = va_arg (ap, intmax_t *);
|
(*argtable) [n].pintmaxarg = va_arg (ap, intmax_t *);
|
||||||
break;
|
break;
|
||||||
#ifdef FLOATING_POINT
|
#ifndef NO_FLOATING_POINT
|
||||||
case T_DOUBLE:
|
case T_DOUBLE:
|
||||||
(*argtable) [n].doublearg = va_arg (ap, double);
|
(*argtable) [n].doublearg = va_arg (ap, double);
|
||||||
break;
|
break;
|
||||||
@ -1612,7 +1604,7 @@ __grow_type_table (int nextarg, enum typeid **typetable, int *tablesize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef FLOATING_POINT
|
#ifndef NO_FLOATING_POINT
|
||||||
|
|
||||||
static int
|
static int
|
||||||
exponent(char *p0, int exp, int fmtch)
|
exponent(char *p0, int exp, int fmtch)
|
||||||
@ -1649,4 +1641,4 @@ exponent(char *p0, int exp, int fmtch)
|
|||||||
}
|
}
|
||||||
return (p - p0);
|
return (p - p0);
|
||||||
}
|
}
|
||||||
#endif /* FLOATING_POINT */
|
#endif /* !NO_FLOATING_POINT */
|
||||||
|
@ -56,9 +56,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include "libc_private.h"
|
#include "libc_private.h"
|
||||||
#include "local.h"
|
#include "local.h"
|
||||||
|
|
||||||
#define FLOATING_POINT
|
#ifndef NO_FLOATING_POINT
|
||||||
|
|
||||||
#ifdef FLOATING_POINT
|
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -254,7 +252,7 @@ again: c = *fmt++;
|
|||||||
base = 16;
|
base = 16;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#ifdef FLOATING_POINT
|
#ifndef NO_FLOATING_POINT
|
||||||
case 'A': case 'E': case 'F': case 'G':
|
case 'A': case 'E': case 'F': case 'G':
|
||||||
case 'a': case 'e': case 'f': case 'g':
|
case 'a': case 'e': case 'f': case 'g':
|
||||||
c = CT_FLOAT;
|
c = CT_FLOAT;
|
||||||
@ -768,7 +766,7 @@ again: c = *fmt++;
|
|||||||
nconversions++;
|
nconversions++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#ifdef FLOATING_POINT
|
#ifndef NO_FLOATING_POINT
|
||||||
case CT_FLOAT:
|
case CT_FLOAT:
|
||||||
/* scan a floating point number as if by strtod */
|
/* scan a floating point number as if by strtod */
|
||||||
if (width == 0 || width > sizeof(buf) - 1)
|
if (width == 0 || width > sizeof(buf) - 1)
|
||||||
@ -793,7 +791,7 @@ again: c = *fmt++;
|
|||||||
nread += width;
|
nread += width;
|
||||||
nconversions++;
|
nconversions++;
|
||||||
break;
|
break;
|
||||||
#endif /* FLOATING_POINT */
|
#endif /* !NO_FLOATING_POINT */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
input_failure:
|
input_failure:
|
||||||
@ -915,7 +913,7 @@ __sccl(tab, fmt)
|
|||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FLOATING_POINT
|
#ifndef NO_FLOATING_POINT
|
||||||
static int
|
static int
|
||||||
parsefloat(FILE *fp, char *buf, char *end)
|
parsefloat(FILE *fp, char *buf, char *end)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user