/*
 * goto.c
 * for Bioinfo Animal Pictures Archive
 * jskim@bulls.kordic.re.kr
 */

#include "version3/web.h"
#include <stdio.h>

#define HTML "HTMLSrc/goto.html"

main()
{
    FILE	*fp;
    
    char *ptr;
    char line[1024];
    char query[256];
    char bgcolor[20];
    
    getentry entries[5];
    int i, x;	/* general purposes */
    
    query[0] = '\0';
    strcpy(bgcolor, "white"); /* default is white */

    i = ProcessGetMethod(entries);
    for (x = 0; x <= i; x++) {
	if (!strcasecmp(entries[x].name, "qt")) {
	    strcpy(query, entries[x].val);
	    continue;
	}
	if (!strcasecmp(entries[x].name, "bgcolor")) {
	    strcpy(bgcolor, entries[x].val);
	    continue;
	}
    }
    
    printf("content-type: text/html\n\n");	/* HTML Header */
    
    fp = fopen(HTML, "r");

    if (fp == NULL) { printf("HTML template error\n"); exit(0); }
    
    /* print the HTML */
    while (fgets(line, 1024, fp)) {
	if (!strncasecmp(line, "__QUERY__", 9)) {
	    printf("%s", query);
	    continue;
	}
	else if (!strncasecmp(line, "__BGCOLOR__", 11)) {
	    printf("%s", bgcolor);
	    continue;
	}
	else printf("%s", line);
    }
    
    fclose(fp);
    exit(0);
}
