# 2.11BSD#431 - /usr/src/usr.bin/shar/traverse.c

##### Functions

    main              X
    namedir           X
    readdir           X
    traverse          X
    tryverse          X

##### Macros

    DIR               X
    MAXNAME           X
    closedir          X
    isdir             X
    namedir           X
    opendir           X

       1: /*LINTLIBRARY*/
       2: #ifndef lint
       3: static  char    sccsid[] = "@(#)traverse.c 1.0 (WangInst) 12/23/84";
       4: #endif
       5:
       6: #include <stdio.h>
       7: #include <sys/types.h>
       8: #include <sys/dir.h>
       9:
      10: #ifdef MAXNAMLEN
      11:
      12: #define namedir(entry) (entry->d_name)
      13: #define MAXNAME 256
      14:
      15: #else
      16:
      17: #define DIR FILE
      18: #define MAXNAME (DIRSIZ+2)
      19: #define opendir(path) fopen (path, "r")
      20: #define closedir(dirp) fclose (dirp)
      21: struct direct *
      22: readdir (dirp)
      23: DIR     *dirp;
      24:     {
      25:     static  struct  direct  entry;
      26:     if (dirp == NULL) return (NULL);
      27:     for (;;)
      28:         {
      29:         if (fread (&entry, sizeof (struct direct), 1, dirp) == 0) return (NULL);
      30:         if (entry.d_ino) return (&entry);
      31:         }
      32:     }
      33: char    *strncpy ();
      34: char *
      35: namedir (entry)
      36: struct  direct  *entry;
      37:     {
      38:     static  char    name[MAXNAME];
      39:     return (strncpy (name, entry->d_name, DIRSIZ));
      40:     }
      41:
      42: #endif
      43:
      44: #include <sys/stat.h>
      45: #define isdir(path) (stat(path, &buf) ? 0 : (buf.st_mode&S_IFMT)==S_IFDIR)
      46:
      47: traverse (path, func)
      48: char    *path;
      49: int     (*func) ();
      50:     {
      51:     DIR     *dirp;
      52:     struct  direct  *entry;
      53:     struct  stat    buf;
      54:     int     filetype = isdir (path) ? 'd' : 'f';
      55:     (*func) (path, filetype, 0);
      56:     if (filetype == 'd')
      57:         {
      58:         if (chdir (path) == 0)
      59:             {
      60:             if (dirp = opendir ("."))
      61:                 {
      62:                 while (entry = readdir (dirp))
      63:                     {
      64:                     char    name[MAXNAME];
      65:                     (void) strcpy (name, namedir (entry));
      66:                     if (strcmp(name, ".") && strcmp(name, ".."))
      67:                         traverse (name, func);
      68:                     }
      69:                 (void) closedir(dirp);
      70:                 }
      71:             (void) chdir ("..");
      72:             }
      73:         }
      74:     (*func) (path, filetype, 1);
      75:     }
      76:
      77: #ifdef STANDALONE
      78:
      79: static  Indent = 0;
      80: tryverse (file, type, pos)
      81: char    *file;
      82:     {
      83:     int     in;
      84:     if (pos == 0)
      85:         {
      86:         for (in = 0; in < Indent; in++) putchar ('\t');
      87:         if (type == 'd')
      88:             {
      89:             printf ("%s/\n", file);
      90:             Indent++;
      91:             }
      92:         else puts (file);
      93:         }
      94:     else if (type == 'd') Indent--;
      95:     }
      96:
      97: main (argc, argv) char **argv;
      98:     {
      99:     int     tryverse ();
     100:     char    *root = argc > 1 ? argv[1] : ".";
     101:     traverse (root, tryverse);
     102:     }
     103: #endif

#### Defined functions

main defined in line 97; never used
namedir defined in line 34; never used
readdir defined in line 21; used 1 times

- in line 62

traverse defined in line 47; used 3 times

- in line 67, 101
- in /usr/src/usr.bin/shar/shar.c line 52

tryverse defined in line 80; used 2 times

- in line 99-101(2)

#### Defined variables

sccsid defined in line 3; never used

#### Defined macros

DIR defined in line 17; never used
MAXNAME defined in line 18; used 2 times

- in line 38, 64

closedir defined in line 20; used 1 times

- in line 69

isdir defined in line 45; used 1 times

- in line 54

namedir defined in line 12; used 1 times

- in line 65

opendir defined in line 19; used 1 times

- in line 60

Last modified: 1986-03-18 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1296 |