This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] strings: Add separator option to allow custom string to separate output records


Not sure if this is the right/best place to send patches, but here's one.

Erik
From 61c652ee6ce09abbb70a9e12e65d87f72c07ea95 Mon Sep 17 00:00:00 2001
From: Erik Ackermann <kurterikackermann@gmail.com>
Date: Wed, 18 Jun 2014 19:30:08 -0700
Subject: [PATCH] Add --separator option to allow a custom string as record
 separator.

---
 binutils/strings.c | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/binutils/strings.c b/binutils/strings.c
index bb00d41..0265511 100644
--- a/binutils/strings.c
+++ b/binutils/strings.c
@@ -48,6 +48,10 @@
    -T {bfdname}
 		Specify a non-default object file format.
 
+  --separator=sep_string
+  -s sep_string	String used to separate parsed strings in output.
+		Default is newline.
+
    --help
    -h		Print the usage message on the standard output.
 
@@ -102,6 +106,9 @@ static char *target;
 static char encoding;
 static int encoding_bytes;
 
+/* Output string used to separate parsed strings  */
+static char *separator;
+
 static struct option long_options[] =
 {
   {"all", no_argument, NULL, 'a'},
@@ -110,6 +117,7 @@ static struct option long_options[] =
   {"radix", required_argument, NULL, 't'},
   {"encoding", required_argument, NULL, 'e'},
   {"target", required_argument, NULL, 'T'},
+  {"separator", required_argument, NULL, 's'},
   {"help", no_argument, NULL, 'h'},
   {"version", no_argument, NULL, 'v'},
   {NULL, 0, NULL, 0}
@@ -159,8 +167,9 @@ main (int argc, char **argv)
   datasection_only = TRUE;
   target = NULL;
   encoding = 's';
+  separator = NULL;
 
-  while ((optc = getopt_long (argc, argv, "afhHn:ot:e:T:Vv0123456789",
+  while ((optc = getopt_long (argc, argv, "afhHn:ot:e:T:s:Vv0123456789",
 			      long_options, (int *) 0)) != EOF)
     {
       switch (optc)
@@ -221,6 +230,10 @@ main (int argc, char **argv)
 	  encoding = optarg[0];
 	  break;
 
+	case 's':
+	  separator = optarg;
+          break;
+
 	case 'V':
 	case 'v':
 	  print_version ("strings");
@@ -307,12 +320,12 @@ strings_a_section (bfd *abfd, asection *sect, void *arg)
   bfd_size_type *filesizep;
   bfd_size_type sectsize;
   void *mem;
-     
+
   if ((sect->flags & DATA_FLAGS) != DATA_FLAGS)
     return;
 
   sectsize = bfd_get_section_size (sect);
-     
+
   if (sectsize <= 0)
     return;
 
@@ -323,7 +336,7 @@ strings_a_section (bfd *abfd, asection *sect, void *arg)
   if (*filesizep == 0)
     {
       struct stat st;
-      
+
       if (bfd_stat (abfd, &st))
 	return;
 
@@ -623,7 +636,10 @@ print_strings (const char *filename, FILE *stream, file_ptr address,
 	  putchar (c);
 	}
 
-      putchar ('\n');
+      if (separator)
+        fputs(separator, stdout);
+      else
+        putchar ('\n');
     }
   free (buf);
 }
@@ -643,6 +659,7 @@ usage (FILE *stream, int status)
   -T --target=<BFDNAME>     Specify the binary file format\n\
   -e --encoding={s,S,b,l,B,L} Select character size and endianness:\n\
                             s = 7-bit, S = 8-bit, {b,l} = 16-bit, {B,L} = 32-bit\n\
+  -s --separator=<sep_string) String used to separate parsed strings in output.\n\
   @<file>                   Read options from <file>\n\
   -h --help                 Display this information\n\
   -v -V --version           Print the program's version number\n"));
-- 
1.9.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]