22 #define BIN_SPRINTF_MAX_LEN (10240) 25 extern int putchar(
int c);
30 else (
void)putchar(c);
36 static int binPrints(
char **out,
const char *
string,
int width,
int pad)
38 register int pc = 0, padchar =
' ';
42 register const char *ptr;
43 for (ptr =
string; *ptr; ++ptr) ++len;
44 if (len >= width) width = 0;
49 for ( ; width > 0; --width) {
54 for ( ; *string ; ++string) {
58 for ( ; width > 0; --width) {
67 #define PRINT_BUF_LEN 12 69 static int binPrinti(
char **out,
int i,
int b,
int sg,
int width,
int pad,
int letbase)
73 register int t, neg = 0, pc = 0;
74 register unsigned int u = i;
84 char ch = (char)(0xFF & (i >> (width * 8)));
93 return binPrints (out, print_buf, width, pad);
96 if (sg && b == 10 && i < 0) {
107 t += letbase -
'0' - 10;
123 return pc +
binPrints (out, s, width, pad);
130 char *format = (
char *)(*varg++);
133 for (; *format != 0; ++format) {
134 if (*format ==
'%') {
137 if (*format ==
'\0')
break;
138 if (*format ==
'%')
goto out;
139 if (*format ==
'-') {
143 while (*format ==
'0') {
147 for ( ; *format >=
'0' && *format <=
'9'; ++format) {
149 width += *format -
'0';
151 if( *format ==
's' ) {
152 register char *
s = *((
char **)varg++);
153 pc +=
binPrints (out, s?s:
"(null)", width, pad);
156 if( *format ==
'd' ) {
157 pc +=
binPrinti (out, *varg++, 10, 1, width, pad,
'a');
160 if( *format ==
'x' ) {
161 pc +=
binPrinti (out, *varg++, 16, 0, width, pad,
'a');
164 if( *format ==
'X' ) {
165 pc +=
binPrinti (out, *varg++, 16, 0, width, pad,
'A');
168 if (*format ==
'y') {
169 pc +=
binPrinti(out, *varg++, 1, 0, width, pad,
'A');
172 if( *format ==
'u' ) {
173 pc +=
binPrinti (out, *varg++, 10, 0, width, pad,
'a');
176 if( *format ==
'c' ) {
190 if (out) **out =
'\0';
198 long long *varg = (
long long *)(&format);
204 long long *varg = (
long long *)(&format);
212 char *bufferPtr = &(buffer[0]);
214 long long *varg = (
long long *)(&fmt);
215 int retCode =
binPrint(&bufferPtr, varg);
218 for (
int i = 0; i < retCode; i++)
220 outvec->push_back(buffer[i]);
231 for (
int i = 0; i < outvec->size(); i++)
233 char szDummy[255] = { 0 };
234 sprintf(szDummy,
"%02x ", (
int)(0xFF & (*outvec)[i]));
237 if (appendReadableText)
239 for (
int i = 0; i < outvec->size(); i++)
241 char szDummy[255] = { 0 };
242 sprintf(szDummy,
"%c", (*outvec)[i] < 0x20 ?
'.' : (*outvec)[i]);
int binSprintf(char *out, const char *format,...)
static void binPrintchar(char **str, int c)
static int binPrints(char **out, const char *string, int width, int pad)
int binPrintf(const char *format,...)
int binSprintfVec(std::vector< unsigned char > *outvec, const char *fmt,...)
#define BIN_SPRINTF_MAX_LEN
std::string binDumpVecToString(std::vector< unsigned char > *outvec, bool appendReadableText)
static int binPrinti(char **out, int i, int b, int sg, int width, int pad, int letbase)
static int binPrint(char **out, long long *varg)
static sick_scan::SickScanCommonTcp * s