/* * Bioinfo Animal Pictures Archive - Search CGI script * APAsrch2.c - Using GET method * Resulting program : APAsrch2.cgi * Kim, Jinsuk [jskim@bioinfo.kordic.re.kr] */ #include "APAsrch2.h" void PrintMsg(content, align, color) char *content; char *align; char *color; { printf("

", align, color); printf("%s

\n", content); } void InsertDelimeter(s) /* insert delimeter for names */ char *s; { char buf[256]; int len; int i, j; int idx[256]; len = strlen(s); /* upper char = 1, lower char = 0, else = -1 ex) DKMMNature-Reptile-PoisonousLizard-GilaMonster.gif 1111100000_1000000_100000000100000_10001000000_000 where _ = -1 */ for (i=0; i= 65 && s[i] <= 90) /* upper case */ idx[i] = 1; else if (s[i] >= 97 && s[i] <= 122) /* lower case */ idx[i] = 0; else idx[i] = -1; } buf[0] = s[0]; for (i=1, j=1; i\n"); if (Dir.num > 0 && Dir.name[0] > 0) { for (x=0; x\n"); if (num_fnd <= 0) { printf("

Sorry, currently this archive has no "); printf("%s image\n", query); if (Dir.num == 1) printf(" in directory %d.

"); else if (Dir.num == 0) { printf(" in directories "); for (x=1; x<=MAX_DIR_NUM; x++) { if (x == MAX_DIR_NUM) printf("and %d.", x); else printf("%d, ", x); } } else { printf(" in directories "); for (x=0; x

  • Try SINGULAR noun.\n (Ex. DOGS -> DOG, WOLVES -> WOLF)\n"); printf("
  • Try SYNONYM.\n (Ex. BLACK PUMA -> PANTHER, MOUNTAIN LION -> COUGAR)\n"); printf("
  • Try BROADER term.\n (Ex. MONITOR -> LIZARD)\n"); printf("
  • Try PARTIAL term.\n (Ex. PUPPY -> PUPP, CROCODILE-> CROC)\n"); printf("
  • NO HELP? Hmmm... Try KEYWORD LIST for this archive.\n"); printf("

\n"); } else { printf("

"); printf("%d image(s) of ", num_fnd); printf("%s found\n", query); if (Dir.num == 1) printf(" in directory %d.

"); else if (Dir.num == 0) { printf(" in directories "); for (x=1; x<=MAX_DIR_NUM; x++) { if (x == MAX_DIR_NUM) printf("and %d ", x); else printf("%d, ", x); } } else { printf(" in directories "); for (x=0; x

\n"); } } int DirListSearch(query, fname, dir_num) char *query; char *fname; int dir_num; { int k = 0; int fsize; /* file size in Kbytes */ char q_buf[256], buf[256], target[256]; FILE *fp; /* file pointers to open index files */ /* File Open Error detection */ if ( (fp=fopen(fname, "r")) == NULL ) { printf("List file open error.

\n"); printf("Contact ", WEB_MASTER); printf("Web master.

\n"); exit(1); } fgets( buf, 256, fp); /* remove first line of LIST1 */ strcpy(buf, query); Space2Star(buf); strcpy(q_buf, "*"); strcat(q_buf, buf); strcat(q_buf, "*"); strlower(q_buf); while (!feof(fp)) { fscanf(fp, "%d %s", &fsize, target); strcpy(buf, target); InsertDelimeter(buf); strlower(buf); if ( CompareString(q_buf, buf) && \ !strstr(buf, ".txt") && \ !strstr(buf, ".html") ) { printf("

  • [",\ CGI_UU2MAIL, ARCH_DIR, dir_num, target); printf("uu2mail] "); if (fsize <= 40) printf("[Preview] "); else printf("[Preview] ", CGI_PREVIEW, ARCH_DIR, dir_num, target); printf("[",\ ARCH_DIR, dir_num, target); printf("%s%d/%s]", ARCH_DIR, dir_num, target); printf(" (%dKb)\n", fsize); k++; } } fclose(fp); return k; } int main() { FILE *fp; getentry entries[MAX_ENTRY_NUM]; long int i, x, y, flag; char query[256]; typedef struct { int name[MAX_DIR_NUM]; int num; }dir; dir Dir; Dir.num = 0; for (x=0; x"); printf("\n"); if ( strlen(query) > 0) printf("Bioinfo Animal Pictures Archive Search \"%s\"\n", query); else printf("Bioinfo Animal Pictures Archive Search\n"); printf("\n"); printf("\n"); printf("
    \n"); printf("
    \n"); printf("
    \n"); printf("
    \n", CGI_APA_SEARCH); printf("Search directories "); for (flag=0, x=0; x"); else printf(">"); printf("%d\n", x+1); flag = 0; } printf("\n"); printf("
    \n", query); printf("
    \n"); printf("Tips:"); printf("Case-insensitive; Able to use wild card characters * and ?;
    Singular noun search; \n"); printf("Examples - WOLF*HOWL, "); printf("ALLIGAT?R\n"); printf("
    \n

    \n


    \n"); printf("
    \n"); if ( strlen(query) > 0) { APAsrch(entries, i); } else { printf("

    Enter Search Keyword\n"); } printf("


    \n"); printf("

    \n"); printf("[ BIOINFO HOME ]
    \n", BIOINFO_HOME); printf("[ Animal Pictures Archive Home ]
    \n",\ APA_HOME); printf("[ Animal Movies ]
    \n", MOVIE_HOME); printf("


    \n"); printf("
    \n"); printf("
    \n"); if((fp=fopen(ACC_NUM_FILE, "r"))==NULL) printf("OOPS! Counter File Open Error"); else { fscanf(fp,"%d",&x); fclose(fp); printf("%d

    \n", x); } printf("

    \n"); printf(""); if((fp=fopen(ACC_NUM_FILE, "w"))==NULL) printf("OOPS! Counter File Open Error"); else { fprintf(fp,"%d\n",x+1); fclose(fp); } /* query logging */ if((fp=fopen(QUERY_LOG_FILE, "a"))==NULL) printf("OOPS! Log File Open Error"); else { fprintf(fp,"%d %s\n", x, query); fclose(fp); } exit(0); } /* * Wild Card Comparison * armian@stissbs.kordic.re.kr */ int CompareString(str1, str2) char *str1, *str2; { int ret; char *ptr1, *ptr2; if (str1[0] == '\0' && str2[0] == '\0') { return 1; } if (str1[0] == '\0' || str2[0] == '\0') { return 0; } if (str1[0] == str2[0]) { ret = CompareString(&str1[1], &str2[1]); } else if (str1[0] == '?') { ret = CompareString(&str1[1], &str2[1]); } else if (str1[0] == '*') { ptr1 = &str1[1]; while(1) { if (*ptr1 == '\0') { return 1; } if (*ptr1 == '*' || *ptr1 == '?') { ptr1++; } else { break; } } while(1) { ptr2 = (char *) strchr(str2, *ptr1); if (ptr2 == NULL) { return 0; } ret = CompareString(ptr1, ptr2); if (ret) return ret; else str2++; } } else { return 0; } return ret; } /* NCSA Web Library */ void getword(char *word, char *line, char stop) { int x = 0, y; for (x = 0; ((line[x]) && (line[x] != stop)); x++) word[x] = line[x]; word[x] = '\0'; if (line[x]) ++x; y = 0; while (line[y++] = line[x++]); } char * makeword(char *line, char stop) { int x = 0, y; char *word = (char *) malloc(sizeof(char) * (strlen(line) + 1)); for (x = 0; ((line[x]) && (line[x] != stop)); x++) word[x] = line[x]; word[x] = '\0'; if (line[x]) ++x; y = 0; while (line[y++] = line[x++]); return word; } char * fmakeword(FILE * f, char stop, int *cl) { int wsize; char *word; int ll; wsize = 102400; ll = 0; word = (char *) malloc(sizeof(char) * (wsize + 1)); while (1) { word[ll] = (char) fgetc(f); if (ll == wsize) { word[ll + 1] = '\0'; wsize += 102400; word = (char *) realloc(word, sizeof(char) * (wsize + 1)); } --(*cl); if ((word[ll] == stop) || (feof(f)) || (!(*cl))) { if (word[ll] != stop) ll++; word[ll] = '\0'; return word; } ++ll; } } char x2c(char *what) { register char digit; digit = (what[0] >= 'A' ? ((what[0] & 0xdf) - 'A') + 10 : (what[0] - '0')); digit *= 16; digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A') + 10 : (what[1] - '0')); return (digit); } void unescape_url(char *url) { register int x, y; for (x = 0, y = 0; url[y]; ++x, ++y) { if ((url[x] = url[y]) == '%') { url[x] = x2c(&url[y + 1]); y += 2; } } url[x] = '\0'; } void plustospace(char *str) { register int x; for (x = 0; str[x]; x++) if (str[x] == '+') str[x] = ' '; } int rind(char *s, char c) { register int x; for (x = strlen(s) - 1; x != -1; x--) if (s[x] == c) return x; return -1; } int getline(char *s, int n, FILE * f) { register int i = 0; while (1) { s[i] = (char) fgetc(f); if (s[i] == CR) s[i] = fgetc(f); if ((s[i] == 0x4) || (s[i] == LF) || (i == (n - 1))) { s[i] = '\0'; return (feof(f) ? 1 : 0); } ++i; } } void send_fd(FILE * f, FILE * fd) { int num_chars = 0; char c; while (1) { c = fgetc(f); if (feof(f)) return; fputc(c, fd); } } /* coded by armian@www.kordic.re.kr */ int ProcessGetMethod(entries) getentry *entries; { char *cl; int x, m; if (strcmp(getenv("REQUEST_METHOD"), "GET")) { printf("This script should be referenced with a METHOD of GET.\n"); printf("If you don't understand this, see this "); printf("forms overview.%c", 10); exit(1); } cl = getenv("QUERY_STRING"); if ( strlen(cl) <= 0 ) { /* printf("No query information to decode.\n"); */ return -1; } for (x = 0; cl[0] != '\0'; x++) { m = x; getword(entries[x].val, cl, '&'); plustospace(entries[x].val); unescape_url(entries[x].val); getword(entries[x].name, entries[x].val, '='); } return m; }