mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-05 09:14:03 +00:00
o Renamed '-b' (show unprintables in octal) to '-B'
o Added a new '-b' which behaves as in AT&T Unices (show unprintables in octal, using C escape codes when possible) o Added '?' to the getopt() string, since the code in the switch considers it as a valid option.
This commit is contained in:
parent
ca67f4589b
commit
0d86878ce0
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=35417
14
bin/ls/ls.1
14
bin/ls/ls.1
@ -33,7 +33,7 @@
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)ls.1 8.7 (Berkeley) 7/29/94
|
||||
.\" $Id: ls.1,v 1.16 1997/12/25 09:36:39 hoek Exp $
|
||||
.\" $Id: ls.1,v 1.17 1998/04/21 22:01:58 des Exp $
|
||||
.\"
|
||||
.Dd July 29, 1994
|
||||
.Dt LS 1
|
||||
@ -43,7 +43,7 @@
|
||||
.Nd list directory contents
|
||||
.Sh SYNOPSIS
|
||||
.Nm ls
|
||||
.Op Fl ACFLRTWabcdfgikloqrstu1
|
||||
.Op Fl ?ABCFLRTWabcdfgikloqrstu1
|
||||
.Op Ar file ...
|
||||
.Sh DESCRIPTION
|
||||
For each operand that names a
|
||||
@ -70,12 +70,17 @@ lexicographical order.
|
||||
.Pp
|
||||
The following options are available:
|
||||
.Bl -tag -width indent
|
||||
.It Fl ?
|
||||
Displays a short list of valid options.
|
||||
.It Fl A
|
||||
List all entries except for
|
||||
.Ql \&.
|
||||
and
|
||||
.Ql \&.. .
|
||||
Always set for the super-user.
|
||||
.It Fl B
|
||||
Force printing of non-graphic characters in file names as \\xxx,
|
||||
where xxx is the numeric value of the character in octal.
|
||||
.It Fl C
|
||||
Force multi-column output; this is the default when output is to a terminal.
|
||||
.It Fl F
|
||||
@ -101,8 +106,9 @@ Display whiteouts when scanning directories.
|
||||
Include directory entries whose names begin with a
|
||||
dot (.).
|
||||
.It Fl b
|
||||
Force printing of non-graphic characters in file names as \\xxx,
|
||||
where xxx is the numeric value of the character in octal.
|
||||
As
|
||||
.Fl B ,
|
||||
but use C escape codes whenever possible.
|
||||
.It Fl c
|
||||
Use time when file status was last changed for sorting or printing.
|
||||
.It Fl d
|
||||
|
16
bin/ls/ls.c
16
bin/ls/ls.c
@ -45,7 +45,7 @@ static const char copyright[] =
|
||||
static char sccsid[] = "@(#)ls.c 8.5 (Berkeley) 4/2/94";
|
||||
#else
|
||||
static const char rcsid[] =
|
||||
"$Id: ls.c,v 1.17 1997/09/18 06:42:27 sef Exp $";
|
||||
"$Id: ls.c,v 1.18 1998/04/21 22:02:00 des Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -89,6 +89,7 @@ int f_newline; /* if precede with newline */
|
||||
int f_nonprint; /* show unprintables as ? */
|
||||
int f_nosort; /* don't sort output */
|
||||
int f_octal; /* show unprintables as \xxx */
|
||||
int f_octal_escape; /* like f_octal but use C escapes if possible */
|
||||
int f_recursive; /* ls subdirectories also */
|
||||
int f_reversesort; /* reverse whatever sort is used */
|
||||
int f_sectime; /* print the real time for all files */
|
||||
@ -136,7 +137,7 @@ main(argc, argv)
|
||||
f_listdot = 1;
|
||||
|
||||
fts_options = FTS_PHYSICAL;
|
||||
while ((ch = getopt(argc, argv, "1ACFLRTWabcdfgikloqrstu")) != -1) {
|
||||
while ((ch = getopt(argc, argv, "?1ABCFLRTWabcdfgikloqrstu")) != -1) {
|
||||
switch (ch) {
|
||||
/*
|
||||
* The -1, -C and -l options all override each other so shell
|
||||
@ -146,6 +147,11 @@ main(argc, argv)
|
||||
f_singlecol = 1;
|
||||
f_column = f_longform = 0;
|
||||
break;
|
||||
case 'B':
|
||||
f_nonprint = 0;
|
||||
f_octal = 1;
|
||||
f_octal_escape = 0;
|
||||
break;
|
||||
case 'C':
|
||||
f_column = 1;
|
||||
f_longform = f_singlecol = 0;
|
||||
@ -201,6 +207,7 @@ main(argc, argv)
|
||||
case 'q':
|
||||
f_nonprint = 1;
|
||||
f_octal = 0;
|
||||
f_octal_escape = 0;
|
||||
break;
|
||||
case 'r':
|
||||
f_reversesort = 1;
|
||||
@ -218,8 +225,9 @@ main(argc, argv)
|
||||
f_whiteout = 1;
|
||||
break;
|
||||
case 'b':
|
||||
f_octal = 1;
|
||||
f_nonprint = 0;
|
||||
f_octal = 0;
|
||||
f_octal_escape = 1;
|
||||
break;
|
||||
default:
|
||||
case '?':
|
||||
@ -432,7 +440,7 @@ display(p, list)
|
||||
prcopy(cur->fts_name, cur->fts_name, cur->fts_namelen);
|
||||
if (cur->fts_namelen > maxlen)
|
||||
maxlen = cur->fts_namelen;
|
||||
if (f_octal) {
|
||||
if (f_octal || f_octal_escape) {
|
||||
int t = len_octal(cur->fts_name, cur->fts_namelen);
|
||||
if (t > maxlen) maxlen = t;
|
||||
}
|
||||
|
@ -35,7 +35,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* from: @(#)ls.h 8.1 (Berkeley) 5/31/93
|
||||
* $Id: ls.h,v 1.7 1997/08/07 15:33:48 steve Exp $
|
||||
* $Id: ls.h,v 1.8 1998/04/21 22:02:00 des Exp $
|
||||
*/
|
||||
|
||||
#define NO_PRINT 1
|
||||
@ -47,6 +47,7 @@ extern int f_flags; /* show flags associated with a file */
|
||||
extern int f_inode; /* print inode */
|
||||
extern int f_longform; /* long listing format */
|
||||
extern int f_octal; /* print unprintables in octal */
|
||||
extern int f_octal_escape; /* like f_octal but use C escapes if possible */
|
||||
extern int f_sectime; /* print the real time for all files */
|
||||
extern int f_size; /* list size in short listing */
|
||||
extern int f_statustime; /* use time of last mode change */
|
||||
|
@ -39,7 +39,7 @@
|
||||
static char sccsid[] = "@(#)print.c 8.4 (Berkeley) 4/17/94";
|
||||
#else
|
||||
static const char rcsid[] =
|
||||
"$Id: print.c,v 1.14 1997/08/07 22:28:24 steve Exp $";
|
||||
"$Id: print.c,v 1.15 1998/04/21 22:02:01 des Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -127,7 +127,7 @@ printlong(dp)
|
||||
printtime(sp->st_ctime);
|
||||
else
|
||||
printtime(sp->st_mtime);
|
||||
if (f_octal) (void)prn_octal(p->fts_name);
|
||||
if (f_octal || f_octal_escape) (void)prn_octal(p->fts_name);
|
||||
else (void)printf("%s", p->fts_name);
|
||||
if (f_type)
|
||||
(void)printtype(sp->st_mode);
|
||||
@ -223,7 +223,8 @@ printaname(p, inodefield, sizefield)
|
||||
if (f_size)
|
||||
chcnt += printf("%*qd ",
|
||||
(int)sizefield, howmany(sp->st_blocks, blocksize));
|
||||
chcnt += f_octal ? prn_octal(p->fts_name) : printf("%s", p->fts_name);
|
||||
chcnt += (f_octal || f_octal_escape) ? prn_octal(p->fts_name)
|
||||
: printf("%s", p->fts_name);
|
||||
if (f_type)
|
||||
chcnt += printtype(sp->st_mode);
|
||||
return (chcnt);
|
||||
@ -304,9 +305,9 @@ printlink(p)
|
||||
return;
|
||||
}
|
||||
path[lnklen] = '\0';
|
||||
if (f_octal) {
|
||||
(void)printf(" -> ");
|
||||
(void)prn_octal(path);
|
||||
if (f_octal || f_octal_escape) {
|
||||
(void)printf(" -> ");
|
||||
(void)prn_octal(path);
|
||||
}
|
||||
else (void)printf(" -> %s", path);
|
||||
}
|
||||
|
@ -39,7 +39,7 @@
|
||||
static char sccsid[] = "@(#)util.c 8.3 (Berkeley) 4/2/94";
|
||||
#else
|
||||
static const char rcsid[] =
|
||||
"$Id: util.c,v 1.11 1997/08/07 22:28:25 steve Exp $";
|
||||
"$Id: util.c,v 1.12 1998/04/21 22:02:01 des Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -73,7 +73,15 @@ prcopy(src, dest, len)
|
||||
* The fts system makes it difficult to replace fts_name with a different-
|
||||
* sized string, so we just calculate the real length here and do the
|
||||
* conversion in prn_octal()
|
||||
*
|
||||
* XXX when using f_octal_escape (-b) rather than f_octal (-B), the
|
||||
* length computed by len_octal may be too big. I just can't be buggered
|
||||
* to fix this as an efficient fix would involve a lookup table. Same goes
|
||||
* for the rather inelegant code in prn_octal.
|
||||
*
|
||||
* DES 1998/04/23
|
||||
*/
|
||||
|
||||
int
|
||||
len_octal(s, len)
|
||||
char *s;
|
||||
@ -82,7 +90,7 @@ len_octal(s, len)
|
||||
int r;
|
||||
|
||||
while (len--)
|
||||
if (isprint(*s++)) r++; else r += 4;
|
||||
if (isprint(*s++)) r++; else r += 4;
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -95,14 +103,62 @@ prn_octal(s)
|
||||
|
||||
while ((ch = *s++))
|
||||
{
|
||||
if (isprint(ch)) putchar(ch), len++;
|
||||
else {
|
||||
putchar('\\');
|
||||
putchar('0' + (ch >> 6));
|
||||
putchar('0' + ((ch >> 3) & 3));
|
||||
putchar('0' + (ch & 3));
|
||||
len += 4;
|
||||
}
|
||||
if (isprint(ch)) putchar(ch), len++;
|
||||
else if (f_octal_escape) {
|
||||
putchar('\\');
|
||||
switch (ch) {
|
||||
case 0:
|
||||
putchar('0');
|
||||
break;
|
||||
case '\\':
|
||||
putchar('\\');
|
||||
break;
|
||||
case '\?':
|
||||
putchar('?');
|
||||
break;
|
||||
case '\'':
|
||||
putchar('\'');
|
||||
break;
|
||||
case '\"':
|
||||
putchar('"');
|
||||
break;
|
||||
case '\a':
|
||||
putchar('a');
|
||||
break;
|
||||
case '\b':
|
||||
putchar('b');
|
||||
break;
|
||||
case '\f':
|
||||
putchar('f');
|
||||
break;
|
||||
case '\n':
|
||||
putchar('n');
|
||||
break;
|
||||
case '\r':
|
||||
putchar('r');
|
||||
break;
|
||||
case '\t':
|
||||
putchar('t');
|
||||
break;
|
||||
case '\v':
|
||||
putchar('v');
|
||||
break;
|
||||
default:
|
||||
putchar('0' + (ch >> 6));
|
||||
putchar('0' + ((ch >> 3) & 3));
|
||||
putchar('0' + (ch & 3));
|
||||
len += 2;
|
||||
break;
|
||||
}
|
||||
len += 2;
|
||||
}
|
||||
else {
|
||||
putchar('\\');
|
||||
putchar('0' + (ch >> 6));
|
||||
putchar('0' + ((ch >> 3) & 3));
|
||||
putchar('0' + (ch & 3));
|
||||
len += 4;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user