55 RCSID(
"$Id: 3a2dff05c53f9800f37d39e8f34ec9f188535b16 $")
57 #include <freeradius-devel/util/snprintf.h>
59 #ifndef HAVE_VSNPRINTF
76 for (i = 1,
P = 1.,
n = -
n ; i <=
n ; i++) {
P *= .1;}
78 for (i = 1,
P = 1. ; i <=
n ; i++) {
P *= 10.0;}
105 while (result >= r) {result *= .1; i++;}
108 while (result <= r) {result *= 10.; i++;}
129 double real_integral = 0.;
148 for (j =
log_10(real); j >= 0; j--) {
150 s = (real - real_integral)/p;
152 while (i + 1. <= s) {i++;}
153 real_integral += i*p;
156 return (real - real_integral);
159 #define PRECISION 1.e-6
181 static char integral_part[
MAX_INT];
188 integral_part[0] =
'0';
189 integral_part[1] =
'\0';
190 fraction_part[0] =
'0';
191 fraction_part[1] =
'\0';
192 return integral_part;
196 if ((sign = number) < 0.) {
205 integral_part[0] =
'0';
208 for ( i = 0; i < digits && number != 0.; ++i) {
212 integral_part[i] = (ch <= 9) ? ch +
'0' : ch +
'a' - 10;
213 if (! isxdigit(integral_part[i]))
221 for (i = 0; i < digits; ++i)
222 integral_part[i] =
'9';
226 integral_part[i++] =
'-';
228 integral_part[i] =
'\0';
231 for ( i--, j = 0; j < i; j++, i--)
232 SWAP_INT(integral_part[i], integral_part[j]);
236 fraction_part[i] = (int)((fp +
PRECISION)*10. +
'0');
237 if (! isdigit(fraction_part[i]))
239 fp = (fp*10.0) - (
double)(long)((fp +
PRECISION)*10.);
241 fraction_part[i] =
'\0';
243 if (fract != (
char **)0)
244 *fract = fraction_part;
246 return integral_part;
265 p->
width -= strlen(tmp);
289 p->
width -= strlen(tmp);
313 p->
width -= strlen(tmp);
379 if (*p->
pf ==
'g' || *p->
pf ==
'G')
380 for (i = strlen(tmp2) - 1; i >= 0 && tmp2[i] ==
'0'; i--)
382 for (; *tmp2; tmp2++)
421 if (*p->
pf ==
'g' || *p->
pf ==
'G')
422 for (i = strlen(tmp2) - 1; i >= 0 && tmp2[i] ==
'0'; i--)
424 for (; *tmp2; tmp2++)
427 if (*p->
pf ==
'g' || *p->
pf ==
'e') {
437 tmp =
itoa((
double)j);
484 case '0': p->
pad =
'0';
break;
485 case '1':
case '2':
case '3':
486 case '4':
case '5':
case '6':
487 case '7':
case '8':
case '9':
488 for (i = 0; isdigit((
uint8_t) *s); i++, s++)
493 p->
width = atoi(number);
520 data.holder = string;
531 if ( *
data.pf ==
'%' ) {
533 for (state = 1; *
data.pf && state;) {
534 switch (*(++
data.pf)) {
544 d = va_arg(
args,
double);
555 d = va_arg(
args,
double);
562 if (-4 < i && i <
data.precision)
574 d = va_arg(
args,
double);
583 d = va_arg(
args,
unsigned long);
585 d = va_arg(
args,
unsigned int);
594 d = va_arg(
args,
long);
596 d = va_arg(
args,
int);
605 d = va_arg(
args,
long);
607 d = va_arg(
args,
int);
617 d = va_arg(
args,
long);
619 d = va_arg(
args,
int);
624 d = va_arg(
args,
int);
634 *(va_arg(
args,
int *)) =
data.counter;
653 case '#':
case ' ':
case '+':
case '*':
654 case '-':
case '.':
case '0':
case '1':
655 case '2':
case '3':
case '4':
case '5':
656 case '6':
case '7':
case '8':
case '9':
660 conv_field[i] = *
data.pf;
661 conv_field[i] =
'\0';
683 #ifndef HAVE_SNPRINTF
733 printf(
"/%%d/, 336\n");
735 printf(
"/%d/\n", 336);
738 printf(
"/%%2d/, 336\n");
740 printf(
"/%2d/\n", 336);
743 printf(
"/%%10d/, 336\n");
745 printf(
"/%10d/\n", 336);
748 printf(
"/%%-10d/, 336\n");
750 printf(
"/%-10d/\n", 336);
755 printf(
"/%%lld/, 336\n");
760 printf(
"/%%2qd/, 336\n");
767 printf(
"/%%f/, 1234.56\n");
769 printf(
"/%f/\n", 1234.56);
772 printf(
"/%%e/, 1234.56\n");
774 printf(
"/%e/\n", 1234.56);
777 printf(
"/%%4.2f/, 1234.56\n");
779 printf(
"/%4.2f/\n", 1234.56);
782 printf(
"/%%3.1f/, 1234.56\n");
784 printf(
"/%3.1f/\n", 1234.56);
787 printf(
"/%%10.3f/, 1234.56\n");
789 printf(
"/%10.3f/\n", 1234.56);
792 printf(
"/%%10.3e/, 1234.56\n");
794 printf(
"/%10.3e/\n", 1234.56);
797 printf(
"/%%+4.2f/, 1234.56\n");
799 printf(
"/%+4.2f/\n", 1234.56);
802 printf(
"/%%010.2f/, 1234.56\n");
804 printf(
"/%010.2f/\n", 1234.56);
807 #define BLURB "Outstanding acting !"
810 printf(
"/%%2s/, \"%s\"\n", BLURB);
812 printf(
"/%2s/\n", BLURB);
815 printf(
"/%%22s/ %s\n", BLURB);
817 printf(
"/%22s/\n", BLURB);
820 printf(
"/%%22.5s/ %s\n", BLURB);
822 printf(
"/%22.5s/\n", BLURB);
825 printf(
"/%%-22.5s/ %s\n", BLURB);
827 printf(
"/%-22.5s/\n", BLURB);
832 printf(
"%%x %%X %%#x, 31, 31, 31\n");
834 printf(
"%x %X %#x\n", 31, 31, 31);
837 printf(
"**%%d**%% d**%% d**, 42, 42, -42\n");
839 printf(
"**%d**% d**% d**\n", 42, 42, -42);
844 printf(
"/%%g/, 31.4\n");
846 printf(
"/%g/\n", 31.4);
849 printf(
"/%%.6g/, 31.4\n");
851 printf(
"/%.6g/\n", 31.4);
854 printf(
"/%%.1G/, 31.4\n");
856 printf(
"/%.1G/\n", 31.4);
860 printf(
"abc%n", &i); printf(
"%d\n", i);
862 printf(
"%s",
holder); printf(
"%d\n\n", i);
864 printf(
"%%*.*s --> 10.10\n");
866 printf(
"%*.*s\n", 10, 10, BLURB);
869 printf(
"%%%%%%%%\n");
874 #define BIG "Hello this is a too big string for the buffer"
876 printf(
"<%%>, %s\n", BIG);
878 printf(
"<%s>\n", BIG);
int main(int argc, char **argv)
PRIVATE int log_10(double r)
PUBLIC int vsnprintf(char *string, size_t length, char *format, va_list args)
PRIVATE void floating(struct DATA *p, double d)
PRIVATE double integral(double real, double *ip)
PRIVATE void octal(struct DATA *p, double d)
PRIVATE double pow_10(int n)
PRIVATE void conv_flag(char *s, struct DATA *p)
PRIVATE char * numtoa(double number, int base, int precision, char **fract)
PRIVATE void strings(struct DATA *p, char *tmp)
PUBLIC int snprintf(char *string, size_t length, char *format, va_alist)
PRIVATE void exponent(struct DATA *p, double d)
PRIVATE void hexa(struct DATA *p, double d)
PRIVATE void float64(struct DATA *p, double d)
if(!subtype_vp) goto fail
int format(printf, 5, 0))