annotate toys/posix/cat.c @ 902:36993c59a3d3

Tighten up lsusb, default to "y".
author Rob Landley <rob@landley.net>
date Tue, 14 May 2013 20:42:54 -0500
parents 6cc69be43c42
children fc1bb49e58a9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
1 /* cat.c - copy inputs to stdout.
279
0ca2fcee572b Spent the five minutes to implement "cat".
Rob Landley <rob@landley.net>
parents:
diff changeset
2 *
0ca2fcee572b Spent the five minutes to implement "cat".
Rob Landley <rob@landley.net>
parents:
diff changeset
3 * Copyright 2006 Rob Landley <rob@landley.net>
0ca2fcee572b Spent the five minutes to implement "cat".
Rob Landley <rob@landley.net>
parents:
diff changeset
4 *
656
6df4ccc0acbe Regularize command headers, update links to standards documents.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
5 * See http://opengroup.org/onlinepubs/9699919799/utilities/cat.html
279
0ca2fcee572b Spent the five minutes to implement "cat".
Rob Landley <rob@landley.net>
parents:
diff changeset
6
0ca2fcee572b Spent the five minutes to implement "cat".
Rob Landley <rob@landley.net>
parents:
diff changeset
7 USE_CAT(NEWTOY(cat, "u", TOYFLAG_BIN))
0ca2fcee572b Spent the five minutes to implement "cat".
Rob Landley <rob@landley.net>
parents:
diff changeset
8
0ca2fcee572b Spent the five minutes to implement "cat".
Rob Landley <rob@landley.net>
parents:
diff changeset
9 config CAT
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
10 bool "cat"
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
11 default y
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
12 help
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
13 usage: cat [-u] [file...]
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
14 Copy (concatenate) files to stdout. If no files listed, copy from stdin.
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
15 Filename "-" is a synonym for stdin.
279
0ca2fcee572b Spent the five minutes to implement "cat".
Rob Landley <rob@landley.net>
parents:
diff changeset
16
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
17 -u Copy one byte at a time (slow).
279
0ca2fcee572b Spent the five minutes to implement "cat".
Rob Landley <rob@landley.net>
parents:
diff changeset
18 */
0ca2fcee572b Spent the five minutes to implement "cat".
Rob Landley <rob@landley.net>
parents:
diff changeset
19
0ca2fcee572b Spent the five minutes to implement "cat".
Rob Landley <rob@landley.net>
parents:
diff changeset
20 #include "toys.h"
0ca2fcee572b Spent the five minutes to implement "cat".
Rob Landley <rob@landley.net>
parents:
diff changeset
21
0ca2fcee572b Spent the five minutes to implement "cat".
Rob Landley <rob@landley.net>
parents:
diff changeset
22 static void do_cat(int fd, char *name)
0ca2fcee572b Spent the five minutes to implement "cat".
Rob Landley <rob@landley.net>
parents:
diff changeset
23 {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
24 int len, size=toys.optflags ? 1 : sizeof(toybuf);
279
0ca2fcee572b Spent the five minutes to implement "cat".
Rob Landley <rob@landley.net>
parents:
diff changeset
25
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
26 for (;;) {
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
27 len = read(fd, toybuf, size);
780
6cc69be43c42 Have error_msg() and friends set TT.exitval to 1 if it's still 0, clean out other places that were setting it that no longer need to.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
28 if (len<0) perror_msg("%s",name);
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
29 if (len<1) break;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
30 xwrite(1, toybuf, len);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
31 }
279
0ca2fcee572b Spent the five minutes to implement "cat".
Rob Landley <rob@landley.net>
parents:
diff changeset
32 }
0ca2fcee572b Spent the five minutes to implement "cat".
Rob Landley <rob@landley.net>
parents:
diff changeset
33
0ca2fcee572b Spent the five minutes to implement "cat".
Rob Landley <rob@landley.net>
parents:
diff changeset
34 void cat_main(void)
0ca2fcee572b Spent the five minutes to implement "cat".
Rob Landley <rob@landley.net>
parents:
diff changeset
35 {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
36 loopfiles(toys.optargs, do_cat);
279
0ca2fcee572b Spent the five minutes to implement "cat".
Rob Landley <rob@landley.net>
parents:
diff changeset
37 }