omments? allow more than one dir to be listed, ^D<CR> to end; cleanups
authorMike Karels <karels@ucbvax.Berkeley.EDU>
Wed, 22 Mar 1989 02:03:28 +0000 (18:03 -0800)
committerMike Karels <karels@ucbvax.Berkeley.EDU>
Wed, 22 Mar 1989 02:03:28 +0000 (18:03 -0800)
SCCS-vsn: sys/stand.att/ls.c 7.5

usr/src/sys/stand.att/ls.c

index ab7378b..efe9e1f 100644 (file)
@@ -14,7 +14,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- *     @(#)ls.c        7.4 (Berkeley) %G%
+ *     @(#)ls.c        7.5 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
 #include "dir.h"
 #include "fs.h"
 #include "saio.h"
 #include "dir.h"
 #include "fs.h"
 #include "saio.h"
+#include "ttychars.h"
 
 main()
 {
        struct inode *ip;
        int fd;
 
 
 main()
 {
        struct inode *ip;
        int fd;
 
-       fd = getfile("ls", 0);
-       ip = &iob[fd - 3].i_ino;
-       if ((ip->i_mode & IFMT) != IFDIR)
-               _stop("ls: not a directory");
-       if (ip->i_size == 0)
-               _stop("ls: zero length directory");
-       ls(fd);
+       for (;;) {
+               if ((fd = getfile("ls", 0)) == -1)
+                       exit();
+               ip = &iob[fd - 3].i_ino;
+               if ((ip->i_mode & IFMT) != IFDIR) {
+                       printf("ls: not a directory\n");
+                       continue;
+               }
+               if (ip->i_size == 0) {
+                       printf("ls: zero length directory\n");
+                       continue;
+               }
+               ls(fd);
+       }
+}
+
+getfile(prompt, mode)
+       char *prompt;
+       int mode;
+{
+       int fd;
+       char buf[100];
+
+       do {
+               printf("%s: ", prompt);
+               gets(buf);
+               if (buf[0] == CTRL('d') && buf[1] == 0)
+                       return (-1);
+       } while ((fd = open(buf, mode)) <= 0);
+       return(fd);
 }
 
 typedef struct direct  DP;
 }
 
 typedef struct direct  DP;
@@ -46,18 +70,18 @@ ls(fd)
        register char *dp;
        char dirbuf[DIRBLKSIZ];
 
        register char *dp;
        char dirbuf[DIRBLKSIZ];
 
-       printf("\nname->inode\n");
+       printf("\ninode\tname\n");
        while ((size = read(fd, dirbuf, DIRBLKSIZ)) == DIRBLKSIZ)
                for(dp = dirbuf; (dp < (dirbuf + size)) &&
                    (dp + ((DP *)dp)->d_reclen) < (dirbuf + size);
                    dp += ((DP *)dp)->d_reclen) {
                        if (((DP *)dp)->d_ino == 0)
                                continue;
        while ((size = read(fd, dirbuf, DIRBLKSIZ)) == DIRBLKSIZ)
                for(dp = dirbuf; (dp < (dirbuf + size)) &&
                    (dp + ((DP *)dp)->d_reclen) < (dirbuf + size);
                    dp += ((DP *)dp)->d_reclen) {
                        if (((DP *)dp)->d_ino == 0)
                                continue;
-                       if (((DP *)dp)->d_reclen > DIRSIZ(((DP *)dp)))
-                               continue;
-                       if (((DP *)dp)->d_namlen > MAXNAMLEN+1)
-                               _stop("Corrupt file name length!  Run fsck soon!\n");
-                       printf("%s->%d\n", ((DP *)dp)->d_name,
-                           ((DP *)dp)->d_ino);
+                       if (((DP *)dp)->d_namlen > MAXNAMLEN+1) {
+                               printf("Corrupt file name length!  Run fsck soon!\n");
+                               return;
+                       }
+                       printf("%d\t%s\n", ((DP *)dp)->d_ino,
+                           ((DP *)dp)->d_name);
                }
 }
                }
 }