summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2023-06-03 02:22:10 +0200
committerLouis Burda <quent.burda@gmail.com>2023-06-03 02:22:10 +0200
commitf32da6a6ef96eedb5c5125e3415fc38ff2e15663 (patch)
treefb03d8a1fe66a6b5b60a7a7031753ba7a4f29644
parent127b061df0f4d1cedc356ec9fc0b031b9403e96b (diff)
downloadtabular-f32da6a6ef96eedb5c5125e3415fc38ff2e15663.tar.gz
tabular-f32da6a6ef96eedb5c5125e3415fc38ff2e15663.zip
Fix issue with detecting closed stdin
-rw-r--r--main.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/main.c b/main.c
index 21dd228..a401b90 100644
--- a/main.c
+++ b/main.c
@@ -37,6 +37,8 @@ static size_t colcnt = 0;
static struct dvec input;
static size_t input_off = 0;
+static bool input_done = false;
+
static struct dvec line;
static struct dvec entries;
static size_t linecnt = 0;
@@ -98,9 +100,6 @@ print_style(FILE *file, const struct tabular_cfg *cfg,
} else if (!row) { /* header */
fprintf(file, "\x1b[1m");
return true;
- } else if (!strcmp(col->name, "Name")) {
- fprintf(file, "\x1b[35m");
- return true;
}
}
@@ -113,6 +112,8 @@ read_line(void)
void *tok, *sep, *end, *line_end;
ssize_t n;
+ if (input_done) return false;
+
while (1) {
while (!(line_end = memchr(input.data + input_off,
line_sep, input.len - input_off))) {
@@ -121,14 +122,15 @@ read_line(void)
dvec_reserve(&input, input.len + BUFSIZ + 1);
n = read(0, input.data + input.len, BUFSIZ);
if (n <= 0) {
+ input_done = true;
line_end = input.data + input.len;
break;
}
input.len += (size_t) n;
}
- if (!input.len) return false;
+ if (input_done && !input.len) return false;
- if (line_end != input.data || skip_empty_lines)
+ if (line_end != input.data || !skip_empty_lines)
break;
input_off += 1;
}
@@ -227,6 +229,7 @@ parse(int argc, const char **argv)
struct winsize ws;
char namebuf[64];
char *end, *c, *upper;
+ size_t len;
int rc, n;
hmap_init(&colmap, 16, hmap_str_hash, hmap_str_keycmp, ga);
@@ -345,10 +348,16 @@ parse(int argc, const char **argv)
if (!*++arg) die("missing args");
col->lpad = strtoul(*arg, &end, 10);
if (end && *end) die("bad %s", arg[-1]);
+ len = col->lpad + strlen(col->name) + col->rpad;
+ if (col->minwidth < len)
+ col->minwidth = len;
} else if (!strcmp(*arg + n, "rpad")) {
if (!*++arg) die("missing args");
col->rpad = strtoul(*arg, &end, 10);
if (end && *end) die("bad %s", arg[-1]);
+ len = col->lpad + strlen(col->name) + col->rpad;
+ if (col->minwidth < len)
+ col->minwidth = len;
} else if (!strcmp(*arg + n, "align")) {
if (!*++arg) die("missing args");
if (!strcmp(*arg, "left")) {