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

index 32ffce1bb74f30d0939b16477654cb8fccc1fa70..c32d6312eabe12fabb83625d7f839959272029e4 100644 (file)
@@ -18,46 +18,17 @@ occurs during counting, then an error message is printed to the stderr and
 continues processing the rest of files listed in a command line.
 .SH OPTIONS
 .TP
+.BR \-n , " \-\-noheadings"
+Do not print a header line in status output.
+.TP
+.BR \-b , " \-\-bytes"
+Print the SIZE column in bytes rather than in a human-readable format.
+.TP
 \fB\-V\fR, \fB\-\-version\fR
 Display version information and exit.
 .TP
 \fB\-h\fR, \fB\-\-help\fR
 Display help text and exit.
-.SH EXAMPLES
-.PP
-An example of successfully executed case:
-.PP
-.RS
-.PD 0
-.TP
-.B fincore /etc/fstab /bin/emacs
-.TP
-1          1544       /etc/fstab
-.TP
-4156       17163144   /bin/emacs
-.TP
-.B echo $?
-.TP
-0
-.PD
-.RE
-.PP
-An example of failure case:
-.PP
-.RS
-.PD 0
-.TP
-.B fincore /etc/passwd
-.TP
-.I fincore: failed to open: /var/log/messages: Permission denied
-.TP
-failed     -1         /var/log/messages
-.TP
-.B echo $?
-.TP
-1
-.PD
-.RE
 .SH AUTHORS
 .MT yamato@\:redhat.com
 Masatake YAMATO
index 1c74b39fa0662c44f42a5b1f333fb9a0416bc35b..f7bccdf62f6ab5ee3b7c5bb7e1a5a3784f122ba8 100644 (file)
@@ -70,26 +70,10 @@ struct fincore_control {
 
        struct libscols_table *tb;              /* output */
 
-       unsigned int bytes : 1;
+       unsigned int bytes : 1,
+                    noheadings : 1;
 };
 
-static void __attribute__((__noreturn__)) usage(FILE *out)
-{
-       const char *p = program_invocation_short_name;
-
-       if (!*p)
-               p = "fincore";
-
-       fputs(USAGE_HEADER, out);
-       fprintf(out, _(" %s [options] file...\n"), program_invocation_short_name);
-       fputs(USAGE_OPTIONS, out);
-       fputs(USAGE_SEPARATOR, out);
-       fputs(USAGE_HELP, out);
-       fputs(USAGE_VERSION, out);
-       fprintf(out, USAGE_MAN_TAIL("fincore(1)"));
-
-       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
-}
 
 static int column_name_to_id(const char *name, size_t namesz)
 {
@@ -253,6 +237,24 @@ static int fincore_name(struct fincore_control *ctl,
        return rc;
 }
 
+static void __attribute__((__noreturn__)) usage(FILE *out)
+{
+       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(USAGE_SEPARATOR, out);
+       fputs(USAGE_HELP, out);
+       fputs(USAGE_VERSION, out);
+
+       fprintf(out, USAGE_MAN_TAIL("fincore(1)"));
+
+       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+}
+
 int main(int argc, char ** argv)
 {
        int c;
@@ -264,6 +266,8 @@ int main(int argc, char ** argv)
        };
 
        static const struct option longopts[] = {
+               { "bytes",      no_argument, NULL, 'b' },
+               { "noheadings", no_argument, NULL, 'n' },
                { "version",    no_argument, NULL, 'V' },
                { "help",       no_argument, NULL, 'h' },
                { NULL, 0, NULL, 0 },
@@ -274,8 +278,14 @@ int main(int argc, char ** argv)
        textdomain(PACKAGE);
        atexit(close_stdout);
 
-       while ((c = getopt_long (argc, argv, "Vh", longopts, NULL)) != -1) {
+       while ((c = getopt_long (argc, argv, "bnVh", longopts, NULL)) != -1) {
                switch (c) {
+               case 'b':
+                       ctl.bytes = 1;
+                       break;
+               case 'n':
+                       ctl.noheadings = 1;
+                       break;
                case 'V':
                        printf(UTIL_LINUX_VERSION);
                        return EXIT_SUCCESS;
@@ -302,6 +312,8 @@ int main(int argc, char ** argv)
        if (!ctl.tb)
                err(EXIT_FAILURE, _("failed to create output table"));
 
+       scols_table_enable_noheadings(ctl.tb, ctl.noheadings);
+
        for (i = 0; i < ncolumns; i++) {
                const struct colinfo *col = get_column_info(i);