]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fincore: add --output
authorKarel Zak <kzak@redhat.com>
Thu, 23 Mar 2017 13:27:42 +0000 (14:27 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 23 Mar 2017 13:27:42 +0000 (14:27 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/fincore.1
misc-utils/fincore.c

index c32d6312eabe12fabb83625d7f839959272029e4..a615d6ab6955a73a33ab3d67db913a93a08591c1 100644 (file)
@@ -16,6 +16,13 @@ pages in core, a file size, and a file name.  If an error
 occurs during counting, then an error message is printed to the stderr and
 .B fincore
 continues processing the rest of files listed in a command line.
+
+The default output is subject to change.  So whenever possible, you should
+avoid using default outputs in your scripts.  Always explicitly define expected
+columns by using
+.B \-\-output
+.I columns-list
+in environments where a stable output is required.
 .SH OPTIONS
 .TP
 .BR \-n , " \-\-noheadings"
@@ -24,6 +31,11 @@ Do not print a header line in status output.
 .BR \-b , " \-\-bytes"
 Print the SIZE column in bytes rather than in a human-readable format.
 .TP
+.BR \-o , " \-\-output \fIlist\fP"
+Define output columns.  See the \fB\-\-help\fP output to get a list of the
+currently supported columns. The default list of columns may be extended if \fIlist\fP is
+specified in the format \fI+list\fP.
+.TP
 \fB\-V\fR, \fB\-\-version\fR
 Display version information and exit.
 .TP
index f7bccdf62f6ab5ee3b7c5bb7e1a5a3784f122ba8..2d46fae39e7ef379c8b9c922d9de12b591631c08 100644 (file)
@@ -239,17 +239,25 @@ static int fincore_name(struct fincore_control *ctl,
 
 static void __attribute__((__noreturn__)) usage(FILE *out)
 {
+       size_t i;
+
        fputs(USAGE_HEADER, out);
        fprintf(out, _(" %s [options] file...\n"), program_invocation_short_name);
 
        fputs(USAGE_OPTIONS, out);
-       fputs(_(" -b, --bytes               print sizes in bytes rather than in human readable format\n"), out);
-       fputs(_(" -n, --noheadings          don't print headings\n"), out);
+       fputs(_(" -b, --bytes           print sizes in bytes rather than in human readable format\n"), out);
+       fputs(_(" -n, --noheadings      don't print headings\n"), out);
+       fputs(_(" -o, --output <list>   output columns\n"), out);
 
        fputs(USAGE_SEPARATOR, out);
        fputs(USAGE_HELP, out);
        fputs(USAGE_VERSION, out);
 
+       fprintf(out, _("\nAvailable columns (for --output):\n"));
+
+       for (i = 0; i < ARRAY_SIZE(infos); i++)
+               fprintf(out, " %11s  %s\n", infos[i].name, _(infos[i].help));
+
        fprintf(out, USAGE_MAN_TAIL("fincore(1)"));
 
        exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
@@ -260,14 +268,16 @@ int main(int argc, char ** argv)
        int c;
        size_t i;
        int rc = EXIT_SUCCESS;
+       char *outarg = NULL;
 
        struct fincore_control ctl = {
-                       .pagesize = getpagesize()
+               .pagesize = getpagesize()
        };
 
        static const struct option longopts[] = {
                { "bytes",      no_argument, NULL, 'b' },
                { "noheadings", no_argument, NULL, 'n' },
+               { "output",     required_argument, NULL, 'o' },
                { "version",    no_argument, NULL, 'V' },
                { "help",       no_argument, NULL, 'h' },
                { NULL, 0, NULL, 0 },
@@ -278,7 +288,7 @@ int main(int argc, char ** argv)
        textdomain(PACKAGE);
        atexit(close_stdout);
 
-       while ((c = getopt_long (argc, argv, "bnVh", longopts, NULL)) != -1) {
+       while ((c = getopt_long (argc, argv, "bno:Vh", longopts, NULL)) != -1) {
                switch (c) {
                case 'b':
                        ctl.bytes = 1;
@@ -286,6 +296,9 @@ int main(int argc, char ** argv)
                case 'n':
                        ctl.noheadings = 1;
                        break;
+               case 'o':
+                       outarg = optarg;
+                       break;
                case 'V':
                        printf(UTIL_LINUX_VERSION);
                        return EXIT_SUCCESS;
@@ -307,6 +320,10 @@ int main(int argc, char ** argv)
                columns[ncolumns++] = COL_FILE;
        }
 
+       if (outarg && string_add_to_idarray(outarg, columns, ARRAY_SIZE(columns),
+                                        &ncolumns, column_name_to_id) < 0)
+               return EXIT_FAILURE;
+
        scols_init_debug(0);
        ctl.tb = scols_new_table();
        if (!ctl.tb)