Mercurial > hg > toybox
annotate toys/catv.c @ 90:7c77c6ec17ee
Add "make defconfig". Modify global options to start with CONFIG_TOYBOX_.
author | Rob Landley <rob@landley.net> |
---|---|
date | Wed, 31 Jan 2007 14:37:01 -0500 |
parents | 69efffcacd70 |
children | 6c7836dbc16e |
rev | line source |
---|---|
35 | 1 /* vi: set sw=4 ts=4: */ |
2 /* | |
3 * cat -v implementation for toybox | |
4 * | |
5 * Copyright (C) 2006 Rob Landley <rob@landley.net> | |
6 */ | |
7 | |
8 /* See "Cat -v considered harmful" at | |
9 * http://cm.bell-labs.com/cm/cs/doc/84/kp.ps.gz */ | |
10 | |
11 #include "toys.h" | |
12 | |
13 int catv_main(void) | |
14 { | |
15 int retval = 0, fd; | |
16 char **argv = toys.optargs; | |
17 | |
18 toys.optflags^=4; | |
19 | |
20 // Loop through files. | |
21 | |
22 do { | |
23 // Read from stdin if there's nothing else to do. | |
24 | |
25 fd = 0; | |
49
bb4c38853a7d
xopen() wants 2 arguments unless you're creating a file, in which case you
Rob Landley <rob@landley.net>
parents:
35
diff
changeset
|
26 if (*argv && 0>(fd = xopen(*argv, O_RDONLY))) retval = EXIT_FAILURE; |
35 | 27 else for(;;) { |
28 int i, res; | |
29 | |
63
69efffcacd70
Add fdprintf(). Remove reread() and rewrite() which handle -EINTR, which
Rob Landley <rob@landley.net>
parents:
49
diff
changeset
|
30 res = read(fd, toybuf, sizeof(toybuf)); |
35 | 31 if (res < 0) retval = EXIT_FAILURE; |
32 if (res < 1) break; | |
33 for (i=0; i<res; i++) { | |
34 char c=toybuf[i]; | |
35 | |
36 if (c > 126 && (toys.optflags & 4)) { | |
37 if (c == 127) { | |
38 printf("^?"); | |
39 continue; | |
40 } else { | |
41 printf("M-"); | |
42 c -= 128; | |
43 } | |
44 } | |
45 if (c < 32) { | |
46 if (c == 10) { | |
47 if (toys.optflags & 1) putchar('$'); | |
48 } else if (toys.optflags & (c==9 ? 2 : 4)) { | |
49 printf("^%c", c+'@'); | |
50 continue; | |
51 } | |
52 } | |
53 putchar(c); | |
54 } | |
55 } | |
90
7c77c6ec17ee
Add "make defconfig". Modify global options to start with CONFIG_TOYBOX_.
Rob Landley <rob@landley.net>
parents:
63
diff
changeset
|
56 if (CFG_TOYBOX_FREE && fd) close(fd); |
35 | 57 } while (*++argv); |
58 | |
59 return retval; | |
60 } |