I have a proposed patch to ls that fixes bin/19354 and makes things
more consistent.  Comments?

/assar

Index: extern.h
===================================================================
RCS file: /home/ncvs/src/bin/ls/extern.h,v
retrieving revision 1.13
diff -u -w -r1.13 extern.h
--- extern.h    2000/06/17 14:19:31     1.13
+++ extern.h    2000/06/22 22:36:10
@@ -43,13 +43,13 @@
 int     statcmp __P((const FTSENT *, const FTSENT *));
 int     revstatcmp __P((const FTSENT *, const FTSENT *));
 
-void    prcopy __P((char *, char *, int));
 void    printcol __P((DISPLAY *));
 void    printlong __P((DISPLAY *));
 void    printscol __P((DISPLAY *));
 void    usage __P((void));
-int     len_octal __P((char *, int));
-int     prn_octal __P((char *));
+int     len_octal __P((const char *, int));
+int     prn_octal __P((const char *));
+int     prn_printable __P((const char *));
 #ifdef COLORLS
 void    parsecolors __P((char *cs));
 void     colorquit __P((int));
Index: ls.c
===================================================================
RCS file: /home/ncvs/src/bin/ls/ls.c,v
retrieving revision 1.41
diff -u -w -r1.41 ls.c
--- ls.c        2000/06/17 14:19:31     1.41
+++ ls.c        2000/06/22 22:36:12
@@ -566,8 +566,6 @@
                                continue;
                        }
                }
-               if (f_nonprint)
-                       prcopy(cur->fts_name, cur->fts_name, cur->fts_namelen);
                if (cur->fts_namelen > maxlen)
                        maxlen = cur->fts_namelen;
                if (f_octal || f_octal_escape) {
Index: ls.h
===================================================================
RCS file: /home/ncvs/src/bin/ls/ls.h,v
retrieving revision 1.13
diff -u -w -r1.13 ls.h
--- ls.h        2000/06/05 02:14:01     1.13
+++ ls.h        2000/06/22 22:36:16
@@ -48,6 +48,7 @@
 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_nonprint;         /* show unprintables as ? */
 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: /home/ncvs/src/bin/ls/print.c,v
retrieving revision 1.35
diff -u -w -r1.35 print.c
--- print.c     2000/06/21 21:49:57     1.35
+++ print.c     2000/06/22 22:36:18
@@ -112,6 +112,21 @@
        }
 }
 
+/*
+ * print name in current style
+ */
+static int
+printname(name)
+       const char *name;
+{
+       if (f_octal || f_octal_escape)
+               return prn_octal(name);
+       else if (f_nonprint)
+               return prn_printable(name);
+       else
+               return printf("%s", name);
+}
+
 void
 printlong(dp)
        DISPLAY *dp;
@@ -166,8 +181,7 @@
                if (f_color)
                        color_printed = colortype(sp->st_mode);
 #endif
-               if (f_octal || f_octal_escape) (void)prn_octal(p->fts_name);
-               else (void)printf("%s", p->fts_name);
+               (void)printname(p->fts_name);
 #ifdef COLORLS
                if (f_color && color_printed)
                        endcolor(0);
@@ -278,8 +292,7 @@
        if (f_color)
                color_printed = colortype(sp->st_mode);
 #endif
-       chcnt += (f_octal || f_octal_escape) ? prn_octal(p->fts_name)
-                                            : printf("%s", p->fts_name);
+       chcnt += printname(p->fts_name);
 #ifdef COLORLS
        if (f_color && color_printed)
                endcolor(0);
@@ -494,9 +507,6 @@
                return;
        }
        path[lnklen] = '\0';
-       if (f_octal || f_octal_escape) {
                (void)printf(" -> ");
-               (void)prn_octal(path);
-       }
-       else (void)printf(" -> %s", path);
+       printname(path);
 }
Index: util.c
===================================================================
RCS file: /home/ncvs/src/bin/ls/util.c,v
retrieving revision 1.21
diff -u -w -r1.21 util.c
--- util.c      2000/06/06 07:29:43     1.21
+++ util.c      2000/06/22 22:36:18
@@ -56,17 +56,19 @@
 #include "ls.h"
 #include "extern.h"
 
-void
-prcopy(src, dest, len)
-       char *src, *dest;
-       int len;
+int
+prn_printable(s)
+       const char *s;
 {
-       unsigned char ch;
+       unsigned char c;
+       int n;
 
-       while (len--) {
-               ch = *src++;
-               *dest++ = isprint(ch) ? ch : '?';
-       }
+       for (n = 0; (c = *s) != '\0'; ++s, ++n)
+               if (isprint(c))
+                       putchar(c);
+               else
+                       putchar('?');
+       return n;
 }
 
 /*
@@ -84,7 +86,7 @@
 
 int
 len_octal(s, len)
-        char *s;
+        const char *s;
        int len;
 {
        int r = 0;
@@ -96,7 +98,7 @@
 
 int
 prn_octal(s)
-        char *s;
+        const char *s;
 {
         unsigned char ch;
        int len = 0;


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message

Reply via email to