Subversion Repositories SvarDOS

Rev

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

Rev 2047 Rev 2048
Line 643... Line 643...
643
  /* Use FindFirstFileEx when available (falls back to FindFirstFile).
643
  /* Use FindFirstFileEx when available (falls back to FindFirstFile).
644
   * Allows us to limit returned results to just directories
644
   * Allows us to limit returned results to just directories
645
   * if supported by underlying filesystem.
645
   * if supported by underlying filesystem.
646
   */
646
   */
647
  hnd = FindFirstFile(buffer, &findData);
647
  hnd = FindFirstFile(buffer, &findData);
648
  if (hnd == INVALID_HANDLE_VALUE) {
648
  if (hnd == NULL) {
649
    showInvalidPath(path); /* Display error message */
649
    showInvalidPath(path); /* Display error message */
650
    return -1L;
650
    return(-1);
651
  }
651
  }
652
 
652
 
653
 
-
 
654
  /*  cycle through entries counting directories found until no more entries */
653
  /*  cycle through entries counting directories found until no more entries */
655
  do {
654
  do {
656
    if (((findData.attrib & FILE_A_DIR) != 0) &&
655
    if (((findData.attrib & FILE_A_DIR) != 0) &&
657
        ((findData.attrib &
656
        ((findData.attrib &
658
         (FILE_A_HIDDEN | FILE_A_SYSTEM)) == 0 || dspAll) ) {
657
         (FILE_A_HIDDEN | FILE_A_SYSTEM)) == 0 || dspAll) ) {
Line 740... Line 739...
740
    free (temp->currentpath);
739
    free (temp->currentpath);
741
    free (temp->dsubdir);
740
    free (temp->dsubdir);
742
    free(temp);
741
    free(temp);
743
    return NULL;
742
    return NULL;
744
  }
743
  }
745
  temp->findnexthnd = INVALID_HANDLE_VALUE;
744
  temp->findnexthnd = NULL;
746
 
745
 
747
  return temp;
746
  return temp;
748
}
747
}
749
 
748
 
-
 
749
 
750
/**
750
/**
751
 * Extends the padding with the necessary 4 characters.
751
 * Extends the padding with the necessary 4 characters.
752
 * Returns the pointer to the padding.
752
 * Returns the pointer to the padding.
753
 * padding should be large enough to hold the additional
753
 * padding should be large enough to hold the additional
754
 * characters and '\0', moreSubdirsFollow specifies if
754
 * characters and '\0', moreSubdirsFollow specifies if
Line 893... Line 893...
893
 
893
 
894
  /* get handle for files in current directory (using wildcard spec) */
894
  /* get handle for files in current directory (using wildcard spec) */
895
  strcpy(buffer, path);
895
  strcpy(buffer, path);
896
  strcat(buffer, "*");
896
  strcat(buffer, "*");
897
  dir = FindFirstFile(buffer, &entry);
897
  dir = FindFirstFile(buffer, &entry);
898
  if (dir == INVALID_HANDLE_VALUE)
898
  if (dir == NULL) return(-1);
899
    return -1;
-
 
900
 
899
 
901
  addPadding(padding, hasMoreSubdirs);
900
  addPadding(padding, hasMoreSubdirs);
902
 
901
 
903
  /* cycle through directory printing out files. */
902
  /* cycle through directory printing out files. */
904
  do
903
  do
Line 963... Line 962...
963
 * Common portion of findFirstSubdir and findNextSubdir
962
 * Common portion of findFirstSubdir and findNextSubdir
964
 * Checks current FindFile results to determine if a valid directory
963
 * Checks current FindFile results to determine if a valid directory
965
 * was found, and if so copies appropriate data into subdir and dsubdir.
964
 * was found, and if so copies appropriate data into subdir and dsubdir.
966
 * It will repeat until a valid subdirectory is found or no more
965
 * It will repeat until a valid subdirectory is found or no more
967
 * are found, at which point it closes the FindFile search handle and
966
 * are found, at which point it closes the FindFile search handle and
968
 * return INVALID_HANDLE_VALUE.  If successful, returns FindFile handle.
967
 * return NULL.  If successful, returns FindFile handle.
969
 */
968
 */
970
static struct FFDTA *cycleFindResults(struct FFDTA *findnexthnd, struct WIN32_FIND_DATA *entry, char *subdir, char *dsubdir) {
969
static struct FFDTA *cycleFindResults(struct FFDTA *findnexthnd, struct WIN32_FIND_DATA *entry, char *subdir, char *dsubdir) {
971
  /* cycle through directory until 1st non . or .. directory is found. */
970
  /* cycle through directory until 1st non . or .. directory is found. */
972
  do
971
  do
973
  {
972
  {
974
    /* skip files & hidden or system directories */
973
    /* skip files & hidden or system directories */
975
    if ((((entry->attrib & FILE_A_DIR) == 0) ||
974
    if ((((entry->attrib & FILE_A_DIR) == 0) ||
976
         ((entry->attrib &
975
         ((entry->attrib &
977
          (FILE_A_HIDDEN | FILE_A_SYSTEM)) != 0  && !dspAll) ) ||
976
          (FILE_A_HIDDEN | FILE_A_SYSTEM)) != 0  && !dspAll) ) ||
978
        (entry->cFileName[0] == '.')) {
977
        (entry->cFileName[0] == '.')) {
979
      if (FindNextFile(findnexthnd, entry) == 0)
978
      if (FindNextFile(findnexthnd, entry) == 0) {
980
      {
-
 
981
        FindClose(findnexthnd);      // prevent resource leaks
979
        FindClose(findnexthnd);      // prevent resource leaks
982
        return INVALID_HANDLE_VALUE; // no subdirs found
980
        return(NULL); // no subdirs found
983
      }
981
      }
984
    }
-
 
985
    else
982
    } else {
986
    {
-
 
987
      /* set display name */
983
      /* set display name */
988
      strcpy(dsubdir, entry->cFileName);
984
      strcpy(dsubdir, entry->cFileName);
989
 
985
 
990
      strcpy(subdir, entry->cFileName);
986
      strcpy(subdir, entry->cFileName);
991
      strcat(subdir, "\\");
987
      strcat(subdir, "\\");
Line 1004... Line 1000...
1004
 * The subdirectory found is stored in subdir.
1000
 * The subdirectory found is stored in subdir.
1005
 * subdir is cleared on error or no subdirectories.
1001
 * subdir is cleared on error or no subdirectories.
1006
 * Returns the findfirst search HANDLE, which should be passed to
1002
 * Returns the findfirst search HANDLE, which should be passed to
1007
 * findclose when directory has finished processing, and can be
1003
 * findclose when directory has finished processing, and can be
1008
 * passed to findnextsubdir to find subsequent subdirectories.
1004
 * passed to findnextsubdir to find subsequent subdirectories.
1009
 * Returns INVALID_HANDLE_VALUE on error.
1005
 * Returns NULL on error.
1010
 * currentpath must end in \
1006
 * currentpath must end in \
1011
 */
1007
 */
1012
static struct FFDTA *findFirstSubdir(char *currentpath, char *subdir, char *dsubdir) {
1008
static struct FFDTA *findFirstSubdir(char *currentpath, char *subdir, char *dsubdir) {
1013
  static char buffer[MAXBUF];
1009
  static char buffer[MAXBUF];
1014
  struct FFDTA *dir;         /* Current directory entry working with      */
1010
  struct FFDTA *dir;         /* Current directory entry working with      */
Line 1016... Line 1012...
1016
  /* get handle for files in current directory (using wildcard spec) */
1012
  /* get handle for files in current directory (using wildcard spec) */
1017
  strcpy(buffer, currentpath);
1013
  strcpy(buffer, currentpath);
1018
  strcat(buffer, "*");
1014
  strcat(buffer, "*");
1019
 
1015
 
1020
  dir = FindFirstFile(buffer, &findSubdir_entry);
1016
  dir = FindFirstFile(buffer, &findSubdir_entry);
1021
  if (dir == INVALID_HANDLE_VALUE) {
1017
  if (dir == NULL) {
1022
    showInvalidPath(currentpath);
1018
    showInvalidPath(currentpath);
1023
    return INVALID_HANDLE_VALUE;
1019
    return(NULL);
1024
  }
1020
  }
1025
 
1021
 
1026
  /* clear result path */
1022
  /* clear result path */
1027
  strcpy(subdir, "");
1023
  strcpy(subdir, "");
1028
 
1024
 
Line 1041... Line 1037...
1041
  /* clear result path */
1037
  /* clear result path */
1042
  strcpy(subdir, "");
1038
  strcpy(subdir, "");
1043
 
1039
 
1044
  if (FindNextFile(findnexthnd, &findSubdir_entry) == 0) return 1; // no subdirs found
1040
  if (FindNextFile(findnexthnd, &findSubdir_entry) == 0) return 1; // no subdirs found
1045
 
1041
 
1046
  if (cycleFindResults(findnexthnd, &findSubdir_entry, subdir, dsubdir) == INVALID_HANDLE_VALUE)
1042
  if (cycleFindResults(findnexthnd, &findSubdir_entry, subdir, dsubdir) == NULL) {
1047
    return 1;
1043
    return 1;
1048
  else
1044
  }
1049
    return 0;
1045
  return 0;
1050
}
1046
}
1051
 
1047
 
1052
/**
1048
/**
1053
 * Given an initial path, displays the directory tree with
1049
 * Given an initial path, displays the directory tree with
1054
 * a non-recursive function using a Stack.
1050
 * a non-recursive function using a Stack.
Line 1065... Line 1061...
1065
 
1061
 
1066
  STACK s;
1062
  STACK s;
1067
  stackDefaults(&s);
1063
  stackDefaults(&s);
1068
  stackInit(&s);
1064
  stackInit(&s);
1069
 
1065
 
1070
  if ( (sdi = newSubdirInfo(NULL, initialpath, initialpath)) == NULL)
1066
  if ( (sdi = newSubdirInfo(NULL, initialpath, initialpath)) == NULL) {
1071
    return 0L;
1067
    return(0);
-
 
1068
  }
1072
  stackPushItem(&s, sdi);
1069
  stackPushItem(&s, sdi);
1073
 
1070
 
1074
  /* Store count of subdirs in initial path so can display message if none. */
1071
  /* Store count of subdirs in initial path so can display message if none. */
1075
  subdirsInInitialpath = sdi->subdircnt;
1072
  subdirsInInitialpath = sdi->subdircnt;
1076
 
1073
 
1077
  do
1074
  do
1078
  {
1075
  {
1079
    sdi = (SUBDIRINFO *)stackPopItem(&s);
1076
    sdi = (SUBDIRINFO *)stackPopItem(&s);
1080
 
1077
 
1081
    if (sdi->findnexthnd == INVALID_HANDLE_VALUE)  // findfirst not called yet
1078
    if (sdi->findnexthnd == NULL) { // findfirst not called yet
1082
    {
-
 
1083
      // 1st time this subdirectory processed, so display its name & possibly files
1079
      // 1st time this subdirectory processed, so display its name & possibly files
1084
      if (sdi->parent == NULL) // if initial path
1080
      if (sdi->parent == NULL) // if initial path
1085
      {
1081
      {
1086
        // display initial path
1082
        // display initial path
1087
        showCurrentPath(/*sdi->dsubdir*/initialpath, NULL, -1, &(sdi->ddata));
1083
        showCurrentPath(/*sdi->dsubdir*/initialpath, NULL, -1, &(sdi->ddata));
Line 1097... Line 1093...
1097
    }
1093
    }
1098
 
1094
 
1099
    if (sdi->subdircnt > 0) /* if (there are more subdirectories to process) */
1095
    if (sdi->subdircnt > 0) /* if (there are more subdirectories to process) */
1100
    {
1096
    {
1101
      int flgErr;
1097
      int flgErr;
1102
      if (sdi->findnexthnd == INVALID_HANDLE_VALUE)
1098
      if (sdi->findnexthnd == NULL) {
1103
      {
-
 
1104
        sdi->findnexthnd = findFirstSubdir(sdi->currentpath, subdir, dsubdir);
1099
        sdi->findnexthnd = findFirstSubdir(sdi->currentpath, subdir, dsubdir);
1105
        flgErr = (sdi->findnexthnd == INVALID_HANDLE_VALUE);
1100
        flgErr = (sdi->findnexthnd == NULL);
1106
      }
-
 
1107
      else
1101
      } else {
1108
      {
-
 
1109
        flgErr = findNextSubdir(sdi->findnexthnd, subdir, dsubdir);
1102
        flgErr = findNextSubdir(sdi->findnexthnd, subdir, dsubdir);
1110
      }
1103
      }
1111
 
1104
 
1112
      if (flgErr) // don't add invalid paths to stack
1105
      if (flgErr) // don't add invalid paths to stack
1113
      {
1106
      {