Mercurial > hg > toybox
annotate toys/other/tac.c @ 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.
The actual code should be the same afterward, this is just cosmetic refactoring.
author | Rob Landley <rob@landley.net> |
---|---|
date | Tue, 13 Nov 2012 17:14:08 -0600 |
parents | 6df4ccc0acbe |
children | f7eaff0c8d0c |
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 /* tac.c - output lines in reverse order |
522
33ce0407ea47
Add tac. (Shell wrapper is smaller, but all-in-one static binary is compelling use case.)
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2 * |
33ce0407ea47
Add tac. (Shell wrapper is smaller, but all-in-one static binary is compelling use case.)
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3 * Copyright 2012 Rob Landley <rob@landley.net> |
33ce0407ea47
Add tac. (Shell wrapper is smaller, but all-in-one static binary is compelling use case.)
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
4 |
33ce0407ea47
Add tac. (Shell wrapper is smaller, but all-in-one static binary is compelling use case.)
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
5 USE_TAC(NEWTOY(tac, NULL, TOYFLAG_USR|TOYFLAG_BIN)) |
33ce0407ea47
Add tac. (Shell wrapper is smaller, but all-in-one static binary is compelling use case.)
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
6 |
33ce0407ea47
Add tac. (Shell wrapper is smaller, but all-in-one static binary is compelling use case.)
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
7 config TAC |
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
|
8 bool "tac" |
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
|
9 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
|
10 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
|
11 usage: tac [FILE...] |
522
33ce0407ea47
Add tac. (Shell wrapper is smaller, but all-in-one static binary is compelling use case.)
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
12 |
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
|
13 Output lines in reverse order. |
522
33ce0407ea47
Add tac. (Shell wrapper is smaller, but all-in-one static binary is compelling use case.)
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
14 */ |
33ce0407ea47
Add tac. (Shell wrapper is smaller, but all-in-one static binary is compelling use case.)
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
15 |
33ce0407ea47
Add tac. (Shell wrapper is smaller, but all-in-one static binary is compelling use case.)
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
16 #include "toys.h" |
33ce0407ea47
Add tac. (Shell wrapper is smaller, but all-in-one static binary is compelling use case.)
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
17 |
33ce0407ea47
Add tac. (Shell wrapper is smaller, but all-in-one static binary is compelling use case.)
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
18 void do_tac(int fd, char *name) |
33ce0407ea47
Add tac. (Shell wrapper is smaller, but all-in-one static binary is compelling use case.)
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
19 { |
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
|
20 struct arg_list *list = NULL; |
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
|
21 char *c; |
522
33ce0407ea47
Add tac. (Shell wrapper is smaller, but all-in-one static binary is compelling use case.)
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
22 |
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
|
23 // Read in lines |
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 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
|
25 struct arg_list *temp; |
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 int len; |
522
33ce0407ea47
Add tac. (Shell wrapper is smaller, but all-in-one static binary is compelling use case.)
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
27 |
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
|
28 if (!(c = get_line(fd))) break; |
522
33ce0407ea47
Add tac. (Shell wrapper is smaller, but all-in-one static binary is compelling use case.)
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
29 |
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
|
30 len = strlen(c); |
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 if (len && c[len-1]=='\n') c[len-1] = 0; |
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
|
32 temp = xmalloc(sizeof(struct arg_list)); |
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
|
33 temp->next = list; |
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
|
34 temp->arg = c; |
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
|
35 list = temp; |
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 } |
522
33ce0407ea47
Add tac. (Shell wrapper is smaller, but all-in-one static binary is compelling use case.)
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
37 |
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
|
38 // Play them back. |
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
|
39 while (list) { |
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
|
40 struct arg_list *temp = list->next; |
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
|
41 xputs(list->arg); |
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
|
42 free(list->arg); |
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
|
43 free(list); |
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
|
44 list = temp; |
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
|
45 } |
522
33ce0407ea47
Add tac. (Shell wrapper is smaller, but all-in-one static binary is compelling use case.)
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
46 } |
33ce0407ea47
Add tac. (Shell wrapper is smaller, but all-in-one static binary is compelling use case.)
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
47 |
33ce0407ea47
Add tac. (Shell wrapper is smaller, but all-in-one static binary is compelling use case.)
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
48 void tac_main(void) |
33ce0407ea47
Add tac. (Shell wrapper is smaller, but all-in-one static binary is compelling use case.)
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
49 { |
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
|
50 loopfiles(toys.optargs, do_tac); |
522
33ce0407ea47
Add tac. (Shell wrapper is smaller, but all-in-one static binary is compelling use case.)
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
51 } |