예제 #1
0
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;
}
예제 #2
0
파일: makefsdata.c 프로젝트: 10code/lwip
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;
}
예제 #3
0
파일: makefsdata.c 프로젝트: 10code/lwip
int main(int argc, char *argv[])
{
  FIND_T fInfo;
  FIND_RET_T fret;
  char path[MAX_PATH_LEN];
  char appPath[MAX_PATH_LEN];
  FILE *data_file;
  FILE *struct_file;
  int filesProcessed;
  int i;
  char targetfile[MAX_PATH_LEN];
  strcpy(targetfile, "fsdata.c");

  memset(path, 0, sizeof(path));
  memset(appPath, 0, sizeof(appPath));

  printf(NEWLINE " makefsdata - HTML to C source converter" NEWLINE);
  printf("     by Jim Pettinato               - circa 2003 " NEWLINE);
  printf("     extended by Simon Goldschmidt  - 2009 " NEWLINE NEWLINE);

  strcpy(path, "fs");
  for(i = 1; i < argc; i++) {
    if (argv[i][0] == '-') {
      if (strstr(argv[i], "-s")) {
        processSubs = 0;
      } else if (strstr(argv[i], "-e")) {
        includeHttpHeader = 0;
      } else if (strstr(argv[i], "-11")) {
        useHttp11 = 1;
      } else if (strstr(argv[i], "-c")) {
        precalcChksum = 1;
      } else if((argv[i][1] == 'f') && (argv[i][2] == ':')) {
        strcpy(targetfile, &argv[i][3]);
        printf("Writing to file \"%s\"\n", targetfile);
      }
    } else {
      strcpy(path, argv[i]);
    }
  }

  /* if command line param or subdir named 'fs' not found spout usage verbiage */
  fret = FINDFIRST_DIR(path, &fInfo);
  if (!FINDFIRST_SUCCEEDED(fret)) {
    /* if no subdir named 'fs' (or the one which was given) exists, spout usage verbiage */
    printf(" Failed to open directory \"%s\"." NEWLINE NEWLINE, path);
    printf(" Usage: htmlgen [targetdir] [-s] [-i] [-f:<filename>]" NEWLINE NEWLINE);
    printf("   targetdir: relative or absolute path to files to convert" NEWLINE);
    printf("   switch -s: toggle processing of subdirectories (default is on)" NEWLINE);
    printf("   switch -e: exclude HTTP header from file (header is created at runtime, default is off)" NEWLINE);
    printf("   switch -11: include HTTP 1.1 header (1.0 is default)" NEWLINE);
    printf("   switch -c: precalculate checksums for all pages (default is off)" NEWLINE);
    printf("   switch -f: target filename (default is \"fsdata.c\")" NEWLINE);
    printf("   if targetdir not specified, htmlgen will attempt to" NEWLINE);
    printf("   process files in subdirectory 'fs'" NEWLINE);
    exit(-1);
  }

  printf("HTTP %sheader will %s statically included." NEWLINE,
    (includeHttpHeader ? (useHttp11 ? "1.1 " : "1.0 ") : ""),
    (includeHttpHeader ? "be" : "not be"));

  sprintf(curSubdir, "");  /* start off in web page's root directory - relative paths */
  printf("  Processing all files in directory %s", path);
  if (processSubs) {
    printf(" and subdirectories..." NEWLINE NEWLINE);
  } else {
    printf("..." NEWLINE NEWLINE);
  }

  GETCWD(appPath, MAX_PATH_LEN);
  data_file = fopen("fsdata.tmp", "wb");
  if (data_file == NULL) {
    printf("Failed to create file \"fsdata.tmp\"\n");
    exit(-1);
  }
  struct_file = fopen("fshdr.tmp", "wb");
  if (struct_file == NULL) {
    printf("Failed to create file \"fshdr.tmp\"\n");
    exit(-1);
  }

  CHDIR(path);

  fprintf(data_file, "#include \"fs.h\"" NEWLINE);
  fprintf(data_file, "#include \"lwip/def.h\"" NEWLINE);
  fprintf(data_file, "#include \"fsdata.h\"" NEWLINE NEWLINE NEWLINE);

  fprintf(data_file, "#define file_NULL (struct fsdata_file *) NULL" NEWLINE NEWLINE NEWLINE);

  sprintf(lastFileVar, "NULL");

  filesProcessed = process_sub(data_file, struct_file);

  /* data_file now contains all of the raw data.. now append linked list of
   * file header structs to allow embedded app to search for a file name */
  fprintf(data_file, NEWLINE NEWLINE);
  fprintf(struct_file, "#define FS_ROOT file_%s" NEWLINE, lastFileVar);
  fprintf(struct_file, "#define FS_NUMFILES %d" NEWLINE NEWLINE, filesProcessed);

  fclose(data_file);
  fclose(struct_file);

  CHDIR(appPath);
  /* append struct_file to data_file */
  printf(NEWLINE "Creating target file..." NEWLINE NEWLINE);
  concat_files("fsdata.tmp", "fshdr.tmp", targetfile);

  /* if succeeded, delete the temporary files */
  remove("fsdata.tmp");
  remove("fshdr.tmp"); 

  printf(NEWLINE "Processed %d files - done." NEWLINE NEWLINE, filesProcessed);

  return 0;
}