/*
* preview.c using 'convert'
* for Animal Pictures Archive
* jskim@bulls.kordic.re.kr
*/
#include "preview.h"
#include "NameSearch/AD_Buf.h"
int lang = 0; /* 0 for english 1 for Korean */
int main()
{
FILE *fp, *fhtml;
char *srcFile, *srcPath;
char previewFile[256];
char FilePath[256];
getentry entries[5];
int width; /* x width in pixel to Resize */
char buf[256];
char line[256];
char *ptr;
register int i, x;
printf("content-type: text/html\n\n"); /* HTML Header */
#ifdef FILEOUT
printf("Debugging Mode\n");
i = 2;
strcpy(entries[0].name, "img");
strcpy(entries[0].val, "animal1/AztecAnts_J01-workers_kill_the_invader.jpg");
strcpy(entries[1].name, "width");
strcpy(entries[1].val, "400");
#else
i = ProcessGetMethod( entries );
#endif
width=0;
for (x = 0; x <= i; x++)
{
if (!strcmp(entries[x].name, "img"))
{
strcpy(FilePath, entries[x].val);
strcpy(buf, entries[x].val);
while (ptr = (char *)strstr(buf, "/"))
{
strcpy(buf, ptr+1);
}
srcFile = (char *) malloc(strlen(buf)+1);
strcpy(srcFile, buf);
strcpy(buf, entries[x].val);
ptr = (char *) strstr(buf, srcFile);
*ptr = '\0';
srcPath = (char *) malloc(strlen(buf)+1);
strcpy(srcPath, buf);
continue;
}
if (!strcmp(entries[x].name, "Lang"))
{
if (!strcasecmp(entries[x].val, "Korean"))
lang = 1;
continue;
}
if (!strcmp(entries[x].name, "width"))
{
width = atoi(entries[x].val);
continue;
}
}
if ( width <= 0)
width = 400; /* Default to 400 */
strcpy(buf, srcFile);
for (i = strlen(srcFile); i > 0; i--)
{
if (buf[i] == '.')
{
buf[i] = '\0';
break;
}
}
if (strstr(srcFile, ".jpg") || strstr(srcFile, ".JPG") || \
strstr(srcFile, ".gif") || strstr(srcFile, ".GIF"))
{
strcpy(previewFile, buf);
if ( strstr(srcFile, ".gif") || strstr(srcFile, ".GIF"))
sprintf(buf, "-s%d.gif", width);
else sprintf(buf, "-s%d.jpg", width);
strcat(previewFile, buf);
sprintf(buf, "%s/%s", PREVIEW_DIR, previewFile);
if ( (fp=fopen(buf, "r")) == NULL )
{
sprintf(buf, "%s -frame 10 -geometry %dx%d \"%s%s\" \"%s/%s\"",\
CONVERT, width, width, srcPath, srcFile, \
PREVIEW_DIR, previewFile);
if (system(buf) == -1) {
printf("problem in preview...
\n");
printf("",\
srcPath, srcFile);
printf("Click here to see full image
\n");
exit(1);
}
}
else
fclose(fp);
}
else
{
printf("The Image %s cannot be previewed.
\n", srcFile);
printf("", srcPath, srcFile);
printf("Click here to see full image
\n");
exit(0);
}
if (lang == 1)
fhtml = fopen(PREVIEW_HTML_HAN, "r");
else
fhtml = fopen(PREVIEW_HTML, "r");
if (fhtml == NULL) {
printf("can't open the template HTML for preview
\n");
exit(0);
}
while (fgets(line, 256, fhtml)) {
if (ptr = (char *)strstr(line, "___IMAGE_NAME___")) {
*ptr = '\0'; printf("%s\n", line);
printf("%s\n", srcFile);
printf("%s\n", ptr+16);
continue;
}
if (ptr = (char *)strstr(line, "___IMAGE_PATH___")) {
*ptr = '\0'; printf("%s", line);
printf("%s", FilePath);
printf("%s\n", ptr+16);
continue;
}
if (ptr = (char *)strstr(line, "___PREVIEW_IMAGE_PATH___")) {
*ptr = '\0'; printf("%s", line);
printf("%s/%s", PREVIEW_DIR, previewFile);
printf("%s\n", ptr+24);
continue;
}
if (ptr = (char *)strstr(line, "___DESCRIPTION_FILE___")) {
*ptr = '\0'; printf("%s\n", line);
PrintDescriptionFile(FilePath);
printf("%s\n", ptr+22);
continue;
}
printf("%s\n", line);
}
fclose(fhtml);
free(srcFile); free(srcPath);
exit(0);
}
int PrintDescriptionFile(char FilePath[])
{
FILE *fp;
int i;
char srcFileDesc[256];
char buf[256];
char buf2[256];
strcpy(buf, FilePath);
for (i = strlen(FilePath); i > 0; i--) {
if (FilePath[i] == '.') {
buf[i] = '\0';
break;
}
}
printf("
\n");
while (1)
{
strcpy(srcFileDesc, buf);
strcat(srcFileDesc, ".txt");
if ( (fp=fopen(srcFileDesc, "r")) == NULL ) ;
else
{
printf("\n");
while(fgets(buf2, 256, fp))
PrintLink(buf2);
printf("\n");
fclose(fp);
break;
}
strcpy(srcFileDesc, buf);
strcat(srcFileDesc, ".TXT");
if ( (fp=fopen(srcFileDesc, "r")) == NULL ) ;
else
{
printf("\n");
while(fgets(buf2, 256, fp))
PrintLink(buf2);
printf("\n");
fclose(fp);
break;
}
strcpy(srcFileDesc, buf);
strcat(srcFileDesc, ".html");
if ( (fp=fopen(srcFileDesc, "r")) == NULL ) ;
else
{
printf("");
while(fgets(buf2, 256, fp))
if (!(strstr(buf2, " |