diff mbox

[6/6] mtd-utils/nanddump.c: Add "forcebinary" flag

Message ID 1278622209-20149-7-git-send-email-norris@broadcom.com
State New, archived
Headers show

Commit Message

Brian Norris July 8, 2010, 8:50 p.m. UTC
Restrict binary dumping so that by default, binary garbage is not
printed directly to a terminal. Output redicted to files or piped to
other commands should not be affected (as judged by "isatty(ofd)").
A new flag "-a" or "--forcebinary" is included so that users can
override this behavior if necessary.

Signed-off-by: Brian Norris <norris@broadcom.com>
---
 nanddump.c |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)

Comments

Brian Norris July 8, 2010, 10:03 p.m. UTC | #1
Sorry, apparently some of the "In-Reply-To" information got screwed up. 
The cover e-mail as well as patches 1 and 3 are in the proper chain, but 
not 2, 4, 5, 6. :(

Brian
Artem Bityutskiy July 18, 2010, 7:23 a.m. UTC | #2
On Thu, 2010-07-08 at 13:50 -0700, Brian Norris wrote:
> Restrict binary dumping so that by default, binary garbage is not
> printed directly to a terminal. Output redicted to files or piped to
> other commands should not be affected (as judged by "isatty(ofd)").
> A new flag "-a" or "--forcebinary" is included so that users can
> override this behavior if necessary.
> 
> Signed-off-by: Brian Norris <norris@broadcom.com>

Could you pleas make hexdump independent (make the ascii switch to be
the function argument, not a global knob), and re-send the nanddump
patches? I did not push patches 2, 3, 6, but pushed the rest of the
patches.
diff mbox

Patch

diff --git a/nanddump.c b/nanddump.c
index 2e316b9..8815bdb 100644
--- a/nanddump.c
+++ b/nanddump.c
@@ -45,6 +45,7 @@  static void display_help (void)
 "\n"
 "           --help               Display this help and exit\n"
 "           --version            Output version information and exit\n"
+"-a         --forcebinary        Force printing of binary data to tty\n"
 "-c         --canonicalprint     Print canonical Hex+ASCII dump\n"
 "-f file    --file=file          Dump to file\n"
 "-i         --ignoreerrors       Ignore errors\n"
@@ -85,6 +86,7 @@  static const char	*dumpfile;		// dump file name
 static bool		omitbad = false;
 static bool		quiet = false;		// suppress diagnostic output
 static bool		ascii = false;		// print nice + ascii
+static bool		forcebinary = false;	// force printing binary to tty
 
 static void process_options (int argc, char * const argv[])
 {
@@ -92,10 +94,11 @@  static void process_options (int argc, char * const argv[])
 
 	for (;;) {
 		int option_index = 0;
-		static const char *short_options = "bs:f:il:opqnc";
+		static const char *short_options = "bs:f:il:opqnca";
 		static const struct option long_options[] = {
 			{"help", no_argument, 0, 0},
 			{"version", no_argument, 0, 0},
+			{"forcebinary", no_argument, 0, 'a'},
 			{"canonicalprint", no_argument, 0, 'c'},
 			{"file", required_argument, 0, 'f'},
 			{"ignoreerrors", no_argument, 0, 'i'},
@@ -147,6 +150,9 @@  static void process_options (int argc, char * const argv[])
 			case 'o':
 				omitoob = true;
 				break;
+			case 'a':
+				forcebinary = true;
+				break;
 			case 'c':
 				ascii = true;
 			case 'p':
@@ -170,6 +176,13 @@  static void process_options (int argc, char * const argv[])
 		exit(EXIT_FAILURE);
 	}
 
+	if (forcebinary && pretty_print) {
+		fprintf(stderr, "The forcebinary and pretty print options are\n"
+				"mutually-exclusive. Choose one or the "
+				"other.\n");
+		exit(EXIT_FAILURE);
+	}
+
 	if ((argc - optind) != 1 || error)
 		display_help ();
 
@@ -354,6 +367,13 @@  int main(int argc, char * const argv[])
 		exit(EXIT_FAILURE);
 	}
 
+	if (!pretty_print && !forcebinary && isatty(ofd)) {
+		fprintf(stderr, "Not printing binary garbage to tty. Use '-a'\n"
+				"or '--forcebinary' to override.\n");
+		close(fd);
+		exit(EXIT_FAILURE);
+	}
+
 	/* Initialize start/end addresses and block size */
 	if (length)
 		end_addr = start_addr + length;