From: Karel Zak Date: Thu, 23 Mar 2017 13:17:46 +0000 (+0100) Subject: fincore: add --bytes and --noheadings X-Git-Tag: v2.30-rc1~171 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3f91dd88ca7ea6905e39519d52896207521f905e;p=thirdparty%2Futil-linux.git fincore: add --bytes and --noheadings Signed-off-by: Karel Zak --- diff --git a/misc-utils/fincore.1 b/misc-utils/fincore.1 index 32ffce1bb7..c32d6312ea 100644 --- a/misc-utils/fincore.1 +++ b/misc-utils/fincore.1 @@ -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 diff --git a/misc-utils/fincore.c b/misc-utils/fincore.c index 1c74b39fa0..f7bccdf62f 100644 --- a/misc-utils/fincore.c +++ b/misc-utils/fincore.c @@ -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);