From: Karel Zak Date: Tue, 10 May 2011 08:37:39 +0000 (+0200) Subject: lib: [tt.c] support key="value" output format X-Git-Tag: v2.20-rc1~292 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bfe695ff5b6a08bbdef6c63bb1a0209548f39875;p=thirdparty%2Futil-linux.git lib: [tt.c] support key="value" output format Signed-off-by: Karel Zak --- diff --git a/include/tt.h b/include/tt.h index 569e81b3a4..c3dcb2b365 100644 --- a/include/tt.h +++ b/include/tt.h @@ -12,13 +12,21 @@ #include "list.h" enum { - TT_FL_TRUNC = (1 << 1), - TT_FL_TREE = (1 << 2), - TT_FL_RAW = (1 << 3), - TT_FL_ASCII = (1 << 4), - TT_FL_NOHEADINGS = (1 << 5), - TT_FL_RIGHT = (1 << 6), - TT_FL_STRICTWIDTH = (1 << 7) + /* + * Global flags + */ + TT_FL_RAW = (1 << 1), + TT_FL_ASCII = (1 << 2), + TT_FL_NOHEADINGS = (1 << 3), + TT_FL_EXPORT = (1 << 4), + + /* + * Column flags + */ + TT_FL_TRUNC = (1 << 5), + TT_FL_TREE = (1 << 6), + TT_FL_RIGHT = (1 << 7), + TT_FL_STRICTWIDTH = (1 << 8) }; struct tt { diff --git a/lib/tt.c b/lib/tt.c index 3e78ad0ced..7cbbce3c20 100644 --- a/lib/tt.c +++ b/lib/tt.c @@ -468,6 +468,14 @@ static void print_data(struct tt *tb, struct tt_column *cl, char *data) return; } + /* NAME=value mode */ + if (tb->flags & TT_FL_EXPORT) { + fprintf(stdout, "%s=\"%s\"", cl->name, data); + if (!is_last_column(tb, cl)) + fputc(' ', stdout); + return; + } + /* note that 'len' and 'width' are number of cells, not bytes */ len = mbs_width(data); @@ -535,6 +543,7 @@ static void print_header(struct tt *tb, char *buf, size_t bufsz) if (!tb->first_run || (tb->flags & TT_FL_NOHEADINGS) || + (tb->flags & TT_FL_EXPORT) || list_empty(&tb->tb_lines)) return; @@ -629,7 +638,8 @@ int tt_print_table(struct tt *tb) if (!line) return -1; - if (tb->first_run && !(tb->flags & TT_FL_RAW)) + if (tb->first_run && + !((tb->flags & TT_FL_RAW) || (tb->flags & TT_FL_EXPORT))) recount_widths(tb, line, line_sz); if (tb->flags & TT_FL_TREE) @@ -695,11 +705,14 @@ int main(int argc, char *argv[]) printf("%s [--ascii | --raw | --list]\n", program_invocation_short_name); return EXIT_SUCCESS; - } else if (argc == 2 && !strcmp(argv[1], "--ascii")) + } else if (argc == 2 && !strcmp(argv[1], "--ascii")) { flags |= TT_FL_ASCII; - else if (argc == 2 && !strcmp(argv[1], "--raw")) { + } else if (argc == 2 && !strcmp(argv[1], "--raw")) { flags |= TT_FL_RAW; notree = 1; + } else if (argc == 2 && !strcmp(argv[1], "--export")) { + flags |= TT_FL_EXPORT; + notree = 1; } else if (argc == 2 && !strcmp(argv[1], "--list")) notree = 1;