4 /* Portable vsprintf by Robert A. Larson <blarson@skat.usc.edu> */
6 /* Copyright 1989 Robert A. Larson.
7 * Distribution in any form is allowed as long as the author
8 * retains credit, changes are noted by their author and the
9 * copyright message remains intact. This program comes as-is
10 * with no warentee of fitness for any purpouse.
12 * Thanks to Doug Gwen, Chris Torek, and others who helped clarify
13 * the ansi printf specs.
15 * Please send any bug fixes and improvments to blarson@skat.usc.edu .
16 * The use of goto is NOT a bug.
19 /* Feb 7, 1989 blarson First usenet release */
21 /* This code implements the vsprintf function, without relying on
22 * the existance of _doprint or other system specific code.
24 * Define NOVOID if void * is not a supported type.
26 * Two compile options are available for efficency:
27 * INTSPRINTF should be defined if sprintf is int and returns
28 * the number of chacters formated.
29 * LONGINT should be defined if sizeof(long) == sizeof(int)
31 * They only make the code smaller and faster, they need not be
34 * UNSIGNEDSPECIAL should be defined if unsigned is treated differently
35 * than int in argument passing. If this is definded, and LONGINT is not,
36 * the compiler must support the type unsingned long.
38 * Most quirks and bugs of the available sprintf fuction are duplicated,
39 * however * in the width and precision fields will work correctly
40 * even if sprintf does not support this, as will the n format.
42 * Bad format strings, or those with very long width and precision
43 * fields (including expanded * fields) will cause undesired results.
48 #ifdef OSK /* os9/68k can take advantage of both */
55 /* This must be a typedef not a #define! */
57 typedef s_char *pointer;
59 typedef void *pointer;
63 #define Sprintf(string,format,arg) (sprintf((string),(format),(arg)))
65 #define Sprintf(string,format,arg) (\
66 sprintf((string),(format),(arg)),\
76 vsprintf(dest, format, args)
78 register s_char *format;
81 register s_char *dp = dest;
90 while (c = *format++) {
97 switch (c = *format++) {
101 dp += Sprintf(dp, tempfmt, va_arg(args, s_char *));
107 #ifdef UNSIGNEDSPECIAL
113 Sprintf(dp, tempfmt, va_arg(args, unsigned long));
116 dp += Sprintf(dp, tempfmt, va_arg(args, unsigned));
126 dp += Sprintf(dp, tempfmt, va_arg(args, long));
129 dp += Sprintf(dp, tempfmt, va_arg(args, int));
138 dp += Sprintf(dp, tempfmt, va_arg(args, double));
143 dp += Sprintf(dp, tempfmt, va_arg(args, pointer));
162 goto continue_format;
168 goto continue_format;
170 tp += Sprintf(tp, "%d", va_arg(args, int));
171 goto continue_format;
173 *va_arg(args, intp) = dp - dest;
187 #endif /* __STDC__ */