#include #include #include #include #include #define HTML_DIR "/home/jskim/public_html/animal/EngNames" #define URL_HEADER "http://AnimalPicturesArchive.com/animal/EngNames" #define FILE_NAME_LEN 100 #define MAX_FILE_NUM 8192 char fname[MAX_FILE_NUM][FILE_NAME_LEN]; main() { DIR *dirp; struct dirent *direntp; char *ptr; int cnt; time_t curTime; int idx; /* general purposes */ /* printf("Content-type: text/html\n\n"); */ 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 ); time(&curTime); idx = curTime%cnt; printf("Location: %s/%s\n\n", URL_HEADER, fname[idx]); exit(0); }