make display line up if block/char devices displayed with other
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Mon, 29 Jun 1992 06:43:48 +0000 (22:43 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Mon, 29 Jun 1992 06:43:48 +0000 (22:43 -0800)
files.  (Jan-Simon has *way* too much free time...)

SCCS-vsn: bin/ls/ls.c 5.67
SCCS-vsn: bin/ls/ls.h 5.18
SCCS-vsn: bin/ls/print.c 5.36

usr/src/bin/ls/ls.c
usr/src/bin/ls/ls.h
usr/src/bin/ls/print.c

index 735a6c3..e570572 100644 (file)
@@ -15,7 +15,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)ls.c       5.66 (Berkeley) %G%";
+static char sccsid[] = "@(#)ls.c       5.67 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -306,9 +306,9 @@ traverse(argc, argv, options)
 }
 
 /*
 }
 
 /*
- * Display() takes a linked list of FTSENT structures passes the list along
- * with any other necessary information to the print function (printfcn()).
- * points to the parent directory of the display list.
+ * Display() takes a linked list of FTSENT structures and passes the list
+ * along with any other necessary information to the print function.  P
+ * points to the parent directory of the display list.
  */
 static void
 display(p, list)
  */
 static void
 display(p, list)
@@ -321,7 +321,7 @@ display(p, list)
        NAMES *np;
        u_long btotal, maxblock, maxinode, maxlen, maxnlink;
        u_quad_t maxsize;
        NAMES *np;
        u_long btotal, maxblock, maxinode, maxlen, maxnlink;
        u_quad_t maxsize;
-       int flen, glen, ulen, maxflags, maxgroup, maxuser;
+       int bcfile, flen, glen, ulen, maxflags, maxgroup, maxuser;
        int entries, needstats;
        char *user, *group, *flags, buf[20];    /* 32 bits == 10 digits */
 
        int entries, needstats;
        char *user, *group, *flags, buf[20];    /* 32 bits == 10 digits */
 
@@ -338,6 +338,7 @@ display(p, list)
        needstats = f_inode || f_longform || f_size;
        flen = 0;
        btotal = maxblock = maxinode = maxlen = maxnlink = 0;
        needstats = f_inode || f_longform || f_size;
        flen = 0;
        btotal = maxblock = maxinode = maxlen = maxnlink = 0;
+       bcfile = 0;
        maxuser = maxgroup = maxflags = 0;
        maxsize = 0;
        for (cur = list, entries = 0; cur; cur = cur->fts_link) {
        maxuser = maxgroup = maxflags = 0;
        maxsize = 0;
        for (cur = list, entries = 0; cur; cur = cur->fts_link) {
@@ -404,6 +405,10 @@ display(p, list)
                                np->group = &np->data[ulen + 1];
                                (void)strcpy(np->group, group);
 
                                np->group = &np->data[ulen + 1];
                                (void)strcpy(np->group, group);
 
+                               if (S_ISCHR(sp->st_mode) ||
+                                   S_ISBLK(sp->st_mode))
+                                       bcfile = 1;
+
                                if (f_flags) {
                                        np->flags = &np->data[ulen + glen + 2];
                                        (void)strcpy(np->flags, flags);
                                if (f_flags) {
                                        np->flags = &np->data[ulen + glen + 2];
                                        (void)strcpy(np->flags, flags);
@@ -421,6 +426,7 @@ display(p, list)
        d.entries = entries;
        d.maxlen = maxlen;
        if (needstats) {
        d.entries = entries;
        d.maxlen = maxlen;
        if (needstats) {
+               d.bcfile = bcfile;
                d.btotal = btotal;
                d.s_block = snprintf(buf, sizeof(buf), "%lu", maxblock);
                d.s_flags = maxflags;
                d.btotal = btotal;
                d.s_block = snprintf(buf, sizeof(buf), "%lu", maxblock);
                d.s_flags = maxflags;
index 629a56f..5e1dbd9 100644 (file)
@@ -7,7 +7,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)ls.h        5.17 (Berkeley) %G%
+ *     @(#)ls.h        5.18 (Berkeley) %G%
  */
 
 #define NO_PRINT       1
  */
 
 #define NO_PRINT       1
@@ -26,6 +26,7 @@ extern int f_type;            /* add type character for non-regular files */
 typedef struct {
        FTSENT *list;
        u_long btotal;
 typedef struct {
        FTSENT *list;
        u_long btotal;
+       int bcfile;
        int entries;
        int maxlen;
        int s_block;
        int entries;
        int maxlen;
        int s_block;
index 5175879..7d65dd8 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)print.c    5.35 (Berkeley) %G%";
+static char sccsid[] = "@(#)print.c    5.36 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -80,6 +80,9 @@ printlong(dp)
                if (S_ISCHR(sp->st_mode) || S_ISBLK(sp->st_mode))
                        (void)printf("%3d, %3d ",
                            major(sp->st_rdev), minor(sp->st_rdev));
                if (S_ISCHR(sp->st_mode) || S_ISBLK(sp->st_mode))
                        (void)printf("%3d, %3d ",
                            major(sp->st_rdev), minor(sp->st_rdev));
+               else if (dp->bcfile)
+                       (void)printf("%*s%*qd ",
+                           8 - dp->s_size, "", dp->s_size, sp->st_size);
                else
                        (void)printf("%*qd ", dp->s_size, sp->st_size);
                if (f_accesstime)
                else
                        (void)printf("%*qd ", dp->s_size, sp->st_size);
                if (f_accesstime)