/*
 * printfree.c
 * for Animal Pictures Archive
 * jskim@AnimalPicturesArchive.com
 * prints the body
 */

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

main()
{
    FILE	*fp;
    char line[1024];
    int		 PrintThisLine = 0;

    getentry entries[5];
    int i, x;	/* general purposes */
    
    printf("content-type: text/html\n\n");	/* HTML Header */
    i = ProcessGetMethod(entries);
    for (x = 0; x <= i; x++) {
	if (!strcasecmp(entries[x].name, "file")) {
	    fp = fopen(entries[x].val, "r");
	    if (fp == NULL) {
		printf("Can't open your request [%s]\n", entries[x].val);
		exit(0);
	    }
	    continue;
	}
    }
    
    while (fgets(line, 1024, fp)) {
	if( !strncasecmp(line, "<html>", 6)) {
	    PrintThisLine = 1;
	    printf("%s", line);
	    continue;
	}
	if( !strncasecmp(line, "</head>", 7)) {
	    PrintThisLine = 0;
	    printf("%s<body><center>\n", line);
	    continue;
	}
	if( !strncasecmp(line, "<!-- Body Starts here -->", 25)) {
	    PrintThisLine = 1;
	    continue;
	}
	if( !strncasecmp(line, "<!-- Body Ends here -->", 23)) {
	    PrintThisLine = 0;
	    continue;
	}
	if (PrintThisLine)
	    printf("%s", line);
    }
    printf("<p><center>\n");
    printf("&copy; CopyLeft 1995-2000, AnimalPicturesArchive.com\n");
    printf("</body></html>\n");
    
    fclose(fp);
    exit(0);
}

