From b28e8864630cc546dd8ca1ff6e135c191fdb34ea Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 19 Mar 2014 17:25:31 +0100 Subject: [PATCH] libsmartcols: remove unnecessary code Signed-off-by: Karel Zak --- libsmartcols/src/smartcolsP.h | 1 - libsmartcols/src/table.c | 1 - libsmartcols/src/table_print.c | 21 +++++++-------------- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/libsmartcols/src/smartcolsP.h b/libsmartcols/src/smartcolsP.h index d7211438e6..20c262951e 100644 --- a/libsmartcols/src/smartcolsP.h +++ b/libsmartcols/src/smartcolsP.h @@ -107,7 +107,6 @@ struct libscols_table { size_t termreduce; /* extra blank space */ int is_term; /* is a tty? */ int flags; - int first_run; FILE *out; /* output stream */ struct list_head tb_columns; diff --git a/libsmartcols/src/table.c b/libsmartcols/src/table.c index 770aaccc2f..d99bc33351 100644 --- a/libsmartcols/src/table.c +++ b/libsmartcols/src/table.c @@ -46,7 +46,6 @@ struct libscols_table *scols_new_table(int flags, struct libscols_symbols *syms) tb->flags = flags; tb->refcount = 1; - tb->first_run = TRUE; tb->out = stdout; INIT_LIST_HEAD(&tb->tb_lines); diff --git a/libsmartcols/src/table_print.c b/libsmartcols/src/table_print.c index 2edd185b45..7da79598a4 100644 --- a/libsmartcols/src/table_print.c +++ b/libsmartcols/src/table_print.c @@ -231,8 +231,7 @@ static void print_header(struct libscols_table *tb, char *buf, size_t bufsz) assert(tb); - if (!tb->first_run || - (tb->flags & SCOLS_FL_NOHEADINGS) || + if ((tb->flags & SCOLS_FL_NOHEADINGS) || (tb->flags & SCOLS_FL_EXPORT) || list_empty(&tb->tb_lines)) return; @@ -551,15 +550,11 @@ int scols_print_table(struct libscols_table *tb) if (!tb) return -1; - if (tb->first_run) { - tb->is_term = isatty(STDOUT_FILENO); - - if (tb->is_term && !tb->termwidth) - tb->termwidth = get_terminal_width(); - if (tb->termwidth <= 0) - tb->termwidth = 80; - tb->termwidth -= tb->termreduce; - } + tb->is_term = isatty(STDOUT_FILENO); + tb->termwidth = tb->is_term ? get_terminal_width() : 0; + if (tb->termwidth <= 0) + tb->termwidth = 80; + tb->termwidth -= tb->termreduce; line_sz = tb->termwidth; @@ -575,8 +570,7 @@ int scols_print_table(struct libscols_table *tb) if (!line) return -ENOMEM; - if (tb->first_run && - !((tb->flags & SCOLS_FL_RAW) || (tb->flags & SCOLS_FL_EXPORT))) + if (!((tb->flags & SCOLS_FL_RAW) || (tb->flags & SCOLS_FL_EXPORT))) recount_widths(tb, line, line_sz); if (tb->flags & SCOLS_FL_TREE) @@ -585,6 +579,5 @@ int scols_print_table(struct libscols_table *tb) print_table(tb, line, line_sz); free(line); - tb->first_run = FALSE; return 0; } -- 2.47.3