aboutsummaryrefslogtreecommitdiff
path: root/toys/other/tac.c
diff options
context:
space:
mode:
Diffstat (limited to 'toys/other/tac.c')
-rw-r--r--toys/other/tac.c41
1 files changed, 25 insertions, 16 deletions
diff --git a/toys/other/tac.c b/toys/other/tac.c
index 2a9e003d..d5f72fd2 100644
--- a/toys/other/tac.c
+++ b/toys/other/tac.c
@@ -13,28 +13,37 @@ config TAC
Output lines in reverse order.
*/
-#define FOR_tac
#include "toys.h"
-GLOBALS(
- struct double_list *dl;
-)
-
-static void do_tac(char **pline, long len)
+static void do_tac(int fd, char *name)
{
- 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);
+ struct arg_list *list = NULL;
+ char *c;
+
+ // Read in lines
+ for (;;) {
+ struct arg_list *temp;
+ long len;
+
+ if (!(c = get_rawline(fd, &len, '\n'))) break;
+
+ temp = xmalloc(sizeof(struct arg_list));
+ temp->next = list;
+ temp->arg = c;
+ list = temp;
+ }
+
+ // Play them back.
+ while (list) {
+ struct arg_list *temp = list->next;
+ xprintf("%s", list->arg);
+ free(list->arg);
+ free(list);
+ list = temp;
}
}
void tac_main(void)
{
- loopfiles_lines(toys.optargs, do_tac);
+ loopfiles(toys.optargs, do_tac);
}