Subversion Repositories SvarDOS

Rev

Rev 2061 | Rev 2063 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2061 Rev 2062
Line 568... Line 568...
568
 
568
 
569
/**
569
/**
570
 * Contains the information stored in a Stack necessary to allow
570
 * Contains the information stored in a Stack necessary to allow
571
 * non-recursive function to display directory tree.
571
 * non-recursive function to display directory tree.
572
 */
572
 */
573
typedef struct SUBDIRINFO
573
struct SUBDIRINFO {
574
{
-
 
575
  struct SUBDIRINFO * parent; /* points to parent subdirectory                */
574
  struct SUBDIRINFO *parent; /* points to parent subdirectory                */
576
  char *currentpath;    /* Stores the full path this structure represents     */
575
  char *currentpath;    /* Stores the full path this structure represents     */
577
  char *subdir;         /* points to last subdir within currentpath           */
576
  char *subdir;         /* points to last subdir within currentpath           */
578
  char *dsubdir;        /* Stores a display ready directory name              */
577
  char *dsubdir;        /* Stores a display ready directory name              */
579
  long subdircnt;       /* Initially a count of how many subdirs in this dir  */
578
  long subdircnt;       /* Initially a count of how many subdirs in this dir  */
580
  struct find_t *findnexthnd; /* The handle returned by findfirst, used in findnext */
579
  struct find_t *findnexthnd; /* The handle returned by findfirst, used in findnext */
581
  struct DIRDATA ddata; /* Maintain directory information, eg attributes      */
580
  struct DIRDATA ddata; /* Maintain directory information, eg attributes      */
582
} SUBDIRINFO;
581
};
583
 
582
 
584
 
583
 
585
/**
584
/**
586
 * Returns 0 if no subdirectories, count if has subdirs.
585
 * Returns 0 if no subdirectories, count if has subdirs.
587
 * Path must end in slash \ or /
586
 * Path must end in slash \ or /
Line 645... Line 644...
645
 * parentpath must end in \ or / or be NULL, however
644
 * parentpath must end in \ or / or be NULL, however
646
 * parent should only be NULL for initialpath
645
 * parent should only be NULL for initialpath
647
 * if subdir does not end in slash, one is added to stored subdir
646
 * if subdir does not end in slash, one is added to stored subdir
648
 * dsubdir is subdir already modified so ready to display to user
647
 * dsubdir is subdir already modified so ready to display to user
649
 */
648
 */
650
static SUBDIRINFO *newSubdirInfo(SUBDIRINFO *parent, char *subdir, char *dsubdir) {
649
static struct SUBDIRINFO *newSubdirInfo(struct SUBDIRINFO *parent, char *subdir, char *dsubdir) {
651
  int parentLen, subdirLen;
650
  int parentLen, subdirLen;
652
  SUBDIRINFO *temp;
651
  struct SUBDIRINFO *temp;
653
 
652
 
654
  /* Get length of parent directory */
653
  /* Get length of parent directory */
655
  if (parent == NULL)
654
  if (parent == NULL)
656
    parentLen = 0;
655
    parentLen = 0;
657
  else
656
  else
Line 660... Line 659...
660
  /* Get length of subdir, add 1 if does not end in slash */
659
  /* Get length of subdir, add 1 if does not end in slash */
661
  subdirLen = strlen(subdir);
660
  subdirLen = strlen(subdir);
662
  if ((subdirLen < 1) || ( (*(subdir+subdirLen-1) != '\\') && (*(subdir+subdirLen-1) != '/') ) )
661
  if ((subdirLen < 1) || ( (*(subdir+subdirLen-1) != '\\') && (*(subdir+subdirLen-1) != '/') ) )
663
    subdirLen++;
662
    subdirLen++;
664
 
663
 
665
  temp = (SUBDIRINFO *)malloc(sizeof(SUBDIRINFO));
664
  temp = malloc(sizeof(struct SUBDIRINFO));
666
  if (temp == NULL)
665
  if (temp == NULL) {
667
  {
-
 
668
    showOutOfMemory(subdir);
666
    showOutOfMemory(subdir);
669
    return NULL;
667
    return NULL;
670
  }
668
  }
671
  if ( ((temp->currentpath = (char *)malloc(parentLen+subdirLen+1)) == NULL) ||
669
  if ( ((temp->currentpath = (char *)malloc(parentLen+subdirLen+1)) == NULL) ||
672
       ((temp->dsubdir = (char *)malloc(strlen(dsubdir)+1)) == NULL) )
670
       ((temp->dsubdir = (char *)malloc(strlen(dsubdir)+1)) == NULL) )
Line 993... Line 991...
993
static long traverseTree(char *initialpath) {
991
static long traverseTree(char *initialpath) {
994
  long subdirsInInitialpath;
992
  long subdirsInInitialpath;
995
  char padding[MAXPADLEN] = "";
993
  char padding[MAXPADLEN] = "";
996
  char subdir[PATH_MAX];
994
  char subdir[PATH_MAX];
997
  char dsubdir[PATH_MAX];
995
  char dsubdir[PATH_MAX];
998
  SUBDIRINFO *sdi;
996
  struct SUBDIRINFO *sdi;
999
 
997
 
1000
  STACK s;
998
  STACK s;
1001
  stackDefaults(&s);
999
  stackDefaults(&s);
1002
  stackInit(&s);
1000
  stackInit(&s);
1003
 
1001
 
Line 1009... Line 1007...
1009
  /* Store count of subdirs in initial path so can display message if none. */
1007
  /* Store count of subdirs in initial path so can display message if none. */
1010
  subdirsInInitialpath = sdi->subdircnt;
1008
  subdirsInInitialpath = sdi->subdircnt;
1011
 
1009
 
1012
  do
1010
  do
1013
  {
1011
  {
1014
    sdi = (SUBDIRINFO *)stackPopItem(&s);
1012
    sdi = (struct SUBDIRINFO *)stackPopItem(&s);
1015
 
1013
 
1016
    if (sdi->findnexthnd == NULL) { // findfirst not called yet
1014
    if (sdi->findnexthnd == NULL) { // findfirst not called yet
1017
      // 1st time this subdirectory processed, so display its name & possibly files
1015
      // 1st time this subdirectory processed, so display its name & possibly files
1018
      if (sdi->parent == NULL) // if initial path
1016
      if (sdi->parent == NULL) // if initial path
1019
      {
1017
      {