aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2009-04-02 16:49:49 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2009-04-02 16:49:49 +0000
commitb15dc3d385fa5f94350c0b4f721c026560891d28 (patch)
tree46864e78f70f9478864f4d1b47362d70b1fc0e29
parentee25b125e45c7e8dfeb82b518d563cf6ea831f4b (diff)
downloadsg3_utils-b15dc3d385fa5f94350c0b4f721c026560891d28.tar.gz
Allow various comma separated list arguments to take space separator
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@242 6180dd3e-e324-4e3e-922d-17de1ae2f315
-rw-r--r--ChangeLog13
-rw-r--r--doc/sg_persist.811
-rw-r--r--doc/sg_reassign.87
-rw-r--r--doc/sg_senddiag.811
-rw-r--r--doc/sg_ses.813
-rw-r--r--doc/sg_wr_mode.828
-rw-r--r--src/sg_persist.c22
-rw-r--r--src/sg_reassign.c22
-rw-r--r--src/sg_senddiag.c14
-rw-r--r--src/sg_ses.c16
-rw-r--r--src/sg_wr_mode.c35
11 files changed, 123 insertions, 69 deletions
diff --git a/ChangeLog b/ChangeLog
index dcb4d1f0..734d01a7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,7 +2,7 @@ Each utility has its own version number, date of last change and
some description at the top of its ".c" file. All utilities in the main
directory have their own "man" pages. There is also a sg3_utils man page.
-Changelog for sg3_utils-1.27 [20090331] [svn: r240]
+Changelog for sg3_utils-1.27 [20090401] [svn: r242]
- sg_write_same: new utility: 10, 16 and 32 byte cdb variants
- sg_inq: sync version descriptors with spc4r18
- add power condition VPD page
@@ -30,7 +30,14 @@ Changelog for sg3_utils-1.27 [20090331] [svn: r240]
- sg_format: add '--fmtpinfo=' and '--pie=' options (sbc3r18)
- sg_readcap: more protection + thin provisioning (sbc3r18)
- sg_persist: code clean up
+ - allow '--transport-id=' argument to use space as separator
- sginfo: fix crash when 1024 sg device nodes (or more)
+ - sg_ses: allow '--data=' argument to use space as separator
+ - sg_senddiag: allow '--raw=' argument to use space as separator
+ - sg_reassign: allow '--address=' argument to use space as
+ separator
+ - sg_wr_mode: allow '--contents=' and '--mask=' arguments to
+ use space as separator
- sg3_utils.spec: correction to configure call
- sg_pt: add scsi_pt_open_device_flags() call
- add scsi_pt_version() and clear_scsi_pt_obj() calls
@@ -40,8 +47,8 @@ Changelog for sg3_utils-1.27 [20090331] [svn: r240]
- sg_cmds_extra: sg_ll_format_unit: remove rto_req argument,
the expanded fmtpinfo argument subsumes it.
- clearer split between Linux and Windows only code and doc
- - automake tools: changes after upgrade to Ubuntu 8.10
- - automake tools: Ubuntu 8.10 libtool ugly -> Debian 5.0
+ - automake tools: change to what Ubuntu 8.10 provides
+ - Ubuntu 8.10 libtool problems -> Debian 4.0
Changelog for sg3_utils-1.26 [20080625] [svn: r183]
- sg_sat_phy_event: new utility; copied from examples
diff --git a/doc/sg_persist.8 b/doc/sg_persist.8
index 59103c1a..c727567c 100644
--- a/doc/sg_persist.8
+++ b/doc/sg_persist.8
@@ -1,4 +1,4 @@
-.TH SG_PERSIST "8" "March 2009" "sg3_utils\-1.27" SG3_UTILS
+.TH SG_PERSIST "8" "April 2009" "sg3_utils\-1.27" SG3_UTILS
.SH NAME
sg_persist \- sends a SCSI PERSISTENT RESERVE (IN or OUT) command
to manipulate registrations and reservations
@@ -213,10 +213,11 @@ existing key' sub\-commands. The latter two sub\-commands can take multiple
transportIDs in a list but only one is supported with this option
variant (use the \fI\-\-transport\-id=\-\fR variant if multiple
transportIDs are required). \fIH,H...\fR is a comma separated list of hex
-bytes which represent the transportID. The list of hex numbers will be
-padded out with zeros to 24 bytes which is the minimum length of a
-transportID. A transportID longer than 24 bytes (e.g. for iSCSI) is
-padded with zeros so its length is a multiple of 4.
+bytes which represent the transportID. A (single) space separated list
+of hex bytes is also allowed but the list needs to be in quotes. The list
+of hex numbers will be padded out with zeros to 24 bytes which is the
+minimum length of a transportID. A transportID longer than 24 bytes (e.g.
+for iSCSI) is padded with zeros so its length is a multiple of 4.
.TP
\fB\-X\fR, \fB\-\-transport\-id=\-\fR
a transportID is required for the PROUT 'register and move' sub\-command
diff --git a/doc/sg_reassign.8 b/doc/sg_reassign.8
index 9d1e489d..46db8002 100644
--- a/doc/sg_reassign.8
+++ b/doc/sg_reassign.8
@@ -1,4 +1,4 @@
-.TH SG_REASSIGN "8" "January 2007" "sg3_utils\-1.23" SG3_UTILS
+.TH SG_REASSIGN "8" "April 2009" "sg3_utils\-1.27" SG3_UTILS
.SH NAME
sg_reassign \- sends a SCSI REASSIGN BLOCKS command
.SH SYNOPSIS
@@ -32,7 +32,8 @@ Arguments to long options are mandatory for short options as well.
where \fIA,A...\fR is a string of comma separated numbers. Each number
is interpreted as decimal unless prefixed by '0x' or '0X' (or it has a
trailing 'h' or 'H'). If multiple logical block addresses are given they
-must be separated by a comma. At least one address must be given.
+must be separated by a comma or a (single) space. A string that contains
+any space separators needs to be quoted. At least one address must be given.
.TP
\fB\-a\fR, \fB\-\-address\fR=\-
reads one or more logical block addresses from stdin. These may be comma,
@@ -135,7 +136,7 @@ Written by Douglas Gilbert.
.SH "REPORTING BUGS"
Report bugs to <dgilbert at interlog dot com>.
.SH COPYRIGHT
-Copyright \(co 2005\-2007 Douglas Gilbert
+Copyright \(co 2005\-2009 Douglas Gilbert
.br
This software is distributed under a FreeBSD license. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
diff --git a/doc/sg_senddiag.8 b/doc/sg_senddiag.8
index f40253c7..e79c4b18 100644
--- a/doc/sg_senddiag.8
+++ b/doc/sg_senddiag.8
@@ -1,4 +1,4 @@
-.TH SG_SENDDIAG "8" "October 2007" "sg3_utils\-1.25" SG3_UTILS
+.TH SG_SENDDIAG "8" "April 2009" "sg3_utils\-1.27" SG3_UTILS
.SH NAME
sg_senddiag \- performs a SCSI SEND DIAGNOSTIC command
.SH SYNOPSIS
@@ -67,9 +67,10 @@ bit is set (as required by SPC\-3).
.TP
\fB\-r\fR, \fB\-\-raw\fR=\fIH,H...\fR
string of comma separated hex numbers each of which should resolve to
-a byte value (i.e. 0 to ff inclusive). This sequence forms a diagnostic
-page to be sent with the SCSI SEND DIAGNOSTIC command. Mostly likely
-the \fI\-\-pf\fR option should also be given.
+a byte value (i.e. 0 to ff inclusive). A (single) space separated string
+of hex bytes is also allowed but the list needs to be in quotes. This
+sequence forms a diagnostic page to be sent with the SCSI SEND DIAGNOSTIC
+command. Mostly likely the \fI\-\-pf\fR option should also be given.
.TP
\fB\-r\fR, \fB\-\-raw=\-\fR
reads sequence of bytes from stdin. The sequence may be comma, space, tab
@@ -244,7 +245,7 @@ Written by Doug Gilbert
.SH "REPORTING BUGS"
Report bugs to <dgilbert at interlog dot com>.
.SH COPYRIGHT
-Copyright \(co 2003\-2007 Douglas Gilbert
+Copyright \(co 2003\-2009 Douglas Gilbert
.br
This software is distributed under the GPL version 2. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
diff --git a/doc/sg_ses.8 b/doc/sg_ses.8
index f0e2c18b..eca97c26 100644
--- a/doc/sg_ses.8
+++ b/doc/sg_ses.8
@@ -1,4 +1,4 @@
-.TH SG_SES "8" "March 2008" "sg3_utils\-1.26" SG3_UTILS
+.TH SG_SES "8" "April 2009" "sg3_utils\-1.27" SG3_UTILS
.SH NAME
sg_ses \- send controls and fetch status from a SCSI Enclosure
Services (SES) device
@@ -39,10 +39,11 @@ The Enclosure control, String Out, Threshold Out, Array control (obsolete
in SES\-2) and Subenclosure String Out diagnostic pages can be set currently.
.TP
\fB\-d\fR, \fB\-\-data\fR=\fIH,H...\fR
-permits a string of comma separated (ASCII) hex digits to be
-specified (limit 512). This allows the parameters to a control diagnostic
-page to be specified. The string given should not include the first 4
-bytes (i.e. page code and length). See next entry for using stdin.
+permits a string of comma separated (ASCII) hex bytes to be specified (limit
+512). A (single) space separated string of hex bytes is also allowed but
+the list needs to be in quotes. This allows the parameters to a control
+diagnostic page to be specified. The string given should not include the
+first 4 bytes (i.e. page code and length). See next entry for using stdin.
.TP
\fB\-d\fR, \fB\-\-data\fR=\-
reads a data string from stdin. Spaces, tabs and line feeds additionally
@@ -148,7 +149,7 @@ Written by Douglas Gilbert.
.SH "REPORTING BUGS"
Report bugs to <dgilbert at interlog dot com>.
.SH COPYRIGHT
-Copyright \(co 2004\-2007 Douglas Gilbert
+Copyright \(co 2004\-2009 Douglas Gilbert
.br
This software is distributed under a FreeBSD license. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
diff --git a/doc/sg_wr_mode.8 b/doc/sg_wr_mode.8
index dfe7365d..e115504c 100644
--- a/doc/sg_wr_mode.8
+++ b/doc/sg_wr_mode.8
@@ -1,4 +1,4 @@
-.TH SG_WR_MODE "8" "March 2008" "sg3_utils\-1.26" SG3_UTILS
+.TH SG_WR_MODE "8" "April 2009" "sg3_utils\-1.27" SG3_UTILS
.SH NAME
sg_wr_mode \- write mode page
.SH SYNOPSIS
@@ -53,12 +53,13 @@ Arguments to long options are mandatory for short options as well.
.TP
\fB\-c\fR, \fB\-\-contents\fR=\fIH,H...\fR
where \fIH,H...\fR is a string of comma separated hex numbers each of
-which should resolve to a byte value (i.e. 0 to ff inclusive). This is the
-new contents of the mode page to be written to \fIDEVICE\fR, potentially
-filtered by the mask string.
+which should resolve to a byte value (i.e. 0 to ff inclusive). A (single)
+space separated string of hex numbers is also allowed but the list needs to
+be in quotes. This is the new contents of the mode page to be written to
+\fIDEVICE\fR, potentially filtered by the mask string.
.TP
\fB\-c\fR, \fB\-\-contents\fR=-
-reads contents string from stdin. The numbers in the string may be comma,
+reads contents string from stdin. The hex numbers in the string may be comma,
space, tab or linefeed (newline) separated. If a line contains "#" then the
remaining characters on that line are ignored. Otherwise each non separator
character should resolve to a byte value (i.e. 0 to ff inclusive). This
@@ -89,13 +90,14 @@ don't support the 10 byte variants hence this option.
.TP
\fB\-m\fR, \fB\-\-mask\fR=\fIM,M...\fR
where \fIM,M...\fR is a string of comma separated hex numbers each of which
-should resolve to a byte value (i.e. 0 to ff inclusive). The mask
-chooses (bit by bit) whether the new mode page comes from the contents (mask
-bit set) or from the existing mode page (mask bit clear). If the mask string
-is shorter than the contents string then the remaining bytes are taken from
-the contents string. If the contents string is shorter than the existing
-mode page then the remaining bytes are taken from the existing mode
-page (i.e. they are left unaltered).
+should resolve to a byte value (i.e. 0 to ff inclusive). A (single) space
+separated string of hex numbers is also allowed but the list needs to be in
+quotes. The mask chooses (bit by bit) whether the new mode page comes from
+the contents (mask bit set) or from the existing mode page (mask bit clear).
+If the mask string is shorter than the contents string then the remaining
+bytes are taken from the contents string. If the contents string is shorter
+than the existing mode page then the remaining bytes are taken from the
+existing mode page (i.e. they are left unaltered).
.TP
\fB\-p\fR, \fB\-\-page\fR=\fIPG\fR
where \fIPG\fR is the page code value to fetch and modify. The page code is
@@ -188,7 +190,7 @@ Written by Douglas Gilbert.
.SH "REPORTING BUGS"
Report bugs to <dgilbert at interlog dot com>.
.SH COPYRIGHT
-Copyright \(co 2004\-2008 Douglas Gilbert
+Copyright \(co 2004\-2009 Douglas Gilbert
.br
This software is distributed under a FreeBSD license. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
diff --git a/src/sg_persist.c b/src/sg_persist.c
index 05539918..96531cad 100644
--- a/src/sg_persist.c
+++ b/src/sg_persist.c
@@ -16,7 +16,7 @@
#include "sg_cmds_basic.h"
#include "sg_cmds_extra.h"
-/* A utility program for the Linux OS SCSI subsystem.
+/* A utility program originally written for the Linux OS SCSI subsystem.
* Copyright (C) 2004-2009 D. Gilbert
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -27,7 +27,7 @@
*/
-static char * version_str = "0.34 20090313";
+static char * version_str = "0.36 20090402";
#define PRIN_RKEY_SA 0x0
@@ -581,11 +581,11 @@ prout_rmove_work(int sg_fd, const struct opts_t * optsp)
return 0;
}
-/* Build transportid byte array from ASCII hexadecimal number which are
- * comma separated. Direct form can only contain one transport ID. In
- * the indirect form (when '-'==*inp) there can be multiple transport IDs,
- * all assumed to contain the same number of bytes each. Fuller description
- * in manpage of sg_persist(8). Returns 0 if successful, else 1 .
+/* Build transportid byte array from ASCII hexadecimal number which are comma
+ * (or (single) space) separated. Direct form can only contain one transport
+ * ID. In the indirect form (when '-'==*inp) there can be multiple transport
+ * IDs, all assumed to contain the same number of bytes each. Fuller
+ * description in manpage of sg_persist(8). Returns 0 if successful, else 1 .
* N.B. Contains transport ID related special handling (e.g. rounds up to
* 24 bytes)
*/
@@ -597,6 +597,7 @@ build_transportid(const char * inp, struct opts_t * optsp)
const char * lcp;
unsigned char * tid_arr;
char * cp;
+ char * c2p;
tid_arr = optsp->transportid_arr;
lcp = inp;
@@ -677,7 +678,7 @@ build_transportid(const char * inp, struct opts_t * optsp)
optsp->transportid_arr_len = off;
optsp->num_transportids = num;
} else { /* hex string on command line */
- k = strspn(inp, "0123456789aAbBcCdDeEfF,");
+ k = strspn(inp, "0123456789aAbBcCdDeEfF, ");
if (in_len != k) {
fprintf(stderr, "build_transportid: error at pos %d\n",
k + 1);
@@ -692,8 +693,13 @@ build_transportid(const char * inp, struct opts_t * optsp)
}
tid_arr[k] = h;
cp = strchr(lcp, ',');
+ c2p = strchr(lcp, ' ');
+ if (NULL == cp)
+ cp = c2p;
if (NULL == cp)
break;
+ if (c2p && (c2p < cp))
+ cp = c2p;
lcp = cp + 1;
} else {
fprintf(stderr, "build_transportid: error at pos %d\n",
diff --git a/src/sg_reassign.c b/src/sg_reassign.c
index 5c249588..88f1547f 100644
--- a/src/sg_reassign.c
+++ b/src/sg_reassign.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005-2007 Douglas Gilbert.
+ * Copyright (c) 2005-2009 Douglas Gilbert.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -45,7 +45,7 @@
#include "sg_cmds_basic.h"
#include "sg_cmds_extra.h"
-/* A utility program for the Linux OS SCSI subsystem.
+/* A utility program originally written for the Linux OS SCSI subsystem.
*
* This utility invokes the REASSIGN BLOCKS SCSI command to reassign
* an existing (possibly damaged) lba on a direct access device (e.g.
@@ -54,7 +54,7 @@
* vendor specific data is written.
*/
-static char * version_str = "1.11 20070925";
+static char * version_str = "1.12 20090401";
#define ME "sg_reassign: "
@@ -148,11 +148,11 @@ get_llnum(const char * buf)
return -1LL;
}
-/* Read numbers (up to 64 bits in size) from command line (comma separated */
-/* list) or from stdin (one per line, comma separated list or */
-/* space separated list). Assumed decimal unless prefixed by '0x', '0X' */
-/* or contains trailing 'h' or 'H' (which indicate hex). */
-/* Returns 0 if ok, or 1 if error. */
+/* Read numbers (up to 64 bits in size) from command line (comma (or
+ * (single) space) separated list) or from stdin (one per line, comma
+ * separated list or space separated list). Assumed decimal unless prefixed
+ * by '0x', '0X' or contains trailing 'h' or 'H' (which indicate hex).
+ * Returns 0 if ok, or 1 if error. */
static int
build_lba_arr(const char * inp, uint64_t * lba_arr,
int * lba_arr_len, int max_arr_len)
@@ -161,6 +161,7 @@ build_lba_arr(const char * inp, uint64_t * lba_arr,
const char * lcp;
int64_t ll;
char * cp;
+ char * c2p;
if ((NULL == inp) || (NULL == lba_arr) ||
(NULL == lba_arr_len))
@@ -239,8 +240,13 @@ build_lba_arr(const char * inp, uint64_t * lba_arr,
if (-1 != ll) {
lba_arr[k] = (uint64_t)ll;
cp = strchr(lcp, ',');
+ c2p = strchr(lcp, ' ');
+ if (NULL == cp)
+ cp = c2p;
if (NULL == cp)
break;
+ if (c2p && (c2p < cp))
+ cp = c2p;
lcp = cp + 1;
} else {
fprintf(stderr, "build_lba_arr: error at pos %d\n",
diff --git a/src/sg_senddiag.c b/src/sg_senddiag.c
index 84e55aab..63313ace 100644
--- a/src/sg_senddiag.c
+++ b/src/sg_senddiag.c
@@ -13,8 +13,8 @@
#include "sg_cmds_basic.h"
#include "sg_cmds_extra.h"
-/* A utility program for the Linux OS SCSI generic ("sg") device driver.
-* Copyright (C) 2003-2007 D. Gilbert
+/* A utility program originally written for the Linux OS SCSI subsystem
+* Copyright (C) 2003-2009 D. Gilbert
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
@@ -24,7 +24,7 @@
the SCSI RECEIVE DIAGNOSTIC command to list supported diagnostic pages.
*/
-static char * version_str = "0.34 20070714";
+static char * version_str = "0.35 20090401";
#define ME "sg_senddiag: "
@@ -397,6 +397,7 @@ static int build_diag_page(const char * inp, unsigned char * mp_arr,
unsigned int h;
const char * lcp;
char * cp;
+ char * c2p;
if ((NULL == inp) || (NULL == mp_arr) ||
(NULL == mp_arr_len))
@@ -470,7 +471,7 @@ static int build_diag_page(const char * inp, unsigned char * mp_arr,
}
*mp_arr_len = off;
} else { /* hex string on command line */
- k = strspn(inp, "0123456789aAbBcCdDeEfF,");
+ k = strspn(inp, "0123456789aAbBcCdDeEfF, ");
if (in_len != k) {
fprintf(stderr, "build_diag_page: error at pos %d\n", k + 1);
return 1;
@@ -484,8 +485,13 @@ static int build_diag_page(const char * inp, unsigned char * mp_arr,
}
mp_arr[k] = h;
cp = strchr(lcp, ',');
+ c2p = strchr(lcp, ' ');
+ if (NULL == cp)
+ cp = c2p;
if (NULL == cp)
break;
+ if (c2p && (c2p < cp))
+ cp = c2p;
lcp = cp + 1;
} else {
fprintf(stderr, "build_diag_page: error at pos %d\n",
diff --git a/src/sg_ses.c b/src/sg_ses.c
index 6aff6cc6..bba29e6e 100644
--- a/src/sg_ses.c
+++ b/src/sg_ses.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004-2008 Douglas Gilbert.
+ * Copyright (c) 2004-2009 Douglas Gilbert.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -46,7 +46,7 @@
* commands tailored for SES (enclosure) devices.
*/
-static char * version_str = "1.43 20080514"; /* ses2r19b */
+static char * version_str = "1.44 20090401"; /* ses2r19b */
#define MX_ALLOC_LEN 4096
#define MX_ELEM_HDR 1024
@@ -1492,6 +1492,7 @@ read_hex(const char * inp, unsigned char * arr, int * arr_len)
unsigned int h;
const char * lcp;
char * cp;
+ char * c2p;
char line[512];
if ((NULL == inp) || (NULL == arr) || (NULL == arr_len))
@@ -1554,7 +1555,7 @@ read_hex(const char * inp, unsigned char * arr, int * arr_len)
}
*arr_len = off;
} else { /* hex string on command line */
- k = strspn(inp, "0123456789aAbBcCdDeEfF,");
+ k = strspn(inp, "0123456789aAbBcCdDeEfF, ");
if (in_len != k) {
fprintf(stderr, "read_hex: error at pos %d\n",
k + 1);
@@ -1569,8 +1570,13 @@ read_hex(const char * inp, unsigned char * arr, int * arr_len)
}
arr[k] = h;
cp = strchr(lcp, ',');
+ c2p = strchr(lcp, ' ');
+ if (NULL == cp)
+ cp = c2p;
if (NULL == cp)
break;
+ if (c2p && (c2p < cp))
+ cp = c2p;
lcp = cp + 1;
} else {
fprintf(stderr, "read_hex: error at pos %d\n",
@@ -1976,7 +1982,9 @@ main(int argc, char * argv[])
break;
default:
fprintf(stderr, "Setting SES control page 0x%x not supported "
- "yet\n", page_code);
+ "by this utility\n", page_code);
+ fprintf(stderr, "That can be done with the sg_senddiag utility "
+ "with its '--raw=' option\n");
ret = SG_LIB_SYNTAX_ERROR;
break;
}
diff --git a/src/sg_wr_mode.c b/src/sg_wr_mode.c
index 9cadbec2..55dd64af 100644
--- a/src/sg_wr_mode.c
+++ b/src/sg_wr_mode.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004-2007 Douglas Gilbert.
+ * Copyright (c) 2004-2009 Douglas Gilbert.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -40,13 +40,13 @@
#include "sg_lib.h"
#include "sg_cmds_basic.h"
-/* A utility program for the Linux OS SCSI subsystem.
+/* A utility program originally written for the Linux OS SCSI subsystem.
*
* This program writes the given mode page contents to the corresponding
* mode page on the given device.
*/
-static char * version_str = "1.09 20070919";
+static char * version_str = "1.10 20090401";
#define ME "sg_wr_mode: "
@@ -110,9 +110,11 @@ static void usage()
}
-/* Read hex numbers from command line (comma separated list) or from */
-/* stdin (one per line, comma separated list or space separated list). */
-/* Returns 0 if ok, or 1 if error. */
+/* Read hex numbers from command line or stdin. On the command line can
+ * either be comma or space separated list. Space separated list need to be
+ * quoted. For stdin (indicated by *inp=='-') there should be either
+ * one entry per line, a comma separated list or space separated list.
+ * Returns 0 if ok, or 1 if error. */
static int build_mode_page(const char * inp, unsigned char * mp_arr,
int * mp_arr_len, int max_arr_len)
{
@@ -120,6 +122,7 @@ static int build_mode_page(const char * inp, unsigned char * mp_arr,
unsigned int h;
const char * lcp;
char * cp;
+ char * c2p;
if ((NULL == inp) || (NULL == mp_arr) ||
(NULL == mp_arr_len))
@@ -193,7 +196,7 @@ static int build_mode_page(const char * inp, unsigned char * mp_arr,
}
*mp_arr_len = off;
} else { /* hex string on command line */
- k = strspn(inp, "0123456789aAbBcCdDeEfF,");
+ k = strspn(inp, "0123456789aAbBcCdDeEfF, ");
if (in_len != k) {
fprintf(stderr, "build_mode_page: error at pos %d\n", k + 1);
return 1;
@@ -207,8 +210,13 @@ static int build_mode_page(const char * inp, unsigned char * mp_arr,
}
mp_arr[k] = h;
cp = strchr(lcp, ',');
+ c2p = strchr(lcp, ' ');
+ if (NULL == cp)
+ cp = c2p;
if (NULL == cp)
break;
+ if (c2p && (c2p < cp))
+ cp = c2p;
lcp = cp + 1;
} else {
fprintf(stderr, "build_mode_page: error at pos %d\n",
@@ -225,8 +233,9 @@ static int build_mode_page(const char * inp, unsigned char * mp_arr,
return 0;
}
-/* Read hex numbers from command line (comma separated list). */
-/* Returns 0 if ok, or 1 if error. */
+/* Read hex numbers from command line (comma separated list).
+ * Can also be (single) space separated list but needs to be quoted on the
+ * command line. Returns 0 if ok, or 1 if error. */
static int build_mask(const char * inp, unsigned char * mask_arr,
int * mask_arr_len, int max_arr_len)
{
@@ -234,6 +243,7 @@ static int build_mask(const char * inp, unsigned char * mask_arr,
unsigned int h;
const char * lcp;
char * cp;
+ char * c2p;
if ((NULL == inp) || (NULL == mask_arr) ||
(NULL == mask_arr_len))
@@ -246,7 +256,7 @@ static int build_mask(const char * inp, unsigned char * mask_arr,
fprintf(stderr, "'--mask' does not accept input from stdin\n");
return 1;
} else { /* hex string on command line */
- k = strspn(inp, "0123456789aAbBcCdDeEfF,");
+ k = strspn(inp, "0123456789aAbBcCdDeEfF, ");
if (in_len != k) {
fprintf(stderr, "build_mode_page: error at pos %d\n", k + 1);
return 1;
@@ -260,8 +270,13 @@ static int build_mask(const char * inp, unsigned char * mask_arr,
}
mask_arr[k] = h;
cp = strchr(lcp, ',');
+ c2p = strchr(lcp, ' ');
+ if (NULL == cp)
+ cp = c2p;
if (NULL == cp)
break;
+ if (c2p && (c2p < cp))
+ cp = c2p;
lcp = cp + 1;
} else {
fprintf(stderr, "build_mode_page: error at pos %d\n",