From e4cd9c66ac515205102dd47a805044a593807457 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Fri, 2 Aug 2019 13:33:41 -0400 Subject: support delimiter lists --- paste.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/paste.c b/paste.c index 5b0dfbe..b4aec0f 100644 --- a/paste.c +++ b/paste.c @@ -31,8 +31,12 @@ static char *delimiter = "\t"; -void putdelim(void) +void putdelim(int put) { + if (!put) { + return; + } + static int i = 0; if (delimiter[i] == '\\') { switch (delimiter[++i]) { @@ -80,7 +84,7 @@ int paste_serial(char *files[]) while ((c = fgetc(f)) != EOF) { /* FIXME: off-by-one on last line */ if (c == '\n') { - putdelim(); + putdelim(1); } else { putchar(c); } @@ -116,8 +120,7 @@ int paste(int nfiles, char *files[]) size_t n = 0; while (nopen > 0) { - /* TODO: delim */ - for (int i = 0; i < nfiles; putdelim(), i++) { + for (int i = 0; i < nfiles; putdelim(++i < nfiles)) { if (f[i] == NULL) { continue; } @@ -131,6 +134,9 @@ int paste(int nfiles, char *files[]) f[i] = NULL; nopen--; + if (nopen == 0) { + i = nfiles; + } continue; } -- cgit v1.2.1