Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/coreutils/fold.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/coreutils/fold.c
r821 r1770 1 /* vi: set sw=4 ts=4: */ 1 2 /* fold -- wrap each input line to fit in specified width. 2 3 … … 10 11 */ 11 12 12 #include <ctype.h> 13 #include <errno.h> 14 #include <stdio.h> 15 #include <stdlib.h> 16 #include <string.h> 17 #include <sys/types.h> 18 #include <unistd.h> 19 #include "busybox.h" 13 #include "libbb.h" 20 14 21 15 static unsigned long flags; … … 45 39 } 46 40 41 int fold_main(int argc, char **argv); 47 42 int fold_main(int argc, char **argv) 48 43 { 44 char *line_out = NULL; 45 int allocated_out = 0; 49 46 char *w_opt; 50 47 int width = 80; … … 52 49 int errs = 0; 53 50 54 if (!ENABLE_DEBUG_YANK_SUSv2) {51 if (ENABLE_INCLUDE_SUSv2) { 55 52 /* Turn any numeric options into -w options. */ 56 53 for (i = 1; i < argc; i++) { … … 61 58 break; 62 59 if (isdigit(*a)) { 63 argv[i] = bb_xasprintf("-w%s", a);60 argv[i] = xasprintf("-w%s", a); 64 61 } 65 62 } … … 67 64 } 68 65 69 flags = bb_getopt_ulflags(argc,argv, "bsw:", &w_opt);66 flags = getopt32(argv, "bsw:", &w_opt); 70 67 if (flags & FLAG_WIDTH) 71 width = bb_xgetlarg(w_opt, 10, 1, 10000);68 width = xatoul_range(w_opt, 1, 10000); 72 69 73 70 argv += optind; 74 71 if (!*argv) { 75 *--argv = "-";72 *--argv = (char*)"-"; 76 73 } 77 74 78 75 do { 79 FILE *istream = bb_wfopen_input(*argv);76 FILE *istream = fopen_or_warn_stdin(*argv); 80 77 int c; 81 78 int column = 0; /* Screen column where next char will go. */ 82 79 int offset_out = 0; /* Index in `line_out' for next char. */ 83 static char *line_out = NULL;84 static int allocated_out = 0;85 80 86 81 if (istream == NULL) { … … 101 96 continue; 102 97 } 103 104 rescan: 98 rescan: 105 99 column = adjust_column(column, c); 106 100 … … 151 145 } 152 146 153 if (ferror(istream) || bb_fclose_nonstdin(istream)) {147 if (ferror(istream) || fclose_if_not_stdin(istream)) { 154 148 bb_perror_msg("%s", *argv); /* Avoid multibyte problems. */ 155 149 errs |= EXIT_FAILURE; … … 157 151 } while (*++argv); 158 152 159 bb_fflush_stdout_and_exit(errs);153 fflush_stdout_and_exit(errs); 160 154 } 161 /* vi: set sw=4 ts=4: */
Note:
See TracChangeset
for help on using the changeset viewer.