Source-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src/bin/ls



"Valeriy E. Ushakov" <uwe%ptc.spbu.ru@localhost> wrote:
> On Sun, Sep 14, 2003 at 19:16:08 +0000, Jan Schaumann wrote:

> > Implement '-b' option, which, following FreeBSD, Linux and (I think) Solaris
> > prints octal escapes for nongraphic characters.
> 
> The logical set shoule include -w, and, probably, -B.

How about the attached patch?

-Jan

-- 
"I am so amazingly cool you could keep a side of meat in me for a 
month. I am so hip I have difficulty seeing over my pelvis."
Index: ls.1
===================================================================
RCS file: /cvsroot/src/bin/ls/ls.1,v
retrieving revision 1.43
diff -b -u -r1.43 ls.1
--- ls.1        2003/09/14 19:16:06     1.43
+++ ls.1        2003/09/15 00:29:33
@@ -40,7 +40,7 @@
 .Nd list directory contents
 .Sh SYNOPSIS
 .Nm
-.Op Fl AabCcdFfgikLlmnopqRrSsTtuWx1
+.Op Fl AaBbCcdFfgikLlmnopqRrSsTtuWwx1
 .Op Ar
 .Sh DESCRIPTION
 For each operand that names a
@@ -77,8 +77,13 @@
 Include directory entries whose names begin with a
 dot
 .Pq Sq \&. .
+.It Fl B
+Force printing of non-printable characters in file names as \\xxx, where xxx
+is the numeric value of the character in octal.
 .It Fl b
-Print octal escapes for nongraphic characters.
+As
+.Fl B ,
+but use C escape codes whenever possible.
 .It Fl C
 Force multi-column output; this is the default when output is to a terminal.
 .It Fl c
@@ -184,6 +189,9 @@
 .Pq Fl t
 or printing
 .Pq Fl l .
+.It Fl w
+Force raw printing of non-printable characters.
+This is the default when output is not to a terminal.
 .It Fl W
 Display whiteouts when scanning directories.
 .It Fl x
@@ -194,6 +202,15 @@
 Force output to be one entry per line.
 This is the default when output is not to a terminal.
 .El
+.Pp
+The
+.Fl B ,
+.Fl b ,
+.Fl w
+and
+.Fl q
+options all override each other; the last one specified determines
+the format used for non-printable characters.
 .Pp
 The
 .Fl 1 ,
Index: ls.c
===================================================================
RCS file: /cvsroot/src/bin/ls/ls.c,v
retrieving revision 1.51
diff -b -u -r1.51 ls.c
--- ls.c        2003/09/14 19:16:06     1.51
+++ ls.c        2003/09/15 00:29:34
@@ -86,7 +86,6 @@
 int f_accesstime;              /* use time of last access */
 int f_column;                  /* columnated format */
 int f_columnacross;            /* columnated format, sorted across */
-int f_escape;                  /* print octal escapes for nongraphic 
characters */
 int f_flags;                   /* show flags associated with a file */
 int f_grouponly;               /* long listing without owner */
 int f_inode;                   /* print inode */
@@ -96,6 +95,8 @@
 int f_nonprint;                        /* show unprintables as ? */
 int f_nosort;                  /* don't sort output */
 int f_numericonly;             /* don't convert uid/gid to name */
+int f_octal;                   /* print octal escapes for nongraphic 
characters */
+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 */
@@ -134,7 +135,7 @@
                f_listdot = 1;
 
        fts_options = FTS_PHYSICAL;
-       while ((ch = getopt(argc, argv, "1ACFLRSTWabcdfgiklmnopqrstux")) != -1) 
{
+       while ((ch = getopt(argc, argv, "1ABCFLRSTWabcdfgiklmnopqrstuwx")) != 
-1) {
                switch (ch) {
                /*
                 * The -1, -C, -l, -m and -x options all override each other so
@@ -195,10 +196,17 @@
                case 'A':
                        f_listdot = 1;
                        break;
-               /* the -b option turns off the -q option. */
+               /* the -B option turns off the -b, -q and -w options. */
+               case 'B':
+                       f_nonprint = 0;
+                       f_octal = 1;
+                       f_octal_escape = 0;
+                       break;
+               /* the -b option turns off the -B, -q and -w options. */
                case 'b':
-                       f_escape = 1;
                        f_nonprint = 0;
+                       f_octal = 0;
+                       f_octal_escape = 1;
                        break;
                /* The -d option turns off the -R option. */
                case 'd':
@@ -224,10 +232,11 @@
                case 'p':
                        f_typedir = 1;
                        break;
-               /* the -q option turns off the -b option. */
+               /* the -q option turns off the -B, -b and -w options. */
                case 'q':
                        f_nonprint = 1;
-                       f_escape = 0;
+                       f_octal = 0;
+                       f_octal_escape = 0;
                        break;
                case 'r':
                        f_reversesort = 1;
@@ -246,6 +255,12 @@
                        break;
                case 'W':
                        f_whiteout = 1;
+                       break;
+               /* the -w option turns off the -B, -b and -q options. */
+               case 'w':
+                       f_nonprint = 0;
+                       f_octal = 0;
+                       f_octal_escape = 0;
                        break;
                default:
                case '?':
Index: ls.h
===================================================================
RCS file: /cvsroot/src/bin/ls/ls.h,v
retrieving revision 1.14
diff -b -u -r1.14 ls.h
--- ls.h        2003/09/14 19:16:06     1.14
+++ ls.h        2003/09/15 00:29:34
@@ -39,11 +39,12 @@
 extern long blocksize;         /* block size units */
 
 extern int f_accesstime;       /* use time of last access */
-extern int f_escape;           /* print octal escapes for nongraphic 
characters */
 extern int f_flags;            /* show flags associated with a file */
 extern int f_grouponly;                /* long listing without owner */
 extern int f_inode;            /* print inode */
 extern int f_longform;         /* long listing format */
+extern int f_octal;            /* print octal escapes for nongraphic 
characters */
+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 */
Index: print.c
===================================================================
RCS file: /cvsroot/src/bin/ls/print.c,v
retrieving revision 1.36
diff -b -u -r1.36 print.c
--- print.c     2003/09/14 19:16:06     1.36
+++ print.c     2003/09/15 00:29:35
@@ -129,7 +129,7 @@
                        printtime(sp->st_ctime);
                else
                        printtime(sp->st_mtime);
-               if (f_escape)
+               if (f_octal || f_octal_escape)
                        (void)safe_print(p->fts_name);
                else if (f_nonprint)
                        (void)printescaped(p->fts_name);
@@ -297,7 +297,7 @@
        if (f_size)
                chcnt += printf("%*llu ", sizefield,
                    (long long)howmany(sp->st_blocks, blocksize));
-       if (f_escape)
+       if (f_octal || f_octal_escape)
                chcnt += safe_print(p->fts_name);
        else if (f_nonprint)
                chcnt += printescaped(p->fts_name);
@@ -377,7 +377,7 @@
        }
        path[lnklen] = '\0';
        (void)printf(" -> ");
-       if (f_escape)
+       if (f_octal || f_octal_escape)
                (void)safe_print(path);
        else if (f_nonprint)
                (void)printescaped(path);
Index: util.c
===================================================================
RCS file: /cvsroot/src/bin/ls/util.c,v
retrieving revision 1.26
diff -b -u -r1.26 util.c
--- util.c      2003/09/14 19:16:07     1.26
+++ util.c      2003/09/15 00:29:35
@@ -61,7 +61,12 @@
 {
        size_t len;
        char *name;
+       int flags;
 
+       flags = VIS_NL | VIS_OCTAL;
+       if (f_octal_escape)
+               flags |= VIS_CSTYLE;
+
        len = strlen(src);
        if (len != 0 && SIZE_T_MAX/len <= 4) {
                errx(EXIT_FAILURE, "%s: name too long", src);
@@ -70,7 +75,7 @@
 
        name = (char *)malloc(4*len+1);
        if (name != NULL) {
-               len = strvis(name, src, VIS_NL | VIS_CSTYLE);
+               len = strvis(name, src, flags);
                printf("%s", name);
                free(name);
                return len;
@@ -98,7 +103,7 @@
 {
 
        (void)fprintf(stderr,
-           "usage: ls [-AabCcdFfgikLlmnopqRrSsTtuWx1] [file ...]\n");
+           "usage: ls [-AaBbCcdFfgikLlmnopqRrSsTtuWwx1] [file ...]\n");
        exit(EXIT_FAILURE);
        /* NOTREACHED */
 }

Attachment: pgpxYmbPw1dvM.pgp
Description: PGP signature



Home | Main Index | Thread Index | Old Index