diff options
author | Dag-Erling Smørgrav <des@FreeBSD.org> | 1998-04-24 07:49:51 +0000 |
---|---|---|
committer | Dag-Erling Smørgrav <des@FreeBSD.org> | 1998-04-24 07:49:51 +0000 |
commit | 0d86878ce09d3a4937cb8df83dc3451fecd3c3ac (patch) | |
tree | a3a03aebc1f45d73498777e0325137a638d7e78a /bin/ls/util.c | |
parent | ca67f4589bea1f87b4d80957107f36e88312ab5e (diff) | |
download | src-0d86878ce09d3a4937cb8df83dc3451fecd3c3ac.tar.gz src-0d86878ce09d3a4937cb8df83dc3451fecd3c3ac.zip |
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.
Notes
Notes:
svn path=/head/; revision=35417
Diffstat (limited to 'bin/ls/util.c')
-rw-r--r-- | bin/ls/util.c | 76 |
1 files changed, 66 insertions, 10 deletions
diff --git a/bin/ls/util.c b/bin/ls/util.c index e445b993a68d..f72ef6cbacb3 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; } |