⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mimetex.c

📁 完美的在线教育系统
💻 C
📖 第 1 页 / 共 5 页
字号:
#endif
/* --- textwidth --- */
#ifndef TEXTWIDTH
  #define TEXTWIDTH (400)
#endif
/* --- font "combinations" --- */
#define	CMSYEX (109)			/*select CMSY10, CMEX10 or STMARY10*/
/* --- prefix prepended to all expressions --- */
#ifndef	PREFIX
  #define PREFIX "\000"			/* default no prepended prefix */
#endif
/* --- skip argv[]'s preceding ARGSIGNAL when parsing command-line args --- */
#ifdef NOARGSIGNAL
  #define ARGSIGNAL NULL
#endif
#ifndef	ARGSIGNAL
  #define ARGSIGNAL "++"
#endif
/* --- security and logging (inhibit message logging, etc) --- */
#ifndef	SECURITY
  #define SECURITY 999			/* default highest security level */
#endif
#ifndef	LOGFILE
  #define LOGFILE "mimetex.log"		/* default log file */
#endif
#ifndef	CACHELOG
  #define CACHELOG "mimetex.log"	/* default caching log file */
#endif
#if !defined(NODUMPENVP) && !defined(DUMPENVP)
  #define DUMPENVP			/* assume char *envp[] available */
#endif
/* --- image caching (cache images if given -DCACHEPATH=\"path\") --- */
#ifndef CACHEPATH
  #define ISCACHING 0			/* no caching */
  #define CACHEPATH "\000"		/* same directory as mimetex.cgi */
#else
  #define ISCACHING 1			/* caching if -DCACHEPATH="path" */
#endif
/* --- \input paths (prepend prefix if given -DPATHPREFIX=\"prefix\") --- */
#ifndef PATHPREFIX
  #define PATHPREFIX "\000"		/* paths relative mimetex.cgi */
#endif
/* --- time zone delta t (in hours) --- */
#ifndef TZDELTA
  #define TZDELTA 0
#endif

/* -------------------------------------------------------------------------
debugging and logging / error reporting
-------------------------------------------------------------------------- */
/* --- debugging and error reporting --- */
#ifndef	MSGLEVEL
  #define MSGLEVEL 1
#endif
#define	DBGLEVEL 9			/* debugging if msglevel>=DBGLEVEL */
#define	LOGLEVEL 3			/* logging if msglevel>=LOGLEVEL */
#ifndef FORMLEVEL
  #define FORMLEVEL LOGLEVEL		/*msglevel if called from html form*/
#endif
GLOBAL(int,seclevel,SECURITY);		/* security level */
GLOBAL(int,msglevel,MSGLEVEL);		/* message level for verbose/debug */
STATIC	FILE *msgfp;			/* output in command-line mode */
/* --- embed warnings in rendered expressions, [\xxx?] if \xxx unknown --- */
#ifdef WARNINGS
  #define WARNINGLEVEL WARNINGS
#else
  #ifdef NOWARNINGS
    #define WARNINGLEVEL 0
  #else
    #define WARNINGLEVEL 1
  #endif
#endif
GLOBAL(int,warninglevel,WARNINGLEVEL);	/* warning level */

/* -------------------------------------------------------------------------
control flags and values
-------------------------------------------------------------------------- */
GLOBAL(int,recurlevel,0);		/* inc/decremented in rasterize() */
GLOBAL(int,scriptlevel,0);		/* inc/decremented in rastlimits() */
GLOBAL(int,isstring,0);			/*pixmap is ascii string, not raster*/
/*SHARED(int,imageformat,1);*/		/* image is 1=bitmap, 2=.gf-like */
GLOBAL(int,isdisplaystyle,1);		/* displaystyle mode (forced if 2) */
GLOBAL(int,ispreambledollars,0);	/* displaystyle mode set by $$...$$ */
GLOBAL(int,fontnum,0);			/* cal=1,scr=2,rm=3,it=4,bb=5,bf=6 */
GLOBAL(int,fontsize,NORMALSIZE);	/* current size */
GLOBAL(int,displaysize,DISPLAYSIZE);	/* use \displaystyle when fontsize>=*/
GLOBAL(int,shrinkfactor,3);		/* shrinkfactors[fontsize] */
GLOBAL(double,unitlength,1.0);		/* #pixels per unit (may be <1.0) */
/*GLOBAL(int,textwidth,TEXTWIDTH);*/	/* #pixels across line */
GLOBAL(int,iscatspace,1);		/* true to add space in rastcat() */
GLOBAL(int,smashmargin,SMASHMARGIN);	/* minimum "smash" margin */
GLOBAL(int,issmashdelta,1);		/* true if smashmargin is a delta */
GLOBAL(int,blanksignal,(-991234));	/*rastsmash signal right-hand blank*/
GLOBAL(int,istransparent,1);		/*true to set background transparent*/
GLOBAL(int,fgred,FGRED);
  GLOBAL(int,fggreen,FGGREEN);
  GLOBAL(int,fgblue,FGBLUE);		/* fg r,g,b */
GLOBAL(int,bgred,BGRED);
  GLOBAL(int,bggreen,BGGREEN);
  GLOBAL(int,bgblue,BGBLUE);		/* bg r,g,b */
GLOBAL(int,isblackonwhite,ISBLACKONWHITE); /*1=black on white,0=reverse*/
GLOBAL(char,exprprefix[256],PREFIX);	/* prefix prepended to expressions */
GLOBAL(int,aaalgorithm,AAALGORITHM);	/* for lp, 1=aalowpass, 2 =aapnm */
GLOBAL(int,fgalias,1);
  GLOBAL(int,fgonly,0);
  GLOBAL(int,bgalias,0);
  GLOBAL(int,bgonly,0);			/* aapnm() params */
GLOBAL(int,issupersampling,ISSUPERSAMPLING); /*1=supersampling 0=lowpass*/
GLOBAL(int,isss,ISSUPERSAMPLING);	/* supersampling flag for main() */
GLOBAL(int,*workingparam,(int *)NULL);	/* working parameter */
GLOBAL(subraster,*workingbox,(subraster *)NULL); /*working subraster box*/
GLOBAL(int,isreplaceleft,0);		/* true to replace leftexpression */
GLOBAL(subraster,*leftexpression,(subraster *)NULL); /*rasterized so far*/
GLOBAL(mathchardef,*leftsymdef,NULL);	/* mathchardef for preceding symbol*/
GLOBAL(int,iscaching,ISCACHING);	/* true if caching images */
GLOBAL(char,cachepath[256],CACHEPATH);	/* relative path to cached files */
GLOBAL(char,pathprefix[256],PATHPREFIX); /*prefix for \input,\counter paths*/
/*GLOBAL(int,iswindows,ISWINDOWS);*/	/* true if compiled for ms windows */

/* -------------------------------------------------------------------------
miscellaneous macros
-------------------------------------------------------------------------- */
#define	max2(x,y)  ((x)>(y)? (x):(y))	/* larger of 2 arguments */
#define	min2(x,y)  ((x)<(y)? (x):(y))	/* smaller of 2 arguments */
#define	max3(x,y,z) max2(max2(x,y),(z))	/* largest of 3 arguments */
#define	min3(x,y,z) min2(min2(x,y),(z))	/* smallest of 3 arguments */
#define absval(x)  ((x)>=0?(x):(-(x)))	/* absolute value */
#define	iround(x)  ((int)((x)>=0?(x)+0.5:(x)-0.5)) /* round double to int */
#define	dmod(x,y)  ((x)-((y)*((double)((int)((x)/(y)))))) /*x%y for doubles*/
#define compress(s,c) if((s)!=NULL)	/* remove embedded c's from s */ \
	{ char *p; while((p=strchr((s),(c)))!=NULL) strcpy(p,p+1); } else
#define	slower(s)  if ((s)!=NULL)	/* lowercase all chars in s */ \
	{ char *p=(s); while(*p!='\000'){*p=tolower(*p); p++;} } else

/* ---
 * PART2
 * ------ */
#if !defined(PARTS) || defined(PART2)
/* ==========================================================================
 * Function:	new_raster ( width, height, pixsz )
 * Purpose:	Allocation and constructor for raster.
 *		mallocs and initializes memory for width*height pixels,
 *		and returns raster struct ptr to caller.
 * --------------------------------------------------------------------------
 * Arguments:	width (I)	int containing width, in bits,
 *				of raster pixmap to be allocated
 *		height (I)	int containing height, in bits/scans,
 *				of raster pixmap to be allocated
 *		pixsz (I)	int containing #bits per pixel, 1 or 8
 * --------------------------------------------------------------------------
 * Returns:	( raster * )	ptr to allocated and initialized
 *				raster struct, or NULL for any error.
 * --------------------------------------------------------------------------
 * Notes:
 * ======================================================================= */
/* --- entry point --- */
raster	*new_raster ( int width, int height, int pixsz )
{
/* -------------------------------------------------------------------------
Allocations and Declarations
-------------------------------------------------------------------------- */
raster	*rp = (raster *)NULL;		/* raster ptr returned to caller */
pixbyte	*pixmap = NULL;			/* raster pixel map to be malloced */
int	nbytes = pixsz*bitmapsz(width,height); /* #bytes needed for pixmap */
int	filler = (isstring?' ':0);	/* pixmap filler */
int	delete_raster();		/* in case pixmap malloc() fails */
int	npadding = (0&&issupersampling?8+256:0); /* padding bytes */
/* -------------------------------------------------------------------------
allocate and initialize raster struct and embedded bitmap
-------------------------------------------------------------------------- */
if ( msgfp!=NULL && msglevel>=9999 )
  { fprintf(msgfp,"new_raster(%d,%d,%d)> entry point\n",
    width,height,pixsz); fflush(msgfp); }
/* --- allocate and initialize raster struct --- */
rp = (raster *)malloc(sizeof(raster));	/* malloc raster struct */
if ( msgfp!=NULL && msglevel>=9999 )
  { fprintf(msgfp,"new_raster> rp=malloc(%d) returned (%s)\n",
    sizeof(raster),(rp==NULL?"null ptr":"success")); fflush(msgfp); }
if ( rp == (raster *)NULL )		/* malloc failed */
  goto end_of_job;			/* return error to caller */
rp->width = width;			/* store width in raster struct */
rp->height = height;			/* and store height */
rp->format = 1;				/* initialize as bitmap format */
rp->pixsz = pixsz;			/* store #bits per pixel */
rp->pixmap = (pixbyte *)NULL;		/* init bitmap as null ptr */
/* --- allocate and initialize bitmap array --- */
if ( msgfp!=NULL && msglevel>=9999 )
  { fprintf(msgfp,"new_raster> calling pixmap=malloc(%d)\n",
    nbytes); fflush(msgfp); }
if ( nbytes>0 && nbytes<=pixsz*maxraster )  /* fail if width*height too big*/
  pixmap = (pixbyte *)malloc(nbytes+npadding); /*bytes for width*height bits*/
if ( msgfp!=NULL && msglevel>=9999 )
  { fprintf(msgfp,"new_raster> pixmap=malloc(%d) returned (%s)\n",
    nbytes,(pixmap==NULL?"null ptr":"success")); fflush(msgfp); }
if ( pixmap == (pixbyte *)NULL )	/* malloc failed */
  { delete_raster(rp);			/* so free everything */
    rp = (raster *)NULL;		/* reset pointer */
    goto end_of_job; }			/* and return error to caller */
memset((void *)pixmap,filler,nbytes);	/* init bytes to binary 0's or ' 's*/
*pixmap = (pixbyte)0;			/* and first byte alwasy 0 */
rp->pixmap = pixmap;			/* store ptr to malloced memory */
/* -------------------------------------------------------------------------
Back to caller with address of raster struct, or NULL ptr for any error.
-------------------------------------------------------------------------- */
end_of_job:
  if ( msgfp!=NULL && msglevel>=9999 )
    { fprintf(msgfp,"new_raster(%d,%d,%d)> returning (%s)\n",
      width,height,pixsz,(rp==NULL?"null ptr":"success")); fflush(msgfp); }
  return ( rp );			/* back to caller with raster */
} /* --- end-of-function new_raster() --- */


/* ==========================================================================
 * Function:	new_subraster ( width, height, pixsz )
 * Purpose:	Allocate a new subraster along with
 *		an embedded raster of width x height.
 * --------------------------------------------------------------------------
 * Arguments:	width (I)	int containing width of embedded raster
 *		height (I)	int containing height of embedded raster
 *		pixsz (I)	int containing #bits per pixel, 1 or 8
 * --------------------------------------------------------------------------
 * Returns:	( subraster * )	ptr to newly-allocated subraster,
 *				or NULL for any error.
 * --------------------------------------------------------------------------
 * Notes:     o	if width or height <=0, embedded raster not allocated
 * ======================================================================= */
/* --- entry point --- */
subraster *new_subraster ( int width, int height, int pixsz )
{
/* -------------------------------------------------------------------------
Allocations and Declarations
-------------------------------------------------------------------------- */
subraster *sp=NULL;			/* subraster returned to caller */
raster	*new_raster(), *rp=NULL;	/* image raster embedded in sp */
int	delete_subraster();		/* in case new_raster() fails */
int	size = NORMALSIZE,		/* default size */
	baseline = height-1;		/* and baseline */
/* -------------------------------------------------------------------------
allocate and initialize subraster struct
-------------------------------------------------------------------------- */
if ( msgfp!=NULL && msglevel>=9999 )
  { fprintf(msgfp,"new_subraster(%d,%d,%d)> entry point\n",
    width,height,pixsz); fflush(msgfp); }
/* --- allocate subraster struct --- */
sp = (subraster *)malloc(sizeof(subraster));  /* malloc subraster struct */
if ( sp == (subraster *)NULL )		/* malloc failed */
  goto end_of_job;			/* return error to caller */
/* --- initialize subraster struct --- */
sp->type = NOVALUE;			/* character or image raster */
sp->symdef =  (mathchardef *)NULL;	/* mathchardef identifying image */
sp->baseline = baseline;		/*0 if image is entirely descending*/
sp->size = size;			/* font size 0-4 */
sp->toprow = sp->leftcol = (-1);	/* upper-left corner of subraster */
sp->image = (raster *)NULL;		/*ptr to bitmap image of subraster*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -