Subversion Repositories SvarDOS

Rev

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

Rev 2046 Rev 2047
Line 602... Line 602...
602
 */
602
 */
603
typedef struct DIRDATA
603
typedef struct DIRDATA
604
{
604
{
605
  DWORD subdirCnt;          /* how many subdirectories we have */
605
  DWORD subdirCnt;          /* how many subdirectories we have */
606
  DWORD fileCnt;            /* how many [normal] files we have */
606
  DWORD fileCnt;            /* how many [normal] files we have */
607
  DWORD dwDirAttributes;    /* Directory attributes            */
607
  unsigned short attrib;    /* Directory attributes            */
608
} DIRDATA;
608
} DIRDATA;
609
 
609
 
610
/**
610
/**
611
 * Contains the information stored in a Stack necessary to allow
611
 * Contains the information stored in a Stack necessary to allow
612
 * non-recursive function to display directory tree.
612
 * non-recursive function to display directory tree.
Line 651... Line 651...
651
  }
651
  }
652
 
652
 
653
 
653
 
654
  /*  cycle through entries counting directories found until no more entries */
654
  /*  cycle through entries counting directories found until no more entries */
655
  do {
655
  do {
656
    if (((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) &&
656
    if (((findData.attrib & FILE_A_DIR) != 0) &&
657
	((findData.dwFileAttributes &
657
        ((findData.attrib &
658
	 (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) == 0 || dspAll) )
658
         (FILE_A_HIDDEN | FILE_A_SYSTEM)) == 0 || dspAll) ) {
659
    {
-
 
660
      if ( (strcmp(findData.cFileName, ".") != 0) && /* ignore initial [current] path */
-
 
661
           (strcmp(findData.cFileName, "..") != 0) ) /* and ignore parent path */
659
      if (findData.cFileName[0] != '.') { /* ignore '.' and '..' */
662
        hasSubdirs++;      /* subdir of initial path found, so increment counter */
660
        hasSubdirs++;      /* subdir of initial path found, so increment counter */
-
 
661
      }
663
    }
662
    }
664
  } while(FindNextFile(hnd, &findData) != 0);
663
  } while(FindNextFile(hnd, &findData) != 0);
665
 
664
 
666
  /* prevent resource leaks, close the handle. */
665
  /* prevent resource leaks, close the handle. */
667
  FindClose(hnd);
666
  FindClose(hnd);
Line 672... Line 671...
672
       corresponding to mount points) may not have a current (.) and
671
       corresponding to mount points) may not have a current (.) and
673
       parent (..) entry.  So we can't get attributes for initial
672
       parent (..) entry.  So we can't get attributes for initial
674
       path in above loop from the FindFile call as it may not show up
673
       path in above loop from the FindFile call as it may not show up
675
       (no . entry).  So instead we explicitly get them here.
674
       (no . entry).  So instead we explicitly get them here.
676
    */
675
    */
677
    if ((ddata->dwDirAttributes = GetFileAttributes(path)) == (DWORD)-1)
676
    if (GetFileAttributes(&(ddata->attrib), path) != 0) {
678
    {
-
 
679
      //printf("ERROR: unable to get file attr, %i\n", GetLastError());
677
      //printf("ERROR: unable to get file attr, %i\n", GetLastError());
680
      ddata->dwDirAttributes = 0;
678
      ddata->attrib = 0;
681
    }
679
    }
682
 
680
 
683
    /* a curiosity, for showing sum of directories process */
681
    /* a curiosity, for showing sum of directories process */
684
    ddata->subdirCnt = hasSubdirs;
682
    ddata->subdirCnt = hasSubdirs;
685
  }
683
  }
Line 843... Line 841...
843
  }
841
  }
844
 
842
 
845
  /* optional display data */
843
  /* optional display data */
846
  if (dspAttr)  /* attributes */
844
  if (dspAttr)  /* attributes */
847
    pprintf("[%c%c%c%c%c] ",
845
    pprintf("[%c%c%c%c%c] ",
848
      (ddata->dwDirAttributes & FILE_ATTRIBUTE_DIRECTORY)?'D':' ',  /* keep this one? its always true */
846
      (ddata->attrib & FILE_A_DIR)?'D':' ',  /* keep this one? its always true */
849
      (ddata->dwDirAttributes & FILE_ATTRIBUTE_ARCHIVE)?'A':' ',
847
      (ddata->attrib & FILE_A_ARCH)?'A':' ',
850
      (ddata->dwDirAttributes & FILE_ATTRIBUTE_SYSTEM)?'S':' ',
848
      (ddata->attrib & FILE_A_SYSTEM)?'S':' ',
851
      (ddata->dwDirAttributes & FILE_ATTRIBUTE_HIDDEN)?'H':' ',
849
      (ddata->attrib & FILE_A_HIDDEN)?'H':' ',
852
      (ddata->dwDirAttributes & FILE_ATTRIBUTE_READONLY)?'R':' '
850
      (ddata->attrib & FILE_A_READONLY)?'R':' '
853
    );
851
    );
854
 
852
 
855
  /* display directory name */
853
  /* display directory name */
856
  pprintf("%s\n", currentpath);
854
  pprintf("%s\n", currentpath);
857
}
855
}
Line 885... Line 883...
885
 * Path must end in slash \ or /
883
 * Path must end in slash \ or /
886
 * Returns -1 on error,
884
 * Returns -1 on error,
887
 *          0 if no files, but no errors either,
885
 *          0 if no files, but no errors either,
888
 *      or  1 if files displayed, no errors.
886
 *      or  1 if files displayed, no errors.
889
 */
887
 */
890
static int displayFiles(char *path, char *padding, int hasMoreSubdirs, DIRDATA *ddata) {
888
static int displayFiles(const char *path, char *padding, int hasMoreSubdirs, DIRDATA *ddata) {
891
  static char buffer[MAXBUF];
889
  static char buffer[MAXBUF];
892
  struct WIN32_FIND_DATA entry; /* current directory entry info    */
890
  struct WIN32_FIND_DATA entry; /* current directory entry info    */
893
  struct FFDTA *dir;         /* Current directory entry working with      */
891
  struct FFDTA *dir;         /* Current directory entry working with      */
894
  unsigned long filesShown = 0;
892
  unsigned long filesShown = 0;
895
 
893
 
Line 904... Line 902...
904
 
902
 
905
  /* cycle through directory printing out files. */
903
  /* cycle through directory printing out files. */
906
  do
904
  do
907
  {
905
  {
908
    /* print padding followed by filename */
906
    /* print padding followed by filename */
909
    if ( ((entry.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) &&
907
    if ( ((entry.attrib & FILE_A_DIR) == 0) &&
910
         ( ((entry.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN |
-
 
911
         FILE_ATTRIBUTE_SYSTEM)) == 0)  || dspAll) )
908
         ( ((entry.attrib & (FILE_A_HIDDEN | FILE_A_SYSTEM)) == 0)  || dspAll) )
912
    {
909
    {
913
      /* print lead padding */
910
      /* print lead padding */
914
      pprintf("%s", padding);
911
      pprintf("%s", padding);
915
 
912
 
916
      /* optional display data */
913
      /* optional display data */
917
      if (dspAttr)  /* file attributes */
914
      if (dspAttr)  /* file attributes */
918
        pprintf("[%c%c%c%c] ",
915
        pprintf("[%c%c%c%c] ",
919
          (entry.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE)?'A':' ',
916
          (entry.attrib & FILE_A_ARCH)?'A':' ',
920
          (entry.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)?'S':' ',
917
          (entry.attrib & FILE_A_SYSTEM)?'S':' ',
921
          (entry.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)?'H':' ',
918
          (entry.attrib & FILE_A_HIDDEN)?'H':' ',
922
          (entry.dwFileAttributes & FILE_ATTRIBUTE_READONLY)?'R':' '
919
          (entry.attrib & FILE_A_READONLY)?'R':' '
923
        );
920
        );
924
 
921
 
925
      if (dspSize)  /* file size */
922
      if (dspSize)  /* file size */
926
      {
923
      {
927
        if (entry.nFileSizeHigh)
924
        if (entry.nFileSizeHigh)
Line 973... Line 970...
973
static struct FFDTA *cycleFindResults(struct FFDTA *findnexthnd, struct WIN32_FIND_DATA *entry, char *subdir, char *dsubdir) {
970
static struct FFDTA *cycleFindResults(struct FFDTA *findnexthnd, struct WIN32_FIND_DATA *entry, char *subdir, char *dsubdir) {
974
  /* cycle through directory until 1st non . or .. directory is found. */
971
  /* cycle through directory until 1st non . or .. directory is found. */
975
  do
972
  do
976
  {
973
  {
977
    /* skip files & hidden or system directories */
974
    /* skip files & hidden or system directories */
978
    if ((((entry->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) ||
975
    if ((((entry->attrib & FILE_A_DIR) == 0) ||
979
         ((entry->dwFileAttributes &
976
         ((entry->attrib &
980
          (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) != 0  && !dspAll) ) ||
977
          (FILE_A_HIDDEN | FILE_A_SYSTEM)) != 0  && !dspAll) ) ||
981
        ((strcmp(entry->cFileName, ".") == 0) ||
-
 
982
         (strcmp(entry->cFileName, "..") == 0)) )
978
        (entry->cFileName[0] == '.')) {
983
    {
-
 
984
      if (FindNextFile(findnexthnd, entry) == 0)
979
      if (FindNextFile(findnexthnd, entry) == 0)
985
      {
980
      {
986
        FindClose(findnexthnd);      // prevent resource leaks
981
        FindClose(findnexthnd);      // prevent resource leaks
987
        return INVALID_HANDLE_VALUE; // no subdirs found
982
        return INVALID_HANDLE_VALUE; // no subdirs found
988
      }
983
      }