source: MondoRescue/branches/2.2.9/mindi-busybox/miscutils/strings.c@ 2870

Last change on this file since 2870 was 2725, checked in by Bruno Cornec, 13 years ago
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File size: 1.6 KB
RevLine 
[821]1/* vi: set sw=4 ts=4: */
2/*
3 * strings implementation for busybox
4 *
[2725]5 * Copyright 2003 Tito Ragusa <farmatito@tiscali.it>
[821]6 *
[2725]7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
[821]8 */
9
[1765]10#include "libbb.h"
11
[2725]12#define WHOLE_FILE 1
13#define PRINT_NAME 2
14#define PRINT_OFFSET 4
15#define SIZE 8
[821]16
[2725]17int strings_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
18int strings_main(int argc UNUSED_PARAM, char **argv)
[821]19{
[1765]20 int n, c, status = EXIT_SUCCESS;
21 unsigned count;
22 off_t offset;
[2725]23 FILE *file;
[821]24 char *string;
25 const char *fmt = "%s: ";
[1765]26 const char *n_arg = "4";
[821]27
[2725]28 getopt32(argv, "afon:", &n_arg);
[821]29 /* -a is our default behaviour */
[1765]30 /*argc -= optind;*/
[821]31 argv += optind;
32
[1765]33 n = xatou_range(n_arg, 1, INT_MAX);
[821]34 string = xzalloc(n + 1);
35 n--;
36
[1765]37 if (!*argv) {
[821]38 fmt = "{%s}: ";
[1765]39 *--argv = (char *)bb_msg_standard_input;
[821]40 }
41
42 do {
[2725]43 file = fopen_or_warn_stdin(*argv);
[1765]44 if (!file) {
45 status = EXIT_FAILURE;
46 continue;
47 }
48 offset = 0;
49 count = 0;
50 do {
51 c = fgetc(file);
[2725]52 if (isprint_asciionly(c) || c == '\t') {
[1765]53 if (count > n) {
[2725]54 bb_putchar(c);
[1765]55 } else {
56 string[count] = c;
57 if (count == n) {
[2725]58 if (option_mask32 & PRINT_NAME) {
[821]59 printf(fmt, *argv);
60 }
[2725]61 if (option_mask32 & PRINT_OFFSET) {
[1765]62 printf("%7"OFF_FMT"o ", offset - n);
[821]63 }
[1765]64 fputs(string, stdout);
[821]65 }
[1765]66 count++;
[821]67 }
[1765]68 } else {
69 if (count > n) {
[2725]70 bb_putchar('\n');
[1765]71 }
72 count = 0;
73 }
74 offset++;
75 } while (c != EOF);
76 fclose_if_not_stdin(file);
77 } while (*++argv);
[821]78
79 if (ENABLE_FEATURE_CLEAN_UP)
80 free(string);
81
[1765]82 fflush_stdout_and_exit(status);
[821]83}
Note: See TracBrowser for help on using the repository browser.