BRL-CAD
bu_sscanf.c File Reference
#include "common.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "bu.h"
#include "vmath.h"
Include dependency graph for bu_sscanf.c:

Go to the source code of this file.

Macros

#define TS_FLOAT_TOL   .0005
 
#define TS_STR_SIZE   128
 
#define TS_STR_WIDTH   "127"
 
#define CHECK_INT_VALS_EQUAL(int_type, pfmt, valp, bu_valp)
 
#define CHECK_FLOAT_VALS_EQUAL(float_type, pfmt, valp, bu_valp)
 
#define SSCANF_TYPE(type)
 
#define SIGNED_HH_DEC   127
 
#define UNSIGNED_HH_DEC   255
 
#define SIGNED_HH_OCT   0177
 
#define UNSIGNED_HH_OCT   0377
 
#define SIGNED_HH_HEX   0x7F
 
#define UNSIGNED_HH_HEX   0xFF
 
#define SIGNED_DEC   32767
 
#define UNSIGNED_DEC   65535
 
#define SIGNED_OCT   0077777
 
#define UNSIGNED_OCT   0177777
 
#define SIGNED_HEX   0x7FFF
 
#define UNSIGNED_HEX   0xFFFF
 
#define SIGNED_L_DEC   2147483647
 
#define UNSIGNED_L_DEC   4294967295
 
#define SIGNED_L_OCT   17777777777
 
#define UNSIGNED_L_OCT   37777777777
 
#define SIGNED_L_HEX   0x7FFFFFFF
 
#define UNSIGNED_L_HEX   0xFFFFFFFF
 
#define SMALL_FLT   1.0e-37
 
#define LARGE_FLT   1.0e+37
 
#define TEST_SIGNED_CONSTANT(str, fmt)
 
#define TEST_UNSIGNED_CONSTANT(str, fmt)
 
#define TEST_SIGNED_CONSTANTS(small, med, large, fmt)
 
#define TEST_UNSIGNED_CONSTANTS(small, med, large, fmt)
 
#define TEST_FLOAT_CONSTANT(c, fmt)
 
#define TEST_FLOAT_VARIANT(fmt)
 
#define TEST_STR_SPACE   " \t\naBc\n"
 
#define TEST_STR_NOSPACE   "aBc"
 
#define TEST_TERMINATION(src, fmt)
 
#define TS_NUM_ASSIGNMENTS   3
 
#define SCAN_3_VALS(type, src, fmt)
 
#define TEST_INT_WIDTH(type, pfmt, src, fmt)
 
#define TEST_FLOAT_WIDTH(type, pfmt, src, fmt)
 
#define FMT_ASSIGN3(fmt)   "%" bu_cpp_str(fmt) " %" bu_cpp_str(fmt) " %" bu_cpp_str(fmt)
 
#define FMT_READ2_ASSIGN1(fmt)   "%*" bu_cpp_str(fmt) " %*" bu_cpp_str(fmt) " %" bu_cpp_str(fmt)
 
#define TEST_FAILURE_1(type, type_fmt, type_init, src, expected_err)
 
#define TEST_FAILURE_2(type, type_fmt, type_init, src, expected_err)
 
#define EXPECT_MATCH_FAILURE   0
 
#define EXPECT_INPUT_FAILURE   EOF
 

Enumerations

enum  {
  SCAN_SHORTSHORT, SCAN_USHORTSHORT, SCAN_SHORT, SCAN_USHORT,
  SCAN_INT, SCAN_UINT, SCAN_LONG, SCAN_ULONG,
  SCAN_POINTER, SCAN_FLOAT, SCAN_DOUBLE, SCAN_LDOUBLE,
  SCAN_SIZE, SCAN_PTRDIFF
}
 

Functions

int main (int argc, char *argv[])
 

Detailed Description

Test bu_sscanf routine.

Definition in file bu_sscanf.c.

Macro Definition Documentation

#define TS_FLOAT_TOL   .0005

Definition at line 35 of file bu_sscanf.c.

#define TS_STR_SIZE   128

Definition at line 37 of file bu_sscanf.c.

#define TS_STR_WIDTH   "127"

Definition at line 38 of file bu_sscanf.c.

#define CHECK_INT_VALS_EQUAL (   int_type,
  pfmt,
  valp,
  bu_valp 
)
Value:
{ \
int_type _val = *(int_type*)(valp); \
int_type _bu_val = *(int_type*)(bu_valp); \
if (_val != _bu_val) { \
bu_exit(1, "\t[FAIL] conversion value mismatch.\n" \
"\t(sscanf) %" bu_cpp_str(pfmt) " != " \
"%" bu_cpp_str(pfmt) " (bu_sscanf).\n", \
_val, _bu_val); \
} \
}
#define bu_cpp_str(s)
Definition: defines.h:138
if(share_geom)
Definition: nmg_mod.c:3829
void bu_exit(int status, const char *fmt,...) _BU_ATTR_NORETURN _BU_ATTR_PRINTF23
Definition: bomb.c:195

Definition at line 151 of file bu_sscanf.c.

#define CHECK_FLOAT_VALS_EQUAL (   float_type,
  pfmt,
  valp,
  bu_valp 
)
Value:
{ \
float_type _val = *(float_type*)(valp); \
float_type _bu_val = *(float_type*)(bu_valp); \
if (!NEAR_EQUAL(_val, _bu_val, TS_FLOAT_TOL)) { \
bu_exit(1, "\t[FAIL] conversion value mismatch.\n" \
"\t(sscanf) %" bu_cpp_str(pfmt) " != " \
"%" bu_cpp_str(pfmt) " (bu_sscanf).\n", \
_val, _bu_val); \
} \
}
#define bu_cpp_str(s)
Definition: defines.h:138
#define TS_FLOAT_TOL
Definition: bu_sscanf.c:35
if(share_geom)
Definition: nmg_mod.c:3829
void bu_exit(int status, const char *fmt,...) _BU_ATTR_NORETURN _BU_ATTR_PRINTF23
Definition: bomb.c:195

Definition at line 163 of file bu_sscanf.c.

#define SSCANF_TYPE (   type)
Value:
BU_ALLOC(val, type); \
BU_ALLOC(bu_val, type); \
\
ret = sscanf(src, fmt, (type*)val); \
bu_ret = bu_sscanf(src, fmt, (type*)bu_val); \
\
checkReturnVal("sscanf", ret, 1); \
checkReturnsEqual(bu_ret, ret);
Definition: db_flip.c:35
#define BU_ALLOC(_ptr, _type)
Definition: malloc.h:223
int bu_sscanf(const char *src, const char *fmt,...) _BU_ATTR_SCANF23
Definition: sscanf.c:676
#define SIGNED_HH_DEC   127

Definition at line 282 of file bu_sscanf.c.

#define UNSIGNED_HH_DEC   255

Definition at line 283 of file bu_sscanf.c.

#define SIGNED_HH_OCT   0177

Definition at line 284 of file bu_sscanf.c.

#define UNSIGNED_HH_OCT   0377

Definition at line 285 of file bu_sscanf.c.

#define SIGNED_HH_HEX   0x7F

Definition at line 286 of file bu_sscanf.c.

#define UNSIGNED_HH_HEX   0xFF

Definition at line 287 of file bu_sscanf.c.

#define SIGNED_DEC   32767

Definition at line 289 of file bu_sscanf.c.

#define UNSIGNED_DEC   65535

Definition at line 290 of file bu_sscanf.c.

#define SIGNED_OCT   0077777

Definition at line 291 of file bu_sscanf.c.

#define UNSIGNED_OCT   0177777

Definition at line 292 of file bu_sscanf.c.

#define SIGNED_HEX   0x7FFF

Definition at line 293 of file bu_sscanf.c.

#define UNSIGNED_HEX   0xFFFF

Definition at line 294 of file bu_sscanf.c.

#define SIGNED_L_DEC   2147483647

Definition at line 296 of file bu_sscanf.c.

#define UNSIGNED_L_DEC   4294967295

Definition at line 297 of file bu_sscanf.c.

#define SIGNED_L_OCT   17777777777

Definition at line 298 of file bu_sscanf.c.

#define UNSIGNED_L_OCT   37777777777

Definition at line 299 of file bu_sscanf.c.

#define SIGNED_L_HEX   0x7FFFFFFF

Definition at line 300 of file bu_sscanf.c.

#define UNSIGNED_L_HEX   0xFFFFFFFF

Definition at line 301 of file bu_sscanf.c.

#define SMALL_FLT   1.0e-37

Definition at line 303 of file bu_sscanf.c.

#define LARGE_FLT   1.0e+37

Definition at line 304 of file bu_sscanf.c.

#define TEST_SIGNED_CONSTANT (   str,
  fmt 
)
Value:
test_sscanf(SCAN_SHORTSHORT, str, "%hh" bu_cpp_str(fmt)); \
test_sscanf(SCAN_SIZE, str, "%z" bu_cpp_str(fmt)); \
test_sscanf(SCAN_SHORT, str, "%h" bu_cpp_str(fmt)); \
test_sscanf(SCAN_INT, str, "%" bu_cpp_str(fmt)); \
test_sscanf(SCAN_LONG, str, "%l" bu_cpp_str(fmt));
#define bu_cpp_str(s)
Definition: defines.h:138
#define TEST_UNSIGNED_CONSTANT (   str,
  fmt 
)
Value:
test_sscanf(SCAN_USHORTSHORT, str, "%hh" bu_cpp_str(fmt)); \
test_sscanf(SCAN_SIZE, str, "%z" bu_cpp_str(fmt)); \
test_sscanf(SCAN_USHORT, str, "%h" bu_cpp_str(fmt)); \
test_sscanf(SCAN_UINT, str, "%" bu_cpp_str(fmt)); \
test_sscanf(SCAN_ULONG, str, "%l" bu_cpp_str(fmt));
#define bu_cpp_str(s)
Definition: defines.h:138
#define TEST_SIGNED_CONSTANTS (   small,
  med,
  large,
  fmt 
)
Value:
test_sscanf(SCAN_SHORTSHORT, "+" bu_cpp_str(small), "%hh" bu_cpp_str(fmt)); \
test_sscanf(SCAN_SHORTSHORT, bu_cpp_str(small), "%hh" bu_cpp_str(fmt)); \
test_sscanf(SCAN_SHORTSHORT, "-" bu_cpp_str(small), "%hh" bu_cpp_str(fmt)); \
test_sscanf(SCAN_SIZE, bu_cpp_str(small), "%z" bu_cpp_str(fmt)); \
test_sscanf(SCAN_SHORT, "+" bu_cpp_str(med), "%h" bu_cpp_str(fmt)); \
test_sscanf(SCAN_SHORT, bu_cpp_str(med), "%h" bu_cpp_str(fmt)); \
test_sscanf(SCAN_SHORT, "-" bu_cpp_str(med), "%h" bu_cpp_str(fmt)); \
test_sscanf(SCAN_INT, "+" bu_cpp_str(med), "%" bu_cpp_str(fmt)); \
test_sscanf(SCAN_INT, bu_cpp_str(med), "%" bu_cpp_str(fmt)); \
test_sscanf(SCAN_INT, "-" bu_cpp_str(med), "%" bu_cpp_str(fmt)); \
test_sscanf(SCAN_LONG, "+" bu_cpp_str(large), "%l" bu_cpp_str(fmt)); \
test_sscanf(SCAN_LONG, bu_cpp_str(large), "%l" bu_cpp_str(fmt)); \
test_sscanf(SCAN_LONG, "-" bu_cpp_str(large), "%l" bu_cpp_str(fmt));
#define bu_cpp_str(s)
Definition: defines.h:138
#define TEST_UNSIGNED_CONSTANTS (   small,
  med,
  large,
  fmt 
)
Value:
test_sscanf(SCAN_USHORTSHORT, bu_cpp_str(small), "%hh" bu_cpp_str(fmt)); \
test_sscanf(SCAN_SIZE, bu_cpp_str(small), "%z" bu_cpp_str(fmt)); \
test_sscanf(SCAN_USHORT, bu_cpp_str(med), "%h" bu_cpp_str(fmt)); \
test_sscanf(SCAN_UINT, bu_cpp_str(med), "%" bu_cpp_str(fmt)); \
test_sscanf(SCAN_ULONG, bu_cpp_str(large), "%l" bu_cpp_str(fmt));
#define bu_cpp_str(s)
Definition: defines.h:138
#define TEST_FLOAT_CONSTANT (   c,
  fmt 
)
Value:
test_sscanf(SCAN_FLOAT, c, "%" bu_cpp_str(fmt)); \
test_sscanf(SCAN_DOUBLE, c, "%l" bu_cpp_str(fmt)); \
test_sscanf(SCAN_LDOUBLE, c, "%L" bu_cpp_str(fmt));
#define bu_cpp_str(s)
Definition: defines.h:138
#define TEST_FLOAT_VARIANT (   fmt)
Value:
TEST_FLOAT_CONSTANT("0.0", fmt); \
TEST_FLOAT_CONSTANT("0.0e0", fmt); \
TEST_FLOAT_CONSTANT("0.0e1", fmt); \
test_sscanf(SCAN_FLOAT, bu_cpp_xstr(SMALL_FLT), "%" bu_cpp_str(fmt)); \
test_sscanf(SCAN_FLOAT, bu_cpp_xstr(LARGE_FLT), "%" bu_cpp_str(fmt)); \
test_sscanf(SCAN_DOUBLE, bu_cpp_xstr(SMALL_FLT), "%l" bu_cpp_str(fmt)); \
test_sscanf(SCAN_DOUBLE, bu_cpp_xstr(LARGE_FLT), "%l" bu_cpp_str(fmt)); \
test_sscanf(SCAN_LDOUBLE, bu_cpp_xstr(SMALL_FLT), "%L" bu_cpp_str(fmt)); \
test_sscanf(SCAN_LDOUBLE, bu_cpp_xstr(LARGE_FLT), "%L" bu_cpp_str(fmt));
#define bu_cpp_str(s)
Definition: defines.h:138
#define SMALL_FLT
Definition: bu_sscanf.c:303
#define TEST_FLOAT_CONSTANT(c, fmt)
#define LARGE_FLT
Definition: bu_sscanf.c:304
#define bu_cpp_xstr(s)
Definition: defines.h:139
#define TEST_STR_SPACE   " \t\naBc\n"
#define TEST_STR_NOSPACE   "aBc"
#define TEST_TERMINATION (   src,
  fmt 
)
Value:
print_src_and_fmt(src, fmt); \
/* init so that 'X' appears after the last char written by bu_sscanf */ \
memset(buf, 'X', TS_STR_SIZE); \
bu_ret = bu_sscanf(src, fmt, buf); \
checkReturnVal("bu_sscanf", bu_ret, 1); \
cp = strchr(buf, 'X');
#define TS_STR_SIZE
Definition: bu_sscanf.c:37
char * strchr(const char *sp, int c)
void * memset(void *s, int c, size_t n)
int bu_sscanf(const char *src, const char *fmt,...) _BU_ATTR_SCANF23
Definition: sscanf.c:676
#define TS_NUM_ASSIGNMENTS   3

Definition at line 552 of file bu_sscanf.c.

#define SCAN_3_VALS (   type,
  src,
  fmt 
)
Value:
print_src_and_fmt(src, fmt); \
vals = bu_malloc(sizeof(type) * TS_NUM_ASSIGNMENTS, "test_sscanf vals"); \
bu_vals = bu_malloc(sizeof(type) * TS_NUM_ASSIGNMENTS, "test_sscanf bu_vals"); \
ret = sscanf(src, fmt, &((type*)vals)[0], &((type*)vals)[1], &((type*)vals)[2]); \
bu_ret = bu_sscanf(src, fmt, &((type*)bu_vals)[0], &((type*)bu_vals)[1], &((type*)bu_vals)[2]); \
checkReturnVal("sscanf", ret, 3); \
checkReturnsEqual(bu_ret, ret);
void * bu_malloc(size_t siz, const char *str)
Definition: malloc.c:314
int bu_sscanf(const char *src, const char *fmt,...) _BU_ATTR_SCANF23
Definition: sscanf.c:676
#define TS_NUM_ASSIGNMENTS
Definition: bu_sscanf.c:552
#define TEST_INT_WIDTH (   type,
  pfmt,
  src,
  fmt 
)
Value:
SCAN_3_VALS(type, src, fmt); \
for (i = 0; i < TS_NUM_ASSIGNMENTS; ++i) { \
val = (void*)&((type*)vals)[i]; \
bu_val = (void*)&((type*)bu_vals)[i]; \
CHECK_INT_VALS_EQUAL(type, pfmt, val, bu_val); \
} \
bu_free(vals, "test_sscanf vals"); \
bu_free(bu_vals, "test_sscanf bu_vals");
Definition: db_flip.c:35
#define CHECK_INT_VALS_EQUAL(int_type, pfmt, valp, bu_valp)
Definition: bu_sscanf.c:151
#define SCAN_3_VALS(type, src, fmt)
#define TS_NUM_ASSIGNMENTS
Definition: bu_sscanf.c:552
void bu_free(void *ptr, const char *str)
Definition: malloc.c:328
#define TEST_FLOAT_WIDTH (   type,
  pfmt,
  src,
  fmt 
)
Value:
SCAN_3_VALS(type, src, fmt); \
for (i = 0; i < TS_NUM_ASSIGNMENTS; ++i) { \
val = (void*)&((type*)vals)[i]; \
bu_val = (void*)&((type*)bu_vals)[i]; \
CHECK_FLOAT_VALS_EQUAL(type, pfmt, val, bu_val); \
} \
bu_free(vals, "test_sscanf vals"); \
bu_free(bu_vals, "test_sscanf bu_vals");
Definition: db_flip.c:35
#define CHECK_FLOAT_VALS_EQUAL(float_type, pfmt, valp, bu_valp)
Definition: bu_sscanf.c:163
#define SCAN_3_VALS(type, src, fmt)
#define TS_NUM_ASSIGNMENTS
Definition: bu_sscanf.c:552
void bu_free(void *ptr, const char *str)
Definition: malloc.c:328
#define FMT_ASSIGN3 (   fmt)    "%" bu_cpp_str(fmt) " %" bu_cpp_str(fmt) " %" bu_cpp_str(fmt)
#define FMT_READ2_ASSIGN1 (   fmt)    "%*" bu_cpp_str(fmt) " %*" bu_cpp_str(fmt) " %" bu_cpp_str(fmt)
#define TEST_FAILURE_1 (   type,
  type_fmt,
  type_init,
  src,
  expected_err 
)
Value:
{ \
type vals[3] = { type_init, type_init, type_init }; \
print_src_and_fmt(src, FMT_ASSIGN3(type_fmt)); \
ret = sscanf(src, FMT_ASSIGN3(type_fmt), &vals[0], &vals[1], &vals[2]); \
bu_ret = sscanf(src, FMT_ASSIGN3(type_fmt), &vals[0], &vals[1], &vals[2]); \
checkReturnVal("sscanf", ret, expected_err); \
checkReturnsEqual(ret, bu_ret); \
for (i = 0; i < 3; ++i) { \
if (vals[i] != type_init) { \
bu_exit(1, "\t[FAIL] No assignment expected, but vals[%d] " \
"changed from %" bu_cpp_str(type_fmt) " to %" bu_cpp_str(type_fmt) ".\n", \
i, type_init, vals[i]); \
} \
} \
}
#define bu_cpp_str(s)
Definition: defines.h:138
if(share_geom)
Definition: nmg_mod.c:3829
void bu_exit(int status, const char *fmt,...) _BU_ATTR_NORETURN _BU_ATTR_PRINTF23
Definition: bomb.c:195
#define FMT_ASSIGN3(fmt)
#define TEST_FAILURE_2 (   type,
  type_fmt,
  type_init,
  src,
  expected_err 
)
Value:
{ \
type val = type_init; \
print_src_and_fmt(src, FMT_READ2_ASSIGN1(type_fmt)); \
ret = sscanf(src, FMT_READ2_ASSIGN1(type_fmt), &val); \
bu_ret = sscanf(src, FMT_READ2_ASSIGN1(type_fmt), &val); \
checkReturnVal("sscanf", ret, expected_err); \
checkReturnsEqual(ret, bu_ret); \
if (val != type_init) { \
bu_exit(1, "\t[FAIL] No assignment expected, but val " \
"changed from %" bu_cpp_str(type_fmt) " to %" bu_cpp_str(type_fmt) ".\n", \
type_init, val); \
} \
}
Definition: db_flip.c:35
#define FMT_READ2_ASSIGN1(fmt)
#define bu_cpp_str(s)
Definition: defines.h:138
if(share_geom)
Definition: nmg_mod.c:3829
void bu_exit(int status, const char *fmt,...) _BU_ATTR_NORETURN _BU_ATTR_PRINTF23
Definition: bomb.c:195
#define EXPECT_MATCH_FAILURE   0
#define EXPECT_INPUT_FAILURE   EOF

Enumeration Type Documentation

anonymous enum
Enumerator
SCAN_SHORTSHORT 
SCAN_USHORTSHORT 
SCAN_SHORT 
SCAN_USHORT 
SCAN_INT 
SCAN_UINT 
SCAN_LONG 
SCAN_ULONG 
SCAN_POINTER 
SCAN_FLOAT 
SCAN_DOUBLE 
SCAN_LDOUBLE 
SCAN_SIZE 
SCAN_PTRDIFF 

Definition at line 109 of file bu_sscanf.c.

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 768 of file bu_sscanf.c.