summaryrefslogtreecommitdiffstats
path: root/bin/ls
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>1998-04-24 07:49:51 +0000
committerdes <des@FreeBSD.org>1998-04-24 07:49:51 +0000
commitaedfea1af81dbce4903bc916468988620f4c150d (patch)
treeb2bd496713c9a27a50dd965ab7f20a1744c0ebf7 /bin/ls
parentabb0f6fda9e4fd0855dbe32688b31270fcbf0099 (diff)
downloadFreeBSD-src-aedfea1af81dbce4903bc916468988620f4c150d.zip
FreeBSD-src-aedfea1af81dbce4903bc916468988620f4c150d.tar.gz
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.
Diffstat (limited to 'bin/ls')
-rw-r--r--bin/ls/ls.114
-rw-r--r--bin/ls/ls.c16
-rw-r--r--bin/ls/ls.h3
-rw-r--r--bin/ls/print.c13
-rw-r--r--bin/ls/util.c76
5 files changed, 97 insertions, 25 deletions
diff --git a/bin/ls/ls.1 b/bin/ls/ls.1
index b34aeee..945ac7c 100644
--- a/bin/ls/ls.1
+++ b/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
diff --git a/bin/ls/ls.c b/bin/ls/ls.c
index 5c6da7e..7fdad3d 100644
--- a/bin/ls/ls.c
+++ b/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;
}
diff --git a/bin/ls/ls.h b/bin/ls/ls.h
index 1a64f7c..eb13c61 100644
--- a/bin/ls/ls.h
+++ b/bin/ls/ls.h
@@ -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 */
diff --git a/bin/ls/print.c b/bin/ls/print.c
index 26b35d7..84e0fe9 100644
--- a/bin/ls/print.c
+++ b/bin/ls/print.c
@@ -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);
}
diff --git a/bin/ls/util.c b/bin/ls/util.c
index e445b99..f72ef6c 100644
--- a/bin/ls/util.c
+++ b/bin/ls/util.c
@@ -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;
}
OpenPOWER on IntegriCloud