aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2014-01-05 17:38:06 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2014-01-05 17:38:06 +0000
commitba45b6eeb5d139d317e496101b0207674a8c8c92 (patch)
tree95b5e7dde436332e78304b1ec4f15052c9e9eb57
parentd95fb62cfb049ca3c682da9b21d32157c46d4800 (diff)
downloadsg3_utils-ba45b6eeb5d139d317e496101b0207674a8c8c92.tar.gz
sg_xcopy: improve CL handling of short options (e.g. '-vv')
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@541 6180dd3e-e324-4e3e-922d-17de1ae2f315
-rw-r--r--ChangeLog3
-rw-r--r--README2
-rw-r--r--debian/changelog2
-rw-r--r--doc/sg3_utils.84
-rw-r--r--sg3_utils.spec2
-rw-r--r--src/sg_xcopy.c81
6 files changed, 58 insertions, 36 deletions
diff --git a/ChangeLog b/ChangeLog
index 4deff663..6f5dcd24 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.38 [20131219] [svn: r540]
+Changelog for sg3_utils-1.38 [20140105] [svn: r541]
- sg_ses: add --dev-slot-num= and --sas-addr=
- error and warning message cleanup
- add --maxlen= option
@@ -15,6 +15,7 @@ Changelog for sg3_utils-1.38 [20131219] [svn: r540]
- sg_xcopy: environment variables: XCOPY_TO_SRC and
XCOPY_TO_DST indicate where xcopy command is sent
- change default to send xcopy to dst (was src)
+ - improve CL handling of short options (e.g. '-vv')
- sg_luns: guard against garbage response
- sg_write_same: repeat if unit attention
- sg_rtpg: fix indexing bug with --extended option
diff --git a/README b/README
index 9a5b6216..3d6ac92f 100644
--- a/README
+++ b/README
@@ -401,4 +401,4 @@ See http://sg.danny.cz/sg/tools.html
Douglas Gilbert
-18th December 2013
+5th January 2014
diff --git a/debian/changelog b/debian/changelog
index 44ea38ab..4f401f67 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -2,7 +2,7 @@ sg3-utils (1.38-0.1) unstable; urgency=low
* New upstream version
- -- Douglas Gilbert <dgilbert@interlog.com> Wed, 18 Dec 2013 15:00:00 -0500
+ -- Douglas Gilbert <dgilbert@interlog.com> Sun, 05 Jan 2014 01:00:00 -0500
sg3-utils (1.37-0.1) unstable; urgency=low
diff --git a/doc/sg3_utils.8 b/doc/sg3_utils.8
index 67c50222..586090ed 100644
--- a/doc/sg3_utils.8
+++ b/doc/sg3_utils.8
@@ -1,4 +1,4 @@
-.TH SG3_UTILS "8" "December 2013" "sg3_utils\-1.38" SG3_UTILS
+.TH SG3_UTILS "8" "January 2014" "sg3_utils\-1.38" SG3_UTILS
.SH NAME
sg3_utils \- a package of utilities for sending SCSI commands
.SH SYNOPSIS
@@ -418,7 +418,7 @@ CREDITS file and individual source files (in the 'src' directory).
.SH "REPORTING BUGS"
Report bugs to <dgilbert at interlog dot com>.
.SH COPYRIGHT
-Copyright \(co 1999\-2013 Douglas Gilbert
+Copyright \(co 1999\-2014 Douglas Gilbert
.br
Some utilities are distributed under a GPL version 2 license while
others, usually more recent ones, are under a FreeBSD license. The files
diff --git a/sg3_utils.spec b/sg3_utils.spec
index 80c5f12e..4f9cb984 100644
--- a/sg3_utils.spec
+++ b/sg3_utils.spec
@@ -79,7 +79,7 @@ fi
%{_libdir}/*.la
%changelog
-* Wed Dec 18 2013 - dgilbert at interlog dot com
+* Sun Jan 05 2014 - dgilbert at interlog dot com
- track t10 changes
* sg3_utils-1.38
diff --git a/src/sg_xcopy.c b/src/sg_xcopy.c
index 70e0262f..ad99fd8b 100644
--- a/src/sg_xcopy.c
+++ b/src/sg_xcopy.c
@@ -1,7 +1,7 @@
/* A utility program for copying files. Similar to 'dd' but using
* the 'Extended Copy' command.
*
- * Copyright (c) 2011-2013 Hannes Reinecke, SUSE Labs
+ * Copyright (c) 2011-2014 Hannes Reinecke, SUSE Labs
*
* Largely taken from 'sg_dd', which has the
*
@@ -62,7 +62,7 @@
#include "sg_cmds_extra.h"
#include "sg_io_linux.h"
-static const char * version_str = "0.41 20131218";
+static const char * version_str = "0.41 20140105";
#define ME "sg_xcopy: "
@@ -1443,6 +1443,18 @@ file_err:
return -SG_LIB_FILE_ERROR;
}
+static int
+num_chs_in_str(const char * s, int slen, int ch)
+{
+ int res = 0;
+
+ while (--slen >= 0) {
+ if (ch == s[slen])
+ ++res;
+ }
+ return res;
+}
+
int
main(int argc, char * argv[])
@@ -1459,7 +1471,7 @@ main(int argc, char * argv[])
int blocks = 0;
int num_help = 0;
int num_xcopy = 0;
- int res, k;
+ int res, k, n, keylen;
int infd, outfd, xcopy_fd;
int ret = 0;
unsigned char list_id = 1;
@@ -1493,6 +1505,7 @@ main(int argc, char * argv[])
buf++;
if (*buf)
*buf++ = '\0';
+ keylen = (int)strlen(key);
if (0 == strncmp(key, "app", 3)) {
ixcf.append = sg_get_num(buf);
oxcf.append = ixcf.append;
@@ -1594,37 +1607,45 @@ main(int argc, char * argv[])
do_time = sg_get_num(buf);
else if (0 == strncmp(key, "verb", 4))
verbose = sg_get_num(buf);
- else if (0 == strncmp(key, "--on_src", 8))
- on_src = 1;
- else if (0 == strncmp(key, "--on_dst", 8))
- on_dst = 1;
- else if (0 == strncmp(key, "-hhh", 4))
- num_help += 3;
- else if (0 == strncmp(key, "-hh", 3))
- num_help += 2;
- else if ((0 == strncmp(key, "--help", 7)) ||
- (0 == strncmp(key, "-h", 2)) ||
- (0 == strcmp(key, "-?")))
+ /* look for long options that start with '--' */
+ else if (0 == strncmp(key, "--help", 6))
++num_help;
- else if ((0 == strncmp(key, "--vers", 6)) ||
- (0 == strcmp(key, "-V"))) {
+ else if (0 == strncmp(key, "--on_dst", 8))
+ ++on_dst;
+ else if (0 == strncmp(key, "--on_src", 8))
+ ++on_src;
+ else if (0 == strncmp(key, "--verb", 6))
+ verbose += 1;
+ else if (0 == strncmp(key, "--vers", 6)) {
pr2serr(ME "%s\n", version_str);
return 0;
- } else if (0 == strncmp(key, "--verb", 6))
- verbose += 1;
- else if (0 == strcmp(key, "-vvvvv"))
- verbose += 5;
- else if (0 == strcmp(key, "-vvvv"))
- verbose += 4;
- else if (0 == strcmp(key, "-vvv"))
- verbose += 3;
- else if (0 == strcmp(key, "-vv"))
- verbose += 2;
- else if (0 == strcmp(key, "-v"))
- verbose += 1;
- else if (0 == strncmp(key, "--xcopy", 6))
+ }
+ else if (0 == strncmp(key, "--xcopy", 7))
; /* ignore; for compatibility with ddpt */
- else {
+ /* look for short options that start with a single '-', they can be
+ * concaternated (e.g. '-vvvV') */
+ else if ((keylen > 1) && ('-' == key[0]) && ('-' != key[1])) {
+ res = 0;
+ n = num_chs_in_str(key + 1, keylen - 1, 'h');
+ num_help += n;
+ res += n;
+ n = num_chs_in_str(key + 1, keylen - 1, 'v');
+ verbose += n;
+ res += n;
+ if (num_chs_in_str(key + 1, keylen - 1, 'V')) {
+ pr2serr("%s\n", version_str);
+ return -1;
+ }
+ n = num_chs_in_str(key + 1, keylen - 1, 'x');
+ /* accept and ignore; for compatibility with ddpt */
+ res += n;
+ if (res < (keylen - 1)) {
+ pr2serr(ME "Unrecognised short option in '%s', try "
+ "'--help'\n", key);
+ if (0 == num_help)
+ return -1;
+ }
+ } else {
pr2serr("Unrecognized option '%s'\n", key);
if (num_help)
usage(num_help);