annotate toys/catv.c @ 233:d4176f3f3835

Zap toys/Config.in and instead create generated/Config.in from contents of toys/*.c. Move relevant info into comment at the top of each toys/*.c. Also convert more of Makefile into a thin wrapper around shell scripts that actually do the work. (Makefile is only still there for the user interface.)
author Rob Landley <rob@landley.net>
date Sat, 19 Jan 2008 17:08:39 -0600
parents 30a6db5a95c2
children 163498bf547b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
1 /* vi: set sw=4 ts=4:
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
2 *
35
f2c7f0799ebe Add cat -v.
Rob Landley <rob@landley.net>
parents:
diff changeset
3 * cat -v implementation for toybox
f2c7f0799ebe Add cat -v.
Rob Landley <rob@landley.net>
parents:
diff changeset
4 *
194
30a6db5a95c2 Add comments about SUSv3 specs (or lack thereof).
Rob Landley <rob@landley.net>
parents: 187
diff changeset
5 * Copyright (C) 2006, 2007 Rob Landley <rob@landley.net>
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
6 *
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
7 * Not in SUSv3, but see "Cat -v considered harmful" at
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
8 * http://cm.bell-labs.com/cm/cs/doc/84/kp.ps.gz
35
f2c7f0799ebe Add cat -v.
Rob Landley <rob@landley.net>
parents:
diff changeset
9
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
10 config CATV
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
11 bool "catv"
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
12 default y
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
13 help
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
14 usage: catv [-evt] [filename...]
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
15
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
16 Display nonprinting characters as escape sequences. Use M-x for
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
17 high ascii characters (>127), and ^x for other nonprinting chars.
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
18
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
19 -e Mark each newline with $
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
20 -t Show tabs as ^I
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
21 -v Don't use ^x or M-x escapes.
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 194
diff changeset
22 */
35
f2c7f0799ebe Add cat -v.
Rob Landley <rob@landley.net>
parents:
diff changeset
23
f2c7f0799ebe Add cat -v.
Rob Landley <rob@landley.net>
parents:
diff changeset
24 #include "toys.h"
f2c7f0799ebe Add cat -v.
Rob Landley <rob@landley.net>
parents:
diff changeset
25
185
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
26 // Callback function for loopfiles()
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
27
187
c983a0af6d4e Add sha1sum. (No -c mode yet.) Slight tweaks to loopfiles() too.
Rob Landley <rob@landley.net>
parents: 186
diff changeset
28 static void do_catv(int fd, char *name)
185
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
29 {
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
30 for(;;) {
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
31 int i, len;
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
32
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
33 len = read(fd, toybuf, sizeof(toybuf));
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
34 if (len < 0) toys.exitval = EXIT_FAILURE;
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
35 if (len < 1) break;
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
36 for (i=0; i<len; i++) {
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
37 char c=toybuf[i];
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
38
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
39 if (c > 126 && (toys.optflags & 4)) {
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
40 if (c == 127) {
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
41 printf("^?");
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
42 continue;
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
43 } else {
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
44 printf("M-");
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
45 c -= 128;
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
46 }
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
47 }
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
48 if (c < 32) {
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
49 if (c == 10) {
186
25447caf1b4b Change command main() functions to return void, and exit(toys.exitval) from
Rob Landley <rob@landley.net>
parents: 185
diff changeset
50 if (toys.optflags & 1) xputc('$');
185
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
51 } else if (toys.optflags & (c==9 ? 2 : 4)) {
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
52 printf("^%c", c+'@');
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
53 continue;
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
54 }
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
55 }
186
25447caf1b4b Change command main() functions to return void, and exit(toys.exitval) from
Rob Landley <rob@landley.net>
parents: 185
diff changeset
56 xputc(c);
185
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
57 }
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
58 }
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
59 }
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
60
186
25447caf1b4b Change command main() functions to return void, and exit(toys.exitval) from
Rob Landley <rob@landley.net>
parents: 185
diff changeset
61 void catv_main(void)
35
f2c7f0799ebe Add cat -v.
Rob Landley <rob@landley.net>
parents:
diff changeset
62 {
f2c7f0799ebe Add cat -v.
Rob Landley <rob@landley.net>
parents:
diff changeset
63 toys.optflags^=4;
185
29e2051296fd Add loopfiles() function, make catv use it.
Rob Landley <rob@landley.net>
parents: 155
diff changeset
64 loopfiles(toys.optargs, do_catv);
35
f2c7f0799ebe Add cat -v.
Rob Landley <rob@landley.net>
parents:
diff changeset
65 }