public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Sami Kerola <kerolasa@iki.fi>
To: util-linux@vger.kernel.org
Cc: kerolasa@iki.fi
Subject: [PATCH 08/33] hexdump: add long options to the command
Date: Sat, 13 Apr 2013 20:54:36 +0100	[thread overview]
Message-ID: <1365882901-11429-9-git-send-email-kerolasa@iki.fi> (raw)
In-Reply-To: <1365882901-11429-1-git-send-email-kerolasa@iki.fi>

Includes update to bash completion, and manual as well.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 bash-completion/hexdump | 22 ++++++++++++++----
 text-utils/hexdump.1    | 24 +++++++++----------
 text-utils/hexsyntax.c  | 61 ++++++++++++++++++++++++++++++++-----------------
 3 files changed, 69 insertions(+), 38 deletions(-)

diff --git a/bash-completion/hexdump b/bash-completion/hexdump
index 0c91187..aa6f8ce 100644
--- a/bash-completion/hexdump
+++ b/bash-completion/hexdump
@@ -5,25 +5,37 @@ _hexdump_module()
 	cur="${COMP_WORDS[COMP_CWORD]}"
 	prev="${COMP_WORDS[COMP_CWORD-1]}"
 	case $prev in
-		'-e')
+		'-e'|'--format')
 			COMPREPLY=( $(compgen -W "format" -- $cur) )
 			return 0
 			;;
-		'-n')
+		'-n'|'--length')
 			COMPREPLY=( $(compgen -W "length" -- $cur) )
 			return 0
 			;;
-		'-s')
+		'-s'|'--skip')
 			COMPREPLY=( $(compgen -W "offset" -- $cur) )
 			return 0
 			;;
-		'-V')
+		'-V'|'--version'|'-h'|'--help')
 			return 0
 			;;
 	esac
 	case $cur in
 		-*)
-			OPTS="-b -c -C -d -o -x -e -f -n -s -v -V"
+			OPTS="	--one-byte-octal
+				--one-byte-char
+				--canonical
+				--two-bytes-decimal
+				--two-bytes-octal
+				--two-bytes-hex
+				--format
+				--format-file
+				--length
+				--skip
+				--no-squeezing
+				--version
+				--help"
 			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
 			return 0
 			;;
diff --git a/text-utils/hexdump.1 b/text-utils/hexdump.1
index 903100d..e8afdba 100644
--- a/text-utils/hexdump.1
+++ b/text-utils/hexdump.1
@@ -31,7 +31,7 @@
 .\"
 .\"	from: @(#)hexdump.1	8.2 (Berkeley) 4/18/94
 .\"
-.TH HEXDUMP "1" "September 2011" "util-linux" "User Commands"
+.TH HEXDUMP "1" "April 2013" "util-linux" "User Commands"
 .SH NAME
 hexdump \- display file contents in ascii, decimal, hexadecimal, or octal
 .SH SYNOPSIS
@@ -49,17 +49,17 @@ suffixes KiB=1024, MiB=1024*1024, and so on for GiB, TiB, PiB, EiB, ZiB and YiB
 (the "iB" is optional, e.g. "K" has the same meaning as "KiB") or the suffixes
 KB=1000, MB=1000*1000, and so on for GB, TB, PB, EB, ZB and YB.
 .TP
-.B \-b
+\fB\-b\fR, \fB\-\-one\-byte\-octal\fR
 \fIOne-byte octal display\fR.  Display the input offset in hexadecimal,
 followed by sixteen space-separated, three-column, zero-filled bytes of input
 data, in octal, per line.
 .TP
-.B \-c
+\fB\-c\fR, \fB\-\-one\-byte\-char\fR
 \fIOne-byte character display\fR.  Display the input offset in hexadecimal,
 followed by sixteen space-separated, three-column, space-filled characters of
 input data per line.
 .TP
-.B \-C
+\fB\-C\fR, \fB\-\-canonical\fR
 \fICanonical hex+ASCII display\fR.  Display the input offset in hexadecimal,
 followed by sixteen space-separated, two-column, hexadecimal bytes, followed
 by the same sixteen bytes in
@@ -68,35 +68,35 @@ format enclosed in
 .RB ' | '
 characters.
 .TP
-.B \-d
+\fB\-d\fR, \fB\-\-two\-bytes\-decimal\fR
 \fITwo-byte decimal display\fR.  Display the input offset in hexadecimal,
 followed by eight space-separated, five-column, zero-filled, two-byte units
 of input data, in unsigned decimal, per line.
 .TP
-.BI \-e \ format_string
+\fB\-e\fR, \fB\-\-format\fR \fIformat_string\fR
 Specify a format string to be used for displaying data.
 .TP
-.BI \-f \ format_file
+\fB\-r\fR, \fB\-\-format\-file\fR \fIfile\fR
 Specify a file that contains one or more newline separated format strings.
 Empty lines and lines whose first non-blank character is a hash mark (\&#)
 are ignored.
 .TP
-.BI \-n \ length
+\fB\-n\fR, \fB\-\-length\fR \fIlength\fR
 Interpret only
 .I length
 bytes of input.
 .TP
-.B \-o
+\fB\-o\fR, \fB\-\-two\-bytes\-octal\fR
 \fITwo-byte octal display\fR.  Display the input offset in hexadecimal,
 followed by eight space-separated, six-column, zero-filled, two-byte
 quantities of input data, in octal, per line.
 .TP
-.BI \-s \ offset
+\fB\-s\fR, \fB\-\-skip\fR \fIoffset\fR
 Skip
 .I offset
 bytes from the beginning of the input.
 .TP
-.B \-v
+\fB\-v\fR, \fB\-\-no\-squeezing\fR
 The
 .B \-v
 option causes
@@ -107,7 +107,7 @@ option, any number of groups of output lines which would be identical to the
 immediately preceding group of output lines (except for the input offsets),
 are replaced with a line comprised of a single asterisk.
 .TP
-.B \-x
+\fB\-x\fR, \fB\-\-two\-bytes\-hex\fR
 \fITwo-byte hexadecimal display\fR.  Display the input offset in hexadecimal,
 followed by eight space-separated, four-column, zero-filled, two-byte
 quantities of input data, in hexadecimal, per line.
diff --git a/text-utils/hexsyntax.c b/text-utils/hexsyntax.c
index b0e4fb7..2910ca5 100644
--- a/text-utils/hexsyntax.c
+++ b/text-utils/hexsyntax.c
@@ -42,6 +42,7 @@
 #include <errno.h>
 #include <err.h>
 #include <limits.h>
+#include <getopt.h>
 #include "hexdump.h"
 #include "nls.h"
 #include "strutils.h"
@@ -56,8 +57,25 @@ newsyntax(int argc, char ***argvp)
 	int ch;
 	char **argv;
 
+	static const struct option longopts[] = {
+		{"one-byte-octal", no_argument, NULL, 'b'},
+		{"one-byte-char", required_argument, NULL, 'c'},
+		{"canonical", required_argument, NULL, 'C'},
+		{"two-bytes-decimal", no_argument, NULL, 'd'},
+		{"two-bytes-octal", required_argument, NULL, 'o'},
+		{"two-bytes-hex", no_argument, NULL, 'x'},
+		{"format", required_argument, NULL, 'e'},
+		{"format-file", required_argument, NULL, 'f'},
+		{"length", required_argument, NULL, 'n'},
+		{"skip", required_argument, NULL, 's'},
+		{"no-squeezing", no_argument, NULL, 'v'},
+		{"help", no_argument, NULL, 'h'},
+		{"version", no_argument, NULL, 'V'},
+		{NULL, no_argument, NULL, 0}
+	};
+
 	argv = *argvp;
-	while ((ch = getopt(argc, argv, "bcCde:f:n:os:vxV")) != -1) {
+	while ((ch = getopt_long(argc, argv, "bcCde:f:n:os:vxhV", longopts, NULL)) != -1) {
 		switch (ch) {
 		case 'b':
 			add("\"%07.7_Ax\n\"");
@@ -99,10 +117,10 @@ newsyntax(int argc, char ***argvp)
 			add("\"%07.7_Ax\n\"");
 			add("\"%07.7_ax \" 8/2 \"   %04x \" \"\\n\"");
 			break;
+		case 'h':
+			usage(stdout);
 		case 'V':
-			printf(_("%s from %s\n"),
-					program_invocation_short_name,
-					PACKAGE_STRING);
+			printf(UTIL_LINUX_VERSION);
 			exit(EXIT_SUCCESS);
 			break;
 		default:
@@ -120,23 +138,24 @@ newsyntax(int argc, char ***argvp)
 
 void __attribute__((__noreturn__)) usage(FILE *out)
 {
-	fprintf(out, _("\nUsage:\n"
-		       " %s [options] file...\n"),
-		       program_invocation_short_name);
-	fprintf(out, _(
-		       "\nOptions:\n"
-		       " -b              one-byte octal display\n"
-		       " -c              one-byte character display\n"
-		       " -C              canonical hex+ASCII display\n"
-		       " -d              two-byte decimal display\n"
-		       " -o              two-byte octal display\n"
-		       " -x              two-byte hexadecimal display\n"
-		       " -e format       format string to be used for displaying data\n"
-		       " -f format_file  file that contains format strings\n"
-		       " -n length       interpret only length bytes of input\n"
-		       " -s offset       skip offset bytes from the beginning\n"
-		       " -v              display without squeezing similar lines\n"
-		       " -V              output version information and exit\n\n"));
+	fputs(USAGE_HEADER, out);
+	fprintf(out, _(" %s [options] file...\n"), program_invocation_short_name);
+	fputs(USAGE_OPTIONS, out);
+	fputs(_(" -b, --one-byte-octal      one-byte octal display\n"), out);
+	fputs(_(" -c, --one-byte-char       one-byte character display\n"), out);
+	fputs(_(" -C, --canonical           canonical hex+ASCII display\n"), out);
+	fputs(_(" -d, --two-bytes-decimal   two-byte decimal display\n"), out);
+	fputs(_(" -o, --two-bytes-octal     two-byte octal display\n"), out);
+	fputs(_(" -x, --two-bytes-hex       two-byte hexadecimal display\n"), out);
+	fputs(_(" -e, --format format       format string to be used for displaying data\n"), out);
+	fputs(_(" -f, --format-file <file>  file that contains format strings\n"), out);
+	fputs(_(" -n, --length <length>     interpret only length bytes of input\n"), out);
+	fputs(_(" -s, --skip <offset>       skip offset bytes from the beginning\n"), out);
+	fputs(_(" -v, --no-squeezing        output identical lines\n"), out);
+	fputs(USAGE_SEPARATOR, out);
+	fputs(USAGE_HELP, out);
+	fputs(USAGE_VERSION, out);
+	fprintf(out, USAGE_MAN_TAIL("hexdump(1)"));
 
 	exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
 }
-- 
1.8.2.1


  parent reply	other threads:[~2013-04-13 19:55 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-13 19:54 [PATCH 00/33] pull: bash completions, help screens, and file writing Sami Kerola
2013-04-13 19:54 ` [PATCH 01/33] bash-completion: add mount and umount Sami Kerola
2013-04-13 19:54 ` [PATCH 02/33] blkid, hwclock, ldattach: use program_invocation_short_name Sami Kerola
2013-04-13 19:54 ` [PATCH 03/33] utmpdump: add option to write to a file Sami Kerola
2013-04-13 19:54 ` [PATCH 04/33] cfdisk: add long options to the command Sami Kerola
2013-04-26 11:30   ` Karel Zak
2013-04-13 19:54 ` [PATCH 05/33] bash-completion: prefer bash 3.x 'here string' syntax Sami Kerola
2013-04-13 21:59   ` Dave Reisner
2013-04-26 11:38     ` Karel Zak
2013-04-26 12:29       ` Sami Kerola
2013-04-13 19:54 ` [PATCH 06/33] setpriv: allow login and group name option arguments Sami Kerola
2013-04-13 19:54 ` [PATCH 07/33] build-sys: add --disable-setterm to ./configure Sami Kerola
2013-04-26 11:53   ` Karel Zak
2013-04-13 19:54 ` Sami Kerola [this message]
2013-04-13 19:54 ` [PATCH 09/33] setsid: exit when control terminal cannot be set Sami Kerola
2013-04-13 19:54 ` [PATCH 10/33] cfdisk: check writing to a file was successful Sami Kerola
2013-04-13 19:54 ` [PATCH 11/33] setpriv: " Sami Kerola
2013-04-13 19:54 ` [PATCH 12/33] agetty: " Sami Kerola
2013-04-13 19:54 ` [PATCH 13/33] pg: " Sami Kerola
2013-04-13 19:54 ` [PATCH 14/33] libblkid: " Sami Kerola
2013-04-13 19:54 ` [PATCH 15/33] libmount: " Sami Kerola
2013-04-13 19:54 ` [PATCH 16/33] include: add close_fd() for noticing write errors before close() Sami Kerola
2013-04-13 19:54 ` [PATCH 17/33] fdformat: check writing to a file descriptor was successful Sami Kerola
2013-04-13 19:54 ` [PATCH 18/33] partx: " Sami Kerola
2013-04-13 19:54 ` [PATCH 19/33] resizepart: " Sami Kerola
2013-04-13 19:54 ` [PATCH 20/33] cfdisk: " Sami Kerola
2013-04-13 19:54 ` [PATCH 21/33] sfdisk: " Sami Kerola
2013-04-13 19:54 ` [PATCH 22/33] wdctl: " Sami Kerola
2013-04-13 19:54 ` [PATCH 23/33] fsck.cramfs: " Sami Kerola
2013-04-13 19:54 ` [PATCH 24/33] fsck.minix: " Sami Kerola
2013-04-13 19:54 ` [PATCH 25/33] mkfs.bfs: " Sami Kerola
2013-04-13 19:54 ` [PATCH 26/33] mkfs.cramfs: unify write check to a file descriptor Sami Kerola
2013-04-13 19:54 ` [PATCH 27/33] mkfs.minix: check writing to a file descriptor was successful Sami Kerola
2013-04-13 19:54 ` [PATCH 28/33] mkswap: unify write check to a file descriptor Sami Kerola
2013-04-13 19:54 ` [PATCH 29/33] swaplabel: check writing to a file descriptor was successful Sami Kerola
2013-04-13 19:54 ` [PATCH 30/33] fallocate: " Sami Kerola
2013-04-13 19:54 ` [PATCH 31/33] setpriv: " Sami Kerola
2013-04-13 19:55 ` [PATCH 32/33] swapon: " Sami Kerola
2013-04-13 19:55 ` [PATCH 33/33] wall: " Sami Kerola
2013-04-17 13:31 ` [PATCH 00/33] pull: bash completions, help screens, and file writing Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1365882901-11429-9-git-send-email-kerolasa@iki.fi \
    --to=kerolasa@iki.fi \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox