]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib: [tt.c] support key="value" output format
authorKarel Zak <kzak@redhat.com>
Tue, 10 May 2011 08:37:39 +0000 (10:37 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 10 May 2011 08:37:39 +0000 (10:37 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
include/tt.h
lib/tt.c

index 569e81b3a419adf79b607debd63470e8f37becff..c3dcb2b365f4ed57d7e1dbe2807fcdc730adb3e4 100644 (file)
 #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 {
index 3e78ad0cedd37bc44ae48bac8072c17043cbdfc1..7cbbce3c2095af9287c53c839cb806b5a4e9cf49 100644 (file)
--- 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;