Revision: 57154
http://sourceforge.net/p/brlcad/code/57154
Author: brlcad
Date: 2013-08-27 00:30:35 +0000 (Tue, 27 Aug 2013)
Log Message:
-----------
ws indent formatting
Modified Paths:
--------------
brlcad/trunk/src/libbu/sscanf.c
Modified: brlcad/trunk/src/libbu/sscanf.c
===================================================================
--- brlcad/trunk/src/libbu/sscanf.c 2013-08-27 00:22:42 UTC (rev 57153)
+++ brlcad/trunk/src/libbu/sscanf.c 2013-08-27 00:30:35 UTC (rev 57154)
@@ -53,40 +53,40 @@
/*
* Flags used during conversion.
*/
-#define LONG 0x00001 /* l: long or double */
-#define LONGDBL 0x00002 /* L: long double */
-#define SHORT 0x00004 /* h: short */
-#define SUPPRESS 0x00008 /* *: suppress assignment */
-#define POINTER 0x00010 /* p: void * (as hex) */
-#define NOSKIP 0x00020 /* [ or c: do not skip blanks */
-#define LONGLONG 0x00400 /* ll: long long (+ deprecated q: quad)
*/
-#define INTMAXT 0x00800 /* j: intmax_t */
-#define PTRDIFFT 0x01000 /* t: ptrdiff_t */
-#define SIZET 0x02000 /* z: size_t */
-#define SHORTSHORT 0x04000 /* hh: char */
-#define UNSIGNED 0x08000 /* %[oupxX] conversions */
-#define ALTERNATE 0x40000 /* # flag for alternate behavior */
+#define LONG 0x00001 /* l: long or double */
+#define LONGDBL 0x00002 /* L: long double */
+#define SHORT 0x00004 /* h: short */
+#define SUPPRESS 0x00008 /* *: suppress assignment */
+#define POINTER 0x00010 /* p: void * (as hex) */
+#define NOSKIP 0x00020 /* [ or c: do not skip blanks */
+#define LONGLONG 0x00400 /* ll: long long (+ deprecated q: quad) */
+#define INTMAXT 0x00800 /* j: intmax_t */
+#define PTRDIFFT 0x01000 /* t: ptrdiff_t */
+#define SIZET 0x02000 /* z: size_t */
+#define SHORTSHORT 0x04000 /* hh: char */
+#define UNSIGNED 0x08000 /* %[oupxX] conversions */
+#define ALTERNATE 0x40000 /* # flag for alternate behavior */
/*
* The following are used in integral conversions only:
* SIGNOK, NDIGITS, PFXOK, and NZDIGITS
*/
-#define SIGNOK 0x00040 /* +/- is (still) legal */
-#define NDIGITS 0x00080 /* no digits detected */
-#define PFXOK 0x00100 /* 0x prefix is (still) legal */
-#define NZDIGITS 0x00200 /* no zero digits detected */
-#define HAVESIGN 0x10000 /* sign detected */
-#define HAVEWIDTH 0x20000
+#define SIGNOK 0x00040 /* +/- is (still) legal */
+#define NDIGITS 0x00080 /* no digits detected */
+#define PFXOK 0x00100 /* 0x prefix is (still) legal */
+#define NZDIGITS 0x00200 /* no zero digits detected */
+#define HAVESIGN 0x10000 /* sign detected */
+#define HAVEWIDTH 0x20000
/*
* Conversion types.
*/
-#define CT_CHAR 0 /* %c conversion */
-#define CT_CCL 1 /* %[...] conversion */
-#define CT_STRING 2 /* %s conversion */
-#define CT_INT 3 /* %[dioupxX] conversion */
-#define CT_FLOAT 4 /* %[efgEFG] conversion */
-#define CT_VLS 5 /* %V and %#V conversion */
+#define CT_CHAR 0 /* %c conversion */
+#define CT_CCL 1 /* %[...] conversion */
+#define CT_STRING 2 /* %s conversion */
+#define CT_INT 3 /* %[dioupxX] conversion */
+#define CT_FLOAT 4 /* %[efgEFG] conversion */
+#define CT_VLS 5 /* %V and %#V conversion */
/* The basic strategy of this routine is to break the formatted scan into
* pieces, one for each conversion in the format string.
@@ -179,7 +179,7 @@
/* scan literal sequence */
GET_FORMAT_PART;
partAssigned = sscanf(&src[numCharsConsumed],
- bu_vls_addr(&partFmt), &partConsumed);
+ bu_vls_addr(&partFmt), &partConsumed);
if (partAssigned < 0) {
EXIT_DUE_TO_INPUT_FAILURE;
@@ -192,244 +192,244 @@
width = 0;
flags = 0;
-again:
+ again:
c = *fmt++;
bu_vls_putc(&partFmt, c);
switch (c) {
- /* Literal '%'. */
- case '%':
- GET_FORMAT_PART;
- partAssigned = sscanf(&src[numCharsConsumed],
- bu_vls_addr(&partFmt), &partConsumed);
+ /* Literal '%'. */
+ case '%':
+ GET_FORMAT_PART;
+ partAssigned = sscanf(&src[numCharsConsumed],
+ bu_vls_addr(&partFmt), &partConsumed);
- if (partAssigned < 0) {
- EXIT_DUE_TO_INPUT_FAILURE;
- }
- UPDATE_COUNTS;
- continue;
+ if (partAssigned < 0) {
+ EXIT_DUE_TO_INPUT_FAILURE;
+ }
+ UPDATE_COUNTS;
+ continue;
- /* MODIFIER */
- case '*':
- flags |= SUPPRESS;
- goto again;
- case '#':
- flags |= ALTERNATE;
- goto again;
- case 'j':
- flags |= INTMAXT;
- goto again;
- case 'l':
- if (!(flags & LONG)) {
- /* First occurrence of 'l' in this conversion specifier. */
- flags |= LONG;
- } else {
- /* Since LONG is set, the previous conversion character must
- * have been 'l'. With this second 'l', we know we have an "ll"
- * modifier, not an 'l' modifier. We need to replace the
- * incorrect flag with the correct one.
- */
- flags &= ~LONG;
- flags |= LONGLONG;
- }
- goto again;
- case 't':
+ /* MODIFIER */
+ case '*':
+ flags |= SUPPRESS;
+ goto again;
+ case '#':
+ flags |= ALTERNATE;
+ goto again;
+ case 'j':
+ flags |= INTMAXT;
+ goto again;
+ case 'l':
+ if (!(flags & LONG)) {
+ /* First occurrence of 'l' in this conversion specifier. */
+ flags |= LONG;
+ } else {
+ /* Since LONG is set, the previous conversion character must
+ * have been 'l'. With this second 'l', we know we have an
"ll"
+ * modifier, not an 'l' modifier. We need to replace the
+ * incorrect flag with the correct one.
+ */
+ flags &= ~LONG;
+ flags |= LONGLONG;
+ }
+ goto again;
+ case 't':
#ifndef HAVE_C99_FORMAT_SPECIFIERS
- /* remove C99 't' */
- bu_vls_trunc(&partFmt, bu_vls_strlen(&partFmt) - 1);
+ /* remove C99 't' */
+ bu_vls_trunc(&partFmt, bu_vls_strlen(&partFmt) - 1);
- /* Assume MSVC.
- *
- * For 32-bit, ptrdiff_t is __int32, and equivalent of %t[dioxX] is
- * %[dioxX].
- *
- * For 64-bit, ptrdiff_t is __int64, and equivalent of %t[dioxX] is
- * %I64[dioxX].
- */
+ /* Assume MSVC.
+ *
+ * For 32-bit, ptrdiff_t is __int32, and equivalent of
%t[dioxX] is
+ * %[dioxX].
+ *
+ * For 64-bit, ptrdiff_t is __int64, and equivalent of
%t[dioxX] is
+ * %I64[dioxX].
+ */
#if defined(SIZEOF_SIZE_T) && SIZEOF_SIZE_T == 8
- bu_vls_strcat(&partFmt, "I64");
+ bu_vls_strcat(&partFmt, "I64");
#endif
#endif
- flags |= PTRDIFFT;
- goto again;
- case 'z':
+ flags |= PTRDIFFT;
+ goto again;
+ case 'z':
#ifndef HAVE_C99_FORMAT_SPECIFIERS
- /* remove C99 'z' */
- bu_vls_trunc(&partFmt, bu_vls_strlen(&partFmt) - 1);
+ /* remove C99 'z' */
+ bu_vls_trunc(&partFmt, bu_vls_strlen(&partFmt) - 1);
- /* Assume MSVC.
- *
- * For 32-bit, size_t is unsigned __int32, and equivalent of
- * %z[dioxX] is %[dioxX].
- *
- * For 64-bit, size_t is unsigned __int64, and equivalent of
- * %z[dioxX] is %I64[dioxX].
- */
+ /* Assume MSVC.
+ *
+ * For 32-bit, size_t is unsigned __int32, and equivalent of
+ * %z[dioxX] is %[dioxX].
+ *
+ * For 64-bit, size_t is unsigned __int64, and equivalent of
+ * %z[dioxX] is %I64[dioxX].
+ */
#if defined(SIZEOF_SIZE_T) && SIZEOF_SIZE_T == 8
- bu_vls_strcat(&partFmt, "I64");
+ bu_vls_strcat(&partFmt, "I64");
#endif
#endif
- flags |= SIZET;
- goto again;
- case 'L':
- flags |= LONGDBL;
- goto again;
- case 'h':
- if (!(flags & SHORT)) {
- /* First occurrence of 'h' in this conversion specifier. */
- flags |= SHORT;
- } else {
+ flags |= SIZET;
+ goto again;
+ case 'L':
+ flags |= LONGDBL;
+ goto again;
+ case 'h':
+ if (!(flags & SHORT)) {
+ /* First occurrence of 'h' in this conversion specifier. */
+ flags |= SHORT;
+ } else {
#ifndef HAVE_C99_FORMAT_SPECIFIERS
- /* Assume MSVC, where there is no equivalent of %hh[diouxX].
- * Will use %h[diouxX] with short instead, then cast into
- * char argument.
- */
- bu_vls_trunc(&partFmt, bu_vls_strlen(&partFmt) - 1);
+ /* Assume MSVC, where there is no equivalent of %hh[diouxX].
+ * Will use %h[diouxX] with short instead, then cast into
+ * char argument.
+ */
+ bu_vls_trunc(&partFmt, bu_vls_strlen(&partFmt) - 1);
#endif
- /* Since SHORT is set, the previous conversion character must
- * have been 'h'. With this second 'h', we know we have an "hh"
- * modifier, not an 'h' modifier. We need to replace the
- * incorrect flag with the correct one.
- */
- flags &= ~SHORT;
- flags |= SHORTSHORT;
- }
- goto again;
+ /* Since SHORT is set, the previous conversion character
must
+ * have been 'h'. With this second 'h', we know we have an
"hh"
+ * modifier, not an 'h' modifier. We need to replace the
+ * incorrect flag with the correct one.
+ */
+ flags &= ~SHORT;
+ flags |= SHORTSHORT;
+ }
+ goto again;
- /* MAXIMUM FIELD WIDTH */
+ /* MAXIMUM FIELD WIDTH */
#define NUMERIC_CHAR_TO_INT(c) (c - '0')
- case '0':
- /* distinguish default width from width set to 0 */
- flags |= HAVEWIDTH;
- /* FALLTHROUGH */
- case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9':
- width = (width * 10) + NUMERIC_CHAR_TO_INT(c);
- goto again;
+ case '0':
+ /* distinguish default width from width set to 0 */
+ flags |= HAVEWIDTH;
+ /* FALLTHROUGH */
+ case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ width = (width * 10) + NUMERIC_CHAR_TO_INT(c);
+ goto again;
- /* CONVERSION */
- case 'd':
- c = CT_INT;
- break;
- case 'i':
- c = CT_INT;
- break;
- case 'o':
- c = CT_INT;
- flags |= UNSIGNED;
- break;
- case 'u':
- c = CT_INT;
- flags |= UNSIGNED;
- break;
- case 'p':
- case 'x':
- case 'X':
- if (c == 'p') {
- flags |= POINTER;
- }
- flags |= PFXOK;
- flags |= UNSIGNED;
- c = CT_INT;
- break;
- case 'A': case 'E': case 'F': case 'G':
- case 'a': case 'e': case 'f': case 'g':
- /* e/f/g, E/F/G, and a/A (C99) are all synonyms for float
- * conversion. Support for a/A is limited to C99-compliant
- * implementations, and there is varying support for E/F/G.
- * Replace all with the most portable 'f' variant.
- */
- bu_vls_trunc(&partFmt, bu_vls_strlen(&partFmt) - 1);
- bu_vls_putc(&partFmt, 'f');
- c = CT_FLOAT;
- break;
- case 's':
- c = CT_STRING;
- break;
- case '[':
- /* note that at this point c == '[' == fmt[-1] and so fmt[0] is
- * either '^' or the first character of the class
- */
+ /* CONVERSION */
+ case 'd':
+ c = CT_INT;
+ break;
+ case 'i':
+ c = CT_INT;
+ break;
+ case 'o':
+ c = CT_INT;
+ flags |= UNSIGNED;
+ break;
+ case 'u':
+ c = CT_INT;
+ flags |= UNSIGNED;
+ break;
+ case 'p':
+ case 'x':
+ case 'X':
+ if (c == 'p') {
+ flags |= POINTER;
+ }
+ flags |= PFXOK;
+ flags |= UNSIGNED;
+ c = CT_INT;
+ break;
+ case 'A': case 'E': case 'F': case 'G':
+ case 'a': case 'e': case 'f': case 'g':
+ /* e/f/g, E/F/G, and a/A (C99) are all synonyms for float
+ * conversion. Support for a/A is limited to C99-compliant
+ * implementations, and there is varying support for E/F/G.
+ * Replace all with the most portable 'f' variant.
+ */
+ bu_vls_trunc(&partFmt, bu_vls_strlen(&partFmt) - 1);
+ bu_vls_putc(&partFmt, 'f');
+ c = CT_FLOAT;
+ break;
+ case 's':
+ c = CT_STRING;
+ break;
+ case '[':
+ /* note that at this point c == '[' == fmt[-1] and so fmt[0] is
+ * either '^' or the first character of the class
+ */
- /* there should be at least one character in between brackets */
- if (fmt[0] == '\0' || fmt[1] == '\0') {
- EXIT_DUE_TO_MISC_ERROR;
- }
+ /* there should be at least one character in between brackets */
+ if (fmt[0] == '\0' || fmt[1] == '\0') {
+ EXIT_DUE_TO_MISC_ERROR;
+ }
- /* skip literal ']' ("[]" or "[^]") */
- if (fmt[0] == ']') {
- fmt = &fmt[1];
- } else if (fmt[0] == '^' && fmt[1] == ']') {
- fmt = &fmt[2];
- }
+ /* skip literal ']' ("[]" or "[^]") */
+ if (fmt[0] == ']') {
+ fmt = &fmt[1];
+ } else if (fmt[0] == '^' && fmt[1] == ']') {
+ fmt = &fmt[2];
+ }
- /* point fmt after character class */
- while (1) {
- c = *fmt++;
- bu_vls_putc(&partFmt, c);
+ /* point fmt after character class */
+ while (1) {
+ c = *fmt++;
+ bu_vls_putc(&partFmt, c);
- if (c == '\0') {
- EXIT_DUE_TO_MISC_ERROR;
+ if (c == '\0') {
+ EXIT_DUE_TO_MISC_ERROR;
+ }
+ if (c == ']') {
+ /* found end of character class */
+ break;
+ }
}
- if (c == ']') {
- /* found end of character class */
- break;
+
+ flags |= NOSKIP;
+ c = CT_CCL;
+ break;
+ case 'c':
+ flags |= NOSKIP;
+ c = CT_CHAR;
+ break;
+ case 'V':
+ c = CT_VLS;
+ break;
+ case 'n':
+ if (flags & SUPPRESS) {
+ /* This is legal, but doesn't really make sense. Caller
+ * requested assignment of the current count of consumed
+ * characters, but then suppressed the assignment they
+ * requested!
+ */
+ continue;
}
- }
- flags |= NOSKIP;
- c = CT_CCL;
- break;
- case 'c':
- flags |= NOSKIP;
- c = CT_CHAR;
- break;
- case 'V':
- c = CT_VLS;
- break;
- case 'n':
- if (flags & SUPPRESS) {
- /* This is legal, but doesn't really make sense. Caller
- * requested assignment of the current count of consumed
- * characters, but then suppressed the assignment they
- * requested!
+ /* Store current count of consumed characters to whatever kind
of
+ * int pointer was provided.
*/
+ if (flags & SHORTSHORT) {
+ *va_arg(ap, char *) = numCharsConsumed;
+ } else if (flags & SHORT) {
+ *va_arg(ap, short *) = numCharsConsumed;
+ } else if (flags & LONG) {
+ *va_arg(ap, long *) = numCharsConsumed;
+ } else if (flags & LONGLONG) {
+ *va_arg(ap, long long *) = numCharsConsumed;
+ } else if (flags & INTMAXT) {
+ *va_arg(ap, intmax_t *) = numCharsConsumed;
+ } else if (flags & SIZET) {
+ *va_arg(ap, size_t *) = numCharsConsumed;
+ } else if (flags & PTRDIFFT) {
+ *va_arg(ap, ptrdiff_t *) = numCharsConsumed;
+ } else {
+ *va_arg(ap, int *) = numCharsConsumed;
+ }
continue;
- }
- /* Store current count of consumed characters to whatever kind of
- * int pointer was provided.
- */
- if (flags & SHORTSHORT) {
- *va_arg(ap, char *) = numCharsConsumed;
- } else if (flags & SHORT) {
- *va_arg(ap, short *) = numCharsConsumed;
- } else if (flags & LONG) {
- *va_arg(ap, long *) = numCharsConsumed;
- } else if (flags & LONGLONG) {
- *va_arg(ap, long long *) = numCharsConsumed;
- } else if (flags & INTMAXT) {
- *va_arg(ap, intmax_t *) = numCharsConsumed;
- } else if (flags & SIZET) {
- *va_arg(ap, size_t *) = numCharsConsumed;
- } else if (flags & PTRDIFFT) {
- *va_arg(ap, ptrdiff_t *) = numCharsConsumed;
- } else {
- *va_arg(ap, int *) = numCharsConsumed;
- }
- continue;
+ case '\0':
+ /* Format string ends with bare '%'. Returning EOF regardless of
+ * successful assignments is a backwards compatibility behavior.
+ */
+ EXIT_DUE_TO_MISC_ERROR;
- case '\0':
- /* Format string ends with bare '%'. Returning EOF regardless of
- * successful assignments is a backwards compatibility behavior.
- */
- EXIT_DUE_TO_MISC_ERROR;
-
- default:
- EXIT_DUE_TO_MATCH_FAILURE;
+ default:
+ EXIT_DUE_TO_MATCH_FAILURE;
}
/* Done parsing conversion specification.
@@ -439,215 +439,217 @@
GET_FORMAT_PART;
#define SSCANF_TYPE(type) \
- if (flags & SUPPRESS) { \
- partAssigned = sscanf(&src[numCharsConsumed], bu_vls_addr(&partFmt), \
- &partConsumed); \
- } else { \
- partAssigned = sscanf(&src[numCharsConsumed], bu_vls_addr(&partFmt), \
- va_arg(ap, type), &partConsumed); \
- }
+ if (flags & SUPPRESS) { \
+ partAssigned = sscanf(&src[numCharsConsumed],
bu_vls_addr(&partFmt), \
+ &partConsumed); \
+ } else { \
+ partAssigned = sscanf(&src[numCharsConsumed],
bu_vls_addr(&partFmt), \
+ va_arg(ap, type), &partConsumed); \
+ }
#define SSCANF_SIGNED_UNSIGNED(type) \
-if (flags & UNSIGNED) { \
- SSCANF_TYPE(unsigned type); \
-} else { \
- SSCANF_TYPE(type); \
-}
+ if (flags & UNSIGNED) { \
+ SSCANF_TYPE(unsigned type); \
+ } else { \
+ SSCANF_TYPE(type); \
+ }
+
+
partAssigned = partConsumed = 0;
switch (c) {
- case CT_VLS:
- /* %V %#V conversion */
- {
- struct bu_vls *vls = NULL;
+ case CT_VLS:
+ /* %V %#V conversion */
+ {
+ struct bu_vls *vls = NULL;
- if (src[numCharsConsumed] == '\0') {
- EXIT_DUE_TO_INPUT_FAILURE;
- }
+ if (src[numCharsConsumed] == '\0') {
+ EXIT_DUE_TO_INPUT_FAILURE;
+ }
- /* Leading input whitespace is skipped for %#V, and for %V if the
- * conversion specification is preceded by at least one whitespace
- * character.
- */
- if (isspace((int)(*bu_vls_addr(&partFmt))) || flags & ALTERNATE) {
- while (1) {
- c = src[numCharsConsumed];
- if (c == '\0' || !isspace(c)) {
- break;
+ /* Leading input whitespace is skipped for %#V, and for %V
if the
+ * conversion specification is preceded by at least one
whitespace
+ * character.
+ */
+ if (isspace((int)(*bu_vls_addr(&partFmt))) || flags &
ALTERNATE) {
+ while (1) {
+ c = src[numCharsConsumed];
+ if (c == '\0' || !isspace(c)) {
+ break;
+ }
+ ++numCharsConsumed;
+ }
}
- ++numCharsConsumed;
- }
- }
- /* if no width provided, width is infinity */
- if (width == 0 && !(flags & HAVEWIDTH)) {
- width = ~(width & 0);
- }
+ /* if no width provided, width is infinity */
+ if (width == 0 && !(flags & HAVEWIDTH)) {
+ width = ~(width & 0);
+ }
- /* grab vls pointer if we're assigning */
- if (!(flags & SUPPRESS)) {
- vls = va_arg(ap, struct bu_vls*);
- }
+ /* grab vls pointer if we're assigning */
+ if (!(flags & SUPPRESS)) {
+ vls = va_arg(ap, struct bu_vls*);
+ }
- /* Copy characters from src to vls. Stop at width, whitespace
- * character, or EOI.
- */
- if (flags & SUPPRESS) {
- for (i = 0; i < width; ++i) {
- c = src[numCharsConsumed + i];
+ /* Copy characters from src to vls. Stop at width,
whitespace
+ * character, or EOI.
+ */
+ if (flags & SUPPRESS) {
+ for (i = 0; i < width; ++i) {
+ c = src[numCharsConsumed + i];
- /* stop at non-matching or EOI */
- if (c == '\0') {
- break;
- }
- if ((flags & ALTERNATE) && isspace(c)) {
- break;
- }
- ++partConsumed;
- }
- } else {
- for (i = 0; i < width; ++i) {
- c = src[numCharsConsumed + i];
+ /* stop at non-matching or EOI */
+ if (c == '\0') {
+ break;
+ }
+ if ((flags & ALTERNATE) && isspace(c)) {
+ break;
+ }
+ ++partConsumed;
+ }
+ } else {
+ for (i = 0; i < width; ++i) {
+ c = src[numCharsConsumed + i];
- /* stop at non-matching or EOI */
- /* stop at non-matching or EOI */
- if (c == '\0') {
- break;
+ /* stop at non-matching or EOI */
+ /* stop at non-matching or EOI */
+ if (c == '\0') {
+ break;
+ }
+ if ((flags & ALTERNATE) && isspace(c)) {
+ break;
+ }
+
+ /* copy valid char to vls */
+ bu_vls_putc(vls, c);
+ ++partConsumed;
+ }
+
+ if (partConsumed > 0) {
+ /* successful assignment */
+ ++partAssigned;
+ }
}
- if ((flags & ALTERNATE) && isspace(c)) {
- break;
- }
+ break;
+ } /* CT_VLS */
- /* copy valid char to vls */
- bu_vls_putc(vls, c);
- ++partConsumed;
- }
+ case CT_CHAR:
+ case CT_CCL:
+ case CT_STRING:
- if (partConsumed > 0) {
- /* successful assignment */
- ++partAssigned;
+ /* %lc %l[...] %ls are unsupported */
+ if (flags & LONG) {
+ EXIT_DUE_TO_MISC_ERROR;
}
- }
- break;
- } /* CT_VLS */
- case CT_CHAR:
- case CT_CCL:
- case CT_STRING:
+ /* unsuppressed %s or %[...] conversion */
+ if (!(flags & SUPPRESS)) {
+ if (width == 0) {
+ if (flags & HAVEWIDTH) {
+ /* Caller specified zero width in the format string.
+ * (%0c %0s or %0[...])
+ *
+ * The behavior of sscanf for a zero width is
+ * undefined, so we provide our own consistent
+ * behavior here.
+ *
+ * The assignment wasn't suppressed, so we'll assume
+ * the caller provided a pointer and wants us to
write
+ * to it. Just write '\0' and call it a successful
+ * assignment.
+ */
+ *va_arg(ap, char*) = '\0';
+ ++partAssigned;
+ break;
+ } else if (c != CT_CHAR) {
+ struct bu_vls err = BU_VLS_INIT_ZERO;
- /* %lc %l[...] %ls are unsupported */
- if (flags & LONG) {
- EXIT_DUE_TO_MISC_ERROR;
- }
-
- /* unsuppressed %s or %[...] conversion */
- if (!(flags & SUPPRESS)) {
- if (width == 0) {
- if (flags & HAVEWIDTH) {
- /* Caller specified zero width in the format string.
- * (%0c %0s or %0[...])
- *
- * The behavior of sscanf for a zero width is
- * undefined, so we provide our own consistent
- * behavior here.
- *
- * The assignment wasn't suppressed, so we'll assume
- * the caller provided a pointer and wants us to write
- * to it. Just write '\0' and call it a successful
- * assignment.
- */
- *va_arg(ap, char*) = '\0';
- ++partAssigned;
- break;
- } else if (c != CT_CHAR) {
- struct bu_vls err = BU_VLS_INIT_ZERO;
-
- /* No width was provided by caller.
- *
- * If the caller is using %s or %[...] without a
- * maximum field width, then there is a bug in the
- * caller code.
- *
- * sscanf could easily overrun the provided buffer and
- * cause a program crash, so just bomb here and make
- * the source of the problem clear.
- */
- bu_vls_sprintf(&err, "ERROR.\n"
- " bu_sscanf was called with bad format
string: \"%s\"\n"
- " %%s and %%[...] conversions must be
bounded using "
- "a maximum field width.", fmt0);
- bu_bomb(bu_vls_addr(&err));
+ /* No width was provided by caller.
+ *
+ * If the caller is using %s or %[...] without a
+ * maximum field width, then there is a bug in the
+ * caller code.
+ *
+ * sscanf could easily overrun the provided buffer
and
+ * cause a program crash, so just bomb here and make
+ * the source of the problem clear.
+ */
+ bu_vls_sprintf(&err, "ERROR.\n"
+ " bu_sscanf was called with bad
format string: \"%s\"\n"
+ " %%s and %%[...] conversions must
be bounded using "
+ "a maximum field width.", fmt0);
+ bu_bomb(bu_vls_addr(&err));
+ }
}
}
- }
- /* ordinary %c or %[...] or %s conversion */
- SSCANF_TYPE(char*);
- break;
+ /* ordinary %c or %[...] or %s conversion */
+ SSCANF_TYPE(char*);
+ break;
- /* %[dioupxX] conversion */
- case CT_INT:
- if (flags & SHORT) {
- SSCANF_SIGNED_UNSIGNED(short int*);
- } else if (flags & SHORTSHORT) {
+ /* %[dioupxX] conversion */
+ case CT_INT:
+ if (flags & SHORT) {
+ SSCANF_SIGNED_UNSIGNED(short int*);
+ } else if (flags & SHORTSHORT) {
#ifndef HAVE_C99_FORMAT_SPECIFIERS
- /* Assume MSVC, where there is no equivalent of %hh[diouxX].
- * Will use %h[diouxX] with short instead, then cast into
- * char argument.
- */
- if (flags & SUPPRESS) {
- partAssigned = sscanf(&src[numCharsConsumed],
- bu_vls_addr(&partFmt), &partConsumed);
- } else {
- if (flags & UNSIGNED) {
- unsigned short charConvVal = 0;
+ /* Assume MSVC, where there is no equivalent of %hh[diouxX].
+ * Will use %h[diouxX] with short instead, then cast into
+ * char argument.
+ */
+ if (flags & SUPPRESS) {
partAssigned = sscanf(&src[numCharsConsumed],
- bu_vls_addr(&partFmt), &charConvVal,
- &partConsumed);
- *va_arg(ap, unsigned char*) = (unsigned
char)charConvVal;
+ bu_vls_addr(&partFmt),
&partConsumed);
} else {
- short charConvVal = 0;
- partAssigned = sscanf(&src[numCharsConsumed],
- bu_vls_addr(&partFmt), &charConvVal,
- &partConsumed);
- *va_arg(ap, signed char*) = (signed char)charConvVal;
+ if (flags & UNSIGNED) {
+ unsigned short charConvVal = 0;
+ partAssigned = sscanf(&src[numCharsConsumed],
+ bu_vls_addr(&partFmt),
&charConvVal,
+ &partConsumed);
+ *va_arg(ap, unsigned char*) = (unsigned
char)charConvVal;
+ } else {
+ short charConvVal = 0;
+ partAssigned = sscanf(&src[numCharsConsumed],
+ bu_vls_addr(&partFmt),
&charConvVal,
+ &partConsumed);
+ *va_arg(ap, signed char*) = (signed
char)charConvVal;
+ }
}
- }
#else
- SSCANF_SIGNED_UNSIGNED(char*);
+ SSCANF_SIGNED_UNSIGNED(char*);
#endif
- } else if (flags & LONG) {
- SSCANF_SIGNED_UNSIGNED(long int*);
- } else if (flags & LONGLONG) {
- SSCANF_SIGNED_UNSIGNED(long long int*);
- } else if (flags & POINTER) {
- SSCANF_TYPE(void*);
- } else if (flags & PTRDIFFT) {
- SSCANF_TYPE(ptrdiff_t*);
- } else if (flags & SIZET) {
- SSCANF_TYPE(size_t*);
- } else if (flags & INTMAXT) {
- if (flags & UNSIGNED) {
- SSCANF_TYPE(uintmax_t*);
+ } else if (flags & LONG) {
+ SSCANF_SIGNED_UNSIGNED(long int*);
+ } else if (flags & LONGLONG) {
+ SSCANF_SIGNED_UNSIGNED(long long int*);
+ } else if (flags & POINTER) {
+ SSCANF_TYPE(void*);
+ } else if (flags & PTRDIFFT) {
+ SSCANF_TYPE(ptrdiff_t*);
+ } else if (flags & SIZET) {
+ SSCANF_TYPE(size_t*);
+ } else if (flags & INTMAXT) {
+ if (flags & UNSIGNED) {
+ SSCANF_TYPE(uintmax_t*);
+ } else {
+ SSCANF_TYPE(intmax_t*);
+ }
} else {
- SSCANF_TYPE(intmax_t*);
+ SSCANF_TYPE(int*);
}
- } else {
- SSCANF_TYPE(int*);
- }
- break;
+ break;
- /* %[aefgAEFG] conversion */
- case CT_FLOAT:
- if (flags & LONG) {
- SSCANF_TYPE(double*);
- } else if (flags & LONGDBL) {
- SSCANF_TYPE(long double*);
- } else {
- SSCANF_TYPE(float*);
- }
+ /* %[aefgAEFG] conversion */
+ case CT_FLOAT:
+ if (flags & LONG) {
+ SSCANF_TYPE(double*);
+ } else if (flags & LONGDBL) {
+ SSCANF_TYPE(long double*);
+ } else {
+ SSCANF_TYPE(float*);
+ }
}
/* check for read error or bad source string */
@@ -669,6 +671,7 @@
return numFieldsAssigned;
} /* bu_vsscanf */
+
int
bu_sscanf(const char *src, const char *fmt, ...)
{
@@ -682,6 +685,7 @@
return ret;
}
+
/*
* Local Variables:
* tab-width: 8
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Introducing Performance Central, a new site from SourceForge and
AppDynamics. Performance Central is your source for news, insights,
analysis and resources for efficient Application Performance Management.
Visit us today!
http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits