/*
* keyword.c
* for Bioinfo Animal Pictures Archive
* jskim@bulls.kordic.re.kr
*/
#include "keyword.h"
void PrintListAll(char *keyword, int level);
int PrintEachLineAll(char *keyword, char *line, int level, int prevLevel);
void DelSpace(char *line);
int flag = NO; /* For PrintEachLineAll() only */
int lang = 0; /* 0 for English, 1 for Korean */
int main()
{
getentry entries[10];
char keyword[256];
register int i, x;
int level;
FILE *fhtml;
char *ptr;
char line[1024];
printf("content-type: text/html\n\n"); /* HTML Header */
#ifdef FILEOUT
printf("Debugging Mode\n");
i = 1;
strcpy(entries[0].name, "keyword");
strcpy(entries[0].val, "all");
strcpy(entries[1].name, "level");
strcpy(entries[1].val, "0");
#else
i = ProcessGetMethod( entries );
#endif
for (x = 0; x <= i; x++) {
if (!strcmp(entries[x].name, "keyword")) {
strcpy(keyword, entries[x].val); trim(keyword);
continue;
}
if (!strcmp(entries[x].name, "level"))
{
level = atoi(entries[x].val);
continue;
}
if (!strcasecmp(entries[x].name, "Lang"))
{
if (!strcasecmp(entries[x].val, "Korean"))
lang = 1;
continue;
}
}
if (lang == 1)
fhtml = fopen(HTML_FILE_ENG, "r");
else
fhtml = fopen(HTML_FILE_ENG, "r");
if (fhtml == NULL) {
printf("HTML template open failed
\n");
exit(-1);
}
while (fgets(line, 1024, fhtml))
{
if ( (ptr=(char *)strstr(line, "__QUERY__")) != NULL) {
*ptr = '\0';
printf("%s%s%s", line, keyword, ptr+9);
}
else if ( (ptr=(char *)strstr(line, "__URL_QUERY__")) != NULL) {
*ptr = '\0';
printf("%s%s%s", line, esc_url(keyword), ptr+13);
}
else if ( (ptr=(char *)strstr(line, "__RESULT_HERE__")) != NULL) {
*ptr = '\0';
printf("%s", line);
if (!strcasecmp(keyword, "all")) PrintListAll(keyword, -1);
else PrintListAll(keyword, level);
printf("%s", ptr+15);
}
else if ((ptr=(char *)strstr(line, "__IMG_SEARCH_LINK__")) != NULL ) {
*ptr = '\0';
printf("%s", line);
WebSearch(keyword, "image");
printf("%s", ptr+19);
}
else if ((ptr = (char *)strstr(line, "__WEB_SEARCH_LINK__")) != NULL ) {
*ptr = '\0';
printf("%s", line);
WebSearch(keyword, "web");
printf("%s", ptr+19);
}
else if ((ptr =(char *)strstr(line, "__AUDIO_SEARCH_LINK__")) != NULL) {
*ptr = '\0';
printf("%s", line);
WebSearch(keyword, "audio");
printf("%s", ptr+21);
}
else if ((ptr =(char *)strstr(line, "__VIDEO_SEARCH_LINK__")) != NULL) {
*ptr = '\0';
printf("%s", line);
WebSearch(keyword, "video");
printf("%s", ptr+21);
}
else printf("%s", line);
}
fclose(fhtml);
exit(0);
}
void PrintListAll(keyword, level)
char *keyword;
int level;
{
FILE *fp;
char buf[256];
int prevLevel = 0;
int i;
if ((fp=fopen(KEYWORD_FILE, "r")) == NULL)
{
printf("
\n"); if (buf[0] != '*') { if (lang == 1) { printf("%s\n", esc_url(buf), line); printf(" -------- [ÇѱÛÀ̸§Ã£±â]\n", buf); } else printf("%s\n", esc_url(buf), line); } else printf("%s\n", line+1); } return curLevel; } /* void DelSpace(string) char *string; { int i; for (i=0; i < strlen(string); i++) { if (string[i] == ' ') string[i] = '+'; } */ /* char *ptr; while (ptr = (char *) strstr(string, " ")) { *(ptr) = '\0'; strcat(string, ptr+1); DelSpace(string); } } */