From 575a1de03a38bdcc9c9697041633732ea34f1021 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 22 Nov 2013 13:31:15 +0100 Subject: [PATCH] lib/tt: add tb_get_nlines() Signed-off-by: Karel Zak --- include/tt.h | 2 ++ lib/tt.c | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/tt.h b/include/tt.h index 11bd81e4bd..ce76524ac7 100644 --- a/include/tt.h +++ b/include/tt.h @@ -95,6 +95,8 @@ extern int tt_line_set_userdata(struct tt_line *ln, void *data); extern void tt_fputs_quoted(const char *data, FILE *out); extern void tt_fputs_nonblank(const char *data, FILE *out); +extern size_t tb_get_nlines(struct tt *tb); + static inline int tt_is_empty(struct tt *tb) { return !tb || list_empty(&tb->tb_lines); diff --git a/lib/tt.c b/lib/tt.c index 46fc00e878..e94524e861 100644 --- a/lib/tt.c +++ b/lib/tt.c @@ -223,6 +223,19 @@ void tt_set_stream(struct tt *tb, FILE *out) tb->out = out; } +size_t tb_get_nlines(struct tt *tb) +{ + struct list_head *p; + size_t ct = 0; + + if (tt_is_empty(tb)) + return 0; + + list_for_each(p, &tb->tb_lines) + ct++; + return ct; +} + void tt_remove_lines(struct tt *tb) { if (!tb) -- 2.47.3