*** dvi2ps-1.8j/Makefile.ORG	Wed Dec  9 18:16:35 1992
--- dvi2ps-1.8j/Makefile	Thu Oct 13 09:31:52 1994
***************
*** 36,43 ****
  NOPACKHDRFILE = ${DVI2LIB}/tex.ps.nopack
  FIXFONTS = ASCII-LW-fix.ps
  
! #CFLAGS = -O #-DSYSV
! CFLAGS = -g #-DSYSV
  CNFCFLAGS = ${CFLAGS} -DDVI2LIB=\"${DVI2LIB}\" -DFONTDESC=\"${FONTDESC}\" \
  	-DPAGEREVERSE=${PAGEREVERSE}
  DEVCFLAGS = ${CFLAGS} -DHDRFILE=\"${HDRFILE}\" -DRESOLUTION=${RESOLUTION} \
--- 36,43 ----
  NOPACKHDRFILE = ${DVI2LIB}/tex.ps.nopack
  FIXFONTS = ASCII-LW-fix.ps
  
! #CFLAGS = -O #-DSYSV -DSVR4 -DUSE_AUTO_FONT
! CFLAGS = -g -DSYSV -DSVR4 -DUSE_AUTO_FONT
  CNFCFLAGS = ${CFLAGS} -DDVI2LIB=\"${DVI2LIB}\" -DFONTDESC=\"${FONTDESC}\" \
  	-DPAGEREVERSE=${PAGEREVERSE}
  DEVCFLAGS = ${CFLAGS} -DHDRFILE=\"${HDRFILE}\" -DRESOLUTION=${RESOLUTION} \
***************
*** 60,66 ****
--- 60,68 ----
  	rastfont.c \
  	bifont.c \
  	compfont.c \
+ 	autofont.c \
  	kanji.c open.c io.c util.c \
+ 	xxstdio.c \
  	version.c \
  	ps.c psspecial.c psrast.c psjxl4.c psbi.c
  
***************
*** 71,77 ****
--- 73,81 ----
  	rastfont.o \
  	bifont.o \
  	compfont.o \
+ 	autofont.o \
  	kanji.o open.o io.o util.o \
+ 	xxstdio.o \
  	version.o
  PSOBJS = ps.o psspecial.o psrast.o psjxl4.o psbi.o
  
***************
*** 124,130 ****
  dconv.o : dconv.h
  run.o: defs.h
  mag.o: defs.h
! fontdesc.o: defs.h
  scanfont.o: dconv.h defs.h set.h
  virfont.o: defs.h set.h virfont.h
  vfdcom.o: dconv.h defs.h
--- 128,134 ----
  dconv.o : dconv.h
  run.o: defs.h
  mag.o: defs.h
! fontdesc.o: defs.h Makefile
  scanfont.o: dconv.h defs.h set.h
  virfont.o: defs.h set.h virfont.h
  vfdcom.o: dconv.h defs.h
***************
*** 134,139 ****
--- 138,144 ----
  jxl4font.o: defs.h rastfont.h jxl4.h
  rastfont.o: file.h defs.h rastfont.h
  compfont.o: defs.h compfont.h
+ autofont.o: defs.h file.h rastfont.h
  bifont.o: file.h defs.h bifont.h jsub.h
  kanji.o: defs.h jsub.h
  open.o: defs.h
*** dvi2ps-1.8j/README.svr4.ORG	Thu Oct 13 09:31:55 1994
--- dvi2ps-1.8j/README.svr4	Thu Oct 13 09:54:43 1994
***************
*** 0 ****
--- 1,46 ----
+ 
+ This is a patched version of dvi2ps-1.8j for System V Rel.4 machines.
+ 
+ This patch provides the following two feature.
+ 
+  1. Performance improvement. SVR4's fseek function flushes the stream
+     buffer unconditionally.  This causes a great performance problem when
+     dvi2ps accesses font glyphs.  The patched version uses wrapper routines
+     defined in xxstdio.c of the system's standard I/O to get rid of
+     redundant buffer flushes.
+ 
+  2. You can take a chance to generate missing fonts automatically by a
+     program such as MakeTeXPK, which can be found in dvips package, by
+     putting a new keyword "autoexec" and a new font type "auto" into the
+     fontdesc file. On visiting a "font" line of "auto" type in the
+     fontdesc, dvi2ps executes the program specified by the "autexec"
+     keyword, in which "%R" and "%M" are substituted by the resolution of
+     the current device and the required magnification in magstep,
+     respectively.  The "autoexec" line must preceed the "font" lines
+     of "auto" types in the fontdesc file.  This feature does not depend
+     on SVR4, so can be enabled on any system.  You have to add
+     -DUSE_AUTO_FONT to CFLAGS in Makefile to enable this.  The following
+     is a fontdesc example which executes MakeTeXPK for missing fonts.
+ 
+     #
+     # Specify the program for automatic font generation, which is
+     # supposed to put new PK fonts into /opt/tex/lib/fonts/pk/auto.
+     autoexec	/opt/xdvi/bin/MakeTeXPK %f %m %R magstep\(%M\)
+     #
+     # First check the prepared PK fonts.
+     font	pk * 3		/opt/tex/lib/fonts/pk/core/%f.%mpk
+     #
+     # Next check the PK fonts generated automatically before.
+     font	pk * 3		/opt/tex/lib/fonts/pk/auto/%f.%mpk
+     #
+     # Try to generate the font by MakeTeXPK if its tfm file exists.
+     font	auto * 0	/opt/tex/lib/fonts/tfm/%f.tfm
+     #
+     # Check the font generated automatically now.
+     font	pk * 3		/opt/tex/lib/fonts/pk/auto/%f.%mpk
+ 
+ 
+ 						    October 12, 1994
+ 
+ 			Hiroshi Nakano <nakano@rins.ryukoku.ac.jp>
+ 			Ryukoku Univ., Seta, Otsu, Japan
*** dvi2ps-1.8j/autofont.c.ORG	Thu Oct 13 09:31:54 1994
--- dvi2ps-1.8j/autofont.c	Thu Oct 13 09:31:54 1994
***************
*** 0 ****
--- 1,75 ----
+ /*
+  *	autofont.c
+  */
+ 
+ #include	<stdio.h>
+ #include	"defs.h"
+ #include	"global.h"
+ #include	"file.h"
+ #include	"rastfont.h"
+ 
+ #ifdef USE_AUTO_FONT
+ #ifndef DEV_NULL_PATH
+ #define DEV_NULL_PATH	"/dev/null"
+ #endif
+ 
+ int autotype_access();
+ void init_auto_fontinfo();
+ 
+ struct fontop autoop = {
+     "auto",
+     autotype_access,
+     init_auto_fontinfo,	/* never called */
+ };
+ 
+ extern char autoexec[];	/* fontdesc.c */
+ 
+ int
+ autotype_access(proto, fe, acca)
+ char *proto;
+ struct font_entry *fe;
+ struct accarg *acca;
+ {
+     int out;
+     FILE *devnull;
+     char execline[PATHLEN+1];
+ 
+     if (acca->acc_mode != ACC_EXACT)
+ 	return 0;
+ 
+     acca->pv_mag = ROUND(acca->actmagfact*resolution);
+     pave(fe->name, proto, acca);
+ #ifdef DEBUG
+     if (Debug)
+ 	fprintf(stderr, "trying to access %s\n", fe->name);
+ #endif
+     if (access(fe->name, R_OK))
+ 	return 0;
+ 	
+     pave(execline, autoexec, acca);
+ 
+     fflush(stdout);
+     out = dup(fileno(stdout));
+     /* We use fopen(3) instead of open(2) to improve portability. */
+     devnull = fopen(DEV_NULL_PATH, "w");
+     dup2(fileno(devnull), fileno(stdout));
+     fclose (devnull);
+ 
+     if (system(execline))
+ 	fprintf(stderr, "auto font generation failed : %s\n", execline);
+ 
+     dup2(out, fileno(stdout));
+     close(out);
+ 
+     return 0;
+ }
+ 
+ void
+ init_auto_fontinfo(fe)
+ struct font_entry *fe;
+ {
+     /* Never Visit */
+     return;
+ }
+ #endif /* USE_AUTO_FONT */
+ 
*** dvi2ps-1.8j/file.h.ORG	Tue Oct 31 19:11:04 1989
--- dvi2ps-1.8j/file.h	Thu Oct 13 09:31:52 1994
***************
*** 3,7 ****
--- 3,10 ----
   */
  #ifdef SYSV
  #include	<sys/types.h>
+ #ifdef SVR4
+ #include	<unistd.h>
  #endif
+ #endif
  #include	<sys/file.h>
*** dvi2ps-1.8j/fontdesc.c.ORG	Thu Dec 10 00:00:00 1992
--- dvi2ps-1.8j/fontdesc.c	Thu Oct 13 09:31:52 1994
***************
*** 2,8 ****
--- 2,16 ----
  #include	"defs.h"
  #include	"global.h"
  
+ #ifdef USE_AUTO_FONT
+ #include	<math.h>
+ extern int resolution;	/* ps.c */
+ #endif
+ 
  extern struct fontop
+ #ifdef USE_AUTO_FONT
+     autoop,	/* autofont.c */
+ #endif
      pkop,	/* pkfont.c */
      gfop,	/* gffont.c */
      pxlop,	/* pxlfont.c */
***************
*** 13,18 ****
--- 21,29 ----
      jfmop,	/* bifont.c */
      jcompop;	/* compfont.c */
  struct fontop *fontops[] = {
+ #ifdef USE_AUTO_FONT
+     &autoop,
+ #endif
      &pkop,
      &gfop,
      &pxlop,
***************
*** 25,30 ****
--- 36,44 ----
  };
  
  extern struct confop
+ #ifdef USE_AUTO_FONT
+     autoexecop,	/* fontdesc.c */
+ #endif
      fdcop,	/* fontdesc.c */
      fontcop,	/* fontdesc.c */
      jfontcop,	/* fontdesc.c */
***************
*** 37,42 ****
--- 51,59 ----
      substcop,	/* fontdesc.c */
      replfcop;	/* fontdesc.c */
  struct confop *confops[] = {
+ #ifdef USE_AUTO_FONT
+     &autoexecop,
+ #endif
      &fdcop,
      &fontcop,
      &jfontcop,
***************
*** 188,194 ****
--- 205,239 ----
      return (&skipcop);
  }
  
+ #ifdef USE_AUTO_FONT
  /*
+  * auto font generator configuration operations
+  */
+ 
+ char autoexec[STRSIZE];
+ 
+ void getautoexec();
+ struct confop autoexecop = {
+     "autoexec",
+     getautoexec
+ };
+ 
+ void
+ getautoexec()
+ {
+     char *p;
+ 
+     for (; fdch == ' ' || fdch == '\t'; fdch = getc(fd))
+ 	;
+     autoexec[0] = fdch;
+     fgets(autoexec+1, sizeof(autoexec)-2, fd);
+ 
+     if ((p = index(autoexec, '\n')) != (char *)NULL)
+ 	*p = '\0';
+ }
+ #endif
+ 
+ /*
   * configuration operations
   */
  
***************
*** 637,642 ****
--- 682,695 ----
      for (p = path, s = proto, pend = path+PATHLEN-1; *s != '\0'; s++)
  	if (*s == '%') {
  	    switch (*++s) {
+ #ifdef USE_AUTO_FONT
+ 	    case 'R':
+ 		sprintf(t = buf, "%d", resolution);
+ 		break;
+ 	    case 'M':
+ 		sprintf(t = buf, "%.1f", log(acca->actmagfact)/log(1.2));
+ 		break;
+ #endif
  	    case 'f':
  	    case 'n':
  	    case 's':
*** dvi2ps-1.8j/global.h.ORG	Thu Dec 10 17:28:44 1992
--- dvi2ps-1.8j/global.h	Thu Jun 20 15:41:37 1996
***************
*** 1,3 ****
--- 1,10 ----
+ #ifdef SVR4
+ #ifndef SYSV
+ #define SYSV
+ #endif
+ #include "xxstdio.h"
+ #endif
+ 
  #ifdef SYSV
  #define	index	strchr
  #define	rindex	strrchr
***************
*** 6,12 ****
--- 13,25 ----
  int  free();
  char *index();
  char *rindex();
+ #ifdef SYSV
+ #ifndef SVR4
+ int sprintf();
+ #endif
+ #else
  char *sprintf();
+ #endif
  char *strcpy();
  char *getenv();
  
*** dvi2ps-1.8j/io.c.ORG	Tue Dec  8 21:38:01 1992
--- dvi2ps-1.8j/io.c	Thu Oct 13 09:31:53 1994
***************
*** 35,44 ****
  FILE *fp;	/* file pointer    */
  int n;		/* number of bytes */
  {
!     byte s[sizeof(int)];
! 
!     fread(s, 1, n, fp);
!     return (makeuint(s, n));
  }
  
  
--- 35,57 ----
  FILE *fp;	/* file pointer    */
  int n;		/* number of bytes */
  {
!     switch (n) {
! 	case 1:
! 	    return (getc(fp));
! 	case 2:
! 	    n = getc(fp) << 8;
! 	    return (n | getc(fp));
! 	case 3:
! 	    n = getc(fp) << 16;
! 	    n |= getc(fp) << 8;
! 	    return (n | getc(fp));
! 	case 4:
! 	    n = getc(fp) << 24;
! 	    n |= getc(fp) << 16;
! 	    n |= getc(fp) << 8;
! 	    return (n | getc(fp));
!     }
!     return (0);
  }
  
  
***************
*** 52,61 ****
  FILE *fp;	/* file pointer    */
  int n;		/* number of bytes */
  {
!     byte s[sizeof(int)];
! 
!     fread(s, 1, n, fp);
!     return (makeint(s, n));
  }
  
  
--- 65,99 ----
  FILE *fp;	/* file pointer    */
  int n;		/* number of bytes */
  {
!     switch (n) {
! 	case 1:
! 	    n = getc(fp);
! 	    if (n & (1 << 7))
! 		n |= ~0xff;
! 	    return (n);
! 	case 2:
! 	    n = getc(fp) << 8;
! 	    n |= getc(fp);
! 	    if (n & (1 << 15))
! 		n |= ~0xffff;
! 	    return (n);
! 	case 3:
! 	    n = getc(fp) << 16;
! 	    n |= getc(fp) << 8;
! 	    n |= getc(fp);
! 	    if (n & (1 << 23))
! 		n |= ~0xffffff;
! 	    return (n);
! 	case 4:
! 	    n = getc(fp) << 24;
! 	    n |= getc(fp) << 16;
! 	    n |= getc(fp) << 8;
! 	    n |= getc(fp);
! 	    if (n & (1 << 31))
! 		n |= ~0xffffffff;
! 	    return (n);
!     }
!     return (0);
  }
  
  
*** dvi2ps-1.8j/jxl4.c.ORG	Sat Nov 28 18:59:11 1992
--- dvi2ps-1.8j/jxl4.c	Thu Oct 13 09:31:53 1994
***************
*** 52,57 ****
--- 52,60 ----
   */
  
  #include <stdio.h>
+ #ifdef SVR4
+ #include "xxstdio.h"
+ #endif
  /* #include "config.h" */
  
  /* extern char	*malloc(); */
*** dvi2ps-1.8j/xxstdio.c.ORG	Thu Oct 13 09:31:54 1994
--- dvi2ps-1.8j/xxstdio.c	Wed Jun 26 19:42:55 1996
***************
*** 0 ****
--- 1,252 ----
+ #ifdef SVR4
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <unistd.h>
+ #include <sys/fcntl.h>
+ 
+ #ifndef _NFILE
+ #define _NFILE 20
+ #endif
+ 
+ #undef fopen
+ #undef freopen
+ #undef fdopen
+ #undef fflush
+ #undef fread
+ #undef fgetc
+ #undef getw
+ #undef gets
+ #undef fgets
+ #undef fseek
+ #undef ftell
+ #undef __filbuf
+ 
+ typedef struct {
+     FILE *fp;
+     long pos;
+ }
+ xxFILE;
+ 
+ static xxFILE *xxfiles = (xxFILE *)NULL;
+ static int xxnfiles = 0;
+ 
+ #define XXOK(p) ((p) && fileno(p) < xxnfiles && xxfiles[fileno(p)].fp == (p))
+ #define XXPOS(p) (xxfiles[fileno(p)].pos)
+ 
+ static void
+ xxinit(fp)
+     FILE *fp;
+ {
+     int fd;
+ 
+     if (!fp || (fp->_flag & (_IOREAD|_IORW|_IOMYBUF)) != _IOREAD)
+ 	return;
+ 
+     fd = fileno(fp);
+ 
+     if (fd >= xxnfiles) {
+ 	int max = fd+_NFILE;
+ 
+ 	if (xxfiles)
+ 	    xxfiles = (xxFILE *)realloc((void *)xxfiles,
+ 					sizeof(xxFILE)*(max+1));
+ 	else
+ 	    xxfiles = (xxFILE *)malloc(sizeof(xxFILE)*(max+1));
+ 
+ 	if (!xxfiles)
+ 	    return;
+ 
+ 	while (xxnfiles <= max)
+ 	    xxfiles[xxnfiles++].fp = (FILE *)NULL;
+     }
+ 
+     if ((xxfiles[fd].pos = lseek(fd, (long)0, SEEK_CUR)) >= 0)
+ 	xxfiles[fd].fp = fp;
+     else
+ 	xxfiles[fd].fp = (FILE *)NULL;
+ }
+ 
+ static long
+ xxlseek(fp, offset, ptrname)
+     FILE *fp;
+     long offset;
+     int ptrname;
+ {
+     long pos = offset, cur;
+     unsigned char *ptr;
+ 
+     /* assume XXOK(fp) */
+ 
+     if (ptrname == SEEK_END) {
+ 	if (fseek(fp, offset, ptrname))
+ 	    return -1;
+ 
+ 	XXPOS(fp) = lseek(fileno(fp), 0, SEEK_CUR);
+ 	return XXPOS(fp) - fp->_cnt;
+     }
+ 
+     cur = XXPOS(fp);
+ 
+     if (ptrname == SEEK_CUR)
+ 	pos += cur - fp->_cnt;
+ 
+     ptr = (pos - cur) + (fp->_ptr + fp->_cnt);
+ 
+     if (ptr < fp->_base || fp->_ptr + fp->_cnt <= ptr) {
+ 	if (fseek(fp, offset, ptrname))
+ 	    return -1;
+ 
+ 	XXPOS(fp) = lseek(fileno(fp), 0, SEEK_CUR);
+ 	return XXPOS(fp) - fp->_cnt;
+     }
+ 
+     fp->_cnt -= ptr - fp->_ptr;
+     fp->_ptr = ptr;
+     return pos;
+ }
+ 
+ FILE *
+ xxfopen(filename, type)
+     char *filename;
+     char *type;
+ {
+     FILE *fp = fopen(filename, type);
+ 
+     xxinit(fp);
+     return fp;
+ }
+ 
+ FILE *
+ xxfreopen(filename, type, fp)
+     char *filename;
+     char *type;
+     FILE *fp;
+ {
+     xxinit(fp = freopen(filename, type, fp));
+     return fp;
+ }
+ 
+ FILE *
+ xxfdopen(fd, type)
+     int fd;
+     char *type;
+ {
+     FILE *fp = fdopen(fd, type);
+ 
+     xxinit(fp);
+     return fp;
+ }
+ 
+ int
+ xxfflush(fp)
+     FILE *fp;
+ {
+     int rc = fflush(fp);
+ 
+     if (XXOK(fp))
+ 	XXPOS(fp) = lseek(fileno(fp), 0, SEEK_CUR);
+ 
+     return rc;
+ }
+ 
+ int
+ xxfread(ptr, size, nitems, fp)
+     void *ptr;
+     int size;
+     int nitems;
+     FILE *fp;
+ {
+     int noseek = (fp && (size*nitems <= fp->_cnt));
+ 
+     nitems = fread(ptr, size, nitems, fp);
+ 
+     if (!noseek && XXOK(fp))
+ 	XXPOS(fp) = lseek(fileno(fp), 0, SEEK_CUR);
+ 
+     return nitems;
+ }
+ 
+ int
+ xxfgetc(fp)
+     FILE *fp;
+ {
+     int c = fgetc(fp);
+ 
+     if (XXOK(fp))
+ 	XXPOS(fp) = lseek(fileno(fp), 0, SEEK_CUR);
+ 
+     return c;
+ }
+ 
+ int
+ xxgetw(fp)
+     FILE *fp;
+ {
+     int w = getw(fp);
+ 
+     if (XXOK(fp))
+ 	XXPOS(fp) = lseek(fileno(fp), 0, SEEK_CUR);
+ 
+     return w;
+ }
+ 
+ char *
+ xxgets(s)
+     char *s;
+ {
+     s = gets(s);
+ 
+     if (XXOK(stdin))
+ 	XXPOS(stdin) = lseek(fileno(stdin), 0, SEEK_CUR);
+ 
+     return s;
+ }
+ 
+ char *
+ xxfgets(s, n, fp)
+     char *s;
+     int n;
+     FILE *fp;
+ {
+     s = fgets(s, n, fp);
+ 
+     if (XXOK(fp))
+ 	XXPOS(fp) = lseek(fileno(fp), 0, SEEK_CUR);
+ 
+     return s;
+ }
+ 
+ int
+ xxfseek(fp, offset, ptrname)
+     FILE *fp;
+     long offset;
+     int ptrname;
+ {
+     if (XXOK(fp))
+ 	return (xxlseek(fp, offset, ptrname) >= 0) ? 0 : -1;
+     else
+ 	return fseek(fp, offset, ptrname);
+ }
+ 
+ long
+ xxftell(fp)
+     FILE *fp;
+ {
+     if (XXOK(fp))
+ 	return xxlseek(fp, 0, SEEK_CUR);
+     else
+ 	return ftell(fp);
+ }
+ 
+ int
+ xx__filbuf(fp)
+     FILE *fp;
+ {
+     int c = __filbuf(fp);
+ 
+     if (XXOK(fp))
+ 	XXPOS(fp) = lseek(fileno(fp), 0, SEEK_CUR);
+ 
+     return c;
+ }
+ #endif /* SVR4 */
*** dvi2ps-1.8j/xxstdio.h.ORG	Thu Oct 13 09:31:54 1994
--- dvi2ps-1.8j/xxstdio.h	Thu Oct 13 09:31:55 1994
***************
*** 0 ****
--- 1,33 ----
+ /*
+  *	We use our own fseek because SVR4's seem to flush the stream
+  *	unconditionally.  SVR4 is supposed for this package.
+  *
+  *						H.Nakano (94/03/23)
+  */
+ 
+ extern FILE *xxfopen();
+ extern FILE *xxfreopen();
+ extern FILE *xxfdopen();
+ extern int xxfflush();
+ extern int xxfread();
+ extern int xxfgetc();
+ extern int xxgetw();
+ extern char *xxgets();
+ extern char *xxfgets();
+ extern int xxfseek();
+ extern long xxftell();
+ extern int xx__filbuf();
+ 
+ #define fopen		xxfopen
+ #define freopen		xxfreopen
+ #define fdopen		xxfdopen
+ #define fflush		xxfflush
+ #define fread		xxfread
+ #define fgetc		xxfgetc
+ #define getw		xxgetw
+ #define gets		xxgets
+ #define fgets		xxfgets
+ #define fseek		xxfseek
+ #define ftell		xxftell
+ #define __filbuf	xx__filbuf
+ 
