diff options
| author | Ron Yorston <rmy@pobox.com> | 2016-10-26 10:32:18 +0100 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2016-10-26 10:32:18 +0100 |
| commit | 94eac583b29d56a28bf18d41f56ecb2a9d0bd336 (patch) | |
| tree | ff7f398db61a851d5e0af51a92004207707acfab /miscutils | |
| parent | 418f43bea899493bb70a6eec6429b3de412be6e7 (diff) | |
| parent | a513bf3c3ce0756c991b21c0ca271e24fedcdb51 (diff) | |
| download | busybox-w32-94eac583b29d56a28bf18d41f56ecb2a9d0bd336.tar.gz busybox-w32-94eac583b29d56a28bf18d41f56ecb2a9d0bd336.tar.bz2 busybox-w32-94eac583b29d56a28bf18d41f56ecb2a9d0bd336.zip | |
Merge branch 'busybox' into merge
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/strings.c | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/miscutils/strings.c b/miscutils/strings.c index 9f5018244..ee6649625 100644 --- a/miscutils/strings.c +++ b/miscutils/strings.c | |||
| @@ -8,13 +8,16 @@ | |||
| 8 | */ | 8 | */ |
| 9 | 9 | ||
| 10 | //usage:#define strings_trivial_usage | 10 | //usage:#define strings_trivial_usage |
| 11 | //usage: "[-afo] [-n LEN] [FILE]..." | 11 | //usage: "[-fo] [-t o/d/x] [-n LEN] [FILE]..." |
| 12 | //usage:#define strings_full_usage "\n\n" | 12 | //usage:#define strings_full_usage "\n\n" |
| 13 | //usage: "Display printable strings in a binary file\n" | 13 | //usage: "Display printable strings in a binary file\n" |
| 14 | //usage: "\n -a Scan whole file (default)" | 14 | //We usually don't bother user with "nop" options. They work, but are not shown: |
| 15 | //usage: "\n -f Precede strings with filenames" | 15 | ////usage: "\n -a Scan whole file (default)" |
| 16 | //usage: "\n -n LEN At least LEN characters form a string (default 4)" | 16 | //unimplemented alternative is -d: Only strings from initialized, loaded data sections |
| 17 | //usage: "\n -o Precede strings with decimal offsets" | 17 | //usage: "\n -f Precede strings with filenames" |
| 18 | //usage: "\n -o Precede strings with octal offsets" | ||
| 19 | //usage: "\n -t o/d/x Precede strings with offsets in base 8/10/16" | ||
| 20 | //usage: "\n -n LEN At least LEN characters form a string (default 4)" | ||
| 18 | 21 | ||
| 19 | #include "libbb.h" | 22 | #include "libbb.h" |
| 20 | 23 | ||
| @@ -22,6 +25,7 @@ | |||
| 22 | #define PRINT_NAME 2 | 25 | #define PRINT_NAME 2 |
| 23 | #define PRINT_OFFSET 4 | 26 | #define PRINT_OFFSET 4 |
| 24 | #define SIZE 8 | 27 | #define SIZE 8 |
| 28 | #define PRINT_RADIX 16 | ||
| 25 | 29 | ||
| 26 | int strings_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 30 | int strings_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 27 | int strings_main(int argc UNUSED_PARAM, char **argv) | 31 | int strings_main(int argc UNUSED_PARAM, char **argv) |
| @@ -33,8 +37,11 @@ int strings_main(int argc UNUSED_PARAM, char **argv) | |||
| 33 | char *string; | 37 | char *string; |
| 34 | const char *fmt = "%s: "; | 38 | const char *fmt = "%s: "; |
| 35 | const char *n_arg = "4"; | 39 | const char *n_arg = "4"; |
| 40 | /* default for -o */ | ||
| 41 | const char *radix = "o"; | ||
| 42 | char *radix_fmt; | ||
| 36 | 43 | ||
| 37 | getopt32(argv, "afon:", &n_arg); | 44 | getopt32(argv, "afon:t:", &n_arg, &radix); |
| 38 | /* -a is our default behaviour */ | 45 | /* -a is our default behaviour */ |
| 39 | /*argc -= optind;*/ | 46 | /*argc -= optind;*/ |
| 40 | argv += optind; | 47 | argv += optind; |
| @@ -43,6 +50,11 @@ int strings_main(int argc UNUSED_PARAM, char **argv) | |||
| 43 | string = xzalloc(n + 1); | 50 | string = xzalloc(n + 1); |
| 44 | n--; | 51 | n--; |
| 45 | 52 | ||
| 53 | if ((radix[0] != 'd' && radix[0] != 'o' && radix[0] != 'x') || radix[1] != 0) | ||
| 54 | bb_show_usage(); | ||
| 55 | |||
| 56 | radix_fmt = xasprintf("%%7"OFF_FMT"%s ", radix); | ||
| 57 | |||
| 46 | if (!*argv) { | 58 | if (!*argv) { |
| 47 | fmt = "{%s}: "; | 59 | fmt = "{%s}: "; |
| 48 | *--argv = (char *)bb_msg_standard_input; | 60 | *--argv = (char *)bb_msg_standard_input; |
| @@ -67,8 +79,8 @@ int strings_main(int argc UNUSED_PARAM, char **argv) | |||
| 67 | if (option_mask32 & PRINT_NAME) { | 79 | if (option_mask32 & PRINT_NAME) { |
| 68 | printf(fmt, *argv); | 80 | printf(fmt, *argv); |
| 69 | } | 81 | } |
| 70 | if (option_mask32 & PRINT_OFFSET) { | 82 | if (option_mask32 & (PRINT_OFFSET | PRINT_RADIX)) { |
| 71 | printf("%7"OFF_FMT"o ", offset - n); | 83 | printf(radix_fmt, offset - n); |
| 72 | } | 84 | } |
| 73 | fputs(string, stdout); | 85 | fputs(string, stdout); |
| 74 | } | 86 | } |
| @@ -85,8 +97,10 @@ int strings_main(int argc UNUSED_PARAM, char **argv) | |||
| 85 | fclose_if_not_stdin(file); | 97 | fclose_if_not_stdin(file); |
| 86 | } while (*++argv); | 98 | } while (*++argv); |
| 87 | 99 | ||
| 88 | if (ENABLE_FEATURE_CLEAN_UP) | 100 | if (ENABLE_FEATURE_CLEAN_UP) { |
| 89 | free(string); | 101 | free(string); |
| 102 | free(radix_fmt); | ||
| 103 | } | ||
| 90 | 104 | ||
| 91 | fflush_stdout_and_exit(status); | 105 | fflush_stdout_and_exit(status); |
| 92 | } | 106 | } |
