From hideo@tsl.pe.u-tokyo.ac.jp Thu Oct  1 18:58:06 1992
Path: kappa!news.u-tokyo.ac.jp!enterprise!pe.u-tokyo!cccgw!hideo
From: hideo@tsl.pe.u-tokyo.ac.jp (hideo)
Newsgroups: fj.comp.texhax
Subject: GS patch for ASCII JTeX's Xtex
Message-ID: <HIDEO.92Sep16161510@tsl.tsl.pe.u-tokyo.ac.jp>
Date: 16 Sep 92 07:15:10 GMT
Sender: news@cccgw.pe.u-tokyo.ac.jp
Distribution: fj
Organization: Takano Sasaki Lab. Dept. of Precision Machinery Eng., Univ. of
	Tokyo, Japan.
Lines: 723

高橋＠東大精密 と申します。

先日、xdvi のなかから ghostscript を起動して EPSF をプレビューできるように
するパッチが投稿されましたが、それを ASCII-JTeX 1.6 についてくる xtex 用に
移植することに成功しましたので投稿します。gs 2.4以上が必要だそうです。

xtexのソースがあるディレクトリで、

patch <このふぁいる
xmkmf
make

すればいけるはずです。X11R5 で xtex をコンパイルするといくつか文句をい
われるようですがそのために必要な変更はこのパッチには入っていません。

お試し下さい。

*** DviPage2.c.orig	Wed Sep 16 16:07:22 1992
--- DviPage2.c	Wed Sep 16 14:21:53 1992
***************
*** 123,128 ****
--- 123,131 ----
  #include <assert.h>
  
  #include "DviPageP.h"
+ #include "gs-view.h"
+ #include <sys/types.h>
+ #include <sys/stat.h>
  
  extern char *ProgName;
  
***************
*** 991,997 ****
--- 994,1173 ----
    }
  }
  
+ #ifdef HAVE_GS
+ #define	PSFIG_CACHE_SIZE	16
  
+ struct psfig_cache_struct {
+     Pixmap pix;
+ 
+     char *psfile;
+     unsigned int width, height;
+     time_t ps_time;
+ 
+     struct psfig_cache_struct *next;
+ }   psfig_cache[] =
+ 
+ {{ 0, NULL, 0, 0, 0, NULL}, { 0, NULL, 0, 0, 0, NULL},
+  { 0, NULL, 0, 0, 0, NULL}, { 0, NULL, 0, 0, 0, NULL},
+  { 0, NULL, 0, 0, 0, NULL}, { 0, NULL, 0, 0, 0, NULL},
+  { 0, NULL, 0, 0, 0, NULL}, { 0, NULL, 0, 0, 0, NULL},
+  { 0, NULL, 0, 0, 0, NULL}, { 0, NULL, 0, 0, 0, NULL},
+  { 0, NULL, 0, 0, 0, NULL}, { 0, NULL, 0, 0, 0, NULL},
+  { 0, NULL, 0, 0, 0, NULL}, { 0, NULL, 0, 0, 0, NULL},
+  { 0, NULL, 0, 0, 0, NULL}, { 0, NULL, 0, 0, 0, NULL}};
+ 
+ Pixmap get_cached_psfig(w, psfile, width, height, flag)
+     DviPageWidget w;
+     char *psfile;
+     unsigned int width, height;
+     Boolean flag;
+ {
+     int i;
+     int hash = 0;
+     struct psfig_cache_struct *cache;
+     struct stat buf;
+ 
+     for (i = 0; psfile[i]; i++)
+ 	hash += psfile[i];
+     hash += width + height;
+     hash %= PSFIG_CACHE_SIZE;
+ 
+     stat(psfile, &buf);
+ 
+     for (cache = &psfig_cache[hash]; cache; cache = cache->next)
+ 	if (cache->width == width &&
+ 	    cache->height == height &&
+ 	    strcmp(cache->psfile, psfile) == 0) {
+ 	    if (cache->ps_time == buf.st_mtime)
+ 		return cache->pix;
+ 	    else {
+ 		XFreePixmap(XtDisplay(w), cache->pix);
+ 		cache->pix = (Pixmap) 0;
+ 		return (Pixmap) 0;
+ 	    }
+ 	}
+     return 0;
+ }
+ 
+ void put_cache_psfig(pix, psfile, width, height)
+     Pixmap pix;
+     char *psfile;
+     unsigned int width, height;
+ {
+     int i;
+     int hash = 0;
+     struct psfig_cache_struct *cache;
+     struct stat buf;
+ 
+     for (i = 0; psfile[i]; i++)
+ 	hash += psfile[i];
+     hash += width + height;
+     hash %= PSFIG_CACHE_SIZE;
+ 
+     stat(psfile, &buf);
+ 
+     if (psfig_cache[hash].pix == 0) {
+ 	psfig_cache[hash].pix = pix;
+ 	psfig_cache[hash].psfile = psfile;
+ 	psfig_cache[hash].width = width;
+ 	psfig_cache[hash].height = height;
+ 	psfig_cache[hash].next = NULL;
+ 	psfig_cache[hash].ps_time = buf.st_mtime;
+     } else {
+ 	for (cache = &psfig_cache[hash]; cache->next; cache = cache->next)
+ 	    if (cache->width == width &&
+ 		cache->height == height &&
+ 		strcmp(cache->psfile, psfile) == 0) {
+ 		if (cache->pix == (Pixmap) 0)
+ 		    cache->pix = pix;
+ 		cache->ps_time = buf.st_mtime;
+ 		return;
+ 	    }
+ 	cache->next = (void *) XtMalloc(sizeof(struct psfig_cache_struct));
+ 	cache->next->pix = pix;
+ 	cache->next->psfile = psfile;
+ 	cache->next->width = width;
+ 	cache->next->height = height;
+ 	cache->next->next = NULL;
+ 	cache->next->ps_time = buf.st_mtime;
+     }
+ }
+ 
+ void draw_ps(psfile, w)
+     struct psfig_info *psfile;
+     DviPageWidget w;
+ {
+     struct gs_info gs;
+     int use_ps_special = 1;
+ 
+     int cx = fastFromSpHoriz(w, w->dviPage.dviStackPointer->h);
+     int cy = fastFromSpVert(w, w->dviPage.dviStackPointer->v);
+ 
+     static GC pix_gc = 0;
+ 
+     gs.psfile = psfile->filename;
+ 
+     gs.width = (psfile->urx - psfile->llx) * psfile->hscale / 72.0
+ 	* w->dviPage.pixelsPerInchHoriz;
+     gs.height = (psfile->ury - psfile->lly) * psfile->vscale / 72.0
+ 	* w->dviPage.pixelsPerInchVert;
+ 
+ #ifdef DEBUG_XTEX_GS
+     printf("pixelsPerInch horiz=%f vert=%f\n",
+ 	w->dviPage.pixelsPerInchHoriz,
+ 	w->dviPage.pixelsPerInchVert);
+     printf("llx: %d, lly: %d, urx: %d, ury: %d\n",
+ 	psfile->llx, psfile->lly, psfile->urx, psfile->ury);
+     printf("hscale: %f, vscale: %f\n", psfile->hscale, psfile->vscale);
+     printf("gs.width: %d, gs.height:%d\n", gs.width, gs.height);
+ #endif
+ 
+     if (use_ps_special) {
+ 	gs.pix = get_cached_psfig(w, gs.psfile, gs.width, gs.height);
+ 	if (gs.pix == 0) {
+ 	    gs.disp = XtDisplay(w);
+ 	    gs.parent = XtWindow(w);
+ 	    gs.pix = XCreatePixmap(XtDisplay(w), XtWindow(w),
+ 		gs.width, gs.height,
+ 		DefaultDepthOfScreen(XtScreen(w)));
+ 	    gs.llx = psfile->llx;
+ 	    gs.lly = psfile->lly;
+ 	    gs.urx = psfile->urx;
+ 	    gs.ury = psfile->ury;
+ 
+ 	    if (pix_gc == 0) {
+ 		pix_gc = XCreateGC(XtDisplay(w), XtWindow(w), 0, 0);
+ 		XCopyGC(XtDisplay(w), w->dviPage.paintGC,
+ 		    GCFunction | GCForeground | GCBackground, pix_gc);
+ 
+ 		if (DefaultDepthOfScreen(XtScreen(w)) > 1) {
+ 		    XSetFunction(XtDisplay(w), pix_gc, GXcopy);
+ 		} else if (WhitePixelOfScreen(XtScreen(w)) == 1) {
+ 		    if (w->dviPage.reverseVideo) {
+ 			XSetFunction(XtDisplay(w), pix_gc, GXorInverted);
+ 		    } else {
+ 			XSetFunction(XtDisplay(w), pix_gc, GXand);
+ 		    }
+ 		}
+ 	    }
+ 	    error(0,0, "ghostscript '%s'", gs.psfile);
+ 	    psfig_to_bitmap(&gs);
+ 
+ 	    put_cache_psfig(gs.pix, gs.psfile, gs.width, gs.height);
+ 	}
+ 	XCopyArea(XtDisplay(w), gs.pix, XtWindow(w), pix_gc,
+ 	    0, 0, gs.width, gs.height,
+ 	    cx, cy);
+     } else {
+ 	XDrawRectangle(XtDisplay(w), XtWindow(w), w->dviPage.paintGC,
+ 	    cx, cy,
+ 	    gs.width - 1, gs.height - 1);
+     }
+ }
+ 
+ #endif
+ 
+ 
  #ifndef HAVE_DPS
  /*
   * Draw the bounding box for a \psfig special.
***************
*** 1290,1330 ****
  #endif
  
  void doSpecial(w, cp)
!      DviPageWidget w;
!      char *cp;
  {
  #define	COMLEN	64
!   char command[COMLEN], *orig_cp;
!   register int len;
!   
!   orig_cp = cp;
!   while (isspace(*cp)) ++cp;
!   len = 0;
!   while (!isspace(*cp) && *cp && len < COMLEN-1) command[len++] = *cp++;
!   command[len] = '\0';
!   if (strcmp(command, "pn") == 0) set_pen_size(w,cp);
!   else if (strcmp(command, "fp") == 0) flush_path(w, 0);
!   else if (strcmp(command, "da") == 0) flush_dashed(w, cp, 0);
!   else if (strcmp(command, "dt") == 0) flush_dashed(w, cp, 1);
!   else if (strcmp(command, "pa") == 0) add_path(w, cp);
!   else if (strcmp(command, "ar") == 0) arc(w, cp, 0);
!   else if (strcmp(command, "ia") == 0) arc(w, cp, 1);
!   else if (strcmp(command, "sp") == 0) flush_spline(w, cp);
!   else if (strcmp(command, "sh") == 0) shade_last(w, cp);
!   else if (strcmp(command, "wh") == 0) shade_last(w, "0");
!   else if (strcmp(command, "bk") == 0) shade_last(w, "1");
!   else if (strcmp(command, "ip") == 0) flush_path(w, 1);
!   else if (strcmp(command, "tx") == 0) Texture(cp);
!   else if (strcmp(command, "ps::[begin]") == 0) psfigBegin(w, cp);
  #ifdef HAVE_DPS
!   else if (strcmp(command, "ps::[end]") == 0) psfigEnd(w, cp);
!   else if (strncmp(command, "ps:",3) == 0) psfigPlotfile(w, cp);
  #else
!   else if (strncmp(command, "ps:",3) == 0)		/* do nothing */;
  #endif
!   else if (strncmp(command, "ln03", 4) == 0) 		/* do nothing */;
!   else if (strncmp(command, "xtex:", 7) == 0) registerActionProc(w, cp) ;
!   else {
!     error(0,0, "special \"%s\" not implemented", orig_cp);
!   }
  }
--- 1466,1514 ----
  #endif
  
  void doSpecial(w, cp)
!     DviPageWidget w;
!     char *cp;
  {
  #define	COMLEN	64
!     char command[COMLEN], *orig_cp;
!     register int len;
! 
!     orig_cp = cp;
!     while (isspace(*cp))
! 	++cp;
!     len = 0;
!     while (!isspace(*cp) && *cp && len < COMLEN - 1)
! 	command[len++] = *cp++;
!     command[len] = '\0';
!     if (strcmp(command, "pn") == 0) set_pen_size(w, cp);
!     else if (strcmp(command, "fp") == 0) flush_path(w, 0);
!     else if (strcmp(command, "da") == 0) flush_dashed(w, cp, 0);
!     else if (strcmp(command, "dt") == 0) flush_dashed(w, cp, 1);
!     else if (strcmp(command, "pa") == 0) add_path(w, cp);
!     else if (strcmp(command, "ar") == 0) arc(w, cp, 0);
!     else if (strcmp(command, "ia") == 0) arc(w, cp, 1);
!     else if (strcmp(command, "sp") == 0) flush_spline(w, cp);
!     else if (strcmp(command, "sh") == 0) shade_last(w, cp);
!     else if (strcmp(command, "wh") == 0) shade_last(w, "0");
!     else if (strcmp(command, "bk") == 0) shade_last(w, "1");
!     else if (strcmp(command, "ip") == 0) flush_path(w, 1);
!     else if (strcmp(command, "tx") == 0) Texture(cp);
! #ifdef HAVE_GS
!     else if (strncmp(command, "epsfile", 7) == 0) psSpecial(w, orig_cp);
! #endif
!     else if (strcmp(command, "ps::[begin]") == 0) psfigBegin(w, cp);
  #ifdef HAVE_DPS
!     else if (strcmp(command, "ps::[end]") == 0) psfigEnd(w, cp);
!     else if (strncmp(command, "ps:", 3) == 0) psfigPlotfile(w, cp);
  #else
!     else if (strncmp(command, "ps:", 3) == 0)	/* do nothing */
! 	;
  #endif
!     else if (strncmp(command, "ln03", 4) == 0)	/* do nothing */
! 	;
!     else if (strncmp(command, "xtex:", 7) == 0)
! 	registerActionProc(w, cp);
!     else {
! 	error(0, 0, "special \"%s\" not implemented", orig_cp);
!     }
  }
*** Imakefile.orig	Wed Sep 16 16:07:22 1992
--- Imakefile	Wed Sep 16 13:54:08 1992
***************
*** 1,7 ****
  #include "../Imake.Config"
  
! CDEBUGFLAGS=-g
  
  /***************************************************************************/
  /*	You shouldn't have to change anything below this line		   */
  /***************************************************************************/
--- 1,11 ----
  #include "../Imake.Config"
  
! /* CDEBUGFLAGS=-g -DDEBUG_XTEX_GS*/
! CDEBUGFLAGS= -O2
  
+ /* for EPSF preview with ghostscript */
+ #define GHOSTSCRIPT YES
+ 
  /***************************************************************************/
  /*	You shouldn't have to change anything below this line		   */
  /***************************************************************************/
***************
*** 19,35 ****
                    file.c dialog.c dvi-simple.c \
                    page.c x11fonts.c mark.c \
                    DviPage.c DviPage2.c Valuator.c\
! 		EzMenu.c EzME.c SmeLine.c
  
  HDRS	= DviPage.h dvi-simple.h mio.h xtex.h x11fonts.h \
  	DviPageP.h mark.h page.h widgets.h Valuator.h ValuatorP.h \
! 	EzMenu.h EzMenuP.h EzME.h EzMEP.h
  
  OBJS = xtex.o widgets.o \
                    file.o dialog.o dvi-simple.o \
                    page.o x11fonts.o mark.o \
                    DviPage.o DviPage2.o Valuator.o \
! 		EzMenu.o EzME.o SmeLine.o
  
  PROGRAMS = xtex
  
--- 23,39 ----
                    file.c dialog.c dvi-simple.c \
                    page.c x11fonts.c mark.c \
                    DviPage.c DviPage2.c Valuator.c\
! 		EzMenu.c EzME.c util.c ps.c gs-view.c
  
  HDRS	= DviPage.h dvi-simple.h mio.h xtex.h x11fonts.h \
  	DviPageP.h mark.h page.h widgets.h Valuator.h ValuatorP.h \
! 	EzMenu.h EzMenuP.h EzME.h EzMEP.h gs-view.h
  
  OBJS = xtex.o widgets.o \
                    file.o dialog.o dvi-simple.o \
                    page.o x11fonts.o mark.o \
                    DviPage.o DviPage2.o Valuator.o \
! 		EzMenu.o EzME.o util.o ps.o gs-view.o
  
  PROGRAMS = xtex
  
***************
*** 40,46 ****
  
  DEFINES = $(XVERSION_DEFINES) $(POSTSCRIPT_DEFINES) -DPOPUP_WINDOW_TYPE=$(POPUP_WINDOW_TYPE) -DXTEX_VERSION=\"$(VERSION)\"
  
! VERSION	=2.16.1J#
  RCS_VERSION=2p15#
  
  #ifdef DISPLAY_POSTSCRIPT
--- 44,50 ----
  
  DEFINES = $(XVERSION_DEFINES) $(POSTSCRIPT_DEFINES) -DPOPUP_WINDOW_TYPE=$(POPUP_WINDOW_TYPE) -DXTEX_VERSION=\"$(VERSION)\"
  
! VERSION	=2.16.1J-GS1.0#
  RCS_VERSION=2p15#
  
  #ifdef DISPLAY_POSTSCRIPT
***************
*** 47,54 ****
--- 51,63 ----
     POSTSCRIPT_DEFINES = -DHAVE_DPS
                DPS_LIB = /usr/lib/libdps.a /usr/lib/libXext.a
  #else
+ #ifdef GHOSTSCRIPT
+    POSTSCRIPT_DEFINES = -DHAVE_GS
+               DPS_LIB = 
+ #else
     POSTSCRIPT_DEFINES =
                DPS_LIB =
+ #endif
  #endif
  
  all:	xtex
*** dialog.c.orig	Wed Sep 16 16:07:23 1992
--- dialog.c	Wed Sep 16 14:16:53 1992
***************
*** 50,56 ****
--- 50,58 ----
  #include "widgets.h"
  
  #ifdef __STDC__
+ #ifdef X11R4
  extern char* XtMalloc(int);
+ #endif
  extern char* realloc(char *, int);
  #else
  extern char* malloc();
*** gs-view.c.orig	Wed Sep 16 16:07:08 1992
--- gs-view.c	Wed Sep 16 14:16:51 1992
***************
*** 0 ****
--- 1,145 ----
+ /*
+  *	gs-view.c
+  *
+  *		by hiro@jaist-east.ac.jp
+  *
+  *	$Date: 1992/09/10 12:28:55 $
+  *	$Revision: 1.3 $
+  */
+ 
+ #include <stdio.h>
+ #include <sys/stat.h>
+ #include <fcntl.h>
+ #include <sys/types.h>
+ #include <X11/X.h>
+ #include <X11/Intrinsic.h>
+ #include <X11/StringDefs.h>
+ #include <X11/Xatom.h>
+ #include <X11/Xmu/Atoms.h>
+ #include <signal.h>
+ 
+ #include "gs-view.h"
+ 
+ #define	GHOSTSCRIPT	"gs"
+ 
+ #define	DEV_NULL	"/dev/null"
+ 
+ static char*	RCS_ID = "$Header: /tmp_mnt/home/fs015/hiro/src/xdvi-14j-ps/RCS/gs-view.c,v 1.3 1992/09/10 12:28:55 hiro Exp $";
+ 
+ struct gs_prop {
+     Window	parent;
+     Atom	GS_DONE;
+     Atom	GS_PAGE;
+ };
+ 
+ static Boolean	check_gs_event(disp, event, props)
+  Display*	disp;
+  XEvent*	event;
+  struct gs_prop*	props;
+ {
+     if (event-> type == ClientMessage &&
+ 	event-> xclient.window == props-> parent &&
+ 	event-> xclient.send_event == TRUE) {
+ #ifdef DEBUG_XDVI_PS
+ 	printf("caught ClientMessage event\n");
+ #endif
+ 	if (event-> xclient.message_type == props-> GS_DONE ||
+ 	    event-> xclient.message_type == props-> GS_PAGE)
+ 	  return TRUE;
+     }
+     else
+       return FALSE;
+ }
+ 
+ int	psfig_to_bitmap(gs)
+  struct gs_info*	gs;
+ {
+     char	param[BUFSIZ];
+ 
+     sprintf(param, "0 0 %d %d %d %d %f %f 0 0 0 0 %d %d",
+ 	    gs-> llx, gs-> lly, gs-> urx, gs-> ury,
+ 	    gs-> width  / ((gs-> urx - gs-> llx) / 72.0),
+ 	    gs-> height / ((gs-> ury - gs-> lly) / 72.0),
+ 	    gs-> width, gs-> height);
+     XChangeProperty(gs-> disp, gs-> parent,
+ 		    XInternAtom(gs-> disp, "GHOSTVIEW", FALSE), XA_STRING,
+ 		    8, PropModeReplace, param, strlen(param));
+ 
+ #ifdef DEBUG
+     printf("property:%s\n", param);
+ #endif
+ 
+     if ((gs-> gs_pid = fork()) == 0) {
+ 	/* child */
+ 	static char	env[BUFSIZ];
+ 	char*	argv[6];
+ 	int	i;
+ 	int	pipe[2];
+ 
+ 	sprintf(env, "DISPLAY=%s", XDisplayString(gs-> disp));
+ 	putEnv(XtNewString(env));
+ 	sprintf(env, "GHOSTVIEW=%d %d", gs-> parent, gs-> pix);
+ 	putEnv(XtNewString(env));
+ 
+ #ifdef DEBUG
+ 	printf("getenv:%s\n", getenv("DISPLAY"));
+ 	printf("getenv:%s\n", getenv("GHOSTVIEW"));
+ #endif
+ 
+ 	i = 0;
+ 	argv[i++] = GHOSTSCRIPT;
+ 	argv[i++] = "-dQUIET";
+ 	argv[i++] = "-dNOPAUSE";
+ 	argv[i++] = gs-> psfile;
+ 	argv[i++] = NULL;
+ 
+ 	for (i = 3; i < 20; i ++)
+ 	  close(i);
+ 
+ 	dup2(open(DEV_NULL, O_RDONLY), 0); /* redirect stdin to /dev/null */
+ 
+ #ifdef DEBUG_XDVI_PS
+ 	printf("gs:exec-ed\n");
+ #endif
+ 	if (execvp(GHOSTSCRIPT, argv)) {
+ 	    perror("gs");
+ 	    exit(-1);
+ 	}
+     }
+     else {
+ 	/* parent */
+ 	XEvent	ev;
+ 	struct gs_prop	props;
+ 
+ 	props.parent = gs-> parent;
+ 	props.GS_DONE = XInternAtom(gs-> disp, "DONE", False);
+ 	props.GS_PAGE = XInternAtom(gs-> disp, "PAGE", False);
+ 
+ 	XIfEvent(gs-> disp, & ev, check_gs_event, & props);
+ #ifdef DEBUG
+ 	if (ev.xclient.message_type == props.GS_DONE ||
+ 	    ev.xclient.message_type == props.GS_PAGE) {
+ 	    printf("caught event:GS_DONE or GS_PAGE\n");
+ 	    printf("mess:%s\n", ev.xclient.data.b);
+ 	}
+ 	else
+ 	  printf("caught another event\n");
+ #endif
+ 	kill(gs-> gs_pid, SIGTERM);
+ 	wait(NULL);
+     }
+     return 0;
+ }
+ 
+ /*
+  * $Log: gs-view.c,v $
+  * Revision 1.3  1992/09/10  12:28:55  hiro
+  * redirect stdin to /dev/null.
+  *
+  * Revision 1.2  1992/09/01  10:36:56  hiro
+  * change putenv() and strdup().
+  *
+  * Revision 1.1  1992/08/29  09:22:45  hiro
+  * Initial revision
+  *
+  */
*** gs-view.h.orig	Wed Sep 16 16:07:08 1992
--- gs-view.h	Wed Sep 16 14:12:59 1992
***************
*** 0 ****
--- 1,49 ----
+ /*
+  *	gs-view.h
+  *
+  *		by hiro@jaist-east.ac.jp
+  *
+  *	$Date: 1992/09/01 08:12:26 $
+  *	$Revision: 1.2 $
+  */
+ 
+ #ifndef X_H
+ #define Pixmap	unsigned long
+ #endif
+ 
+ struct bitmap_info {
+     Pixmap	bitmap;
+     unsigned int	width, height;
+ };
+ 
+ #ifdef X_H
+ struct	gs_info {
+     Display*	disp;
+     Window	parent;
+     char*	psfile;
+     Pixmap	pix;
+     unsigned int	width, height;
+     unsigned int	llx, lly;
+     unsigned int	urx, ury;
+     FILE*	gs_out;
+     int 	gs_pid;
+ };
+ #endif
+ 
+ struct psfig_info {
+     char*	filename;
+     float	llx, lly;
+     float	urx, ury;
+     float	hscale, vscale;
+     struct bitmap_info	fig[4];
+ };
+ 
+ /*
+  * $Log: gs-view.h,v $
+  * Revision 1.2  1992/09/01  08:12:26  hiro
+  * change 'pid_t' to 'int'.
+  *
+  * Revision 1.1  1992/08/29  09:21:34  hiro
+  * Initial revision
+  *
+  */
*** util.c.orig	Wed Sep 16 16:07:08 1992
--- util.c	Mon Sep 14 13:27:17 1992
***************
*** 0 ****
--- 1,95 ----
+ /*
+  * DVI previewer for X.
+  *
+  * Eric Cooper, CMU, September 1985.
+  *
+  * Code derived from dvi-imagen.c.
+  *
+  * Modification history:
+  * 1/1986	Modified for X.10 by Bob Scheifler, MIT LCS.
+  * 7/1988	Modified for X.11 by Mark Eichin, MIT
+  * 12/1988	Added 'R' option, toolkit, magnifying glass
+  *			--Paul Vojta, UC Berkeley.
+  * 2/1989	Added tpic support	--Jeffrey Lee, U of Toronto
+  * 4/1989	Modified for System V by Donald Richardson, Clarkson Univ.
+  * 3/1990	Added VMS support	--Scott Allendorf, U of Iowa
+  * 7/1990	Added reflection mode	--Michael Pak, Hebrew U of Jerusalem
+  *
+  *	Compilation options:
+  *	SYSV	compile for System V
+  *	VMS	compile for VMS
+  *	X10	compile for X10
+  *	NOTOOL	compile without toolkit (X11 only)
+  *	BUTTONS	compile with buttons on the side of the window (needs toolkit)
+  *	MSBITFIRST	store bitmaps internally with most significant bit first
+  *	BMSHORT	store bitmaps in shorts instead of bytes
+  *	BMLONG	store bitmaps in longs instead of bytes
+  *	ALTFONT	default for -altfont option
+  *	A4	use European size paper
+  *	TEXXET	support reflection dvi codes (right-to-left typesetting)
+  */
+ 
+ #include <stdio.h>
+ #include <errno.h>
+ int	errno;
+ 
+ #ifdef VMS
+ #include <rmsdef.h>
+ #endif /* VMS */
+ 
+ #ifndef	X_NOT_STDC_ENV
+ #include <stdlib.h>
+ #else
+ char	*calloc();
+ #endif
+ #if	defined(macII) && !defined(__STDC__) /* stdlib.h doesn't define these */
+ char	*calloc();
+ #endif /* macII */
+ 
+ #if	NeedVarargsPrototypes		/* this is for oops */
+ #include <stdarg.h>
+ #else
+ #include <varargs.h>
+ #endif
+ 
+ #ifdef	DOPRNT	/* define this if vfprintf gives you trouble */
+ #define	vfprintf(stream, message, args)	_doprnt(message, args, stream)
+ #endif
+ 
+ /*
+  *	General utility routines.
+  */
+ 
+ /*
+  *
+  */
+ 
+ extern char**	environ;
+ 
+ #ifdef BCOPY
+ #define	memcpy(a, b, n)	bcopy(b, a, n)
+ #endif
+ 
+ void	putEnv(env)
+  char*	env;
+ {
+     int 	i, n;
+ 
+     for (i = 0; env[i] != '='; i ++)
+       ;
+     i ++;
+     for (n = 0; environ[n]; n ++) {
+ 	if (strncmp(environ[n], env, i) == 0)
+ 	  break;
+     }
+     if (environ[n] == NULL) {
+ 	char**	ptr = (void*)XtMalloc(sizeof(char*) * (n + 2));
+ 
+ 	memcpy(ptr, environ, sizeof(char*) * n);
+ 	environ = ptr;
+ 	environ[n] = env;
+ 	environ[n+1] = NULL;
+     }
+     else
+       environ[n] = env;
+ }

--
高橋 英男       東京大学大学院工学系研究科精密機械工学専攻佐々木研究室Ｍ２
                TEL:03-3812-2111 Ext. 6475
                e-mail:hideo@tsl.pe.u-tokyo.ac.jp

