aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2022-08-07 02:22:53 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2022-08-07 02:22:53 +0000
commit23beedb782b58779546c58a7e9ef18aeccf50485 (patch)
tree9a98707784d48a4fa055b81f11b8d2135cdcb435 /lib
parent640f7a7eff809159d9ac4c3ffc3681a6a5c3bede (diff)
downloadsg3_utils-23beedb782b58779546c58a7e9ef18aeccf50485.tar.gz
sg_inq+sg_vpd: more JSON work (tpc)
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@964 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.in1
-rw-r--r--lib/sg_lib.c41
-rw-r--r--lib/sg_lib_data.c6
3 files changed, 33 insertions, 15 deletions
diff --git a/lib/Makefile.in b/lib/Makefile.in
index 45b464fc..406cc024 100644
--- a/lib/Makefile.in
+++ b/lib/Makefile.in
@@ -280,6 +280,7 @@ EGREP = @EGREP@
ETAGS = @ETAGS@
EXEEXT = @EXEEXT@
FGREP = @FGREP@
+FILECMD = @FILECMD@
GETOPT_O_FILES = @GETOPT_O_FILES@
GREP = @GREP@
INSTALL = @INSTALL@
diff --git a/lib/sg_lib.c b/lib/sg_lib.c
index 7256c435..b1c9792a 100644
--- a/lib/sg_lib.c
+++ b/lib/sg_lib.c
@@ -3559,18 +3559,23 @@ sg_get_llnum_nomult(const char * buf)
/* Read ASCII hex bytes or binary from fname (a file named '-' taken as
* stdin). If reading ASCII hex then there should be either one entry per
- * line or a comma, space, hyphen or tab separated list of bytes. If
- * no_space is * set then a string of ACSII hex digits is expected, 2 per
- * byte. Everything from and including a '#' on a line is ignored. Returns
- * 0 if ok, or an error code. If the error code is
- * SG_LIB_LBA_OUT_OF_RANGE then mp_arr would be exceeded and both mp_arr
- * and mp_arr_len are written to. */
+ * line or a comma, space, hyphen or tab separated list of bytes. If no_space
+ * is set then a string of ACSII hex digits is expected, 2 perbyte.
+ * Everything from and including a '#' on a line is ignored. Returns 0 if ok,
+ * or an error code. If the error code is SG_LIB_LBA_OUT_OF_RANGE then mp_arr
+ * would be exceeded and both mp_arr and mp_arr_len are written to.
+ * The max_arr_len_and argument may carry extra information: when it
+ * is negative its absolute value is used for the maximum number of bytes to
+ * write to mp_arr _and_ the first hexadecimal value on each line is skipped.
+ * Many hexadecimal output programs place a running address (index) as the
+ * first field on each line. When as_binary and/or no_space are true, the
+ * absolute value of max_arr_len_and is used. */
int
sg_f2hex_arr(const char * fname, bool as_binary, bool no_space,
- uint8_t * mp_arr, int * mp_arr_len, int max_arr_len)
+ uint8_t * mp_arr, int * mp_arr_len, int max_arr_len_and)
{
- bool has_stdin, split_line;
- int fn_len, in_len, k, j, m, fd, err;
+ bool has_stdin, split_line, skip_first, redo_first;
+ int fn_len, in_len, k, j, m, fd, err, max_arr_len;
int off = 0;
int ret = 0;
unsigned int h;
@@ -3584,6 +3589,13 @@ sg_f2hex_arr(const char * fname, bool as_binary, bool no_space,
pr2ws("%s: bad arguments\n", __func__);
return SG_LIB_LOGIC_ERROR;
}
+ if (max_arr_len_and < 0) {
+ skip_first = true;
+ max_arr_len = -max_arr_len_and;
+ } else {
+ skip_first = false;
+ max_arr_len = max_arr_len_and;
+ }
fn_len = strlen(fname);
if (0 == fn_len)
return SG_LIB_SYNTAX_ERROR;
@@ -3727,8 +3739,9 @@ sg_f2hex_arr(const char * fname, bool as_binary, bool no_space,
if (isxdigit(*lcp) && (! isxdigit(*(lcp + 1))))
carry_over[0] = *lcp;
off += k;
- } else {
- for (k = 0; k < 1024; ++k) {
+ } else { /* (white)space separated ASCII hexadecimal bytes */
+ for (redo_first = false, k = 0; k < 1024;
+ k = (redo_first ? k : k + 1)) {
if (1 == sscanf(lcp, "%10x", &h)) {
if (h > 0xff) {
pr2ws("%s: hex number larger than 0xff in line "
@@ -3746,8 +3759,12 @@ sg_f2hex_arr(const char * fname, bool as_binary, bool no_space,
ret = SG_LIB_LBA_OUT_OF_RANGE;
*mp_arr_len = max_arr_len;
goto fini;
- } else
+ } else if ((0 == k) && skip_first && (! redo_first))
+ redo_first = true;
+ else {
+ redo_first = false;
mp_arr[off + k] = h;
+ }
lcp = strpbrk(lcp, " ,-\t");
if (NULL == lcp)
break;
diff --git a/lib/sg_lib_data.c b/lib/sg_lib_data.c
index 3e291eb2..4906bb60 100644
--- a/lib/sg_lib_data.c
+++ b/lib/sg_lib_data.c
@@ -19,8 +19,8 @@
#include "sg_lib_data.h"
-const char * sg_lib_version_str = "2.90 20220622";
-/* spc6r06, sbc5r01, zbc2r13 */
+const char * sg_lib_version_str = "2.91 20220730";
+/* spc6r06, sbc5r03, zbc2r13 */
/* indexed by pdt; those that map to own index do not decay */
@@ -434,7 +434,7 @@ struct sg_lib_value_name_t sg_lib_pr_out_arr[] = {
* as there is no need to differentiate. */
struct sg_lib_value_name_t sg_lib_xcopy_sa_arr[] = { /* originating */
{0x0, PDT_ALL, "Extended copy(LID1)"},
- {0x1, PDT_ALL, "Extended copy"}, /* was 'Extended copy(LID4)' */
+ {0x1, PDT_ALL, "Extended copy"}, /* 'Extended copy(LID4)' until spc5r01 */
{0x10, PDT_ALL, "Populate token"},
{0x11, PDT_ALL, "Write using token"},
{0x16, PDT_TAPE, "Set tape stream mirroring"}, /* ADC-4 and SSC-5 */