summaryrefslogtreecommitdiff
path: root/lib/snprintf.c
diff options
context:
space:
mode:
authorAlain Magloire <alainm@gnu.org>2001-05-04 03:58:27 +0000
committerAlain Magloire <alainm@gnu.org>2001-05-04 03:58:27 +0000
commite94e8805cc5b73ef8710f58892fbce83d074b084 (patch)
tree3e7f59d660e545cfa5fb56c81ab558fd054d727f /lib/snprintf.c
parente73d4524f0675ee2050d6dc0c932f7deb83f29af (diff)
downloadmailutils-e94e8805cc5b73ef8710f58892fbce83d074b084.tar.gz
mailutils-e94e8805cc5b73ef8710f58892fbce83d074b084.tar.bz2
Patches from Sergey, se Changelog for details:
2001-04-23 Sergey Poznyakoff
Diffstat (limited to 'lib/snprintf.c')
-rw-r--r--lib/snprintf.c66
1 files changed, 33 insertions, 33 deletions
diff --git a/lib/snprintf.c b/lib/snprintf.c
index 9ea33b099..9e039120a 100644
--- a/lib/snprintf.c
+++ b/lib/snprintf.c
@@ -2,21 +2,21 @@
/*
Unix snprintf implementation.
Version 1.3
-
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
-
+
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
+
Revision History:
1.3:
@@ -55,7 +55,7 @@ pow_10(int n)
pow_10(n)
int n;
#endif
-{
+{
int i;
double P;
@@ -67,7 +67,7 @@ int n;
}
/*
- * Find the integral part of the log in base 10
+ * Find the integral part of the log in base 10
* Note: this not a real log10()
I just need and approximation(integerpart) of x in:
10^x ~= r
@@ -81,7 +81,7 @@ log_10(double r)
log_10(r)
double r;
#endif
-{
+{
int i = 0;
double result = 1.;
@@ -110,7 +110,7 @@ integral(real, ip)
double real;
double * ip;
#endif
-{
+{
int j;
double i, s, p;
double real_integral = 0.;
@@ -144,11 +144,11 @@ double * ip;
}
#define PRECISION 1.e-6
-/*
+/*
* return an ascii representation of the integral part of the number
* and set fract to be an ascii representation of the fraction part
* the container for the fraction and the integral part or staticly
- * declare with fix size
+ * declare with fix size
*/
PRIVATE char *
#ifdef __STDC__
@@ -171,7 +171,7 @@ char ** fract;
int ch;
/* taking care of the obvious case: 0.0 */
- if (number == 0.) {
+ if (number == 0.) {
integral_part[0] = '0';
integral_part[1] = '\0';
fraction_part[0] = '0';
@@ -183,7 +183,7 @@ char ** fract;
if ((sign = number) < 0.) {
number = -number;
digits--; /* sign consume one digit */
- }
+ }
fraction = integral(number, &ip);
number = ip;
@@ -198,11 +198,11 @@ char ** fract;
ch = (int)((fp + PRECISION)*base); /* force to round */
integral_part[i] = (ch <= 9) ? ch + '0' : ch + 'a' - 10;
if (! isxdigit(integral_part[i])) /* bail out overflow !! */
- break;
+ break;
number = ip;
}
}
-
+
/* Oh No !! out of bound, ho well fill it up ! */
if (number != 0.)
for (i = 0; i < digits; ++i)
@@ -216,7 +216,7 @@ char ** fract;
/* reverse every thing */
for ( i--, j = 0; j < i; j++, i--)
- SWAP_INT(integral_part[i], integral_part[j]);
+ SWAP_INT(integral_part[i], integral_part[j]);
/* the fractionnal part */
for (i=0, fp=fraction; precision > 0 && i < MAX_FRACT ; i++, precision-- ) {
@@ -354,7 +354,7 @@ double d;
((d > 0. && p->justify == RIGHT) ? 1:0) -
((p->space == FOUND) ? 1:0) -
strlen(tmp) - p->precision - 1;
- PAD_RIGHT(p);
+ PAD_RIGHT(p);
PUT_PLUS(d, p);
PUT_SPACE(d, p);
while (*tmp) { /* the integral */
@@ -365,12 +365,12 @@ double d;
PUT_CHAR('.', p); /* put the '.' */
if (*p->pf == 'g' || *p->pf == 'G') /* smash the trailing zeros */
for (i = strlen(tmp2) - 1; i >= 0 && tmp2[i] == '0'; i--)
- tmp2[i] = '\0';
+ tmp2[i] = '\0';
for (; *tmp2; tmp2++)
PUT_CHAR(*tmp2, p); /* the fraction */
-
+
PAD_LEFT(p);
-}
+}
/* %e %E %g exponent representation */
PRIVATE void
@@ -388,12 +388,12 @@ double d;
DEF_PREC(p);
j = log_10(d);
d = d / pow_10(j); /* get the Mantissa */
- d = ROUND(d, p);
+ d = ROUND(d, p);
tmp = dtoa(d, p->precision, &tmp2);
/* 1 for unit, 1 for the '.', 1 for 'e|E',
* 1 for '+|-', 3 for 'exp' */
/* calculate how much padding need */
- p->width = p->width -
+ p->width = p->width -
((d > 0. && p->justify == RIGHT) ? 1:0) -
((p->space == FOUND) ? 1:0) - p->precision - 7;
PAD_RIGHT(p);
@@ -407,7 +407,7 @@ double d;
PUT_CHAR('.', p); /* the '.' */
if (*p->pf == 'g' || *p->pf == 'G') /* smash the trailing zeros */
for (i = strlen(tmp2) - 1; i >= 0 && tmp2[i] == '0'; i--)
- tmp2[i] = '\0';
+ tmp2[i] = '\0';
for (; *tmp2; tmp2++)
PUT_CHAR(*tmp2, p); /* the fraction */
@@ -470,7 +470,7 @@ struct DATA * p;
case '1': case '2': case '3':
case '4': case '5': case '6':
case '7': case '8': case '9': /* gob all the digits */
- for (i = 0; isdigit(*s); i++, s++)
+ for (i = 0; isdigit(*s); i++, s++)
if (i < MAX_FIELD/2 - 1)
number[i] = *s;
number[i] = '\0';
@@ -524,10 +524,10 @@ va_list args;
case 'f': /* float, double */
STAR_ARGS(&data);
d = va_arg(args, double);
- floating(&data, d);
+ floating(&data, d);
state = 0;
break;
- case 'g':
+ case 'g':
case 'G':
STAR_ARGS(&data);
DEF_PREC(&data);
@@ -559,7 +559,7 @@ va_list args;
d = va_arg(args, unsigned int);
decimal(&data, d);
state = 0;
- break;
+ break;
case 'd': /* decimal */
STAR_ARGS(&data);
if (data.a_long == FOUND)
@@ -578,7 +578,7 @@ va_list args;
octal(&data, d);
state = 0;
break;
- case 'x':
+ case 'x':
case 'X': /* hexadecimal */
STAR_ARGS(&data);
if (data.a_long == FOUND)
@@ -612,11 +612,11 @@ va_list args;
state = 0;
break;
case '#': case ' ': case '+': case '*':
- case '-': case '.': case '0': case '1':
+ case '-': case '.': case '0': case '1':
case '2': case '3': case '4': case '5':
case '6': case '7': case '8': case '9':
/* initialize width and precision */
- for (i = 0; isflag(*data.pf); i++, data.pf++)
+ for (i = 0; isflag(*data.pf); i++, data.pf++)
if (i < MAX_FIELD - 1)
conv_field[i] = *data.pf;
conv_field[i] = '\0';
@@ -642,7 +642,7 @@ va_list args;
#ifndef HAVE_SNPRINTF
PUBLIC int
-#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
+#if __STDC__
snprintf(char *string, size_t length, const char * format, ...)
#else
snprintf(string, length, format, va_alist)
@@ -655,7 +655,7 @@ va_dcl
int rval;
va_list args;
-#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
+#if __STDC__
va_start(args, format);
#else
va_start(args);
@@ -808,7 +808,7 @@ void main()
printf("abc%n", &i); printf("%d\n", i);
snprintf(holder, sizeof holder, "abc%n", &i);
printf("%s", holder); printf("%d\n\n", i);
-
+
printf("%%*.*s --> 10.10\n");
snprintf(holder, sizeof holder, "%*.*s\n", 10, 10, BLURB);
printf("%*.*s\n", 10, 10, BLURB);
@@ -821,7 +821,7 @@ void main()
#define BIG "Hello this is a too big string for the buffer"
/* printf("A buffer to small of 10, trying to put this:\n");*/
- printf("<%%>, %s\n", BIG);
+ printf("<%%>, %s\n", BIG);
i = snprintf(holder, 10, "%s\n", BIG);
printf("<%s>\n", BIG);
printf("<%s>\n", holder);

Return to:

Send suggestions and report system problems to the System administrator.