annotate lib/swig/swigwin-2.0.11/CCache/snprintf.c @ 2103:2318216e5206

stru_AA1058[i]._494836() continue
author Ritor1
date Tue, 17 Dec 2013 23:11:49 +0600
parents b3009adc0e2f
children
rev   line source
1899
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
1 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
2 * Copyright Patrick Powell 1995
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
3 * This code is based on code written by Patrick Powell (papowell@astart.com)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
4 * It may be used for any purpose as long as this notice remains intact
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
5 * on all source code distributions
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
6 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
7
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
8 /**************************************************************
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
9 * Original:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
10 * Patrick Powell Tue Apr 11 09:48:21 PDT 1995
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
11 * A bombproof version of doprnt (dopr) included.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
12 * Sigh. This sort of thing is always nasty do deal with. Note that
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
13 * the version here does not include floating point...
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
14 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
15 * snprintf() is used instead of sprintf() as it does limit checks
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
16 * for string length. This covers a nasty loophole.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
17 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
18 * The other functions are there to prevent NULL pointers from
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
19 * causing nast effects.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
20 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
21 * More Recently:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
22 * Brandon Long <blong@fiction.net> 9/15/96 for mutt 0.43
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
23 * This was ugly. It is still ugly. I opted out of floating point
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
24 * numbers, but the formatter understands just about everything
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
25 * from the normal C string format, at least as far as I can tell from
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
26 * the Solaris 2.5 printf(3S) man page.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
27 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
28 * Brandon Long <blong@fiction.net> 10/22/97 for mutt 0.87.1
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
29 * Ok, added some minimal floating point support, which means this
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
30 * probably requires libm on most operating systems. Don't yet
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
31 * support the exponent (e,E) and sigfig (g,G). Also, fmtint()
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
32 * was pretty badly broken, it just wasn't being exercised in ways
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
33 * which showed it, so that's been fixed. Also, formated the code
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
34 * to mutt conventions, and removed dead code left over from the
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
35 * original. Also, there is now a builtin-test, just compile with:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
36 * gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
37 * and run snprintf for results.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
38 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
39 * Thomas Roessler <roessler@guug.de> 01/27/98 for mutt 0.89i
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
40 * The PGP code was using unsigned hexadecimal formats.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
41 * Unfortunately, unsigned formats simply didn't work.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
42 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
43 * Michael Elkins <me@cs.hmc.edu> 03/05/98 for mutt 0.90.8
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
44 * The original code assumed that both snprintf() and vsnprintf() were
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
45 * missing. Some systems only have snprintf() but not vsnprintf(), so
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
46 * the code is now broken down under HAVE_SNPRINTF and HAVE_VSNPRINTF.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
47 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
48 * Andrew Tridgell (tridge@samba.org) Oct 1998
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
49 * fixed handling of %.0f
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
50 * added test for HAVE_LONG_DOUBLE
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
51 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
52 * tridge@samba.org, idra@samba.org, April 2001
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
53 * got rid of fcvt code (twas buggy and made testing harder)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
54 * added C99 semantics
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
55 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
56 **************************************************************/
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
57
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
58 #ifndef NO_CONFIG_H /* for some tests */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
59 #include "config.h"
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
60 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
61
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
62 #ifdef HAVE_STRING_H
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
63 #include <string.h>
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
64 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
65
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
66 #ifdef HAVE_STRINGS_H
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
67 #include <strings.h>
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
68 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
69 #ifdef HAVE_CTYPE_H
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
70 #include <ctype.h>
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
71 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
72 #include <sys/types.h>
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
73 #include <stdarg.h>
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
74 #ifdef HAVE_STDLIB_H
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
75 #include <stdlib.h>
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
76 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
77
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
78 #if defined(HAVE_SNPRINTF) && defined(HAVE_VSNPRINTF) && defined(HAVE_C99_VSNPRINTF)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
79 /* only include stdio.h if we are not re-defining snprintf or vsnprintf */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
80 #include <stdio.h>
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
81 /* make the compiler happy with an empty file */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
82 void dummy_snprintf(void) {}
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
83 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
84
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
85 #ifdef HAVE_LONG_DOUBLE
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
86 #define LDOUBLE long double
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
87 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
88 #define LDOUBLE double
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
89 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
90
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
91 #ifdef HAVE_LONG_LONG
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
92 #define LLONG long long
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
93 #else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
94 #define LLONG long
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
95 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
96
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
97 static size_t dopr(char *buffer, size_t maxlen, const char *format,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
98 va_list args);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
99 static void fmtstr(char *buffer, size_t *currlen, size_t maxlen,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
100 char *value, int flags, int min, int max);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
101 static void fmtint(char *buffer, size_t *currlen, size_t maxlen,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
102 long value, int base, int min, int max, int flags);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
103 static void fmtfp(char *buffer, size_t *currlen, size_t maxlen,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
104 LDOUBLE fvalue, int min, int max, int flags);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
105 static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
106
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
107 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
108 * dopr(): poor man's version of doprintf
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
109 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
110
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
111 /* format read states */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
112 #define DP_S_DEFAULT 0
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
113 #define DP_S_FLAGS 1
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
114 #define DP_S_MIN 2
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
115 #define DP_S_DOT 3
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
116 #define DP_S_MAX 4
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
117 #define DP_S_MOD 5
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
118 #define DP_S_CONV 6
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
119 #define DP_S_DONE 7
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
120
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
121 /* format flags - Bits */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
122 #define DP_F_MINUS (1 << 0)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
123 #define DP_F_PLUS (1 << 1)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
124 #define DP_F_SPACE (1 << 2)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
125 #define DP_F_NUM (1 << 3)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
126 #define DP_F_ZERO (1 << 4)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
127 #define DP_F_UP (1 << 5)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
128 #define DP_F_UNSIGNED (1 << 6)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
129
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
130 /* Conversion Flags */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
131 #define DP_C_SHORT 1
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
132 #define DP_C_LONG 2
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
133 #define DP_C_LDOUBLE 3
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
134 #define DP_C_LLONG 4
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
135
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
136 #define char_to_int(p) ((p)- '0')
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
137 #ifndef MAX
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
138 #define MAX(p,q) (((p) >= (q)) ? (p) : (q))
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
139 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
140
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
141 static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
142 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
143 char ch;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
144 LLONG value;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
145 LDOUBLE fvalue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
146 char *strvalue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
147 int min;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
148 int max;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
149 int state;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
150 int flags;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
151 int cflags;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
152 size_t currlen;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
153
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
154 state = DP_S_DEFAULT;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
155 currlen = flags = cflags = min = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
156 max = -1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
157 ch = *format++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
158
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
159 while (state != DP_S_DONE) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
160 if (ch == '\0')
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
161 state = DP_S_DONE;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
162
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
163 switch(state) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
164 case DP_S_DEFAULT:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
165 if (ch == '%')
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
166 state = DP_S_FLAGS;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
167 else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
168 dopr_outch (buffer, &currlen, maxlen, ch);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
169 ch = *format++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
170 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
171 case DP_S_FLAGS:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
172 switch (ch) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
173 case '-':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
174 flags |= DP_F_MINUS;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
175 ch = *format++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
176 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
177 case '+':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
178 flags |= DP_F_PLUS;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
179 ch = *format++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
180 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
181 case ' ':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
182 flags |= DP_F_SPACE;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
183 ch = *format++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
184 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
185 case '#':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
186 flags |= DP_F_NUM;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
187 ch = *format++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
188 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
189 case '0':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
190 flags |= DP_F_ZERO;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
191 ch = *format++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
192 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
193 default:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
194 state = DP_S_MIN;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
195 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
196 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
197 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
198 case DP_S_MIN:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
199 if (isdigit((unsigned char)ch)) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
200 min = 10*min + char_to_int (ch);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
201 ch = *format++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
202 } else if (ch == '*') {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
203 min = va_arg (args, int);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
204 ch = *format++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
205 state = DP_S_DOT;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
206 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
207 state = DP_S_DOT;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
208 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
209 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
210 case DP_S_DOT:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
211 if (ch == '.') {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
212 state = DP_S_MAX;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
213 ch = *format++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
214 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
215 state = DP_S_MOD;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
216 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
217 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
218 case DP_S_MAX:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
219 if (isdigit((unsigned char)ch)) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
220 if (max < 0)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
221 max = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
222 max = 10*max + char_to_int (ch);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
223 ch = *format++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
224 } else if (ch == '*') {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
225 max = va_arg (args, int);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
226 ch = *format++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
227 state = DP_S_MOD;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
228 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
229 state = DP_S_MOD;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
230 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
231 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
232 case DP_S_MOD:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
233 switch (ch) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
234 case 'h':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
235 cflags = DP_C_SHORT;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
236 ch = *format++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
237 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
238 case 'l':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
239 cflags = DP_C_LONG;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
240 ch = *format++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
241 if (ch == 'l') { /* It's a long long */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
242 cflags = DP_C_LLONG;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
243 ch = *format++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
244 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
245 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
246 case 'L':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
247 cflags = DP_C_LDOUBLE;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
248 ch = *format++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
249 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
250 default:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
251 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
252 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
253 state = DP_S_CONV;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
254 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
255 case DP_S_CONV:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
256 switch (ch) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
257 case 'd':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
258 case 'i':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
259 if (cflags == DP_C_SHORT)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
260 value = va_arg (args, int);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
261 else if (cflags == DP_C_LONG)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
262 value = va_arg (args, long int);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
263 else if (cflags == DP_C_LLONG)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
264 value = va_arg (args, LLONG);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
265 else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
266 value = va_arg (args, int);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
267 fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
268 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
269 case 'o':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
270 flags |= DP_F_UNSIGNED;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
271 if (cflags == DP_C_SHORT)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
272 value = va_arg (args, unsigned int);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
273 else if (cflags == DP_C_LONG)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
274 value = (long)va_arg (args, unsigned long int);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
275 else if (cflags == DP_C_LLONG)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
276 value = (long)va_arg (args, unsigned LLONG);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
277 else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
278 value = (long)va_arg (args, unsigned int);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
279 fmtint (buffer, &currlen, maxlen, value, 8, min, max, flags);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
280 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
281 case 'u':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
282 flags |= DP_F_UNSIGNED;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
283 if (cflags == DP_C_SHORT)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
284 value = va_arg (args, unsigned int);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
285 else if (cflags == DP_C_LONG)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
286 value = (long)va_arg (args, unsigned long int);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
287 else if (cflags == DP_C_LLONG)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
288 value = (LLONG)va_arg (args, unsigned LLONG);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
289 else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
290 value = (long)va_arg (args, unsigned int);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
291 fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
292 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
293 case 'X':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
294 flags |= DP_F_UP;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
295 case 'x':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
296 flags |= DP_F_UNSIGNED;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
297 if (cflags == DP_C_SHORT)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
298 value = va_arg (args, unsigned int);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
299 else if (cflags == DP_C_LONG)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
300 value = (long)va_arg (args, unsigned long int);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
301 else if (cflags == DP_C_LLONG)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
302 value = (LLONG)va_arg (args, unsigned LLONG);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
303 else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
304 value = (long)va_arg (args, unsigned int);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
305 fmtint (buffer, &currlen, maxlen, value, 16, min, max, flags);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
306 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
307 case 'f':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
308 if (cflags == DP_C_LDOUBLE)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
309 fvalue = va_arg (args, LDOUBLE);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
310 else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
311 fvalue = va_arg (args, double);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
312 /* um, floating point? */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
313 fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
314 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
315 case 'E':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
316 flags |= DP_F_UP;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
317 case 'e':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
318 if (cflags == DP_C_LDOUBLE)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
319 fvalue = va_arg (args, LDOUBLE);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
320 else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
321 fvalue = va_arg (args, double);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
322 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
323 case 'G':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
324 flags |= DP_F_UP;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
325 case 'g':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
326 if (cflags == DP_C_LDOUBLE)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
327 fvalue = va_arg (args, LDOUBLE);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
328 else
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
329 fvalue = va_arg (args, double);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
330 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
331 case 'c':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
332 dopr_outch (buffer, &currlen, maxlen, va_arg (args, int));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
333 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
334 case 's':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
335 strvalue = va_arg (args, char *);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
336 if (!strvalue) strvalue = "(NULL)";
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
337 if (max == -1) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
338 max = strlen(strvalue);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
339 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
340 if (min > 0 && max >= 0 && min > max) max = min;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
341 fmtstr (buffer, &currlen, maxlen, strvalue, flags, min, max);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
342 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
343 case 'p':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
344 strvalue = (char *)va_arg(args, void *);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
345 fmtint (buffer, &currlen, maxlen, (long) strvalue, 16, min, max, flags);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
346 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
347 case 'n':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
348 if (cflags == DP_C_SHORT) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
349 short int *num;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
350 num = va_arg (args, short int *);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
351 *num = currlen;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
352 } else if (cflags == DP_C_LONG) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
353 long int *num;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
354 num = va_arg (args, long int *);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
355 *num = (long int)currlen;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
356 } else if (cflags == DP_C_LLONG) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
357 LLONG *num;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
358 num = va_arg (args, LLONG *);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
359 *num = (LLONG)currlen;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
360 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
361 int *num;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
362 num = va_arg (args, int *);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
363 *num = currlen;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
364 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
365 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
366 case '%':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
367 dopr_outch (buffer, &currlen, maxlen, ch);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
368 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
369 case 'w':
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
370 /* not supported yet, treat as next char */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
371 ch = *format++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
372 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
373 default:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
374 /* Unknown, skip */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
375 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
376 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
377 ch = *format++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
378 state = DP_S_DEFAULT;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
379 flags = cflags = min = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
380 max = -1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
381 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
382 case DP_S_DONE:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
383 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
384 default:
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
385 /* hmm? */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
386 break; /* some picky compilers need this */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
387 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
388 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
389 if (maxlen != 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
390 if (currlen < maxlen - 1)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
391 buffer[currlen] = '\0';
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
392 else if (maxlen > 0)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
393 buffer[maxlen - 1] = '\0';
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
394 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
395
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
396 return currlen;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
397 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
398
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
399 static void fmtstr(char *buffer, size_t *currlen, size_t maxlen,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
400 char *value, int flags, int min, int max)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
401 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
402 int padlen, strln; /* amount to pad */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
403 int cnt = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
404
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
405 #ifdef DEBUG_SNPRINTF
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
406 printf("fmtstr min=%d max=%d s=[%s]\n", min, max, value);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
407 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
408 if (value == 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
409 value = "<NULL>";
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
410 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
411
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
412 for (strln = 0; value[strln]; ++strln); /* strlen */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
413 padlen = min - strln;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
414 if (padlen < 0)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
415 padlen = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
416 if (flags & DP_F_MINUS)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
417 padlen = -padlen; /* Left Justify */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
418
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
419 while ((padlen > 0) && (cnt < max)) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
420 dopr_outch (buffer, currlen, maxlen, ' ');
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
421 --padlen;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
422 ++cnt;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
423 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
424 while (*value && (cnt < max)) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
425 dopr_outch (buffer, currlen, maxlen, *value++);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
426 ++cnt;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
427 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
428 while ((padlen < 0) && (cnt < max)) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
429 dopr_outch (buffer, currlen, maxlen, ' ');
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
430 ++padlen;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
431 ++cnt;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
432 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
433 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
434
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
435 /* Have to handle DP_F_NUM (ie 0x and 0 alternates) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
436
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
437 static void fmtint(char *buffer, size_t *currlen, size_t maxlen,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
438 long value, int base, int min, int max, int flags)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
439 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
440 int signvalue = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
441 unsigned long uvalue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
442 char convert[20];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
443 int place = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
444 int spadlen = 0; /* amount to space pad */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
445 int zpadlen = 0; /* amount to zero pad */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
446 int caps = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
447
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
448 if (max < 0)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
449 max = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
450
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
451 uvalue = value;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
452
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
453 if(!(flags & DP_F_UNSIGNED)) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
454 if( value < 0 ) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
455 signvalue = '-';
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
456 uvalue = -value;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
457 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
458 if (flags & DP_F_PLUS) /* Do a sign (+/i) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
459 signvalue = '+';
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
460 else if (flags & DP_F_SPACE)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
461 signvalue = ' ';
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
462 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
463 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
464
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
465 if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
466
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
467 do {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
468 convert[place++] =
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
469 (caps? "0123456789ABCDEF":"0123456789abcdef")
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
470 [uvalue % (unsigned)base ];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
471 uvalue = (uvalue / (unsigned)base );
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
472 } while(uvalue && (place < 20));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
473 if (place == 20) place--;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
474 convert[place] = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
475
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
476 zpadlen = max - place;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
477 spadlen = min - MAX (max, place) - (signvalue ? 1 : 0);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
478 if (zpadlen < 0) zpadlen = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
479 if (spadlen < 0) spadlen = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
480 if (flags & DP_F_ZERO) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
481 zpadlen = MAX(zpadlen, spadlen);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
482 spadlen = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
483 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
484 if (flags & DP_F_MINUS)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
485 spadlen = -spadlen; /* Left Justifty */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
486
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
487 #ifdef DEBUG_SNPRINTF
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
488 printf("zpad: %d, spad: %d, min: %d, max: %d, place: %d\n",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
489 zpadlen, spadlen, min, max, place);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
490 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
491
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
492 /* Spaces */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
493 while (spadlen > 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
494 dopr_outch (buffer, currlen, maxlen, ' ');
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
495 --spadlen;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
496 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
497
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
498 /* Sign */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
499 if (signvalue)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
500 dopr_outch (buffer, currlen, maxlen, signvalue);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
501
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
502 /* Zeros */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
503 if (zpadlen > 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
504 while (zpadlen > 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
505 dopr_outch (buffer, currlen, maxlen, '0');
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
506 --zpadlen;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
507 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
508 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
509
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
510 /* Digits */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
511 while (place > 0)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
512 dopr_outch (buffer, currlen, maxlen, convert[--place]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
513
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
514 /* Left Justified spaces */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
515 while (spadlen < 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
516 dopr_outch (buffer, currlen, maxlen, ' ');
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
517 ++spadlen;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
518 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
519 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
520
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
521 static LDOUBLE abs_val(LDOUBLE value)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
522 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
523 LDOUBLE result = value;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
524
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
525 if (value < 0)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
526 result = -value;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
527
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
528 return result;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
529 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
530
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
531 static LDOUBLE POW10(int exp)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
532 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
533 LDOUBLE result = 1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
534
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
535 while (exp) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
536 result *= 10;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
537 exp--;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
538 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
539
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
540 return result;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
541 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
542
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
543 static LLONG ROUND(LDOUBLE value)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
544 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
545 LLONG intpart;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
546
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
547 intpart = (LLONG)value;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
548 value = value - intpart;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
549 if (value >= 0.5) intpart++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
550
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
551 return intpart;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
552 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
553
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
554 /* a replacement for modf that doesn't need the math library. Should
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
555 be portable, but slow */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
556 static double my_modf(double x0, double *iptr)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
557 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
558 int i;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
559 long l;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
560 double x = x0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
561 double f = 1.0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
562
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
563 for (i=0;i<100;i++) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
564 l = (long)x;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
565 if (l <= (x+1) && l >= (x-1)) break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
566 x *= 0.1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
567 f *= 10.0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
568 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
569
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
570 if (i == 100) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
571 /* yikes! the number is beyond what we can handle. What do we do? */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
572 (*iptr) = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
573 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
574 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
575
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
576 if (i != 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
577 double i2;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
578 double ret;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
579
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
580 ret = my_modf(x0-l*f, &i2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
581 (*iptr) = l*f + i2;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
582 return ret;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
583 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
584
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
585 (*iptr) = l;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
586 return x - (*iptr);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
587 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
588
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
589
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
590 static void fmtfp (char *buffer, size_t *currlen, size_t maxlen,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
591 LDOUBLE fvalue, int min, int max, int flags)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
592 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
593 int signvalue = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
594 double ufvalue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
595 char iconvert[311];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
596 char fconvert[311];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
597 int iplace = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
598 int fplace = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
599 int padlen = 0; /* amount to pad */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
600 int zpadlen = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
601 int caps = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
602 int index;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
603 double intpart;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
604 double fracpart;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
605 double temp;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
606
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
607 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
608 * AIX manpage says the default is 0, but Solaris says the default
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
609 * is 6, and sprintf on AIX defaults to 6
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
610 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
611 if (max < 0)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
612 max = 6;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
613
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
614 ufvalue = abs_val (fvalue);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
615
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
616 if (fvalue < 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
617 signvalue = '-';
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
618 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
619 if (flags & DP_F_PLUS) { /* Do a sign (+/i) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
620 signvalue = '+';
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
621 } else {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
622 if (flags & DP_F_SPACE)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
623 signvalue = ' ';
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
624 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
625 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
626
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
627 #if 0
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
628 if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
629 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
630
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
631 #if 0
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
632 if (max == 0) ufvalue += 0.5; /* if max = 0 we must round */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
633 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
634
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
635 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
636 * Sorry, we only support 16 digits past the decimal because of our
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
637 * conversion method
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
638 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
639 if (max > 16)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
640 max = 16;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
641
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
642 /* We "cheat" by converting the fractional part to integer by
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
643 * multiplying by a factor of 10
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
644 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
645
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
646 temp = ufvalue;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
647 my_modf(temp, &intpart);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
648
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
649 fracpart = ROUND((POW10(max)) * (ufvalue - intpart));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
650
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
651 if (fracpart >= POW10(max)) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
652 intpart++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
653 fracpart -= POW10(max);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
654 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
655
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
656
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
657 /* Convert integer part */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
658 do {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
659 temp = intpart;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
660 my_modf(intpart*0.1, &intpart);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
661 temp = temp*0.1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
662 index = (int) ((temp -intpart +0.05)* 10.0);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
663 /* index = (int) (((double)(temp*0.1) -intpart +0.05) *10.0); */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
664 /* printf ("%llf, %f, %x\n", temp, intpart, index); */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
665 iconvert[iplace++] =
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
666 (caps? "0123456789ABCDEF":"0123456789abcdef")[index];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
667 } while (intpart && (iplace < 311));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
668 if (iplace == 311) iplace--;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
669 iconvert[iplace] = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
670
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
671 /* Convert fractional part */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
672 if (fracpart)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
673 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
674 do {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
675 temp = fracpart;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
676 my_modf(fracpart*0.1, &fracpart);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
677 temp = temp*0.1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
678 index = (int) ((temp -fracpart +0.05)* 10.0);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
679 /* index = (int) ((((temp/10) -fracpart) +0.05) *10); */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
680 /* printf ("%lf, %lf, %ld\n", temp, fracpart, index); */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
681 fconvert[fplace++] =
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
682 (caps? "0123456789ABCDEF":"0123456789abcdef")[index];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
683 } while(fracpart && (fplace < 311));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
684 if (fplace == 311) fplace--;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
685 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
686 fconvert[fplace] = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
687
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
688 /* -1 for decimal point, another -1 if we are printing a sign */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
689 padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
690 zpadlen = max - fplace;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
691 if (zpadlen < 0) zpadlen = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
692 if (padlen < 0)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
693 padlen = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
694 if (flags & DP_F_MINUS)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
695 padlen = -padlen; /* Left Justifty */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
696
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
697 if ((flags & DP_F_ZERO) && (padlen > 0)) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
698 if (signvalue) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
699 dopr_outch (buffer, currlen, maxlen, signvalue);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
700 --padlen;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
701 signvalue = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
702 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
703 while (padlen > 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
704 dopr_outch (buffer, currlen, maxlen, '0');
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
705 --padlen;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
706 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
707 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
708 while (padlen > 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
709 dopr_outch (buffer, currlen, maxlen, ' ');
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
710 --padlen;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
711 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
712 if (signvalue)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
713 dopr_outch (buffer, currlen, maxlen, signvalue);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
714
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
715 while (iplace > 0)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
716 dopr_outch (buffer, currlen, maxlen, iconvert[--iplace]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
717
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
718 #ifdef DEBUG_SNPRINTF
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
719 printf("fmtfp: fplace=%d zpadlen=%d\n", fplace, zpadlen);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
720 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
721
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
722 /*
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
723 * Decimal point. This should probably use locale to find the correct
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
724 * char to print out.
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
725 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
726 if (max > 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
727 dopr_outch (buffer, currlen, maxlen, '.');
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
728
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
729 while (fplace > 0)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
730 dopr_outch (buffer, currlen, maxlen, fconvert[--fplace]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
731 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
732
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
733 while (zpadlen > 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
734 dopr_outch (buffer, currlen, maxlen, '0');
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
735 --zpadlen;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
736 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
737
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
738 while (padlen < 0) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
739 dopr_outch (buffer, currlen, maxlen, ' ');
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
740 ++padlen;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
741 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
742 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
743
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
744 static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
745 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
746 if (*currlen < maxlen) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
747 buffer[(*currlen)] = c;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
748 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
749 (*currlen)++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
750 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
751
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
752 /* yes this really must be a ||. Don't muck with this (tridge) */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
753 #if !defined(HAVE_VSNPRINTF) || !defined(HAVE_C99_VSNPRINTF)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
754 int vsnprintf (char *str, size_t count, const char *fmt, va_list args)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
755 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
756 return dopr(str, count, fmt, args);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
757 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
758 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
759
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
760 /* yes this really must be a ||. Don't muck wiith this (tridge)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
761 *
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
762 * The logic for these two is that we need our own definition if the
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
763 * OS *either* has no definition of *sprintf, or if it does have one
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
764 * that doesn't work properly according to the autoconf test. Perhaps
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
765 * these should really be smb_snprintf to avoid conflicts with buggy
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
766 * linkers? -- mbp
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
767 */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
768 #if !defined(HAVE_SNPRINTF) || !defined(HAVE_C99_SNPRINTF)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
769 int snprintf(char *str,size_t count,const char *fmt,...)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
770 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
771 size_t ret;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
772 va_list ap;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
773
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
774 va_start(ap, fmt);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
775 ret = vsnprintf(str, count, fmt, ap);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
776 va_end(ap);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
777 return ret;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
778 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
779 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
780
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
781 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
782
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
783 #ifndef HAVE_VASPRINTF
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
784 int vasprintf(char **ptr, const char *format, va_list ap)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
785 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
786 int ret;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
787
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
788 ret = vsnprintf(0, 0, format, ap);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
789 if (ret <= 0) return ret;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
790
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
791 (*ptr) = (char *)malloc(ret+1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
792 if (!*ptr) return -1;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
793 ret = vsnprintf(*ptr, ret+1, format, ap);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
794
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
795 return ret;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
796 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
797 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
798
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
799
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
800 #ifndef HAVE_ASPRINTF
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
801 int asprintf(char **ptr, const char *format, ...)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
802 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
803 va_list ap;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
804 int ret;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
805
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
806 *ptr = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
807 va_start(ap, format);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
808 ret = vasprintf(ptr, format, ap);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
809 va_end(ap);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
810
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
811 return ret;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
812 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
813 #endif
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
814
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
815 #ifndef HAVE_VSYSLOG
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
816 #ifdef HAVE_SYSLOG
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
817 void vsyslog (int facility_priority, char *format, va_list arglist)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
818 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
819 char *msg = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
820 vasprintf(&msg, format, arglist);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
821 if (!msg)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
822 return;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
823 syslog(facility_priority, "%s", msg);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
824 free(msg);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
825 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
826 #endif /* HAVE_SYSLOG */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
827 #endif /* HAVE_VSYSLOG */
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
828
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
829 #ifdef TEST_SNPRINTF
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
830
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
831 int sprintf(char *str,const char *fmt,...);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
832
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
833 int main (void)
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
834 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
835 char buf1[1024];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
836 char buf2[1024];
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
837 char *fp_fmt[] = {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
838 "%1.1f",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
839 "%-1.5f",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
840 "%1.5f",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
841 "%123.9f",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
842 "%10.5f",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
843 "% 10.5f",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
844 "%+22.9f",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
845 "%+4.9f",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
846 "%01.3f",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
847 "%4f",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
848 "%3.1f",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
849 "%3.2f",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
850 "%.0f",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
851 "%f",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
852 "-16.16f",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
853 0
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
854 };
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
855 double fp_nums[] = { 6442452944.1234, -1.5, 134.21, 91340.2, 341.1234, 0203.9, 0.96, 0.996,
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
856 0.9996, 1.996, 4.136, 0};
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
857 char *int_fmt[] = {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
858 "%-1.5d",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
859 "%1.5d",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
860 "%123.9d",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
861 "%5.5d",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
862 "%10.5d",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
863 "% 10.5d",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
864 "%+22.33d",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
865 "%01.3d",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
866 "%4d",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
867 "%d",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
868 0
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
869 };
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
870 long int_nums[] = { -1, 134, 91340, 341, 0203, 0};
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
871 char *str_fmt[] = {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
872 "10.5s",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
873 "5.10s",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
874 "10.1s",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
875 "0.10s",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
876 "10.0s",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
877 "1.10s",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
878 "%s",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
879 "%.1s",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
880 "%.10s",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
881 "%10s",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
882 0
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
883 };
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
884 char *str_vals[] = {"hello", "a", "", "a longer string", 0};
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
885 int x, y;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
886 int fail = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
887 int num = 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
888
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
889 printf ("Testing snprintf format codes against system sprintf...\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
890
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
891 for (x = 0; fp_fmt[x] ; x++) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
892 for (y = 0; fp_nums[y] != 0 ; y++) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
893 int l1 = snprintf(0, 0, fp_fmt[x], fp_nums[y]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
894 int l2 = snprintf(buf1, sizeof(buf1), fp_fmt[x], fp_nums[y]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
895 sprintf (buf2, fp_fmt[x], fp_nums[y]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
896 if (strcmp (buf1, buf2)) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
897 printf("snprintf doesn't match Format: %s\n\tsnprintf = [%s]\n\t sprintf = [%s]\n",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
898 fp_fmt[x], buf1, buf2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
899 fail++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
900 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
901 if (l1 != l2) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
902 printf("snprintf l1 != l2 (%d %d) %s\n", l1, l2, fp_fmt[x]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
903 fail++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
904 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
905 num++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
906 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
907 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
908
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
909 for (x = 0; int_fmt[x] ; x++) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
910 for (y = 0; int_nums[y] != 0 ; y++) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
911 int l1 = snprintf(0, 0, int_fmt[x], int_nums[y]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
912 int l2 = snprintf(buf1, sizeof(buf1), int_fmt[x], int_nums[y]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
913 sprintf (buf2, int_fmt[x], int_nums[y]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
914 if (strcmp (buf1, buf2)) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
915 printf("snprintf doesn't match Format: %s\n\tsnprintf = [%s]\n\t sprintf = [%s]\n",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
916 int_fmt[x], buf1, buf2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
917 fail++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
918 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
919 if (l1 != l2) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
920 printf("snprintf l1 != l2 (%d %d) %s\n", l1, l2, int_fmt[x]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
921 fail++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
922 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
923 num++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
924 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
925 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
926
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
927 for (x = 0; str_fmt[x] ; x++) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
928 for (y = 0; str_vals[y] != 0 ; y++) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
929 int l1 = snprintf(0, 0, str_fmt[x], str_vals[y]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
930 int l2 = snprintf(buf1, sizeof(buf1), str_fmt[x], str_vals[y]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
931 sprintf (buf2, str_fmt[x], str_vals[y]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
932 if (strcmp (buf1, buf2)) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
933 printf("snprintf doesn't match Format: %s\n\tsnprintf = [%s]\n\t sprintf = [%s]\n",
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
934 str_fmt[x], buf1, buf2);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
935 fail++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
936 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
937 if (l1 != l2) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
938 printf("snprintf l1 != l2 (%d %d) %s\n", l1, l2, str_fmt[x]);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
939 fail++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
940 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
941 num++;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
942 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
943 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
944
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
945 printf ("%d tests failed out of %d.\n", fail, num);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
946
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
947 printf("seeing how many digits we support\n");
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
948 {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
949 double v0 = 0.12345678901234567890123456789012345678901;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
950 for (x=0; x<100; x++) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
951 snprintf(buf1, sizeof(buf1), "%1.1f", v0*pow(10, x));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
952 sprintf(buf2, "%1.1f", v0*pow(10, x));
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
953 if (strcmp(buf1, buf2)) {
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
954 printf("we seem to support %d digits\n", x-1);
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
955 break;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
956 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
957 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
958 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
959
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
960 return 0;
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
961 }
b3009adc0e2f Adding swig, gitignore, hgignore
Nomad
parents:
diff changeset
962 #endif /* SNPRINTF_TEST */