blob: 2a9e003db40aa0c089a8c55b2fe8779d3adac155 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
/* tac.c - output lines in reverse order
*
* Copyright 2012 Rob Landley <rob@landley.net>
USE_TAC(NEWTOY(tac, NULL, TOYFLAG_USR|TOYFLAG_BIN))
config TAC
bool "tac"
default y
help
usage: tac [FILE...]
Output lines in reverse order.
*/
#define FOR_tac
#include "toys.h"
GLOBALS(
struct double_list *dl;
)
static void do_tac(char **pline, long len)
{
if (pline) {
dlist_add(&TT.dl, *pline);
*pline = 0;
} else while (TT.dl) {
struct double_list *dl = dlist_lpop(&TT.dl);
xprintf("%s", dl->data);
free(dl->data);
free(dl);
}
}
void tac_main(void)
{
loopfiles_lines(toys.optargs, do_tac);
}
|