home *** CD-ROM | disk | FTP | other *** search
- /* Multipart-mixed cgi demo.
-
- Troy Downing 1995
-
- This was written to demonstrate the multipart/mixed-replace
- capabilities that are now available with HTML 3.o compliant
- browsers.
-
- This will send a series of images to a browser. Each image
- will replace the previous image giving the illusion of an
- animation. This will work best on fast networks with small
- images of the same size/resolution.
-
- Just to make things simple, I've named the images 1..8.gif,
- this could be easily modified to deal with other
- filenames/types.
- */
-
-
- #include <stdio.h>
-
-
- #define BOUNDARY "--ThisRandomString\n" /*marks beginning of
- file*/
- #define ENDING "--ThisRandomString--\n" /*marks end of file*/
- #define HEADER "Content-type: multipart/x-mixed-
- replace;boundary=ThisRandomString"
- #define TYPE "Content-type: image/gif" /*mime type of file*/
- #define IMAGETYPE "gif" /*filename suffix*/
- #define IMAGEDIR "/usr/downing/gifs/" /*contains the
- images*/
- #define NAMELEN 256
- #define REPEAT 8 /*number of images to
- send*/
- #define BUF_SIZE 1024 /*number of bytes to read
- at once*/
-
-
- void main(void)
- {
- FILE *f_spew; /*points to image files*/
- char file[NAMELEN]; /*holds image file name for use with
- fopen()*/
- char buffer[BUF_SIZE]; /*buffer for reading file*/
- int counter,count,tries;
-
- printf("%s\n\n",HEADER); /*print the multipart header*/
-
- counter=REPEAT+1;
- while(counter--) /*cycle through images*/
- {
- printf("%s",BOUNDARY); /*print beginning boundary*/
- printf("%s\n\n",TYPE); /*print mime type for image*/
-
- sprintf(file,"%s%d.%s",IMAGEDIR,counter,IMAGETYPE);
- /*construct filename*/
- while((f_spew = fopen(file,"r"))==NULL) /*open file*/
- {
- if(tries--<0) break;
- }
- while (!feof(f_spew)) /*send data while not EOF*/
- {
- count = fread(buffer, 1, BUF_SIZE, f_spew);
- fwrite(buffer, 1, count, stdout);
- }
-
- fclose(f_spew);
-
- printf("%s",ENDING); /*print ending boundary*/
- }
-
- }
-
-