diff -Nru mimetex-1.74/debian/changelog mimetex-1.76/debian/changelog --- mimetex-1.74/debian/changelog 2014-07-14 20:16:16.000000000 +0000 +++ mimetex-1.76/debian/changelog 2017-11-23 08:15:02.000000000 +0000 @@ -1,3 +1,15 @@ +mimetex (1.76-1) unstable; urgency=medium + + * New release. + * Fix FTCBFS: Use cross compilers. (Closes: #882458). Thanks to + Helmut Grohne for report and patch! + * Update compat version to 10. + * Update standards version to 4.1.1. No changes needed. + * Remove reference to external file in manual + (W: mimetex: privacy-breach-generic). + + -- Hilmar Preuße Thu, 23 Nov 2017 09:15:02 +0100 + mimetex (1.74-1) unstable; urgency=low * New upstream release diff -Nru mimetex-1.74/debian/compat mimetex-1.76/debian/compat --- mimetex-1.74/debian/compat 2014-07-13 21:08:48.000000000 +0000 +++ mimetex-1.76/debian/compat 2017-11-23 07:30:23.000000000 +0000 @@ -1 +1 @@ -8 +10 diff -Nru mimetex-1.74/debian/control mimetex-1.76/debian/control --- mimetex-1.74/debian/control 2014-07-14 20:10:43.000000000 +0000 +++ mimetex-1.76/debian/control 2017-11-23 07:56:33.000000000 +0000 @@ -2,8 +2,8 @@ Section: utils Priority: optional Maintainer: Hilmar Preuße -Build-Depends: debhelper (>= 8) -Standards-Version: 3.9.5 +Build-Depends: debhelper (>= 10) +Standards-Version: 4.1.1 Package: mimetex Architecture: any diff -Nru mimetex-1.74/debian/patches/Makefile.diff mimetex-1.76/debian/patches/Makefile.diff --- mimetex-1.74/debian/patches/Makefile.diff 2014-07-14 20:02:00.000000000 +0000 +++ mimetex-1.76/debian/patches/Makefile.diff 2017-11-23 07:59:54.000000000 +0000 @@ -1,16 +1,18 @@ ---- mimetex-1.73.orig/Makefile -+++ mimetex-1.73/Makefile +Index: mimetex-1.75/Makefile +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ mimetex-1.75/Makefile 2017-11-23 08:57:56.000000000 +0100 @@ -0,0 +1,13 @@ +all: mimetex + +mimetex: mimetex.o gifsave.o -+ gcc -DAA mimetex.o gifsave.o -lm -o mimetex `dpkg-buildflags --get LDFLAGS` ++ $(CC) -DAA mimetex.o gifsave.o -lm -o mimetex `dpkg-buildflags --get LDFLAGS` + +mimetex.o: -+ gcc -DAA -c mimetex.c `dpkg-buildflags --get CFLAGS` `dpkg-buildflags --get CPPFLAGS` ++ $(CC) -DAA -c mimetex.c `dpkg-buildflags --get CFLAGS` `dpkg-buildflags --get CPPFLAGS` + +gifsave.o: -+ gcc -DAA -c gifsave.c `dpkg-buildflags --get CFLAGS` `dpkg-buildflags --get CPPFLAGS` ++ $(CC) -DAA -c gifsave.c `dpkg-buildflags --get CFLAGS` `dpkg-buildflags --get CPPFLAGS` + +clean: + rm -f mimetex mimetex.o gifsave.o diff -Nru mimetex-1.74/debian/patches/mimetex_manual.diff mimetex-1.76/debian/patches/mimetex_manual.diff --- mimetex-1.74/debian/patches/mimetex_manual.diff 1970-01-01 00:00:00.000000000 +0000 +++ mimetex-1.76/debian/patches/mimetex_manual.diff 2017-11-23 08:03:23.000000000 +0000 @@ -0,0 +1,14 @@ +Index: mimetex-1.75/mimetex.html +=================================================================== +--- mimetex-1.75.orig/mimetex.html 2017-07-11 08:04:54.000000000 +0200 ++++ mimetex-1.75/mimetex.html 2017-11-23 09:03:15.000000000 +0100 +@@ -459,8 +459,7 @@ + mimeTeX + + +- ++   +   + + pixmap on fp @@ -120,7 +122,7 @@ * get_delim(symbol,height,family) delim just larger than height * make_delim(symbol,height) construct delim exactly height size * ================= Tokenize/Parse Functions ================== - * texchar(expression,chartoken) retruns next char or \sequence + * texchar(expression,chartoken) returns next char or \sequence * texsubexpr(expr,subexpr,maxsubsz,left,right,isescape,isdelim) * texleft(expr,subexpr,maxsubsz,ldelim,rdelim) \left...\right * texscripts(expression,subscript,superscript,which)get scripts @@ -139,6 +141,9 @@ * isnumeric(s) determine if s is an integer * evalterm(store,term) evaluate numeric value of expression * getstore(store,identifier)return value corresponding to ident + * getdirective(string,directive,iscase,isvalid,nargs,args) \dir + * strpspn(s,reject,segment) non-{[()]} chars of s not in reject + * strqspn(s,q,isunescape) find matching " or ' in quoted string * unescape_url(url,isescape), x2c(what) xlate %xx url-encoded * PART3 =========== Rasterize an Expression (recursively) =========== * --- here's the primary entry point for all of mimeTeX --- @@ -176,9 +181,11 @@ * rastmagnify(expression,size,basesp,arg1,arg2,arg3) \magnify * rastreflect(expression,size,basesp,arg1,arg2,arg3)\reflectbox * rastfbox(expression,size,basesp,arg1,arg2,arg3) \fbox + * rastovalbox(expression,size,basesp,arg1,arg2,arg3) \ovalbox * rastinput(expression,size,basesp,arg1,arg2,arg3) \input * rastcounter(expression,size,basesp,arg1,arg2,arg3) \counter * rasteval(expression,size,basesp,arg1,arg2,arg3) \eval + * rastmathtex(expression,size,basesp,arg1,arg2,arg3) \mathtex * rasttoday(expression,size,basesp,arg1,arg2,arg3) \today * rastcalendar(expression,size,basesp,arg1,arg2,arg3) \calendar * rastenviron(expression,size,basesp,arg1,arg2,arg3) \environ @@ -198,6 +205,8 @@ * urlprune(url,n) http://abc.def.ghi.com/etc-->abc.def.ghi.com * urlncmp(url1,url2,n) compares topmost n levels of two url's * dbltoa(d,npts) double to comma-separated ascii + * rotmatrix(axis,theta) rotation matrix, theta degs around axis + * matmult(mat,vec) returns result of mat(rix) x vec(tor) * === Anti-alias completed raster (lowpass) or symbols (ss) === * aalowpass(rp,bytemap,grayscale) lowpass grayscale bytemap * aapnm(rp,bytemap,grayscale) lowpass based on pnmalias.c @@ -213,10 +222,14 @@ * aalookup(gridnum) table lookup for all possible 3x3 grids * aalowpasslookup(rp,bytemap,grayscale) driver for aalookup() * aasupsamp(rp,aa,sf,grayscale) or by supersampling + * imgsupsamp(rp,sf,grayscale)supersampling to shrink rp->pixmap + * ssweights(width,height,maxwt,wts)build canonical ss wt matrix * aacolormap(bytemap,nbytes,colors,colormap)make colors,colormap * aaweights(width,height) builds "canonical" weight matrix * aawtpixel(image,ipixel,weights,rotate) weight image at ipixel * === miscellaneous === + * mimetexgetbytemap(expression,width,height) bytemap expression + * mimetextypebytemap(bp,grayscale,width,height,fp) type bytemap * mimetexsetmsg(newmsglevel,newmsgfp) set msglevel and msgfp * PART1 ========================== Driver =========================== * main(argc,argv) parses math expression and emits mime xbitmap @@ -394,7 +407,9 @@ * 11/18/09 J.Forkosh Version 1.72 released. * 11/15/11 J.Forkosh Version 1.73 released. * 02/15/12 J.Forkosh Version 1.74 released. - * 09/26/12 J.Forkosh Most recent revision (also see REVISIONDATE) + * 12/28/16 J.Forkosh Version 1.75 released. + * 07/11/17 J.Forkosh Version 1.76 released. + * 07/11/17 J.Forkosh Most recent revision (also see REVISIONDATE) * See http://www.forkosh.com/mimetexchangelog.html for further details. * ****************************************************************************/ @@ -402,9 +417,9 @@ /* ------------------------------------------------------------------------- Program id -------------------------------------------------------------------------- */ -#define VERSION "1.74" /* mimeTeX version number */ -#define REVISIONDATE "26 Sept 2012" /* date of most recent revision */ -#define COPYRIGHTTEXT "Copyright(c) 2002-2012, John Forkosh Associates, Inc" +#define VERSION "1.76" /* mimeTeX version number */ +#define REVISIONDATE "11 July 2017" /* date of most recent revision */ +#define COPYRIGHTTEXT "Copyright(c) 2002-2017, John Forkosh Associates, Inc" /* ------------------------------------------------------------------------- header files and macros @@ -413,7 +428,9 @@ #include #include /*#include */ +#define _GNU_SOURCE /* for strcasestr() in string.h */ #include +char *strcasestr(); /* non-standard extension */ #include #include #include @@ -459,14 +476,14 @@ /* --- * windows-specific header info * ---------------------------- */ -#ifndef WINDOWS /* -DWINDOWS not supplied by user */ +#if !defined(WINDOWS) /* -DWINDOWS not supplied by user */ #if defined(_WINDOWS) || defined(_WIN32) || defined(WIN32) \ || defined(DJGPP) /* try to recognize windows compilers */ \ || defined(_USRDLL) /* must be WINDOWS if compiling for DLL */ #define WINDOWS /* signal windows */ #endif #endif -#ifdef WINDOWS /* Windows opens stdout in char mode, and */ +#if defined(WINDOWS) /* Windows opens stdout in char mode, and */ #include /* precedes every 0x0A with spurious 0x0D.*/ #include /* So emitcache() issues a Win _setmode() */ /* call to put stdout in binary mode. */ @@ -491,24 +508,24 @@ /* --- * check for supersampling or low-pass anti-aliasing * ------------------------------------------------- */ -#ifdef SS +#if defined(SS) #define ISSUPERSAMPLING 1 - #ifndef AAALGORITHM + #if !defined(AAALGORITHM) #define AAALGORITHM 1 /* default supersampling algorithm */ #endif - #ifndef AA /* anti-aliasing not explicitly set */ + #if !defined(AA) /* anti-aliasing not explicitly set */ #define AA /* so define it ourselves */ #endif - #ifndef SSFONTS /* need supersampling fonts */ + #if !defined(SSFONTS) /* need supersampling fonts */ #define SSFONTS #endif #else #define ISSUPERSAMPLING 0 - #ifndef AAALGORITHM + #if !defined(AAALGORITHM) #define AAALGORITHM 3 /*2*/ /* default lowpass algorithm */ #endif #endif -#ifndef MAXFOLLOW +#if !defined(MAXFOLLOW) #define MAXFOLLOW 8 /* aafollowline() maxturn default */ #endif @@ -527,55 +544,65 @@ #endif /* --- resolve output option inconsistencies --- */ #if defined(XBITMAP) /* xbitmap supercedes gif and png */ - #ifdef AA + #if defined(AA) #undef AA #endif - #ifdef GIF + #if defined(GIF) #undef GIF #endif - #ifdef PNG + #if defined(PNG) #undef PNG #endif #endif /* --- * decide whether or not to compile main() - * --------------------------------------- */ + * ------------------------------------------ */ #if defined(XBITMAP) || defined(GIF) || defined(PNG) - /* --- yes, compile main() --- */ + /* --- yes, main() >>will<< be compiled --- */ #define DRIVER /* main() driver will be compiled */ -#else /* --- main() won't be compiled (e.g., for gfuntype.c) --- */ - #ifndef TEXFONTS - #define NOTEXFONTS /* texfonts not required */ +#else /* --- no, main() >>won't<< be compiled (e.g., for gfuntype.c) --- */ + /* --- + * e.g., for gfuntype.c you should compile it as + * cc -DNOTEXFONTS gfuntype.c mimetex.c -lm -o gfuntype + * alternatively, gifscroll.c >>needs<< texfonts.h info + * and should be compiled >>without<< that -DNO... switch. + * Most programs should likely be compiled >>without<< it. + * ---------------------------------------------------------- */ + #if defined(NOTEXFONTS) && defined(TEXFONTS) /*do we want texfonts.h???*/ + #undef TEXFONTS /*assume texfonts.h >>not<< required if both given*/ #endif #endif /* --- * application headers - * ------------------- */ + * ---------------------- */ +/* --- TeX font info --- */ #if !defined(NOTEXFONTS) && !defined(TEXFONTS) - #define TEXFONTS /* to include texfonts.h */ + #define TEXFONTS /* default #include's texfonts.h */ #endif +/* --- "demo" programs only #include a few structs from mimetex.h --- */ +#define _MIMETEXMAIN (1) /* to include "everything" */ #include "mimetex.h" /* --- * info needed when gif image returned in memory buffer * ---------------------------------------------------- */ -#ifdef GIF /* compiling along with gifsave.c */ +#if defined(GIF) /* compiling along with gifsave.c */ extern int gifSize; extern int maxgifSize; #else /* or just set dummy values */ static int gifSize=0, maxgifSize=0; #endif /* --- gamma correction --- */ -#ifndef GAMMA +#if !defined(GAMMA) #define GAMMA 1.25 /*1.75*/ /*2.2*/ #endif -#ifndef REVERSEGAMMA +#if !defined(REVERSEGAMMA) #define REVERSEGAMMA 0.5 /* for \reverse white-on-black */ #endif /* --- opaque background (default to transparent) --- */ -#ifndef OPAQUE +#if !defined(OPAQUE) #define ISTRANSPARENT 1 #else #define ISTRANSPARENT 0 @@ -603,28 +630,63 @@ #define MAXGIFSZ 131072 /* max #bytes in output GIF image */ #endif +/* --- + * note: point3d.x,y,z are relative to the origin 0.,0.,0. of an abstract + * coordinate system, calculated to be at the center pixel of a raster. + * point3d and matrix3d are used for rotations, as per + * https://en.wikipedia.org/wiki/Rotation_matrix#In_three_dimensions + * in function rotrast3d() + * ------------------------------------------------------------------------ */ +#if 0 + /* --- + * >> Note: point3d and matrix3d now defined in mimetex.h << + * (they're temporarily left here only as comments) + * ------------------------------------------------------------ */ + /* --- 3d-point --- */ + #define point3d struct point3d_struct /* "typedef" for point3d_struct */ + point3d { + /*---x,y,z-coords relative to 0.,0.,0. origin of abstract coord axes---*/ + double x; /* x-coord */ + double y; /* y-coord */ + double z; /* z-coord */ + } ; /* --- end-of-point3d_struct --- */ + /* --- 3d-matrix (rotation matrix) stored row-wise --- */ + #define matrix3d struct matrix3d_struct /* "typedef" for matrix3d_struct */ + matrix3d { + /* --- 3x3 matrix stored row-wise --- */ + point3d xrow; /* x-row */ + point3d yrow; /* y-row */ + point3d zrow; /* z-row */ + } ; /* --- end-of-matrix3d_struct --- */ +#endif +/* --- 3d-rotation parameters --- */ +#define YAXIS {0.,1.,0.} /* x-component=0, y=1, z=0 */ +#define UTHETA 0.0 /* no rotation (in degrees) */ +GLOBAL(point3d,uaxis,YAXIS); /* rotate around y-axis */ +GLOBAL(double,utheta,UTHETA); /* rotation amount in degrees */ + /* ------------------------------------------------------------------------- adjustable default values -------------------------------------------------------------------------- */ /* --- * anti-aliasing parameters * ------------------------ */ -#ifndef CENTERWT +#if !defined(CENTERWT) /*#define CENTERWT 32*/ /* anti-aliasing centerwt default */ /*#define CENTERWT 10*/ /* anti-aliasing centerwt default */ #define CENTERWT 8 /* anti-aliasing centerwt default */ #endif -#ifndef ADJACENTWT +#if !defined(ADJACENTWT) /*#define ADJACENTWT 3*/ /* anti-aliasing adjacentwt default*/ #define ADJACENTWT 2 /* anti-aliasing adjacentwt default*/ #endif -#ifndef CORNERWT +#if !defined(CORNERWT) #define CORNERWT 1 /* anti-aliasing cornerwt default*/ #endif -#ifndef MINADJACENT +#if !defined(MINADJACENT) #define MINADJACENT 6 /*anti-aliasing minadjacent default*/ #endif -#ifndef MAXADJACENT +#if !defined(MAXADJACENT) #define MAXADJACENT 8 /*anti-aliasing maxadjacent default*/ #endif /* --- variables for anti-aliasing parameters --- */ @@ -665,7 +727,7 @@ other variables -------------------------------------------------------------------------- */ /* --- black on white background (default), or white on black --- */ -#ifdef WHITE +#if defined(WHITE) #define ISBLACKONWHITE 0 /* white on black background */ #else #define ISBLACKONWHITE 1 /* black on white background */ @@ -674,13 +736,13 @@ #define BGRED (ISBLACKONWHITE?255:0) #define BGGREEN (ISBLACKONWHITE?255:0) #define BGBLUE (ISBLACKONWHITE?255:0) -#ifndef FGRED +#if !defined(FGRED) #define FGRED (ISBLACKONWHITE?0:255) #endif -#ifndef FGGREEN +#if !defined(FGGREEN) #define FGGREEN (ISBLACKONWHITE?0:255) #endif -#ifndef FGBLUE +#if !defined(FGBLUE) #define FGBLUE (ISBLACKONWHITE?0:255) #endif /* --- advertisement @@ -691,92 +753,108 @@ #ifndef HOST_SHOWAD #define HOST_SHOWAD "\000" /* show ads on all hosts */ #endif +/* --- mathTeX info for \mathtex{} directive --- */ +#if !defined(MATHTEX) /* localhost:// or http://url/ */ + #define MATHTEX "localhost://mathtex.cgi" +#endif +#if !defined(MATHTEXPWD) /* mathTeX \password{} */ + #define MATHTEXPWD "\000" +#endif +#if !defined(WGET) /* local /path/to/wget */ + #define WGET "wget" +#endif /* --- "smash" margin (0 means no smashing) --- */ -#ifndef SMASHMARGIN - #ifdef NOSMASH +#if !defined(SMASHMARGIN) + #if defined(NOSMASH) #define SMASHMARGIN 0 #else #define SMASHMARGIN 3 #endif #endif -#ifndef SMASHCHECK +#if !defined(SMASHCHECK) #define SMASHCHECK 0 #endif /* --- textwidth --- */ -#ifndef TEXTWIDTH +#if !defined(TEXTWIDTH) #define TEXTWIDTH (400) #endif /* --- font "combinations" --- */ #define CMSYEX (109) /*select CMSY10, CMEX10 or STMARY10*/ /* --- prefix prepended to all expressions --- */ -#ifndef PREFIX +#if !defined(PREFIX) #define PREFIX "\000" /* default no prepended prefix */ #endif /* --- skip argv[]'s preceding ARGSIGNAL when parsing command-line args --- */ -#ifdef NOARGSIGNAL +#if defined(NOARGSIGNAL) #define ARGSIGNAL NULL #endif -#ifndef ARGSIGNAL +#if !defined(ARGSIGNAL) #define ARGSIGNAL "++" #endif /* --- security and logging (inhibit message logging, etc) --- */ -#ifndef SECURITY +#if !defined(SECURITY) #define SECURITY 999 /* default highest security level */ #endif -#ifndef LOGFILE +#if !defined(LOGFILE) #define LOGFILE "mimetex.log" /* default log file */ #endif -#ifndef CACHELOG +#if !defined(CACHELOG) #define CACHELOG "mimetex.log" /* default caching log file */ #endif #if !defined(NODUMPENVP) && !defined(DUMPENVP) #define DUMPENVP /* assume char *envp[] available */ #endif /* --- max query_string length if no http_referer supplied --- */ -#ifndef NOREFMAXLEN +#if !defined(NOREFMAXLEN) #define NOREFMAXLEN 9999 /* default to any length query */ #endif -#ifndef NOREFSAFELEN +#if !defined(NOREFSAFELEN) #define NOREFSAFELEN 24 /* too small for hack exploit */ #endif /* --- check whether or not to perform http_referer check --- */ -#ifdef REFERER /* only specified referers allowed */ +#if defined(REFERER) /* only specified referers allowed */ #undef NOREFMAXLEN #define NOREFMAXLEN NOREFSAFELEN #else /* all http_referer's allowed */ #define REFERER NULL #endif /* --- check top levels of http_referer against server_name --- */ -#ifdef REFLEVELS /* #topmost levels to check */ +#if defined(REFLEVELS) /* #topmost levels to check */ #undef NOREFMAXLEN #define NOREFMAXLEN NOREFSAFELEN #else - #ifdef NOREFCHECK + #if defined(NOREFCHECK) #define REFLEVELS 0 /* don't match host and referer */ #else #define REFLEVELS 3 /* default matches abc.def.com */ #endif #endif +/* --- password to bypass preceding REFERER checks --- */ +#if !defined(PASSWORD) + #define PASSWORD "\000" /* \password{PASSWORD} in expression */ +#endif +static char password[128] = "\000"; /* user's \password{password} */ +static int ispassword = 0; /* true if password==PASSWORD */ /* --- check whether or not \input, \counter, \environment permitted --- */ -#ifdef DEFAULTSECURITY /* default security specified */ +#if defined(DEFAULTSECURITY) /* default security specified */ #define EXPLICITDEFSECURITY /* don't override explicit default */ #else /* defualt security not specified */ #define DEFAULTSECURITY (8) /* so set default security level */ #endif -#ifdef INPUTREFERER /*http_referer's permitted to \input*/ - #ifndef INPUTSECURITY /* so we need to permit \input{} */ +#if defined(INPUTREFERER) /*http_referer's permitted to \input*/ + #if !defined(INPUTSECURITY) /* so we need to permit \input{} */ #define INPUTSECURITY (99999) /* make sure SECURITY=DBGLEVEL */ #define LOGLEVEL 3 /* logging if msglevel>=LOGLEVEL */ -#ifndef FORMLEVEL +#if !defined(FORMLEVEL) #define FORMLEVEL LOGLEVEL /*msglevel if called from html form*/ #endif -#ifndef ERRORSTATUS /* exit(ERRORSTATUS) for any error */ +#if !defined(ERRORSTATUS) /* exit(ERRORSTATUS) for any error */ #define ERRORSTATUS 0 /* default doesn't signal errors */ #endif GLOBAL(int,seclevel,SECURITY); /* security level */ @@ -847,11 +925,14 @@ GLOBAL(int,errorstatus,ERRORSTATUS); /* exit status if error encountered*/ GLOBAL(int,exitstatus,0); /* exit status (0=success) */ STATIC FILE *msgfp; /* output in command-line mode */ +/* --- logging macros --- */ +#define logdump(lvl,msg) if(msglevel>=(lvl)) {logmsg(msg);}else +#define logmsg(msg) if(1) {logger(msgfp,msglevel,(msg),NULL);}else /* --- embed warnings in rendered expressions, [\xxx?] if \xxx unknown --- */ -#ifdef WARNINGS +#if defined(WARNINGS) #define WARNINGLEVEL WARNINGS #else - #ifdef NOWARNINGS + #if defined(NOWARNINGS) #define WARNINGLEVEL 0 #else #define WARNINGLEVEL 1 @@ -936,12 +1017,18 @@ /* ------------------------------------------------------------------------- store for evalterm() [n.b., these are stripped-down funcs from nutshell] -------------------------------------------------------------------------- */ -#define STORE struct store_struct /* "typedef" for store struct */ -#define MAXSTORE 100 /* max 100 identifiers */ -STORE { - char *identifier; /* identifier */ - int *value; /* address of corresponding value */ - } ; /* --- end-of-store_struct --- */ +#if 0 + /* --- + * >> Note: STORE and MAXSTORE now defined in mimetex.h << + * (they're temporarily left here only as comments) + * ----------------------------------------------------------- */ + #define STORE struct store_struct /* "typedef" for store struct */ + #define MAXSTORE 100 /* max 100 identifiers */ + STORE { + char *identifier; /* identifier */ + int *value; /* address of corresponding value */ + } ; /* --- end-of-store_struct --- */ +#endif static STORE mimestore[MAXSTORE] = { { "fontsize", &fontsize }, { "fs", &fontsize }, /* font size */ { "fontnum", &fontnum }, { "fn", &fontnum }, /* font number */ @@ -951,6 +1038,21 @@ } ; /* --- end-of-mimestore[] --- */ /* ------------------------------------------------------------------------- +other application global data +-------------------------------------------------------------------------- */ +/* --- getdirective() global data --- */ +static int argformat = 0; /* 111... if arg not {}-enclosed */ +static int optionalpos = 0; /* # {args} before optional [args] */ +static int noptional = 0; /* # optional [args] found */ +static char optionalargs[10][128] = /* buffer for optional args */ + { "\000", "\000", "\000", "\000", "\000", "\000", "\000", "\000" }; +/* --- **dump/debug** data --- */ +int isdumpgif = 0; /* **debug** dump gif image */ +#if !defined(DUMPGIF) + #define DUMPGIF "dumpgif" /* use .gif_dumpgif extension */ +#endif + +/* ------------------------------------------------------------------------- miscellaneous macros -------------------------------------------------------------------------- */ #if 0 /* --- these are now #define'd in mimetex.h --- */ @@ -1002,6 +1104,13 @@ #define strsqueezep(s,t) if(!isempty((s))&&!isempty((t))) { \ int sqlen=strlen((s))-strlen((t)); \ if (sqlen>0 && sqlen<=999) {strsqueeze((s),sqlen);} } else +/* --- skip/find whitespace (from mathtex.c for getdirective()) --- */ +#define findwhite(thisstr) while ( !isempty(thisstr) ) \ + if ( isthischar(*(thisstr),WHITESPACE) ) break; else (thisstr)++ + /* thisstr += strcspn(thisstr,WHITESPACE) */ +/* --- skip \command (i.e., find char past last char of \command) --- */ +#define skipcommand(thisstr) while ( !isempty(thisstr) ) \ + if ( !isalpha(*(thisstr)) ) break; else (thisstr)++ /* --- * PART2 @@ -1025,7 +1134,7 @@ * Notes: * ======================================================================= */ /* --- entry point --- */ -raster *new_raster ( int width, int height, int pixsz ) +FUNCSCOPE raster *new_raster ( int width, int height, int pixsz ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -1034,7 +1143,7 @@ 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 delete_raster();*/ /* in case pixmap malloc() fails */ int npadding = (0&&issupersampling?8+256:0); /* padding bytes */ /* ------------------------------------------------------------------------- allocate and initialize raster struct and embedded bitmap @@ -1046,7 +1155,7 @@ 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); } + (int)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 */ @@ -1068,7 +1177,7 @@ 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 */ +*pixmap = (pixbyte)0; /* and first byte always 0 */ rp->pixmap = pixmap; /* store ptr to malloced memory */ /* ------------------------------------------------------------------------- Back to caller with address of raster struct, or NULL ptr for any error. @@ -1096,14 +1205,14 @@ * Notes: o if width or height <=0, embedded raster not allocated * ======================================================================= */ /* --- entry point --- */ -subraster *new_subraster ( int width, int height, int pixsz ) +FUNCSCOPE 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 */ +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 */ /* ------------------------------------------------------------------------- @@ -1156,7 +1265,7 @@ * Notes: * ======================================================================= */ /* --- entry point --- */ -chardef *new_chardef ( ) +FUNCSCOPE chardef *new_chardef ( ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -1196,7 +1305,7 @@ * Notes: * ======================================================================= */ /* --- entry point --- */ -int delete_raster ( raster *rp ) +FUNCSCOPE int delete_raster ( raster *rp ) { /* ------------------------------------------------------------------------- free raster bitmap and struct @@ -1223,12 +1332,12 @@ * Notes: * ======================================================================= */ /* --- entry point --- */ -int delete_subraster ( subraster *sp ) +FUNCSCOPE int delete_subraster ( subraster *sp ) { /* ------------------------------------------------------------------------- free subraster struct -------------------------------------------------------------------------- */ -int delete_raster(); /* to delete embedded raster */ +/*int delete_raster();*/ /* to delete embedded raster */ if ( sp != (subraster *)NULL ) /* can't free null ptr */ { if ( sp->type != CHARASTER ) /* not static character data */ @@ -1252,7 +1361,7 @@ * Notes: * ======================================================================= */ /* --- entry point --- */ -int delete_chardef ( chardef *cp ) +FUNCSCOPE int delete_chardef ( chardef *cp ) { /* ------------------------------------------------------------------------- free chardef struct @@ -1282,18 +1391,18 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -raster *rastcpy ( raster *rp ) +FUNCSCOPE raster *rastcpy ( raster *rp ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -raster *new_raster(), *newrp=NULL; /*copied raster returned to caller*/ +raster /**new_raster(),*/ *newrp=NULL; /*copied raster returned to caller*/ int height= (rp==NULL?0:rp->height), /* original and copied height */ width = (rp==NULL?0:rp->width), /* original and copied width */ pixsz = (rp==NULL?0:rp->pixsz), /* #bits per pixel */ nbytes= (rp==NULL?0:(pixmapsz(rp))); /* #bytes in rp's pixmap */ /* ------------------------------------------------------------------------- -allocate rotated raster and fill it +allocate copied raster and fill it -------------------------------------------------------------------------- */ /* --- allocate copied raster with same width,height, and copy bitmap --- */ if ( rp != NULL ) /* nothing to copy if ptr null */ @@ -1316,14 +1425,14 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -subraster *subrastcpy ( subraster *sp ) +FUNCSCOPE subraster *subrastcpy ( subraster *sp ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -subraster *new_subraster(), *newsp=NULL; /* allocate new subraster */ -raster *rastcpy(), *newrp=NULL; /* and new raster image within it */ -int delete_subraster(); /* dealloc newsp if rastcpy() fails*/ +subraster /**new_subraster(),*/ *newsp=NULL; /* allocate new subraster */ +raster /**rastcpy(),*/ *newrp=NULL; /* and new raster image within it */ +/*int delete_subraster();*/ /* dealloc newsp if rastcpy() fails*/ /* ------------------------------------------------------------------------- make copy, and return it to caller -------------------------------------------------------------------------- */ @@ -1367,12 +1476,12 @@ * a hat is <, etc. * ======================================================================= */ /* --- entry point --- */ -raster *rastrot ( raster *rp ) +FUNCSCOPE raster *rastrot ( raster *rp ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -raster *new_raster(), *rotated=NULL; /*rotated raster returned to caller*/ +raster /**new_raster(),*/ *rotated=NULL;/*rotated raster returned to caller*/ int height = rp->height, irow, /* original height, row index */ width = rp->width, icol, /* original width, column index */ pixsz = rp->pixsz; /* #bits per pixel */ @@ -1393,6 +1502,78 @@ /* ========================================================================== + * Function: rastrot3d ( rp, axis, theta ) + * Purpose: rotates rp around 3d-axis by theta, projecting back onto + * x,y-plane + * -------------------------------------------------------------------------- + * Arguments: rp (I) ptr to raster struct with image to be rotated + * axis (I) point3d * specifying rotation axis + * theta (I) double specifying rotation in degrees + * -------------------------------------------------------------------------- + * Returns: ( raster * ) ptr to new raster struct with rotated image, + * or NULL for any error. + * -------------------------------------------------------------------------- + * Notes: o + * ======================================================================= */ +/* --- entry point --- */ +FUNCSCOPE raster *rastrot3d ( raster *rp, point3d *axis, double theta ) +{ +/* ------------------------------------------------------------------------- +Allocations and Declarations +-------------------------------------------------------------------------- */ +raster /**new_raster(),*/ *rotp = NULL; /* rotated raster back to caller */ +int width = rp->width, icol = 0, /* raster width, column index */ + height= rp->height, irow = 0, /* raster height, row index */ + pixsz = rp->pixsz; /* #bits per pixel */ +double midcol = ((double)(width))/2.0, /* x-origin index coord */ + midrow = ((double)(height))/2.0; /* y-origin index coord */ +int bgpixel = 0; /* background pixel value */ +matrix3d /**rotmatrix(),*/ *rotmat=NULL; /* rotation matrix */ +/*point3d *matmult();*/ /* matrix multiplication */ +/* ------------------------------------------------------------------------- +Initialization +-------------------------------------------------------------------------- */ +/* --- check input --- */ +if ( rp == NULL ) goto end_of_job; /* error if no input raster supplied */ +/* --- get rotation matrix --- */ +if ( (rotmat = rotmatrix(axis,theta)) /*rotate around axis by theta degrees*/ +== NULL ) goto end_of_job; /*some problem, likely 0-length axis*/ +/* --- allocate rotated raster (with same width,height) --- */ +if ( (rotp = new_raster(width,height,pixsz)) /* (same width,height) */ +== NULL ) goto end_of_job; /* quit if allocation failed */ +/* ------------------------------------------------------------------------- +rotate pixel-by-pixel +-------------------------------------------------------------------------- */ +for ( irow=0; irowy + midrow + dy); /* rotated row */ + int jcol = (int)(urot->x + midcol + dx); /* rotated col */ + if ( jrow>=0 && jrow=0 && jcolheight, irow, /* height, row index */ width = rp->width, icol, /* width, column index */ mrow = 0, mcol = 0, /* dup pixels magstep*magstep times*/ @@ -1460,7 +1641,8 @@ * as described by http://en.wikipedia.org/wiki/2xSaI * ======================================================================= */ /* --- entry point --- */ -intbyte *bytemapmag ( intbyte *bytemap, int width, int height, int magstep ) +FUNCSCOPE intbyte *bytemapmag ( intbyte *bytemap, + int width, int height, int magstep ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -1579,12 +1761,12 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -raster *rastref ( raster *rp, int axis ) +FUNCSCOPE raster *rastref ( raster *rp, int axis ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -raster *new_raster(), *reflected=NULL; /* reflected raster back to caller */ +raster /**new_raster(),*/ *reflected=NULL;/*reflected raster back to caller*/ int height = rp->height, irow, /* height, row index */ width = rp->width, icol, /* width, column index */ pixsz = rp->pixsz; /* #bits per pixel */ @@ -1624,8 +1806,8 @@ * Notes: * ======================================================================= */ /* --- entry point --- */ -int rastput ( raster *target, raster *source, - int top, int left, int isopaque ) +FUNCSCOPE int rastput ( raster *target, raster *source, + int top, int left, int isopaque ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -1731,16 +1913,16 @@ * +------------------------+ --- * ======================================================================= */ /* --- entry point --- */ -subraster *rastcompose ( subraster *sp1, subraster *sp2, int offset2, - int isalign, int isfree ) +FUNCSCOPE subraster *rastcompose ( subraster *sp1, subraster *sp2, + int offset2, int isalign, int isfree ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -subraster *new_subraster(), *sp=(subraster *)NULL; /* returned subraster */ +subraster /**new_subraster(),*/ *sp=(subraster *)NULL; /*returned subraster*/ raster *rp=(raster *)NULL; /* new composite raster in sp */ -int delete_subraster(); /* in case isfree non-zero */ -int rastput(); /*place sp1,sp2 in composite raster*/ +/*int delete_subraster();*/ /* in case isfree non-zero */ +/*int rastput();*/ /*place sp1,sp2 in composite raster*/ int base1 = sp1->baseline, /*baseline for underlying subraster*/ height1 = (sp1->image)->height, /* height for underlying subraster */ width1 = (sp1->image)->width, /* width for underlying subraster */ @@ -1847,16 +2029,16 @@ * Notes: * ======================================================================= */ /* --- entry point --- */ -subraster *rastcat ( subraster *sp1, subraster *sp2, int isfree ) +FUNCSCOPE subraster *rastcat ( subraster *sp1, subraster *sp2, int isfree ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -subraster *new_subraster(), *sp=(subraster *)NULL; /* returned subraster */ +subraster /**new_subraster(),*/ *sp=(subraster *)NULL; /*returned subraster*/ raster *rp=(raster *)NULL; /* new concatted raster */ -int delete_subraster(); /* in case isfree non-zero */ -int rastput(); /*place sp1,sp2 in concatted raster*/ -int type_raster(); /* debugging display */ +/*int delete_subraster();*/ /* in case isfree non-zero */ +/*int rastput();*/ /*place sp1,sp2 in concatted raster*/ +/*int type_raster();*/ /* debugging display */ int base1 = sp1->baseline, /*baseline for left-hand subraster*/ height1 = (sp1->image)->height, /* height for left-hand subraster */ width1 = (sp1->image)->width, /* width for left-hand subraster */ @@ -2051,16 +2233,16 @@ * Notes: * ======================================================================= */ /* --- entry point --- */ -subraster *rastack ( subraster *sp1, subraster *sp2, - int base, int space, int iscenter, int isfree ) +FUNCSCOPE subraster *rastack ( subraster *sp1, subraster *sp2, + int base, int space, int iscenter, int isfree ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -subraster *new_subraster(), *sp=(subraster *)NULL; /* returned subraster */ +subraster /**new_subraster(),*/ *sp=(subraster *)NULL; /*returned subraster*/ raster *rp=(raster *)NULL; /* new stacked raster in sp */ -int delete_subraster(); /* in case isfree non-zero */ -int rastput(); /* place sp1,sp2 in stacked raster */ +/*int delete_subraster();*/ /* in case isfree non-zero */ +/*int rastput();*/ /* place sp1,sp2 in stacked raster */ int base1 = sp1->baseline, /* baseline for lower subraster */ height1 = (sp1->image)->height, /* height for lower subraster */ width1 = (sp1->image)->width, /* width for lower subraster */ @@ -2140,23 +2322,22 @@ * But recent changes haven't been tested/exercised. * ======================================================================= */ /* --- entry point --- */ -raster *rastile ( subraster *tiles, int ntiles ) +FUNCSCOPE raster *rastile ( subraster *tiles, int ntiles ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -raster *new_raster(), *composite=(raster *)NULL; /*raster back to caller*/ +raster /**new_raster(),*/ *composite=(raster *)NULL;/*raster back to caller*/ int width=0, height=0, pixsz=0, /*width,height,pixsz of composite raster*/ toprow=9999, rightcol=-999, /* extreme upper-right corner of tiles */ botrow=-999, leftcol=9999; /* extreme lower-left corner of tiles */ int itile; /* tiles[] index */ -int rastput(); /* overlay each tile in composite raster */ +/*int rastput();*/ /* overlay each tile in composite raster */ /* ------------------------------------------------------------------------- run through tiles[] to determine dimensions for composite raster -------------------------------------------------------------------------- */ /* --- determine row and column bounds of composite raster --- */ -for ( itile=0; itiletoprow); @@ -2206,7 +2387,7 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -int rastsmash ( subraster *sp1, subraster *sp2 ) +FUNCSCOPE int rastsmash ( subraster *sp1, subraster *sp2 ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -2226,7 +2407,7 @@ int firstcol1[1025], nfirst1=0, /* 1st sp1 col containing set pixel*/ firstcol2[1025], nfirst2=0; /* 1st sp2 col containing set pixel*/ int smin=9999, xmin=9999,ymin=9999; /* min separation (s=x+y) */ -int type_raster(); /* display debugging output */ +/*int type_raster();*/ /* display debugging output */ /* ------------------------------------------------------------------------- find right edge of sp1 and left edge of sp2 (these will be abutting edges) -------------------------------------------------------------------------- */ @@ -2314,7 +2495,7 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -int rastsmashcheck ( char *term ) +FUNCSCOPE int rastsmashcheck ( char *term ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -2401,30 +2582,30 @@ * and caller should check dimensions in returned subraster * ======================================================================= */ /* --- entry point --- */ -subraster *accent_subraster ( int accent, int width, int height, -int direction, int pixsz ) +FUNCSCOPE subraster *accent_subraster ( int accent, int width, int height, + int direction, int pixsz ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ /* --- general info --- */ -raster *new_raster(), *rp=NULL; /*raster containing desired accent*/ -subraster *new_subraster(), *sp=NULL; /* subraster returning accent */ -int delete_raster(), delete_subraster(); /*free allocated raster on err*/ -int line_raster(), /* draws lines */ - rule_raster(), /* draw solid boxes */ +raster /**new_raster(),*/ *rp=NULL; /*raster containing desired accent*/ +subraster /**new_subraster(),*/ *sp=NULL; /* subraster returning accent */ +/*int delete_raster(), delete_subraster();*/ /*free allocated raster on err*/ +int /*line_raster(),*/ /* draws lines */ + /*rule_raster(),*/ /* draw solid boxes */ thickness = 1; /* line thickness */ /*int pixval = (pixsz==1? 1 : (pixsz==8?255:(-1)));*/ /*black pixel value*/ /* --- other working info --- */ int col0, col1, /* cols for line */ row0, row1; /* rows for line */ -subraster *get_delim(), *accsp=NULL; /*find suitable cmex10 symbol/accent*/ +subraster /**get_delim(),*/ *accsp=NULL; /*find suitable cmex10 symbol/accent*/ /* --- info for under/overbraces, tildes, etc --- */ char brace[16]; /*"{" for over, "}" for under, etc*/ -raster *rastrot(), /* rotate { for overbrace, etc */ - *rastcpy(); /* may need copy of original */ -subraster *arrow_subraster(); /* rightarrow for vec */ -subraster *rastack(); /* stack accent atop extra space */ +/*raster *rastrot(),*/ /* rotate { for overbrace, etc */ +/* *rastcpy();*/ /* may need copy of original */ +/*subraster *arrow_subraster();*/ /* rightarrow for vec */ +/*subraster *rastack();*/ /* stack accent atop extra space */ int iswidthneg = 0; /* set true if width<0 arg passed */ int serifwidth=0; /* serif for surd */ int isBig=0; /* true for ==>arrow, false for -->*/ @@ -2582,14 +2763,14 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -subraster *arrow_subraster ( int width, int height, int pixsz, - int drctn, int isBig ) +FUNCSCOPE subraster *arrow_subraster ( int width, int height, int pixsz, + int drctn, int isBig ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -subraster *new_subraster(), *arrowsp=NULL; /* allocate arrow subraster */ -int rule_raster(); /* draw arrow line */ +subraster /**new_subraster(),*/ *arrowsp=NULL; /* allocate arrow subraster */ +/*int rule_raster();*/ /* draw arrow line */ int irow, midrow=height/2; /* index, midrow is arrowhead apex */ int icol, thickness=(height>15?2:2); /* arrowhead thickness and index */ int pixval = (pixsz==1? 1 : (pixsz==8?255:(-1))); /* black pixel value */ @@ -2658,14 +2839,14 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -subraster *uparrow_subraster ( int width, int height, int pixsz, - int drctn, int isBig ) +FUNCSCOPE subraster *uparrow_subraster ( int width, int height, int pixsz, + int drctn, int isBig ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -subraster *new_subraster(), *arrowsp=NULL; /* allocate arrow subraster */ -int rule_raster(); /* draw arrow line */ +subraster /**new_subraster(),*/ *arrowsp=NULL; /* allocate arrow subraster */ +/*int rule_raster();*/ /* draw arrow line */ int icol, midcol=width/2; /* index, midcol is arrowhead apex */ int irow, thickness=(width>15?2:2); /* arrowhead thickness and index */ int pixval = (pixsz==1? 1 : (pixsz==8?255:(-1))); /* black pixel value */ @@ -2741,8 +2922,8 @@ * more or less comparable. * ======================================================================= */ /* --- entry point --- */ -int rule_raster ( raster *rp, int top, int left, - int width, int height, int type ) +FUNCSCOPE int rule_raster ( raster *rp, int top, int left, + int width, int height, int type ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -2832,8 +3013,8 @@ * whose top-left corner is row0,col0. * ======================================================================= */ /* --- entry point --- */ -int line_raster ( raster *rp, int row0, int col0, - int row1, int col1, int thickness ) +FUNCSCOPE int line_raster ( raster *rp, int row0, int col0, + int row1, int col1, int thickness ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -2854,7 +3035,7 @@ xwidth= (isline? 0.0 : /*#pixels per row to get sloped line thcknss*/ ((double)thickness)*sqrt((dx*dx)+(dy*dy*ar*ar))/fabs(dy*ar)), xheight = 1.0; -int line_recurse(), isrecurse=1; /* true to draw line recursively */ +int /*line_recurse(),*/ isrecurse=1; /* true to draw line recursively */ /* ------------------------------------------------------------------------- Check args -------------------------------------------------------------------------- */ @@ -2964,8 +3145,8 @@ * until a horizontal or vertical segment is found * ======================================================================= */ /* --- entry point --- */ -int line_recurse ( raster *rp, double row0, double col0, - double row1, double col1, int thickness ) +FUNCSCOPE int line_recurse ( raster *rp, double row0, double col0, + double row1, double col1, int thickness ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -3025,8 +3206,8 @@ * o using ellipse equation x^2/a^2 + y^2/b^2 = 1 * ======================================================================= */ /* --- entry point --- */ -int circle_raster ( raster *rp, int row0, int col0, - int row1, int col1, int thickness, char *quads ) +FUNCSCOPE int circle_raster ( raster *rp, int row0, int col0, + int row1, int col1, int thickness, char *quads ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -3057,7 +3238,7 @@ yx2, yx; /* solved minor ellipse coord */ int isokay = 1; /* true if no pixels out-of-bounds */ char *qptr=NULL, *allquads="1234"; /* quadrants if input quads==NULL */ -int circle_recurse(), isrecurse=1; /* true to draw ellipse recursively*/ +int /*circle_recurse(),*/ isrecurse=1; /*true to draw ellipse recursively*/ /* ------------------------------------------------------------------------- pixel-by-pixel along positive major axis, quit when it goes negative -------------------------------------------------------------------------- */ @@ -3186,8 +3367,8 @@ * equation is r = ab/sqrt(a^2*sin^2(theta)+b^2*cos^2(theta)) * ======================================================================= */ /* --- entry point --- */ -int circle_recurse ( raster *rp, int row0, int col0, - int row1, int col1, int thickness, double theta0, double theta1 ) +FUNCSCOPE int circle_recurse ( raster *rp, int row0, int col0, int row1, + int col1, int thickness, double theta0, double theta1 ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -3261,8 +3442,8 @@ * until a point is found * ======================================================================= */ /* --- entry point --- */ -int bezier_raster ( raster *rp, double r0, double c0, - double r1, double c1, double rt, double ct ) +FUNCSCOPE int bezier_raster ( raster *rp, double r0, double c0, + double r1, double c1, double rt, double ct ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -3336,14 +3517,14 @@ * draws all four sides, too. * ======================================================================= */ /* --- entry point --- */ -raster *border_raster ( raster *rp, int ntop, int nbot, - int isline, int isfree ) +FUNCSCOPE raster *border_raster ( raster *rp, int ntop, int nbot, + int isline, int isfree ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -raster *new_raster(), *bp=(raster *)NULL; /*raster back to caller*/ -int rastput(); /* overlay rp in new bordered raster */ +raster /**new_raster(),*/ *bp=(raster *)NULL; /*raster back to caller*/ +/*int rastput();*/ /* overlay rp in new bordered raster */ int width = (rp==NULL?0:rp->width), /* width of raster */ height = (rp==NULL?0:rp->height), /* height of raster */ istopneg=0, isbotneg=0, /* true if ntop or nbot negative */ @@ -3449,14 +3630,14 @@ * Notes: o For \! negative space, for \hspace{-10}, etc. * ======================================================================= */ /* --- entry point --- */ -raster *backspace_raster ( raster *rp, int nback, int *pback, int minspace, - int isfree ) +FUNCSCOPE raster *backspace_raster ( raster *rp, int nback, int *pback, + int minspace, int isfree ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -raster *new_raster(), *bp=(raster *)NULL; /* raster returned to caller */ -int delete_raster(); /* free input rp if isfree is true */ +raster /**new_raster(),*/ *bp=(raster *)NULL; /*raster returned to caller*/ +/*int delete_raster();*/ /* free input rp if isfree is true */ int width = (rp==NULL?0:rp->width), /* original width of raster */ height = (rp==NULL?0:rp->height), /* height of raster */ mback = nback, /* nback adjusted for minspace */ @@ -3518,7 +3699,7 @@ * Notes: * ======================================================================= */ /* --- entry point --- */ -int type_raster ( raster *rp, FILE *fp ) +FUNCSCOPE int type_raster ( raster *rp, FILE *fp ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -3529,8 +3710,8 @@ char scanline[133]; /* ascii image for one scan line */ int scan_width; /* #chars in scan (<=display_width)*/ int irow, locol,hicol=(-1); /* height index, width indexes */ -raster *gftobitmap(), *bitmaprp=rp; /* convert .gf to bitmap if needed */ -int delete_raster(); /*free bitmap converted for display*/ +raster /**gftobitmap(),*/ *bitmaprp=rp; /* convert .gf to bitmap if needed */ +/*int delete_raster();*/ /*free bitmap converted for display*/ /* -------------------------------------------------------------------------- initialization -------------------------------------------------------------------------- */ @@ -3616,8 +3797,8 @@ * Notes: * ======================================================================= */ /* --- entry point --- */ -int type_bytemap ( intbyte *bp, int grayscale, - int width, int height, FILE *fp ) +FUNCSCOPE int type_bytemap ( intbyte *bp, int grayscale, + int width, int height, FILE *fp ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -3635,6 +3816,8 @@ /* -------------------------------------------------------------------------- initialization -------------------------------------------------------------------------- */ +/* --- check args --- */ +if ( bp == NULL ) goto end_of_job; /* nothing to do */ /* --- redirect null fp --- */ if ( fp == (FILE *)NULL ) fp = stdout; /* default fp to stdout if null */ /* --- check for ascii string --- */ @@ -3687,7 +3870,7 @@ /* ------------------------------------------------------------------------- Back to caller with 1=okay, 0=failed. -------------------------------------------------------------------------- */ -return ( 1 ); +end_of_job: return ( 1 ); } /* --- end-of-function type_bytemap() --- */ @@ -3706,13 +3889,13 @@ * Notes: * ======================================================================= */ /* --- entry point --- */ -int xbitmap_raster ( raster *rp, FILE *fp ) +FUNCSCOPE int xbitmap_raster ( raster *rp, FILE *fp ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ char *title = "image"; /* dummy title */ -int hex_bitmap(); /* dump bitmap as hex bytes */ +/*int hex_bitmap();*/ /* dump bitmap as hex bytes */ /* -------------------------------------------------------------------------- emit text to display mime xbitmap representation of rp->bitmap image -------------------------------------------------------------------------- */ @@ -3761,7 +3944,7 @@ * by .pbm or .pgm depending on ptype. * ======================================================================= */ /* --- entry point --- */ -int type_pbmpgm ( raster *rp, int ptype, char *file ) +FUNCSCOPE int type_pbmpgm ( raster *rp, int ptype, char *file ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -3878,6 +4061,126 @@ /* ========================================================================== + * Function: read_pbm ( fp, sf ) + * Purpose: read already-opened file (or pipe) containing pbm, + * and return subraster corresponding to its bitmap image + * -------------------------------------------------------------------------- + * Arguments: fp (I) FILE *ptr to already-opened file or pipe + * (the latter for \mathtex{} and maybe others) + * sf (I) double containing "shrink factor" .01image raster in subraster */ +raster *ssrp=NULL /*, *imgsupsamp()*/; /* supersampled/shrunk rp */ +/*int delete_subraster(),*/ /* in case of problem/error */ +/* delete_raster();*/ /* in case we shrink/supersample rp */ +unsigned char *pixels = NULL; /* pixels returned in pbm image */ +char fline[8192], /* fgets(fline,8190,fp) buffer */ + *lineptr=NULL, *endptr=NULL; /* strtol ptr to 1st char after num*/ +char *magicnumber = "P1"; /* filetype identification */ +int gotmagic = 0; /* set true when magicnumber found */ +int ncols=0, nrows=0, /* image width,height from wget */ + jcol=0, irow=0, /* col~width, row~height indexes */ + ipixel=0, npixels=0, /* pixel index, npixels=ncols*nrows */ + pixval=0; /* pixval=strtol() from pipeline */ +int pixsz = 1, /* bitmap in returned raster's pixmap*/ + ssgrayscale = 2; /*256;*/ /* grayscale for imgsupsamp() */ +/* --- + * check input + * -------------- */ +if ( fp == NULL ) goto end_of_job; +/* --- + * read the first few lines to get width, height + * ------------------------------------------------ */ +while ( 1 ) { /* read lines (shouldn't find eof) */ + if ( fgets(fline,8190,fp) == NULL ) goto end_of_job; /* premature eof */ + if ( gotmagic ) { /* next line has "width height" */ + char *p = strchr(fline,(int)('#')); /* first look for comment char */ + if ( p != (char *)NULL ) *p = '\000'; /* and terminate line at comment */ + p = fline; skipwhite(p); /* now find first non-whitespace char*/ + if ( *p == '\000' ) continue; /* and skip empty lines */ + ncols = (int)strtol(fline,&endptr,10); /* convert width */ + nrows = (int)strtol(endptr,NULL,10); /* and convert height */ + break; } /* and we're ready to pixelize... */ + if ( strstr(fline,magicnumber) != NULL ) /* found magicnumber */ + gotmagic = 1; /* set flag */ + } /* --- end-of-while(1) --- */ +/* --- + * allocate pixels and xlate remainder of pipe + * ---------------------------------------------- */ +/* --- allocate pixels --- */ +npixels = nrows*ncols; /* that's what we need */ +if ( npixels<1 || npixels>9999999 ) goto end_of_job; /* sanity check */ +if ( (pixels = (unsigned char *)malloc(npixels)) /*ask for it if not insane*/ +== NULL ) goto end_of_job; /* and quit if request denied */ +/* --- xlate remainder of pipe --- */ +ipixel = 0; /* start with first pixel */ +while ( 1 ) { /* read lines (shouldn't find eof) */ + /* --- read next line --- */ + if ( fgets(fline,511,fp) == NULL ) { /* premature eof */ + free(pixels); pixels=NULL; /* failed to xlate completely */ + goto end_of_job; } /* free, reset return ptr, quit */ + /* --- xlate 0's and 1's on the line --- */ + lineptr = fline; /* start at beginning of line */ + while ( ipixel < npixels ) { + while ( *lineptr != '\000' ) /* skip leading non-digits */ + if ( isdigit(*lineptr) ) break; /* done at first digit */ + else lineptr++; /* or skip leading non-digit */ + if ( *lineptr == '\000' ) break; /* no more numbers on this line */ + pixval = (int)strtol(lineptr,&endptr,10); /*convert next num to 0 or 1*/ + pixels[ipixel++] = (unsigned char)pixval; /*i.e., let's hope it's 0 or 1*/ + lineptr = endptr; /* move on to next number */ + } /* --- end-of-while(ipixels= npixels ) break; /* pixelized image complete */ + } /* --- end-of-while(1) --- */ +/* --- + * create subraster for pixelized image + * --------------------------------------- */ +if ( (sp = new_subraster(ncols,nrows,pixsz)) /* allocate/init subraster */ +== NULL ) goto end_of_job; /* or quit if failed */ +if ( (rp = sp->image) /* image raster in new subraster */ +== NULL ) { /* apparently some internal problem */ + delete_subraster(sp); /* free "buggy" subraster */ + sp=NULL; goto end_of_job; } /* return error to caller */ +sp->type = IMAGERASTER; /* set raster type as image */ +sp->baseline = (nrows+1)/2; /* default baseline at image center */ +sp->toprow = sp->leftcol = 0; /* init/unused */ +ipixel = 0; /* start with first pixel */ +/* --- copy 0/1 pixels from pbm to sp->image raster --- */ +for ( irow=0; irow0.01 && sf<0.99 ) { /* valid sf means shrink requested */ + if ( (ssrp = imgsupsamp(rp,sf,ssgrayscale)) /* supersample rp to shrink it */ + != NULL ) { /* succeeded, so replace rp with ssrp*/ + /* printf("read_pbm> imgsupsamp() succeeded\n"); */ + sp->image = ssrp; /* replaced rp with ssrp */ + sp->baseline = (int)( (sf*((double)nrows)+1.0)/2.0 + 0.5 ); + delete_raster(rp); } /* free no-longer-needed rp */ + /* else printf("read_pbm> imgsupsamp() failed\n"); */ + } /* --- end-of-if(sf>.01&&sf<.99) --- */ +end_of_job: + if ( pixels != NULL ) free((void *)pixels); /* raster's pixmap has image */ + return ( sp ); /*back to caller with pbm subraster*/ +} /* --- end-of-function read_pbm() --- */ + + +/* ========================================================================== * Function: cstruct_chardef ( cp, fp, col1 ) * Purpose: Emit a C struct of cp on fp, starting in col1. * -------------------------------------------------------------------------- @@ -3894,14 +4197,14 @@ * Notes: * ======================================================================= */ /* --- entry point --- */ -int cstruct_chardef ( chardef *cp, FILE *fp, int col1 ) +FUNCSCOPE int cstruct_chardef ( chardef *cp, FILE *fp, int col1 ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ char field[64]; /* field within output line */ -int cstruct_raster(), /* emit a raster */ - emit_string(); /* emit a string and comment */ +/*int cstruct_raster(),*/ /* emit a raster */ +/* emit_string();*/ /* emit a string and comment */ /* ------------------------------------------------------------------------- emit charnum, location, name / hirow, hicol, lorow, locol -------------------------------------------------------------------------- */ @@ -3939,15 +4242,15 @@ * Notes: * ======================================================================= */ /* --- entry point --- */ -int cstruct_raster ( raster *rp, FILE *fp, int col1 ) +FUNCSCOPE int cstruct_raster ( raster *rp, FILE *fp, int col1 ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ char field[64]; /* field within output line */ char typecast[64] = "(pixbyte *)"; /* type cast for pixmap string */ -int hex_bitmap(); /* to emit raster bitmap */ -int emit_string(); /* emit a string and comment */ +/*int hex_bitmap();*/ /* to emit raster bitmap */ +/*int emit_string();*/ /* emit a string and comment */ /* ------------------------------------------------------------------------- emit width and height -------------------------------------------------------------------------- */ @@ -3985,7 +4288,7 @@ * Notes: * ======================================================================= */ /* --- entry point --- */ -int hex_bitmap ( raster *rp, FILE *fp, int col1, int isstr ) +FUNCSCOPE int hex_bitmap ( raster *rp, FILE *fp, int col1, int isstr ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -4051,7 +4354,7 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -int emit_string ( FILE *fp, int col1, char *string, char *comment ) +FUNCSCOPE int emit_string ( FILE *fp, int col1, char *string, char *comment ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -4108,12 +4411,12 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -raster *gftobitmap ( raster *gf ) +FUNCSCOPE raster *gftobitmap ( raster *gf ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -raster *new_raster(), *rp=NULL; /* image raster retuned to caller */ +raster /**new_raster(),*/ *rp=NULL; /* image raster retuned to caller */ int width=0, height=0, totbits=0; /* gf->width, gf->height, #bits */ int format=0, icount=0, ncounts=0, /*.gf format, count index, #counts*/ ibit=0, bitval=0; /* bitmap index, bit value */ @@ -4194,7 +4497,7 @@ * shorter table matches, i.e., in this case \ep * ======================================================================= */ /* --- entry point --- */ -mathchardef *get_symdef ( char *symbol ) +FUNCSCOPE mathchardef *get_symdef ( char *symbol ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -4315,7 +4618,7 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -int get_ligature ( char *expression, int family ) +FUNCSCOPE int get_ligature ( char *expression, int family ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -4371,7 +4674,7 @@ * is returned instead. * ======================================================================= */ /* --- entry point --- */ -chardef *get_chardef ( mathchardef *symdef, int size ) +FUNCSCOPE chardef *get_chardef ( mathchardef *symdef, int size ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -4482,17 +4785,19 @@ * Notes: o just wraps a subraster envelope around get_chardef() * ======================================================================= */ /* --- entry point --- */ -subraster *get_charsubraster ( mathchardef *symdef, int size ) +FUNCSCOPE subraster *get_charsubraster ( mathchardef *symdef, int size ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -chardef *get_chardef(), *gfdata=NULL; /* chardef struct for symdef,size */ -int get_baseline(); /* baseline of gfdata */ -subraster *new_subraster(), *sp=NULL; /* subraster containing gfdata */ -raster *bitmaprp=NULL, *gftobitmap(); /* convert .gf-format to bitmap */ -int delete_subraster(); /* in case gftobitmap() fails */ -int aasupsamp(), /*antialias char with supersampling*/ +chardef /**get_chardef(),*/ *gfdata=NULL; /* chardef struct for symdef,size */ +/*int get_baseline();*/ /* baseline of gfdata */ +subraster /**new_subraster(),*/ *sp=NULL; /* subraster containing gfdata */ +raster *bitmaprp=NULL /*, *gftobitmap()*/; /* convert .gf-format to bitmap */ +raster *rotp=NULL /*, *rastrot3d()*/; /* rotate character if utheta>0 */ +/*int delete_subraster();*/ /* in case gftobitmap() fails */ +/*int delete_raster();*/ /* in case IMAGERASTER replaced */ +int /*aasupsamp(),*/ /*antialias char with supersampling*/ grayscale=256; /* aasupersamp() parameters */ /* ------------------------------------------------------------------------- look up chardef for symdef at size, and embed data (gfdata) in subraster @@ -4533,6 +4838,13 @@ sp->baseline /= shrinkfactor; /* rescale baseline */ sp->type = IMAGERASTER; } /* character is an image raster */ } /* --- end-of-if(issupersampling) --- */ + if ( absval(utheta) > 1.0e-6 ) { /* character 3d-rotation wanted */ + rotp = rastrot3d(sp->image,&uaxis,utheta); /* rotate image around uaxis */ + if ( sp->type != CHARASTER ) /* not a static character raster */ + delete_raster(sp->image); /* so free currently allocated image */ + sp->image = rotp; /* and replace it with rotated image */ + sp->type = IMAGERASTER; /* allocated raster will be freed */ + } /* --- end-of-if(absval(utheta)>1.0e-6) --- */ } /* --- end-of-if(sp!=NULL) --- */ end_of_job: if ( msgfp!=NULL && msglevel>=999 ) @@ -4559,13 +4871,13 @@ * Notes: o just combines get_symdef() and get_charsubraster() * ======================================================================= */ /* --- entry point --- */ -subraster *get_symsubraster ( char *symbol, int size ) +FUNCSCOPE subraster *get_symsubraster ( char *symbol, int size ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -subraster *sp=NULL, *get_charsubraster(); /* subraster containing gfdata */ -mathchardef *symdef=NULL, *get_symdef(); /* mathchardef lookup for symbol */ +subraster *sp=NULL /*, *get_charsubraster()*/; /*subraster containing gfdata*/ +mathchardef *symdef=NULL /*, *get_symdef()*/;/*mathchardef lookup for symbol*/ /* ------------------------------------------------------------------------- look up mathchardef for symbol -------------------------------------------------------------------------- */ @@ -4597,7 +4909,7 @@ * and everything else descends below the baseline. * ======================================================================= */ /* --- entry point --- */ -int get_baseline ( chardef *gfdata ) +FUNCSCOPE int get_baseline ( chardef *gfdata ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -4635,15 +4947,15 @@ * but the best-fit width is searched for (rather than height) * ======================================================================= */ /* --- entry point --- */ -subraster *get_delim ( char *symbol, int height, int family ) +FUNCSCOPE subraster *get_delim ( char *symbol, int height, int family ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ mathchardef *symdefs = symtable; /* table of mathchardefs */ -subraster *get_charsubraster(), *sp=(subraster *)NULL; /* best match char */ -subraster *make_delim(); /* construct delim if can't find it*/ -chardef *get_chardef(), *gfdata=NULL; /* get chardef struct for a symdef */ +subraster /**get_charsubraster(),*/ *sp=(subraster *)NULL; /*best match char*/ +/*subraster *make_delim();*/ /* construct delim if can't find it*/ +chardef /**get_chardef(),*/ *gfdata=NULL; /*get chardef struct for a symdef*/ char lcsymbol[256], *symptr, /* lowercase symbol for comparison */ *unescsymbol = symbol; /* unescaped symbol */ int symlen = (symbol==NULL?0:strlen(symbol)), /* #chars in caller's sym*/ @@ -4764,20 +5076,20 @@ * and interpreted as width (rather than height) * ======================================================================= */ /* --- entry point --- */ -subraster *make_delim ( char *symbol, int height ) +FUNCSCOPE subraster *make_delim ( char *symbol, int height ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -subraster *sp = (subraster *)NULL, /* subraster returned to caller */ - *new_subraster(); /* allocate subraster */ -subraster *get_symsubraster(), /* look up delim pieces in cmex10 */ +subraster *sp = (subraster *)NULL /* subraster returned to caller */ + /*,*new_subraster()*/; /* allocate subraster */ +subraster /**get_symsubraster(),*/ /* look up delim pieces in cmex10 */ *symtop=NULL, *symbot=NULL, *symmid=NULL, *symbar=NULL, /* pieces */ - *topsym=NULL, *botsym=NULL, *midsym=NULL, *barsym=NULL, /* +filler */ - *rastack(), *rastcat(); /* stack pieces, concat filler */ + *topsym=NULL, *botsym=NULL, *midsym=NULL, *barsym=NULL /* +filler */ + /*,*rastack(), *rastcat()*/; /* stack pieces, concat filler */ int isdrawparen = 0; /*1=draw paren, 0=build from pieces*/ raster *rasp = (raster *)NULL; /* sp->image */ -int isokay=0, delete_subraster(); /* set true if delimiter drawn ok */ +int isokay=0 /*, delete_subraster()*/; /*set true if delimiter drawn ok*/ int pixsz = 1, /* pixels are one bit each */ symsize = 0; /* size arg for get_symsubraster() */ int thickness = 1; /* drawn lines are one pixel thick */ @@ -4788,10 +5100,10 @@ *lp2=NULL, *rp2=NULL, /* synonym for lp,rp */ *lp3=NULL, *rp3=NULL, /* synonym for lp,rp */ *lp4=NULL, *rp4=NULL; /* synonym for lp,rp */ -int circle_raster(), /* ellipse for ()'s in sp->image */ - rule_rsater(), /* horizontal or vertical lines */ - line_raster(); /* line between two points */ -subraster *uparrow_subraster(); /* up/down arrows */ +/*int circle_raster(),*/ /* ellipse for ()'s in sp->image */ +/* rule_rsater(),*/ /* horizontal or vertical lines */ +/* line_raster();*/ /* line between two points */ +/*subraster *uparrow_subraster();*/ /* up/down arrows */ int isprealloc = 1; /*pre-alloc subraster, except arrow*/ int oldsmashmargin = smashmargin, /* save original smashmargin */ wasnocatspace = isnocatspace; /* save original isnocatspace */ @@ -5130,7 +5442,7 @@ * returns any whitespace character as the next character. * ======================================================================= */ /* --- entry point --- */ -char *texchar ( char *expression, char *chartoken ) +FUNCSCOPE char *texchar ( char *expression, char *chartoken ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -5255,17 +5567,17 @@ * And it also acts as a LaTeX \left. and matches any \right) * ======================================================================= */ /* --- entry point --- */ -char *texsubexpr ( char *expression, char *subexpr, int maxsubsz, - char *left, char *right, int isescape, int isdelim ) +FUNCSCOPE char *texsubexpr ( char *expression, char *subexpr, int maxsubsz, + char *left, char *right, int isescape, int isdelim ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texchar(); /*next char (or \sequence) from expression*/ +/*char *texchar();*/ /*next char (or \sequence) from expression*/ char *leftptr, leftdelim[256] = "(\000", /* left( found in expression */ rightdelim[256] = ")\000"; /* and matching right) */ char *origexpression=expression, *origsubexpr=subexpr; /*original inputs*/ -char *strtexchr(), *texleft(); /* check for \left, and get it */ +/*char *strtexchr(), *texleft();*/ /* check for \left, and get it */ int gotescape = 0, /* true if leading char of expression is \ */ prevescape = 0; /* while parsing, true if preceding char \ */ int isbrace(); /* check for left,right braces */ @@ -5406,14 +5718,14 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -char *texleft ( char *expression, char *subexpr, int maxsubsz, - char *ldelim, char *rdelim ) +FUNCSCOPE char *texleft ( char *expression, char *subexpr, int maxsubsz, + char *ldelim, char *rdelim ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texchar(), /* get delims after \left,\right */ - *strtexchr(), *pright=expression; /* locate matching \right */ +char /**texchar(),*/ /* get delims after \left,\right */ + /**strtexchr(),*/ *pright=expression; /* locate matching \right */ static char left[16]="\\left", right[16]="\\right"; /* tex delimiters */ int sublen = 0; /* #chars between \left...\right */ /* ------------------------------------------------------------------------- @@ -5508,13 +5820,13 @@ * i.e., totally ignoring all but the last "script" encountered * ======================================================================= */ /* --- entry point --- */ -char *texscripts ( char *expression, char *subscript, - char *superscript, int which ) +FUNCSCOPE char *texscripts ( char *expression, char *subscript, + char *superscript, int which ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texsubexpr(); /* next subexpression from expression */ +/*char *texsubexpr();*/ /* next subexpression from expression */ int gotsub=0, gotsup=0; /* check that we don't eat, e.g., x_1_2 */ /* ------------------------------------------------------------------------- init "scripts" @@ -5575,7 +5887,7 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -int isbrace ( char *expression, char *braces, int isescape ) +FUNCSCOPE int isbrace ( char *expression, char *braces, int isescape ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -5639,7 +5951,7 @@ * ptr will have "flushed" and preamble parameters after size * ======================================================================= */ /* --- entry point --- */ -char *preamble ( char *expression, int *size, char *subexpr ) +FUNCSCOPE char *preamble ( char *expression, int *size, char *subexpr ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -5744,18 +6056,18 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -char *mimeprep ( char *expression ) +FUNCSCOPE char *mimeprep ( char *expression ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ char *expptr=expression, /* ptr within expression */ *tokptr=NULL, /*ptr to token found in expression*/ - *texsubexpr(), argval[8192]; /*parse for macro args after token*/ -char *strchange(); /* change leading chars of string */ -int strreplace(); /* replace nnn with actual num, etc*/ -char *strwstr(); /*use strwstr() instead of strstr()*/ -char *findbraces(); /*find left { and right } for \atop*/ + /**texsubexpr(),*/ argval[8192]; /*parse for macro args after token*/ +/*char *strchange();*/ /* change leading chars of string */ +/*int strreplace();*/ /* replace nnn with actual num, etc*/ +/*char *strwstr();*/ /*use strwstr() instead of strstr()*/ +/*char *findbraces();*/ /*find left { and right } for \atop*/ int idelim=0, /* left- or right-index */ isymbol=0; /*symbols[],rightcomment[],etc index*/ int xlateleft = 0; /* true to xlate \left and \right */ @@ -5862,6 +6174,8 @@ { "\\aangle","26", "{\\boxaccent{#1}{#2}}" }, { "\\actuarial","2 ","{#1\\boxaccent{6}{#2}}" }, /*comprehensive sym list*/ { "\\boxaccent","2", "{\\fbox[,#1]{#2}}" }, + { "\\password", "1", "\000" }, + { "\\comment", "1", "\000" }, /* -------------------------------------------- html char termchar LaTeX equivalent... -------------------------------------------- */ @@ -5912,15 +6226,18 @@ { "\\AA", NULL, "{\\rm~A\\limits^{-1$o}}" }, { "\\aa", NULL, "{\\rm~a\\limits^{-1$o}}" }, { "\\bmod", NULL, "{\\hspace2{\\rm~mod}\\hspace2}" }, + { "\\mod", NULL, "{\\hspace2{\\rm~mod}\\hspace2}" }, { "\\vdots", NULL, "{\\raisebox3{\\rotatebox{90}{\\ldots}}}" }, { "\\dots", NULL, "{\\cdots}" }, { "\\cdots", NULL, "{\\raisebox3{\\ldots}}" }, { "\\ldots", NULL, "{\\fs4.\\hspace1.\\hspace1.}" }, { "\\ddots", NULL, "{\\fs4\\raisebox8.\\hspace1\\raisebox4." "\\hspace1\\raisebox0.}"}, + { "\\cong", NULL, "{\\raisebox{-4}{\\approx\\atop-}}" }, { "\\notin", NULL, "{\\not\\in}" }, { "\\neq", NULL, "{\\not=}" }, { "\\ne", NULL, "{\\not=}" }, + { "\\pm", NULL, "{\\math\\plusminus}" }, /* don't have \bf\pm */ { "\\mapsto", NULL, "{\\rule[fs/2]{1}{5+fs}\\hspace{-99}\\to}" }, { "\\hbar", NULL, "{\\compose~h{{\\fs{-1}-\\atop\\vspace3}}}" }, { "\\angle", NULL, "{\\compose{\\hspace{3}\\lt}{\\circle(10,15;-80,80)}}"}, @@ -6188,6 +6505,10 @@ /* --- (recursively) call mimeprep() to prep the argument --- */ if ( !isempty(argval) ) /* have an argument */ mimeprep(argval); /* so (recursively) prep it */ + /* --- "specials" (e.g., \password) check --- */ + if ( strstr(htmlsym,"password") != NULL ) { /* have \password{} */ + argval[64] = '\000'; /* make sure it's not too long */ + strcpy(password,argval); } /* save it for http_referer checks */ /* --- replace #`iarg` in macro with argval --- */ sprintf(argsignal,"#%d",iarg); /* #1...#9 signals argument */ while ( (argsigptr=strstr(argval,argsignal)) != NULL ) /* #1...#9 */ @@ -6311,7 +6632,7 @@ * (i.e., we don't do a realloc) * ======================================================================= */ /* --- entry point --- */ -char *strchange ( int nfirst, char *from, char *to ) +FUNCSCOPE char *strchange ( int nfirst, char *from, char *to ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -6356,7 +6677,7 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -int strreplace ( char *string, char *from, char *to, int nreplace ) +FUNCSCOPE int strreplace ( char *string, char *from, char *to, int nreplace ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -6364,8 +6685,8 @@ int fromlen = (from==NULL?0:strlen(from)), /* #chars to be replaced */ tolen = (to==NULL?0:strlen(to)); /* #chars in replacement string */ char *pfrom = (char *)NULL, /*ptr to 1st char of from in string*/ - *pstring = string, /*ptr past previously replaced from*/ - *strchange(); /* change 'from' to 'to' */ + *pstring = string /*ptr past previously replaced from*/ + /*,*strchange()*/; /* change 'from' to 'to' */ int nreps = 0; /* #replacements returned to caller*/ /* ------------------------------------------------------------------------- repace occurrences of 'from' in string to 'to' @@ -6438,7 +6759,7 @@ * by "virtual blanks". * ======================================================================= */ /* --- entry point --- */ -char *strwstr ( char *string, char *substr, char *white, int *sublen ) +FUNCSCOPE char *strwstr(char *string, char *substr, char *white, int *sublen) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -6553,13 +6874,13 @@ * with output from the preceding call. * ======================================================================= */ /* --- entry point --- */ -char *strdetex ( char *s, int mode ) +FUNCSCOPE char *strdetex ( char *s, int mode ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ static char sbuff[4096]; /* copy of s with no math chars */ -int strreplace(); /* replace _ with -, etc */ +/*int strreplace();*/ /* replace _ with -, etc */ /* ------------------------------------------------------------------------- Make a clean copy of s -------------------------------------------------------------------------- */ @@ -6605,7 +6926,7 @@ * Notes: o texchr should contain its leading \, e.g., "\\left" * ======================================================================= */ /* --- entry point --- */ -char *strtexchr ( char *string, char *texchr ) +FUNCSCOPE char *strtexchr ( char *string, char *texchr ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -6651,7 +6972,7 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -char *findbraces ( char *expression, char *command ) +FUNCSCOPE char *findbraces ( char *expression, char *command ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -6697,6 +7018,7 @@ } /* --- end-of-function findbraces() --- */ +#if 0 /* --- enhanced version from mathtex below --- */ /* ========================================================================== * Function: strpspn ( char *s, char *reject, char *segment ) * Purpose: finds the initial segment of s containing no chars @@ -6729,7 +7051,7 @@ * o leading/trailing whitespace is trimmed from returned segment * ======================================================================= */ /* --- entry point --- */ -char *strpspn ( char *s, char *reject, char *segment ) +FUNCSCOPE char *strpspn ( char *s, char *reject, char *segment ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -6765,6 +7087,7 @@ trimwhite(segment); } /* trim leading/trailing whitespace*/ return ( ps ); /* back to caller */ } /* --- end-of-function strpspn() --- */ +#endif /* ========================================================================== @@ -6788,7 +7111,7 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -int isstrstr ( char *string, char *snippets, int iscase ) +FUNCSCOPE int isstrstr ( char *string, char *snippets, int iscase ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -6849,7 +7172,7 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -int isnumeric ( char *s ) +FUNCSCOPE int isnumeric ( char *s ) { /* ------------------------------------------------------------------------- determine whether s is an integer @@ -6891,7 +7214,7 @@ * (index?a:b:c:etc) which must be enclosed in parentheses. * ======================================================================= */ /* --- entry point --- */ -int evalterm ( STORE *store, char *term ) +FUNCSCOPE int evalterm ( STORE *store, char *term ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -7011,7 +7334,7 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -int getstore ( STORE *store, char *identifier ) +FUNCSCOPE int getstore ( STORE *store, char *identifier ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -7041,6 +7364,385 @@ /* ========================================================================== + * Function: getdirective(string, directive, iscase, isvalid, nargs, args) + * Purpose: Locates the first \directive{arg1}...{nargs} in string, + * returns arg1...nargs in args[], + * and removes \directive and its args from string. + * -------------------------------------------------------------------------- + * Arguments: string (I/0) char * to null-terminated string from which + * the first occurrence of \directive will be + * interpreted and removed + * directive (I) char * to null-terminated string containing + * the \directive to be interpreted in string + * iscase (I) int containing 1 if match of \directive + * in string should be case-sensitive, + * or 0 if match is case-insensitive. + * isvalid (I) int containing validity check option: + * 0=no checks, 1=must be numeric + * nargs (I) int containing (maximum) number of + * {args} following \directive, or 0 if none. + * args (O) void * interpreted as (char *) if nargs=1 + * to return the one and only arg, + * or interpreted as (char **) if nargs>1 + * to array of returned arg strings + * -------------------------------------------------------------------------- + * Returns: ( char * ) ptr to first char after removed \directive, or + * NULL if \directive not found, or any error. + * -------------------------------------------------------------------------- + * Notes: o If optional [arg]'s are found, they're stored in the global + * optionalargs[] buffer, and the noptional counter is bumped. + * o set global argformat's decimal digits for each arg, + * e.g., 1357... means 1 for 1st arg, 3 for 2nd, 5 for 3rd, etc. + * 0 for an arg is the default format (i.e., argformat=0), + * and means it's formatted as a LaTeX {arg} or [arg]. + * 1 for an arg means arg terminated by first non-alpha char + * 2 means arg terminated by { (e.g., as for /def) + * 8 means arg terminated by first whitespace char + * ======================================================================= */ +/* --- entry point --- */ +FUNCSCOPE char *getdirective ( char *string, char *directive, + int iscase, int isvalid, int nargs, void *args ) +{ +/* ------------------------------------------------------------------------- +Allocations and Declarations +-------------------------------------------------------------------------- */ +int iarg = (-1); /* init to signal error */ +char *pfirst = NULL, /* ptr to 1st char of directive */ + *plast = NULL, /* ptr past last char of last arg */ + *plbrace=NULL, *prbrace=NULL; /* ptr to left,right brace of arg */ +int fldlen = 0; /* #chars between { and } delims */ +char argfld[512]; /* {arg} characters */ +int nfmt=0, /*isnegfmt=0,*/ /* {arg} format */ + argfmt[9]={0,0,0,0,0,0,0,0,0}; /* argformat digits */ +int gotargs = (args==NULL?0:1); /* true if args array supplied */ +int isdalpha = 1; /* true if directive ends with alpha*/ +/*char *strpspn(char *s,char *reject,char *segment);*/ /*non-() not in rej*/ +#if 0 /* --- declared globally above --- */ +/* --- + * mathtex global variables (not used by mimetex) + * ------------------------------------------------- */ +int noptional = 0; +char optionalargs[10][32]; +int argformat = 0; +int optionalpos = 0; +#endif +/* ------------------------------------------------------------------------- +Find first \directive in string +-------------------------------------------------------------------------- */ +noptional = 0; /* no optional [args] yet */ +for ( iarg=0; iarg<8; iarg++ ) /* for each one... */ + *optionalargs[iarg] = '\000'; /* re-init optional [arg] buffer */ +if ( argformat != 0 ) { /* have argformat */ + int myfmt = argformat; /* local copy */ + if ( myfmt < 0 ) { /*isnegfmt=1;*/ myfmt=(-myfmt); } /* check sign */ + while ( myfmt>0 && nfmt<9 ) { /* have more format digits */ + argfmt[nfmt] = myfmt%10; /* store low-order decimal digit */ + myfmt /= 10; /* and shift it out */ + nfmt++; } /* count another format digit */ + } /* --- end-of-if(argformat!=0) --- */ +if ( isempty(directive) ) goto end_of_job; /* no input \directive given */ +if ( !isalpha((int)(directive[strlen(directive)-1])) )isdalpha=0;/*not alpha*/ +pfirst = string; /* start at beginning of string */ +while ( 1 ) { /* until we find \directive */ + if ( !isempty(pfirst) ) /* still have string from caller */ + pfirst = /* ptr to 1st char of directive */ + (iscase>0? strstr(pfirst,directive): /* case-sensistive match */ + strcasestr(pfirst,directive)); /* case-insensistive match */ + if ( isempty(pfirst) ) { /* \directive not found in string */ + pfirst = NULL; /* signal \directive not found */ + goto end_of_job; } /* quit, signalling error to caller*/ + plast = pfirst + strlen(directive); /*ptr to fist char past directive*/ + if ( !isdalpha || !isalpha((int)(*plast)) ) break; /* found \directive */ + pfirst = plast; /* keep looking */ + plast = NULL; /* reset plast */ + } /* --- end-of-while(1) --- */ +if ( nargs < 0 ) { /* optional [arg] may be present */ + nargs = -nargs; /* flip sign back to positive */ + /*noptional = 1;*/ } /* and set optional flag */ +/* ------------------------------------------------------------------------- +Get arguments +-------------------------------------------------------------------------- */ +iarg = 0; /* no args yet */ +if ( nargs > 0 ) /* \directive has {args} */ + while ( iarg < nargs+noptional ) { /* get each arg */ + int karg = iarg-noptional; /* non-optional arg index */ + int kfmt = (nfmt<=karg?0:argfmt[nfmt-karg-1]); /* arg format digit */ + /* --- find left { and right } arg delimiters --- */ + plbrace = plast; /*ptr to fist char past previous arg*/ + skipwhite(plbrace); /* push it to first non-white char */ + if ( isempty(plbrace) ) break; /* reached end-of-string */ + /* --- check LaTeX for single-char arg or {arg} or optional [arg] --- */ + if ( kfmt == 0 ) { /* interpret LaTeX {arg} format */ + if ( !isthischar(*plbrace,(iarg==optionalpos+noptional?"{[":"{")) ) { + /* --- single char argument --- */ + plast = plbrace + 1; /* first char after single-char arg*/ + argfld[0] = *plbrace; /* arg field is this one char */ + argfld[1] = '\000'; } /* null-terminate field */ + else { /* have {arg} or optional [arg] */ + /* note: to use for validation, need robust {} match like strpspn() */ + if ( (prbrace = strchr(plbrace,(*plbrace=='{'?'}':']'))) /*right }or]*/ + == NULL ) break; /*and no more args if no right brace*/ + if ( 1 ) /* true to use strpspn() */ + prbrace = strpspn(plbrace,NULL,NULL); /* push to matching } or ] */ + plast = prbrace + 1; /* first char after right brace */ + /* --- extract arg field between { and } delimiters --- */ + fldlen = (int)(prbrace-plbrace) - 1; /* #chars between { and } delims*/ + if ( fldlen >= 256 ) fldlen=255; /* don't overflow argfld[] buffer */ + if ( fldlen > 0 ) /* have chars in field */ + memcpy(argfld,plbrace+1,fldlen); /*copy field chars to local buffer*/ + argfld[fldlen] = '\000'; /* and null-terminate field */ + trimwhite(argfld); /* trim whitespace from argfld */ + } /* --- end-of-if/else(!isthischar(*plbrace,...)) --- */ + } /* --- end-of-if(kfmt==0) --- */ + /* --- check plain TeX for arg terminated by whitespace --- */ + if ( kfmt != 0 ) { /* interpret plain TeX arg format */ + char *parg = NULL; /* ptr into arg, used as per kfmt */ + plast = plbrace; /* start at first char of arg */ + if ( *plast == '\\' ) plast++; /* skip leading \command backslash */ + /* --- interpret arg according to its format --- */ + switch ( kfmt ) { + case 1: + default: skipcommand(plast); break; /* push ptr to non-alpha char */ + case 2: parg = strchr(plast,'{'); /* next arg always starts with { */ + if ( parg != NULL ) plast=parg; else plast++; /* up to { or 1 char */ + break; + case 8: findwhite(plast); break; /*ptr to whitespace after last char*/ + } /* --- end-of-switch(kfmt) --- */ + /* --- extract arg field --- */ + fldlen = (int)(plast-plbrace); /* #chars between in field */ + if ( fldlen >= 256 ) fldlen=255; /* don't overflow argfld[] buffer */ + if ( fldlen > 0 ) /* have chars in field */ + memcpy(argfld,plbrace,fldlen); /*copy field chars to local buffer*/ + argfld[fldlen] = '\000'; /* and null-terminate field */ + if ( 1 ) { trimwhite(argfld); } /* trim whitespace from argfld */ + } /* --- end-of-if(kfmt!=0) --- */ + if ( isvalid != 0 ) { /* argfld[] validity check desired */ + if ( isvalid == 1 ) { /* numeric check wanted */ + int validlen = strspn(argfld," +-.0123456789"); /*very simple check*/ + argfld[validlen] = '\000'; } /* truncate invalid chars */ + } /* --- end-of-if(isvalid!=0) --- */ + /* --- store argument field in caller's array --- */ + if ( kfmt==0 && *plbrace=='[' ) { /*store [arg] as optionalarg instead*/ + if ( noptional < 8 ) { /* don't overflow our buffer */ + strninit(optionalargs[noptional],argfld,254); } /*copy to optionalarg*/ + noptional++; } /* count another optional [arg] */ + else /*{args} returned in caller's array*/ + if ( gotargs ) { /*caller supplied address or array*/ + if ( nargs < 2 ) /*just one arg, so it's an address*/ + strcpy((char *)args,argfld); /* so copy arg field there */ + else { /* >1 arg, so it's a ptr array */ + char *argptr = ((char **)args)[karg]; /* arg ptr in array of ptrs */ + if ( argptr != NULL ) /* array has iarg-th address */ + strcpy(argptr,argfld); /* so copy arg field there */ + else gotargs = 0; } } /* no more addresses in array */ + /* --- completed this arg --- */ + iarg++; /* bump arg count */ + } /* --- end-of-while(iarg 0 ) /* have room in segment buffer */ + memcpy(segment+seglen,ps,copylen); } /* so copy non-reject chars */ + seglen += spanlen; ps += spanlen; /* bump to next char */ + } /* --- end-of-while(*ps!=0) --- */ +end_of_job: + if ( segment != NULL ) { /* caller gave us segment */ + if ( isempty(qreject) && !isempty(s) ) { /* no reject char */ + segment[min2(seglen,maxseg)] = *ps; seglen++; } /*closing )]} to seg*/ + segment[min2(seglen,maxseg)] = '\000'; /* null-terminate the segment */ + trimwhite(segment); } /* trim leading/trailing whitespace*/ + return ( ps ); /* back to caller */ +} /* --- end-of-function strpspn() --- */ + + +/* ========================================================================== + * Function: strqspn ( char *s, char *q, int isunescape ) + * Purpose: finds matching/closing " or ' in quoted string + * that begins with " or ', and optionally changes + * escaped quotes to unescaped quotes. + * -------------------------------------------------------------------------- + * Arguments: s (I) (char *)pointer to null-terminated string + * that begins with " or ', + * q (O) (char *)pointer returning null-terminated + * quoted token, with or without outer quotes, + * and with or without escaped inner quotes + * changed to unescaped quotes, depending + * on isunescape. + * isunescape (I) int containing 1 to change \" to " if s + * is "quoted" or change \' to ' if 'quoted', + * or containing 2 to change both \" and \' + * to unescaped quotes. Other \sequences aren't + * changed. Note that \\" emits \". + * isunescape=0 makes no changes at all. + * Note: the following not implemented yet -- + * If unescape is negative, its abs() is used, + * but outer quotes aren't included in q. + * -------------------------------------------------------------------------- + * Returns: ( char * ) pointer to matching/closing " or ' + * (or to char after quote if isunescape<0), + * or terminating '\000' if none found, + * or unchanged (same as s) if not quoted string + * -------------------------------------------------------------------------- + * Notes: o + * ======================================================================= */ +/* --- entry point --- */ +FUNCSCOPE char *strqspn ( char *s, char *q, int isunescape ) +{ +/* ------------------------------------------------------------------------- +Allocations and Declarations +-------------------------------------------------------------------------- */ +char *ps = s, *pq = q; /* current pointer into s, q */ +char quote = '\000'; /* " or ' quote character */ +int qcopy = (isunescape<0?0:1); /* true to copy outer quotes */ +int isescaped = 0; /* true to signal \escape sequence */ +int maxqlen = 2400; /* max length of returned q */ +/* ------------------------------------------------------------------------- +Initialization +-------------------------------------------------------------------------- */ +/* --- check args --- */ +if ( s == NULL ) goto end_of_job; /* no string supplied */ +skipwhite(ps); /* skip leading whitespace */ +if ( *ps == '\000' /* string exhausted */ +|| (!isthischar(*ps,"\"\'")) ) { /* or not a " or ' quoted string */ + ps = s; goto end_of_job; } /*signal error/not string to caller*/ +if ( isunescape < 0 ) isunescape = (-isunescape); /* flip positive */ +/* --- set quote character --- */ +quote = *ps; /* set quote character */ +if ( qcopy && q!=NULL ) *pq++ = quote; /* and copy it to output token */ +/* ------------------------------------------------------------------------- +span characters between quotes +-------------------------------------------------------------------------- */ +while ( *(++ps) != '\000' ) { /* end-of-string always terminates */ + /* --- process escaped chars --- */ + if ( isescaped ) { /* preceding char was \ */ + if ( *ps != '\\' ) isescaped = 0; /* reset isescaped flag unless \\ */ + if ( q != NULL ) { /* caller wants quoted token */ + if ( isunescape==0 /* don't unescape anything */ + || (isunescape==1 && *ps!=quote) /* escaped char not our quote */ + || (isunescape==2 && (!isthischar(*ps,"\"\'"))) ) /* not any quote */ + if ( --maxqlen > 0 ) /* so if there's room in token */ + *pq++ = '\\'; /*keep original \ in returned token*/ + if ( !isescaped ) /* will have to check 2nd \ in \\ */ + if ( --maxqlen > 0 ) /* if there's room in token */ + *pq++ = *ps; } /* put escaped char in token */ + continue; } /* go on to next char in string */ + /* --- check if next char escaped --- */ + if ( *ps == '\\' ) { /* found escape char */ + isescaped=1; continue; } /*set flag and process escaped char*/ + /* --- check for unescaped closing quote --- */ + if ( *ps == quote ) { /* got an unescaped quote */ + if ( qcopy && q!=NULL ) *pq++ = quote; /* copy it to output token */ + if ( 0 && !qcopy ) ps++; /* return ptr to char after quote */ + goto end_of_job; } /* back to caller */ + /* --- process other chars --- */ + if ( q != NULL ) /* caller want token returned */ + if ( --maxqlen > 0 ) /* and there's still room in token */ + *pq++ = *ps; /* put char in token */ + } /* --- end-of-while(*(++ps)!='\000') --- */ +/*ps = NULL;*/ /*pq = q;*/ /* error if no closing quote found */ +end_of_job: + if ( q != NULL ) *pq = '\000'; /* null-terminate returned token */ + return ( ps ); /* return ptr to " or ', or NULL */ +} /* --- end-of-function strqspn() --- */ + + +/* ========================================================================== * Functions: int unescape_url ( char *url, int isescape ) * char x2c ( char *what ) * Purpose: unescape_url replaces 3-character sequences %xx in url @@ -7071,11 +7773,11 @@ * o Added ^M,^F,etc to blank xlation 0n 01-Oct-06 * ======================================================================= */ /* --- entry point --- */ -int unescape_url(char *url, int isescape) { +FUNCSCOPE int unescape_url(char *url, int isescape) { int x=0,y=0,prevescape=0,gotescape=0; int xlateplus = (isplusblank==1?1:0); /* true to xlate plus to blank */ int strreplace(); /* replace + with blank, if needed */ - char x2c(); + /*char x2c();*/ static char *hex="0123456789ABCDEFabcdef"; /* --- * xlate ctrl chars to blanks @@ -7153,7 +7855,7 @@ return 0; } /* --- end-of-function unescape_url() --- */ /* --- entry point --- */ -char x2c(char *what) { +FUNCSCOPE char x2c(char *what) { char digit; digit = (what[0] >= 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0')); digit *= 16; @@ -7184,35 +7886,35 @@ * of that expression. Then do what you want with the bitmap. * ======================================================================= */ /* --- entry point --- */ -subraster *rasterize ( char *expression, int size ) +FUNCSCOPE subraster *rasterize ( char *expression, int size ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *preamble(), pretext[512]; /* process preamble, if present */ -char chartoken[MAXSUBXSZ+1], *texsubexpr(), /*get subexpression from expr*/ +char /**preamble(),*/ pretext[512]; /* process preamble, if present */ +char chartoken[MAXSUBXSZ+1], /**texsubexpr(),*/ /*get subexpr from expr*/ *subexpr = chartoken; /* token may be parenthesized expr */ -int isbrace(); /* check subexpr for braces */ -mathchardef *symdef, *get_symdef(); /*get mathchardef struct for symbol*/ -int ligdef, get_ligature(); /*get symtable[] index for ligature*/ +/*int isbrace();*/ /* check subexpr for braces */ +mathchardef *symdef /*, *get_symdef()*/; /*get mathchardef struct for symbol*/ +int ligdef /*, get_ligature()*/; /*get symtable[] index for ligature*/ int natoms=0; /* #atoms/tokens processed so far */ -int type_raster(); /* display debugging output */ -subraster *rasterize(), /* recurse */ - *rastparen(), /* handle parenthesized subexpr's */ - *rastlimits(); /* handle sub/superscripted expr's */ -subraster *rastcat(), /* concatanate atom subrasters */ - *subrastcpy(), /* copy final result if a charaster*/ - *new_subraster(); /* new subraster for isstring mode */ -subraster *get_charsubraster(), /* character subraster */ +/*int type_raster();*/ /* display debugging output */ +/*subraster *rasterize(),*/ /* recurse */ +/* *rastparen(),*/ /* handle parenthesized subexpr's */ +/* *rastlimits();*/ /* handle sub/superscripted expr's */ +/*subraster *rastcat(),*/ /* concatanate atom subrasters */ +/* *subrastcpy(),*/ /* copy final result if a charaster*/ +/* *new_subraster();*/ /* new subraster for isstring mode */ +subraster /**get_charsubraster(),*/ /* character subraster */ *sp=NULL, *prevsp=NULL, /* raster for current, prev char */ *expraster = (subraster *)NULL; /* raster returned to caller */ -int delete_subraster(); /* free everything before returning*/ +/*int delete_subraster();*/ /* free everything before returning*/ int family = fontinfo[fontnum].family; /* current font family */ int isleftscript = 0, /* true if left-hand term scripted */ wasscripted = 0, /* true if preceding token scripted*/ wasdelimscript = 0; /* true if preceding delim scripted*/ /*int pixsz = 1;*/ /*default #bits per pixel, 1=bitmap*/ -char *strdetex(); /* detex token for error message */ +/*char *strdetex();*/ /* detex token for error message */ /* --- global values saved/restored at each recursive iteration --- */ int wasstring = isstring, /* initial isstring mode flag */ wasdisplaystyle = isdisplaystyle, /*initial displaystyle mode flag*/ @@ -7459,7 +8161,7 @@ * but passed for consistency * ======================================================================= */ /* --- entry point --- */ -subraster *rastparen ( char **subexpr, int size, subraster *basesp ) +FUNCSCOPE subraster *rastparen ( char **subexpr, int size, subraster *basesp ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -7471,14 +8173,14 @@ isleftdot = 0; /* true if left paren is \left. */ char left[32], right[32]; /* parens enclosing expresion */ char noparens[MAXSUBXSZ+1]; /* get subexpr without parens */ -subraster *rasterize(), *sp=NULL; /* rasterize what's between ()'s */ +subraster /**rasterize(),*/ *sp=NULL; /* rasterize what's between ()'s */ int isheight = 1; /*true=full height, false=baseline*/ int height, /* height of rasterized noparens[] */ baseline; /* and its baseline */ int family = /*CMSYEX*/ CMEX10; /* family for paren chars */ -subraster *get_delim(), *lp=NULL, *rp=NULL; /* left and right paren chars */ -subraster *rastcat(); /* concatanate subrasters */ -int delete_subraster(); /*in case of error after allocation*/ +subraster /**get_delim(),*/ *lp=NULL, *rp=NULL; /*left and right paren chars*/ +/*subraster *rastcat();*/ /* concatanate subrasters */ +/*int delete_subraster();*/ /*in case of error after allocation*/ /* ------------------------------------------------------------------------- rasterize "interior" of expression, i.e., without enclosing parens -------------------------------------------------------------------------- */ @@ -7560,25 +8262,26 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -subraster *rastlimits ( char **expression, int size, subraster *basesp ) +FUNCSCOPE subraster *rastlimits ( char **expression, int size, + subraster *basesp ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -subraster *rastscripts(), *rastdispmath(), /*one of these will do the work*/ - *rastcat(), /* may need to concat scripts */ - *rasterize(), /* may need to construct dummy base*/ +subraster /**rastscripts(),*rastdispmath(),*/ /*one of these will do the work*/ + /**rastcat(),*/ /* may need to concat scripts */ + /**rasterize(),*/ /* may need to construct dummy base*/ *scriptsp = basesp, /* and this will become the result */ *dummybase = basesp; /* for {}_i construct a dummy base */ int isdisplay = (-1); /* set 1 for displaystyle, else 0 */ int oldsmashmargin = smashmargin; /* save original smashmargin */ -int type_raster(); /* display debugging output */ -int delete_subraster(); /* free dummybase, if necessary */ -int rastsmashcheck(); /* check if okay to smash scripts */ +/*int type_raster();*/ /* display debugging output */ +/*int delete_subraster();*/ /* free dummybase, if necessary */ +/*int rastsmashcheck();*/ /* check if okay to smash scripts */ /* --- to check for \limits or \nolimits preceding scripts --- */ -char *texchar(), *exprptr=*expression, limtoken[255]; /*check for \limits*/ +char /**texchar(),*/ *exprptr=*expression, limtoken[255]; /*check \limits*/ int toklen=0; /* strlen(limtoken) */ -mathchardef *tokdef, *get_symdef(); /* mathchardef struct for limtoken */ +mathchardef *tokdef /*, *get_symdef()*/; /* mathchardef struct for limtoken */ int class=(leftsymdef==NULL?NOVALUE:leftsymdef->class); /*base sym class*/ /* ------------------------------------------------------------------------- determine whether or not to use displaymath @@ -7688,16 +8391,17 @@ * but is called directly from rasterize(), as necessary. * ======================================================================= */ /* --- entry point --- */ -subraster *rastscripts ( char **expression, int size, subraster *basesp ) +FUNCSCOPE subraster *rastscripts ( char **expression, int size, + subraster *basesp ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texscripts(), /* parse expression for scripts */ +char /**texscripts(),*/ /* parse expression for scripts */ subscript[512], supscript[512]; /* scripts parsed from expression */ -subraster *rasterize(), *subsp=NULL, *supsp=NULL; /* rasterize scripts */ -subraster *new_subraster(), *sp=NULL, /* super- over subscript subraster */ - *rastack(); /*sets scripts in displaymath mode*/ +subraster /**rasterize(),*/ *subsp=NULL, *supsp=NULL; /* rasterize scripts */ +subraster /**new_subraster(),*/ *sp=NULL /*super- over subscript subraster*/ + /*,*rastack()*/; /*sets scripts in displaymath mode*/ raster *rp=NULL; /* image raster embedded in sp */ int height=0, width=0, baseline=0, /* height,width,baseline of sp */ subht=0, subwidth=0, subln=0, /* height,width,baseline of sub */ @@ -7712,9 +8416,9 @@ vbelow = szval+1, /*sub's top/bot below base's top/bot*/ vbottom = szval+1; /*sup's bot above (sub's below) bsln*/ /*int istweak = 1;*/ /* true to tweak script positioning */ -int rastput(); /*put scripts in constructed raster*/ -int delete_subraster(); /* free work areas */ -int rastsmashcheck(); /* check if okay to smash scripts */ +/*int rastput();*/ /*put scripts in constructed raster*/ +/*int delete_subraster();*/ /* free work areas */ +/*int rastsmashcheck();*/ /* check if okay to smash scripts */ int pixsz = 1; /*default #bits per pixel, 1=bitmap*/ /* ------------------------------------------------------------------------- Obtain subscript and/or superscript expressions, and rasterize them/it @@ -7839,17 +8543,17 @@ * Notes: o sp returned unchanged if no super/subscript(s) follow it. * ======================================================================= */ /* --- entry point --- */ -subraster *rastdispmath ( char **expression, int size, subraster *sp ) +FUNCSCOPE subraster *rastdispmath (char **expression, int size, subraster *sp) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texscripts(), /* parse expression for scripts */ +char /**texscripts(),*/ /* parse expression for scripts */ subscript[512], supscript[512]; /* scripts parsed from expression */ int issub=0, issup=0; /* true if we have sub,sup */ -subraster *rasterize(), *subsp=NULL, *supsp=NULL, /* rasterize scripts */ - *rastack(), /* stack operator with scripts */ - *new_subraster(); /* for dummy base sp, if needed */ +subraster /**rasterize(),*/ *subsp=NULL, *supsp=NULL /* rasterize scripts */ + /*,*rastack(),*/ /* stack operator with scripts */ + /**new_subraster()*/; /* for dummy base sp, if needed */ int vspace = 1; /* vertical space between scripts */ /* ------------------------------------------------------------------------- Obtain subscript and/or superscript expressions, and rasterize them/it @@ -7918,30 +8622,30 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -subraster *rastleft ( char **expression, int size, subraster *basesp, - int ildelim, int arg2, int arg3 ) +FUNCSCOPE subraster *rastleft ( char **expression, int size, subraster *basesp, + int ildelim, int arg2, int arg3 ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -subraster *rasterize(), *sp=NULL; /*rasterize between \left...\right*/ -subraster *get_delim(), *lp=NULL, *rp=NULL; /* left and right delim chars */ -subraster *rastlimits(); /*handle sub/super scripts on lp,rp*/ -subraster *rastcat(); /* concat lp||sp||rp subrasters */ +subraster /**rasterize(),*/ *sp=NULL; /*rasterize between \left...\right*/ +subraster /**get_delim(),*/ *lp=NULL, *rp=NULL; /*left and right delim chars*/ +/*subraster *rastlimits();*/ /*handle sub/super scripts on lp,rp*/ +/*subraster *rastcat();*/ /* concat lp||sp||rp subrasters */ int family=CMSYEX, /* get_delim() family */ height=0, rheight=0, /* subexpr, right delim height */ margin=(size+1), /* delim height margin over subexpr*/ opmargin=(5); /* extra margin for \int,\sum,\etc */ char /* *texleft(),*/ subexpr[MAXSUBXSZ+1];/*chars between \left...\right*/ -char *texchar(), /* get delims after \left,\right */ +char /* *texchar(),*/ /* get delims after \left,\right */ ldelim[256]=".", rdelim[256]="."; /* delims following \left,\right */ -char *strtexchr(), *pleft, *pright; /*locate \right matching our \left*/ +char /**strtexchr(),*/ *pleft, *pright;/*locate \right matching our \left*/ int isleftdot=0, isrightdot=0; /* true if \left. or \right. */ int isleftscript=0, isrightscript=0; /* true if delims are scripted */ int sublen=0; /* strlen(subexpr) */ int idelim=0; /* 1=left,2=right */ /* int gotldelim = 0; */ /* true if ildelim given by caller */ -int delete_subraster(); /* free subraster if rastleft fails*/ +/*int delete_subraster();*/ /* free subraster if rastleft fails*/ int wasdisplaystyle = isdisplaystyle; /* save current displaystyle */ int istextleft=0, istextright=0; /* true for non-displaystyle delims*/ /* --- recognized delimiters --- */ @@ -8167,8 +8871,8 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -subraster *rastright ( char **expression, int size, subraster *basesp, - int ildelim, int arg2, int arg3 ) +FUNCSCOPE subraster *rastright(char **expression, int size, subraster *basesp, + int ildelim, int arg2, int arg3) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -8206,24 +8910,24 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -subraster *rastmiddle ( char **expression, int size, subraster *basesp, - int arg1, int arg2, int arg3 ) +FUNCSCOPE subraster *rastmiddle(char **expression, int size, subraster *basesp, + int arg1, int arg2, int arg3) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -subraster *rasterize(), *sp=NULL, *subsp[32]; /*rasterize \middle subexpr's*/ +subraster /**rasterize(),*/ *sp=NULL, *subsp[32]; /*rasterize \middle subexpr*/ char *exprptr = *expression, /* local copy of ptr to expression */ - *texchar(), delim[32][132], /* delimiters following \middle's */ - *strtexchr(), /* locate \middle's */ + /**texchar(),*/ delim[32][132], /* delimiters following \middle's */ + /**strtexchr(),*/ /* locate \middle's */ subexpr[MAXSUBXSZ+1], *subptr=NULL;/*subexpression between \middle's*/ int height=0, habove=0, hbelow=0; /* height, above & below baseline */ int idelim, ndelims=0, /* \middle count (max 32) */ family = CMSYEX; /* delims from CMSY10 or CMEX10 */ -subraster *subrastcpy(), /* copy subraster */ - *rastcat(), /* concatanate subraster */ - *get_delim(); /* get rasterized delimiter */ -int delete_subraster(); /* free work area subsp[]'s at eoj */ +/*subraster *subrastcpy(),*/ /* copy subraster */ +/* *rastcat(),*/ /* concatanate subraster */ +/* *get_delim();*/ /* get rasterized delimiter */ +/*int delete_subraster();*/ /* free work area subsp[]'s at eoj */ /* ------------------------------------------------------------------------- initialization -------------------------------------------------------------------------- */ @@ -8324,13 +9028,13 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -subraster *rastflags ( char **expression, int size, subraster *basesp, - int flag, int value, int arg3 ) +FUNCSCOPE subraster *rastflags(char **expression, int size, subraster *basesp, + int flag, int value, int arg3) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texsubexpr(), /* parse expression for... */ +char /**texsubexpr(),*/ /* parse expression for... */ valuearg[1024]="NOVALUE"; /* value from expression, if needed */ int argvalue=NOVALUE, /* atoi(valuearg) */ isdelta=0, /* true if + or - precedes valuearg */ @@ -8385,6 +9089,7 @@ case ISSMASH: /* set (minimum) "smash" margin */ case ISGAMMA: /* set gamma correction */ case ISPBMPGM: /* set pbmpgm output flag and ptype*/ + case ISUTHETA: /* set utheta 3d-rotation angle */ if ( value != NOVALUE ) /* passed a fixed value to be set */ { argvalue = value; /* set given fixed int value */ dblvalue = (double)value; } /* or maybe interpreted as double */ @@ -8399,6 +9104,7 @@ switch ( flag ) { /* convert to double or int */ default: argvalue = atoi(valuearg); break; /* convert to int */ case ISGAMMA: + case ISUTHETA: dblvalue = strtod(valuearg,NULL); break; } /* or to double */ } /* --- end-of-if(*valuearg!='?') --- */ } /* --- end-of-if(value==NOVALUE) --- */ @@ -8518,6 +9224,10 @@ if ( dblvalue >= 0.0 ) /* got a value */ gammacorrection = dblvalue; /* set gamma correction */ break; + case ISUTHETA: /* set 3d-rotation angle for chars */ + if ( absval(dblvalue) >= 1.0e-6 ) /* got a value */ + utheta = dblvalue; /* set utheta */ + break; } /* --- end-of-switch() --- */ break; case PNMPARAMS: /*set fgalias,fgonly,bgalias,bgonly*/ @@ -8572,22 +9282,23 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -subraster *rastspace ( char **expression, int size, subraster *basesp, - int width, int isfill, int isheight ) +FUNCSCOPE subraster *rastspace(char **expression, int size, subraster *basesp, + int width, int isfill, int isheight) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -subraster *new_subraster(), *spacesp=NULL; /* subraster for space */ -raster *bp=NULL, *backspace_raster(); /* for negative space */ -int delete_subraster(); /* if fail, free unneeded subraster*/ +subraster /**new_subraster(),*/ *spacesp=NULL; /* subraster for space */ +raster *bp=NULL /*, *backspace_raster()*/; /* for negative space */ +/*int delete_subraster();*/ /* if fail, free unneeded subraster*/ int baseht=1, baseln=0; /* height,baseline of base symbol */ int pixsz = 1; /*default #bits per pixel, 1=bitmap*/ int isstar=0, minspace=0; /* defaults for negative hspace */ -char *texsubexpr(), widtharg[256]; /* parse for optional {width} */ -int evalterm(), evalue=0; /* evaluate [args], {args} */ -subraster *rasterize(), *rightsp=NULL; /*rasterize right half of expression*/ -subraster *rastcat(); /* cat rightsp after \hfill */ +int maxwidth = 2047; /* max width of expression in pixels*/ +char /**texsubexpr(),*/ widtharg[256]; /* parse for optional {width} */ +int /*evalterm(),*/ evalue=0; /* evaluate [args], {args} */ +subraster /**rasterize(),*/ *rightsp=NULL; /*rasterize right half of expresn*/ +/*subraster *rastcat();*/ /* cat rightsp after \hfill */ /* ------------------------------------------------------------------------- initialization -------------------------------------------------------------------------- */ @@ -8600,7 +9311,7 @@ -------------------------------------------------------------------------- */ if ( width == 0 ) { /* width specified in expression */ double dwidth; int widthval; /* test {width} before using it */ - int minwidth = (isfill||isheight?1:-600); /* \hspace allows negative */ + int minwidth = (isfill||isheight?1:-maxwidth); /* \hspace allows negative */ /* --- check if optional [minspace] given for negative \hspace --- */ if ( *(*expression) == '[' ) { /* [minspace] if leading char is [ */ /* ---parse [minspace], bump expression past it, evaluate expression--- */ @@ -8614,7 +9325,7 @@ dwidth = unitlength*((double)evalterm(mimestore,widtharg)); /* scaled */ widthval = /* convert {width} to integer */ (int)( dwidth + (dwidth>=0.0?0.5:(-0.5)) ); - if ( widthval>=minwidth && widthval<=600 ) /* sanity check */ + if ( widthval>=minwidth && widthval<=maxwidth ) /* sanity check */ width = widthval; /* replace deafault width */ } /* --- end-of-if(width==0) --- */ /* ------------------------------------------------------------------------- @@ -8705,16 +9416,16 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -subraster *rastnewline ( char **expression, int size, subraster *basesp, - int arg1, int arg2, int arg3 ) +FUNCSCOPE subraster *rastnewline ( char **expression, int size, + subraster *basesp, int arg1, int arg2, int arg3 ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -subraster *rastack(), *newlsp=NULL; /* subraster for both lines */ -subraster *rasterize(), *rightsp=NULL; /*rasterize right half of expression*/ -char *texsubexpr(), spacexpr[129]/*, *xptr=spacexpr*/; /*for \\[vspace]*/ -int evalterm(), evalue=0; /* evaluate [arg], {arg} */ +subraster /**rastack(),*/ *newlsp=NULL; /* subraster for both lines */ +subraster /**rasterize(),*/ *rightsp=NULL; /*rasterize right half of expresn*/ +char /**texsubexpr(),*/ spacexpr[129]/*, *xptr=spacexpr*/; /*for\\[vspace]*/ +int /*evalterm(),*/ evalue=0; /* evaluate [arg], {arg} */ int vspace = size+2; /* #pixels between lines */ /* ------------------------------------------------------------------------- obtain optional [vspace] argument immediately following \\ command @@ -8780,20 +9491,21 @@ * In text mode use two spaces {\rm~[f]\longrightarrow~~[g]}. * ======================================================================= */ /* --- entry point --- */ -subraster *rastarrow ( char **expression, int size, subraster *basesp, - int drctn, int isBig, int arg3 ) +FUNCSCOPE subraster *rastarrow(char **expression, int size, subraster *basesp, + int drctn, int isBig, int arg3) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -subraster *arrow_subraster(), *arrowsp=NULL; /* subraster for arrow */ -char *texsubexpr(), widtharg[256]; /* parse for optional [width] */ -char *texscripts(), sub[1024],super[1024]; /* and _^limits after [width]*/ -subraster *rasterize(), *subsp=NULL,*supsp=NULL; /*rasterize limits*/ -subraster *new_subraster(), *rastack(), *spacesp=NULL; /*space below arrow*/ -int delete_subraster(); /*free work areas in case of error*/ -int evalterm(); /* evaluate [arg], {arg} */ +subraster /**arrow_subraster(),*/ *arrowsp=NULL; /* subraster for arrow */ +char /**texsubexpr(),*/ widtharg[256]; /* parse for optional [width] */ +char /**texscripts(),*/ sub[1024],super[1024];/*and _^limits after [width]*/ +subraster /**rasterize(),*/ *subsp=NULL,*supsp=NULL; /*rasterize limits*/ +subraster /**new_subraster(), *rastack(),*/ *spacesp=NULL;/*space below arrow*/ +/*int delete_subraster();*/ /*free work areas in case of error*/ +/*int evalterm();*/ /* evaluate [arg], {arg} */ int width = 10 + 8*size, height; /* width, height for \longxxxarrow */ +int maxwidth = 1024; /* max arrow width in pixels */ int islimits = 1; /*true to handle limits internally*/ int limsize = size-1; /* font size for limits */ int vspace = 1; /* #empty rows below arrow */ @@ -8807,7 +9519,7 @@ *expression = texsubexpr(*expression,widtharg,255,"[","]",0,0); widthval = /* convert [width] to integer */ (int)((unitlength*((double)evalterm(mimestore,widtharg)))+0.5); - if ( widthval>=2 && widthval<=600 ) /* sanity check */ + if ( widthval>=2 && widthval<=maxwidth ) /* sanity check */ width = widthval; } /* replace deafault width */ /* --- now parse for limits, and bump expression past it(them) --- */ if ( islimits ) /* handling limits internally */ @@ -8875,19 +9587,20 @@ * In text use two spaces {\rm~[f]\longuparrow~~[g]}. * ======================================================================= */ /* --- entry point --- */ -subraster *rastuparrow ( char **expression, int size, subraster *basesp, - int drctn, int isBig, int arg3 ) +FUNCSCOPE subraster *rastuparrow ( char **expression, int size, + subraster *basesp, int drctn, int isBig, int arg3 ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -subraster *uparrow_subraster(), *arrowsp=NULL; /* subraster for arrow */ -char *texsubexpr(), heightarg[256]; /* parse for optional [height] */ -char *texscripts(), sub[1024],super[1024]; /* and _^limits after [width]*/ -subraster *rasterize(), *subsp=NULL,*supsp=NULL; /*rasterize limits*/ -subraster *rastcat(); /* cat superscript left, sub right */ -int evalterm(); /* evaluate [arg], {arg} */ +subraster /**uparrow_subraster(),*/ *arrowsp=NULL; /* subraster for arrow */ +char /**texsubexpr(),*/ heightarg[256]; /* parse for optional [height] */ +char /**texscripts(),*/ sub[1024],super[1024]; /*and _^limits after[width]*/ +subraster /**rasterize(),*/ *subsp=NULL,*supsp=NULL; /*rasterize limits*/ +/*subraster *rastcat();*/ /* cat superscript left, sub right */ +/*int evalterm();*/ /* evaluate [arg], {arg} */ int height = 8 + 2*size, width; /* height, width for \longxxxarrow */ +int maxheight = 800; /* max arrow height in pixels */ int islimits = 1; /*true to handle limits internally*/ int limsize = size-1; /* font size for limits */ int pixsz = 1; /*default #bits per pixel, 1=bitmap*/ @@ -8900,7 +9613,7 @@ *expression = texsubexpr(*expression,heightarg,255,"[","]",0,0); heightval = /* convert [height] to integer */ (int)((unitlength*((double)evalterm(mimestore,heightarg)))+0.5); - if ( heightval>=2 && heightval<=600 ) /* sanity check */ + if ( heightval>=2 && heightval<=maxheight ) /* sanity check */ height = heightval; } /* replace deafault height */ /* --- now parse for limits, and bump expression past it(them) --- */ if ( islimits ) /* handling limits internally */ @@ -8971,20 +9684,20 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -subraster *rastoverlay ( char **expression, int size, subraster *basesp, - int overlay, int offset2, int arg3 ) +FUNCSCOPE subraster *rastoverlay ( char **expression, int size, + subraster *basesp, int overlay, int offset2, int arg3 ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texsubexpr(), /*parse expression for base,overlay*/ +char /**texsubexpr(),*/ /*parse expression for base,overlay*/ expr1[512], expr2[512]; /* base, overlay */ -subraster *rasterize(), *sp1=NULL, *sp2=NULL, /*rasterize 1=base, 2=overlay*/ - *new_subraster(); /*explicitly alloc sp2 if necessary*/ -subraster *rastcompose(), *overlaysp=NULL; /*subraster for composite overlay*/ +subraster /**rasterize(),*/ *sp1=NULL, *sp2=NULL /*rasterize 1=base,2=overlay*/ + /*,*new_subraster()*/; /*explicitly alloc sp2 if necessary*/ +subraster /**rastcompose(),*/ *overlaysp=NULL;/*subrast for composite overlay*/ int isalign = 0; /* true to align baselines */ -int line_raster(); /* draw diagonal for \Not */ -int evalterm(); /* evaluate [arg], {arg} */ +/*int line_raster();*/ /* draw diagonal for \Not */ +/*int evalterm();*/ /* evaluate [arg], {arg} */ /* ------------------------------------------------------------------------- Obtain base, and maybe overlay, and rasterize them -------------------------------------------------------------------------- */ @@ -9085,30 +9798,54 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -subraster *rastfrac ( char **expression, int size, subraster *basesp, - int isfrac, int arg2, int arg3 ) +FUNCSCOPE subraster *rastfrac(char **expression, int size, subraster *basesp, + int isfrac, int arg2, int arg3) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texsubexpr(), /*parse expression for numer,denom*/ +char /**texsubexpr(),*/ /*parse expression for numer,denom*/ numer[MAXSUBXSZ+1], denom[MAXSUBXSZ+1]; /* parsed numer, denom */ -subraster *rasterize(), *numsp=NULL, *densp=NULL; /*rasterize numer, denom*/ -subraster *rastack(), *fracsp=NULL; /* subraster for numer/denom */ -subraster *new_subraster()/*, *spacesp=NULL*/; /* space for num or den */ +subraster /**rasterize(),*/ *numsp=NULL, *densp=NULL;/*rasterize numer,denom*/ +subraster /**rastack(),*/ *fracsp=NULL; /* subraster for numer/denom */ +/*subraster *new_subraster(), *spacesp=NULL;*/ /* space for num or den */ int width=0, /* width of constructed raster */ numheight=0; /* height of numerator */ int baseht=0, baseln=0; /* height,baseline of base symbol */ /*int istweak = 1;*/ /*true to tweak baseline alignment*/ -int rule_raster(), /* draw horizontal line for frac */ - lineheight = 1; /* thickness of fraction line */ +int /*rule_raster(),*/ /* draw horizontal line for frac */ + lineheight = (isfrac?1:0); /* thickness of fraction line */ int vspace = (size>2?2:1); /*vertical space between components*/ -int delete_subraster(); /*free work areas in case of error*/ -int type_raster(); /* display debugging output */ +/*int delete_subraster();*/ /*free work areas in case of error*/ +/*int type_raster();*/ /* display debugging output */ /* ------------------------------------------------------------------------- Obtain numerator and denominator, and rasterize them -------------------------------------------------------------------------- */ -/* --- parse for numerator,denominator and bump expression past them --- */ +/* --- first parse out optional \frac[] argument(s) --- */ +if ( *(*expression) == '[' ) { /* check for []-enclosed arg(s) */ + char optarg[512]; /* buffer for optional \frac[arg] */ + *expression = texsubexpr(*expression,optarg,511,"[","]",0,0); + if ( !isempty(optarg) ) { /* got optional arg */ + char *semi = strchr(optarg,';'); /* optionally followed by ; */ + if ( semi != NULL ) { /* found further optional ; */ + char *comma = strchr(semi+1,','); /* further optionally followed by , */ + *semi = '\000'; /* null-terminate optarg at ; */ + if ( comma != NULL ) *comma = '\000'; /* and that arg at (first) , */ + /* nextarg=atoi(semi+1)); */ /* convert argument after ; */ + isfrac = atoi(semi+1); /* kludge for \frac[;0] = \atop */ + lineheight = (isfrac?1:0); /* and reset lineheight */ + if ( comma != NULL ) { /* have , and arg */ + /* nextarg=atoi(comma+1); */ /* convert argument after , */ + } /* --- end-of-if(comma!=NULL) --- */ + } /* --- end-of-if(semi!=NULL) --- */ + trimwhite(optarg); /* remove leading/trailing whitespace*/ + if ( !isempty(optarg) ) /* wasn't just ";other,args" */ + vspace = atoi(optarg); /* convert optarg to vspace int */ + if ( vspace<0 || vspace>999 ) /* sanity check (revert to default) */ + vspace = (size>2?2:1); /* back to original default */ + } /* --- end-of-if(!isempty(optarg)) --- */ + } /* --- end-of-if(**expression=='[') --- */ +/* ---then parse for numerator,denominator and bump expression past them--- */ *expression = texsubexpr(*expression,numer,0,"{","}",0,0); *expression = texsubexpr(*expression,denom,0,"{","}",0,0); if ( *numer=='\000' && *denom=='\000' ) /* missing both components of frac */ @@ -9123,7 +9860,7 @@ { if ( numsp != NULL ) /* already rasterized numerator */ delete_subraster(numsp); /* so free now-unneeded numerator */ goto end_of_job; } /* and quit */ -/* --- if one componenet missing, use a blank space for it --- */ +/* --- if one component missing, use a blank space for it --- */ if ( numsp == NULL ) /* no numerator given */ numsp = rasterize("[?]",size-1); /* missing numerator */ if ( densp == NULL ) /* no denominator given */ @@ -9139,7 +9876,7 @@ construct raster with numerator stacked over denominator -------------------------------------------------------------------------- */ /* --- construct raster with numer/denom --- */ -if ( (fracsp = rastack(densp,numsp,0,2*vspace+lineheight,1,3))/*numer/denom*/ +if ( (fracsp = rastack(densp,numsp,0,(2*vspace)+lineheight,1,3))/*numer/denom*/ == NULL ) /* failed to construct numer/denom */ { delete_subraster(numsp); /* so free now-unneeded numerator */ delete_subraster(densp); /* and now-unneeded denominator */ @@ -9196,20 +9933,20 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -subraster *rastackrel ( char **expression, int size, subraster *basesp, - int base, int arg2, int arg3 ) +FUNCSCOPE subraster *rastackrel ( char **expression, int size, + subraster *basesp, int base, int arg2, int arg3 ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texsubexpr(), /*parse expression for upper,lower*/ +char /**texsubexpr(),*/ /*parse expression for upper,lower*/ upper[MAXSUBXSZ+1], lower[MAXSUBXSZ+1]; /* parsed upper, lower */ -subraster *rasterize(), *upsp=NULL, *lowsp=NULL; /* rasterize upper, lower */ -subraster *rastack(), *relsp=NULL; /* subraster for upper/lower */ +subraster /**rasterize(),*/ *upsp=NULL, *lowsp=NULL; /*rasterize upper,lower*/ +subraster /**rastack(),*/ *relsp=NULL; /* subraster for upper/lower */ int upsize = (base==1? size:size-1), /* font size for upper component */ lowsize = (base==2? size:size-1); /* font size for lower component */ int vspace = 1; /*vertical space between components*/ -int delete_subraster(); /*free work areas in case of error*/ +/*int delete_subraster();*/ /*free work areas in case of error*/ /* ------------------------------------------------------------------------- Obtain numerator and denominator, and rasterize them -------------------------------------------------------------------------- */ @@ -9268,21 +10005,21 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -subraster *rastmathfunc ( char **expression, int size, subraster *basesp, - int mathfunc, int islimits, int arg3 ) +FUNCSCOPE subraster *rastmathfunc ( char **expression, int size, + subraster *basesp, int mathfunc, int islimits, int arg3 ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texscripts(), /* parse expression for _limits */ +char /**texscripts(),*/ /* parse expression for _limits */ func[MAXTOKNSZ+1], limits[MAXSUBXSZ+1]; /*func as {\rm func}, limits*/ -char *texsubexpr(), /* parse expression for arg */ +char /**texsubexpr(),*/ /* parse expression for arg */ funcarg[MAXTOKNSZ+1]; /* optional func arg */ -subraster *rasterize(), *funcsp=NULL, *limsp=NULL; /*rasterize func,limits*/ -subraster *rastack(), *mathfuncsp=NULL; /* subraster for mathfunc/limits */ +subraster /**rasterize(),*/ *funcsp=NULL, *limsp=NULL;/*rasterize func,limits*/ +subraster /**rastack(),*/ *mathfuncsp=NULL; /*subraster for mathfunc/limits*/ int limsize = size-1; /* font size for limits */ int vspace = 1; /*vertical space between components*/ -int delete_subraster(); /*free work areas in case of error*/ +/*int delete_subraster();*/ /*free work areas in case of error*/ /* --- table of function names by mathfunc number --- */ static int numnames = 34; /* number of names in table */ static char *funcnames[] = { @@ -9375,23 +10112,23 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -subraster *rastsqrt ( char **expression, int size, subraster *basesp, - int arg1, int arg2, int arg3 ) +FUNCSCOPE subraster *rastsqrt(char **expression, int size, subraster *basesp, + int arg1, int arg2, int arg3) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texsubexpr(), subexpr[MAXSUBXSZ+1], /*parse subexpr to be sqrt-ed*/ +char /**texsubexpr(),*/ subexpr[MAXSUBXSZ+1],/*parse subexpr to be sqrt-ed*/ rootarg[MAXSUBXSZ+1]; /* optional \sqrt[rootarg]{...} */ -subraster *rasterize(), *subsp=NULL; /* rasterize subexpr */ -subraster *accent_subraster(), *sqrtsp=NULL, /* subraster with the sqrt */ - *new_subraster(), *rootsp=NULL; /* optionally preceded by [rootarg]*/ +subraster /**rasterize(),*/ *subsp=NULL; /* rasterize subexpr */ +subraster /**accent_subraster(),*/ *sqrtsp=NULL, /* subraster with the sqrt */ + /**new_subraster(),*/ *rootsp=NULL;/*optionally preceded by [rootarg]*/ int sqrtheight=0, sqrtwidth=0, surdwidth=0, /* height,width of sqrt */ rootheight=0, rootwidth=0, /* height,width of rootarg raster */ subheight=0, subwidth=0, pixsz=0; /* height,width,pixsz of subexpr */ -int rastput(); /* put subexpr in constructed sqrt */ +/*int rastput();*/ /* put subexpr in constructed sqrt */ int overspace = 2; /*space between subexpr and overbar*/ -int delete_subraster(); /* free work areas */ +/*int delete_subraster();*/ /* free work areas */ /* ------------------------------------------------------------------------- Obtain subexpression to be sqrt-ed, and rasterize it -------------------------------------------------------------------------- */ @@ -9492,21 +10229,21 @@ * of isabove and isscript args. * ======================================================================= */ /* --- entry point --- */ -subraster *rastaccent ( char **expression, int size, subraster *basesp, - int accent, int isabove, int isscript ) +FUNCSCOPE subraster *rastaccent ( char **expression, int size, + subraster *basesp, int accent, int isabove, int isscript ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texsubexpr(), subexpr[MAXSUBXSZ+1]; /*parse subexpr to be accented*/ -char *texscripts(), *script=NULL, /* \under,overbrace allow scripts */ +char /**texsubexpr(),*/ subexpr[MAXSUBXSZ+1];/*parse subexp to be accented*/ +char /**texscripts(),*/ *script=NULL, /* \under,overbrace allow scripts */ subscript[MAXTOKNSZ+1], supscript[MAXTOKNSZ+1]; /* parsed scripts */ -subraster *rasterize(), *subsp=NULL, *scrsp=NULL; /*rasterize subexpr,script*/ -subraster *rastack(), *accsubsp=NULL; /* stack accent, subexpr, script */ -subraster *accent_subraster(), *accsp=NULL; /*raster for the accent itself*/ +subraster /**rasterize(),*/ *subsp=NULL,*scrsp=NULL;/*rasterize subexp,script*/ +subraster /**rastack(),*/ *accsubsp=NULL; /* stack accent, subexpr, script */ +subraster /**accent_subraster(),*/ *accsp=NULL;/*raster for the accent itself*/ int accheight=0, accwidth=0, accdir=0,/*accent height, width, direction*/ subheight=0, subwidth=0, pixsz=0; /* height,width,pixsz of subexpr */ -int delete_subraster(); /*free work areas in case of error*/ +/*int delete_subraster();*/ /*free work areas in case of error*/ int vspace = 0; /*vertical space between accent,sub*/ /* ------------------------------------------------------------------------- Obtain subexpression to be accented, and rasterize it @@ -9605,21 +10342,21 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -subraster *rastfont ( char **expression, int size, subraster *basesp, - int ifontnum, int arg2, int arg3 ) +FUNCSCOPE subraster *rastfont(char **expression, int size, subraster *basesp, + int ifontnum, int arg2, int arg3) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texsubexpr(), fontchars[MAXSUBXSZ+1], /* chars to render in font */ +char /**texsubexpr(),*/ fontchars[MAXSUBXSZ+1], /*chars to render in font*/ subexpr[MAXSUBXSZ+1]; /* turn \cal{AB} into \calA\calB */ char *pfchars=fontchars, fchar='\0'; /* run thru fontchars one at a time*/ char *name = NULL; /* fontinfo[ifontnum].name */ int family = 0, /* fontinfo[ifontnum].family */ istext = 0, /* fontinfo[ifontnum].istext */ class = 0; /* fontinfo[ifontnum].class */ -subraster *rasterize(), *fontsp=NULL, /* rasterize chars in font */ - *rastflags(); /* or just set flag to switch font */ +subraster /**rasterize(),*/ *fontsp=NULL /* rasterize chars in font */ + /*,*rastflags()*/; /* or just set flag to switch font */ int oldsmashmargin = smashmargin; /* turn off smash in text mode */ #if 0 /* --- fonts recognized by rastfont --- */ @@ -9769,19 +10506,19 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -subraster *rastbegin ( char **expression, int size, subraster *basesp, - int arg1, int arg2, int arg3 ) +FUNCSCOPE subraster *rastbegin(char **expression, int size, subraster *basesp, + int arg1, int arg2, int arg3) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texsubexpr(), subexpr[MAXSUBXSZ+1], /* \begin{} environment params*/ +char /**texsubexpr(),*/ subexpr[MAXSUBXSZ+1],/*\begin{} environment params*/ *exprptr=NULL,*begptr=NULL,*endptr=NULL,*braceptr=NULL; /* ptrs */ char *begtoken="\\begin{", *endtoken="\\end{"; /*tokens we're looking for*/ -int strreplace(); /* replace substring in string */ -char *strchange(); /*\begin...\end --> {\begin...\end}*/ +/*int strreplace();*/ /* replace substring in string */ +/*char *strchange();*/ /*\begin...\end --> {\begin...\end}*/ char *delims = (char *)NULL; /* mdelims[ienviron] */ -subraster *rasterize(), *sp=NULL; /* rasterize environment */ +subraster /**rasterize(),*/ *sp=NULL; /* rasterize environment */ int ienviron = 0; /* environs[] index */ int nbegins = 0; /* #\begins nested beneath this one*/ int envlen=0, sublen=0; /* #chars in environ, subexpr */ @@ -10014,16 +10751,16 @@ * default justification is c(entered) and B(aseline). * ======================================================================= */ /* --- entry point --- */ -subraster *rastarray ( char **expression, int size, subraster *basesp, - int arg1, int arg2, int arg3 ) +FUNCSCOPE subraster *rastarray(char **expression, int size, subraster *basesp, + int arg1, int arg2, int arg3) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texsubexpr(), subexpr[MAXSUBXSZ+1], *exprptr, /*parse array subexpr*/ +char /**texsubexpr(),*/subexpr[MAXSUBXSZ+1],*exprptr,/*parse array subexpr*/ subtok[MAXTOKNSZ+1], *subptr=subtok, /* &,\\ inside { } not a delim*/ token[MAXTOKNSZ+1], *tokptr=token, /* subexpr token to rasterize */ - *preamble(), *preptr=token; /*process optional size,lcr preamble*/ + /**preamble(),*/ *preptr=token; /*process optional size,lcr preamble*/ char *coldelim="&", *rowdelim="\\"; /* need escaped rowdelim */ int maxarraysz = 63; /* max #rows, cols */ int justify[65]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* -1,0,+1 = l,c,r */ @@ -10086,22 +10823,22 @@ int isescape=0,wasescape=0, /* current,prev chars escape? */ ischarescaped=0, /* is current char escaped? */ nescapes=0; /* #consecutive escapes */ -subraster *rasterize(), *toksp[1025], /* rasterize tokens */ - *new_subraster(), *arraysp=NULL; /* subraster for entire array */ +subraster /**rasterize(),*/ *toksp[1025], /* rasterize tokens */ + /**new_subraster(),*/ *arraysp=NULL; /* subraster for entire array */ raster *arrayrp=NULL; /* raster for entire array */ -int delete_subraster(); /* free toksp[] workspace at eoj */ +/*int delete_subraster();*/ /* free toksp[] workspace at eoj */ int rowspace=2, colspace=4, /* blank space between rows, cols */ hspace=1, vspace=1; /*space to accommodate hline,vline*/ int width=0, height=0, /* width,height of array */ leftcol=0, toprow=0; /*upper-left corner for cell in it*/ int rastput(); /* embed tokens/cells in array */ -int rule_raster(); /* draw hlines and vlines in array */ +/*int rule_raster();*/ /* draw hlines and vlines in array */ char *hlchar="\\hline", *hdchar="\\hdash"; /* token signals hline */ -char *texchar(), hltoken[1025]; /* extract \hline from token */ +char /**texchar(),*/ hltoken[1025]; /* extract \hline from token */ int ishonly=0, hltoklen, minhltoklen=3; /*flag, token must be \hl or \hd*/ int isnewrow=1; /* true for new row */ int pixsz = 1; /*default #bits per pixel, 1=bitmap*/ -int evalterm(), evalue=0; /* evaluate [arg], {arg} */ +int /*evalterm(),*/ evalue=0; /* evaluate [arg], {arg} */ static int mydaemonlevel = 0; /* check against global daemonlevel*/ /* ------------------------------------------------------------------------- Macros to determine extra raster space required for vline/hline @@ -10527,34 +11264,35 @@ * o * ======================================================================= */ /* --- entry point --- */ -subraster *rastpicture ( char **expression, int size, subraster *basesp, - int arg1, int arg2, int arg3 ) +FUNCSCOPE subraster *rastpicture ( char **expression, int size, + subraster *basesp, int arg1, int arg2, int arg3 ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texsubexpr(), picexpr[2049], *picptr=picexpr, /* picture {expre} */ +char /**texsubexpr(),*/ picexpr[2049], *picptr=picexpr, /*picture {expre}*/ putexpr[256], *putptr,*multptr, /*[multi]put (x,y[;xinc,yinc;num])*/ pream[96], *preptr, /* optional put preamble */ picelem[1025]; /* picture element following put */ -subraster *rasterize(), *picelemsp=NULL, /* rasterize picture elements */ - *new_subraster(), *picturesp=NULL, /* subraster for entire picture */ +subraster /**rasterize(),*/ *picelemsp=NULL, /* rasterize picture elements */ + /**new_subraster(),*/ *picturesp=NULL, /*subraster for entire picture*/ *oldworkingbox = workingbox; /* save working box on entry */ raster *picturerp=NULL; /* raster for entire picture */ -int delete_subraster(); /* free picelemsp[] workspace */ +/*int delete_subraster();*/ /* free picelemsp[] workspace */ int pixsz = 1; /* pixels are one bit each */ double x=0.0,y=0.0, /* x,y-coords for put,multiput*/ xinc=0.0,yinc=0.0; /* x,y-incrementss for multiput*/ int width=0, height=0, /* #pixels width,height of picture */ ewidth=0, eheight=0, /* pic element width,height */ + maxwidth=1600, maxheight=1600, /* max width,height in pixels */ ix=0,xpos=0, iy=0,ypos=0, /* mimeTeX x,y pixel coords */ num=1, inum; /* number reps, index of element */ -int evalterm(); /* evaluate [arg] and {arg}'s */ +/*int evalterm();*/ /* evaluate [arg] and {arg}'s */ int iscenter=0; /* center or lowerleft put position*/ int *oldworkingparam = workingparam, /* save working param on entry */ origin = 0; /* x,yinc ++=00 +-=01 -+=10 --=11 */ -int rastput(); /* embed elements in picture */ -int type_raster(); /* display debugging output */ +/*int rastput();*/ /* embed elements in picture */ +/*int type_raster();*/ /* display debugging output */ /* ------------------------------------------------------------------------- First obtain (width,height) arguments immediately following \picture command -------------------------------------------------------------------------- */ @@ -10577,8 +11315,8 @@ allocate subraster and raster for complete picture -------------------------------------------------------------------------- */ /* --- sanity check on width,height args --- */ -if ( width < 2 || width > 600 -|| height < 2 || height > 600 ) goto end_of_job; +if ( width < 2 || width > maxwidth +|| height < 2 || height > maxheight ) goto end_of_job; /* --- allocate and initialize subraster for constructed picture --- */ if ( (picturesp=new_subraster(width,height,pixsz)) /*allocate new subraster*/ == NULL ) goto end_of_job; /* quit if failed */ @@ -10747,25 +11485,26 @@ * o if {xlen} not given, then it's assumed xlen = |xinc| * ======================================================================= */ /* --- entry point --- */ -subraster *rastline ( char **expression, int size, subraster *basesp, - int arg1, int arg2, int arg3 ) +FUNCSCOPE subraster *rastline(char **expression, int size, subraster *basesp, + int arg1, int arg2, int arg3) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texsubexpr(),linexpr[257], *xptr=linexpr; /*line(xinc,yinc){xlen}*/ -subraster *new_subraster(), *linesp=NULL; /* subraster for line */ +char /**texsubexpr(),*/linexpr[257], *xptr=linexpr;/*line(xinc,yinc){xlen}*/ +subraster /**new_subraster(),*/ *linesp=NULL; /* subraster for line */ /*char *origexpression = *expression;*/ /*original expression after \line*/ int pixsz = 1; /* pixels are one bit each */ int thickness = 1; /* line thickness */ double xinc=0.0, yinc=0.0, /* x,y-increments for line, */ xlen=0.0, ylen=0.0; /* x,y lengths for line */ int width=0, height=0, /* #pixels width,height of line */ + maxwidth=1600, maxheight=1600, /* max width,height in pixels */ rwidth=0, rheight=0; /*alloc width,height plus thickness*/ -int evalterm(); /* evaluate [arg] and {arg}'s */ +/*int evalterm();*/ /* evaluate [arg] and {arg}'s */ int istop=0, isright=0, /* origin at bot-left if x,yinc>=0 */ origin = 0; /* x,yinc: ++=00 +-=01 -+=10 --=11 */ -int line_raster(); /* draw line in linesp->image */ +/*int line_raster();*/ /* draw line in linesp->image */ /* ------------------------------------------------------------------------- obtain (xinc,yinc) arguments immediately following \line command -------------------------------------------------------------------------- */ @@ -10819,8 +11558,8 @@ allocate subraster and raster for line -------------------------------------------------------------------------- */ /* --- sanity check on width,height,thickness args --- */ -if ( width < 1 || width > 600 -|| height < 1 || height > 600 +if ( width < 1 || width > maxwidth +|| height < 1 || height > maxheight || thickness<1||thickness>25 ) goto end_of_job; /* --- allocate and initialize subraster for constructed line --- */ if ( (linesp=new_subraster(rwidth,rheight,pixsz)) /* alloc new subraster */ @@ -10876,20 +11615,21 @@ * o if width=0 then you get an invisible strut 1 (one) pixel wide * ======================================================================= */ /* --- entry point --- */ -subraster *rastrule ( char **expression, int size, subraster *basesp, - int arg1, int arg2, int arg3 ) +FUNCSCOPE subraster *rastrule(char **expression, int size, subraster *basesp, + int arg1, int arg2, int arg3) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texsubexpr(), rulexpr[257]; /* rule[lift]{wdth}{hgt} */ -subraster *new_subraster(), *rulesp=NULL; /* subraster for rule */ +char /**texsubexpr(),*/ rulexpr[257]; /* rule[lift]{wdth}{hgt} */ +subraster /**new_subraster(),*/ *rulesp=NULL; /* subraster for rule */ int pixsz = 1; /* pixels are one bit each */ int lift=0, width=0, height=0; /* default rule parameters */ double dval; /* convert ascii params to doubles */ -int rwidth=0, rheight=0; /* alloc width, height plus lift */ -int rule_raster(); /* draw rule in rulesp->image */ -int evalterm(); /* evaluate args */ +int rwidth=0, rheight=0, /* alloc width, height plus lift */ + maxwidth=1600, maxheight=1600; /* max width,height in pixels */ +/*int rule_raster();*/ /* draw rule in rulesp->image */ +/*int evalterm();*/ /* evaluate args */ /* ------------------------------------------------------------------------- Obtain lift,width,height -------------------------------------------------------------------------- */ @@ -10919,8 +11659,8 @@ allocate subraster and raster for rule -------------------------------------------------------------------------- */ /* --- sanity check on width,height,thickness args --- */ -if ( rwidth < 1 || rwidth > 600 -|| rheight < 1 || rheight > 600 ) goto end_of_job; +if ( rwidth < 1 || rwidth > maxwidth +|| rheight < 1 || rheight > maxheight ) goto end_of_job; /* --- allocate and initialize subraster for constructed rule --- */ if ( (rulesp=new_subraster(rwidth,rheight,pixsz)) /* alloc new subraster */ == NULL ) goto end_of_job; /* quit if failed */ @@ -10971,24 +11711,25 @@ * o * ======================================================================= */ /* --- entry point --- */ -subraster *rastcircle ( char **expression, int size, subraster *basesp, - int arg1, int arg2, int arg3 ) +FUNCSCOPE subraster *rastcircle ( char **expression, int size, + subraster *basesp, int arg1, int arg2, int arg3 ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texsubexpr(), circexpr[512],*xptr=circexpr; /*circle(xdiam[,ydiam])*/ +char /**texsubexpr(),*/circexpr[512],*xptr=circexpr;/*circle(xdiam[,ydiam])*/ char *qptr=NULL, quads[256]="1234"; /* default to draw all quadrants */ double theta0=0.0, theta1=0.0; /* ;theta0,theta1 instead of ;quads*/ -subraster *new_subraster(), *circsp=NULL; /* subraster for ellipse */ +subraster /**new_subraster(),*/ *circsp=NULL; /* subraster for ellipse */ int pixsz = 1; /* pixels are one bit each */ double xdiam=0.0, ydiam=0.0; /* x,y major/minor axes/diameters */ -int width=0, height=0; /* #pixels width,height of ellipse */ +int width=0, height=0, /* #pixels width,height of ellipse */ + maxwidth=1600, maxheight=1600; /* max width,height in pixels */ int thickness = 1; /* drawn lines are one pixel thick */ -int evalterm(); /* evaluate [arg],{arg} expressions*/ +/*int evalterm();*/ /* evaluate [arg],{arg} expressions*/ int origin = 55; /* force origin centered */ -int circle_raster(), /* draw ellipse in circsp->image */ - circle_recurse(); /* for theta0,theta1 args */ +/*int circle_raster(),*/ /* draw ellipse in circsp->image */ +/* circle_recurse();*/ /* for theta0,theta1 args */ /* ------------------------------------------------------------------------- obtain (xdiam[,ydiam]) arguments immediately following \circle command -------------------------------------------------------------------------- */ @@ -11027,8 +11768,8 @@ allocate subraster and raster for complete picture -------------------------------------------------------------------------- */ /* --- sanity check on width,height args --- */ -if ( width < 1 || width > 600 -|| height < 1 || height > 600 ) goto end_of_job; +if ( width < 1 || width > maxwidth +|| height < 1 || height > maxheight ) goto end_of_job; /* --- allocate and initialize subraster for constructed ellipse --- */ if ( (circsp=new_subraster(width,height,pixsz)) /* allocate new subraster */ == NULL ) goto end_of_job; /* quit if failed */ @@ -11088,27 +11829,28 @@ * \picture(){~(col0,row0){\bezier(col1,row1)(colt,rowt)}~} * ======================================================================= */ /* --- entry point --- */ -subraster *rastbezier ( char **expression, int size, subraster *basesp, - int arg1, int arg2, int arg3 ) +FUNCSCOPE subraster *rastbezier ( char **expression, int size, + subraster *basesp, int arg1, int arg2, int arg3 ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ subraster *new_subraster(), *bezsp=NULL; /* subraster for bezier */ -char *texsubexpr(), bezexpr[129],*xptr=bezexpr; /*\bezier(r,c)(r,c)(r,c)*/ +char /**texsubexpr(),*/bezexpr[129],*xptr=bezexpr;/*\bezier(r,c)(r,c)(r,c)*/ double r0=0.0,c0=0.0, r1=0.0,c1=0.0, rt=0.0,ct=0.0, /* bezier points */ rmid=0.0, cmid=0.0, /* coords at parameterized midpoint*/ rmin=0.0, cmin=0.0, /* minimum r,c */ rmax=0.0, cmax=0.0, /* maximum r,c */ rdelta=0.0, cdelta=0.0, /* rmax-rmin, cmax-cmin */ r=0.0, c=0.0; /* some point */ -int evalterm(); /* evaluate [arg],{arg} expressions*/ +/*int evalterm();*/ /* evaluate [arg],{arg} expressions*/ int iarg=0; /* 0=r0,c0 1=r1,c1 2=rt,ct */ -int width=0, height=0; /* dimensions of bezier raster */ +int width=0, height=0, /* dimensions of bezier raster */ + maxwidth=1600, maxheight=1600; /* max width,height in pixels */ int pixsz = 1; /* pixels are one bit each */ /*int thickness = 1;*/ /* drawn lines are one pixel thick */ int origin = 0; /*c's,r's reset to lower-left origin*/ -int bezier_raster(); /* draw bezier in bezsp->image */ +/*int bezier_raster();*/ /* draw bezier in bezsp->image */ /* ------------------------------------------------------------------------- obtain (c1,r1)(ct,rt) args immediately following \bezier command -------------------------------------------------------------------------- */ @@ -11159,8 +11901,8 @@ allocate raster -------------------------------------------------------------------------- */ /* --- sanity check on width,height args --- */ -if ( width < 1 || width > 600 -|| height < 1 || height > 600 ) goto end_of_job; +if ( width < 1 || width > maxwidth +|| height < 1 || height > maxheight ) goto end_of_job; /* --- allocate and initialize subraster for constructed bezier --- */ if ( (bezsp=new_subraster(width,height,pixsz)) /* allocate new subraster */ == NULL ) goto end_of_job; /* quit if failed */ @@ -11213,16 +11955,16 @@ * o * ======================================================================= */ /* --- entry point --- */ -subraster *rastraise ( char **expression, int size, subraster *basesp, - int arg1, int arg2, int arg3 ) +FUNCSCOPE subraster *rastraise(char **expression, int size, subraster *basesp, + int arg1, int arg2, int arg3) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texsubexpr(), subexpr[MAXSUBXSZ+1], *liftexpr=subexpr; /* args */ -subraster *rasterize(), *raisesp=NULL; /* rasterize subexpr to be raised */ +char /**texsubexpr(),*/ subexpr[MAXSUBXSZ+1], *liftexpr=subexpr; /*args*/ +subraster /**rasterize(),*/ *raisesp=NULL; /*rasterize subexpr to be raised*/ int lift=0; /* amount to raise/lower baseline */ -int evalterm(); /* evaluate [arg],{arg} expressions*/ +/*int evalterm();*/ /* evaluate [arg],{arg} expressions*/ /* ------------------------------------------------------------------------- obtain {lift} argument immediately following \raisebox command -------------------------------------------------------------------------- */ @@ -11278,21 +12020,21 @@ * o * ======================================================================= */ /* --- entry point --- */ -subraster *rastrotate ( char **expression, int size, subraster *basesp, - int arg1, int arg2, int arg3 ) +FUNCSCOPE subraster *rastrotate ( char **expression, int size, + subraster *basesp, int arg1, int arg2, int arg3 ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texsubexpr(), subexpr[MAXSUBXSZ+1], *degexpr=subexpr; /* args */ -subraster *rasterize(), *rotsp=NULL; /* subraster for rotated subexpr */ -raster *rastrot(), *rotrp=NULL; /* rotate subraster->image 90 degs */ -int delete_raster(); /* delete intermediate rasters */ +char /**texsubexpr(),*/ subexpr[MAXSUBXSZ+1], *degexpr=subexpr; /*args*/ +subraster /**rasterize(),*/ *rotsp=NULL; /* subraster for rotated subexpr */ +raster /**rastrot(),*/ *rotrp=NULL; /* rotate subraster->image 90 degs */ +/*int delete_raster();*/ /* delete intermediate rasters */ int baseline=0; /* baseline of rasterized image */ double degrees=0.0, ipart,fpart; /* degrees to be rotated */ int idegrees=0, isneg=0; /* positive ipart, isneg=1 if neg */ int n90=0, isn90=1; /* degrees is n90 multiples of 90 */ -int evalterm(); /* evaluate [arg],{arg} expressions*/ +/*int evalterm();*/ /* evaluate [arg],{arg} expressions*/ /* ------------------------------------------------------------------------- obtain {degrees} argument immediately following \rotatebox command -------------------------------------------------------------------------- */ @@ -11390,17 +12132,17 @@ * o * ======================================================================= */ /* --- entry point --- */ -subraster *rastmagnify ( char **expression, int size, subraster *basesp, - int arg1, int arg2, int arg3 ) +FUNCSCOPE subraster *rastmagnify ( char **expression, int size, + subraster *basesp, int arg1, int arg2, int arg3 ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texsubexpr(), subexpr[MAXSUBXSZ+1], *magexpr=subexpr; /* args */ -subraster *rasterize(), *magsp=NULL; /* subraster for magnified subexpr */ -raster *rastmag(), *magrp=NULL; /* magnify subraster->image */ +char /**texsubexpr(),*/ subexpr[MAXSUBXSZ+1], *magexpr=subexpr; /* args */ +subraster /**rasterize(),*/ *magsp=NULL; /* subraster for magnified subexpr */ +raster /**rastmag(),*/ *magrp=NULL; /* magnify subraster->image */ int magstep = 1; /* default magnification */ -int delete_raster(); /* delete intermediate raster */ +/*int delete_raster();*/ /* delete intermediate raster */ int baseline=0; /* baseline of rasterized image */ /* ------------------------------------------------------------------------- obtain {magstep} argument immediately following \magnify command @@ -11468,17 +12210,17 @@ * o * ======================================================================= */ /* --- entry point --- */ -subraster *rastreflect ( char **expression, int size, subraster *basesp, - int arg1, int arg2, int arg3 ) +FUNCSCOPE subraster *rastreflect ( char **expression, int size, + subraster *basesp, int arg1, int arg2, int arg3 ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texsubexpr(), subexpr[MAXSUBXSZ+1], *axisexpr=subexpr; /* args */ -subraster *rasterize(), *refsp=NULL; /* subraster for reflected subexpr */ -raster *rastref(), *refrp=NULL; /* reflect subraster->image */ +char /**texsubexpr(),*/ subexpr[MAXSUBXSZ+1], *axisexpr=subexpr; /* args */ +subraster /**rasterize(),*/ *refsp=NULL; /* subraster for reflected subexpr */ +raster /**rastref(),*/ *refrp=NULL; /* reflect subraster->image */ int axis = 1; /* default horizontal reflection */ -int delete_raster(); /* delete intermediate raster */ +/*int delete_raster();*/ /* delete intermediate raster */ int baseline=0; /* baseline of rasterized image */ /* ------------------------------------------------------------------------- obtain [axis] argument immediately following \reflectbox command, if given @@ -11545,16 +12287,16 @@ * o * ======================================================================= */ /* --- entry point --- */ -subraster *rastfbox ( char **expression, int size, subraster *basesp, - int arg1, int arg2, int arg3 ) +FUNCSCOPE subraster *rastfbox(char **expression, int size, subraster *basesp, + int arg1, int arg2, int arg3) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texsubexpr(), subexpr[MAXSUBXSZ+1], widtharg[512]; /* args */ -subraster *rasterize(), *framesp=NULL; /* rasterize subexpr to be framed */ -raster *border_raster(), *bp=NULL; /* framed image raster */ -int evalterm(), evalue=0; /* interpret [width][height] */ +char /**texsubexpr(),*/ subexpr[MAXSUBXSZ+1], widtharg[512]; /* args */ +subraster /**rasterize(),*/ *framesp=NULL; /*rasterize subexpr to be framed*/ +raster /**border_raster(),*/ *bp=NULL; /* framed image raster */ +int /*evalterm(),*/ evalue=0; /* interpret [width][height] */ int fwidth=6, fthick=1, /*extra frame width, line thickness*/ fsides=0; /* frame sides: 1=left,2=top,4=right,8=bot */ int width=(-1), height=(-1), /* optional [width][height] args */ @@ -11632,6 +12374,140 @@ /* ========================================================================== + * Function: rastovalbox ( expression, size, basesp, arg1, arg2, arg3 ) + * Purpose: \ovalbox{subexpression} handler, returns subraster + * containing subexpression with ellipse drawn around it + * -------------------------------------------------------------------------- + * Arguments: expression (I/O) char ** to first char of null-terminated + * string immediately following \ovalbox to be + * rasterized, and returning ptr immediately + * following last character processed. + * size (I) int containing 0-7 default font size + * basesp (I) subraster * to character (or subexpression) + * immediately preceding \ovalbox + * (unused, but passed for consistency) + * arg1 (I) int unused + * arg2 (I) int unused + * arg3 (I) int unused + * -------------------------------------------------------------------------- + * Returns: ( subraster * ) ptr to subraster corresponding to \ovalbox + * requested, or NULL for any parsing error + * -------------------------------------------------------------------------- + * Notes: o Summary of syntax... + * \ovalbox[n;#ovals,wdelta,hdelta]{subexpression} + * o Originally copied from rastfbox(), above, + * but I've modified the [] optional argument parsing + * o Thanks to answers from Jean-Marie Becker and "Narasimham" at + * http://math.stackexchange.com/questions/2149677/ + * for providing info about ellipse circumscribing a rectangle + * ======================================================================= */ +/* --- entry point --- */ +FUNCSCOPE subraster *rastovalbox ( char **expression, int size, + subraster *basesp, int arg1, int arg2, int arg3 ) +{ +/* ------------------------------------------------------------------------- +Allocations and Declarations +-------------------------------------------------------------------------- */ +char /**texsubexpr(),*/ subexpr[MAXSUBXSZ+1], narg[512], /* args */ + composexpr[MAXSUBXSZ+2048], /* compose subexpr[] with ellipse(s)*/ + ovalexpr[2048]; /* nested \compose{}{}'s */ +subraster /**rasterize(),*/ *framesp=NULL; /*rasterize subexpr to be oval'ed*/ +/*int delete_subraster();*/ /* just need width,height */ +int fwidth = 3+size/999; /* extra frame width */ +int width=(-1), height=(-1), /* width,height of subexpr[] */ + origheight = (-1), /* original subexpr[] height */ + baseline = (-1); /* and its original baseline */ +/*double sqrt2 = 1.414213562;*/ /*you think that's accurate enough?*/ +double x0=0.0, y0=0.0, /*rectangle half-width, half-height*/ + a=0.0, b=0.0; /*ellipse semi-major, semi-minor axis*/ +double n = 2.0; /*width/height=(semi-major/minor)^n*/ +int ioval=0, novals=1, /* #concentric ovals to draw */ + wdelta=(3), hdelta=(-3); /*width,height deltas for each oval*/ +/* ------------------------------------------------------------------------- +obtain {subexpr} argument +-------------------------------------------------------------------------- */ +/* --- first check for optional \ovalbox[n] and bump expression past it--- */ +if ( *(*expression) == '[' ) { /* check for []-enclosed n arg */ + *expression = texsubexpr(*expression,narg,511,"[","]",0,0); + if ( !isempty(narg) ) { /* got n */ + char *semi = strchr(narg,';'); /* optionally followed by ;#ovals */ + if ( semi != NULL ) { /* found optional ;#ovals */ + char *comma = strchr(semi+1,','); /* optionally followed by ,w,hdelta */ + *semi = '\000'; /* null-terminate 'n' argument at ; */ + if ( comma != NULL ) *comma = '\000'; /* and #ovals arg at (first) , */ + if ( (novals=atoi(semi+1)) /* convert #ovals argument after ; */ + < 1 ) novals = 1; /* and make sure it's >0 */ + if ( comma != NULL ) { /*have ,wdelta and maybe ,hdelta args*/ + char *comma2 = strchr(comma+1,','); /* ,wdelta and maybe ,hdelta */ + if ( comma2 != NULL ) *comma2 = '\000'; /* null-terminate wdelta */ + hdelta = wdelta = atoi(comma+1); /* init both wdelta,hdelta */ + if ( comma2 != NULL ) /* but we have separate ,hdelta */ + hdelta = atoi(comma2+1); /* so set hdelta separately */ + } /* --- end-of-if(comma!=NULL) --- */ + } /* --- end-of-if(semi!=NULL) --- */ + if ( (n = atof(narg)) /* convert narg to double */ + <= .001 ) n = 2.0; /* sanity check (revert to default) */ + } /* --- end-of-if(!isempty(narg)) --- */ + } /* --- end-of-if(**expression=='[') --- */ +/* --- parse for {subexpr} arg, and bump expression past it --- */ +*expression = texsubexpr(*expression,subexpr,0,"{","}",0,0); +/* ------------------------------------------------------------------------- +rasterize subexpression to be ellipse-framed +-------------------------------------------------------------------------- */ +if ( (framesp = rasterize(subexpr,size)) /* rasterize subexpression */ +== NULL ) goto end_of_job; /* and quit if failed */ +if ( framesp->image == NULL ) goto end_of_job; /* or quit if no image */ +/* --- pull out info we need --- */ +width = (framesp->image)->width; /* width of subexpr image */ +height = (framesp->image)->height; /* height of subexpr image */ +baseline = framesp->baseline; /* and original baseline */ +delete_subraster(framesp); /* just needed width,height,baseline */ +origheight = height; /* original "rectangle" height */ +/* --- old formulas for circumscribing ellipse (corresponds to n=1) --- */ +/*width = (int)(0.5+sqrt2*(double)(width +fwidth));*/ /*major ellipse axis*/ +/*height = (int)(0.5+sqrt2*(double)(height+fwidth));*/ /*minor ellipse axis*/ +/* --- use general formulas for circumscribing ellipse --- */ +x0 = ((double)width)/2.0; y0 = ((double)height)/2.0; /* half-width,height */ +a = sqrt(x0*x0 + pow(x0,2.0/n)*pow(y0,2.0-2.0/n)); +b = sqrt(y0*y0 + pow(y0,2.0/n)*pow(x0,2.0-2.0/n)); +width = (int)(2.0*a + 0.5) + fwidth; +height = (int)(2.0*b + 0.5) + fwidth; +baseline += ((height-origheight)+1)/2; /* baseline of subexpr[] chars */ +/* ------------------------------------------------------------------------- +construct nested \compose{\compose{\circle(,)}{\circle(,)}}{\circle(,)} +-------------------------------------------------------------------------- */ +*ovalexpr = '\000'; /* init as empty string */ +for ( ioval=0; ioval 1024 ) break; /* sanity check */ + strcpy(ovalbuff,ovalexpr); /* save current ovalexpr */ + sprintf(thisoval,"\\circle(%d,%d)",thiswidth,thisheight); /*draw this oval*/ + if ( ioval == 0 ) { /* initial oval */ + strcpy(ovalexpr,thisoval); } /* just copy \circle(,) directive */ + else { /* nest with \compose{}{}'s */ + sprintf(ovalexpr,"\\compose{%s}{%s}",ovalbuff,thisoval); } + } /* --- end-of-for(ioval) --- */ +/* ------------------------------------------------------------------------- +compose with circumscribed ellipse(s), reset params, and return it to caller +-------------------------------------------------------------------------- */ +/* --- construct expression to be rasterized + (note: too bad we have to re-rasterize original subexpr[]) --- */ + /* sprintf(composexpr,"\\compose{\\circle(%d,%d)}{%.8000s}", + width,height,subexpr); */ +sprintf(composexpr,"\\compose{%s}{%.8000s}", ovalexpr,subexpr); +if ( (framesp = rasterize(composexpr,size)) /*rasterize ellipse with subexpr*/ +== NULL ) goto end_of_job; /* and quit if failed */ +framesp->baseline = baseline; /* reset baseline (I hope) */ +/* --- return ellipse-framed subexpr to caller --- */ +end_of_job: + return ( framesp ); /* return framed subexpr to caller */ +} /* --- end-of-function rastovalbox() --- */ + + +/* ========================================================================== * Function: rastinput ( expression, size, basesp, arg1, arg2, arg3 ) * Purpose: \input{filename} handler, reads filename and returns * subraster containing image of expression read from filename @@ -11658,23 +12534,27 @@ * o * ======================================================================= */ /* --- entry point --- */ -subraster *rastinput ( char **expression, int size, subraster *basesp, - int arg1, int arg2, int arg3 ) +FUNCSCOPE subraster *rastinput(char **expression, int size, subraster *basesp, + int arg1, int arg2, int arg3) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texsubexpr(), tag[1024]="\000", filename[1024]="\000"; /* args */ -subraster *rasterize(), *inputsp=NULL; /* rasterized input image */ -int status, rastreadfile(); /* read input file */ -int format=0, npts=0; /* don't reformat (numerical) input */ +char /**texsubexpr(),*/ tag[1024]="\000", filename[1024]="\000"; /*args*/ +subraster /**rasterize(),*/ *inputsp=NULL /* rasterized input image */ + /*,*read_pbm()*/; /* read .pbm file and make subraster image */ +int status /*, rastreadfile()*/; /* read input file */ +FILE *fp=NULL /*, *rastopenfile()*/; /* reading .pbm files locally */ +int format=0, npts=0, /* don't reformat (numerical) input */ + ispbm = 0; /* set true for \input[pbm]{filename.pbm} */ +double sf = 0.0; /* shrink factor (0 or 1 means don't shrink)*/ int isinput = (seclevel<=inputseclevel?1:0); /*true if \input permitted*/ /*int evalterm();*/ /* evaluate expressions */ char *inputpath = INPUTPATH; /* permitted \input{} paths for any user */ -int isstrstr(); /* search for valid inputpath in filename */ +/*int isstrstr();*/ /* search for valid inputpath in filename */ char subexpr[MAXFILESZ+1] = "\000", /*concatanated lines from input file*/ - *mimeprep(), /* preprocess inputted data */ - *dbltoa(), *reformat=NULL; /* reformat numerical input */ + /**mimeprep(),*/ /* preprocess inputted data */ + /**dbltoa(),*/ *reformat=NULL; /* reformat numerical input */ /* ------------------------------------------------------------------------- obtain [tag]{filename} argument -------------------------------------------------------------------------- */ @@ -11686,7 +12566,11 @@ { format = 1; /* signal dtoa()/dbltoa() format */ if ( (reformat=strchr(reformat,'=')) != NULL ) /* have dtoa= */ npts = (int)strtol(reformat+1,NULL,0); } /* so set npts */ - if ( format == 0 ) { /* reformat not requested */ + if ( (reformat=strstr(argfld,"pbm")) != NULL ) /*input a .pbm image file*/ + { ispbm = 1; /* set ispbm flag */ + if ( (reformat=strchr(reformat,',')) != NULL ) /* have pbm, */ + sf = strtod(reformat+1,NULL); } /* so set sf(shrinkfactor) */ + if ( format==0 && !ispbm ) { /* not reformat request, and not pbm */ strninit(tag,argfld,1020); } } /* so interpret arg as tag */ /* --- parse for {filename} arg, and bump expression past it --- */ *expression = texsubexpr(*expression,filename,1020,"{","}",0,0); @@ -11710,6 +12594,14 @@ Read file (and convert to numeric if [dtoa] option was given) -------------------------------------------------------------------------- */ if ( isinput ) { /* user permitted to use \input{} */ + if ( ispbm ) { /* special case: input a .pbm file */ + fp = rastopenfile(filename,"r"); /* open the .pbm file for "r"ead */ + if ( fp != NULL ) { /* opened .pbm file successfully */ + if(0) printf("rastinput> sf=%.3f to read_pbm(%s,sf)\n",sf,filename); + inputsp = read_pbm(fp,sf); /* create subraster image from .pbm */ + fclose(fp); } /* close file after reading */ + goto end_of_job; /* all done, return inputsp to caller*/ + } /* --- end-of-if(ispbm) --- */ status = rastreadfile(filename,0,tag,subexpr); /* read file */ if ( *subexpr == '\000' ) goto end_of_job; /* quit if problem */ /* --- rasterize input subexpression --- */ @@ -11764,26 +12656,26 @@ * o :tag is optional * ======================================================================= */ /* --- entry point --- */ -subraster *rastcounter ( char **expression, int size, subraster *basesp, - int arg1, int arg2, int arg3 ) +FUNCSCOPE subraster *rastcounter ( char **expression, int size, + subraster *basesp, int arg1, int arg2, int arg3 ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texsubexpr(), filename[1024]="\000", /* counter file */ +char /**texsubexpr(),*/ filename[1024]="\000", /* counter file */ logfile[1024]="\000", tag[1024]="\000"; /*optional log file and tag*/ -subraster *rasterize(), *countersp=NULL; /* rasterized counter image */ +subraster /**rasterize(),*/ *countersp=NULL; /* rasterized counter image */ FILE /* *fp=NULL,*/ *logfp=NULL; /* counter and log file pointers */ -int status=0,rastreadfile(),rastwritefile(), /*read,write counter file*/ +int status=0,/*rastreadfile(),rastwritefile(),*//*read,write counter file*/ iscounter = (seclevel<=counterseclevel?1:0), /*is \counter permitted*/ isstrict = 1; /* true to only write to existing files */ char text[MAXFILESZ] = "1_", /* only line in counter file without tags */ *delim = NULL, /* delimiter in text */ utext[128] = "1_", /* default delimiter */ *udelim = utext+1; /* underscore delimiter */ -char *rasteditfilename(), /* edit log file name */ - *timestamp(), /* timestamp for logging */ - *dbltoa(); /* double to comma-separated ascii */ +/*char *rasteditfilename(),*/ /* edit log file name */ +/* *timestamp(),*/ /* timestamp for logging */ +/* *dbltoa();*/ /* double to comma-separated ascii */ int counter = 1, /* atoi(text) (after _ removed, if present) */ value = 1, /* optional [value] argument */ gotvalue = 0, /* set true if [value] supplied */ @@ -11948,20 +12840,21 @@ * arg2 (I) int unused * arg3 (I) int unused * -------------------------------------------------------------------------- - * Returns: ( subraster * ) subraster ptr to date stamp + * Returns: ( subraster * ) subraster ptr to image of eval-uated + * expression * -------------------------------------------------------------------------- * Notes: o * ======================================================================= */ /* --- entry point --- */ -subraster *rasteval ( char **expression, int size, subraster *basesp, - int arg1, int arg2, int arg3 ) +FUNCSCOPE subraster *rasteval(char **expression, int size, subraster *basesp, + int arg1, int arg2, int arg3 ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texsubexpr(), subexpr[MAXSUBXSZ]; /* arg to be evaluated */ -subraster *rasterize(), *evalsp=NULL; /* rasterize evaluated expression */ -int evalterm(), value=0; /* evaluate expression */ +char /**texsubexpr(),*/ subexpr[MAXSUBXSZ]; /* arg to be evaluated */ +subraster /**rasterize(),*/ *evalsp=NULL; /* rasterize evaluated expression */ +int /*evalterm(),*/ value=0; /* evaluate expression */ /* ------------------------------------------------------------------------- Parse for subexpr to be \eval-uated, and bump expression past it -------------------------------------------------------------------------- */ @@ -11984,6 +12877,102 @@ /* ========================================================================== + * Function: rastmathtex ( expression, size, basesp, arg1, arg2, arg3 ) + * Purpose: handle \mathtex... + * ...obtain pixel image corresponding to expression + * by "calling" mathtex, using wget, + * for pbm-style bitmap of expression, + * and then pixelizing it, and wrapping it in a subraster. + * -------------------------------------------------------------------------- + * Arguments: expression (I/O) char ** to first char of null-terminated + * string immediately following \mathtex, + * and returning ptr immediately + * following last character processed. + * size (I) int containing 0-11 default font size + * (unused, but passed for consistency) + * basesp (I) subraster * to character (or subexpression) + * immediately preceding \mathtex + * (unused, but passed for consistency) + * arg1 (I) int unused + * arg2 (I) int unused + * arg3 (I) int unused + * -------------------------------------------------------------------------- + * Returns: ( subraster * ) subraster ptr to image of pixelized + * pbm bitmap of expression returned by mathtex + * -------------------------------------------------------------------------- + * Notes: o Adapted from function + * BYTE *plainmimetext(char *expression, int *width, int *height) + * in gifsave89.c + * ======================================================================= */ +/* --- + * entry point + * -------------- */ +FUNCSCOPE subraster *rastmathtex ( char **expression, int size, + subraster *basesp, int arg1, int arg2, int arg3 ) +{ +/* --- + * allocations and declarations + * ------------------------------- */ +/* --- for mimetex --- */ +char /**texsubexpr(),*/ subexpr[MAXSUBXSZ]; /* arg to be evaluated */ +subraster /**read_pbm(),*/ *mathtexsp=NULL; /*rasterize mathtex'ed expression*/ +/* --- for wget() pipe to mathtex --- */ +char command[2048], /* complete popen(command,"r") */ + execwget[1024]; /* wget either mimetex or mathtex */ +FILE *wget = NULL; /* wget's stdout */ +char *localhost="localhost://", *plocalhost=NULL; /*check if running local*/ +char *mathtexpwd = MATHTEXPWD; /* mathTeX \password{} */ +/* --- + * initialization + * ----------------- */ +/* --- Parse for subexpr for mathtex, and bump expression past it ---*/ +*expression = texsubexpr(*expression,subexpr,0,"{","}",0,0); +if ( *subexpr == '\000' ) /* couldn't get subexpression */ + goto end_of_job; /* nothing to do, so quit */ +/* --- + * set up wget command for webservice + * ------------------------------------- */ +strcpy( execwget, /* --- mathTeX webservice --- */ + WGET /*...begins with /path/to/wget */ + " -q -O - " /*...followed by wget options */ + "\"" MATHTEX "?\\pbm" ); /*..."mathtex.cgi?\pbm\dpi{400} */ +if ( !isempty(mathtexpwd) ) { /* need \password{} ??? */ + strcat(execwget,"\\password{"); /* start with \password{ */ + strcat(execwget,mathtexpwd); /* then actual mathtex password */ + strcat(execwget,"}"); } /* and closing } */ +strcat(execwget," "); /* blank space if message needs it */ +/* --- + * open pipe to wget (or run locally) + * ------------------------------------- */ +/* --- first construct popen() command using execwget --- */ +strcpy(command,execwget); /* shell command plus mimetex url */ +strcat(command,subexpr); /* followed by \mathtex{subexpr} */ +strcat(command,"\""); /* and closing " */ +/* --- then check for local mathTeX executable --- */ +if ( (plocalhost=strstr(MATHTEX,localhost)) /* does url have localhost://? */ +!= NULL ) { /* if so, replace wget */ + strcpy(command,plocalhost+strlen(localhost)); /*path follows localhost://*/ + strcat(command," \"\\pbm\\stdout "); /* start with "\pbm\stdout */ + strcat(command,subexpr); /* followed by \mathtex{subexpr} */ + strcat(command,"\""); /* and closing " */ + } /* --- end-of-if(plocalhost!=NULL) --- */ +/* --- issue wget command and capture its stdout --- */ +if ( (wget = popen(command,"r")) /* issue command and capture stdout*/ +== NULL ) goto end_of_job; /* or quit if failed */ +/* --- + * create subraster for pixelized image + * --------------------------------------- */ +mathtexsp = read_pbm(wget,0.0); +/* --- + * end-of-job + * ------------- */ +end_of_job: + if ( wget != NULL ) pclose(wget); /* close pipe (if open) */ + return ( mathtexsp ); /* back with mathtex subraster */ +} /* --- end-of-function rastmathtex() --- */ + + +/* ========================================================================== * Function: rasttoday ( expression, size, basesp, arg1, arg2, arg3 ) * Purpose: handle \today * -------------------------------------------------------------------------- @@ -12004,15 +12993,15 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -subraster *rasttoday ( char **expression, int size, subraster *basesp, - int arg1, int arg2, int arg3 ) +FUNCSCOPE subraster *rasttoday(char **expression, int size, subraster *basesp, + int arg1, int arg2, int arg3) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texsubexpr(), optarg[2050]; /* optional [+/-tzdelta,ifmt] args */ -char *timestamp(), *today=optarg; /* timestamp to be rasterized */ -subraster *rasterize(), *todaysp=NULL; /* rasterize timestamp */ +char /**texsubexpr(),*/ optarg[2050]; /* optional [+/-tzdelta,ifmt] args */ +char /**timestamp(),*/ *today=optarg; /* timestamp to be rasterized */ +subraster /**rasterize(),*/ *todaysp=NULL; /* rasterize timestamp */ int ifmt=1, tzdelta=0; /* default timestamp() args */ /* ------------------------------------------------------------------------- Get optional args \today[+/-tzdelta,ifmt] @@ -12065,15 +13054,15 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -subraster *rastcalendar ( char **expression, int size, subraster *basesp, - int arg1, int arg2, int arg3 ) +FUNCSCOPE subraster *rastcalendar ( char **expression, int size, + subraster *basesp, int arg1, int arg2, int arg3 ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texsubexpr(), optarg[2050]; /* optional [year,month] args */ -char *calendar(), *calstr=NULL; /* calendar to be rasterized */ -subraster *rasterize(), *calendarsp=NULL; /* rasterize calendar string */ +char /**texsubexpr(),*/ optarg[2050]; /* optional [year,month] args */ +char /**calendar(),*/ *calstr=NULL; /* calendar to be rasterized */ +subraster /**rasterize(),*/ *calendarsp=NULL; /* rasterize calendar string */ int year=0,month=0,day=0, argval=0; /* default calendar() args */ /* ------------------------------------------------------------------------- Get optional args \today[+/-tzdelta,ifmt] @@ -12135,26 +13124,26 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -subraster *rastenviron ( char **expression, int size, subraster *basesp, - int arg1, int arg2, int arg3 ) +FUNCSCOPE subraster *rastenviron ( char **expression, int size, + subraster *basesp, int arg1, int arg2, int arg3 ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texsubexpr(), optarg[255]; /* optional [...] args (for future)*/ +char /**texsubexpr(),*/ optarg[255]; /* optional [...] args (for future)*/ char environstr[8192] = "\000", /* string for all environment vars */ environvar[1024] = "\000"; /* one environment variable */ -char *strwrap(), /* wrap long lines */ - *strdetex(), /* removes/replaces any math chars */ +char /**strwrap(),*/ /* wrap long lines */ + /**strdetex(),*/ /* removes/replaces any math chars */ *environptr = NULL; /* ptr to preprocessed environvar */ -char *mimeprep(); /* preprocess environvar string */ -int unescape_url(); /* convert all %xx's to chars */ +/*char *mimeprep();*/ /* preprocess environvar string */ +/*int unescape_url();*/ /* convert all %xx's to chars */ int isenviron = (seclevel<=environseclevel?1:0); /*is \environ permitted*/ int maxvarlen = 512, /* max chars in environment var */ maxenvlen = 6400, /* max chars in entire string */ wraplen = 48; /* strwrap() wrap lines at 48 chars*/ int ienv = 0; /* environ[] index */ -subraster *rasterize(), *environsp=NULL; /* rasterize environment string */ +subraster /**rasterize(),*/ *environsp=NULL; /*rasterize environment string*/ /* ------------------------------------------------------------------------- Get args -------------------------------------------------------------------------- */ @@ -12230,20 +13219,20 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -subraster *rastmessage ( char **expression, int size, subraster *basesp, - int arg1, int arg2, int arg3 ) +FUNCSCOPE subraster *rastmessage ( char **expression, int size, + subraster *basesp, int arg1, int arg2, int arg3 ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texsubexpr(), amsg[256]="\000"; /* message number text */ +char /**texsubexpr(),*/ amsg[256]="\000"; /* message number text */ int imsg = 0; /* default message number */ char msg[4096]; -subraster *rasterize(), *messagesp=NULL; /* rasterize requested message */ -int strreplace(); /*replace SERVER_NAME in refmsgnum*/ +subraster /**rasterize(),*/ *messagesp=NULL; /* rasterize requested message */ +/*int strreplace();*/ /*replace SERVER_NAME in refmsgnum*/ int reflevels = REFLEVELS; /* #topmost levels to match */ -char *urlprune(); /*prune referer_match in refmsgnum*/ -char *strdetex(); /* remove math chars from messages */ +/*char *urlprune();*/ /*prune referer_match in refmsgnum*/ +/*char *strdetex();*/ /* remove math chars from messages */ char *http_host = getenv("HTTP_HOST"), /* http host for mimeTeX */ *server_name = getenv("SERVER_NAME"), /* server hosting mimeTeX */ *referer_match = (!isempty(http_host)?http_host: /*match http_host*/ @@ -12297,14 +13286,14 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -subraster *rastnoop ( char **expression, int size, subraster *basesp, - int nargs, int arg2, int arg3 ) +FUNCSCOPE subraster *rastnoop(char **expression, int size, subraster *basesp, + int nargs, int arg2, int arg3) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *texsubexpr(), subexpr[MAXSUBXSZ+1]; /*dummy args eaten by \escape*/ -subraster *rasterize(), *noopsp=NULL; /* rasterize subexpr */ +char /**texsubexpr(),*/subexpr[MAXSUBXSZ+1];/*dummy args eaten by \escape*/ +subraster /**rasterize(),*/ *noopsp=NULL; /* rasterize subexpr */ /* --- flush accompanying args if necessary --- */ if ( nargs != NOVALUE /* not unspecified */ && nargs > 0 ) /* and args to be flushed */ @@ -12333,14 +13322,14 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -FILE *rastopenfile ( char *filename, char *mode ) +FUNCSCOPE FILE *rastopenfile ( char *filename, char *mode ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ FILE *fp = (FILE *)NULL /*,*fopen()*/; /*file pointer to opened filename*/ char texfile[2050] = "\000", /* local, edited copy of filename */ - *rasteditfilename(), /* prepend pathprefix if necessary */ + /**rasteditfilename(),*/ /* prepend pathprefix if necessary */ amode[512] = "r"; /* test open mode if arg mode=NULL */ int ismode = 0; /* true of mode!=NULL */ /* -------------------------------------------------------------------------- @@ -12391,14 +13380,14 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -char *rasteditfilename ( char *filename ) +FUNCSCOPE char *rasteditfilename ( char *filename ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ static char editname[2050]; /*edited filename returned to caller*/ -char *strchange(); /* prepend pathprefix if necessary */ -int strreplace(), /* remove ../'s and ..\'s */ +/*char *strchange();*/ /* prepend pathprefix if necessary */ +int /*strreplace(),*/ /* remove ../'s and ..\'s */ isprefix = (*pathprefix=='\000'?0:1); /* true if paths have prefix */ /* -------------------------------------------------------------------------- edit filename @@ -12451,12 +13440,12 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -int rastreadfile ( char *filename, int islock, char *tag, char *value ) +FUNCSCOPE int rastreadfile(char *filename, int islock, char *tag, char *value) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -FILE *fp = (FILE *)NULL, *rastopenfile(); /* pointer to opened filename */ +FILE *fp = (FILE *)NULL /*, *rastopenfile()*/; /*ptr to opened filename*/ char texfile[1024] = "\000", /* local copy of input filename */ text[MAXLINESZ+1]; /* line from input file */ char *tagp, tag1[1024], tag2[1024]; /* left and right */ @@ -12547,18 +13536,18 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -int rastwritefile( char *filename, char *tag, char *value, int isstrict ) +FUNCSCOPE int rastwritefile(char *filename,char *tag,char *value,int isstrict) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -FILE *fp = (FILE *)NULL, *rastopenfile(); /* pointer to opened filename */ +FILE *fp = (FILE *)NULL /*, *rastopenfile()*/; /*ptr to opened filename*/ char texfile[1024] = "\000", /* local copy of input filename */ filebuff[MAXFILESZ+1] = "\000", /* entire contents of file */ - tag1[1024], tag2[1024], /* left and right */ - *strchange(), /* put value between ...*/ - *timestamp(); /* log modification time */ -int istag=0, rastreadfile(), /* read file if tag!=NULL */ + tag1[1024], tag2[1024] /* left and right */ + /*,*strchange(),*/ /* put value between ...*/ + /**timestamp()*/; /* log modification time */ +int istag=0, /*rastreadfile(),*/ /* read file if tag!=NULL */ /*isstrict = (seclevel>5? 1:0),*/ /*true only writes existing files*/ isnewfile = 0, /* true if writing new file */ status = 0; /* status returned, 1=okay */ @@ -12686,7 +13675,7 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -char *calendar( int year, int month, int day ) +FUNCSCOPE char *calendar( int year, int month, int day ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -12785,7 +13774,7 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -char *timestamp( int tzdelta, int ifmt ) +FUNCSCOPE char *timestamp( int tzdelta, int ifmt ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -12797,8 +13786,8 @@ int year=0, hour=0,ispm=1, /* adjust year, and set am/pm hour */ month=0, day=0, /* adjust day and month for delta */ minute=0,second=0; /* minute and second not adjusted */ -int tzadjust(); /* time zone adjustment function */ -int daynumber(); /* #days since Jan 1, 1973 */ +/*int tzadjust();*/ /* time zone adjustment function */ +/*int daynumber();*/ /* #days since Jan 1, 1973 */ static char *daynames[] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" } ; static char *monthnames[] = { "?", "January", "February", "March", "April", @@ -12888,7 +13877,7 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -int tzadjust ( int tzdelta, int *year, int *month, int *day, int *hour ) +FUNCSCOPE int tzadjust(int tzdelta, int *year, int *month, int *day, int *hour) { /* -------------------------------------------------------------------------- Allocations and Declarations @@ -12948,7 +13937,7 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -int daynumber ( int year, int month, int day ) +FUNCSCOPE int daynumber ( int year, int month, int day ) { /* -------------------------------------------------------------------------- Allocations and Declarations @@ -13022,7 +14011,7 @@ * produced linebreaks). * ======================================================================= */ /* --- entry point --- */ -char *strwrap ( char *s, int linelen, int tablen ) +FUNCSCOPE char *strwrap ( char *s, int linelen, int tablen ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -13030,8 +14019,8 @@ static char sbuff[4096]; /* line-wrapped copy of s */ char *sol = sbuff; /* ptr to start of current line*/ char tab[32] = " "; /* tab string */ -int strreplace(); /* remove \n's */ -char *strchange(); /* add \n's and indent space */ +/*int strreplace();*/ /* remove \n's */ +/*char *strchange();*/ /* add \n's and indent space */ int finalnewline = (lastchar(s)=='\n'?1:0); /*newline at end of string?*/ int istab = (tablen>0?1:0), /* init true to indent first line */ iswhite = 0; /* true if line break on whitespace*/ @@ -13079,7 +14068,7 @@ fflush(msgfp); } /* --- look for last whitespace preceding linelen --- */ while ( 1 ) { /* till we exceed linelen */ - wordlen = strcspn(sol+thislen," \t\n\r\f\v :;.,"); /*ptr to next white/break*/ + wordlen = strcspn(sol+thislen," \t\n\r\f\v :;.,"); /*ptr next white/break*/ if ( sol[thislen+wordlen] == '\000' ) /* no more whitespace in string */ goto end_of_job; /* so nothing more we can do */ if ( thislen+thistab+wordlen >= linelen ) /* next word won't fit */ @@ -13115,7 +14104,7 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -char *strnlower ( char *s, int n ) +FUNCSCOPE char *strnlower ( char *s, int n ) { /* ------------------------------------------------------------------------- lowercase s @@ -13154,7 +14143,7 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -char *urlprune ( char *url, int n ) +FUNCSCOPE char *urlprune ( char *url, int n ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -13162,7 +14151,7 @@ static char pruned[2048]; /* pruned url returned to caller */ char *purl = /*NULL*/pruned; /* ptr to pruned, init for error */ char *delim = NULL; /* delimiter separating components */ -char *strnlower(); /* lowercase a string */ +/*char *strnlower();*/ /* lowercase a string */ int istruncate = (n<0?1:0); /*true to truncate .com from pruned*/ int ndots = 0; /* number of dots found in url */ /* ------------------------------------------------------------------------- @@ -13231,12 +14220,12 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -int urlncmp ( char *url1, char *url2, int n ) +FUNCSCOPE int urlncmp ( char *url1, char *url2, int n ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -char *urlprune(), *prune=NULL, /* prune url's */ +char /**urlprune(),*/ *prune=NULL, /* prune url's */ prune1[4096], prune2[4096]; /* pruned copies of url1,url2 */ int ismatch = 0; /* true if url's match */ /* ------------------------------------------------------------------------- @@ -13274,7 +14263,7 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -char *dbltoa ( double dblval, int npts ) +FUNCSCOPE char *dbltoa ( double dblval, int npts ) /* double dblval; int npts; */ { @@ -13346,6 +14335,108 @@ /* ========================================================================== + * Function: rotmatrix ( axis, theta ) + * Constructs rotation matrix for theta degrees around axis + * (see Notes below for discussion). + * -------------------------------------------------------------------------- + * Arguments: axis (I) point3d * to u=(u_x,u_y,u_z) components + * of rotation axis (u's tail point at origin), + * or NULL ptr returns previous matrix + * theta (I) double containing rotation in degrees + * (positive theta rotation according to + * right-hand screw rule), + * or 0.0 returns previous matrix + * -------------------------------------------------------------------------- + * Returns: ( matrix3d * ) pointer to constructed rotation matrix, + * or NULL for any error + * -------------------------------------------------------------------------- + * Notes: o For discussion, see + * http://wikipedia.org/wiki/Rotation_matrix#In_three_dimensions + * + * ======================================================================= */ +/* --- entry point --- */ +FUNCSCOPE matrix3d *rotmatrix ( point3d *axis, double theta ) +{ +/* ------------------------------------------------------------------------- +Allocations and Declarations +-------------------------------------------------------------------------- */ +static matrix3d rot = /* returned rotation matrix */ + { {0.,0.,0,}, {0.,0.,0,}, {0.,0.,0,} }; /* just init as zero's */ +matrix3d *prot = &(rot); /* init returned rot ptr */ +double pi = 3.14159265359; /* pi */ +double u,ux,uy,uz, /* axis length and components */ + tsin,tcos; /* sin,cos (theta) */ +/* ------------------------------------------------------------------------- +Initialization +-------------------------------------------------------------------------- */ +if ( axis == NULL /* no rotation axis, or no theta */ +|| absval(theta) < 1.0e-10 ) goto end_of_job;/*just return preceding matrix*/ +if ( 1 ) theta *= (pi/180.); /*convert theta in degrees to radians*/ +tsin = sin(theta); tcos = cos(theta); /* sin,cos (theta) */ +ux = axis->x; uy = axis->y; uz = axis->z; /* unnormalized axis components */ +u = sqrt((ux*ux)+(uy*uy)+(uz*uz)); /* axis length */ +if ( u < 1.0e-10 ) goto end_of_job; /* zero-vector is an error */ +ux /= u; uy /= u; uz /= u; /* normalized axis components */ +/* ------------------------------------------------------------------------- +rotation matrix components, stored row-wise +-------------------------------------------------------------------------- */ +/* --- x-row --- */ +rot.xrow.x = tcos + ux*ux*(1.0-tcos); +rot.xrow.y = ux*uy*(1.0-tcos) - uz*tsin; +rot.xrow.z = ux*uz*(1.0-tcos) + uy*tsin; +/* --- y-row --- */ +rot.yrow.x = uy*ux*(1.0-tcos) + uz*tsin; +rot.yrow.y = tcos + uy*uy*(1.0-tcos); +rot.yrow.z = uy*uz*(1.0-tcos) - ux*tsin; +/* --- z-row --- */ +rot.zrow.x = uz*ux*(1.0-tcos) - uy*tsin; +rot.zrow.y = uz*uy*(1.0-tcos) + ux*tsin; +rot.zrow.z = tcos + uz*uz*(1.0-tcos); +prot = &(rot); /* point return value to matrix */ +end_of_job: + return ( prot ); /*back to caller with rotation matrix*/ +} /* --- end-of-function rotmatrix() --- */ + + +/* ========================================================================== + * Function: matmult ( mat, vec ) + * returns result of mat(rix) x vec(tor) + * -------------------------------------------------------------------------- + * Arguments: mat (I) matrix3d * to matrix + * vec (I) point3d * to vector + * -------------------------------------------------------------------------- + * Returns: ( point3d * ) pointer to result of mat(rix) x vec(tor), + * or NULL for any error + * -------------------------------------------------------------------------- + * Notes: o + * ======================================================================= */ +/* --- entry point --- */ +FUNCSCOPE point3d *matmult ( matrix3d *mat, point3d *vec ) +{ +/* ------------------------------------------------------------------------- +Allocations and Declarations +-------------------------------------------------------------------------- */ +static point3d mult; /* returned matrix x vector product */ +point3d *pmult = NULL; /* init mult ptr for error */ +/* ------------------------------------------------------------------------- +Initialization +-------------------------------------------------------------------------- */ +if ( mat == NULL /* mat and vec required input */ +|| vec == NULL ) goto end_of_job; /* missing required input */ +/* ------------------------------------------------------------------------- +matrix multiplication +-------------------------------------------------------------------------- */ +/* --- x,y,z-components of mat(rix) x vec(tor) product --- */ +mult.x = (mat->xrow.x)*vec->x + (mat->xrow.y)*vec->y + (mat->xrow.z)*vec->z; +mult.y = (mat->yrow.x)*vec->x + (mat->yrow.y)*vec->y + (mat->yrow.z)*vec->z; +mult.z = (mat->zrow.x)*vec->x + (mat->zrow.y)*vec->y + (mat->zrow.z)*vec->z; +pmult = &(mult); /* point return value to product */ +end_of_job: + return ( pmult ); /*back to caller with matrix x vector*/ +} /* --- end-of-function matmult() --- */ + + +/* ========================================================================== * Function: aalowpass ( rp, bytemap, grayscale ) * Purpose: calculates a lowpass anti-aliased bytemap * for rp->bitmap, with each byte 0...grayscale-1 @@ -13374,7 +14465,7 @@ * as per the preceding note). * ======================================================================= */ /* --- entry point --- */ -int aalowpass (raster *rp, intbyte *bytemap, int grayscale) +FUNCSCOPE int aalowpass (raster *rp, intbyte *bytemap, int grayscale) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -13486,7 +14577,7 @@ * on sourceforge. * ======================================================================= */ /* --- entry point --- */ -int aapnm (raster *rp, intbyte *bytemap, int grayscale) +FUNCSCOPE int aapnm (raster *rp, intbyte *bytemap, int grayscale) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -13660,7 +14751,7 @@ * to interpret 3x3 lowpass pixel grids. * ======================================================================= */ /* --- entry point --- */ -int aapnmlookup (raster *rp, intbyte *bytemap, int grayscale) +FUNCSCOPE int aapnmlookup (raster *rp, intbyte *bytemap, int grayscale) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -13676,8 +14767,8 @@ isfgonly = fgonly, /*(0) true to only antialias fg bits*/ isbgalias = bgalias, /*(0) true to antialias bg bits */ isbgonly = bgonly; /*(0) true to only antialias bg bits*/ -int gridnum=(-1), aagridnum(), /* grid# for 3x3 grid at irow,icol */ - patternum=(-1), aapatternnum(); /*pattern#, 1-51, for input gridnum*/ +int gridnum=(-1), /*aagridnum(),*/ /* grid# for 3x3 grid at irow,icol */ + patternum=(-1) /*, aapatternnum()*/; /*pattern#1-51 for input gridnum*/ int aapatterns(); /* to antialias special patterns */ /* --- * pattern number data @@ -13841,19 +14932,19 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -int aapatterns (raster *rp, int irow, int icol, - int gridnum, int patternum, int grayscale) +FUNCSCOPE int aapatterns ( raster *rp, int irow, int icol, + int gridnum, int patternum, int grayscale ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ int aaval = (-1); /* antialiased value returned */ int iscenter = (gridnum&1); /* true if center pixel set/black */ -int aapatternnum(), /* if patternum not supplied */ - aapattern1124(), /* routine for patterns #11,24 */ - aapattern19(), /* special routine for pattern #19 */ - aapattern20(), /* special routine for pattern #20 */ - aapattern39(); /* special routine for pattern #39 */ +/*int aapatternnum(),*/ /* if patternum not supplied */ +/* aapattern1124(),*/ /* routine for patterns #11,24 */ +/* aapattern19(),*/ /* special routine for pattern #19 */ +/* aapattern20(),*/ /* special routine for pattern #20 */ +/* aapattern39();*/ /* special routine for pattern #39 */ /* ------------------------------------------------------------------------- special pattern number processing -------------------------------------------------------------------------- */ @@ -13911,8 +15002,8 @@ * corner, eg, * line, eg, * * ======================================================================= */ /* --- entry point --- */ -int aapattern1124 (raster *rp, int irow, int icol, - int gridnum, int grayscale) +FUNCSCOPE int aapattern1124 ( raster *rp, int irow, int icol, + int gridnum, int grayscale ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -13927,7 +15018,7 @@ topdiagval=0, botdiagval=0, /* upper,lower diagonal pixel bits */ cornval=0, diagval=0; /* vert+horzcorn, top+botdiag */ int hdirection=99, vdirection=99, /* horz,vert corner direction */ - hturn=99,vturn=99, aafollowline(); /* follow corner till turns */ + hturn=99,vturn=99 /*, aafollowline()*/; /*follow corner till turns*/ /* ------------------------------------------------------------------------- Check corner and diagonal pixels -------------------------------------------------------------------------- */ @@ -14036,8 +15127,8 @@ * *** --* *-- --- * ======================================================================= */ /* --- entry point --- */ -int aapattern19 (raster *rp, int irow, int icol, - int gridnum, int grayscale) +FUNCSCOPE int aapattern19 ( raster *rp, int irow, int icol, + int gridnum, int grayscale ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -14046,7 +15137,7 @@ int iscenter = gridnum&1; /* true if pixel at irow,icol black*/ int orientation = 1, /* 1=vertical, 2=horizontal */ jrow=irow, jcol=icol; /* middle pixel of *** line */ -int turn1=0,turn2=0, aafollowline(); /* follow *** line till it turns */ +int turn1=0,turn2=0 /*, aafollowline()*/; /*follow *** line till it turns*/ /* ------------------------------------------------------------------------- Initialization and calculation of antialiased value -------------------------------------------------------------------------- */ @@ -14109,8 +15200,8 @@ * *-- --- -*- --- * ======================================================================= */ /* --- entry point --- */ -int aapattern20 (raster *rp, int irow, int icol, - int gridnum, int grayscale) +FUNCSCOPE int aapattern20 ( raster *rp, int irow, int icol, + int gridnum, int grayscale ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -14120,7 +15211,7 @@ int direction = 1, /* direction to follow ** line */ jrow1=irow, jcol1=icol, /* coords of * */ jrow2=irow, jcol2=icol; /* coords of adjacent ** pixel */ -int turn1=0,turn2=0, aafollowline(); /* follow *,** lines till turns */ +int turn1=0,turn2=0 /*, aafollowline()*/; /*follow *,** lines till turns*/ /* ------------------------------------------------------------------------- Initialization and calculation of antialiased value -------------------------------------------------------------------------- */ @@ -14188,8 +15279,8 @@ * *-- --- **- --- * ======================================================================= */ /* --- entry point --- */ -int aapattern39 (raster *rp, int irow, int icol, - int gridnum, int grayscale) +FUNCSCOPE int aapattern39 ( raster *rp, int irow, int icol, + int gridnum, int grayscale ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -14199,7 +15290,7 @@ int direction = 1, /* direction to follow ** line */ jrow1=irow, jcol1=icol, /* coords of * */ jrow2=irow, jcol2=icol; /* coords of adjacent ** pixel */ -int turn1=0,turn2=0, aafollowline(); /* follow *,** lines till turns */ +int turn1=0,turn2=0 /*, aafollowline()*/; /*follow *,** lines till turns*/ /* ------------------------------------------------------------------------- Initialization and calculation of antialiased value -------------------------------------------------------------------------- */ @@ -14290,7 +15381,7 @@ * ----- ----- * ======================================================================= */ /* --- entry point --- */ -int aafollowline (raster *rp, int irow, int icol, int direction) +FUNCSCOPE int aafollowline ( raster *rp, int irow, int icol, int direction ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -14442,7 +15533,7 @@ * white. * ======================================================================= */ /* --- entry point --- */ -int aagridnum (raster *rp, int irow, int icol) +FUNCSCOPE int aagridnum ( raster *rp, int irow, int icol ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -14591,7 +15682,7 @@ * **- *-* **- *-* -*- * ======================================================================= */ /* --- entry point --- */ -int aapatternnum ( int gridnum ) +FUNCSCOPE int aapatternnum ( int gridnum ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -14652,13 +15743,13 @@ * for the center pixel (gridnum bit 0) of the grid. * ======================================================================= */ /* --- entry point --- */ -int aalookup ( int gridnum ) +FUNCSCOPE int aalookup ( int gridnum ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ int grayscale = (-1); /*returned grayscale, init for error*/ -int pattern = (-1), aapatternnum(); /*pattern#, 1-51, for input gridnum*/ +int pattern = (-1) /*, aapatternnum()*/;/*pattern#1-51 for input gridnum*/ int iscenter = gridnum&1; /*low-order bit set for center pixel*/ /* --- gray scales --- */ #define WHT 0 @@ -14776,7 +15867,7 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -int aalowpasslookup (raster *rp, intbyte *bytemap, int grayscale) +FUNCSCOPE int aalowpasslookup ( raster *rp, intbyte *bytemap, int grayscale ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -14786,8 +15877,8 @@ int bgbitval=0 /*, fgbitval=1*/; /* background, foreground bitval */ int bitval=0, /* value of rp bit at irow,icol */ aabyteval=0; /* antialiased (or unchanged) value*/ -int gridnum=0, aagridnum(), /* grid# for 3x3 grid at irow,icol */ - aalookup(); /* table look up antialiased value*/ +int gridnum=0 /*, aagridnum(),*/ /* grid# for 3x3 grid at irow,icol */ + /*aalookup()*/; /* table look up antialiased value*/ /* ------------------------------------------------------------------------- generate bytemap by table lookup for each pixel of bitmap -------------------------------------------------------------------------- */ @@ -14837,7 +15928,7 @@ * lines, which would otherwise turn from black to a gray shade. * ======================================================================= */ /* --- entry point --- */ -int aasupsamp (raster *rp, raster **aa, int sf, int grayscale) +FUNCSCOPE int aasupsamp ( raster *rp, raster **aa, int sf, int grayscale ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -14850,8 +15941,8 @@ int maxaaval=(-9999), /* max grayscale val set in matrix */ isrescalemax=1; /* 1=rescale maxaaval to grayscale */ int irp=0,jrp=0, iaa=0,jaa=0, iwt=0,jwt=0; /*indexes, i=width j=height*/ -raster *aap=NULL, *new_raster(); /* raster for supersampled image */ -raster *aaweights(); /* get weight matrix applied to rp */ +raster *aap=NULL /*, *new_raster()*/; /* raster for supersampled image */ +/*raster *aaweights();*/ /* get weight matrix applied to rp */ static raster *aawts = NULL; /* aaweights() resultant matrix */ static int prevshrink = NOVALUE, /* shrinkfactor from previous call */ sumwts = 0; /* sum of weights */ @@ -14859,8 +15950,8 @@ /*grayfrac = 20,*/ maxwt = 10, /* max weight in weight matrix */ minwtfrac=10, maxwtfrac=70; /* force light pts white, dark black*/ -int type_raster(), type_bytemap(); /* debugging display routines */ -int delete_raster(); /* delete old rasters */ +/*int type_raster(), type_bytemap();*/ /* debugging display routines */ +/*int delete_raster();*/ /* delete old rasters */ /* ------------------------------------------------------------------------- Initialization -------------------------------------------------------------------------- */ @@ -14976,6 +16067,208 @@ /* ========================================================================== + * Function: imgsupsamp ( rp, sf, grayscale ) + * Purpose: calculates a supersampled image of rp->pixmap, + * shrunk by 0<(double)sf<1, with each byte 0...grayscale-1 + * -------------------------------------------------------------------------- + * Arguments: rp (I) raster * to image to be super-sampled + * sf (I) double containing supersampling shrinkfactor + * ( 0.001 <= sf <= 0.999 ) + * grayscale (I) int containing number of grayscales + * to be calculated, 0...grayscale-1 + * (typically given as 2 or 256) + * -------------------------------------------------------------------------- + * Returns: ( raster * ) ptr to supersampled raster, NULL=any error + * -------------------------------------------------------------------------- + * Notes: o If the center point of the box being averaged is black, + * then the entire "average" is forced black (grayscale-1) + * regardless of the surrounding points. This is my attempt + * to avoid a "washed-out" appearance of thin (one-pixel-wide) + * lines, which would otherwise turn from black to a gray shade. + * ======================================================================= */ +/* --- entry point --- */ +FUNCSCOPE raster *imgsupsamp ( raster *rp, double sf, int grayscale ) +{ +/* ------------------------------------------------------------------------- +Allocations and Declarations +-------------------------------------------------------------------------- */ +raster *ssp=NULL /*, *new_raster()*/; /* new raster for returned ss */ +int rpheight=rp->height, rpwidth=rp->width, /* rp raster dimensions */ + ssheight=0, sswidth=0, /* supersampled dimensions */ + wtheight=0, wtwidth=0; /* weight matrix dimensions */ +int iss=0, jss=0; /* ss indexes, i=width j=height */ +/*int delete_raster();*/ /* delete stale sswts rasters */ +int maxwt=10 /*, ssweights()*/; /* weight matrix applied to rp */ +static raster *sswts = NULL; /* ssweights() resultant matrix */ +static double prevsf = 0.0; /* shrinkfactor from previous call */ +static int sumwts = 0; /* sum of weights */ +int maxssval=(-9999), /* max grayscale set in ss */ + isrescalemax = (grayscale>4?1:0), /* 1=rescale maxssval to grayscale*/ + minwtfrac=10, maxwtfrac=70; /* force light pts white, dark black*/ + /*grayfrac=20, blackfrac=40; */ /* force black if this many pts are */ +int blackfrac = 30; /* supersamp density (lower=darker) */ +int sspixsz = (grayscale>2?8:1); /* pixsz = 1,8 for returned raster */ +/* ------------------------------------------------------------------------- +Initialization +-------------------------------------------------------------------------- */ +/* --- check args --- */ +if ( rp == NULL /* no ptr to input arg */ + || sf<0.001 || sf>0.999 /* invalid shrink factor */ + || grayscale<2 || grayscale>256 /* invalid grayscale */ + ) goto end_of_job; /* quit if invalid request */ +/* --- supersamp raster dimensions --- */ +ssheight = (int)(((double)rpheight)*sf + 0.5); /* shrink height by sf */ +sswidth = (int)(((double)rpwidth)*sf + 0.5); /* shrink width by sf */ +if ( ssheight<1 || sswidth<1 ) goto end_of_job; /* shrunk too much */ +/* --- weight matrix dimensions --- */ +wtheight = max2(3.0,(1.0/sf)); /* at least 3x3-point averaging */ +wtheight = 1 + (wtheight/2)*2; /* and always an odd number */ +wtwidth = wtheight; /* same (for now) */ +/* --- get weight matrix (or use current one) --- */ +if ( absval(sf-prevsf) > 0.00001 ) { /* have new sf shrink factor */ + if (sswts!=NULL) delete_raster(sswts); /* free previous weight matrix */ + sswts = NULL; /* let ssweights() re-alloc */ + if ( (sumwts = ssweights(wtwidth,wtheight,maxwt,&sswts)) /*new wt matrix*/ + < 0 ) goto end_of_job; /* failed to build new weights */ + prevsf = sf; } /* save new shrink factor */ +/* --- allocate output raster */ +if ( (ssp = new_raster(sswidth,ssheight,sspixsz)) /* alloc output raster */ +== NULL ) goto end_of_job; /* quit if alloc fails */ +/* ------------------------------------------------------------------------- +Step through each pixel of ssp, sampling corresponding submatrix of rp +-------------------------------------------------------------------------- */ +for ( jss=0; jss=0 && i=0 && j 0 ) { /*normalize and rescale non-zero val*/ + int ssfrac = (100*ssval)/sumwts; /* weighted percent of black points */ + if( (100*nrp)/mrp >= blackfrac /* high number of black interior pts*/ + || ssfrac >= maxwtfrac ) /* high weight of sampled black pts */ + ssval = grayscale-1; /* so set supersampled pt black */ + else if( ssfrac <= minwtfrac ) /* low weight of sampledblack pts */ + ssval = 0; /* so set supersampled pt white */ + else /* rescale calculated weight */ + ssval = ((grayscale-1)*ssval + ((sumwts/2)-1))/sumwts; + setpixel(ssp,jss,iss,ssval); /*weighted val in supersamp raster*/ + maxssval = max2(maxssval,ssval); } /* largest sval so far */ + } /* --- end-of-for(iss)/for(jss) --- */ +/* --- + * rescale supersampled image so darkest points become black + * ------------------------------------------------------------ */ +if ( isrescalemax ) { /* flag set to rescale maxaaval */ + double scalef = ((double)(grayscale-1))/((double)maxssval); + for ( jss=0; jss= blackfrac ) /* high weight of sampledblack pts */ + ssval = grayscale-1; /* so set supersampled pt black */ + else if( 0&&ssfrac <= minwtfrac ) /* low weight of sampledblack pts */ + ssval = 0; /* so set supersampled pt white */ + setpixel(ssp,jss,iss,ssval); } /* replace rescaled val in raster */ + } /* --- end-of-if(isrescalemax) --- */ +/* ------------------------------------------------------------------------- +Back to caller with supersampled image +-------------------------------------------------------------------------- */ +end_of_job: + return ( ssp ); +} /* --- end-of-function imgsupsamp() --- */ + + +/* ========================================================================== + * Function: ssweights ( width, height, maxwt, wts ) + * Build "canonical" supersampling weight matrix, + * width x height, with maximum maxwt, in raster wts + * (see Notes below for discussion). + * -------------------------------------------------------------------------- + * Arguments: width (I) int containing width (#cols) of returned + * raster/matrix wts of weights + * height (I) int containing height (#rows) of returned + * raster/matrix wts of weights + * maxwt (I) int containing maximum weight allowed + * wts (O) raster ** returning calculated weights + * (if *wts==NULL, a new_raster() of + * width x height is allocated, and + * caller must delete_raster() it when done) + * -------------------------------------------------------------------------- + * Returns: ( int ) sum of all width*height weights, + * or -1 for any error + * -------------------------------------------------------------------------- + * Notes: o For example, given width=7, height=5, builds the matrix + * 1 2 3 4 3 2 1 + * 2 4 6 8 6 4 2 + * 3 6 9 12 9 6 3 + * 2 4 6 8 6 4 2 + * 1 2 3 4 3 2 1 + * If an even dimension given, the two center numbers stay + * the same, e.g., 123321 for the top row if width=6. + * o For an odd square n x n matrix, the sum of all n^2 + * weights will be ((n+1)/2)^4. + * o The largest weight (in raster of bytes) is 255, + * so the largest square matrix is 31 x 31. Any weight that + * tries to grow beyond 255 is held constant at 255. + * ======================================================================= */ +/* --- entry point --- */ +FUNCSCOPE int ssweights ( int width, int height, int maxwt, raster **wts ) +{ +/* ------------------------------------------------------------------------- +Allocations and Declarations +-------------------------------------------------------------------------- */ +int irow=0, icol=0, /* height, width indexes */ + weight = 0, /*running weight, as per Notes above*/ + totwt = (-1); /* sum of weights in wts */ +int ssalgorithm = 99; /* maybe for later use */ +/*raster *new_raster();*/ /* if caller wants wts allocated */ +/* ------------------------------------------------------------------------- +Initialization +-------------------------------------------------------------------------- */ +/* --- check args --- */ +if ( width<1 || height<1 || maxwt<1 ) goto end_of_job; /* bad args */ +maxwt = min2(maxwt,255); /* 255 is maximum weight allowed */ +if ( wts == NULL ) goto end_of_job; /* no raster address supplied */ +if ( *wts == NULL ) /* caller wants wts allocated */ + if ( (*wts = new_raster(width,height,8)) /* caller must delete_raster() */ + == NULL ) goto end_of_job; /* quit if alloc failed */ +/* ------------------------------------------------------------------------- +Fill weight matrix, as per Notes above +-------------------------------------------------------------------------- */ +totwt = 0; /* reset sum */ +for ( irow=0; irowimage returned by rasterize()*/ +int nwide=0, nhigh=0, npixels=nwide*nhigh, /* raster dimensions */ + icol =0, irow =0, ipixel =0; /* col,row,pixel indexes */ +/*int delete_subraster();*/ /* free raster after making bytemap */ +char exprbuffer[4096]; /* local copy of expression */ +/* --- + * initialization + * ----------------- */ +/* --- check args --- */ +if ( width != NULL ) *width =0; /* init width (in case of error) */ +if ( height != NULL ) *height=0; /* init height */ +if ( isempty(expression) ) goto end_of_job; /* nothing to do */ +/* --- preprocess a local copy of caller's expression --- */ +strninit(exprbuffer,expression,2048); /* local copy of expression */ +mimeprep(exprbuffer); /* preprocess expression */ +/* --- + * rasterize expression + * ----------------------- */ +if ( (sp = rasterize(exprbuffer,NORMALSIZE)) /* rasterize expression */ +== NULL ) goto end_of_job; /* quit if failed to rasterize */ +/* --- apply any 'magstep' to magnify entire rasterized >>bit< 1 && magstep <= 10 ) { /* magnify entire bitmap image */ + raster /**rastmag(),*/ *magrp=NULL; /* bitmap magnify function */ + int baseline = sp->baseline; /* original image baseline */ + magrp = rastmag(sp->image,magstep); /* magnify raster image */ + if ( magrp != NULL ) { /* succeeded to magnify image */ + delete_raster(sp->image); /* free original raster image */ + sp->image = magrp; /*and replace it with magnified one*/ + /* --- adjust parameters --- */ + baseline *= magstep; /* scale baseline */ + if ( baseline > 0 ) baseline += 1; /* adjust for no descenders */ + sp->baseline = baseline; } /*reset baseline of magnified image*/ + } /* --- end-of-if(magstep) --- */ +/* --- finally, adjust bitmap width to multiple of eight bits --- */ +if ( 1 ) { + rp = border_raster(sp->image,0,0,0,1); /* image width multiple of 8 bits */ + if ( rp != NULL ) sp->image = rp; } /* save successfully bordred image */ +/* --- + * get pixels for returned bytemap + * ---------------------------------- */ +if ( (rp = sp->image) /* raster image in returned subraster*/ +== NULL ) goto end_of_job; /* shouldn't happen, probably a bug */ +/* --- raster dimensions --- */ +nwide=rp->width; nhigh=rp->height; npixels=nwide*nhigh; /* width and height */ +if ( width != NULL ) *width =nwide; /* set actual image width in pixels */ +if ( height != NULL ) *height=nhigh; /* and height */ +if ( npixels < 1 ) goto end_of_job; /* some kind of problem */ +/* --- allocate bytemap ... --- */ +if ( (bytemap = (unsigned char *)malloc(npixels+nwide)) /*plus one extra row*/ +== NULL ) goto end_of_job; /* malloc() failed */ +/* --- ...and transfer pixels to it --- */ +for ( irow=0; irow> Note: logdata now defined in mimetex.h << + * (it's temporarily left here only as comments) + * ------------------------------------------------ */ + /* --- logging data structure --- */ + #define logdata struct logdata_struct /* "typedef" for logdata_struct*/ + logdata { + /* ----------------------------------------------------------------------- + environment variable name, max #chars to display, min msglevel to display + ------------------------------------------------------------------------ */ + char *name; /* environment variable name */ + int maxlen; /* max #chars to display */ + int msglevel; /* min msglevel to display data */ + } ; /* --- end-of-logdata_struct --- */ +#endif /* --- data logged by mimeTeX --- */ STATIC logdata mimelog[] #ifdef INITVALS @@ -15401,7 +16833,9 @@ ; -/* --- entry point --- */ +/* --- + * entry point + * -------------- */ int main ( int argc, char *argv[] #ifdef DUMPENVP , char *envp[] @@ -15416,9 +16850,9 @@ char *expression = exprbuffer; /* ptr to expression */ int size = NORMALSIZE; /* default font size */ char *query = getenv("QUERY_STRING"); /* getenv("QUERY_STRING") result */ -char *mimeprep(); /* preprocess expression */ -int unescape_url(); /* convert %xx's to ascii chars */ -int emitcache(); /* emit cached image if it exists */ +/*char *mimeprep();*/ /* preprocess expression */ +/*int unescape_url();*/ /* convert %xx's to ascii chars */ +/*int emitcache();*/ /* emit cached image if it exists */ int /*isquery = 0, (now global)*/ /* true if input from QUERY_STRING */ isqempty = 0, /* true if query string empty */ isqforce = 0, /* true to force query emulation */ @@ -15427,18 +16861,20 @@ isinmemory = 1, /* true to generate image in memory*/ isdumpimage = 0, /* true to dump image on stdout */ isdumpbuffer = 0; /* true to dump to memory buffer */ +char /**getdirective(),*/ argstring[256], /*look for \directive's, etc*/ + *pdirective = NULL; /* ptr to char after \directive */ /* --- rasterization --- */ -subraster *rasterize(), *sp=NULL; /* rasterize expression */ -raster *border_raster(), *bp=NULL; /* put a border around raster */ -int delete_subraster(); /* for clean-up at end-of-job */ -int type_raster(), type_bytemap(), /* screen dump function prototypes */ - xbitmap_raster(); /* mime xbitmap output function */ +subraster /**rasterize(),*/ *sp=NULL; /* rasterize expression */ +raster /**border_raster(),*/ *bp=NULL; /* put a border around raster */ +/*int delete_subraster();*/ /* for clean-up at end-of-job */ +/*int type_raster(), type_bytemap(),*/ /* screen dump function prototypes */ +/* xbitmap_raster();*/ /* mime xbitmap output function */ /* --- http_referer --- */ char *referer = REFERER; /* http_referer must contain this */ char *inputreferer = INPUTREFERER; /*http_referer's permitted to \input*/ -int reflevels = REFLEVELS, urlncmp(); /* cmp http_referer,server_name */ -int strreplace(); /* replace SERVER_NAME in errmsg */ -char *urlprune(); /* prune referer_match */ +int reflevels = REFLEVELS /*, urlncmp()*/; /*cmp http_referer,server_name*/ +/*int strreplace();*/ /* replace SERVER_NAME in errmsg */ +/*char *urlprune();*/ /* prune referer_match */ struct { char *referer; int msgnum; } /* http_referer can't contain this */ denyreferer[] = { /* referer table to deny access to */ #ifdef DENYREFERER @@ -15446,12 +16882,13 @@ #endif { NULL, -999 } }; /* trailer */ char *http_referer = getenv("HTTP_REFERER"), /* referer using mimeTeX */ + *remote_addr = getenv("REMOTE_ADDR"), /* ip address of referer */ *http_host = getenv("HTTP_HOST"), /* http host for mimeTeX */ *server_name = getenv("SERVER_NAME"), /* server hosting mimeTeX */ *referer_match = (!isempty(http_host)?http_host: /*match http_host*/ (!isempty(server_name)?server_name:(NULL))); /* or server_name */ int ishttpreferer = (isempty(http_referer)?0:1); -int isstrstr(); /* search http_referer for referer */ +/*int isstrstr();*/ /* search http_referer for referer */ int isinvalidreferer = 0; /* true for inavlid referer */ int norefmaxlen = NOREFMAXLEN; /*max query_string len if no referer*/ /* --- gif --- */ @@ -15463,32 +16900,32 @@ char *gif_outfile = (char *)NULL, /* gif output defaults to stdout */ gif_buffer[MAXGIFSZ] = "\000", /* or gif written in memory buffer */ cachefile[256] = "\000", /* full path and name to cache file*/ - *md5str(); /* md5 has of expression */ + *md5hash=NULL /*, *md5str()*/; /* md5 hash of expression */ int maxage = 7200; /* max-age is two hours */ int valign = (-9999); /*Vertical-Align:baseline-(height-1)*/ /* --- pbm/pgm (-g switch) --- */ /*int ispbmpgm = 0; (now global)*/ /* true to write pbm/pgm file */ -int type_pbmpgm(); /* entry point, graphic format */ +/*int type_pbmpgm();*/ /* entry point, graphic format */ char *pbm_outfile = (char *)NULL; /* output file defaults to stdout */ /* --- anti-aliasing --- */ intbyte *bytemap_raster = NULL, /* anti-aliased bitmap */ colors[256]; /* grayscale vals in bytemap */ -int aalowpass(), aapnm(), /*lowpass filters for anti-aliasing*/ +int /*aalowpass(), aapnm(),*/ /*lowpass filters for anti-aliasing*/ grayscale = 256; /* 0-255 grayscales in 8-bit bytes */ -int ncolors=2, /* #colors (2=b&w) */ - aacolormap(); /* build colormap from bytemap */ +int ncolors=2 /* #colors (2=b&w) */ + /*,aacolormap()*/; /* build colormap from bytemap */ int ipattern; /*patternnumcount[] index diagnostic*/ /* --- advertisement preprocessing --- */ -int advertisement(), crc16(); /*wrap expression in advertisement*/ +/*int advertisement(), crc16();*/ /*wrap expression in advertisement*/ char *adtemplate = NULL; /* usually use default message */ char *host_showad = HOST_SHOWAD; /* show ads only on this host */ /* --- messages --- */ char logfile[256] = LOGFILE, /*log queries if msglevel>=LOGLEVEL*/ cachelog[256] = CACHELOG; /* cached image log in cachepath/ */ -char *timestamp(); /* time stamp for logged messages */ -char *strdetex(); /* remove math chars from messages */ -int logger(); /* logs environ variables */ -int ismonth(); /* check argv[0] for current month */ +/*char *timestamp();*/ /* time stamp for logged messages */ +/*char *strdetex();*/ /* remove math chars from messages */ +/*int logger();*/ /* logs environ variables */ +/*int ismonth();*/ /* check argv[0] for current month */ char *progname = (argc>0?argv[0]:"noname"); /* name program executed as */ char *dashes = /* separates logfile entries */ "--------------------------------------------------------------------------"; @@ -15671,11 +17108,15 @@ { pbm_outfile = gif_outfile; /* use -e switch file for pbm/pgm */ gif_outfile = (char *)NULL; /* reset gif output file */ /*isdumpimage--;*/ } /* and decrement -e count */ + /* --- + * permit \input, etc in command-line mode + * ------------------------------------------ */ + inputseclevel = (99999); /* \input allowed */ } /* --- end-of-if(!isquery) --- */ /* --- * check for
input * ---------------------- */ -if ( isquery ) { /* must be */ +if ( isquery ) { /* must be */ if ( !memcmp(expression,"formdata",8) ) /*must be */ { char *delim=strchr(expression,'='); /* find equal following formdata */ if ( delim != (char *)NULL ) /* found unescaped equal sign */ @@ -15689,6 +17130,7 @@ isformdata = 1; } /* set flag to signal form data */ else /* --- query, but not input --- */ unescape_url(expression,0); } /* convert _all_ %xx's to chars */ +md5hash = md5str(expression); /* md5 hash of unedited expression */ /* --- * check queries for prefixes/suffixes/embedded that might cause problems * ---------------------------------------------------------------------- */ @@ -15699,32 +17141,55 @@ * check queries for embedded prefixes signalling special processing * ----------------------------------------------------------------- */ if ( isquery ) /* only check queries */ - { - /* --- check for msglevel=###$ prefix --- */ - if ( !memcmp(expression,"msglevel=",9) ) /* query has msglevel prefix */ - { char *delim=strchr(expression,'$'); /* find $ delim following msglevel*/ + { + if ( getdirective(expression,"\\dumpgif",1,0,1,argstring)/*\dumpgif{level}*/ + != NULL ) { /* found \dumpgif{level} */ + isdumpgif = atoi(argstring); /* interpret arg as isdumpgif value */ + if ( isdumpgif>1 ) { *logfile = '\000'; /* default logfile for dumpgif */ + if ( !isempty(cachepath) ) strcat(logfile,cachepath); + strcat(logfile,DUMPGIF); strcat(logfile,".txt"); + if ( msglevel < LOGLEVEL ) msglevel=LOGLEVEL; } + } /* --- end-of-if(getdirective("\\dumpgif")!=NULL) --- */ + if ( 0 ) /* --- done by getdirective() immediately above --- */ + if ( strstr(expression,"\\dumpgif") != NULL ) { /* debug dump gif image*/ + char *dumpgif = strstr(expression,"\\dumpgif"); /* ptr to \dumpgif */ + strsqueeze(dumpgif,strlen("\\dumpgif")); /* get rid of \dumpgif */ + isdumpgif = 1; } /* set flag to dump gif image */ + if ( getdirective(expression,"\\msglevel",1,0,1,argstring)/*\msglevel{lev}*/ + != NULL ) { /* found \msglevel{level} */ + if ( 1 || (seclevel<=9) ) /* permit msglevel specification */ + msglevel = atoi(argstring); } /* interpret msglevel */ + if ( getdirective(expression,"\\logfile",1,0,1,argstring) /*\logfile{file}*/ + != NULL ) { /* found \logfile{file} */ + if ( 1 || (seclevel<=3) ) /* permit logfile specification */ + strcpy(logfile,argstring); } /* copy \logfile{filename} */ + if ( 0 ) { /* --- done by getdirective()'s immediately above --- */ + /* --- check for msglevel=###$ prefix --- */ + if ( !memcmp(expression,"msglevel=",9) ) { /* query has msglevel prefix */ + char *delim=strchr(expression,'$'); /* find $ delim following msglevel*/ if ( delim != (char *)NULL ) /* check that we found delim */ { *delim = '\000'; /* replace delim with null */ if ( seclevel <= 9 ) /* permit msglevel specification */ msglevel = atoi(expression+9); /* interpret ### in msglevel###$ */ strsqueezep(expression,delim+1); } } /* squeeze out prefix & delim */ - /* --- next check for logfile=xxx$ prefix (must follow msglevel) --- */ - if ( !memcmp(expression,"logfile=",8) ) /* query has logfile= prefix */ - { char *delim=strchr(expression,'$'); /* find $ delim following logfile=*/ - if ( delim != (char *)NULL ) /* check that we found delim */ - { *delim = '\000'; /* replace delim with null */ - if ( seclevel <= 3 ) /* permit logfile specification */ - strcpy(logfile,expression+8); /* interpret xxx in logfile=xxx$ */ - strsqueezep(expression,delim+1); } } /* squeeze out prefix & delim */ - } /* --- end-of-if(isquery) --- */ + /* --- next check for logfile=xxx$ prefix (must follow msglevel) --- */ + if ( !memcmp(expression,"logfile=",8) ) { /* query has logfile= prefix */ + char *delim=strchr(expression,'$'); /* find $ delim following logfile=*/ + if ( delim != (char *)NULL ) /* check that we found delim */ + { *delim = '\000'; /* replace delim with null */ + if ( seclevel <= 3 ) /* permit logfile specification */ + strcpy(logfile,expression+8); /* interpret xxx in logfile=xxx$ */ + strsqueezep(expression,delim+1); } } /* squeeze out prefix & delim */ + } /* --- end-of-if(0) --- */ + } /* --- end-of-if(isquery) --- */ + /* --- * log query (e.g., for debugging) * ------------------------------- */ if ( isquery ) /* only log query_string's */ - if ( msglevel >= LOGLEVEL /* check if logging */ + if ( (msglevel >= LOGLEVEL) /* check if logging */ && seclevel <= 5 ) /* and if logging permitted */ - if ( logfile != NULL ) /* if a logfile is given */ - if ( *logfile != '\000' ) { /*and if it's not an empty string*/ + if ( !isempty(logfile) ) { /* if a logfile is given */ if ( (msgfp=fopen(logfile,"a")) /* open logfile for append */ != NULL ) /* ignore logging if can't open */ { @@ -15767,7 +17232,7 @@ #endif /* --- DUMPENVIRON ---*/ } /* --- end-of-if(msglevel>=9) --- */ /* --- close log file if no longer needed --- */ - if ( msglevel < DBGLEVEL ) /* logging, but not debugging */ + if ( (msglevel=1 && msgfp!=NULL ) + fprintf(msgfp,"mimeTeX> \\password{%s} %s\n", + password, (ispassword==1?"successful":"failed") ); } + } /* --- end-of-if(expression!=NULL) --- */ +/* --- * check if http_referer is allowed to use this image and to use \input{} * ---------------------------------------------------------------------- */ -if ( isquery ) { /* not relevant if "interactive" */ +if ( isquery /* not relevant if "interactive" */ +&& !ispassword ) { /* nor if user supplied password */ /* --- check -DREFERER=\"comma,separated,list\" of valid referers --- */ if ( referer != NULL ) { /* compiled with -DREFERER=\"...\" */ if ( strcmp(referer,"month") != 0 ) /* but it's *only* "month" signal */ if ( ishttpreferer ) /* or called "standalone" */ if ( !isstrstr(http_referer,referer,0) ) { /* invalid http_referer */ expression = invalid_referer_msg; /* so give user error message */ - isinvalidreferer = 1; } } /* and signal invalid referer */ + isinvalidreferer = 10; } } /* and signal invalid referer */ else /* compiled without -DREFERER= */ if ( reflevels > 0 ) { /*match referer unless -DREFLEVELS=0*/ /* --- check topmost levels of http_referer against http_host --- */ @@ -15806,8 +17286,10 @@ strcpy(exprbuffer,invalid_referer_match); /* init error message */ strreplace(exprbuffer,"SERVER_NAME", /* and then replace SERVER_NAME */ strdetex(urlprune(referer_match,reflevels),1),0);/*with referer_match*/ - isinvalidreferer = 1; } /* and signal invalid referer */ + isinvalidreferer = 20; } /* and signal invalid referer */ } /* --- end-of-if(reflevels>0) --- */ + } /* --- end-of-if(isquery&&!ispassword) --- */ +if ( isquery ) { /* not relevant if "interactive" */ /* --- check -DINPUTREFERER=\"comma,separated,list\" of \input users --- */ inputseclevel = INPUTSECURITY; /* set default input security */ if ( inputreferer != NULL ) { /* compiled with -DINPUTREFERER= */ @@ -15821,19 +17303,22 @@ /* --- * check if referer contains "month" signal * ---------------------------------------- */ -if ( isquery ) /* not relevant if "interactive" */ +if ( isquery /* not relevant if "interactive" */ +&& !ispassword ) /* nor if user supplied password */ if ( referer != NULL ) /* nor if compiled w/o -DREFERER= */ if ( !isinvalidreferer ) /* nor if already invalid referer */ if ( strstr(referer,"month") != NULL ) /* month check requested */ if ( !ismonth(progname) ) /* not executed as mimetexJan-Dec */ { expression = invalid_referer_msg; /* so give user error message */ - isinvalidreferer = 1; } /* and signal invalid referer */ + isinvalidreferer = 30; } /* and signal invalid referer */ /* --- * check if http_referer is to be denied access * -------------------------------------------- */ -if ( isquery ) /* not relevant if "interactive" */ +if ( isquery /* not relevant if "interactive" */ +&& !ispassword ) /* nor if user supplied password */ if ( !isinvalidreferer ) /* nor if already invalid referer */ - { int iref=0, msgnum=(-999); /* denyreferer index, message# */ + { int iref=0, msgnum=(-999), /* denyreferer index, message# */ + whundredths = 0; /* or wait hundredths of a sec */ for ( iref=0; msgnum<0; iref++ ) { /* run through denyreferer[] table */ char *deny = denyreferer[iref].referer; /* referer to be denied */ if ( deny == NULL ) break; /* null signals end-of-table */ @@ -15848,15 +17333,19 @@ if ( isstrstr(http_referer,deny,0) ) /* invalid http_referer */ msgnum = denyreferer[iref].msgnum; /* so set message# */ } /* --- end-of-for(iref) --- */ - if ( msgnum >= 0 ) /* deny access to this referer */ - { if ( msgnum > maxmsgnum ) msgnum = 0; /* keep index within bounds */ - expression = msgtable[msgnum]; /* set user error message */ - isinvalidreferer = 1; } /* and signal invalid referer */ + if ( msgnum >= 100 ) { /* wait but don't deny */ + whundredths = 10*(msgnum-100); /* hundredths=10*tenths */ + msgnum = (-999); } /* reset valid referer */ + if ( msgnum >= 0 ) { /* deny access to this referer */ + if ( msgnum > maxmsgnum ) msgnum = 0; /* keep index within bounds */ + expression = msgtable[msgnum]; /* set user error message */ + isinvalidreferer = 40; } /* and signal invalid referer */ } /* --- end-of-if(!isinvalidreferer) --- */ /* --- also check maximum query_string length if no http_referer given --- */ -if ( isquery ) /* not relevant if "interactive" */ +if ( isquery /* not relevant if "interactive" */ +&& !ispassword ) /* nor if user supplied password */ if ( !isinvalidreferer ) /* nor if already invalid referer */ - if ( !ishttpreferer ) /* no http_referer supplied */ + if ( !ishttpreferer ) { /* no http_referer supplied */ if ( strlen(expression) > norefmaxlen ) { /* query_string too long */ if ( isempty(referer_match) ) /* no referer_match to display */ expression = invalid_referer_msg; /* set invalid http_referer message*/ @@ -15864,7 +17353,11 @@ strcpy(exprbuffer,invalid_referer_match); /* init error message */ strreplace(exprbuffer,"SERVER_NAME", /* and then replace SERVER_NAME */ strdetex(urlprune(referer_match,reflevels),1),0); } /*with host_http*/ - isinvalidreferer = 1; } /* and signal invalid referer */ + isinvalidreferer = 50; } /* and signal invalid referer */ + } /* --- end-of-if(!ishttpreferer) --- */ +if ( isdumpgif ) { + sprintf(argstring,"isinvalidreferer=%d\n",isinvalidreferer); + logdump(0,argstring); } /* --- * check for "advertisement" * ------------------------- */ @@ -15902,7 +17395,7 @@ if ( iscaching ) /* image caching enabled */ { /* --- set up path to cached image file --- */ - char *md5hash = md5str(expression); /* md5 hash of expression */ + /*char *md5hash = md5str(expression);*/ /*md5 hash of unedited expression*/ if ( md5hash == NULL ) /* failed for some reason */ iscaching = 0; /* so turn off caching */ else @@ -15923,8 +17416,7 @@ /* --- log caching request --- */ if ( msglevel >= 1 /* check if logging */ /*&& seclevel <= 5*/ ) /* and if logging permitted */ - if ( cachelog != NULL ) /* if a logfile is given */ - if ( *cachelog != '\000' ) /*and if it's not an empty string*/ + if ( !isempty(cachelog) ) /* if a logfile is given */ { char filename[256]; /* construct cachepath/cachelog */ FILE *filefp=NULL; /* fopen(filename) */ strcpy(filename,cachepath); /* start with (relative) path */ @@ -15935,8 +17427,7 @@ fprintf(filefp,"%s %s\n", /* timestamp, md5 file */ timestamp(TZDELTA,0),cachefile+strlen(cachepath)); /*skip path*/ fprintf(filefp,"%s\n",expression); /* expression in filename */ - if ( http_referer != NULL ) /* show referer if we have one */ - if ( *http_referer != '\000' ) /* and if not an empty string*/ + if ( !isempty(http_referer) ) /* show referer if we have one */ { int loglen = strlen(dashes); /* #chars on line in log file*/ char *refp = http_referer; /* line to be printed */ isreflogged = 1; /* signal http_referer logged*/ @@ -15946,6 +17437,8 @@ refp += loglen; } } /* bump ptr to next part */ if ( !isreflogged ) /* http_referer not logged */ fprintf(filefp,"http://none\n"); /* so log dummy referer line */ + fprintf(filefp,"remote_addr=%s\n", /* and log ip_address... */ + (!isempty(remote_addr)?remote_addr:"None")); /* ...or "None" */ fprintf(filefp,"%s\n",dashes); /* separator line */ fclose(filefp); } /* close logfile immediately */ } /* --- end-of-if(cachelog!=NULL) --- */ @@ -15962,8 +17455,9 @@ /* ------------------------------------------------------------------------- rasterize expression and put a border around it -------------------------------------------------------------------------- */ -/* --- preprocess expression, converting LaTeX constructs for mimeTeX --- */ -if ( expression != NULL ) { /* have expression to rasterize */ +/* --- preprocess expression, converting LaTeX constructs for mimeTeX + (now done above to get \password{} before referer checks) --- */ +if ( 0 && expression!=NULL ) { /* have expression to rasterize */ expression = mimeprep(expression); } /* preprocess expression */ /* --- double-check that we actually have an expression to rasterize --- */ if ( expression == NULL ) { /* nothing to rasterize */ @@ -15995,7 +17489,7 @@ /* --- magnify entire image here if we need >>bit< 1 && magstep <= 10 ) { /* magnify entire bitmap image */ - raster *rastmag(), *magrp=NULL; /* bitmap magnify function */ + raster /**rastmag(),*/ *magrp=NULL; /* bitmap magnify function */ int baseline = sp->baseline; /* original image baseline */ magrp = rastmag(sp->image,magstep); /* magnify raster image */ if ( magrp != NULL ) { /* succeeded to magnify image */ @@ -16098,7 +17592,7 @@ * --------------------------------------------------------------- */ if ( 1 ) { /* or use rastmag() above instead */ if ( magstep > 1 && magstep <= 10 ) { /*magnify entire bytemap image*/ - intbyte *bytemapmag(), *magmap=NULL; /* bytemap magnify function */ + intbyte /**bytemapmag(),*/ *magmap=NULL; /*bytemap magnify function*/ magmap=bytemapmag(bytemap_raster,raster_width,raster_height,magstep); if ( magmap != NULL ) { /* succeeded to magnify image */ free(bytemap_raster); /* free original bytemap image */ @@ -16373,7 +17867,7 @@ * Notes: o There's a three day "grace period", e.g., Dec 3 mtaches Nov. * ======================================================================= */ /* --- entry point --- */ -int ismonth ( char *month ) +FUNCSCOPE int ismonth ( char *month ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -16417,11 +17911,12 @@ /* ========================================================================== - * Function: logger ( fp, msglevel, message, logvars ) + * Function: logger ( logfp, msglevel, message, logvars ) * Purpose: Logs the environment variables specified in logvars * to fp if their msglevel is >= the passed msglevel. * -------------------------------------------------------------------------- - * Arguments: fp (I) FILE * to file containing log + * Arguments: logfp (I) FILE * to file containing log, + * or NULL defaults to global msgfp * msglevel (I) int containing logging message level * message (I) char * to optional message, or NULL * logvars (I) logdata * to array of environment variables @@ -16433,19 +17928,27 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -int logger ( FILE *fp, int msglevel, char *message, logdata *logvars ) +FUNCSCOPE int logger ( FILE *logfp, int msglevel, + char *message, logdata *logvars ) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ +FILE *fp = (logfp!=NULL?logfp:msgfp); /* use caller's logfp, or msgfp */ int ilog=0, nlogged=0; /* logvars[] index, #vars logged */ -char *timestamp(); /* timestamp logged */ +/*char *timestamp();*/ /* timestamp logged */ char *value = NULL; /* getenv(name) to be logged */ +static int ncalls = 0; /* #calls (headers on 1st call) */ +static char *dashes = + "------------------------------------------------------------------------"; /* ------------------------------------------------------------------------- Log each variable -------------------------------------------------------------------------- */ -fprintf(fp,"%s\n",timestamp(TZDELTA,0)); /*emit timestamp before first var*/ -if ( message != NULL ) /* optional message supplied */ +if ( fp == NULL ) goto end_of_job; /* no output file */ +if ( ++ncalls == 1 ) { /* headers */ + fprintf(fp,"%s\n",dashes); + fprintf(fp,"%s\n",timestamp(TZDELTA,0)); } /*emit timestamp before 1st var*/ +if ( !isempty(message) ) /* optional message supplied */ fprintf(fp," MESSAGE = %s\n",message); /* emit caller-supplied message */ if ( logvars != (logdata *)NULL ) /* have logvars */ for ( ilog=0; logvars[ilog].name != NULL; ilog++ ) /* till end-of-table */ @@ -16457,7 +17960,7 @@ logvars[ilog].name,logvars[ilog].maxlen,value); nlogged++; /* bump #vars logged */ } /* --- end-of-for(ilog) --- */ -return ( nlogged ); /* back to caller */ +end_of_job: return ( nlogged ); /* back to caller */ } /* --- end-of-function logger() --- */ @@ -16480,12 +17983,12 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -int emitcache ( char *cachefile, int maxage, int valign, int isbuffer ) +FUNCSCOPE int emitcache(char *cachefile, int maxage, int valign, int isbuffer) { /* ------------------------------------------------------------------------- Allocations and Declarations -------------------------------------------------------------------------- */ -int nbytes=gifSize, readcachefile(); /* read cache file */ +int nbytes=gifSize /*, readcachefile()*/; /* read cache file */ FILE *emitptr = stdout; /* emit cachefile to stdout */ unsigned char buffer[MAXGIFSZ+1]; /* bytes from cachefile */ unsigned char *buffptr = buffer; /* ptr to buffer */ @@ -16537,6 +18040,14 @@ if ( fwrite(buffptr,sizeof(unsigned char),nbytes,emitptr) /* write buffer */ < nbytes ) /* failed to write all bytes */ nbytes = 0; /* reset total count to 0 */ +if ( isdumpgif && (0 || !isbuffer) ) { /* **debug** dump gif */ + char dumpfile[999]; FILE *dumpptr=NULL; + strcpy(dumpfile,cachefile); + strcat(dumpfile,"_"); strcat(dumpfile,DUMPGIF); + if ( (dumpptr=fopen(dumpfile,"wb")) != NULL ) { + fwrite(buffptr,sizeof(unsigned char),nbytes,dumpptr); + fclose(dumpptr); } + } /* --- end-of-if(isdumpgif) --- */ end_of_job: return ( nbytes ); /* back with #bytes emitted */ } /* --- end-of-function emitcache() --- */ @@ -16557,7 +18068,7 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -int readcachefile ( char *cachefile, unsigned char *buffer ) +FUNCSCOPE int readcachefile ( char *cachefile, unsigned char *buffer ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -16614,7 +18125,7 @@ * Notes: o * ======================================================================= */ /* --- entry point --- */ -int advertisement ( char *expression, char *message ) +FUNCSCOPE int advertisement ( char *expression, char *message ) { /* ------------------------------------------------------------------------- Allocations and Declarations @@ -16634,7 +18145,7 @@ char adbuffer[MAXEXPRSZ+2048]; /*construct wrapped expression here*/ char *beginmath = " ", /* start math mode */ *endmath = " "; /* end math mode */ -int strreplace(); /* replace %%keywords%% with values*/ +/*int strreplace();*/ /* replace %%keywords%% with values*/ /* ------------------------------------------------------------------------- wrap expression in advertisement -------------------------------------------------------------------------- */ @@ -16665,7 +18176,7 @@ * Notes: o From Numerical Recipes in C, 2nd ed, page 900. * ======================================================================= */ /* --- entry point --- */ -int crc16 ( char *s ) +FUNCSCOPE int crc16 ( char *s ) { /* ------------------------------------------------------------------------- Compute the crc @@ -16703,21 +18214,27 @@ * by four functions P1()...P4() to accommodate a problem * with Compaq's vax/vms C compiler. * ======================================================================= */ -/* --- #include "md5.h" --- */ -#ifndef uint8 - #define uint8 unsigned char -#endif -#ifndef uint32 - #define uint32 unsigned long int -#endif -typedef struct - { uint32 total[2]; - uint32 state[4]; - uint8 buffer[64]; - } md5_context; -void md5_starts( md5_context *ctx ); -void md5_update( md5_context *ctx, uint8 *input, uint32 length ); -void md5_finish( md5_context *ctx, uint8 digest[16] ); +#if 0 + /* --- + * >> Note: uint8, uint32 and md5_context now defined in mimetex.h << + * (they're temporarily left here only as comments) + * --------------------------------------------------------------------- */ + /* --- #include "md5.h" --- */ + #ifndef uint8 + #define uint8 unsigned char + #endif + #ifndef uint32 + #define uint32 unsigned long int + #endif + typedef struct + { uint32 total[2]; + uint32 state[4]; + uint8 buffer[64]; + } md5_context; +#endif +FUNCSCOPE void md5_starts( md5_context *ctx ); +FUNCSCOPE void md5_update( md5_context *ctx, uint8 *input, uint32 length ); +FUNCSCOPE void md5_finish( md5_context *ctx, uint8 digest[16] ); /* --- md5.h --- */ #define GET_UINT32(n,b,i) \ { (n) = ( (uint32) (b)[(i) ] ) \ @@ -16730,25 +18247,29 @@ (b)[(i) + 2] = (uint8) ( (n) >> 16 ); \ (b)[(i) + 3] = (uint8) ( (n) >> 24 ); } /* --- P,S,F macros defined as functions --- */ +FUNCSCOPE void P1(uint32 *X,uint32 *a,uint32 b,uint32 c,uint32 d,int k,int s,uint32 t) { *a += (uint32)(d ^ (b & (c ^ d))) + X[k] + t; *a = ((*a<> (32-s))) + b; return; } +FUNCSCOPE void P2(uint32 *X,uint32 *a,uint32 b,uint32 c,uint32 d,int k,int s,uint32 t) { *a += (uint32)(c ^ (d & (b ^ c))) + X[k] + t; *a = ((*a<> (32-s))) + b; return; } +FUNCSCOPE void P3(uint32 *X,uint32 *a,uint32 b,uint32 c,uint32 d,int k,int s,uint32 t) { *a += (uint32)(b ^ c ^ d) + X[k] + t; *a = ((*a<> (32-s))) + b; return; } +FUNCSCOPE void P4(uint32 *X,uint32 *a,uint32 b,uint32 c,uint32 d,int k,int s,uint32 t) { *a += (uint32)(c ^ (b | ~d)) + X[k] + t; *a = ((*a<> (32-s))) + b; return; } /* --- entry point (this one little stub written by me)--- */ -char *md5str( char *instr ) +FUNCSCOPE char *md5str( char *instr ) { static char outstr[64]; unsigned char md5sum[16]; md5_context ctx; @@ -16762,7 +18283,7 @@ return ( outstr ); } /* --- entry point (all md5 functions below by Christophe Devine) --- */ -void md5_starts( md5_context *ctx ) +FUNCSCOPE void md5_starts( md5_context *ctx ) { ctx->total[0] = 0; ctx->total[1] = 0; ctx->state[0] = 0x67452301; @@ -16770,7 +18291,7 @@ ctx->state[2] = 0x98BADCFE; ctx->state[3] = 0x10325476; } -void md5_process( md5_context *ctx, uint8 data[64] ) +FUNCSCOPE void md5_process( md5_context *ctx, uint8 data[64] ) { uint32 X[16], A, B, C, D; GET_UINT32( X[0], data, 0 ); GET_UINT32( X[1], data, 4 ); @@ -16861,7 +18382,7 @@ ctx->state[2] += C; ctx->state[3] += D; } -void md5_update( md5_context *ctx, uint8 *input, uint32 length ) +FUNCSCOPE void md5_update( md5_context *ctx, uint8 *input, uint32 length ) { uint32 left, fill; if( length < 1 ) return; left = ctx->total[0] & 0x3F; @@ -16885,7 +18406,7 @@ memcpy( (void *) (ctx->buffer + left), (void *) input, length ); } -void md5_finish( md5_context *ctx, uint8 digest[16] ) +FUNCSCOPE void md5_finish( md5_context *ctx, uint8 digest[16] ) { static uint8 md5_padding[64] = { 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -16943,4 +18464,3 @@ #endif /* driver */ #endif /* PART1 */ /* ======================= END-OF-FILE MIMETEX.C ========================= */ - diff -Nru mimetex-1.74/mimetex.h mimetex-1.76/mimetex.h --- mimetex-1.74/mimetex.h 2012-09-26 07:25:37.000000000 +0000 +++ mimetex-1.76/mimetex.h 2017-07-11 02:18:41.000000000 +0000 @@ -40,10 +40,35 @@ * 07/04/03 J.Forkosh Version 1.01 released. * --- * 09/06/08 J.Forkosh Version 1.70 released. + * --- + * 07/11/17 J.Forkosh function scope & prototypes for version 1.76 * ***************************************************************************/ +/* --- + * Function Scope and Prototypes (to enable static function scope, + * avoiding function name collisions when compiling together with + * other modules) + * ----------------------------------------------------------------- */ +#if !defined(FUNCSCOPE) + #define FUNCSCOPE static +#endif +#if !defined(FUNCSHARED) + #define FUNCSHARED /*static*/ +#endif + +/* --- + * public entry points + * ---------------------- */ +FUNCSHARED unsigned char *mimetexgetbytemap ( char *expression, + int *width, int *height ); +FUNCSHARED int mimetextypebytemap ( unsigned char *bp, int grayscale, + int width, int height, FILE *fp ); +FUNCSHARED int mimetexsetmsg ( int newmsglevel, FILE *newmsgfp ); + + +#if defined(_MIMETEXMAIN) /* -------------------------------------------------------------------------- check for compilation by parts (not supported yet) -------------------------------------------------------------------------- */ @@ -304,7 +329,7 @@ * ----------------------- */ STATIC int nfontinfo /* legal font#'s are 1...nfontinfo */ #ifdef INITVALS - = 11 + = 12 #endif ; STATIC struct {char *name; int family; int istext; int class;} @@ -324,6 +349,7 @@ { "\\textgreek",CMMI10GR,1,-1 }, /*(9) \textgreek{ab}-->\alpha\beta */ { "\\textbfgreek",CMMI10BGR,1,-1 },/*(10)\textbfgreek{ab}-->\alpha\beta*/ { "\\textbbgreek",BBOLD10GR,1,-1 },/*(11)\textbbgreek{ab}-->\alpha\beta*/ + { "\\textbf", CMMIB10, 1, -1 }, /*(12)\textbf{abc}-->{\mathbf~abc}+space*/ { NULL, 0, 0, 0 } } #endif ; /* --- end-of-fonts[] --- */ @@ -412,11 +438,324 @@ #define FRACRASTER (4) /* image of \frac{}{} */ #define ASCIISTRING (5) /* ascii string (not a raster) */ + +/* --- + * note: point3d.x,y,z are relative to the origin 0.,0.,0. of an abstract + * coordinate system, calculated to be at the center pixel of a raster. + * point3d and matrix3d are used for rotations, as per + * https://en.wikipedia.org/wiki/Rotation_matrix#In_three_dimensions + * in function rotrast3d() + * ------------------------------------------------------------------------ */ +/* --- 3d-point --- */ +#define point3d struct point3d_struct /* "typedef" for point3d_struct */ +point3d { + /* --- x,y,z-coords relative to 0.,0.,0. origin of abstract coord axes --- */ + double x; /* x-coord */ + double y; /* y-coord */ + double z; /* z-coord */ + } ; /* --- end-of-point3d_struct --- */ +/* --- 3d-matrix (rotation matrix) stored row-wise --- */ +#define matrix3d struct matrix3d_struct /* "typedef" for matrix3d_struct */ +matrix3d { + /* --- 3x3 matrix stored row-wise --- */ + point3d xrow; /* x-row */ + point3d yrow; /* y-row */ + point3d zrow; /* z-row */ + } ; /* --- end-of-matrix3d_struct --- */ + +/* ------------------------------------------------------------------------- +store for evalterm() [n.b., these are stripped-down funcs from nutshell] +-------------------------------------------------------------------------- */ +#define STORE struct store_struct /* "typedef" for store struct */ +#define MAXSTORE 100 /* max 100 identifiers */ +STORE { + char *identifier; /* identifier */ + int *value; /* address of corresponding value */ + } ; /* --- end-of-store_struct --- */ + +/* ------------------------------------------------------------------------- +logging data structure (default data to be logged remains in mimetex.c) +-------------------------------------------------------------------------- */ +/* --- logging data structure --- */ +#define logdata struct logdata_struct /* "typedef" for logdata_struct*/ +logdata { + /* ----------------------------------------------------------------------- + environment variable name, max #chars to display, min msglevel to display + ------------------------------------------------------------------------ */ + char *name; /* environment variable name */ + int maxlen; /* max #chars to display */ + int msglevel; /* min msglevel to display data */ + } ; /* --- end-of-logdata_struct --- */ + /* --- - * issue rasterize() call end extract embedded raster from returned subraster - * -------------------------------------------------------------------------- */ -subraster *rasterize(); /* declare rasterize */ -#define make_raster(expression,size) ((rasterize(expression,size))->image) + * from #include "md5.h" (for md5 functions) + * -------------------------------------------- */ +#ifndef uint8 + #define uint8 unsigned char +#endif +#ifndef uint32 + #define uint32 unsigned long int +#endif +typedef struct + { uint32 total[2]; + uint32 state[4]; + uint8 buffer[64]; + } md5_context; + +/* --- + * Function Prototypes and Scope (to enable static function scope, + * avoiding function name collisions when compiling together with + * other modules) + * ----------------------------------------------------------------- */ +FUNCSCOPE raster *new_raster ( int width, int height, int pixsz ); +FUNCSCOPE subraster *new_subraster ( int width, int height, int pixsz ); +FUNCSCOPE chardef *new_chardef ( ); +FUNCSCOPE int delete_raster ( raster *rp ); +FUNCSCOPE int delete_subraster ( subraster *sp ); +FUNCSCOPE int delete_chardef ( chardef *cp ); +FUNCSCOPE raster *rastcpy ( raster *rp ); +FUNCSCOPE subraster *subrastcpy ( subraster *sp ); +FUNCSCOPE raster *rastrot ( raster *rp ); +FUNCSCOPE raster *rastrot3d ( raster *rp, point3d *axis, double theta ); +FUNCSCOPE raster *rastmag ( raster *rp, int magstep ); +FUNCSCOPE intbyte *bytemapmag ( intbyte *bytemap, + int width, int height, int magstep ); +FUNCSCOPE raster *rastref ( raster *rp, int axis ); +FUNCSCOPE int rastput ( raster *target, raster *source, + int top, int left, int isopaque ); +FUNCSCOPE subraster *rastcompose ( subraster *sp1, subraster *sp2, + int offset2, int isalign, int isfree ); +FUNCSCOPE subraster *rastcat ( subraster *sp1, subraster *sp2, int isfree ); +FUNCSCOPE subraster *rastack ( subraster *sp1, subraster *sp2, int base, + int space, int iscenter, int isfree ); +FUNCSCOPE raster *rastile ( subraster *tiles, int ntiles ); +FUNCSCOPE int rastsmash ( subraster *sp1, subraster *sp2 ); +FUNCSCOPE int rastsmashcheck ( char *term ); +FUNCSCOPE subraster *accent_subraster ( int accent, int width, int height, + int direction, int pixsz ); +FUNCSCOPE subraster *arrow_subraster ( int width, int height, int pixsz, + int drctn, int isBig ); +FUNCSCOPE subraster *uparrow_subraster ( int width, int height, int pixsz, + int drctn, int isBig ); +FUNCSCOPE int rule_raster ( raster *rp, int top, int left, + int width, int height, int type ); +FUNCSCOPE int line_raster ( raster *rp, int row0, int col0, + int row1, int col1, int thickness ); +FUNCSCOPE int line_recurse ( raster *rp, double row0, double col0, + double row1, double col1, int thickness ); +FUNCSCOPE int circle_raster ( raster *rp, int row0, int col0, + int row1, int col1, int thickness, char *quads ); +FUNCSCOPE int circle_recurse ( raster *rp, int row0, int col0, int row1, + int col1, int thickness, double theta0, double theta1 ); +FUNCSCOPE int bezier_raster ( raster *rp, double r0, double c0, + double r1, double c1, double rt, double ct ); +FUNCSCOPE raster *border_raster ( raster *rp, int ntop, int nbot, + int isline, int isfree ); +FUNCSCOPE raster *backspace_raster ( raster *rp, int nback, int *pback, + int minspace, int isfree ); +FUNCSCOPE int type_raster ( raster *rp, FILE *fp ); +FUNCSCOPE int type_bytemap ( intbyte *bp, int grayscale, + int width, int height, FILE *fp ); +FUNCSCOPE int xbitmap_raster ( raster *rp, FILE *fp ); +FUNCSCOPE int type_pbmpgm ( raster *rp, int ptype, char *file ); +FUNCSCOPE subraster *read_pbm ( FILE *fp, double sf ); +FUNCSCOPE int cstruct_chardef ( chardef *cp, FILE *fp, int col1 ); +FUNCSCOPE int cstruct_raster ( raster *rp, FILE *fp, int col1 ); +FUNCSCOPE int hex_bitmap ( raster *rp, FILE *fp, int col1, int isstr ); +FUNCSCOPE int emit_string ( FILE *fp, int col1, char *string, + char *comment ); +FUNCSCOPE raster *gftobitmap ( raster *gf ); +FUNCSCOPE mathchardef *get_symdef ( char *symbol ); +FUNCSCOPE int get_ligature ( char *expression, int family ); +FUNCSCOPE chardef *get_chardef ( mathchardef *symdef, int size ); +FUNCSCOPE subraster *get_charsubraster ( mathchardef *symdef, int size ); +FUNCSCOPE subraster *get_symsubraster ( char *symbol, int size ); +FUNCSCOPE int get_baseline ( chardef *gfdata ); +FUNCSCOPE subraster *get_delim ( char *symbol, int height, int family ); +FUNCSCOPE subraster *make_delim ( char *symbol, int height ); +FUNCSCOPE char *texchar ( char *expression, char *chartoken ); +FUNCSCOPE char *texsubexpr ( char *expression, char *subexpr, + int maxsubsz, char *left, char *right, + int isescape, int isdelim ); +FUNCSCOPE char *texleft ( char *expression, char *subexpr, int maxsubsz, + char *ldelim, char *rdelim ); +FUNCSCOPE char *texscripts ( char *expression, char *subscript, + char *superscript, int which ); +FUNCSCOPE int isbrace ( char *expression, char *braces, int isescape ); +FUNCSCOPE char *preamble ( char *expression, int *size, char *subexpr ); +FUNCSCOPE char *mimeprep ( char *expression ); +FUNCSCOPE char *strchange ( int nfirst, char *from, char *to ); +FUNCSCOPE int strreplace(char *string,char *from,char *to,int nreplace); +FUNCSCOPE char *strwstr(char *string,char *substr,char *white,int *sublen); +FUNCSCOPE char *strdetex ( char *s, int mode ); +FUNCSCOPE char *strtexchr ( char *string, char *texchr ); +FUNCSCOPE char *findbraces ( char *expression, char *command ); +/*FUNCSCOPE char *strpspn ( char *s, char *reject, char *segment );*/ +FUNCSCOPE int isstrstr ( char *string, char *snippets, int iscase ); +FUNCSCOPE int isnumeric ( char *s ); +FUNCSCOPE int evalterm ( STORE *store, char *term ); +FUNCSCOPE int getstore ( STORE *store, char *identifier ); +FUNCSCOPE char *getdirective ( char *string, char *directive, + int iscase, int isvalid, int nargs, void *args ); +FUNCSCOPE char *strpspn ( char *s, char *reject, char *segment ); +FUNCSCOPE char *strqspn ( char *s, char *q, int isunescape ); +FUNCSCOPE int unescape_url(char *url, int isescape); +FUNCSCOPE char x2c(char *what); +FUNCSCOPE subraster *rasterize ( char *expression, int size ); +FUNCSCOPE subraster *rastparen ( char **subexpr, int size, subraster *basesp ); +FUNCSCOPE subraster *rastlimits ( char **expression, int size, + subraster *basesp ); +FUNCSCOPE subraster *rastscripts ( char **expression, int size, + subraster *basesp ); +FUNCSCOPE subraster *rastdispmath (char **expression, int size, subraster *sp); +/* --- + * handler functions for math operations + * ---------------------------------------- */ +FUNCSCOPE subraster *rastleft ( char **expression, int size, subraster *basesp, + int ildelim, int arg2, int arg3 ); +FUNCSCOPE subraster *rastright(char **expression, int size, subraster *basesp, + int ildelim, int arg2, int arg3); +FUNCSCOPE subraster *rastmiddle(char **expression, int size, subraster *basesp, + int arg1, int arg2, int arg3); +FUNCSCOPE subraster *rastflags(char **expression, int size, subraster *basesp, + int flag, int value, int arg3); +FUNCSCOPE subraster *rastspace(char **expression, int size, subraster *basesp, + int width, int isfill, int isheight); +FUNCSCOPE subraster *rastnewline ( char **expression, int size, + subraster *basesp, int arg1, int arg2, int arg3 ); +FUNCSCOPE subraster *rastarrow(char **expression, int size, subraster *basesp, + int drctn, int isBig, int arg3); +FUNCSCOPE subraster *rastuparrow ( char **expression, int size, + subraster *basesp, int drctn, int isBig, int arg3 ); +FUNCSCOPE subraster *rastoverlay ( char **expression, int size, + subraster *basesp, int overlay, int offset2, int arg3 ); +FUNCSCOPE subraster *rastfrac(char **expression, int size, subraster *basesp, + int isfrac, int arg2, int arg3); +FUNCSCOPE subraster *rastackrel ( char **expression, int size, + subraster *basesp, int base, int arg2, int arg3 ); +FUNCSCOPE subraster *rastmathfunc ( char **expression, int size, + subraster *basesp, int mathfunc, int islimits, int arg3 ); +FUNCSCOPE subraster *rastsqrt(char **expression, int size, subraster *basesp, + int arg1, int arg2, int arg3); +FUNCSCOPE subraster *rastaccent ( char **expression, int size, + subraster *basesp, int accent, int isabove, int isscript ); +FUNCSCOPE subraster *rastfont(char **expression, int size, subraster *basesp, + int ifontnum, int arg2, int arg3); +FUNCSCOPE subraster *rastbegin(char **expression, int size, subraster *basesp, + int arg1, int arg2, int arg3); +FUNCSCOPE subraster *rastarray(char **expression, int size, subraster *basesp, + int arg1, int arg2, int arg3); +FUNCSCOPE subraster *rastpicture ( char **expression, int size, + subraster *basesp, int arg1, int arg2, int arg3 ); +FUNCSCOPE subraster *rastline(char **expression, int size, subraster *basesp, + int arg1, int arg2, int arg3); +FUNCSCOPE subraster *rastrule(char **expression, int size, subraster *basesp, + int arg1, int arg2, int arg3); +FUNCSCOPE subraster *rastcircle ( char **expression, int size, + subraster *basesp, int arg1, int arg2, int arg3 ); +FUNCSCOPE subraster *rastbezier ( char **expression, int size, + subraster *basesp, int arg1, int arg2, int arg3 ); +FUNCSCOPE subraster *rastraise(char **expression, int size, subraster *basesp, + int arg1, int arg2, int arg3); +FUNCSCOPE subraster *rastrotate ( char **expression, int size, + subraster *basesp, int arg1, int arg2, int arg3 ); +FUNCSCOPE subraster *rastmagnify ( char **expression, int size, + subraster *basesp, int arg1, int arg2, int arg3 ); +FUNCSCOPE subraster *rastreflect ( char **expression, int size, + subraster *basesp, int arg1, int arg2, int arg3 ); +FUNCSCOPE subraster *rastfbox(char **expression, int size, subraster *basesp, + int arg1, int arg2, int arg3); +FUNCSCOPE subraster *rastovalbox ( char **expression, int size, + subraster *basesp, int arg1, int arg2, int arg3 ); +FUNCSCOPE subraster *rastinput(char **expression, int size, subraster *basesp, + int arg1, int arg2, int arg3); +FUNCSCOPE subraster *rastcounter ( char **expression, int size, + subraster *basesp, int arg1, int arg2, int arg3 ); +FUNCSCOPE subraster *rasteval(char **expression, int size, subraster *basesp, + int arg1, int arg2, int arg3 ); +FUNCSCOPE subraster *rastmathtex ( char **expression, int size, + subraster *basesp, int arg1, int arg2, int arg3 ); +FUNCSCOPE subraster *rasttoday(char **expression, int size, subraster *basesp, + int arg1, int arg2, int arg3); +FUNCSCOPE subraster *rastcalendar ( char **expression, int size, + subraster *basesp, int arg1, int arg2, int arg3 ); +FUNCSCOPE subraster *rastenviron ( char **expression, int size, + subraster *basesp, int arg1, int arg2, int arg3 ); +FUNCSCOPE subraster *rastmessage ( char **expression, int size, + subraster *basesp, int arg1, int arg2, int arg3 ); +FUNCSCOPE subraster *rastnoop(char **expression, int size, subraster *basesp, + int nargs, int arg2, int arg3); +/* --- end-of-handler-functions-for-math-operations --- */ +FUNCSCOPE FILE *rastopenfile ( char *filename, char *mode ); +FUNCSCOPE char *rasteditfilename ( char *filename ); +FUNCSCOPE int rastreadfile ( char *filename, int islock, + char *tag, char *value ); +FUNCSCOPE int rastwritefile ( char *filename,char *tag, + char *value, int isstrict ); +FUNCSCOPE char *calendar( int year, int month, int day ); +FUNCSCOPE char *timestamp( int tzdelta, int ifmt ); +FUNCSCOPE int tzadjust ( int tzdelta, + int *year, int *month, int *day, int *hour ); +FUNCSCOPE int daynumber ( int year, int month, int day ); +FUNCSCOPE char *strwrap ( char *s, int linelen, int tablen ); +FUNCSCOPE char *strnlower ( char *s, int n ); +FUNCSCOPE char *urlprune ( char *url, int n ); +FUNCSCOPE int urlncmp ( char *url1, char *url2, int n ); +FUNCSCOPE char *dbltoa ( double dblval, int npts ); +FUNCSCOPE matrix3d *rotmatrix ( point3d *axis, double theta ); +FUNCSCOPE point3d *matmult ( matrix3d *mat, point3d *vec ); +FUNCSCOPE int aalowpass (raster *rp, intbyte *bytemap, int grayscale); +FUNCSCOPE int aapnm (raster *rp, intbyte *bytemap, int grayscale); +FUNCSCOPE int aapnmlookup (raster *rp, intbyte *bytemap, int grayscale); +FUNCSCOPE int aapatterns ( raster *rp, int irow, int icol, + int gridnum, int patternum, int grayscale ); +FUNCSCOPE int aapattern1124 ( raster *rp, int irow, int icol, + int gridnum, int grayscale ); +FUNCSCOPE int aapattern19 ( raster *rp, int irow, int icol, + int gridnum, int grayscale ); +FUNCSCOPE int aapattern20 ( raster *rp, int irow, int icol, + int gridnum, int grayscale ); +FUNCSCOPE int aapattern39 ( raster *rp, int irow, int icol, + int gridnum, int grayscale ); +FUNCSCOPE int aafollowline ( raster *rp, int irow, int icol, + int direction ); +FUNCSCOPE int aagridnum ( raster *rp, int irow, int icol ); +FUNCSCOPE int aapatternnum ( int gridnum ); +FUNCSCOPE int aalookup ( int gridnum ); +FUNCSCOPE int aalowpasslookup ( raster *rp, intbyte *bytemap, + int grayscale ); +FUNCSCOPE int aasupsamp(raster *rp, raster **aa, int sf, int grayscale); +FUNCSCOPE raster *imgsupsamp ( raster *rp, double sf, int grayscale ); +FUNCSCOPE int ssweights(int width, int height, int maxwt, raster **wts); +FUNCSCOPE int aacolormap ( intbyte *bytemap, int nbytes, + intbyte *colors, intbyte *colormap ); +FUNCSCOPE raster *aaweights ( int width, int height ); +FUNCSCOPE int aawtpixel(raster *image, int ipixel, raster *weights, + int rotate); +FUNCSHARED int mimetexsetmsg ( int newmsglevel, FILE *newmsgfp ); +FUNCSHARED unsigned char *mimetexgetbytemap ( char *expression, + int *width, int *height ); + /* int main ( int argc, char *argv[] ); */ + /* int CreateGifFromEq ( char *expression, char *gifFileName ); */ +FUNCSCOPE int ismonth ( char *month ); +FUNCSCOPE int logger ( FILE *logfp, int msglevel, + char *message, logdata *logvars ); +FUNCSCOPE int emitcache(char *cachefile, int maxage, int valign, + int isbuffer); +FUNCSCOPE int readcachefile ( char *cachefile, unsigned char *buffer ); +FUNCSCOPE int advertisement ( char *expression, char *message ); +FUNCSCOPE int crc16 ( char *s ); +FUNCSCOPE void + P1(uint32 *X,uint32 *a,uint32 b,uint32 c,uint32 d,int k,int s,uint32 t), + P2(uint32 *X,uint32 *a,uint32 b,uint32 c,uint32 d,int k,int s,uint32 t), + P3(uint32 *X,uint32 *a,uint32 b,uint32 c,uint32 d,int k,int s,uint32 t), + P4(uint32 *X,uint32 *a,uint32 b,uint32 c,uint32 d,int k,int s,uint32 t); +FUNCSCOPE char *md5str( char *instr ); +FUNCSCOPE void md5_starts(md5_context *ctx); +FUNCSCOPE void md5_process(md5_context *ctx, uint8 data[64]); +FUNCSCOPE void md5_update(md5_context *ctx, uint8 *input, uint32 length); +FUNCSCOPE void md5_finish(md5_context *ctx, uint8 digest[16]); + /* int GetPixel ( int x, int y ); */ /* ------------------------------------------------------------------------- @@ -569,41 +908,47 @@ /* --- * handler functions for math operations - * ------------------------------------- */ -subraster *rastflags(); /* set flags, e.g., for \rm */ -subraster *rastfrac(); /* handle \frac \atop expressions */ -subraster *rastackrel(); /* handle \stackrel expressions */ -subraster *rastmathfunc(); /* handle \lim,\log,etc expressions*/ -subraster *rastoverlay(); /* handle \not */ -subraster *rastspace(); /* handle math space, \hspace,\hfill*/ -subraster *rastnewline(); /* handle \\ newline */ -subraster *rastarrow(); /* handle \longrightarrow, etc */ -subraster *rastuparrow(); /* handle \longuparrow, etc */ -subraster *rastsqrt(); /* handle \sqrt */ -subraster *rastaccent(); /* handle \hat \vec \braces, etc */ -subraster *rastfont(); /* handle \cal{} \scr{}, etc */ -subraster *rastbegin(); /* handle \begin{}...\end{} */ -subraster *rastleft(); /* handle \left...\right */ -subraster *rastmiddle(); /* handle \left...\middle...\right */ -subraster *rastarray(); /* handle \array{...} */ -subraster *rastpicture(); /* handle \picture(,){...} */ -subraster *rastline(); /* handle \line(xinc,yinc){xlen} */ -subraster *rastrule(); /* handle \rule[lift]{width}{height}*/ -subraster *rastcircle(); /* handle \circle(xdiam[,ydiam]) */ -subraster *rastbezier(); /*handle\bezier(c0,r0)(c1,r1)(ct,rt)*/ -subraster *rastraise(); /* handle \raisebox{lift}{expr} */ -subraster *rastrotate(); /* handle \rotatebox{degs}{expr} */ -subraster *rastmagnify(); /* handle \magnify{magstep}{expr} */ -subraster *rastreflect(); /* handle \reflectbox[axis]{expr} */ -subraster *rastfbox(); /* handle \fbox{expr} */ -subraster *rastinput(); /* handle \input{filename} */ -subraster *rastcounter(); /* handle \counter{filename} */ -subraster *rasteval(); /* handle \eval{expression} */ -subraster *rasttoday(); /* handle \today[+/-tzdelta,ifmt] */ -subraster *rastcalendar(); /* handle \calendar[yaer,month] */ -subraster *rastenviron(); /* handle \environment */ -subraster *rastmessage(); /* handle \message */ -subraster *rastnoop(); /* handle \escape's to be flushed */ + * ---------------------------------------- */ +#if 0 /* --- now declared above --- */ + FUNCSCOPE subraster + *rastflags(), /* set flags, e.g., for \rm */ + *rastfrac(), /* handle \frac \atop expressions */ + *rastackrel(), /* handle \stackrel expressions */ + *rastmathfunc(), /* handle \lim,\log,etc expressions*/ + *rastoverlay(), /* handle \not */ + *rastspace(), /* handle math space, \hspace,\hfill*/ + *rastnewline(), /* handle \\ newline */ + *rastarrow(), /* handle \longrightarrow, etc */ + *rastuparrow(), /* handle \longuparrow, etc */ + *rastsqrt(), /* handle \sqrt */ + *rastaccent(), /* handle \hat \vec \braces, etc */ + *rastfont(), /* handle \cal{} \scr{}, etc */ + *rastbegin(), /* handle \begin{}...\end{} */ + *rastleft(), /* handle \left...\right */ + *rastmiddle(), /* handle \left...\middle...\right */ + *rastarray(), /* handle \array{...} */ + *rastpicture(), /* handle \picture(,){...} */ + *rastline(), /* handle \line(xinc,yinc){xlen} */ + *rastrule(), /* handle \rule[lift]{width}{height}*/ + *rastcircle(), /* handle \circle(xdiam[,ydiam]) */ + *rastbezier(), /* handle\bezier(c0,r0)(c1,r1)(ct,rt)*/ + *rastraise(), /* handle \raisebox{lift}{expr} */ + *rastrotate(), /* handle \rotatebox{degs}{expr} */ + *rastmagnify(), /* handle \magnify{magstep}{expr} */ + *rastreflect(), /* handle \reflectbox[axis]{expr} */ + *rastfbox(), /* handle \fbox{expr} */ + *rastovalbox(), /* handle \ovalbox{expr} */ + *rastinput(), /* handle \input{filename} */ + *rastcounter(), /* handle \counter{filename} */ + *rasteval(), /* handle \eval{expression} */ + *rastmathtex(), /* handle \mathtex{expression} */ + *rasttoday(), /* handle \today[+/-tzdelta,ifmt] */ + *rastcalendar(), /* handle \calendar[yaer,month] */ + *rastenviron(), /* handle \environment */ + *rastmessage(), /* handle \message */ + *rastnoop() /* handle \escape's to be flushed */ + ; /* --- end-of-functions-for-math-operations --- */ +#endif /* --- sqrt --- */ #define SQRTACCENT (1) /* \sqrt */ @@ -641,6 +986,7 @@ #define ISCONTENTTYPE (13) /*enable/disable Content-type lines*/ #define ISCONTENTCACHED (14) /* write Content-type to cache file*/ #define ISPBMPGM (15) /* write pbm/pgm (instead of gif) */ +#define ISUTHETA (16) /* 3d-rotation angle for chars */ /* --- * mathchardefs for symbols recognized by mimetex @@ -676,6 +1022,7 @@ { "\\array",NOVALUE,NOVALUE,NOVALUE, (HANDLER)(rastarray) }, { "\\matrix",NOVALUE,NOVALUE,NOVALUE, (HANDLER)(rastarray) }, { "\\tabular",NOVALUE,NOVALUE,NOVALUE,(HANDLER)(rastarray) }, + { "\\center",NOVALUE,NOVALUE,NOVALUE, (HANDLER)(rastarray) }, { "\\picture",NOVALUE,NOVALUE,NOVALUE,(HANDLER)(rastpicture) }, { "\\line", NOVALUE,NOVALUE,NOVALUE, (HANDLER)(rastline) }, { "\\rule", NOVALUE,NOVALUE,NOVALUE, (HANDLER)(rastrule) }, @@ -689,8 +1036,10 @@ { "\\reflectbox",NOVALUE,NOVALUE,NOVALUE,(HANDLER)(rastreflect) }, { "\\fbox", NOVALUE,NOVALUE,NOVALUE, (HANDLER)(rastfbox) }, { "\\boxed",NOVALUE,NOVALUE,NOVALUE, (HANDLER)(rastfbox) }, + { "\\ovalbox", NOVALUE,NOVALUE,NOVALUE,(HANDLER)(rastovalbox) }, { "\\input",NOVALUE,NOVALUE,NOVALUE, (HANDLER)(rastinput) }, { "\\evaluate",NOVALUE,NOVALUE,NOVALUE,(HANDLER)(rasteval) }, + { "\\mathtex",NOVALUE,NOVALUE,NOVALUE,(HANDLER)(rastmathtex) }, { "\\today",NOVALUE,NOVALUE,NOVALUE, (HANDLER)(rasttoday) }, { "\\calendar",NOVALUE,NOVALUE,NOVALUE,(HANDLER)(rastcalendar) }, { "\\environment",NOVALUE,NOVALUE,NOVALUE,(HANDLER)(rastenviron) }, @@ -740,7 +1089,7 @@ { "\\mathbb", 5, NOVALUE,NOVALUE, (HANDLER)(rastfont) }, { "\\rm", 3, NOVALUE,NOVALUE, (HANDLER)(rastfont) }, { "\\text", 3, NOVALUE,NOVALUE, (HANDLER)(rastfont) }, - { "\\textbf", 3, NOVALUE,NOVALUE, (HANDLER)(rastfont) }, + { "\\textbf", 12, NOVALUE,NOVALUE, (HANDLER)(rastfont) }, { "\\textrm", 3, NOVALUE,NOVALUE, (HANDLER)(rastfont) }, { "\\mathrm", 7, NOVALUE,NOVALUE, (HANDLER)(rastfont) }, { "\\cyr", 8, NOVALUE,NOVALUE, (HANDLER)(rastfont) }, @@ -800,6 +1149,7 @@ { "\\aaalg",ISAAALGORITHM, NOVALUE,NOVALUE, (HANDLER)(rastflags) }, { "\\pnmparams",PNMPARAMS, NOVALUE,NOVALUE, (HANDLER)(rastflags) }, { "\\pbmpgm", ISPBMPGM, NOVALUE,NOVALUE, (HANDLER)(rastflags) }, + { "\\utheta", ISUTHETA, NOVALUE,NOVALUE, (HANDLER)(rastflags) }, { "\\gammacorrection",ISGAMMA,NOVALUE,NOVALUE,(HANDLER)(rastflags) }, { "\\nocontenttype",ISCONTENTTYPE, 0,NOVALUE, (HANDLER)(rastflags) }, { "\\nodepth", ISCONTENTCACHED, 0,NOVALUE, (HANDLER)(rastflags) }, @@ -1196,6 +1546,7 @@ { "\\div", 4, CMSY10, BINARYOP, NULL }, { "\\diamond", 5, CMSY10, BINARYOP, NULL }, { "\\pm", 6, CMSY10, BINARYOP, NULL }, + { "\\plusminus", 6, CMSY10, BINARYOP, NULL }, { "\\mp", 7, CMSY10, BINARYOP, NULL }, { "\\oplus", 8, CMSY10, BINARYOP, NULL }, { "\\ominus", 9, CMSY10, BINARYOP, NULL }, @@ -2254,7 +2605,7 @@ } #endif /* INITVALS */ ; /* --- end-of-symtable[] --- */ - /* ======================= END-OF-FILE MIMETEX.H ========================= */ -#endif +#endif /*defined(_MIMETEXMAIN)*/ +#endif /*defined(_MIMETEX)*/ diff -Nru mimetex-1.74/mimetex.html mimetex-1.76/mimetex.html --- mimetex-1.74/mimetex.html 2013-09-12 10:13:01.000000000 +0000 +++ mimetex-1.76/mimetex.html 2017-07-11 06:04:54.000000000 +0000 @@ -1,6 +1,6 @@ + that's vertically aligned with your surrounding text. Along with several standard @@ -1444,13 +1451,13 @@ $mimetexurl = "http://www.yourdomain.com/cgi-bin/mimetex.cgi?"; function verticalalign( $expression ) { global $mimetexurl; - // note: curl_init() stops at the first whitespace char in $url argument - $expression = ereg_replace(" ","~",$expression); // so remove whitespace $url = $mimetexurl . "\depth~" . $expression; + $referer = $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF']; $valign = "0"; $ch = curl_init( $url ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt( $ch, CURLOPT_HEADER, true ); + curl_setopt( $ch, CURLOPT_REFERER, $referer ); $gif = curl_exec( $ch ); $errno = curl_errno( $ch ); curl_close( $ch ); @@ -1463,6 +1470,9 @@ } function mimetextag( $expression ) { global $mimetexurl; + // note: curl_init() stops at the first whitespace char in $url argument + $expression = preg_replace("{ }","~",$expression); //so remove whitespace + $expression = preg_replace("{\n}","~",$expression); // and newlines $valign = verticalalign($expression); $url = $mimetexurl . "\depth~" . $expression; echo ' <img src="',$url,'" '; @@ -1474,10 +1484,12 @@

Now you can write   <?php mimetextag('\frac12\left(a^2+b^2\right)'); ?> wherever you want to see - + alt="" border=0 style="Vertical-Align:-7px"> + correctly aligned. Note that the php code automatically prepends  \depth  to your expression for you.