Source-Changes-HG archive

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

[src/trunk]: src/bin/ls Do not modify the file name when not printing non-pri...



details:   https://anonhg.NetBSD.org/src/rev/6c64bbb7a128
branches:  trunk
changeset: 488074:6c64bbb7a128
user:      assar <assar%NetBSD.org@localhost>
date:      Sat Jun 17 16:11:25 2000 +0000

description:
Do not modify the file name when not printing non-printables, also do
it consistently with the file name and possible symbolic link target.

fixes bin/10385 and bin/10384

diffstat:

 bin/ls/extern.h |   4 ++--
 bin/ls/ls.c     |   6 ++----
 bin/ls/ls.h     |   3 ++-
 bin/ls/print.c  |  16 ++++++++++++----
 bin/ls/util.c   |  20 ++++++++++----------
 5 files changed, 28 insertions(+), 21 deletions(-)

diffs (147 lines):

diff -r 8c3bf65c9aa2 -r 6c64bbb7a128 bin/ls/extern.h
--- a/bin/ls/extern.h   Sat Jun 17 15:05:26 2000 +0000
+++ b/bin/ls/extern.h   Sat Jun 17 16:11:25 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: extern.h,v 1.10 1999/05/17 12:16:03 lukem Exp $        */
+/*     $NetBSD: extern.h,v 1.11 2000/06/17 16:11:25 assar Exp $        */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -48,7 +48,7 @@
 
 int     ls_main __P((int, char *[]));
 
-void    prcopy __P((char *, char *, int));
+void    printescaped __P((const char *));
 void    printacol __P((DISPLAY *));
 void    printcol __P((DISPLAY *));
 void    printlong __P((DISPLAY *));
diff -r 8c3bf65c9aa2 -r 6c64bbb7a128 bin/ls/ls.c
--- a/bin/ls/ls.c       Sat Jun 17 15:05:26 2000 +0000
+++ b/bin/ls/ls.c       Sat Jun 17 16:11:25 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ls.c,v 1.41 2000/03/06 11:03:45 enami Exp $    */
+/*     $NetBSD: ls.c,v 1.42 2000/06/17 16:11:25 assar Exp $    */
 
 /*
  * Copyright (c) 1989, 1993, 1994
@@ -46,7 +46,7 @@
 #if 0
 static char sccsid[] = "@(#)ls.c       8.7 (Berkeley) 8/5/94";
 #else
-__RCSID("$NetBSD: ls.c,v 1.41 2000/03/06 11:03:45 enami Exp $");
+__RCSID("$NetBSD: ls.c,v 1.42 2000/06/17 16:11:25 assar Exp $");
 #endif
 #endif /* not lint */
 
@@ -472,8 +472,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 (needstats) {
diff -r 8c3bf65c9aa2 -r 6c64bbb7a128 bin/ls/ls.h
--- a/bin/ls/ls.h       Sat Jun 17 15:05:26 2000 +0000
+++ b/bin/ls/ls.h       Sat Jun 17 16:11:25 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ls.h,v 1.10 1999/02/17 15:28:09 kleink Exp $   */
+/*     $NetBSD: ls.h,v 1.11 2000/06/17 16:11:25 assar Exp $    */
 
 /*
  * Copyright (c) 1989, 1993
@@ -51,6 +51,7 @@
 extern int f_statustime;       /* use time of last mode change */
 extern int f_type;             /* add type character for non-regular files */
 extern int f_typedir;          /* add type character for directories */
+extern int f_nonprint;         /* show unprintables as ? */
 
 typedef struct {
        FTSENT *list;
diff -r 8c3bf65c9aa2 -r 6c64bbb7a128 bin/ls/print.c
--- a/bin/ls/print.c    Sat Jun 17 15:05:26 2000 +0000
+++ b/bin/ls/print.c    Sat Jun 17 16:11:25 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: print.c,v 1.27 1999/11/09 15:06:31 drochner Exp $      */
+/*     $NetBSD: print.c,v 1.28 2000/06/17 16:11:26 assar Exp $ */
 
 /*
  * Copyright (c) 1989, 1993, 1994
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)print.c    8.5 (Berkeley) 7/28/94";
 #else
-__RCSID("$NetBSD: print.c,v 1.27 1999/11/09 15:06:31 drochner Exp $");
+__RCSID("$NetBSD: print.c,v 1.28 2000/06/17 16:11:26 assar Exp $");
 #endif
 #endif /* not lint */
 
@@ -132,7 +132,11 @@
                        printtime(sp->st_ctime);
                else
                        printtime(sp->st_mtime);
-               (void)printf("%s", p->fts_name);
+               if (f_nonprint)
+                       printescaped(p->fts_name);
+               else
+                       (void)printf("%s", p->fts_name);
+
                if (f_type || (f_typedir && S_ISDIR(sp->st_mode)))
                        (void)printtype(sp->st_mode);
                if (S_ISLNK(sp->st_mode))
@@ -379,5 +383,9 @@
                return;
        }
        path[lnklen] = '\0';
-       (void)printf(" -> %s", path);
+       (void)printf(" -> ");
+       if (f_nonprint)
+               printescaped(path);
+       else
+               (void)printf("%s", path);
 }
diff -r 8c3bf65c9aa2 -r 6c64bbb7a128 bin/ls/util.c
--- a/bin/ls/util.c     Sat Jun 17 15:05:26 2000 +0000
+++ b/bin/ls/util.c     Sat Jun 17 16:11:25 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: util.c,v 1.17 1999/02/17 15:28:09 kleink Exp $ */
+/*     $NetBSD: util.c,v 1.18 2000/06/17 16:11:26 assar Exp $  */
 
 /*
  * Copyright (c) 1989, 1993, 1994
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)util.c     8.5 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: util.c,v 1.17 1999/02/17 15:28:09 kleink Exp $");
+__RCSID("$NetBSD: util.c,v 1.18 2000/06/17 16:11:26 assar Exp $");
 #endif
 #endif /* not lint */
 
@@ -58,16 +58,16 @@
 #include "extern.h"
 
 void
-prcopy(src, dest, len)
-       char *src, *dest;
-       int len;
+printescaped(src)
+       const char *src;
 {
-       int ch;
+       int c;
 
-       while (len--) {
-               ch = *src++;
-               *dest++ = isprint(ch) ? ch : '?';
-       }
+       while ((c = *src++) != '\0')
+               if (isprint(c))
+                       (void)putchar(c);
+               else
+                       (void)putchar('?');
 }
 
 void



Home | Main Index | Thread Index | Old Index