make -f output look like standard outputs
[unix-history] / usr / src / bin / ls / print.c
index 0318b1d..0fda4ac 100644 (file)
@@ -19,7 +19,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)print.c    5.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)print.c    5.12 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -45,12 +45,12 @@ printlong(stats, num)
        LS *stats;
        register int num;
 {
        LS *stats;
        register int num;
 {
-       (void)printf("total %lu\n", stats[0].lstat.st_flags);
+       (void)printf("total %lu\n", stats[0].lstat.st_btotal);
        for (; num--; ++stats) {
                if (f_inode)
                        (void)printf("%6lu ", stats->lstat.st_ino);
                if (f_size)
        for (; num--; ++stats) {
                if (f_inode)
                        (void)printf("%6lu ", stats->lstat.st_ino);
                if (f_size)
-                       (void)printf("%4ld ", stats->lstat.st_blocks / 2);
+                       (void)printf("%4ld ", stats->lstat.st_blocks);
                printperms(stats->lstat.st_mode);
                (void)printf("%3d ", stats->lstat.st_nlink);
                printowner(stats->lstat.st_uid);
                printperms(stats->lstat.st_mode);
                (void)printf("%3d ", stats->lstat.st_nlink);
                printowner(stats->lstat.st_uid);
@@ -77,53 +77,43 @@ printlong(stats, num)
        }
 }
 
        }
 }
 
+#define        TAB     8
+
 printcol(stats, num)
        LS *stats;
 printcol(stats, num)
        LS *stats;
-       register int num;
+       int num;
 {
        extern int termwidth;
 {
        extern int termwidth;
-       int row, col;
-       int colwidth;           /* width of a printing column */
-       int numcols;            /* number of columns */
-       int numrows;            /* number of rows */
-       int base;               /* subscript for leftmost column */
-       int chcnt;              /* character count printed */
-       int newcnt;
-       int curcol;
+       register int base, chcnt, cnt, col, colwidth;
+       int endcol, numcols, numrows, row;
 
 
-       colwidth = stats[0].lstat.st_flags;
+       colwidth = stats[0].lstat.st_maxlen;
        if (f_inode)
                colwidth += 6;
        if (f_size)
                colwidth += 5;
        if (f_type)
                colwidth += 1;
        if (f_inode)
                colwidth += 6;
        if (f_size)
                colwidth += 5;
        if (f_type)
                colwidth += 1;
-       colwidth += 3;
+       colwidth = (colwidth + TAB) & ~(TAB - 1);
 
        numcols = termwidth / colwidth;
        numrows = num / numcols;
        if (num % numcols)
                ++numrows;
 
 
        numcols = termwidth / colwidth;
        numrows = num / numcols;
        if (num % numcols)
                ++numrows;
 
-#define        TAB     8
+       if (f_size)
+               (void)printf("total %lu\n", stats[0].lstat.st_btotal);
        for (row = 0; row < numrows; ++row) {
        for (row = 0; row < numrows; ++row) {
-               curcol = colwidth;
-               chcnt = 0;
-               for (base = row, col = 0; col < numcols; ++col) {
+               endcol = colwidth;
+               for (base = row, chcnt = col = 0; col < numcols; ++col) {
                        chcnt += printaname(stats + base);
                        if ((base += numrows) >= num)
                                break;
                        chcnt += printaname(stats + base);
                        if ((base += numrows) >= num)
                                break;
-                       for (;;) {
-                               newcnt = (chcnt + TAB & ~(TAB - 1));
-                               if (newcnt > curcol) {
-                                       break;
-                               }
+                       while ((cnt = (chcnt + TAB & ~(TAB - 1))) <= endcol) {
                                (void)putchar('\t');
                                (void)putchar('\t');
-                               chcnt = newcnt;
+                               chcnt = cnt;
                        }
                        }
-                       for (; chcnt < curcol; ++chcnt)
-                               (void)putchar(' ');
-                       curcol += colwidth;
+                       endcol += colwidth;
                }
                putchar('\n');
        }
                }
                putchar('\n');
        }
@@ -142,7 +132,7 @@ printaname(lp)
        if (f_inode)
                chcnt += printf("%5lu ", lp->lstat.st_ino);
        if (f_size)
        if (f_inode)
                chcnt += printf("%5lu ", lp->lstat.st_ino);
        if (f_size)
-               chcnt += printf("%4ld ", lp->lstat.st_blocks / 2);
+               chcnt += printf("%4ld ", lp->lstat.st_blocks);
        chcnt += printf("%s", lp->name);
        if (f_type)
                chcnt += printtype(lp->lstat.st_mode);
        chcnt += printf("%s", lp->name);
        if (f_type)
                chcnt += printtype(lp->lstat.st_mode);
@@ -165,7 +155,7 @@ printowner(uid)
        if (cp->uid != uid || !*cp->name) {
                /* if can't find owner, print out number instead */
                if (!(pw = getpwuid(uid))) {
        if (cp->uid != uid || !*cp->name) {
                /* if can't find owner, print out number instead */
                if (!(pw = getpwuid(uid))) {
-                       (void)printf("%-*.*u ", UT_NAMESIZE, UT_NAMESIZE, uid);
+                       (void)printf("%-*u ", UT_NAMESIZE, uid);
                        return;
                }
                cp->uid = uid;
                        return;
                }
                cp->uid = uid;
@@ -188,7 +178,7 @@ printgrp(gid)
        if (cp->gid != gid || *cp->name) {
                /* can't find group, print out number instead */
                if (!(gr = getgrgid(gid))) {
        if (cp->gid != gid || *cp->name) {
                /* can't find group, print out number instead */
                if (!(gr = getgrgid(gid))) {
-                       (void)printf("%-*.*u ", UT_NAMESIZE, UT_NAMESIZE, gid);
+                       (void)printf("%-*u ", UT_NAMESIZE, gid);
                        return;
                }
                cp->gid = gid;
                        return;
                }
                cp->gid = gid;