summaryrefslogtreecommitdiff
path: root/miscutils/strings.c
diff options
context:
space:
mode:
authorDenis Vlasenko2007-06-17 12:19:07 +0000
committerDenis Vlasenko2007-06-17 12:19:07 +0000
commit787d92645b516257de2aa726580f66774a3be163 (patch)
treec358430b9b10abac096cd17629531982a86b2b74 /miscutils/strings.c
parentea9e798004ab2c4022ccb54c2d8effbe25b7b122 (diff)
downloadbusybox-787d92645b516257de2aa726580f66774a3be163.zip
busybox-787d92645b516257de2aa726580f66774a3be163.tar.gz
strings: strings a b was processing a twice, fix that
Diffstat (limited to 'miscutils/strings.c')
-rw-r--r--miscutils/strings.c69
1 files changed, 35 insertions, 34 deletions
diff --git a/miscutils/strings.c b/miscutils/strings.c
index eff1bd9..f0ef2a2 100644
--- a/miscutils/strings.c
+++ b/miscutils/strings.c
@@ -19,9 +19,10 @@
int strings_main(int argc, char **argv);
int strings_main(int argc, char **argv)
{
- int n, c, i = 0, status = EXIT_SUCCESS;
+ int n, c, status = EXIT_SUCCESS;
unsigned opt;
- unsigned long count;
+ unsigned count;
+ off_t offset;
FILE *file = stdin;
char *string;
const char *fmt = "%s: ";
@@ -29,56 +30,56 @@ int strings_main(int argc, char **argv)
opt = getopt32(argc, argv, "afon:", &n_arg);
/* -a is our default behaviour */
-
- argc -= optind;
+ /*argc -= optind;*/
argv += optind;
- n = xatoul_range(n_arg, 1, INT_MAX);
+ n = xatou_range(n_arg, 1, INT_MAX);
string = xzalloc(n + 1);
n--;
- if (argc == 0) {
+ if (!*argv) {
fmt = "{%s}: ";
- *argv = (char *)bb_msg_standard_input;
+ *--argv = (char *)bb_msg_standard_input;
goto PIPE;
}
do {
file = fopen_or_warn(*argv, "r");
- if (file) {
-PIPE:
- count = 0;
- do {
- c = fgetc(file);
- if (isprint(c) || c == '\t') {
- if (i <= n) {
- string[i] = c;
- } else {
- putchar(c);
- }
- if (i == n) {
+ if (!file) {
+ status = EXIT_FAILURE;
+ continue;
+ }
+ PIPE:
+ offset = 0;
+ count = 0;
+ do {
+ c = fgetc(file);
+ if (isprint(c) || c == '\t') {
+ if (count > n) {
+ putchar(c);
+ } else {
+ string[count] = c;
+ if (count == n) {
if (opt & PRINT_NAME) {
printf(fmt, *argv);
}
if (opt & PRINT_OFFSET) {
- printf("%7lo ", count - n);
+ printf("%7"OFF_FMT"o ", offset - n);
}
- printf("%s", string);
+ fputs(string, stdout);
}
- i++;
- } else {
- if (i > n) {
- putchar('\n');
- }
- i = 0;
+ count++;
}
- count++;
- } while (c != EOF);
- fclose_if_not_stdin(file);
- } else {
- status = EXIT_FAILURE;
- }
- } while (--argc > 0);
+ } else {
+ if (count > n) {
+ putchar('\n');
+ }
+ count = 0;
+ }
+ offset++;
+ } while (c != EOF);
+ fclose_if_not_stdin(file);
+ } while (*++argv);
if (ENABLE_FEATURE_CLEAN_UP)
free(string);