This function is mainly used to output the contents of the input structure. Supports standard formats for printf and scanf. For detailed parameters, see:
begin_packed_struct
struct test
{
uint8_t a;
uint16_t b;
uint32_t c;
int8_t d;
int16_t e;
int32_t f;
float g;
double h;
char i[32];
uint64_t j;
int64_t k;
char l;
unsigned char m;
short int n;
unsigned short int o;
int p;
unsigned int q;
long r;
unsigned long s;
long long t;
unsigned long long u;
size_t v;
long double w;
}end_packed_struct;
const char* sg = " uint8_t:[%hhu]\n" \
" uint16_t:[%hu]\n" \
" uint32_t:[%u]\n" \
" int8_t:[%hhd]\n" \
" int16_t:[%hd]\n" \
" int32_t:[%d]\n" \
" float:[%hf]\n" \
" double:[%f]\n" \
" char[]:[%.32s]\n" \
" uint64_t:[%lu]\n" \
" int64_t:[%ld]\n" \
" char:[%hhd]\n" \
" unsigned char:[%hhu]\n" \
" short int:[%hd]\n" \
"unsigned short int:[%hu]\n" \
" int:[%d]\n" \
" unsigned int:[%u]\n" \
" long:[%ld]\n" \
" unsigned long:[%lu]\n" \
" long long:[%lld]\n" \
"unsigned long long:[%llu]\n" \
" size_t:[%uz]\n" \
" long double:[%Lf]\n";
#ifdef CONFIG_FILE_STREAM struct lib_stdoutstream_s stdoutstream; lib_stdoutstream(&stdoutstream, stdout); flockfile(stdout); lib_bsprintf(&stdoutstream.common, sv, &test_v); lib_bsprintf(&stdoutstream.common, sg, &test_g); funlockfile(stdout); #else struct lib_rawoutstream_s rawoutstream; struct lib_bufferedoutstream_s outstream; lib_rawoutstream(&rawoutstream, STDOUT_FILENO); lib_bufferedoutstream(&outstream, &rawoutstream.common); lib_bsprintf(&outstream.common, sv, &test_v); lib_bsprintf(&outstream.common, sg, &test_g); lib_stream_flush(&outstream.common); #endif
This function adds a formatted standard scanf string to the structure(lib_bscanf).
special:
demo
#define TOSTR(str) #str
#define TONNAME(name) TOSTR(name)
#define v_uint8_t 97
#define v_uint16_t 19299
#define v_uint32_t 22155
......
#define v_l_double -9299.9299929912122464755474
char bflag[] = "%hhu%hu%u%hhd%hd%d%f%lf%32s%llu%lld%hhd%hhu%hd%hu%d%u%ld%lu%lld%llu%zu%ld";
char binput[] = TONNAME(v_uint8_t) \
" " TONNAME(v_uint16_t) \
" " TONNAME(v_uint32_t) \
" " TONNAME(v_int8_t) \
" " TONNAME(v_int16_t) \
" " TONNAME(v_int32_t) \
" " TONNAME(v_float) \
" " TONNAME(v_double) \
" " TONNAME(v_char_arr) \
" " TONNAME(v_uint64_t) \
" " TONNAME(v_int64_t) \
" " TONNAME(v_char) \
" " TONNAME(v_u_char) \
" " TONNAME(v_s_int) \
" " TONNAME(v_u_s_int) \
" " TONNAME(v_int) \
" " TONNAME(v_u_int) \
" " TONNAME(v_long) \
" " TONNAME(v_u_long) \
" " TONNAME(v_l_l) \
" " TONNAME(v_u_l_l) \
" " TONNAME(v_size_t) \
" " TONNAME(v_l_double);
struct test vg; ret = lib_bscanf(binput, bflag, &vg);