#include #include #define LF 10 #define CR 13 #define SOURCE "/home/httpd/html/animal/Keywords/han.dat" /* #define SOURCE "han.dat" */ #define HTML_TEMPLATE "/home/httpd/html/animal/HTMLSrc/EngName.html" #define HTML_DIR "/home/httpd/html/animal/EngNames" #define THUMNAIL_DIR "/home/httpd/html/animal/PIX" /* this is for URL */ #define IMG_DIR "/animal/PIX" #define BUTTON_DIR "/img" #define SEARCH_CGI "/animal/APAsrch3.cgi" #define CUT_WHEN 150 typedef struct { char han[100]; char syn[100]; char eng[100]; char sci[100]; char dsc[65536]; char snd[1024]; char mov[1024]; } DATA; main() { FILE *fin; DATA dat; char line[1024]; char buf[1024]; int cnt; int i; int Update = 0; if ( (fin = fopen(SOURCE, "r")) == NULL ) { printf("Can't open source file [%s]\n", SOURCE); exit(0); } dat.eng[0] = '\0'; dat.syn[0] = '\0'; dat.sci[0] = '\0'; dat.snd[0] = '\0'; dat.mov[0] = '\0'; dat.dsc[0] = '\0'; cnt = 0; while (fgets(line, 1024, fin)) { if (!strncasecmp(line, "#Han=", 5)) { if (cnt > 0) { makeonehtml(dat); dat.eng[0] = '\0'; dat.syn[0] = '\0'; dat.sci[0] = '\0'; dat.snd[0] = '\0'; dat.mov[0] = '\0'; dat.dsc[0] = '\0'; } strcpy(dat.han, line+5); trim(dat.han); cnt++; } else if (!strncasecmp(line, "#Eng=", 5)) { strcpy(dat.eng, line+5); trim(dat.eng); } else if (!strncasecmp(line, "#Sci=", 5)) { strcpy(dat.sci, line+5); trim(dat.sci); } else if (!strncasecmp(line, "#Syn=", 5)) { strcpy(dat.syn, line+5); trim(dat.syn); } else if (!strncasecmp(line, "#mov=", 5)) { strcpy(dat.mov, line+5); trim(dat.mov); } else if (!strncasecmp(line, "#snd=", 5)) { strcpy(dat.snd, line+5); trim(dat.snd); } else if (!strncasecmp(line, "#dsc=", 5)) strcpy(dat.dsc, line+5); else if (!strncasecmp(line, "#Update=Y", 9)) Update = 1; else if (!strcmp(line, "\n") || !strcmp(line, " \n") || !strcmp(line, " \n") || !strcmp(line, " \n") ) strcat(dat.dsc, "

"); else strcat(dat.dsc, line); } makeonehtml(dat); fclose(fin); } makeonehtml(d) DATA d; { FILE *fp, *fin; char buf[256]; char buf2[256]; char fname[256]; char eng4cgi[256]; char eng4org[256]; char line[2048]; char *ptr, *ptr2; int i, len; strcpy(buf, d.eng); strcpy(eng4org, d.eng); len = strlen(buf); for (i=0; i < len; i++) { if (buf[i] == ',') { buf[i] = '\0'; eng4org[i] = '\0'; trim(buf); trim(eng4org); break; } else if (buf[i] == ' ') buf[i] = '+'; } /* make html name */ if (buf[0]=='*') strcpy(buf2, buf+1); else strcpy(buf2, buf); strcpy(eng4cgi, buf2); len = strlen(buf2); for (i=0; i < len; i++) { if (buf2[i] == ' ' || buf2[i] == '\'' || buf2[i] == '+') buf2[i] = '_'; } sprintf(fname, "%s/%s.html", HTML_DIR, buf2); if ( (fp = fopen(fname, "w")) == NULL ) { printf("[%s] ÆÄÀÏÀ» ¸¸µé ¼ö ¾ø½À´Ï´Ù.\n", buf); return (0); } if ( (fin = fopen(HTML_TEMPLATE, "r")) == NULL ) { printf("[%s] ÆÄÀÏÀ» ¸¸µé ¼ö ¾ø½À´Ï´Ù.\n", HTML_TEMPLATE); return (0); } while (fgets(line, 2048, fin)) { if ( (ptr = (char *)strstr(line, "___ENGLISH_NAMES_HERE___")) != NULL ) { *ptr = '\0'; fprintf(fp, "%s", line); strcpy(buf, d.eng); while ( (char *) ptr2 = (char *) strstr(buf, ",") ) { *ptr2 = '\0'; if (buf[0] == '*') fprintf(fp, "%s, \n", buf+1); else { for (i=0; i < strlen(buf); i++) if (buf[i] == ' ') buf[i] = '+'; fprintf(fp, "", SEARCH_CGI, buf); for (i=0; i < strlen(buf); i++) if (buf[i] == '+') buf[i] = ' '; fprintf(fp, "%s, \n", buf); } strcpy(buf, ptr2+1); trim(buf); } if (buf[0] == '*') fprintf(fp, "%s
\n", buf+1); else { for (i=0; i < strlen(buf); i++) if (buf[i] == ' ') buf[i] = '+'; fprintf(fp, "", SEARCH_CGI, buf); for (i=0; i < strlen(buf); i++) if (buf[i] == '+') buf[i] = ' '; fprintf(fp, "%s
\n", buf); } fprintf(fp, "%s", ptr+24); } else if ( (ptr = (char *)strstr(line, "___ENGLISH_NAME_HERE___")) != NULL ) { *ptr = '\0'; fprintf(fp, "%s%s%s", line, eng4org, ptr+23); } else if ( (ptr = (char *)strstr(line, "___LATIN_NAME_HERE___")) != NULL ) { *ptr = '\0'; fprintf(fp, "%s%s%s", line, d.sci, ptr+21); } else if ( (ptr = (char *)strstr(line, "___FAMILY_NAME_HERE___")) != NULL ) { *ptr = '\0'; fprintf(fp, "%s", line); strncpy(buf, d.dsc, 256); if ( ptr2=(char *)strstr(buf, "dae") ) { *(ptr2+3) = '\0'; while (1) { --ptr2; if ( *ptr2 == '(' || *ptr2 == '>' ) { fprintf(fp, "Family: %s", ptr2+1); break; } else if (*ptr2 == '=') break; } } fprintf(fp, "%s", ptr+22); } else if ( (ptr = (char *)strstr(line, "___ORDER_NAME_HERE___")) != NULL ) { *ptr = '\0'; fprintf(fp, "%s", line); fprintf(fp, "%s", ptr+21); } else if ( (ptr = (char *)strstr(line, "___THUMBNAIL_HERE___")) != NULL ) { *ptr = '\0'; fprintf(fp, "%s", line); if (buf[0] != '*') fprintf(fp,"", eng4cgi); strcpy(buf, eng4cgi); if ( mkchkImageName(buf) ) /* buf contains + chars in the place of space */ fprintf(fp,"\"Click", IMG_DIR, buf); else fprintf(fp,"Click here to
search iamges
"); fprintf(fp, "%s", ptr+20); } else fprintf(fp, "%s", line); } fclose(fp); fclose(fin); } int mkchkImageName(s) char *s; { int i; char *ptr; char buf[256]; trim(s); (int) s[0] = toupper((int) s[0]); for (i=0; i