Diff for /loncom/cgi/mimeTeX/mimetex.c between versions 1.3 and 1.4

version 1.3, 2007/10/09 21:41:41 version 1.4, 2008/12/04 12:17:13
Line 1 Line 1
 /****************************************************************************  /****************************************************************************
  *   *
  * Copyright(c) 2002-2006, John Forkosh Associates, Inc. All rights reserved.   * Copyright(c) 2002-2008, John Forkosh Associates, Inc. All rights reserved.
    *           http://www.forkosh.com   mailto: john@forkosh.com
  * --------------------------------------------------------------------------   * --------------------------------------------------------------------------
  * This file is part of mimeTeX, which is free software. You may redistribute   * This file is part of mimeTeX, which is free software. You may redistribute
  * and/or modify it under the terms of the GNU General Public License,   * and/or modify it under the terms of the GNU General Public License,
  * version 2 or later, as published by the Free Software Foundation.   * version 3 or later, as published by the Free Software Foundation.
  *      MimeTeX is distributed in the hope that it will be useful, but   *      MimeTeX is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY, not even the implied warranty of MERCHANTABILITY.   * WITHOUT ANY WARRANTY, not even the implied warranty of MERCHANTABILITY.
  * See the GNU General Public License for specific details.   * See the GNU General Public License for specific details.
Line 12 Line 13
  * agreed to these terms and conditions, and that you possess the legal   * agreed to these terms and conditions, and that you possess the legal
  * right and ability to enter into this agreement and to use mimeTeX   * right and ability to enter into this agreement and to use mimeTeX
  * in accordance with it.   * in accordance with it.
  *      Your mimeTeX distribution should contain a copy of the GNU General   *      Your mimetex.zip distribution file should contain the file COPYING,
  * Public License.  If not, write to the Free Software Foundation, Inc.,   * an ascii text copy of the GNU General Public License, version 3.
  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA,   * If not, point your browser to  http://www.gnu.org/licenses/
  * or point your browser to  http://www.gnu.org/licenses/gpl.html   * or write to the Free Software Foundation, Inc.,
    * 59 Temple Place, Suite 330,  Boston, MA 02111-1307 USA.
  * --------------------------------------------------------------------------   * --------------------------------------------------------------------------
  *   *
  * Purpose:   o MimeTeX, licensed under the gpl, lets you easily embed   * Purpose:   o MimeTeX, licensed under the gpl, lets you easily embed
Line 25 Line 27
  * entirely separate little program that doesn't use TeX or   * entirely separate little program that doesn't use TeX or
  * its fonts in any way.  It's just one cgi that you put in   * its fonts in any way.  It's just one cgi that you put in
  * your site's cgi-bin/ directory, with no other dependencies.   * your site's cgi-bin/ directory, with no other dependencies.
  * So mimeTeX is very easy to install.  And it's equally easy   *     So mimeTeX is very easy to install.  And it's equally
  * to use.  Just place an html <img> tag in your document   * easy to use.  Just place an html <img> tag in your document
  * wherever you want to see the corresponding LaTeX expression.   * wherever you want to see the corresponding LaTeX expression.
  * For example,   * For example,
  * <img src="../cgi-bin/mimetex.cgi?\int_{-\infty}^xe^{-t^2}dt"   * <img src="../cgi-bin/mimetex.cgi?\int_{-\infty}^xe^{-t^2}dt"
  *  alt="" border=0 align=middle>   *  alt="" border=0 align=middle>
  * immediately generates the corresponding gif image on-the-fly,   * immediately generates the corresponding gif image on-the-fly,
  * displaying the rendered expression wherever you put that   * displaying the rendered expression wherever you put that
  * <img> tag.  MimeTeX doesn't need intermediate dvi-to-gif   * <img> tag.
  * conversion, and it doesn't clutter up your filesystem with   *     MimeTeX doesn't need intermediate dvi-to-gif conversion,
  * separate little gif files for each converted expression.   * and it doesn't clutter up your filesystem with separate
    * little gif files for each converted expression.
  * But image caching is available by using mimeTeX's   * But image caching is available by using mimeTeX's
  * -DCACHEPATH=\"path/\" compile option (see below).   * -DCACHEPATH=\"path/\" compile option (see below).
  * There's also no inherent need to repeatedly write the   * There's also no inherent need to repeatedly write the
  * cumbersome <img> tag illustrated above.  You can write   * cumbersome <img> tag illustrated above.  You can write
  * your own custom tags, or write a wrapper script around   * your own custom tags, or write a wrapper script around
  * mimeTeX to simplify the notation.   * mimeTeX to simplify the notation.
    *     Further discussion about mimeTeX's features and
    * usage is available on its homepage,
    *  http://www.forkosh.com/mimetex.html
    * and similarly in mimetex.html included with your mimetex.zip
    * distribution file.
  *   *
  * Functions: ===================== Raster Functions ======================   * Functions: ===================== Raster Functions ======================
  * PART2 --- raster constructor functions ---   * PART2 --- raster constructor functions ---
Line 188 Line 196
  * ismonth(month)          is month current month ("jan"-"dec")?   * ismonth(month)          is month current month ("jan"-"dec")?
  * unescape_url(url,isescape), x2c(what)   xlate %xx url-encoded   * unescape_url(url,isescape), x2c(what)   xlate %xx url-encoded
  * logger(fp,msglevel,logvars)        logs environment variables   * logger(fp,msglevel,logvars)        logs environment variables
  * emitcache(cachefile,maxage,isbuffer) emit cachefile to stdout   * emitcache(cachefile,maxage,valign,isbuffer)    emit cachefile
  * readcachefile(cachefile,buffer)    read cachefile into buffer   * readcachefile(cachefile,buffer)    read cachefile into buffer
  * md5str(instr)                      md5 hash library functions   * md5str(instr)                      md5 hash library functions
  * GetPixel(x,y)           callback function for gifsave library   * GetPixel(x,y)           callback function for gifsave library
  *   *
  * Source: mimetex.c  (needs mimetex.h and texfonts.h to compile,   * Source: mimetex.c  (needs mimetex.h and texfonts.h to compile,
  * and also needs gifsave.c if compiled with -DAA or -DGIF)   * and also needs gifsave.c when compiled with -DAA or -DGIF)
  *   *
  * --------------------------------------------------------------------------   * --------------------------------------------------------------------------
  * Notes      o See bottom of file for main() driver (and "friends"),   * Notes      o See bottom of file for main() driver (and "friends"),
Line 211 Line 219
  * and with -DAA or -DGIF you'll also need gifsave.c   * and with -DAA or -DGIF you'll also need gifsave.c
  *      o For gif images, the gifsave.c library by Sverre H. Huseby   *      o For gif images, the gifsave.c library by Sverre H. Huseby
  * <http://shh.thathost.com> slightly modified by me to allow   * <http://shh.thathost.com> slightly modified by me to allow
  * (a)sending output to stdout and (b)specifying a transparent   * (a)sending output to stdout or returning it in memory,
  * background color index, is included with mimeTeX,   * and (b)specifying a transparent background color index,
  * and it's documented in mimetex.html#gifsave .   * is included with mimeTeX, and it's documented in
    * mimetex.html#gifsave .
  *      o Optional compile-line -D defined symbols are documented   *      o Optional compile-line -D defined symbols are documented
  * in mimetex.html#options .  They include (additional -D   * in mimetex.html#options .  They include (additional -D
  * switches are discussed in mimetex.html#options)...   * switches are discussed in mimetex.html#options)...
Line 332 Line 341
  * 10/02/04 J.Forkosh Version 1.50 released.   * 10/02/04 J.Forkosh Version 1.50 released.
  * 11/30/04 J.Forkosh Version 1.60 released.   * 11/30/04 J.Forkosh Version 1.60 released.
  * 10/11/05 J.Forkosh Version 1.64 released.   * 10/11/05 J.Forkosh Version 1.64 released.
  * 11/30/06 J.Forkosh most recent changes   * 11/30/06 J.Forkosh Version 1.65 released.
    * 09/06/08 J.Forkosh Version 1.70 released.
  *   *
  ****************************************************************************/   ****************************************************************************/
   
Line 669  GLOBAL(char,*subexprptr,(char *)NULL); / Line 679  GLOBAL(char,*subexprptr,(char *)NULL); /
 /*SHARED(int,imageformat,1);*/ /* image is 1=bitmap, 2=.gf-like */  /*SHARED(int,imageformat,1);*/ /* image is 1=bitmap, 2=.gf-like */
 GLOBAL(int,isdisplaystyle,1); /* displaystyle mode (forced if 2) */  GLOBAL(int,isdisplaystyle,1); /* displaystyle mode (forced if 2) */
 GLOBAL(int,ispreambledollars,0); /* displaystyle mode set by $$...$$ */  GLOBAL(int,ispreambledollars,0); /* displaystyle mode set by $$...$$ */
 GLOBAL(int,isemitcontenttype,1); /* true to emit mime content-type */  
 GLOBAL(int,fontnum,0); /* cal=1,scr=2,rm=3,it=4,bb=5,bf=6 */  GLOBAL(int,fontnum,0); /* cal=1,scr=2,rm=3,it=4,bb=5,bf=6 */
 GLOBAL(int,fontsize,NORMALSIZE); /* current size */  GLOBAL(int,fontsize,NORMALSIZE); /* current size */
 GLOBAL(int,displaysize,DISPLAYSIZE); /* use \displaystyle when fontsize>=*/  GLOBAL(int,displaysize,DISPLAYSIZE); /* use \displaystyle when fontsize>=*/
Line 716  GLOBAL(int,fraccenterline,NOVALUE); /* b Line 725  GLOBAL(int,fraccenterline,NOVALUE); /* b
 /*GLOBAL(int,currentcharclass,NOVALUE);*/ /*primarily to check for PUNCTION*/  /*GLOBAL(int,currentcharclass,NOVALUE);*/ /*primarily to check for PUNCTION*/
 GLOBAL(int,iscaching,ISCACHING); /* true if caching images */  GLOBAL(int,iscaching,ISCACHING); /* true if caching images */
 GLOBAL(char,cachepath[256],CACHEPATH); /* relative path to cached files */  GLOBAL(char,cachepath[256],CACHEPATH); /* relative path to cached files */
   GLOBAL(int,isemitcontenttype,1); /* true to emit mime content-type */
   int iscachecontenttype = 0; /* true to cache mime content-type */
   char contenttype[2048] = "\000"; /* content-type:, etc buffer */
 GLOBAL(char,pathprefix[256],PATHPREFIX); /*prefix for \input,\counter paths*/  GLOBAL(char,pathprefix[256],PATHPREFIX); /*prefix for \input,\counter paths*/
 /*GLOBAL(int,iswindows,ISWINDOWS);*/ /* true if compiled for ms windows */  /*GLOBAL(int,iswindows,ISWINDOWS);*/ /* true if compiled for ms windows */
   
Line 13474  messages Line 13486  messages
 -------------------------------------------------------------------------- */  -------------------------------------------------------------------------- */
 static char *copyright = /* copyright, gnu/gpl notice */  static char *copyright = /* copyright, gnu/gpl notice */
  "+-----------------------------------------------------------------------+\n"   "+-----------------------------------------------------------------------+\n"
  "|mimeTeX vers 1.64, Copyright(c) 2002-2006, John Forkosh Associates, Inc|\n"   "|mimeTeX vers 1.70, Copyright(c) 2002-2008, John Forkosh Associates, Inc|\n"
  "+-----------------------------------------------------------------------+\n"   "+-----------------------------------------------------------------------+\n"
  "| mimeTeX is free software, licensed to you under terms of the GNU/GPL, |\n"   "| mimeTeX is free software, licensed to you under terms of the GNU/GPL, |\n"
  "|           and comes with absolutely no warranty whatsoever.           |\n"   "|           and comes with absolutely no warranty whatsoever.           |\n"
Line 13551  char *gif_outfile = (char *)NULL, /* gif Line 13563  char *gif_outfile = (char *)NULL, /* gif
  cachefile[256] = "\000", /* full path and name to cache file*/   cachefile[256] = "\000", /* full path and name to cache file*/
  *md5str(); /* md5 has of expression */   *md5str(); /* md5 has of expression */
 int maxage = 7200; /* max-age is two hours */  int maxage = 7200; /* max-age is two hours */
   int valign = (-9999); /*Vertical-Align:baseline-(height-1)*/
 /* --- pbm/pgm (-g switch) --- */  /* --- pbm/pgm (-g switch) --- */
 int ispbmpgm = 0; /* true to write pbm/pgm file */  int ispbmpgm = 0; /* true to write pbm/pgm file */
 int type_pbmpgm(), ptype=0; /* entry point, graphic format */  int type_pbmpgm(), ptype=0; /* entry point, graphic format */
Line 13583  initialization Line 13596  initialization
 /* --- set global variables --- */  /* --- set global variables --- */
 msgfp = stdout; /* for comamnd-line mode output */  msgfp = stdout; /* for comamnd-line mode output */
 isss = issupersampling; /* set supersampling flag */  isss = issupersampling; /* set supersampling flag */
   isemitcontenttype = 1; /* true to emit mime content-type */
   iscachecontenttype = 0; /* true to cache mime content-type */
   *contenttype = '\000'; /* reset content-type:, etc. cache */
   iscaching = ISCACHING; /* true if caching images */
   if ( iscaching ) { /* images are being cached */
     strcpy(cachepath,CACHEPATH); /* relative path to cached files */
     if ( *cachepath == '%' ) { /* leading % signals cache headers */
       iscachecontenttype = 1; /* signal caching mime content-type*/
       strcpy(cachepath,cachepath+1); } } /* and squeeze out leading % char */
 gifSize = 0; /* signal that image not in memory */  gifSize = 0; /* signal that image not in memory */
   fgred=FGRED; fggreen=FGGREEN; fgblue=FGBLUE; /* default foreground colors */
   bgred=BGRED; bggreen=BGGREEN; bgblue=BGBLUE; /* default background colors */
 shrinkfactor = shrinkfactors[NORMALSIZE]; /* set shrinkfactor */  shrinkfactor = shrinkfactors[NORMALSIZE]; /* set shrinkfactor */
 for ( ipattern=1; ipattern<=51; ipattern++ )  for ( ipattern=1; ipattern<=51; ipattern++ )
  patternnumcount0[ipattern] = patternnumcount1[ipattern] = 0;   patternnumcount0[ipattern] = patternnumcount1[ipattern] = 0;
Line 13594  if ( query != NULL )   /* check query st Line 13618  if ( query != NULL )   /* check query st
   if ( strlen(query) >= 1 ) /* caller gave us a query string */    if ( strlen(query) >= 1 ) /* caller gave us a query string */
     { strncpy(expression,query,MAXEXPRSZ); /* so use it as expression */      { strncpy(expression,query,MAXEXPRSZ); /* so use it as expression */
       expression[MAXEXPRSZ] = '\000'; /* make sure it's null terminated */        expression[MAXEXPRSZ] = '\000'; /* make sure it's null terminated */
         if ( 0 ) /*true to remove leading whitespace*/
           while ( isspace(*expression) && *expression!='\000' )
             strcpy(expression,expression+1); /* squeeze out white space */
       isquery = 1; } /* and set isquery flag */        isquery = 1; } /* and set isquery flag */
 if ( !isquery ) /* empty query string */  if ( !isquery ) /* empty query string */
   { char *host = getenv("HTTP_HOST"), /* additional getenv("") results */    { char *host = getenv("HTTP_HOST"), /* additional getenv("") results */
Line 13913  if ( isquery )    /* don't cache command Line 13940  if ( isquery )    /* don't cache command
    /* --- emit mime content-type line --- */     /* --- emit mime content-type line --- */
    if ( 0 && isemitcontenttype ) /* now done in emitcache() */     if ( 0 && isemitcontenttype ) /* now done in emitcache() */
     { fprintf( stdout, "Cache-Control: max-age=%d\n",maxage );      { fprintf( stdout, "Cache-Control: max-age=%d\n",maxage );
         if ( abs(valign) < 999 ) /* have vertical align */
           fprintf( stdout, "Vertical-Align: %d\n",valign );
       fprintf( stdout, "Content-type: image/gif\n\n" ); }        fprintf( stdout, "Content-type: image/gif\n\n" ); }
    /* --- emit cached image if it already exists --- */     /* --- emit cached image if it already exists --- */
    if ( emitcache(cachefile,maxage,0) > 0 ) /* cached image emitted */     if ( emitcache(cachefile,maxage,valign,0) > 0 ) /* cached image emitted */
     goto end_of_job; /* so nothing else to do */      goto end_of_job; /* so nothing else to do */
    /* --- log caching request --- */     /* --- log caching request --- */
    if ( msglevel >= 1 /* check if logging */     if ( msglevel >= 1 /* check if logging */
Line 13958  if ( !isdumpimage )   /* don't mix ascii Line 13987  if ( !isdumpimage )   /* don't mix ascii
 rasterize expression and put a border around it  rasterize expression and put a border around it
 -------------------------------------------------------------------------- */  -------------------------------------------------------------------------- */
 /* --- preprocess expression, converting LaTeX constructs for mimeTeX  --- */  /* --- preprocess expression, converting LaTeX constructs for mimeTeX  --- */
 expression = mimeprep(expression); /* preprocess expression */  if ( expression != NULL ) { /* have expression to rasterize */
     expression = mimeprep(expression); } /* preprocess expression */
 /* --- double-check that we actually have an expression to rasterize --- */  /* --- double-check that we actually have an expression to rasterize --- */
 if ( expression == NULL ) /* nothing to rasterize */  if ( expression == NULL ) /* nothing to rasterize */
  { if ( (!isquery||isqlogging) && msgfp!=NULL ) /*emit error if not a query*/   { if ( (!isquery||isqlogging) && msgfp!=NULL ) /*emit error if not a query*/
Line 13977  if ( issupersampling )   /* no border ne Line 14007  if ( issupersampling )   /* no border ne
 else /* for mime xbitmaps must have... */  else /* for mime xbitmaps must have... */
   bp = border_raster(sp->image,0,0,0,1); /* image width multiple of 8 bits */    bp = border_raster(sp->image,0,0,0,1); /* image width multiple of 8 bits */
 sp->image = bitmap_raster = bp; /* global copy for gif,png output */  sp->image = bitmap_raster = bp; /* global copy for gif,png output */
   if ( sp!=NULL && bp!=NULL ) { /* have raster */
     valign = sp->baseline - (bp->height - 1); /* #pixels for Vertical-Align: */
     if ( abs(valign) > 255 ) valign = (-9999); } /* sanity check */
 if ( ispbmpgm && ptype<2 ) /* -g switch or -g1 switch */  if ( ispbmpgm && ptype<2 ) /* -g switch or -g1 switch */
   type_pbmpgm(bp,ptype,pbm_outfile); /* emit b/w pbm file */    type_pbmpgm(bp,ptype,pbm_outfile); /* emit b/w pbm file */
 /* -------------------------------------------------------------------------  /* -------------------------------------------------------------------------
Line 14119  if (  isquery    /* called from browser Line 14152  if (  isquery    /* called from browser
  ------------------------------------------------------------------------- */   ------------------------------------------------------------------------- */
   /* --- don't use memory buffer if outout file given --- */    /* --- don't use memory buffer if outout file given --- */
   if ( gif_outfile != NULL ) isinmemory = 0; /* reset memory buffer flag */    if ( gif_outfile != NULL ) isinmemory = 0; /* reset memory buffer flag */
     /* --- construct contenttype[] buffer containing mime headers --- */
     if ( 1 ) { /* always construct buffer */
       sprintf( contenttype, "Cache-Control: max-age=%d\n", maxage );
       /*sprintf(contenttype+strlen(contenttype),
          "Expires: Fri, 31 Oct 2003 23:59:59 GMT\n" );*/
       /*sprintf(contenttype+strlen(contenttype),
          "Last-Modified: Wed, 15 Oct 2003 01:01:01 GMT\n");*/
       if ( abs(valign) < 999 ) /* have Vertical-Align: header info*/
         sprintf( contenttype+strlen(contenttype),
          "Vertical-Align: %d\n", valign );
       sprintf( contenttype+strlen(contenttype),
         "Content-type: image/gif\n\n" ); }
   /* --- emit mime content-type line --- */    /* --- emit mime content-type line --- */
   if ( isemitcontenttype /* content-type lines wanted */    if ( isemitcontenttype /* content-type lines wanted */
   &&   !isdumpimage /* don't mix ascii with image dump */    &&   !isdumpimage /* don't mix ascii with image dump */
   &&   !isinmemory /* done below if in memory */    &&   !isinmemory /* done below if in memory */
   &&   !iscaching ) /* done by emitcache() if caching */    &&   !iscaching ) /* done by emitcache() if caching */
     { fprintf( stdout, "Cache-Control: max-age=%d\n",maxage );      { fputs(contenttype,stdout); } /* emit content-type: header buffer*/
       /*fprintf( stdout, "Expires: Fri, 31 Oct 2003 23:59:59 GMT\n" );*/  
       /*fprintf( stdout, "Last-Modified: Wed, 15 Oct 2003 01:01:01 GMT\n" );*/  
       fprintf( stdout, "Content-type: image/gif\n\n" ); }  
   /* --- write output to memory buffer, possibly for testing --- */    /* --- write output to memory buffer, possibly for testing --- */
   if ( isinmemory /* want gif written to memory */    if ( isinmemory /* want gif written to memory */
   ||   isdumpbuffer ) /*or dump memory buffer for testing*/    ||   isdumpbuffer ) /*or dump memory buffer for testing*/
Line 14190  if (  isquery    /* called from browser Line 14232  if (  isquery    /* called from browser
   ||   msglevel >= 99 ) { /* or debugging */    ||   msglevel >= 99 ) { /* or debugging */
   int maxage2 = (isdumpimage?(-1):maxage); /* no headers if dumping image */    int maxage2 = (isdumpimage?(-1):maxage); /* no headers if dumping image */
    if ( iscaching ) /* caching enabled */     if ( iscaching ) /* caching enabled */
      emitcache(cachefile,maxage2,0); /* cached image (hopefully) emitted*/       emitcache(cachefile,maxage2,valign,0); /*emit cached image (hopefully)*/
    else if ( isinmemory ) /* or emit image from memory buffer*/     else if ( isinmemory ) /* or emit image from memory buffer*/
      emitcache(gif_buffer,maxage2,1); } /* emitted from memory buffer */       emitcache(gif_buffer,maxage2,valign,1); } /*emitted from memory buffer*/
   /* --- for testing, may need to write image buffer to file --- */    /* --- for testing, may need to write image buffer to file --- */
   if ( isdumpbuffer > 99 ) /* gif image in memory buffer */    if ( isdumpbuffer > 99 ) /* gif image in memory buffer */
    if ( gifSize > 0 ) /* and it's not an empty buffer */     if ( gifSize > 0 ) /* and it's not an empty buffer */
Line 14572  return ( nlogged );   /* back to caller Line 14614  return ( nlogged );   /* back to caller
 } /* --- end-of-function logger() --- */  } /* --- end-of-function logger() --- */
   
 /* ==========================================================================  /* ==========================================================================
  * Function: emitcache ( cachefile, maxage, isbuffer )   * Function: emitcache ( cachefile, maxage, valign, isbuffer )
  * Purpose: dumps bytes from cachefile to stdout   * Purpose: dumps bytes from cachefile to stdout
  * --------------------------------------------------------------------------   * --------------------------------------------------------------------------
  * Arguments: cachefile (I) pointer to null-terminated char string   * Arguments: cachefile (I) pointer to null-terminated char string
  * containing full path to file to be dumped,   * containing full path to file to be dumped,
  * or contains buffer of bytes to be dumped   * or contains buffer of bytes to be dumped
  * maxage (I) int containing maxage. in seconds, for   * maxage (I) int containing maxage, in seconds, for
  * http header, or -1 to not emit headers   * http header, or -1 to not emit headers
    * valign (I) int containing Vertical-Align:, in pixels,
    * for http header, or <= -999 to not emit
  * isbuffer (I) 1 if cachefile is buffer of bytes to be   * isbuffer (I) 1 if cachefile is buffer of bytes to be
  * dumped   * dumped
  * --------------------------------------------------------------------------   * --------------------------------------------------------------------------
Line 14588  return ( nlogged );   /* back to caller Line 14632  return ( nlogged );   /* back to caller
  * Notes:     o   * Notes:     o
  * ======================================================================= */   * ======================================================================= */
 /* --- entry point --- */  /* --- entry point --- */
 int emitcache ( char *cachefile, int maxage, int isbuffer )  int emitcache ( char *cachefile, int maxage, int valign, int isbuffer )
 {  {
 /* -------------------------------------------------------------------------  /* -------------------------------------------------------------------------
 Allocations and Declarations  Allocations and Declarations
Line 14597  int nbytes=gifSize, readcachefile(); /* Line 14641  int nbytes=gifSize, readcachefile(); /*
 FILE *emitptr = stdout; /* emit cachefile to stdout */  FILE *emitptr = stdout; /* emit cachefile to stdout */
 unsigned char buffer[MAXGIFSZ+1]; /* bytes from cachefile */  unsigned char buffer[MAXGIFSZ+1]; /* bytes from cachefile */
 unsigned char *buffptr = buffer; /* ptr to buffer */  unsigned char *buffptr = buffer; /* ptr to buffer */
   int isvalign = (abs(valign)<999?1:0); /* true to emit Vertical-Align: */
   int iscontenttypecached = iscachecontenttype; /*true if headers cached*/
 /* -------------------------------------------------------------------------  /* -------------------------------------------------------------------------
 initialization  initialization
 -------------------------------------------------------------------------- */  -------------------------------------------------------------------------- */
Line 14604  initialization Line 14650  initialization
 if ( emitptr == (FILE *)NULL ) /* failed to open emit file */  if ( emitptr == (FILE *)NULL ) /* failed to open emit file */
   goto end_of_job; /* so return 0 bytes to caller */    goto end_of_job; /* so return 0 bytes to caller */
 /* --- read the file if necessary --- */  /* --- read the file if necessary --- */
 if ( isbuffer ) /* cachefile is buffer */  if ( isbuffer ) { /* cachefile is buffer */
  buffptr = (unsigned char *)cachefile; /* so reset buffer pointer */    buffptr = (unsigned char *)cachefile; /* so reset buffer pointer */
 else /* cachefile is file name */    iscontenttypecached = 0; } /* and iscontenttypecached flag */
  if ( (nbytes = readcachefile(cachefile,buffer)) /* read the file */  else { /* cachefile is file name */
  < 1 ) goto end_of_job; /* quit if file not read */    if ( (nbytes = readcachefile(cachefile,buffer)) /* read the file */
     < 1 ) goto end_of_job; } /* quit if file not read */
 /* --- first emit http headers if requested --- */  /* --- first emit http headers if requested --- */
 if ( isemitcontenttype /* content-type lines enabled */  if ( isemitcontenttype /* content-type lines enabled */
   &&   !iscontenttypecached /* and not in cached image */
 &&   maxage >= 0 ) /* caller wants http headers */  &&   maxage >= 0 ) /* caller wants http headers */
  { /* --- emit mime content-type line --- */   { /* --- emit mime content-type line --- */
    fprintf( emitptr, "Cache-Control: max-age=%d\n",maxage );     fprintf( emitptr, "Cache-Control: max-age=%d\n",maxage );
    fprintf( emitptr, "Content-Length: %d\n",nbytes );     fprintf( emitptr, "Content-Length: %d\n",nbytes );
      if ( isvalign ) /* Vertical-Align: header wanted */
        fprintf( emitptr, "Vertical-Align: %d\n",valign );
    fprintf( emitptr, "Content-type: image/gif\n\n" ); }     fprintf( emitptr, "Content-type: image/gif\n\n" ); }
 /* -------------------------------------------------------------------------  /* -------------------------------------------------------------------------
 set stdout to binary mode (for Windows)  set stdout to binary mode (for Windows)

Removed from v.1.3  
changed lines
  Added in v.1.4


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>