#include #include #include #include #include #include "web.h" #define HTML_TEMPLATE "/home/jinsuk/WebDocs/AnimalPicturesArchive.com/animal/HTMLSrc/han_idx.html" #define HTML_DIR "/home/jinsuk/WebDocs/AnimalPicturesArchive.com/animal/Dic" #define FILE_NAME_LEN 100 #define MAX_FILE_NUM 8192 int str_comp(char *, char *); char fname[MAX_FILE_NUM][FILE_NAME_LEN]; main() { FILE *fp, *fout; DIR *dirp; struct dirent *direntp; char *ptr; char line[256]; char path[256]; /* file path */ char name[256]; /* animal name */ int cnt; int i; /* general purposes */ fp = fopen(HTML_TEMPLATE, "r"); if (fp == NULL) { printf("HTML template error\n"); exit(0); } sprintf(path, "%s/index.html", HTML_DIR); fout = fopen(path, "w"); if (fout == NULL) { printf("HTML index [%s] open error\n", path); exit(0); } cnt = 0; dirp = opendir( HTML_DIR ); while ( (direntp = readdir( dirp )) != NULL ) { if (!strcmp(direntp->d_name, ".html")) continue; if (!strncmp(direntp->d_name, "index", 5)) continue; ptr = (char *) strstr(direntp->d_name, "."); if (!strcmp(ptr+1, "html")) { strcpy(fname[cnt], direntp->d_name); cnt++; } } closedir( dirp ); qsort(fname, cnt, FILE_NAME_LEN, (int *)str_comp); /* print the HTML */ while (fgets(line, 256, fp)) { if (!strncasecmp(line, "___FILE_LIST_HERE___", 20)) { fprintf(fout, "\n"); for (i=0; i < cnt; i++) { if ( i%((cnt+3)/3) == 0 ) { if (i>0) fprintf(fout,"\n"); fprintf(fout, "
    \n", i+1); } make_name(fname[i], name); fprintf(fout, "
  1. %s\n", URLencode(fname[i]),name); } fprintf(fout, "
\n"); } else fprintf(fout, "%s", line); } fclose(fp); exit(0); } int str_comp(char *i, char *j) { return (strcasecmp(i, j)); } int make_name(char *org, char *new) { char *ptr; strcpy(new, org); ptr = (char *)strstr(new, ".html"); if (ptr == NULL) return 0; *ptr = '\0'; return 0; }