*** xdvi-17-miyu-b6/README.svr4.ORG	Tue Jul  5 12:55:48 1994
--- xdvi-17-miyu-b6/README.svr4	Tue Jul  5 15:30:43 1994
***************
*** 0 ****
--- 1,13 ----
+ 
+ This is a patched version of xdvi-17 + miyu-patch for System V Rel.4
+ machines to improve performance.
+ 
+ SVR4's fseek function flushes the stream buffer unconditionally.  This
+ causes a great performance problem when xdvi acceses 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.
+ 
+ 							July 5, 1994
+ 
+ 			Hiroshi Nakano <nakano@rins.ryukoku.ac.jp>
+ 			Ryukoku Univ., Seta, Otsu, Japan
*** xdvi-17-miyu-b6/SelFile.c.ORG	Tue Jul  5 13:57:14 1994
--- xdvi-17-miyu-b6/SelFile.c	Thu Mar 24 10:41:40 1994
***************
*** 62,67 ****
--- 62,71 ----
  
  #include "SFinternal.h"
  
+ #ifdef SVR4
+ #include "xxstdio.h"
+ #endif
+ 
  #ifndef MAXPATHLEN
  #define MAXPATHLEN 1024
  #endif /* ndef MAXPATHLEN */
*** xdvi-17-miyu-b6/VFlib-1.32/JGlib.c.ORG	Tue Jul  5 13:57:16 1994
--- xdvi-17-miyu-b6/VFlib-1.32/JGlib.c	Thu Mar 24 12:47:25 1994
***************
*** 33,38 ****
--- 33,45 ----
  #include  "JGlib.h"
  #include  "JGlib0.h"
  
+ #ifdef SYSV
+ #define bzero(p, n)	memset(p, 0, n)
+ #endif
+ #ifdef SVR4
+ #include "xxstdio.h"
+ #endif
+ 
  #define		BEG_STEP	8
  
  static	double	beg_para[BEG_STEP+1][4];
*** xdvi-17-miyu-b6/VFlib-1.32/Makefile.ORG	Tue Jul  5 13:57:16 1994
--- xdvi-17-miyu-b6/VFlib-1.32/Makefile	Thu Mar 24 11:26:52 1994
***************
*** 3,15 ****
  #   by H.Kakugawa
  #
  
  # normal ..
  #CC   = cc
! COPT = -O
  
  # gcc
  #CC   = gcc
! #COPT = -O2
  
  all:	ZFlib.o JGlib.o VFlib.o VFlib.a
  
--- 3,17 ----
  #   by H.Kakugawa
  #
  
+ ADDLIBS = -lsocket -lnsl
+ 
  # normal ..
  #CC   = cc
! COPT = -O -I.. -DSYSV -DSVR4
  
  # gcc
  #CC   = gcc
! #COPT = -O2 -I.. -DSYSV -DSVR4
  
  all:	ZFlib.o JGlib.o VFlib.o VFlib.a
  
***************
*** 18,24 ****
  
  VFlib.a: VFlib.o ZFlib.o JGlib.o VF.h config.h
  	ar rcv VFlib.a VFlib.o ZFlib.o JGlib.o
- 	ranlib VFlib.a
  
  VFlib.o: VFlib.c VF.h config.h
  	$(CC) -c $(COPT) VFlib.c
--- 20,25 ----
***************
*** 37,49 ****
  
  # test programs
  test1:	test1.o VFlib.o
! 	$(CC) -o test1  test1.o VFlib.a $(FSLIB) -lX11 -lm
  
  test2:	test2.o ZFlib-test.o
! 	$(CC) -o test2  test2.o ZFlib-test.o -lX11
  
  test3:	test3.o JGlib-test.o
! 	$(CC) -o test3  test3.o JGlib-test.o -lX11
  
  test1.o: test1.c 
  	$(CC) -c $(COPT) test1.c
--- 38,50 ----
  
  # test programs
  test1:	test1.o VFlib.o
! 	$(CC) -o test1  test1.o VFlib.a $(FSLIB) -lX11 -lm $(ADDLIBS)
  
  test2:	test2.o ZFlib-test.o
! 	$(CC) -o test2  test2.o ZFlib-test.o -lX11 $(ADDLIBS)
  
  test3:	test3.o JGlib-test.o
! 	$(CC) -o test3  test3.o JGlib-test.o -lX11 $(ADDLIBS)
  
  test1.o: test1.c 
  	$(CC) -c $(COPT) test1.c
*** xdvi-17-miyu-b6/VFlib-1.32/ZFlib.c.ORG	Tue Jul  5 13:57:16 1994
--- xdvi-17-miyu-b6/VFlib-1.32/ZFlib.c	Thu Mar 24 11:26:35 1994
***************
*** 34,39 ****
--- 34,46 ----
  #include  "ZFlib.h"
  #include  "ZFlib0.h"
  
+ #ifdef SYSV
+ #define bzero(p, n)	memset(p, 0, n)
+ #endif
+ #ifdef SVR4
+ #include "xxstdio.h"
+ #endif
+ 
  static ZF_inited = 0;
  
  static BUFFER  zf_buffer;
*** xdvi-17-miyu-b6/VFlib-1.32/test1.c.ORG	Tue Jul  5 13:57:17 1994
--- xdvi-17-miyu-b6/VFlib-1.32/test1.c	Thu Mar 24 11:02:23 1994
***************
*** 13,18 ****
--- 13,21 ----
  #include <sys/types.h>
  #include "VF.h"
  
+ #ifdef SYSV
+ #define bzero(p, n)	memset(p, 0, n)
+ #endif
  
  /* Pixel Size */
  #define BUF_XDOTS 200    
*** xdvi-17-miyu-b6/VFlib-1.32/test2.c.ORG	Tue Jul  5 13:57:17 1994
--- xdvi-17-miyu-b6/VFlib-1.32/test2.c	Thu Mar 24 11:02:27 1994
***************
*** 12,17 ****
--- 12,21 ----
  #include <sys/types.h>
  #include "VF.h"
  
+ #ifdef SYSV
+ #define bzero(p, n)	memset(p, 0, n)
+ #endif
+ 
  #define WINSIZE 400
  
  
*** xdvi-17-miyu-b6/VFlib-1.32/test3.c.ORG	Tue Jul  5 13:57:17 1994
--- xdvi-17-miyu-b6/VFlib-1.32/test3.c	Thu Mar 24 11:02:31 1994
***************
*** 12,17 ****
--- 12,21 ----
  #include <sys/types.h>
  #include "VF.h"
  
+ #ifdef SYSV
+ #define bzero(p, n)	memset(p, 0, n)
+ #endif
+ 
  #define WINSIZE 400
  
  
*** xdvi-17-miyu-b6/util.c.ORG	Tue Jul  5 13:57:20 1994
--- xdvi-17-miyu-b6/util.c	Thu Mar 24 10:41:38 1994
***************
*** 281,283 ****
--- 281,286 ----
  
  #endif	/* PS */
  
+ #ifdef SVR4
+ #include "xxstdio.c"
+ #endif
*** xdvi-17-miyu-b6/xdvi.h.ORG	Tue Jul  5 13:57:21 1994
--- xdvi-17-miyu-b6/xdvi.h	Tue Jul  5 13:47:50 1994
***************
*** 27,32 ****
--- 27,36 ----
  #endif
  #endif	/* NTTZEIT */
  
+ #if defined(SVR4) && !defined(SYSV)
+ #define	SYSV	1
+ #endif
+ 
  #ifndef X10
  #include <X11/Xlib.h>	/* include Xfuncs.h, if available */
  #include <X11/Xutil.h>	/* needed for XDestroyImage */
***************
*** 130,135 ****
--- 134,143 ----
  #endif
  #endif
  
+ #ifdef SVR4
+ #include "xxstdio.h"
+ #endif
+ 
  #define	Printf	(void) printf
  #define	Puts	(void) puts
  #define	Fprintf	(void) fprintf
*** xdvi-17-miyu-b6/xxstdio.c.ORG	Thu Mar 24 10:41:40 1994
--- xdvi-17-miyu-b6/xxstdio.c	Wed Jan 22 15:43:45 1997
***************
*** 0 ****
--- 1,253 ----
+ #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);
+     fcntl (fd, F_SETFD, 1);
+ 
+     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 */
*** xdvi-17-miyu-b6/xxstdio.h.ORG	Thu Mar 24 10:41:40 1994
--- xdvi-17-miyu-b6/xxstdio.h	Thu Mar 24 11:18:17 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
+ 
