Skip to content

Commit 55edd97

Browse files
domohawknickclifton
authored andcommitted
Adds an option to the strings program to specify a separator between the emitted pieces of text.
* strings.c: Add -s/--output-separator option to specify custom separator string. * NEWS: Mention the new feature. * doc/binutils.text (strings): Document the new command line option.
1 parent 3f263e4 commit 55edd97

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

binutils/ChangeLog

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2015-09-10 Erik Ackermann <[email protected]>
2+
3+
* strings.c: Add -s/--output-separator option to specify custom
4+
separator string.
5+
* NEWS: Mention the new feature.
6+
* doc/binutils.text (strings): Document the new command line
7+
option.
8+
19
2015-09-09 Nick Clifton <[email protected]>
210

311
* doc/binutils.texi (ar): Remove bogus sentance concerning thin

binutils/NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
* Add --update-section option to objcopy.
88

9+
* Add --output-separator option to strings.
10+
911
Changes in 2.25:
1012

1113
* Add --data option to strings to only print strings in loadable, initialized

binutils/doc/binutils.texi

+8
Original file line numberDiff line numberDiff line change
@@ -2790,6 +2790,7 @@ strings [@option{-afovV}] [@option{-}@var{min-len}]
27902790
[@option{-}] [@option{--all}] [@option{--print-file-name}]
27912791
[@option{-T} @var{bfdname}] [@option{--target=}@var{bfdname}]
27922792
[@option{-w}] [@option{--include-all-whitespace}]
2793+
[@option{-s}] [@option{--output-separator}@var{sep_string}]
27932794
[@option{--help}] [@option{--version}] @var{file}@dots{}
27942795
@c man end
27952796
@end smallexample
@@ -2894,6 +2895,13 @@ By default tab and space characters are included in the strings that
28942895
are displayed, but other whitespace characters, such a newlines and
28952896
carriage returns, are not. The @option{-w} option changes this so
28962897
that all whitespace characters are considered to be part of a string.
2898+
2899+
@item -s
2900+
@itemx --output-separator
2901+
By default, output strings are delimited by a new-line. This option
2902+
allows you to supply any string to be used as the output record
2903+
separator. Useful with --include-all-whitespace where strings
2904+
may contain new-lines internally.
28972905
@end table
28982906

28992907
@c man end

binutils/strings.c

+19-2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
-T {bfdname}
5656
Specify a non-default object file format.
5757
58+
--output-separator=sep_string
59+
-s sep_string String used to separate parsed strings in output.
60+
Default is newline.
61+
5862
--help
5963
-h Print the usage message on the standard output.
6064
@@ -114,6 +118,9 @@ static char *target;
114118
static char encoding;
115119
static int encoding_bytes;
116120

121+
/* Output string used to separate parsed strings */
122+
static char *output_separator;
123+
117124
static struct option long_options[] =
118125
{
119126
{"all", no_argument, NULL, 'a'},
@@ -124,6 +131,7 @@ static struct option long_options[] =
124131
{"include-all-whitespace", required_argument, NULL, 'w'},
125132
{"encoding", required_argument, NULL, 'e'},
126133
{"target", required_argument, NULL, 'T'},
134+
{"output-separator", required_argument, NULL, 's'},
127135
{"help", no_argument, NULL, 'h'},
128136
{"version", no_argument, NULL, 'v'},
129137
{NULL, 0, NULL, 0}
@@ -178,8 +186,9 @@ main (int argc, char **argv)
178186
datasection_only = TRUE;
179187
target = NULL;
180188
encoding = 's';
189+
output_separator = NULL;
181190

182-
while ((optc = getopt_long (argc, argv, "adfhHn:wot:e:T:Vv0123456789",
191+
while ((optc = getopt_long (argc, argv, "adfhHn:wot:e:T:s:Vv0123456789",
183192
long_options, (int *) 0)) != EOF)
184193
{
185194
switch (optc)
@@ -248,6 +257,10 @@ main (int argc, char **argv)
248257
encoding = optarg[0];
249258
break;
250259

260+
case 's':
261+
output_separator = optarg;
262+
break;
263+
251264
case 'V':
252265
case 'v':
253266
print_version ("strings");
@@ -650,7 +663,10 @@ print_strings (const char *filename, FILE *stream, file_ptr address,
650663
putchar (c);
651664
}
652665

653-
putchar ('\n');
666+
if (output_separator)
667+
fputs (output_separator, stdout);
668+
else
669+
putchar ('\n');
654670
}
655671
free (buf);
656672
}
@@ -681,6 +697,7 @@ usage (FILE *stream, int status)
681697
-T --target=<BFDNAME> Specify the binary file format\n\
682698
-e --encoding={s,S,b,l,B,L} Select character size and endianness:\n\
683699
s = 7-bit, S = 8-bit, {b,l} = 16-bit, {B,L} = 32-bit\n\
700+
-s --output-separator=<string> String used to separate strings in output.\n\
684701
@<file> Read options from <file>\n\
685702
-h --help Display this information\n\
686703
-v -V --version Print the program's version number\n"));

0 commit comments

Comments
 (0)