fincore: add --output
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
3f91dd88ca
commit
c5cb541299
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue