1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
/****************************************************************
Copyright (C) 1997 Lucent Technologies
All Rights Reserved
Permission to use, copy, modify, and distribute this software and
its documentation for any purpose and without fee is hereby
granted, provided that the above copyright notice appear in all
copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of Lucent or any of its entities
not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior
permission.
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
****************************************************************/
/* This is for Sun (and other systems with brain-damaged sprintf that
* doesn't return the count of characters transmitted).
* It implements only the relevant subset of sprintf.
* With ANSI C (and other sensible systems), you can omit Sprintf.o
* if you add -DSprintf=sprintf to CFLAGS (in the makefile).
*/
#include "stdio.h"
#include "string.h"
#ifdef KR_headers
#ifndef size_t__
#define size_t int
#define size_t__
#endif
#include "varargs.h"
#else
#include "stddef.h"
#include "stdarg.h"
#include "stdlib.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
static void
bad
#ifdef KR_headers
(fmt) char *fmt;
#else
(const char *fmt)
#endif
{
printf("bad fmt in Sprintf, starting with \"%s\"\n", fmt);
exit(1);
}
#define put(x) *outbuf++ = x
int
Sprintf
#ifdef KR_headers
(va_alist)
va_dcl
#else
(char *outbuf, const char *fmt, ...)
#endif
{
char *ob0, *s;
char buf[32];
va_list ap;
long i, j;
#ifdef KR_headers
char *outbuf, *fmt;
va_start(ap);
outbuf = va_arg(ap, char*);
fmt = va_arg(ap, char*);
#else
va_start(ap, fmt);
#endif
ob0 = outbuf;
for(;;) {
for(;;) {
switch(i = *fmt++) {
case 0:
goto done;
case '%':
break;
default:
put(i);
continue;
}
break;
}
switch(*fmt++) {
case 'c':
i = va_arg(ap, int);
put(i);
continue;
case 'l':
if (*fmt != 'd')
bad(fmt);
fmt++;
i = va_arg(ap, long);
goto have_i;
case 'd':
i = va_arg(ap, int);
have_i:
if (i < 0) {
put('-');
i = -i;
}
s = buf;
do {
j = i / 10;
*s++ = i - 10*j + '0';
}
while(i = j);
do {
i = *--s;
put(i);
}
while(s > buf);
continue;
case 's':
s = va_arg(ap, char*);
while(i = *s++)
{ put(i); }
continue;
default:
bad(fmt);
}
}
done:
*outbuf = 0;
return outbuf - ob0;
}
#ifdef __cplusplus
}
#endif
|