Add the '-l' option which prints string attribute followed by a file name.

Reviewed by:	rwatson, sheldonh
This commit is contained in:
Boris Popov 2000-05-11 10:00:22 +00:00
parent 36fba7e903
commit d220443d1c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=60372
2 changed files with 26 additions and 10 deletions

View file

@ -33,9 +33,9 @@
.Nd retrieve a named extended attribute
.Sh SYNOPSIS
.Nm getextattr
.Op Fl s
.Op Fl ls
.Ar attrname
.Ar filename Op ...
.Ar filename ...
.Sh DESCRIPTION
.Nm
is a user tool to retrieve a named extended attribute on a file or
@ -45,11 +45,16 @@ The
argument should be the name of the attribute, and
.Ar filename
a list of files and directories from which to retrieve attribute data.
If the
.Op Fl s
flag is specified,
.Nm
will attempt to display the attribute data as a string, although the
.Pp
The following options are available:
.Bl -tag -width indent
.It Fl l
Print attributes in the first column and file names in the second.
Can be used only in conjunction with the
.Fl s
option.
.It Fl s
Attempt to display the attribute data as a string, although the
results may not look pretty if the data is binary data.
The
.Xr strvisx 3
@ -57,6 +62,8 @@ function is used to generate the string, so control sequences should
be safely escaped.
Otherwise, the attribute data will be represented as a series of two-digit
hex numbers.
.El
.Sh IMPLEMENTATION NOTES
In order for
.Nm
to succeed, the attribute service must be available on the file system,

View file

@ -60,9 +60,12 @@ main(int argc, char *argv[])
int ch;
int flag_as_string = 0;
int flag_reverse = 0;
while ((ch = getopt(argc, argv, "s")) != -1) {
while ((ch = getopt(argc, argv, "ls")) != -1) {
switch (ch) {
case 'l':
flag_reverse = 1;
case 's':
flag_as_string = 1;
break;
@ -93,12 +96,18 @@ main(int argc, char *argv[])
if (error == -1)
perror(argv[arg_counter]);
else {
printf("%s:", argv[arg_counter]);
if (flag_as_string) {
strvisx(visbuf, buf, error, VIS_SAFE
| VIS_WHITE);
printf(" \"%s\"\n", visbuf);
if (flag_reverse) {
printf("%s ", visbuf);
printf("%s\n", argv[arg_counter]);
} else {
printf("%s:", argv[arg_counter]);
printf(" \"%s\"\n", visbuf);
}
} else {
printf("%s:", argv[arg_counter]);
for (i = 0; i < error; i++)
if (i % 16 == 0)
printf("\n %02x ", buf[i]);