Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/coreutils/catv.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/coreutils/catv.c
r3232 r3621 20 20 21 21 #include "libbb.h" 22 #include "common_bufsiz.h" 23 24 #define CATV_OPT_e (1<<0) 25 #define CATV_OPT_t (1<<1) 26 #define CATV_OPT_v (1<<2) 27 struct BUG_const_mismatch { 28 char BUG_const_mismatch[ 29 CATV_OPT_e == VISIBLE_ENDLINE && CATV_OPT_t == VISIBLE_SHOW_TABS 30 ? 1 : -1 31 ]; 32 }; 22 33 23 34 int catv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; … … 26 37 int retval = EXIT_SUCCESS; 27 38 int fd; 28 unsigned flags; 29 30 flags = getopt32(argv, "etv"); 31 #define CATV_OPT_e (1<<0) 32 #define CATV_OPT_t (1<<1) 33 #define CATV_OPT_v (1<<2) 34 flags ^= CATV_OPT_v; 39 unsigned opts; 40 opts = getopt32(argv, "etv"); 35 41 argv += optind; 42 #if 0 /* These consts match, we can just pass "opts" to visible() */ 43 if (opts & CATV_OPT_e) 44 flags |= VISIBLE_ENDLINE; 45 if (opts & CATV_OPT_t) 46 flags |= VISIBLE_SHOW_TABS; 47 #endif 36 48 37 49 /* Read from stdin if there's nothing else to do. */ 38 50 if (!argv[0]) 39 51 *--argv = (char*)"-"; 52 53 #define read_buf bb_common_bufsiz1 54 setup_common_bufsiz(); 40 55 do { 41 56 fd = open_or_warn_stdin(*argv); … … 47 62 int i, res; 48 63 49 #define read_buf bb_common_bufsiz150 64 res = read(fd, read_buf, COMMON_BUFSIZE); 51 65 if (res < 0) 52 66 retval = EXIT_FAILURE; 53 if (res < 1)67 if (res <= 0) 54 68 break; 55 69 for (i = 0; i < res; i++) { 56 70 unsigned char c = read_buf[i]; 57 58 if (c > 126 && (flags & CATV_OPT_v)) { 59 if (c == 127) { 60 printf("^?"); 61 continue; 62 } 63 printf("M-"); 64 c -= 128; 71 if (opts & CATV_OPT_v) { 72 putchar(c); 73 } else { 74 char buf[sizeof("M-^c")]; 75 visible(c, buf, opts); 76 fputs(buf, stdout); 65 77 } 66 if (c < 32) {67 if (c == 10) {68 if (flags & CATV_OPT_e)69 bb_putchar('$');70 } else if (flags & (c==9 ? CATV_OPT_t : CATV_OPT_v)) {71 printf("^%c", c+'@');72 continue;73 }74 }75 bb_putchar(c);76 78 } 77 79 }
Note:
See TracChangeset
for help on using the changeset viewer.