34 #define _CRT_SECURE_NO_WARNINGS 42 #define MAXLN (10 * 1024) 44 #define ISSPACE " \t\n\r\f\v" 50 val = (int)(val & 0xFF);
52 int ret = isspace(val);
81 unsigned long value, v1, v2;
85 if (p[0] ==
'0' && (p[1] ==
'x' || p[1] ==
'X')) {
90 if (base == 16 && (q = strchr(p,
'.')) != 0) {
91 if (q - p >
sizeof(tmp) - 1)
94 strncpy(tmp, p, q - p);
105 *vp = (v1 << 16) + v2;
111 if (*p >=
'0' && *p <=
'9')
113 else if (*p >=
'a' && *p <=
'f')
114 digit = *p -
'a' + 10;
115 else if (*p >=
'A' && *p <=
'F')
116 digit = *p -
'A' + 10;
133 int binAtob(
unsigned long*vp,
char *p,
int base)
159 count = vfscanf(stdin, fmt, ap);
174 count = vfscanf(fp, fmt, ap);
189 count = vsscanf(buf, fmt, ap);
203 if (fgets(buf,
MAXLN, fp) == 0)
205 count = vsscanf(buf, fmt, ap);
221 binVsscanf(
const char *bufOrg,
const char *
s, va_list ap,
int bufLen)
223 int count, noassign, base, lflag;
230 bufEnd = buf + bufLen;
232 count = noassign = width = lflag = base = 0;
234 while (*s && (buf < bufEnd))
241 if (strchr(
"dibouxycsefg%", *s))
245 else if (*s ==
'l' || *s ==
'L')
247 else if (*s >=
'1' && *s <=
'9') {
248 for (tc = s; isdigit(*s); s++);
249 strncpy(tmp, tc, s - tc);
251 binAtob((
unsigned long *)&width, tmp, 10);
262 width = (int)strcspn(buf,
ISSPACE);
264 strncpy(t = va_arg(ap,
char *), buf, width);
269 else if (*s ==
'c') {
273 strncpy(t = va_arg(ap,
char *), buf, width);
278 else if (strchr(
"dobxyu", *s)) {
283 if (*s ==
'd' || *s ==
'u')
295 width = (int)strcspn(buf,
ISSPACE);
297 width = (int)(strchr(buf, *(s + 1)) - buf);
301 memcpy(tmp, buf, width);
302 unsigned char *destAdr = va_arg(ap,
unsigned char *);
303 unsigned long destVal = 0;
304 for (
int i = 0; i < width; i++)
307 destVal |= (
unsigned char)(0xFF & tmp[i]);
309 for (
int i = 0; i < width; i++)
311 unsigned char val = (
unsigned char)(0xFF & (destVal >> (i * 8)));
317 strncpy(tmp, buf, width);
320 binAtob(va_arg(ap,
unsigned long *), tmp, base);
326 width = noassign = lflag = 0;
345 binScanfVec(
const std::vector<unsigned char> *vec,
const char *fmt, ...)
347 if (vec->size() == 0)
351 const char *buf = (
const char *)(&(*vec)[0]);
353 int bufLen = (int)vec->size();
373 if (scanfMask == NULL)
378 const char *
s = scanfMask;
379 const char *tc = NULL;
390 if (strchr(
"dibouxycsefg%", *s))
394 else if (*s ==
'l' || *s ==
'L')
396 else if (*s >=
'1' && *s <=
'9') {
397 for (tc = s; isdigit(*s); s++);
398 strncpy(tmp, tc, s - tc);
400 sscanf(tmp,
"%d", &width);
int binScanfGuessDataLenFromMask(const char *scanfMask)
int binSscanf(const char *fmt,...)
int binScanfVec(const std::vector< unsigned char > *vec, const char *fmt,...)
static int _binAtob(unsigned long *vp, char *p, int base)
int binAtob(unsigned long *vp, char *p, int base)
static char * _binGetbase(char *p, int *basep)
int binFscanf(FILE *fp, const char *fmt,...)
static sick_scan::SickScanCommonTcp * s
static int binVfscanf(FILE *fp, const char *fmt, va_list ap)
static int binVsscanf(const char *bufOrg, const char *s, va_list ap, int bufLen)
sscanf-like function In addition to standard sscanf a format identifier "y" is introduced to parse bi...