/* * NewImg.c * for Bioinfo Animal Pictures Archive * jskim@bulls.kordic.re.kr * prints image info in ascending order of date */ #define KOREAN 1 #include "version3/web.h" #include #include #include #include #include #define NEW_IMG_DIR "New" #define HTML_ENG "HTMLSrc/New_eng.html" #define HTML_HAN "HTMLSrc/New_han.html" #define CGI_PREVIEW "preview.cgi" #define CGI_VIEW "ViewImg.cgi" #define CGI_MAIL "uu2mail.cgi" typedef struct { char name[256]; int size; /* file size in bytes */ time_t time; /* when added */ }IMAGE; int int_comp(IMAGE *, IMAGE *); static int lang = 0; main() { FILE *fp; DIR *dirp; struct dirent *direntp; struct stat Stat; IMAGE img[1024]; char *ptr; char line[256]; char path[256]; /* file path */ int cnt; time_t CurTime; getentry entries[5]; int i, x; /* general purposes */ int start = 0, end; int dspNum = 10; i = ProcessGetMethod(entries); for (x = 0; x <= i; x++) { if (!strcasecmp(entries[x].name, "start")) { start = atoi(entries[x].val); continue; } if (!strcasecmp(entries[x].name, "dspNum")) { dspNum = atoi(entries[x].val); if (dspNum <= 0) dspNum = 10; continue; } if (!strcasecmp(entries[x].name, "Lang")) { if ( !strcasecmp(entries[x].val, "Korean") ) { lang = KOREAN; } continue; } } printf("content-type: text/html\n\n"); /* HTML Header */ if (lang == KOREAN) fp = fopen(HTML_HAN, "r"); else fp = fopen(HTML_ENG, "r"); if (fp == NULL) { printf("HTML template error\n"); exit(0); } cnt = 0; dirp = opendir( NEW_IMG_DIR ); while ( (direntp = readdir( dirp )) != NULL ) { ptr = (char *) strstr(direntp->d_name, "."); if (!strcasecmp(ptr+1, "jpg") || !strcasecmp(ptr+1, "gif")) { sprintf(path, "%s/%s", NEW_IMG_DIR, direntp->d_name); lstat(path, &Stat); strcpy(img[cnt].name, direntp->d_name); img[cnt].size = Stat.st_size; img[cnt].time = Stat.st_ctime; cnt++; } } closedir( dirp ); qsort(img, cnt, sizeof(IMAGE), (int *)int_comp); time(&CurTime); /* limit the range */ if (start < 0 || start > cnt) start = 0; if (start + dspNum >= cnt) end = cnt; else end = start+dspNum; /* print the HTML */ while (fgets(line, 256, fp)) { if (!strncasecmp(line, "___IMAGE_LIST___", 16)) { printf("\n"); for (i=start; i < end; i++) { PrintImgInfo(i, img[i], CurTime); } printf("
\n"); continue; } if (!strncasecmp(line, "___PAGE_LIST___", 15)) { printPageList(start, dspNum, cnt); } else printf("%s", line); } fclose(fp); exit(0); } int PrintImgInfo(int num, IMAGE img, time_t CurTime) { char path[256]; /* path */ int days; int hours; int i, len; days = (CurTime - img.time)/(24*3600); hours = ( (CurTime - img.time)%(24*3600) )/3600; /* print thumbnail image name */ sprintf(path, "PREVIEW/%s", img.name); for (i=strlen(path); i > 0; i--) { if (path[i] == '.' && !strcasecmp(path+i, ".jpg")) strcpy(path+i, "-s160.jpg"); else if (path[i] == '.' && !strcasecmp(path+i, ".gif")) strcpy(path+i, "-s160.gif"); } makethumbnail(path, img.name); printf( "\n"); if (lang == KOREAN) printf( "",NEW_IMG_DIR, img.name); else printf( "",NEW_IMG_DIR, img.name); printf( "\n", path); sprintf(path, "%s/%s", NEW_IMG_DIR, img.name); printf( "  "); len = strlen(img.name); for (i=0; i\n\n"); return 0; } int int_comp(IMAGE *i, IMAGE *j) { if ( i->time < j->time) return (1); if (i->time > j->time) return (-1); return (0); } int makethumbnail(char *thumbnail, char *srcImg) { FILE *fp; char buf[512]; fp = fopen(thumbnail, "r"); if (fp != NULL) return 0; sprintf(buf, "/usr/X11R6/bin/convert -frame 5 -geometry 160x160 \"%s/%s\" \"%s\"", NEW_IMG_DIR, srcImg, thumbnail); system(buf); return 0; } int printPageList(int start, int dspNum, int cnt) { int i; if (start > 0) { if (lang == KOREAN) printf("[¹Ù·ÎÀü]\n", start-dspNum, dspNum); else printf("[Prev]\n", start-dspNum, dspNum); } for (i=0; i < cnt; i+= dspNum) { if (start == i) printf(" %d\n", i/dspNum+1); else { printf("%d\n", dspNum, i/dspNum+1); } else { printf("&dspNum=%d>%d\n", dspNum, i/dspNum+1); } } } if (start+dspNum < cnt) { if (lang == KOREAN) printf("[´ÙÀ½]\n", start+dspNum, dspNum); else printf("[Next]\n", start+dspNum, dspNum); } }