int process_sub(FILE *data_file, FILE *struct_file)
{
  FIND_T fInfo;
  FIND_RET_T fret;
  int filesProcessed = 0;

  if (processSubs) {
    /* process subs recursively */
    size_t sublen = strlen(curSubdir);
    size_t freelen = sizeof(curSubdir) - sublen - 1;
    LWIP_ASSERT("sublen < sizeof(curSubdir)", sublen < sizeof(curSubdir));
    fret = FINDFIRST_DIR("*", &fInfo);
    if (FINDFIRST_SUCCEEDED(fret)) {
      do {
        const char *curName = FIND_T_FILENAME(fInfo);
        if ((curName[0] == '.') || (strcmp(curName, "CVS") == 0)) {
          continue;
        }
        if (!FIND_T_IS_DIR(fInfo)) {
          continue;
        }
        if (freelen > 0) {
           CHDIR(curName);
           strncat(curSubdir, "/", freelen);
           strncat(curSubdir, curName, freelen - 1);
           curSubdir[sizeof(curSubdir) - 1] = 0;
           printf("processing subdirectory %s/..." NEWLINE, curSubdir);
           filesProcessed += process_sub(data_file, struct_file);
           CHDIR("..");
           curSubdir[sublen] = 0;
        } else {
           printf("WARNING: cannot process sub due to path length restrictions: \"%s/%s\"\n", curSubdir, curName);
        }
      } while (FINDNEXT_SUCCEEDED(FINDNEXT(fret, &fInfo)));
    }
  }

  fret = FINDFIRST_FILE("*.*", &fInfo);
  if (FINDFIRST_SUCCEEDED(fret)) {
    /* at least one file in directory */
    do {
      if (FIND_T_IS_FILE(fInfo)) {
        const char *curName = FIND_T_FILENAME(fInfo);
        printf("processing %s/%s..." NEWLINE, curSubdir, curName);
        if (process_file(data_file, struct_file, curName) < 0) {
          printf(NEWLINE "Error... aborting" NEWLINE);
          return -1;
        }
        filesProcessed++;
      }
    } while (FINDNEXT_SUCCEEDED(FINDNEXT(fret, &fInfo)));
  }
  return filesProcessed;
}
Example #2
0
int process_sub(FILE *data_file, FILE *struct_file)
{
  FIND_T fInfo;
  FIND_RET_T fret;
  int filesProcessed = 0;
  char oldSubdir[MAX_PATH_LEN];

  if (processSubs) {
    /* process subs recursively */
    strcpy(oldSubdir, curSubdir);
    fret = FINDFIRST_DIR("*", &fInfo);
    if (FINDFIRST_SUCCEEDED(fret)) {
      do {
        const char *curName = FIND_T_FILENAME(fInfo);
        if (curName == NULL) continue;
        if (curName[0] == '.') continue;
        if (strcmp(curName, "CVS") == 0) continue;
        if (!FIND_T_IS_DIR(fInfo)) continue;
        CHDIR(curName);
        strcat(curSubdir, "/");
        strcat(curSubdir, curName);
        printf(NEWLINE "processing subdirectory %s/..." NEWLINE, curSubdir);
        filesProcessed += process_sub(data_file, struct_file);
        CHDIR("..");
        strcpy(curSubdir, oldSubdir);
      } while (FINDNEXT_SUCCEEDED(FINDNEXT(fret, &fInfo)));
    }
  }

  fret = FINDFIRST_FILE("*.*", &fInfo);
  if (FINDFIRST_SUCCEEDED(fret)) {
    /* at least one file in directory */
    do {
      if (FIND_T_IS_FILE(fInfo)) {
        const char *curName = FIND_T_FILENAME(fInfo);
        printf("processing %s/%s..." NEWLINE, curSubdir, curName);
        if (process_file(data_file, struct_file, curName) < 0) {
          printf(NEWLINE "Error... aborting" NEWLINE);
          return -1;
        }
        filesProcessed++;
      }
    } while (FINDNEXT_SUCCEEDED(FINDNEXT(fret, &fInfo)));
  }
  return filesProcessed;
}