Subversion Repositories SvarDOS

Rev

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

Rev 2052 Rev 2053
Line 594... Line 594...
594
 * On error (invalid path) displays message and returns -1L.
594
 * On error (invalid path) displays message and returns -1L.
595
 * Stores additional directory data in ddata if non-NULL
595
 * Stores additional directory data in ddata if non-NULL
596
 * and path is valid.
596
 * and path is valid.
597
 */
597
 */
598
static long hasSubdirectories(char *path, DIRDATA *ddata) {
598
static long hasSubdirectories(char *path, DIRDATA *ddata) {
599
  static struct WIN32_FIND_DATA findData;
599
  static struct FFDTA findData;
600
  struct FFDTA *hnd;
600
  struct FFDTA *hnd;
601
  static char buffer[MAXBUF];
601
  static char buffer[MAXBUF];
602
  int hasSubdirs = 0;
602
  int hasSubdirs = 0;
603
 
603
 
604
  /* get the handle to start with (using wildcard spec) */
604
  /* get the handle to start with (using wildcard spec) */
Line 615... Line 615...
615
    return(-1);
615
    return(-1);
616
  }
616
  }
617
 
617
 
618
  /*  cycle through entries counting directories found until no more entries */
618
  /*  cycle through entries counting directories found until no more entries */
619
  do {
619
  do {
620
    if (((findData.attrib & FILE_A_DIR) != 0) &&
620
    if (((findData.ff_attr & FILE_A_DIR) != 0) &&
621
        ((findData.attrib &
621
        ((findData.ff_attr &
622
         (FILE_A_HIDDEN | FILE_A_SYSTEM)) == 0 || dspAll) ) {
622
         (FILE_A_HIDDEN | FILE_A_SYSTEM)) == 0 || dspAll) ) {
623
      if (findData.cFileName[0] != '.') { /* ignore '.' and '..' */
623
      if (findData.ff_name[0] != '.') { /* ignore '.' and '..' */
624
        hasSubdirs++;      /* subdir of initial path found, so increment counter */
624
        hasSubdirs++;      /* subdir of initial path found, so increment counter */
625
      }
625
      }
626
    }
626
    }
627
  } while(FindNextFile(hnd, &findData) != 0);
627
  } while(FindNextFile(hnd, &findData) != 0);
628
 
628
 
Line 850... Line 850...
850
 *          0 if no files, but no errors either,
850
 *          0 if no files, but no errors either,
851
 *      or  1 if files displayed, no errors.
851
 *      or  1 if files displayed, no errors.
852
 */
852
 */
853
static int displayFiles(const char *path, char *padding, int hasMoreSubdirs, DIRDATA *ddata) {
853
static int displayFiles(const char *path, char *padding, int hasMoreSubdirs, DIRDATA *ddata) {
854
  static char buffer[MAXBUF];
854
  static char buffer[MAXBUF];
855
  struct WIN32_FIND_DATA entry; /* current directory entry info    */
855
  struct FFDTA entry;   /* current directory entry info    */
856
  struct FFDTA *dir;         /* Current directory entry working with      */
856
  struct FFDTA *dir;    /* Current directory entry working with      */
857
  unsigned long filesShown = 0;
857
  unsigned long filesShown = 0;
858
 
858
 
859
  /* get handle for files in current directory (using wildcard spec) */
859
  /* get handle for files in current directory (using wildcard spec) */
860
  strcpy(buffer, path);
860
  strcpy(buffer, path);
861
  strcat(buffer, "*");
861
  strcat(buffer, "*");
Line 866... Line 866...
866
 
866
 
867
  /* cycle through directory printing out files. */
867
  /* cycle through directory printing out files. */
868
  do
868
  do
869
  {
869
  {
870
    /* print padding followed by filename */
870
    /* print padding followed by filename */
871
    if ( ((entry.attrib & FILE_A_DIR) == 0) &&
871
    if ( ((entry.ff_attr & FILE_A_DIR) == 0) &&
872
         ( ((entry.attrib & (FILE_A_HIDDEN | FILE_A_SYSTEM)) == 0)  || dspAll) )
872
         ( ((entry.ff_attr & (FILE_A_HIDDEN | FILE_A_SYSTEM)) == 0)  || dspAll) )
873
    {
873
    {
874
      /* print lead padding */
874
      /* print lead padding */
875
      pprintf("%s", padding);
875
      pprintf("%s", padding);
876
 
876
 
877
      /* optional display data */
877
      /* optional display data */
878
      if (dspAttr)  /* file attributes */
878
      if (dspAttr)  /* file attributes */
879
        pprintf("[%c%c%c%c] ",
879
        pprintf("[%c%c%c%c] ",
880
          (entry.attrib & FILE_A_ARCH)?'A':' ',
880
          (entry.ff_attr & FILE_A_ARCH)?'A':' ',
881
          (entry.attrib & FILE_A_SYSTEM)?'S':' ',
881
          (entry.ff_attr & FILE_A_SYSTEM)?'S':' ',
882
          (entry.attrib & FILE_A_HIDDEN)?'H':' ',
882
          (entry.ff_attr & FILE_A_HIDDEN)?'H':' ',
883
          (entry.attrib & FILE_A_READONLY)?'R':' '
883
          (entry.ff_attr & FILE_A_READONLY)?'R':' '
884
        );
884
        );
885
 
885
 
886
      if (dspSize)  /* file size */
886
      if (dspSize) { /* file size */
887
      {
-
 
888
        if (entry.nFileSizeHigh)
-
 
889
        {
-
 
890
          pprintf("******** ");  /* error exceed max value we can display, > 4GB */
-
 
891
        }
-
 
892
        else
-
 
893
        {
-
 
894
          if (entry.nFileSizeLow < 1048576l)  /* if less than a MB, display in bytes */
887
        if (entry.ff_fsize < 1048576ul)  /* if less than a MB, display in bytes */
895
            pprintf("%10lu ", entry.nFileSizeLow);
888
          pprintf("%10lu ", entry.ff_fsize);
896
          else                               /* otherwise display in KB */
889
        else                               /* otherwise display in KB */
897
            pprintf("%8luKB ", entry.nFileSizeLow/1024UL);
890
          pprintf("%8luKB ", entry.ff_fsize / 1024ul);
898
        }
-
 
899
      }
891
      }
900
 
892
 
901
      /* print filename */
893
      /* print filename */
902
      pprintf("%s\n", entry.cFileName);
894
      pprintf("%s\n", entry.ff_name);
903
 
895
 
904
      filesShown++;
896
      filesShown++;
905
    }
897
    }
906
  } while(FindNextFile(dir, &entry) != 0);
898
  } while(FindNextFile(dir, &entry) != 0);
907
 
899
 
Line 929... Line 921...
929
 * was found, and if so copies appropriate data into subdir and dsubdir.
921
 * was found, and if so copies appropriate data into subdir and dsubdir.
930
 * It will repeat until a valid subdirectory is found or no more
922
 * It will repeat until a valid subdirectory is found or no more
931
 * are found, at which point it closes the FindFile search handle and
923
 * are found, at which point it closes the FindFile search handle and
932
 * return NULL.  If successful, returns FindFile handle.
924
 * return NULL.  If successful, returns FindFile handle.
933
 */
925
 */
934
static struct FFDTA *cycleFindResults(struct FFDTA *findnexthnd, struct WIN32_FIND_DATA *entry, char *subdir, char *dsubdir) {
926
static struct FFDTA *cycleFindResults(struct FFDTA *findnexthnd, struct FFDTA *entry, char *subdir, char *dsubdir) {
935
  /* cycle through directory until 1st non . or .. directory is found. */
927
  /* cycle through directory until 1st non . or .. directory is found. */
936
  do
928
  do
937
  {
929
  {
938
    /* skip files & hidden or system directories */
930
    /* skip files & hidden or system directories */
939
    if ((((entry->attrib & FILE_A_DIR) == 0) ||
931
    if ((((entry->ff_attr & FILE_A_DIR) == 0) ||
940
         ((entry->attrib &
932
         ((entry->ff_attr &
941
          (FILE_A_HIDDEN | FILE_A_SYSTEM)) != 0  && !dspAll) ) ||
933
          (FILE_A_HIDDEN | FILE_A_SYSTEM)) != 0  && !dspAll) ) ||
942
        (entry->cFileName[0] == '.')) {
934
        (entry->ff_name[0] == '.')) {
943
      if (FindNextFile(findnexthnd, entry) == 0) {
935
      if (FindNextFile(findnexthnd, entry) == 0) {
944
        FindClose(findnexthnd);      // prevent resource leaks
936
        FindClose(findnexthnd);      // prevent resource leaks
945
        return(NULL); // no subdirs found
937
        return(NULL); // no subdirs found
946
      }
938
      }
947
    } else {
939
    } else {
948
      /* set display name */
940
      /* set display name */
949
      strcpy(dsubdir, entry->cFileName);
941
      strcpy(dsubdir, entry->ff_name);
950
 
942
 
951
      strcpy(subdir, entry->cFileName);
943
      strcpy(subdir, entry->ff_name);
952
      strcat(subdir, "\\");
944
      strcat(subdir, "\\");
953
    }
945
    }
954
  } while (!*subdir); // while (subdir is still blank)
946
  } while (!*subdir); // while (subdir is still blank)
955
 
947
 
956
  return findnexthnd;
948
  return findnexthnd;
957
}
949
}
958
 
950
 
959
 
951
 
960
/* FindFile buffer used by findFirstSubdir and findNextSubdir only */
952
/* FindFile buffer used by findFirstSubdir and findNextSubdir only */
961
static struct WIN32_FIND_DATA findSubdir_entry; /* current directory entry info    */
953
static struct FFDTA findSubdir_entry; /* current directory entry info    */
962
 
954
 
963
/**
955
/**
964
 * Given the current path, find the 1st subdirectory.
956
 * Given the current path, find the 1st subdirectory.
965
 * The subdirectory found is stored in subdir.
957
 * The subdirectory found is stored in subdir.
966
 * subdir is cleared on error or no subdirectories.
958
 * subdir is cleared on error or no subdirectories.