default sizes are in 512-byte blocks; add -k flag for kilobytes
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Wed, 23 Aug 1989 03:26:46 +0000 (19:26 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Wed, 23 Aug 1989 03:26:46 +0000 (19:26 -0800)
SCCS-vsn: bin/ls/ls.c 5.33
SCCS-vsn: bin/ls/ls.h 5.8
SCCS-vsn: bin/ls/print.c 5.15
SCCS-vsn: bin/ls/util.c 5.5

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

index 8acdb3e..f58f473 100644 (file)
@@ -25,7 +25,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)ls.c       5.32 (Berkeley) %G%";
+static char sccsid[] = "@(#)ls.c       5.33 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -49,6 +49,7 @@ int f_column;                 /* columnated format */
 int f_group;                   /* show group ownership of a file */
 int f_ignorelink;              /* indirect through symbolic link operands */
 int f_inode;                   /* print inode */
 int f_group;                   /* show group ownership of a file */
 int f_ignorelink;              /* indirect through symbolic link operands */
 int f_inode;                   /* print inode */
+int f_kblocks;                 /* print size in kilobytes */
 int f_listalldot;              /* list . and .. as well */
 int f_listdir;                 /* list actual directory, not contents */
 int f_listdot;                 /* list files beginning with . */
 int f_listalldot;              /* list . and .. as well */
 int f_listdir;                 /* list actual directory, not contents */
 int f_listdot;                 /* list files beginning with . */
@@ -95,7 +96,7 @@ main(argc, argv)
        if (!getuid())
                f_listdot = 1;
 
        if (!getuid())
                f_listdot = 1;
 
-       while ((ch = getopt(argc, argv, "1ACFLRacdgilqrstu")) != EOF) {
+       while ((ch = getopt(argc, argv, "1ACFLRacdgiklqrstu")) != EOF) {
                switch (ch) {
                /*
                 * -1, -C and -l all override each other
                switch (ch) {
                /*
                 * -1, -C and -l all override each other
@@ -148,6 +149,9 @@ main(argc, argv)
                case 'i':
                        f_inode = 1;
                        break;
                case 'i':
                        f_inode = 1;
                        break;
+               case 'k':
+                       f_kblocks = 1;
+                       break;
                case 'q':
                        f_nonprint = 1;
                        break;
                case 'q':
                        f_nonprint = 1;
                        break;
index 41b4f0a..53d654e 100644 (file)
@@ -17,7 +17,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- *     @(#)ls.h        5.7 (Berkeley) %G%
+ *     @(#)ls.h        5.8 (Berkeley) %G%
  */
 
 typedef struct _lsstruct {
  */
 
 typedef struct _lsstruct {
@@ -40,6 +40,7 @@ extern int errno;
 extern int f_accesstime;       /* use time of last access */
 extern int f_group;            /* show group ownership of a file */
 extern int f_inode;            /* print inode */
 extern int f_accesstime;       /* use time of last access */
 extern int f_group;            /* show group ownership of a file */
 extern int f_inode;            /* print inode */
+extern int f_kblocks;          /* print size in kilobytes */
 extern int f_longform;         /* long listing format */
 extern int f_singlecol;                /* use single column output */
 extern int f_size;             /* list size in short listing */
 extern int f_longform;         /* long listing format */
 extern int f_singlecol;                /* use single column output */
 extern int f_size;             /* list size in short listing */
index b72d53b..4a814b5 100644 (file)
@@ -19,7 +19,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)print.c    5.14 (Berkeley) %G%";
+static char sccsid[] = "@(#)print.c    5.15 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -46,14 +46,18 @@ printlong(stats, num)
        register int num;
 {
        if (f_total)
        register int num;
 {
        if (f_total)
-               (void)printf("total %lu\n", stats[0].lstat.st_btotal);
+               (void)printf("total %lu\n", f_kblocks ?
+                   howmany(stats[0].lstat.st_btotal, 2) :
+                   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);
+                       (void)printf("%4ld ", f_kblocks ?
+                           howmany(stats->lstat.st_blocks, 2) :
+                           stats->lstat.st_blocks);
                printperms(stats->lstat.st_mode);
                printperms(stats->lstat.st_mode);
-               (void)printf("%3d ", stats->lstat.st_nlink);
+               (void)printf("%3u ", stats->lstat.st_nlink);
                printowner(stats->lstat.st_uid);
                if (f_group)
                        printgrp(stats->lstat.st_gid);
                printowner(stats->lstat.st_uid);
                if (f_group)
                        printgrp(stats->lstat.st_gid);
@@ -103,7 +107,9 @@ printcol(stats, num)
                ++numrows;
 
        if (f_size && f_total)
                ++numrows;
 
        if (f_size && f_total)
-               (void)printf("total %lu\n", stats[0].lstat.st_btotal);
+               (void)printf("total %lu\n", f_kblocks ?
+                   howmany(stats[0].lstat.st_btotal, 2) :
+                   stats[0].lstat.st_btotal);
        for (row = 0; row < numrows; ++row) {
                endcol = colwidth;
                for (base = row, chcnt = col = 0; col < numcols; ++col) {
        for (row = 0; row < numrows; ++row) {
                endcol = colwidth;
                for (base = row, chcnt = col = 0; col < numcols; ++col) {
@@ -133,7 +139,8 @@ 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);
+               chcnt += printf("%4ld ", f_kblocks ?
+                   howmany(lp->lstat.st_blocks, 2) : 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);
index 46354ab..16c754b 100644 (file)
@@ -19,7 +19,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)util.c     5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)util.c     5.5 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -57,6 +57,6 @@ nomem()
 
 usage()
 {
 
 usage()
 {
-       (void)fprintf(stderr, "usage: ls [-1ACFLRacdgilqrstu] [file ...]\n");
+       (void)fprintf(stderr, "usage: ls [-1ACFLRacdgiklqrstu] [file ...]\n");
        exit(1);
 }
        exit(1);
 }