1 /* vi: set sw=4 ts=4: */
3 * strings implementation for busybox
5 * Copyright 2003 Tito Ragusa <farmatito@tiscali.it>
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
10 //usage:#define strings_trivial_usage
11 //usage: "[-afo] [-n LEN] [FILE]..."
12 //usage:#define strings_full_usage "\n\n"
13 //usage: "Display printable strings in a binary file\n"
14 //usage: "\n -a Scan whole file (default)"
15 //usage: "\n -f Precede strings with filenames"
16 //usage: "\n -n LEN At least LEN characters form a string (default 4)"
17 //usage: "\n -o Precede strings with decimal offsets"
23 #define PRINT_OFFSET 4
26 int strings_main(int argc
, char **argv
) MAIN_EXTERNALLY_VISIBLE
;
27 int strings_main(int argc UNUSED_PARAM
, char **argv
)
29 int n
, c
, status
= EXIT_SUCCESS
;
34 const char *fmt
= "%s: ";
35 const char *n_arg
= "4";
37 getopt32(argv
, "afon:", &n_arg
);
38 /* -a is our default behaviour */
42 n
= xatou_range(n_arg
, 1, INT_MAX
);
43 string
= xzalloc(n
+ 1);
48 *--argv
= (char *)bb_msg_standard_input
;
52 file
= fopen_or_warn_stdin(*argv
);
54 status
= EXIT_FAILURE
;
61 if (isprint_asciionly(c
) || c
== '\t') {
67 if (option_mask32
& PRINT_NAME
) {
70 if (option_mask32
& PRINT_OFFSET
) {
71 printf("%7"OFF_FMT
"o ", offset
- n
);
73 fputs(string
, stdout
);
85 fclose_if_not_stdin(file
);
88 if (ENABLE_FEATURE_CLEAN_UP
)
91 fflush_stdout_and_exit(status
);