comparison toys/other/catv.c @ 668:0ee40175a307

Fix catv to display byte 255 correctly. (It's both M- and ^?.)
author Rob Landley <rob@landley.net>
date Sat, 06 Oct 2012 01:54:24 -0500
parents 6df4ccc0acbe
children 7e846e281e38
comparison
equal deleted inserted replaced
667:40bc0523ae61 668:0ee40175a307
23 -v Don't use ^x or M-x escapes. 23 -v Don't use ^x or M-x escapes.
24 */ 24 */
25 25
26 #include "toys.h" 26 #include "toys.h"
27 27
28 #define FLAG_v 4
29 #define FLAG_t 2
30 #define FLAG_e 1
31
28 // Callback function for loopfiles() 32 // Callback function for loopfiles()
29 33
30 static void do_catv(int fd, char *name) 34 static void do_catv(int fd, char *name)
31 { 35 {
32 for(;;) { 36 for(;;) {
36 if (len < 0) toys.exitval = EXIT_FAILURE; 40 if (len < 0) toys.exitval = EXIT_FAILURE;
37 if (len < 1) break; 41 if (len < 1) break;
38 for (i=0; i<len; i++) { 42 for (i=0; i<len; i++) {
39 char c=toybuf[i]; 43 char c=toybuf[i];
40 44
41 if (c > 126 && (toys.optflags & 4)) { 45 if (c > 126 && (toys.optflags & FLAG_v)) {
46 if (c > 127) {
47 printf("M-");
48 c -= 128;
49 }
42 if (c == 127) { 50 if (c == 127) {
43 printf("^?"); 51 printf("^?");
44 continue; 52 continue;
45 } else {
46 printf("M-");
47 c -= 128;
48 } 53 }
49 } 54 }
50 if (c < 32) { 55 if (c < 32) {
51 if (c == 10) { 56 if (c == 10) {
52 if (toys.optflags & 1) xputc('$'); 57 if (toys.optflags & FLAG_e) xputc('$');
53 } else if (toys.optflags & (c==9 ? 2 : 4)) { 58 } else if (toys.optflags & (c==9 ? FLAG_t : FLAG_v)) {
54 printf("^%c", c+'@'); 59 printf("^%c", c+'@');
55 continue; 60 continue;
56 } 61 }
57 } 62 }
58 xputc(c); 63 xputc(c);
60 } 65 }
61 } 66 }
62 67
63 void catv_main(void) 68 void catv_main(void)
64 { 69 {
65 toys.optflags^=4; 70 toys.optflags ^= FLAG_v;
66 loopfiles(toys.optargs, do_catv); 71 loopfiles(toys.optargs, do_catv);
67 } 72 }