Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/coreutils/catv.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/coreutils/catv.c
r821 r1770 11 11 * http://cm.bell-labs.com/cm/cs/doc/84/kp.ps.gz */ 12 12 13 #include "busybox.h" 14 #include <unistd.h> 15 #include <fcntl.h> 13 #include "libbb.h" 16 14 15 int catv_main(int argc, char **argv); 17 16 int catv_main(int argc, char **argv) 18 17 { 19 int retval = EXIT_SUCCESS, fd, flags; 18 int retval = EXIT_SUCCESS; 19 int fd; 20 unsigned flags; 20 21 21 flags = bb_getopt_ulflags(argc, argv, "etv"); 22 flags ^= 4; 22 flags = getopt32(argv, "etv"); 23 #define CATV_OPT_e (1<<0) 24 #define CATV_OPT_t (1<<1) 25 #define CATV_OPT_v (1<<2) 26 flags ^= CATV_OPT_v; 27 argv += optind; 23 28 24 // Loop through files. 25 26 argv += optind; 29 /* Read from stdin if there's nothing else to do. */ 30 fd = 0; 31 if (!argv[0]) { 32 argv--; 33 goto jump_in; 34 } 27 35 do { 28 // Read from stdin if there's nothing else to do. 29 30 fd = 0; 31 if (*argv && 0>(fd = bb_xopen(*argv, O_RDONLY))) retval = EXIT_FAILURE; 32 else for(;;) { 36 fd = open_or_warn(*argv, O_RDONLY); 37 if (fd < 0) { 38 retval = EXIT_FAILURE; 39 continue; 40 } 41 jump_in: 42 for (;;) { 33 43 int i, res; 34 44 35 res = read(fd, bb_common_bufsiz1, sizeof(bb_common_bufsiz1)); 36 if (res < 0) retval = EXIT_FAILURE; 37 if (res <1) break; 38 for (i=0; i<res; i++) { 39 char c=bb_common_bufsiz1[i]; 45 #define read_buf bb_common_bufsiz1 46 res = read(fd, read_buf, COMMON_BUFSIZE); 47 if (res < 0) 48 retval = EXIT_FAILURE; 49 if (res < 1) 50 break; 51 for (i = 0; i < res; i++) { 52 unsigned char c = read_buf[i]; 40 53 41 if (c > 126 && (flags & 4)) {54 if (c > 126 && (flags & CATV_OPT_v)) { 42 55 if (c == 127) { 43 56 printf("^?"); 44 57 continue; 45 } else {46 printf("M-");47 c -= 128;48 58 } 59 printf("M-"); 60 c -= 128; 49 61 } 50 62 if (c < 32) { 51 63 if (c == 10) { 52 if (flags & 1) putchar('$'); 53 } else if (flags & (c==9 ? 2 : 4)) { 64 if (flags & CATV_OPT_e) 65 putchar('$'); 66 } else if (flags & (c==9 ? CATV_OPT_t : CATV_OPT_v)) { 54 67 printf("^%c", c+'@'); 55 68 continue; … … 59 72 } 60 73 } 61 if (ENABLE_FEATURE_CLEAN_UP && fd) close(fd); 74 if (ENABLE_FEATURE_CLEAN_UP && fd) 75 close(fd); 62 76 } while (*++argv); 63 77 64 return retval;78 fflush_stdout_and_exit(retval); 65 79 }
Note:
See TracChangeset
for help on using the changeset viewer.