Skip to content

Commit

Permalink
sync to upstream sdparm svn rev 382
Browse files Browse the repository at this point in the history
See ChangeLog file for pre-release sdparm-1.13 [20230523]
svn commit message: propagate sg_scn3pr() helper from sg_lib
  • Loading branch information
doug-gilbert committed May 23, 2023
1 parent 6e2c831 commit 541492d
Show file tree
Hide file tree
Showing 12 changed files with 649 additions and 619 deletions.
4 changes: 2 additions & 2 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ The version number is hardcoded into sdparm.c (in a C string);
the rpm spec file: sdparm.spec ; the debian/changelog file;
and the configure.ac file (in the AC_INIT item).

ChangeLog for pre-release sdparm-1.13 [20230517] [svn: r381]
ChangeLog for pre-release sdparm-1.13 [20230523] [svn: r382]
- add --json[=JO] and --js-file=JFN options
- apart from with a real device, json output can be
requested with --enumerate or --inhex=FN
Expand All @@ -25,7 +25,7 @@ ChangeLog for pre-release sdparm-1.13 [20230517] [svn: r381]
output of further descriptors, override this
truncation with --flexible option
- experimental: add NetBSD support
- point svn:externals to sg3_utils revision 1035
- point svn:externals to sg3_utils revision 1038
- remove the imtermediate files generated by ./autogen.sh
- this reduces size of svn and git repositories but still
plan to have these intermediate files in release tarballs
Expand Down
2 changes: 1 addition & 1 deletion debian/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ sdparm (1.13-0.1) unstable; urgency=low

* see ChangeLog

-- Douglas Gilbert <[email protected]> Mon, 08 May 2023 19:00:00 -0400
-- Douglas Gilbert <[email protected]> Fri, 19 May 2023 23:00:00 -0400

sdparm (1.12-0.1) unstable; urgency=low

Expand Down
14 changes: 12 additions & 2 deletions include/sg_pr2serr.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ extern FILE * sg_warnings_strm;
* output to pr2ws() . */
int pr2ws(const char * fmt, ...) __printf(1, 2);

/* Want safe, 'n += snprintf(b + n, blen - n, ...)' style sequence of
* functions that can be called multiple times. Returns number of chars
/* Want safe, 'n += snprintf(b + n, blen - n, ...);' pattern that can
* be called repeatedly. However snprintf() takes an unsigned second argument
* (size_t) that explodes if 'blen - n' goes negative. This function instead
* uses signed integers (second argument and return value) and is safe if the
* second argument is negative. It returns number of chars actually
* placed in cp excluding the trailing null char. So for cp_max_len > 0 the
* return value is always < cp_max_len; for cp_max_len <= 1 the return value
* is 0 and no chars are written to cp. Note this means that when
Expand All @@ -55,6 +58,13 @@ int pr2ws(const char * fmt, ...) __printf(1, 2);
* called scnprintf(). */
int sg_scnpr(char * cp, int cp_max_len, const char * fmt, ...) __printf(3, 4);

/* This function is similar to sg_scnpr() but takes the "n" in that pattern
* as an extra, third argument where it is renamed 'off'. This function will
* start writing chars at 'fcp + off' for no more than 'fcp_len - off - 1'
* characters. The return value is the same as sg_scnpr(). */
int sg_scn3pr(char * fcp, int fcp_len, int off,
const char * fmt, ...) __printf(4, 5);

#ifdef __cplusplus
}
#endif
Expand Down
9 changes: 5 additions & 4 deletions lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ if DEBUG
# This is active if --enable-debug given to ./configure
# removed -Wduplicated-branches because needs gcc-8
DBG_CFLAGS = -Wextra -Wmisleading-indentation -Wduplicated-cond -Wlogical-op -Wnull-dereference -Wshadow -Wjump-misses-init -Wunused -Wsizeof-array-argument
DBG_CXXFLAGS = -Wextra -Wmisleading-indentation -Wduplicated-cond -Wlogical-op -Wnull-dereference -Wshadow -Wunused -Wsizeof-array-argument
DBG_CPPFLAGS = -DDEBUG
else
DBG_CFLAGS =
DBG_CXXFLAGS =
DBG_CPPFLAGS =
endif

Expand All @@ -92,16 +94,15 @@ AM_CPPFLAGS = -iquote ${top_srcdir}/include -D_LARGEFILE64_SOURCE -D_FILE_OFFSET
AM_CFLAGS = -Wall -W $(DBG_CFLAGS)
# AM_CFLAGS = -Wall -W -flto=auto $(DBG_CFLAGS)
# AM_CFLAGS = -Wall -W $(DBG_CFLAGS) -fanalyzer
# AM_CFLAGS = -Wall -W -Wextra -Wmisleading-indentation -Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wnull-dereference -Wshadow -Wjump-misses-init
# AM_CFLAGS = -Wall -W -pedantic -std=c99
# AM_CFLAGS = -Wall -W -pedantic -std=c11
# AM_CFLAGS = -Wall -W -pedantic -std=c11 --analyze
# AM_CFLAGS = -Wall -W -pedantic -std=c++11
# AM_CFLAGS = -Wall -W -pedantic -std=c++14
# AM_CFLAGS = -Wall -W -pedantic -std=c++1z
# AM_CFLAGS = -Wall -W -pedantic -std=c++17 $(DBG_CXXFLAGS)
# AM_CFLAGS = -Wall -W -pedantic -std=c++20 --analyze
# AM_CFLAGS = -Wall -W -pedantic -std=c++20 $(DBG_CFLAGS)
# AM_CFLAGS = -Wall -W -pedantic -std=c++23 $(DBG_CFLAGS)
# AM_CFLAGS = -Wall -W -pedantic -std=c++20 $(DBG_CXXFLAGS)
# AM_CFLAGS = -Wall -W -pedantic -std=c++23 $(DBG_CXXFLAGS)

lib_LTLIBRARIES = libsgutils2.la

Expand Down
98 changes: 47 additions & 51 deletions lib/sg_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,63 +143,55 @@ sgj_parse_opts(sgj_state * jsp, const char * j_optarg)
char *
sg_json_usage(int char_if_not_j, char * b, int blen)
{
int n = 0;
int n;
char short_opt = char_if_not_j ? char_if_not_j : 'j';

if ((NULL == b) || (blen < 1))
goto fini;
n += sg_scnpr(b + n, blen - n, "JSON option usage:\n");
n += sg_scnpr(b + n, blen - n,
" --json[=JO] | -%c[=JO]\n\n", short_opt);
n += sg_scnpr(b + n, blen - n, " where JO is a string of one or more "
"of:\n");
n += sg_scnpr(b + n, blen - n,
n = sg_scnpr(b, blen, "JSON option usage:\n");
n += sg_scn3pr(b, blen, n, " --json[=JO] | -%c[=JO]\n\n", short_opt);
n += sg_scn3pr(b, blen, n, " where JO is a string of one or more of:\n");
n += sg_scn3pr(b, blen, n,
" 0 | 2 tab pretty output to 2 spaces\n");
n += sg_scnpr(b + n, blen - n,
n += sg_scn3pr(b, blen, n,
" 4 tab pretty output to 4 spaces (def)\n");
n += sg_scnpr(b + n, blen - n,
" 8 tab pretty output to 8 spaces\n");
n += sg_scn3pr(b, blen, n, " 8 tab pretty output to 8 spaces\n");
if (n >= (blen - 1))
goto fini;
n += sg_scnpr(b + n, blen - n,
" e show 'exit_status' field\n");
n += sg_scnpr(b + n, blen - n,
" h show 'hex' fields\n");
n += sg_scnpr(b + n, blen - n,
n += sg_scn3pr(b, blen, n, " e show 'exit_status' field\n");
n += sg_scn3pr(b, blen, n, " h show 'hex' fields\n");
n += sg_scn3pr(b, blen, n,
" k packed, only non-pretty printed output\n");
n += sg_scnpr(b + n, blen - n,
" l show lead-in fields (invocation "
n += sg_scn3pr(b, blen, n, " l show lead-in fields (invocation "
"information)\n");
n += sg_scnpr(b + n, blen - n,
n += sg_scn3pr(b, blen, n,
" n show 'name_extra' information fields\n");
n += sg_scnpr(b + n, blen - n,
n += sg_scn3pr(b, blen, n,
" o non-JSON output placed in 'plain_text_output' "
"array in lead-in\n");
if (n >= (blen - 1))
goto fini;
n += sg_scnpr(b + n, blen - n,
" p pretty print the JSON output\n");
n += sg_scnpr(b + n, blen - n,
n += sg_scn3pr(b, blen, n, " p pretty print the JSON output\n");
n += sg_scn3pr(b, blen, n,
" s show string output (usually fields named "
"'meaning')\n");
n += sg_scnpr(b + n, blen - n,
" v make JSON output more verbose\n");
n += sg_scnpr(b + n, blen - n,
n += sg_scn3pr(b, blen, n, " v make JSON output more verbose\n");
n += sg_scn3pr(b, blen, n,
" - | ~ | ! toggle next letter setting\n");

sg_scnpr(b + n, blen - n, "\nIn the absence of the optional JO argument, "
"the following are set\non: 'elps' while the others are set "
"off, and tabs are set to 4.\nBefore command line JO options "
"are applied, the environment\nvariable: %s is applied (if "
"present). Note that\nno space is permitted between the short "
"option ('-%c') and its\nargument ('JO'). For more information "
"see 'man sg3_utils_json' or\n'man sdparm_json' .\n",
sgj_opts_ev, short_opt);
sg_scn3pr(b, blen, n, "\nIn the absence of the optional JO argument, "
"the following are set\non: 'elps' while the others are set "
"off, and tabs are set to 4.\nBefore command line JO options "
"are applied, the environment\nvariable: %s is applied (if "
"present). Note that\nno space is permitted between the short "
"option ('-%c') and its\nargument ('JO'). For more information "
"see 'man sg3_utils_json' or\n'man sdparm_json' .\n",
sgj_opts_ev, short_opt);
fini:
return b;
}

char *
static char *
sg_json_settings(sgj_state * jsp, char * b, int blen)
{
snprintf(b, blen, "%d%se%sh%sk%sl%sn%so%sp%ss%sv", jsp->pr_indent_size,
Expand Down Expand Up @@ -234,6 +226,8 @@ sgj_init_state(sgj_state * jsp, const char * j_optarg)
{
const char * cp;

if (NULL == jsp)
return false;
sgj_def_opts(jsp);
jsp->basep = NULL;
jsp->out_hrp = NULL;
Expand All @@ -255,14 +249,16 @@ sgj_start_r(const char * util_name, const char * ver_str, int argc,
char *argv[], sgj_state * jsp)
{
int k;
json_value * jvp = json_object_new(0);
json_value * jvp;
json_value * jv2p = NULL;
json_value * jap = NULL;


if (NULL == jsp)
return NULL;
jvp = json_object_new(0);
if (NULL == jvp)
return NULL;
if (NULL == jsp)
return jvp;

jsp->basep = jvp;
if (jsp->pr_leadin) {
Expand Down Expand Up @@ -826,7 +822,7 @@ h2str(const uint8_t * byte_arr, int num_bytes, char * bp, int blen)
int j, k, n;

for (k = 0, n = 0; (k < num_bytes) && (n < blen); ) {
j = sg_scnpr(bp + n, blen - n, "%02x ", byte_arr[k]);
j = sg_scn3pr(bp, blen, n, "%02x ", byte_arr[k]);
if (j < 2)
break;
n += j;
Expand Down Expand Up @@ -1082,36 +1078,36 @@ sgj_haj_helper(char * b, int blen_max, const char * name,
int n = 0;

if (name) {
n += sg_scnpr(b + n, blen_max - n, "%s", name);
n += sg_scn3pr(b, blen_max, n, "%s", name);
switch (sep) {
case SGJ_SEP_NONE:
break;
case SGJ_SEP_SPACE_1:
n += sg_scnpr(b + n, blen_max - n, " ");
n += sg_scn3pr(b, blen_max, n, " ");
break;
case SGJ_SEP_SPACE_2:
n += sg_scnpr(b + n, blen_max - n, " ");
n += sg_scn3pr(b, blen_max, n, " ");
break;
case SGJ_SEP_SPACE_3:
n += sg_scnpr(b + n, blen_max - n, " ");
n += sg_scn3pr(b, blen_max, n, " ");
break;
case SGJ_SEP_SPACE_4:
n += sg_scnpr(b + n, blen_max - n, " ");
n += sg_scn3pr(b, blen_max, n, " ");
break;
case SGJ_SEP_EQUAL_NO_SPACE:
n += sg_scnpr(b + n, blen_max - n, "=");
n += sg_scn3pr(b, blen_max, n, "=");
break;
case SGJ_SEP_EQUAL_1_SPACE:
n += sg_scnpr(b + n, blen_max - n, "= ");
n += sg_scn3pr(b, blen_max, n, "= ");
break;
case SGJ_SEP_SPACE_EQUAL_SPACE:
n += sg_scnpr(b + n, blen_max - n, " = ");
n += sg_scn3pr(b, blen_max, n, " = ");
break;
case SGJ_SEP_COLON_NO_SPACE:
n += sg_scnpr(b + n, blen_max - n, ":");
n += sg_scn3pr(b, blen_max, n, ":");
break;
case SGJ_SEP_COLON_1_SPACE:
n += sg_scnpr(b + n, blen_max - n, ": ");
n += sg_scn3pr(b, blen_max, n, ": ");
break;
default:
break;
Expand All @@ -1120,9 +1116,9 @@ sgj_haj_helper(char * b, int blen_max, const char * name,
if (use_jvp)
n += sgj_jtype_to_s(b + n, blen_max - n, jvp, as_hex);
else if (as_hex)
n += sg_scnpr(b + n, blen_max - n, "0x%" PRIx64, val_instead);
n += sg_scn3pr(b, blen_max, n, "0x%" PRIx64, val_instead);
else
n += sg_scnpr(b + n, blen_max - n, "%" PRIi64, val_instead);
n += sg_scn3pr(b, blen_max, n, "%" PRIi64, val_instead);
return n;
}

Expand Down Expand Up @@ -1311,7 +1307,7 @@ sgj_haj_subo_r(sgj_state * jsp, sgj_opaque_p jop, int leadin_sp,
for (n = 0; n < leadin_sp; ++n)
b[n] = ' ';
b[n] = '\0';
if ((! as_json) || (jsp && jsp->pr_out_hr))
if ((! as_json) || jsp->pr_out_hr)
sgj_haj_helper(b + n, blen - n, aname, sep, false, NULL, value,
hex_haj);

Expand Down
5 changes: 2 additions & 3 deletions lib/sg_json_sg_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,11 +612,10 @@ sgj_js_sense_descriptors(sgj_state * jsp, sgj_opaque_p jop,
else if (sds > 9)
snprintf(b, blen, "%s [%d]", "Reserved", sds);
else {
n = 0;
n += sg_scnpr(b + n, blen - n, "EXTENDED COPY command copy %s",
n = sg_scnpr(b, blen, "EXTENDED COPY command copy %s",
(sds == 1) ? "source" : "destination");
if (sds > 1)
sg_scnpr(b + n, blen - n, " %d", sds - 1);
sg_scn3pr(b, blen, n, " %d", sds - 1);
}
sgj_js_nv_ihexstr(jsp, jo2p, "sense_data_source",
(0x7 & descp[2]), NULL, b);
Expand Down
Loading

0 comments on commit 541492d

Please sign in to comment.