prettyness police
[unix-history] / usr / src / bin / ls / print.c
index 59188e5..f8b9478 100644 (file)
@@ -1,6 +1,6 @@
 /*
 /*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1989, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  * Michael Fischbein.
  *
  * This code is derived from software contributed to Berkeley by
  * Michael Fischbein.
@@ -9,22 +9,25 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)print.c    5.34 (Berkeley) %G%";
+static char sccsid[] = "@(#)print.c    8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #include <sys/stat.h>
 #endif /* not lint */
 
 #include <sys/param.h>
 #include <sys/stat.h>
-#include <fts.h>
-#include <time.h>
+
+#include <err.h>
 #include <errno.h>
 #include <errno.h>
+#include <fts.h>
 #include <grp.h>
 #include <pwd.h>
 #include <grp.h>
 #include <pwd.h>
-#include <utmp.h>
-#include <unistd.h>
-#include <tzfile.h>
-#include <stdlib.h>
 #include <stdio.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <string.h>
+#include <time.h>
+#include <tzfile.h>
+#include <unistd.h>
+#include <utmp.h>
+
 #include "ls.h"
 #include "extern.h"
 
 #include "ls.h"
 #include "extern.h"
 
@@ -39,7 +42,7 @@ void
 printscol(dp)
        DISPLAY *dp;
 {
 printscol(dp)
        DISPLAY *dp;
 {
-       register FTSENT *p;
+       FTSENT *p;
 
        for (p = dp->list; p; p = p->fts_link) {
                if (IS_NOPRINT(p))
 
        for (p = dp->list; p; p = p->fts_link) {
                if (IS_NOPRINT(p))
@@ -53,8 +56,8 @@ void
 printlong(dp)
        DISPLAY *dp;
 {
 printlong(dp)
        DISPLAY *dp;
 {
-       register FTSENT *p;
-       register struct stat *sp;
+       struct stat *sp;
+       FTSENT *p;
        NAMES *np;
        char buf[20];
 
        NAMES *np;
        char buf[20];
 
@@ -68,7 +71,7 @@ printlong(dp)
                if (f_inode)
                        (void)printf("%*lu ", dp->s_inode, sp->st_ino);
                if (f_size)
                if (f_inode)
                        (void)printf("%*lu ", dp->s_inode, sp->st_ino);
                if (f_size)
-                       (void)printf("%*ld ",
+                       (void)printf("%*qd ",
                            dp->s_block, howmany(sp->st_blocks, blocksize));
                (void)strmode(sp->st_mode, buf);
                np = p->fts_pointer;
                            dp->s_block, howmany(sp->st_blocks, blocksize));
                (void)strmode(sp->st_mode, buf);
                np = p->fts_pointer;
@@ -80,6 +83,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)
@@ -106,8 +112,8 @@ printcol(dp)
        extern int termwidth;
        static FTSENT **array;
        static int lastentries = -1;
        extern int termwidth;
        static FTSENT **array;
        static int lastentries = -1;
-       register FTSENT *p;
-       register int base, chcnt, cnt, col, colwidth, num;
+       FTSENT *p;
+       int base, chcnt, cnt, col, colwidth, num;
        int endcol, numcols, numrows, row;
 
        /*
        int endcol, numcols, numrows, row;
 
        /*
@@ -118,7 +124,7 @@ printcol(dp)
                lastentries = dp->entries;
                if ((array =
                    realloc(array, dp->entries * sizeof(FTSENT *))) == NULL) {
                lastentries = dp->entries;
                if ((array =
                    realloc(array, dp->entries * sizeof(FTSENT *))) == NULL) {
-                       err(0, "%s", strerror(errno));
+                       warn(NULL);
                        printscol(dp);
                }
        }
                        printscol(dp);
                }
        }
@@ -170,7 +176,7 @@ printcol(dp)
  */
 static int
 printaname(p, inodefield, sizefield)
  */
 static int
 printaname(p, inodefield, sizefield)
-       register FTSENT *p;
+       FTSENT *p;
        u_long sizefield, inodefield;
 {
        struct stat *sp;
        u_long sizefield, inodefield;
 {
        struct stat *sp;
@@ -179,10 +185,10 @@ printaname(p, inodefield, sizefield)
        sp = p->fts_statp;
        chcnt = 0;
        if (f_inode)
        sp = p->fts_statp;
        chcnt = 0;
        if (f_inode)
-               chcnt += printf("%*lu ", inodefield, sp->st_ino);
+               chcnt += printf("%*lu ", (int)inodefield, sp->st_ino);
        if (f_size)
        if (f_size)
-               chcnt += printf("%*ld ",
-                   sizefield, howmany(sp->st_blocks, blocksize));
+               chcnt += printf("%*qd ",
+                   (int)sizefield, howmany(sp->st_blocks, blocksize));
        chcnt += printf("%s", p->fts_name);
        if (f_type)
                chcnt += printtype(sp->st_mode);
        chcnt += printf("%s", p->fts_name);
        if (f_type)
                chcnt += printtype(sp->st_mode);
@@ -246,11 +252,10 @@ printlink(p)
 
        if (p->fts_level == FTS_ROOTLEVEL)
                (void)snprintf(name, sizeof(name), "%s", p->fts_name);
 
        if (p->fts_level == FTS_ROOTLEVEL)
                (void)snprintf(name, sizeof(name), "%s", p->fts_name);
-       else
+       else 
                (void)snprintf(name, sizeof(name),
                (void)snprintf(name, sizeof(name),
-                   "%s/%s", p->fts_parent->fts_name, p->fts_name);
-
-       if ((lnklen = readlink(name, path, sizeof(name) - 1)) == -1) {
+                   "%s/%s", p->fts_parent->fts_accpath, p->fts_name);
+       if ((lnklen = readlink(name, path, sizeof(path) - 1)) == -1) {
                (void)fprintf(stderr, "\nls: %s: %s\n", name, strerror(errno));
                return;
        }
                (void)fprintf(stderr, "\nls: %s: %s\n", name, strerror(errno));
                return;
        }