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