home *** CD-ROM | disk | FTP | other *** search
/ The HTML Web Publisher's Construction Kit / HTMLWPCK.ISO / unix / cgi / c_src / movie.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-27  |  2.0 KB  |  74 lines

  1. /*    Multipart-mixed cgi demo.
  2.  
  3.     Troy Downing 1995
  4.     
  5.     This was written to demonstrate the multipart/mixed-replace
  6.     capabilities that are now available with HTML 3.o compliant
  7.     browsers.
  8.  
  9.     This will send a series of images to a browser. Each image 
  10.     will replace the previous image giving the illusion of an
  11.     animation. This will work best on fast networks with small
  12.     images of the same size/resolution.
  13.  
  14.     Just to make things simple, I've named the images 1..8.gif,
  15.     this could be easily modified to deal with other 
  16. filenames/types.
  17. */
  18.  
  19.  
  20. #include <stdio.h>
  21.  
  22.  
  23. #define BOUNDARY    "--ThisRandomString\n"     /*marks beginning of 
  24. file*/
  25. #define ENDING        "--ThisRandomString--\n"   /*marks end of file*/
  26. #define HEADER    "Content-type: multipart/x-mixed-
  27. replace;boundary=ThisRandomString"
  28. #define TYPE        "Content-type: image/gif"  /*mime type of file*/
  29. #define IMAGETYPE    "gif"               /*filename suffix*/
  30. #define IMAGEDIR    "/usr/downing/gifs/"        /*contains the 
  31. images*/
  32. #define NAMELEN        256
  33. #define REPEAT        8               /*number of images to 
  34. send*/
  35. #define BUF_SIZE    1024               /*number of bytes to read 
  36. at once*/
  37.  
  38.  
  39. void main(void)
  40. {
  41.     FILE   *f_spew;        /*points to image files*/
  42.       char   file[NAMELEN];    /*holds image file name for use with 
  43. fopen()*/
  44.     char   buffer[BUF_SIZE]; /*buffer for reading file*/
  45.     int counter,count,tries;
  46.  
  47.     printf("%s\n\n",HEADER);    /*print the multipart header*/
  48.            
  49.     counter=REPEAT+1;
  50.     while(counter--)            /*cycle through images*/
  51.     {
  52.        printf("%s",BOUNDARY);    /*print beginning boundary*/
  53.        printf("%s\n\n",TYPE);    /*print mime type for image*/
  54.  
  55.        sprintf(file,"%s%d.%s",IMAGEDIR,counter,IMAGETYPE); 
  56. /*construct filename*/
  57.            while((f_spew = fopen(file,"r"))==NULL) /*open file*/
  58.            {
  59.         if(tries--<0) break;
  60.            }
  61.        while (!feof(f_spew))    /*send data while not EOF*/
  62.            {
  63.               count = fread(buffer, 1, BUF_SIZE, f_spew);
  64.               fwrite(buffer, 1, count, stdout);
  65.            }
  66.  
  67.            fclose(f_spew);
  68.  
  69.            printf("%s",ENDING);    /*print ending boundary*/
  70.        }
  71.     
  72. }
  73.  
  74.