Annotation of /trunk/mkinitrd-magellan/busybox/miscutils/strings.c
Parent Directory | Revision Log
Revision 984 -
(hide annotations)
(download)
Sun May 30 11:32:42 2010 UTC (13 years, 11 months ago) by niro
File MIME type: text/plain
File size: 1612 byte(s)
Sun May 30 11:32:42 2010 UTC (13 years, 11 months ago) by niro
File MIME type: text/plain
File size: 1612 byte(s)
-updated to busybox-1.16.1 and enabled blkid/uuid support in default config
1 | niro | 532 | /* vi: set sw=4 ts=4: */ |
2 | /* | ||
3 | * strings implementation for busybox | ||
4 | * | ||
5 | niro | 984 | * Copyright 2003 Tito Ragusa <farmatito@tiscali.it> |
6 | niro | 532 | * |
7 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. | ||
8 | */ | ||
9 | |||
10 | niro | 816 | #include "libbb.h" |
11 | niro | 532 | |
12 | #define WHOLE_FILE 1 | ||
13 | #define PRINT_NAME 2 | ||
14 | #define PRINT_OFFSET 4 | ||
15 | #define SIZE 8 | ||
16 | |||
17 | niro | 816 | int strings_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
18 | int strings_main(int argc UNUSED_PARAM, char **argv) | ||
19 | niro | 532 | { |
20 | niro | 816 | int n, c, status = EXIT_SUCCESS; |
21 | unsigned count; | ||
22 | off_t offset; | ||
23 | FILE *file; | ||
24 | niro | 532 | char *string; |
25 | const char *fmt = "%s: "; | ||
26 | niro | 816 | const char *n_arg = "4"; |
27 | niro | 532 | |
28 | niro | 984 | getopt32(argv, "afon:", &n_arg); |
29 | niro | 532 | /* -a is our default behaviour */ |
30 | niro | 816 | /*argc -= optind;*/ |
31 | niro | 532 | argv += optind; |
32 | |||
33 | niro | 816 | n = xatou_range(n_arg, 1, INT_MAX); |
34 | niro | 532 | string = xzalloc(n + 1); |
35 | n--; | ||
36 | |||
37 | niro | 816 | if (!*argv) { |
38 | niro | 532 | fmt = "{%s}: "; |
39 | niro | 816 | *--argv = (char *)bb_msg_standard_input; |
40 | niro | 532 | } |
41 | |||
42 | do { | ||
43 | niro | 816 | file = fopen_or_warn_stdin(*argv); |
44 | if (!file) { | ||
45 | status = EXIT_FAILURE; | ||
46 | continue; | ||
47 | } | ||
48 | offset = 0; | ||
49 | count = 0; | ||
50 | do { | ||
51 | c = fgetc(file); | ||
52 | niro | 984 | if (isprint_asciionly(c) || c == '\t') { |
53 | niro | 816 | if (count > n) { |
54 | bb_putchar(c); | ||
55 | } else { | ||
56 | string[count] = c; | ||
57 | if (count == n) { | ||
58 | niro | 984 | if (option_mask32 & PRINT_NAME) { |
59 | niro | 532 | printf(fmt, *argv); |
60 | } | ||
61 | niro | 984 | if (option_mask32 & PRINT_OFFSET) { |
62 | niro | 816 | printf("%7"OFF_FMT"o ", offset - n); |
63 | niro | 532 | } |
64 | niro | 816 | fputs(string, stdout); |
65 | niro | 532 | } |
66 | niro | 816 | count++; |
67 | niro | 532 | } |
68 | niro | 816 | } else { |
69 | if (count > n) { | ||
70 | bb_putchar('\n'); | ||
71 | } | ||
72 | count = 0; | ||
73 | } | ||
74 | offset++; | ||
75 | } while (c != EOF); | ||
76 | fclose_if_not_stdin(file); | ||
77 | } while (*++argv); | ||
78 | niro | 532 | |
79 | if (ENABLE_FEATURE_CLEAN_UP) | ||
80 | free(string); | ||
81 | |||
82 | fflush_stdout_and_exit(status); | ||
83 | } |