aboutsummaryrefslogtreecommitdiff
path: root/coreutils/catv.c
diff options
context:
space:
mode:
authoraldot <aldot@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-08-28 23:31:54 +0000
committeraldot <aldot@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-08-28 23:31:54 +0000
commitd52f45a484fc7fc049ab40db9adc6ead7ea9b122 (patch)
tree2a57564b8917a983365c765d4daa83032d9f0a17 /coreutils/catv.c
parent2803d256e9decd450b955c2846bf945db72bb79e (diff)
downloadbusybox-w32-d52f45a484fc7fc049ab40db9adc6ead7ea9b122.tar.gz
busybox-w32-d52f45a484fc7fc049ab40db9adc6ead7ea9b122.tar.bz2
busybox-w32-d52f45a484fc7fc049ab40db9adc6ead7ea9b122.zip
- pull from busybox_scratch: r15829:15850
Various fixes, cleanups and shrinkage: saves 952 Bytes: text data bss dec hex filename 1087742 15853 790632 1894227 1ce753 ../busybox/busybox.old 1086790 15853 790632 1893275 1ce39b busybox via: # scripts/bloat-o-meter ../busybox/busybox_unstripped.old busybox_unstripped function old new delta ipcrm_main 756 822 +66 getval - 61 +61 maybe_set_utc - 40 +40 udhcpc_main 2896 2912 +16 md5_hash_block 428 437 +9 opt 8 16 +8 qgravechar 106 110 +4 make_bitmap 292 295 +3 inflate_unzip 2056 2059 +3 add_partition 1412 1414 +2 __parsespent 156 158 +2 qrealloc 41 42 +1 format - 1 +1 catv_main 313 314 +1 watch_main 293 292 -1 varunset 81 80 -1 part 1 - -1 check_if_skip 837 836 -1 start_stop_daemon_main 840 837 -3 create_lost_and_found 175 172 -3 supress_non_delimited_lines 4 - -4 static.l 4 - -4 static.c 5 1 -4 bsd_sum_file 237 233 -4 eval2 338 332 -6 arithmetic_common 166 158 -8 cmpfunc 22 5 -17 cksum_main 294 275 -19 cmp_main 465 439 -26 dd_main 1535 1508 -27 rmmod_main 376 333 -43 cut_file 727 644 -83 ipcs_main 3809 3721 -88 cut_main 722 614 -108 date_main 1443 1263 -180 remove_ids 222 - -222 ------------------------------------------------------------------------------ (add/remove: 3/4 grow/shrink: 11/18 up/down: 217/-853) Total: -636 bytes git-svn-id: svn://busybox.net/trunk/busybox@16009 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'coreutils/catv.c')
-rw-r--r--coreutils/catv.c44
1 files changed, 25 insertions, 19 deletions
diff --git a/coreutils/catv.c b/coreutils/catv.c
index e18203915..f8229c20e 100644
--- a/coreutils/catv.c
+++ b/coreutils/catv.c
@@ -14,49 +14,55 @@
14 14
15int catv_main(int argc, char **argv) 15int catv_main(int argc, char **argv)
16{ 16{
17 int retval = EXIT_SUCCESS, fd, flags; 17 int retval = EXIT_SUCCESS, fd;
18 unsigned long flags;
18 19
19 flags = bb_getopt_ulflags(argc, argv, "etv"); 20 flags = bb_getopt_ulflags(argc, argv, "etv");
20 flags ^= 4; 21#define CATV_OPT_e (1<<0)
21 22#define CATV_OPT_t (1<<1)
22 // Loop through files. 23#define CATV_OPT_v (1<<2)
24 flags ^= CATV_OPT_v;
23 25
24 argv += optind; 26 argv += optind;
25 do { 27 do {
26 // Read from stdin if there's nothing else to do. 28 /* Read from stdin if there's nothing else to do. */
27
28 fd = 0; 29 fd = 0;
29 if (*argv && 0>(fd = xopen(*argv, O_RDONLY))) retval = EXIT_FAILURE; 30 if (*argv && 0 > (fd = xopen(*argv, O_RDONLY)))
30 else for(;;) { 31 retval = EXIT_FAILURE;
32 else for (;;) {
31 int i, res; 33 int i, res;
32 34
33 res = read(fd, bb_common_bufsiz1, sizeof(bb_common_bufsiz1)); 35 res = read(fd, bb_common_bufsiz1, sizeof(bb_common_bufsiz1));
34 if (res < 0) retval = EXIT_FAILURE; 36 if (res < 0)
35 if (res <1) break; 37 retval = EXIT_FAILURE;
36 for (i=0; i<res; i++) { 38 if (res < 1)
37 char c=bb_common_bufsiz1[i]; 39 break;
40 for (i = 0; i < res; i++) {
41 char c = bb_common_bufsiz1[i];
38 42
39 if (c > 126 && (flags & 4)) { 43 if (c > 126 && (flags & CATV_OPT_v)) {
40 if (c == 127) { 44 if (c == 127) {
41 printf("^?"); 45 bb_printf("^?");
42 continue; 46 continue;
43 } else { 47 } else {
44 printf("M-"); 48 bb_printf("M-");
45 c -= 128; 49 c -= 128;
46 } 50 }
47 } 51 }
48 if (c < 32) { 52 if (c < 32) {
49 if (c == 10) { 53 if (c == 10) {
50 if (flags & 1) putchar('$'); 54 if (flags & CATV_OPT_e)
51 } else if (flags & (c==9 ? 2 : 4)) { 55 putchar('$');
52 printf("^%c", c+'@'); 56 } else if (flags & (c==9 ? CATV_OPT_t : CATV_OPT_v)) {
57 bb_printf("^%c", c+'@');
53 continue; 58 continue;
54 } 59 }
55 } 60 }
56 putchar(c); 61 putchar(c);
57 } 62 }
58 } 63 }
59 if (ENABLE_FEATURE_CLEAN_UP && fd) close(fd); 64 if (ENABLE_FEATURE_CLEAN_UP && fd)
65 close(fd);
60 } while (*++argv); 66 } while (*++argv);
61 67
62 return retval; 68 return retval;