2 |
/* |
/* |
3 |
* strings implementation for busybox |
* strings implementation for busybox |
4 |
* |
* |
5 |
* Copyright Tito Ragusa <farmatito@tiscali.it> |
* Copyright 2003 Tito Ragusa <farmatito@tiscali.it> |
6 |
* |
* |
7 |
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball. |
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball. |
8 |
*/ |
*/ |
18 |
int strings_main(int argc UNUSED_PARAM, char **argv) |
int strings_main(int argc UNUSED_PARAM, char **argv) |
19 |
{ |
{ |
20 |
int n, c, status = EXIT_SUCCESS; |
int n, c, status = EXIT_SUCCESS; |
|
unsigned opt; |
|
21 |
unsigned count; |
unsigned count; |
22 |
off_t offset; |
off_t offset; |
23 |
FILE *file; |
FILE *file; |
25 |
const char *fmt = "%s: "; |
const char *fmt = "%s: "; |
26 |
const char *n_arg = "4"; |
const char *n_arg = "4"; |
27 |
|
|
28 |
opt = getopt32(argv, "afon:", &n_arg); |
getopt32(argv, "afon:", &n_arg); |
29 |
/* -a is our default behaviour */ |
/* -a is our default behaviour */ |
30 |
/*argc -= optind;*/ |
/*argc -= optind;*/ |
31 |
argv += optind; |
argv += optind; |
49 |
count = 0; |
count = 0; |
50 |
do { |
do { |
51 |
c = fgetc(file); |
c = fgetc(file); |
52 |
if (isprint(c) || c == '\t') { |
if (isprint_asciionly(c) || c == '\t') { |
53 |
if (count > n) { |
if (count > n) { |
54 |
bb_putchar(c); |
bb_putchar(c); |
55 |
} else { |
} else { |
56 |
string[count] = c; |
string[count] = c; |
57 |
if (count == n) { |
if (count == n) { |
58 |
if (opt & PRINT_NAME) { |
if (option_mask32 & PRINT_NAME) { |
59 |
printf(fmt, *argv); |
printf(fmt, *argv); |
60 |
} |
} |
61 |
if (opt & PRINT_OFFSET) { |
if (option_mask32 & PRINT_OFFSET) { |
62 |
printf("%7"OFF_FMT"o ", offset - n); |
printf("%7"OFF_FMT"o ", offset - n); |
63 |
} |
} |
64 |
fputs(string, stdout); |
fputs(string, stdout); |