23 #define BIN_SPRINTF_MAX_LEN (10240)
27 extern int putchar(
int c);
34 { (void) putchar(c); }
40 static int binPrints(
char **out,
const char *
string,
int width,
int pad)
42 register int pc = 0, padchar =
' ';
47 register const char *ptr;
48 for (ptr =
string; *ptr; ++ptr) ++len;
58 for (; width > 0; --width)
64 for (; *string; ++string)
69 for (; width > 0; --width)
79 #define PRINT_BUF_LEN 12
81 static int binPrinti(
char **out,
int i,
int b,
int sg,
int width,
int pad,
int letbase)
85 register int t, neg = 0, pc = 0;
86 register unsigned int u = i;
96 char ch = (char) (0xFF & (i >> (width * 8)));
106 return binPrints(out, print_buf, width, pad);
109 if (sg && b == 10 && i < 0)
123 t += letbase -
'0' - 10;
150 char *format = (
char *) (*varg++);
153 for (; *format != 0; ++format)
168 while (*format ==
'0')
173 for (; *format >=
'0' && *format <=
'9'; ++format)
176 width += *format -
'0';
180 register char *
s = *((
char **) varg++);
181 pc +=
binPrints(out,
s ?
s :
"(null)", width, pad);
186 pc +=
binPrinti(out, *varg++, 10, 1, width, pad,
'a');
191 pc +=
binPrinti(out, *varg++, 16, 0, width, pad,
'a');
196 pc +=
binPrinti(out, *varg++, 16, 0, width, pad,
'A');
201 pc +=
binPrinti(out, *varg++, 1, 0, width, pad,
'A');
206 pc +=
binPrinti(out, *varg++, 10, 0, width, pad,
'a');
234 long long *varg = (
long long *) (&format);
240 long long *varg = (
long long *) (&format);
248 char *bufferPtr = &(buffer[0]);
250 long long *varg = (
long long *) (&fmt);
251 int retCode =
binPrint(&bufferPtr, varg);
254 for (
int i = 0; i < retCode; i++)
256 outvec->push_back(buffer[i]);
267 for (
int i = 0; i < outvec->size(); i++)
269 char szDummy[255] = {0};
270 sprintf(szDummy,
"%02x ", (
int) (0xFF & (*outvec)[i]));
273 if (appendReadableText)
275 for (
int i = 0; i < outvec->size(); i++)
277 char szDummy[255] = {0};
278 sprintf(szDummy,
"%c", (*outvec)[i] < 0x20 ?
'.' : (*outvec)[i]);