Reply to request for more detailed diff on new dtree.c
Ed Arnold
arnold at csu-cs.UUCP
Thu Mar 15 12:12:17 AEST 1984
I'm posting a new diff due to requests by some who are having trouble
incorporating my fixes. This time I did a diff with a -c5 option. Make sure
you have the correct original source. If people have more problems and
there are enough requests, I'll post my entire revised source. I hope that
this will be enough.
Cheers,
Ed Arnold (denelcor!csu-cs!arnold)
*** dtree1.1.c Wed Mar 14 18:28:38 1984
--- dtree2.1.c Wed Mar 14 18:14:45 1984
***************
*** 29,38
* -v) variable length columns
* -x) do not cross mounted file systems.
* -c length) set max column length to "length"
*/
#define STATS /* comment out to remove stats, giving more core space */
/* and thus the ability to tree larger tree structures */
/* on PDP 11/70s */
/* #define NEWDIR /* directory structure ala Berkeley 4.1c or 4.2 */
--- 29,48 -----
* -v) variable length columns
* -x) do not cross mounted file systems.
* -c length) set max column length to "length"
*/
+ /* Modified by Ed Arnold CSU-CS (csu-cs!arnold) 3-5-84
+ *
+ * Allows symbolic links to both directories and individual files.
+ * With a '-l' or '-al' option, links are denoted with a 'l' in front of
+ * file or directory permissions. In all other instances both links to
+ * directories and files are represented just as files are. Contents of
+ * linked directories are not printed due to the possibility of
+ * recursively linked directories.
+ */
+
#define STATS /* comment out to remove stats, giving more core space */
/* and thus the ability to tree larger tree structures */
/* on PDP 11/70s */
#define NEWDIR /* directory structure ala Berkeley 4.1c or 4.2 */
***************
*** 33,43
#define STATS /* comment out to remove stats, giving more core space */
/* and thus the ability to tree larger tree structures */
/* on PDP 11/70s */
! /* #define NEWDIR /* directory structure ala Berkeley 4.1c or 4.2 */
static char Sccsid[]="@(#)dtree.c 2.3 2/14/84";
#include <stdio.h>
#include <sys/types.h>
--- 43,53 -----
#define STATS /* comment out to remove stats, giving more core space */
/* and thus the ability to tree larger tree structures */
/* on PDP 11/70s */
! #define NEWDIR /* directory structure ala Berkeley 4.1c or 4.2 */
#define LINK /* allows links to be processed in Berkeley 4.2 version */
/* NEWDIR must be defined as well as LINK */
static char Sccsid[]="@(#)dtree.c 2.3 2/14/84";
***************
*** 35,44
/* and thus the ability to tree larger tree structures */
/* on PDP 11/70s */
/* #define NEWDIR /* directory structure ala Berkeley 4.1c or 4.2 */
static char Sccsid[]="@(#)dtree.c 2.3 2/14/84";
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
--- 45,57 -----
/* and thus the ability to tree larger tree structures */
/* on PDP 11/70s */
#define NEWDIR /* directory structure ala Berkeley 4.1c or 4.2 */
+ #define LINK /* allows links to be processed in Berkeley 4.2 version */
+ /* NEWDIR must be defined as well as LINK */
+
static char Sccsid[]="@(#)dtree.c 2.3 2/14/84";
#ifdef LINK
static char Rcsid[] ="$Header: dtree.c,v 2.1 84/03/08 02:24:03 arnold Exp $";
#endif LINK
***************
*** 37,46
/* #define NEWDIR /* directory structure ala Berkeley 4.1c or 4.2 */
static char Sccsid[]="@(#)dtree.c 2.3 2/14/84";
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef STATS
# include <pwd.h>
--- 50,63 -----
#define LINK /* allows links to be processed in Berkeley 4.2 version */
/* NEWDIR must be defined as well as LINK */
static char Sccsid[]="@(#)dtree.c 2.3 2/14/84";
+ #ifdef LINK
+ static char Rcsid[] ="$Header: dtree.c,v 2.1 84/03/08 02:24:03 arnold Exp $";
+ #endif LINK
+
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef STATS
# include <pwd.h>
***************
*** 92,101
int Gflag = 0; /* set for group stats instead of owner */
int Longflg = 0; /* set for long listing */
int Compact = 0; /* set for shortened long listing */
#endif STATS
struct stat Status;
struct entry {
int next; /* index to next element in list */
/* could be a ptr, but realloc() */
/* might screw us then */
--- 109,121 -----
int Gflag = 0; /* set for group stats instead of owner */
int Longflg = 0; /* set for long listing */
int Compact = 0; /* set for shortened long listing */
#endif STATS
struct stat Status;
+ #ifdef LINK
+ struct stat Lstat; /* stat of link, if there is one */
+ #endif LINK
struct entry {
int next; /* index to next element in list */
/* could be a ptr, but realloc() */
/* might screw us then */
***************
*** 267,277
if (!ptr || *++ptr == '\0')
sprintf(addr(List,Index)->e_name, "%.*s", Length, top);
else
sprintf(addr(List,Index)->e_name, "%.*s", Length, ptr);
! if (stat(top, &Status) == FAIL) {
fprintf(stderr, "Can't stat %s\n", top);
continue;
}
Device = Status.st_dev;
addr(List,0)->dir = 1;
--- 287,297 -----
if (!ptr || *++ptr == '\0')
sprintf(addr(List,Index)->e_name, "%.*s", Length, top);
else
sprintf(addr(List,Index)->e_name, "%.*s", Length, ptr);
! if(stat(top, &Status) == FAIL) {
fprintf(stderr, "Can't stat %s\n", top);
continue;
}
Device = Status.st_dev;
addr(List,0)->dir = 1;
***************
*** 362,371
|| (strcmp(dp->d_name, "..") == SAME)
|| (Point && dp->d_name[0] == '.'))
continue;
sprintf(sub, "%s", dp->d_name);
if ((tmp = stat(sub, &Status)) == FAIL) {
fprintf(stderr, "%s:stat can't find\n", sub);
continue;
}
if ((Status.st_mode & S_IFMT) == S_IFDIR)
--- 382,397 -----
|| (strcmp(dp->d_name, "..") == SAME)
|| (Point && dp->d_name[0] == '.'))
continue;
sprintf(sub, "%s", dp->d_name);
+ #ifdef LINK
+ if (lstat (sub,&Lstat) == FAIL) {
+ fprintf(stderr, "%s:lstat can't find\n", sub);
+ continue;
+ }
+ #endif LINK
if ((tmp = stat(sub, &Status)) == FAIL) {
fprintf(stderr, "%s:stat can't find\n", sub);
continue;
}
#ifdef LINK
***************
*** 366,376
sprintf(sub, "%s", dp->d_name);
if ((tmp = stat(sub, &Status)) == FAIL) {
fprintf(stderr, "%s:stat can't find\n", sub);
continue;
}
! if ((Status.st_mode & S_IFMT) == S_IFDIR)
addr(List,Index)->dir = 1;
else if (All)
addr(List,Index)->dir = 0;
else
continue;
--- 392,410 -----
#endif LINK
if ((tmp = stat(sub, &Status)) == FAIL) {
fprintf(stderr, "%s:stat can't find\n", sub);
continue;
}
! #ifdef LINK
! if (((Lstat.st_mode & S_IFMT) == S_IFLNK) &&
! ((Status.st_mode & S_IFMT) == S_IFDIR))
! addr(List,Index)->dir = 0;
! else if ((((Lstat.st_mode & S_IFMT) == S_IFLNK) &&
! ((Status.st_mode & S_IFMT) != S_IFDIR)) && (All))
! addr(List,Index)->dir = 0;
! #endif LINK
! else if ((Status.st_mode & S_IFMT) == S_IFDIR)
addr(List,Index)->dir = 1;
else if (All)
addr(List,Index)->dir = 0;
else
continue;
***************
*** 375,391
else
continue;
sprintf(addr(List,Index)->e_name, "%.*s", Length, dp->d_name);
addr(List,Index)->last = 0;
addr(List,Index)->end = 0;
! addr(List,Index)->dev = (Device == Status.st_dev);
! #ifdef STATS
! addr(List,Index)->e_mode = Status.st_mode;
! addr(List,Index)->e_uid = Status.st_uid;
! addr(List,Index)->e_gid = Status.st_gid;
! addr(List,Index)->e_size = Status.st_size;
! #endif STATS
if (stln(addr(List,Index)->e_name) > Maxes[Level])
Maxes[Level] = stln(addr(List,Index)->e_name);
++Index;
if (Index*SIZEOFentry >= Size) {
Size += 20*SIZEOFentry;
--- 409,438 -----
else
continue;
sprintf(addr(List,Index)->e_name, "%.*s", Length, dp->d_name);
addr(List,Index)->last = 0;
addr(List,Index)->end = 0;
! #ifdef LINK
! if ((Lstat.st_mode & S_IFMT) == S_IFLNK) {
! addr(List,Index)->dev = (Device == Lstat.st_dev);
! addr(List,Index)->e_mode = Lstat.st_mode;
! addr(List,Index)->e_uid = Lstat.st_uid;
! addr(List,Index)->e_gid = Lstat.st_gid;
! addr(List,Index)->e_size = Lstat.st_size;
! }
! else {
! #endif LINK
! addr(List,Index)->dev = (Device == Status.st_dev);
! #ifdef STATS
! addr(List,Index)->e_mode = Status.st_mode;
! addr(List,Index)->e_uid = Status.st_uid;
! addr(List,Index)->e_gid = Status.st_gid;
! addr(List,Index)->e_size = Status.st_size;
! #endif STATS
! #ifdef LINK
! }
! #endif LINK
if (stln(addr(List,Index)->e_name) > Maxes[Level])
Maxes[Level] = stln(addr(List,Index)->e_name);
++Index;
if (Index*SIZEOFentry >= Size) {
Size += 20*SIZEOFentry;
***************
*** 680,689
register int i = 0, j = 0;
a_mode[j++] = ' ';
switch (p_mode & S_IFMT) {
case S_IFDIR:
a_mode[j++] = 'd';
break;
#ifdef S_IFMPC /* defined in stats.h if you have MPX files */
case S_IFMPC:
--- 727,741 -----
register int i = 0, j = 0;
a_mode[j++] = ' ';
switch (p_mode & S_IFMT) {
+ #ifdef LINK
+ case S_IFLNK:
+ a_mode[j++] = 'l';
+ break;
+ #endif LINK
case S_IFDIR:
a_mode[j++] = 'd';
break;
#ifdef S_IFMPC /* defined in stats.h if you have MPX files */
case S_IFMPC:
More information about the Comp.sources.unix
mailing list