public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] strings: Add --include-all-whitespace option
@ 2014-06-19  3:11 Erik Ackermann
  2014-06-26 13:12 ` Nicholas Clifton
  0 siblings, 1 reply; 2+ messages in thread
From: Erik Ackermann @ 2014-06-19  3:11 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 377 bytes --]

This patch adds an option to allow all whitespace to be considered a
valid "string", not just the space character covered in ISPRINT and
the TAB character which is special cased.

This add some context for the previous patch for a custom record
separator, because used with this option newlines can be inside valid
text, we might want to supply a custom unique dlimiter.

Erik

[-- Attachment #2: 0001-Add-include-all-whitespace-option-to-consider-all-wh.patch --]
[-- Type: text/x-patch, Size: 3289 bytes --]

From a72f19f818970233ec256f61b902aecaaa2a59d6 Mon Sep 17 00:00:00 2001
From: Erik Ackermann <kurterikackermann@gmail.com>
Date: Wed, 18 Jun 2014 20:07:43 -0700
Subject: [PATCH] Add --include-all-whitespace option to consider all
 whitespace as valid in parsing.

---
 binutils/strings.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/binutils/strings.c b/binutils/strings.c
index bb00d41..b071447 100644
--- a/binutils/strings.c
+++ b/binutils/strings.c
@@ -35,6 +35,10 @@
    -t {o,x,d}	Print the offset within the file before each string,
 		in octal/hex/decimal.
 
+  --include-all-whitespace
+  -w		By default tab and space are the only whitepace included in graphic
+		char sequences. this option considers all of isspace() valid.
+
    -o		Like -to.  (Some other implementations have -o like -to,
 		others like -td.  We chose one arbitrarily.)
 
@@ -68,7 +72,9 @@
 #define STRING_ISGRAPHIC(c) \
       (   (c) >= 0 \
        && (c) <= 255 \
-       && ((c) == '\t' || ISPRINT (c) || (encoding == 'S' && (c) > 127)))
+       && ((c) == '\t' || ISPRINT (c) || (encoding == 'S' && (c) > 127) \
+           || (include_all_whitespace == TRUE && ISSPACE (c))) \
+      )
 
 #ifndef errno
 extern int errno;
@@ -83,6 +89,9 @@ static int address_radix;
 /* Minimum length of sequence of graphic chars to trigger output.  */
 static int string_min;
 
+/* Whether or not we include all whitespace as a graphic char.   */
+static bfd_boolean include_all_whitespace;
+
 /* TRUE means print address within file for each string.  */
 static bfd_boolean print_addresses;
 
@@ -108,6 +117,7 @@ static struct option long_options[] =
   {"print-file-name", no_argument, NULL, 'f'},
   {"bytes", required_argument, NULL, 'n'},
   {"radix", required_argument, NULL, 't'},
+  {"include-all-whitespace", required_argument, NULL, 'w'},
   {"encoding", required_argument, NULL, 'e'},
   {"target", required_argument, NULL, 'T'},
   {"help", no_argument, NULL, 'h'},
@@ -154,13 +164,14 @@ main (int argc, char **argv)
   expandargv (&argc, &argv);
 
   string_min = 4;
+  include_all_whitespace = FALSE;
   print_addresses = FALSE;
   print_filenames = FALSE;
   datasection_only = TRUE;
   target = NULL;
   encoding = 's';
 
-  while ((optc = getopt_long (argc, argv, "afhHn:ot:e:T:Vv0123456789",
+  while ((optc = getopt_long (argc, argv, "afhHn:wot:e:T:Vv0123456789",
 			      long_options, (int *) 0)) != EOF)
     {
       switch (optc)
@@ -183,6 +194,10 @@ main (int argc, char **argv)
 	    fatal (_("invalid integer argument %s"), optarg);
 	  break;
 
+	case 'w':
+	  include_all_whitespace = TRUE;
+	  break;
+
 	case 'o':
 	  print_addresses = TRUE;
 	  address_radix = 8;
@@ -639,6 +654,7 @@ usage (FILE *stream, int status)
   -n --bytes=[number]       Locate & print any NUL-terminated sequence of at\n\
   -<number>                   least [number] characters (default 4).\n\
   -t --radix={o,d,x}        Print the location of the string in base 8, 10 or 16\n\
+  -w --include-all-whitespace Include all whitespace as valid string characters\n\
   -o                        An alias for --radix=o\n\
   -T --target=<BFDNAME>     Specify the binary file format\n\
   -e --encoding={s,S,b,l,B,L} Select character size and endianness:\n\
-- 
1.9.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] strings: Add --include-all-whitespace option
  2014-06-19  3:11 [PATCH] strings: Add --include-all-whitespace option Erik Ackermann
@ 2014-06-26 13:12 ` Nicholas Clifton
  0 siblings, 0 replies; 2+ messages in thread
From: Nicholas Clifton @ 2014-06-26 13:12 UTC (permalink / raw)
  To: Erik Ackermann, binutils

Hi Erik,

> This patch adds an option to allow all whitespace to be considered a
> valid "string", not just the space character covered in ISPRINT and
> the TAB character which is special cased.

I have applied your patch.  There was one thing missing however - 
documentation.  So I have also patched the binutils/NEWS and 
binutils/doc/binutils.texi files to mention this new feature.

Cheers
   Nick


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-06-26 13:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-19  3:11 [PATCH] strings: Add --include-all-whitespace option Erik Ackermann
2014-06-26 13:12 ` Nicholas Clifton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).