#include "NameHeader.h" #include "web.h" #define HTMLSRC "HTMLSrc/NameSearchTemplate.html" #define HTMLSRC_ENG "HTMLSrc/NameSearch_eng.html" #define DICT_DIR "/animal/Dic" #define KOREAN 1 static int lang = 0; main() { int fd; FILE *fin; /* html template */ DATA *d; char query[128]; /* user query */ getentry entries[16]; /* arguments from the user via http */ int Matched = 0; /* matched (1) or not (0) */ char buf[256]; char *ptr; int i, j, x; printf("Content-type: text/html\n\n"); if ( (fd = open(DATA_FILE, O_RDONLY)) < 0) { printf("Can't open data file [%s]\n", DATA_FILE); exit(0); } read(fd, (char *) &cnt, sizeof(int)); d = (DATA *) malloc(sizeof(DATA)*cnt); read(fd, (char *) d, sizeof(DATA)*cnt); close(fd); strcpy(query, "\0"); /* initialize user query as NULL */ i = ProcessGetMethod( entries ); /* extract user's requirements */ for (x=0; x<=i; x++) { if (!strcasecmp(entries[x].name, "qt")) { strcpy(query, entries[x].val); trim(query); continue; } } if ( (fin=fopen(HTMLSRC, "r")) == NULL) { printf("HTML template¸¦ ¿­ ¼ö ¾ø½À´Ï´Ù. °ü¸®ÀÚ¿¡°Ô ¹®ÀÇÇϽʽÿÀ.\n"); exit(0); } while (fgets(buf, 256, fin)) { if ( (ptr=(char *)strstr(buf, "__QUERY__")) != NULL) { *ptr = '\0'; printf("%s%s%s", buf, query, ptr+9); } else if ( strstr(buf, "__RESULT__") && (strlen(query) > 0) ) { for (i=0, j=0; i < cnt; i++) { if (strstr(d[i].han, query)) Matched = 1; strlower(query); strcpy(buf, d[i].eng); strlower(buf); if (strstr(buf, query)) Matched = 1; strcpy(buf, d[i].sci); strlower(buf); if (strstr(buf, query)) Matched = 1; if (Matched) { j++; if (j==1) { printf("\n"); printf("\n"); } PrintItem(d[i], j); } Matched = 0; } if (j>0) printf("
¼ø¼­
ÇѱÛ
¿µ¾î
Çиí
\n"); else printf("

Á˼ÛÇÕ´Ï´Ù. ÁúÀÇ¿¡ ÀûÇÕÇÑ Ç׸ñÀÌ ¾ø½À´Ï´Ù.\n"); } else if ( strstr(buf, "__RESULT__") && (strlen(query) <= 0) ) printf("

°Ë»ö¾î¸¦ ÀÔ·ÂÇØÁֽʽÿÀ.\n"); else printf("%s", buf); } free(d); fclose(fin); } PrintItem(DATA d, int j) { char *ptr; char buf[MAX_ENG_LEN]; int i; printf("%d", j); if( (ptr=(char *)strstr(d.han, ",")) ) { trim(ptr+1); *ptr = '\0'; trim(d.han); printf("%s(%s)\n", DICT_DIR, URLencode(d.han), d.han, ptr+1); } else printf("%s\n", DICT_DIR, URLencode(d.han), d.han); printf("\n"); while (1) { if (ptr=(char *)strstr(d.eng, ",")) { *ptr = '\0'; trim(d.eng); if (d.eng[0] == '*') printf("%s, ", d.eng+1); else { strcpy(buf, d.eng); for (i=0; i%s,\n", buf, d.eng); } strcpy(d.eng, ptr+1); } else { trim(d.eng); if (d.eng[0] == '*') printf("%s", d.eng+1); else { strcpy(buf, d.eng); for (i=0; i%s\n", buf, d.eng); } break; } } printf("\n%s", d.sci); }