From: Karel Zak Date: Thu, 18 Nov 2010 20:06:27 +0000 (+0100) Subject: findmnt: apply new changes from tt.c X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9ead000613ea527f047597d2978ca605f1314418;p=util-linux findmnt: apply new changes from tt.c Signed-off-by: Karel Zak --- diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c index 0e3cc376..9d3547b1 100644 --- a/misc-utils/findmnt.c +++ b/misc-utils/findmnt.c @@ -190,46 +190,6 @@ static int column_name_to_id(const char *name, size_t namesz) return -1; } -/* - * parses list of columns from @str and add IDs to columns[] - */ -static int set_columns(const char *str) -{ - const char *begin = NULL, *p; - - ncolumns = 0; - - if (!str || !*str) - return -1; - - ncolumns = 0; - - for (p = str; p && *p; p++) { - const char *end = NULL; - int id; - - if (!begin) - begin = p; /* begin of the column name */ - if (*p == ',') - end = p; /* terminate the name */ - if (*(p + 1) == '\0') - end = p + 1; /* end of string */ - if (!begin || !end) - continue; - if (end <= begin) - return -1; - - id = column_name_to_id(begin, end - begin); - if (id == -1) - return -1; - columns[ ncolumns++ ] = id; - begin = NULL; - if (end && !*end) - break; - } - return 0; -} - /* Returns LABEL or UUID */ static const char *get_tag(mnt_fs *fs, const char *tagname) { @@ -446,6 +406,8 @@ again: static int __attribute__((__noreturn__)) usage(FILE *out) { + int i; + fprintf(out, _( "\nUsage:\n" " %1$s [options]\n" @@ -478,6 +440,17 @@ static int __attribute__((__noreturn__)) usage(FILE *out) " -S, --source device, LABEL= or UUID=device\n" " -T, --target mountpoint\n\n")); + + fprintf(out, _("\nAvailable columns:\n")); + + for (i = 0; i < __NCOLUMNS; i++) { + + fprintf(out, " %-12s", infos[i].name); + if (i && !((i+1) % 3)) + fputc('\n', out); + } + fputc('\n', out); + fprintf(out, _("\nFor more information see findmnt(1).\n")); exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS); @@ -577,7 +550,8 @@ int main(int argc, char *argv[]) set_all_columns_truncate(FALSE); break; case 'o': - if (set_columns(optarg)) + if (tt_parse_columns_list(optarg, columns, &ncolumns, + column_name_to_id)) exit(EXIT_FAILURE); break; case 'O': @@ -695,7 +669,7 @@ int main(int argc, char *argv[]) } for (i = 0; i < ncolumns; i++) { - int fl = get_column_truncate(i) ? TT_FL_TRUNCATE : 0; + int fl = get_column_truncate(i) ? TT_FL_TRUNC : 0; if (get_column_id(i) == COL_TARGET && (tt_flags & TT_FL_TREE)) fl |= TT_FL_TREE;