Newsgroups: fj.sources,fj.comp.texhax
Path: galaxy.trc.rwcp.or.jp!mex1!hiro
From: hiro@jaist-east.ac.jp (Masahiro Morita)
Subject: xdvi-14jgs:patch to preview PS figures.
Message-ID: <HIRO.92Sep11173326@skywalker.jaist-east.ac.jp>
Lines: 1045
Sender: news@jaist-east.ac.jp (0000-news(0000))
Organization: Japan Advanced Institute of Science and Technology Hokuriku,
	Ishikawa, Japan
Distribution: fj
Date: Fri, 11 Sep 1992 08:33:26 GMT
Xref: galaxy.trc.rwcp.or.jp fj.sources:2843 fj.comp.texhax:3013
X-originally-archived-at: http://galaxy.rwcp.or.jp/text/cgi-bin/newsarticle2?ng=fj.comp.texhax&nb=3013&hd=a
X-reformat-date: Mon, 18 Oct 2004 15:18:22 +0900
X-reformat-comment: Tabs were expanded into 4 column tabstops by the Galaxy's archiver. See http://katsu.watanabe.name/ancientfj/galaxy-format.html for more info.


$B?9ED!wKLN&@hC<Bg$G$9!#(B

$BBgJQ$J$,$i$/$*BT$?$;CW$7$^$7$?!#(Bxdvi $B$G(B PS $B$N3($r<h$j9~$s$@(B dvi $B$r%W%l%S%e!<(B
$B$9$k$?$a$N%Q%C%A%-%C%H$G$9!#(B

$B;d$N0&MQ$7$F$$$k(B xdvi $B$,$"$NI=<($N=9$$(B xt?x $B$J$s$>$KIi$1$F$J$k$b$N$+$H;W$C(B
$B$F:n$j$^$7$?!#$I$&$>8fMxMQ2<$5$$!#(B

$B%Q%C%A$O(B xdvi-14 $B$rE83+$7$?%G%#%l%/%H%j>e$G$^$:(B xdvi-14j.patch $B$r$"$F!"(B
$B$=$N8e$K!"$3$N%Q%C%A$rEv$F$^$9!#(B

 % zcat xdvi-14.tar.Z | tar xf -
 % cd xdvi-14
 % patch -p1 < xdvi-14j.patch
 % patch -p1 < $B$3$N%Q%C%A(B
 % make

...$B$F$J46$8$G$9!#(B

$B$G$O!#(B


*** /dev/nullThu Sep 10 20:54:19 1992
--- xdvi-14j-ps/README.xdvi-14jgsFri Sep 11 16:59:30 1992
***************
*** 0 ****
--- 1,95 ----
+ 
+ README for xdvi-14jgs
+ 
+  $B$3$N%Q%C%A$O(B xdvi patchlevel 14 $B$N(B ASCII-jTeX $BBP1~HG$K(B GNU
+ GhostScript $B$r;H$C$F(B Encapsulated PostScript $B7A<0$N%U%!%$%k$r<h$j9~$s(B
+ $B$@(B dvi $B$r%W%l%S%e!<$9$k5!G=$rIU2C$9$k%Q%C%A$G$9!#(B
+ 
+ 
+ * $B%$%s%9%H!<%kJ}K!(B
+ 
+  $B$^$:!"(Bxdvi-14.tar.Z $B$r%+%l%s%H%G%#%l%/%H%j$KE83+$7!"(Bxdvi-14j.patch $B$r(B
+ $BEv$F$^$9!#(B
+ 
+  % zcat xdvi-14.tar.Z | tar xf -
+  % cd xdvi-14
+  % patch -p1 < xdvi-14j.patch
+ 
+  $B$D$.$K!"$3$N%Q%C%1!<%8$rE83+$7!"%Q%C%A$rEv$F$^$9!#(B
+ 
+  % patch -p1 < diff.14j-14jgs
+ 
+  Imakefile $B$b$7$/$O(B Makefile $B$r<+J,$N4D6-$K9g$o$;$FJT=8$7$?8e!"(Bmake $B$7(B
+ $B$^$9!#(B
+ 
+  % make
+ 
+ $B0J>e$G=PMh>e$,$j$G$9!#(B
+ 
+  $BEvA3$N;v$J$,$i!"<B9T;~$K$O(B GhostScript v2.4 $B0J9_$,%$%s%9%H!<%k$5$l$F$$(B
+ $B$kI,MW$,$"$j$^$9!#(B
+ 
+ 
+ * $B5!G=(B
+ 
+  $B5/F0$O:#KxDL$j!"(B
+ 
+     % xdvi dokodoko/hogehoge.dvi
+ 
+  $B$N$h$&$K$7$^$9!#(Bhogehoge.dvi $B$K(B EPSF $B$,;XDj$5$l$F$$$?>l9g!"(B
+ hogehoge.dvi $B$N$"$k%G%#%l%/%H%j$+$i$=$l$rFI$_9~$_I=<($7$^$9!#$?$@$7!"(B
+ $B5/F0;~$N%G%U%)%k%H$G$O(B PS $B$OI=<($5$l$:!"$=$l$rJq$`OH$@$1$,I=<($5$l$^$9!#(B
+ CTRL-G $B$r2!$9$H(B PS $B$,I=<($5$l$^$9!#(BCTRL-G $B$O%H%0%kF0:n$7$^$9!#$^$?!"5/(B
+ $BF0;~$K(B -ps $B%*%W%7%g%s$r$D$1$k$H!":G=i$+$i(B PS $B$,I=<($5$l$^$9!#$^$?!"(B
+ .Xdefaults $B$K(B
+ 
+ XDvi.psSpesial: {true|false}
+ 
+ $B$H=q$$$F$bF1MM$G$9!#(B
+ 
+  $B$$$^$N$H$3$m!"(Bepsf.sty $B$"$k$$$O(B psfig.sty $B$r$b$A$$$F:n@.$7$?(B \special
+ $B$r=hM}$G$-$^$9!#(B
+ 
+  $B$^$?!"(BTPIC special $B$O=>MhDL$j%5%]!<%H$7$F$$$^$9!#(B
+ 
+ 
+ * $B%P%0(B
+  xdvi $B$N(B foreground/background color $B$,(B $B9u(B/$BGr(B $B0J30$N?'$K$J$C$F$$$k>l9g(B
+ $B$G$b(B PS $B$O>o$KGrCO$K9u(B($B$"$k$$$O(B PS $BCf$G;XDj$5$l$??'(B)$B$GIA2h$5$l$^$9!#$D(B
+ $B$^$j(B PS $B$N?';XDj$,M%@h$5$l$^$9!#$=$l0J30$NJ8;z$NItJ,$G$N(B
+ foreground/background $B$N;XDj$OM-8z$G$9!#$?$@$7!"%b%N%/%m%G%#%9%W%l%$$N(B
+ $B>l9g$K8B$C$F$O(B -rv $B$J$I$G(B PS $B$NI=<(?'$rJQ99$9$k$3$H$,=PMh$^$9!#(B
+ 
+  $B:#2s$N%P!<%8%g%s$G%5%]!<%H$7$F$$$k(B \special $B$N7A<0$O(B epsf.sty $B$"$k$$(B
+ $B$O(B psfig.sty $B$J$I$rMQ$$$F:n@.$7$?$b$N$K8B$i$l$F$$$^$9!#=>$C$F!"(B
+ jdvi2kps $B$J$I$G%5%]!<%H$7$F$$$k(B meipsmac.sty $B$J$I$K$h$C$F:n@.$7$?(B 
+ \special $B$O:#2s$N%P!<%8%g%s$G$O=hM}$G$-$^$;$s!#>-Mh$N%P!<%8%g%s$K4|BT(B
+ $B$7$^$7$g$&!#(B^_^;
+ 
+ 
+ * $B$=$NB>(B
+ 
+  gs-view.[ch] $B$K$O!"(BGhostScript $B$H$N%$%s%?%U%'!<%9$r$H$k$?$a$N%k!<%A%s(B
+ $B$,=q$+$l$F$$$^$9$,!"$3$NItJ,$O$+$J$jHFMQ$K;H$($k$h$&$K9M$($?$D$b$j$G$9!#(B
+ $B=>$C$F!"B>$N%W%m%0%i%`Cf$G<+M3$K$3$NItJ,$r%3%T!<$7$F;H$C$F$b$i$C$F$b7k(B
+ $B9=$G$9!#$=$l$K4X$7$F!"Cx:n8,>y$N8"Mx$r9T;H$9$k$D$b$j$O$"$j$^$;$s(B($B$?$@(B
+ $B$7!"0l@Z$N@UG$$O$H$j$^$;$s$,(B)$B!#(B
+ 
+ 
+ * $B:G8e$K(B
+ 
+  $B$3$N%Q%C%A%-%C%H$N%Y!<%?%F%9%H$K6(NO$7$F2<$5$C$?0J2<$N3'MM$K$O!"$3$N>l(B
+ $B$r<Z$j$F!"$*Ni$r=R$Y$?$$$H;W$$$^$9!#$"$j$,$H$&$4$6$$$^$7$?!#(B
+ 
+    $B1RF#(B@$BIY;NDLBgJ,%=%U%H%&%'%"%i%\%i%H%j(B (eto@ai.cs.fujitsu.co.jp)
+    $BAREg(B@$BElBg(B                             (kura@nacsis.ac.jp)
+    $BLnO$(B@$BIY;NDL9q:]8&(B                     (noro@iias.flab.fujitsu.co.jp)
+    $B@gED(B@$B5~Bg(B                             (senda@cr-x.kuis.kyoto-u.ac.jp)
+    $B8M@n(B@$BN)L?4[Bg(B                         (togawa@hestia.cs.ritsumei.ac.jp)
+    $BOI:d(B@NTT                              (wasisaka@wink.ntt.jp)
+    $B0BN1(B@$B:eBg(B                             (yasutome@satsuki.ics.osaka-u.ac.jp)
+ <$B%"%k%U%!%Y%C%H=g(B,$B7I>NN,(B>
+ 
+ 
+  $B$J$*$3$N%Q%C%A%-%C%H$K4X$9$k$*Ld$$9g$o$;!"$"$k$$$O%P%0%l%]!<%H$=$NB>$O(B
+ hiro@jaist-east.ac.jp $B$^$G$*$M$,$$$7$^$9!#(B
*** /dev/nullThu Sep 10 20:54:19 1992
--- xdvi-14j-ps/gs-view.hTue Sep  1 17:11:32 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 Pixmapunsigned long
+ #endif
+ 
+ struct bitmap_info {
+     Pixmapbitmap;
+     unsigned intwidth, height;
+ };
+ 
+ #ifdef X_H
+ structgs_info {
+     Display*disp;
+     Windowparent;
+     char*psfile;
+     Pixmappix;
+     unsigned intwidth, height;
+     unsigned intllx, lly;
+     unsigned inturx, ury;
+     FILE*gs_out;
+     int gs_pid;
+ };
+ #endif
+ 
+ struct psfig_info {
+     char*filename;
+     unsigned intllx, lly;
+     unsigned inturx, ury;
+     floathscale, vscale;
+     struct bitmap_infofig[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
+  *
+  */
*** /dev/nullThu Sep 10 20:54:19 1992
--- xdvi-14j-ps/gs-view.cThu Sep 10 21:27:37 1992
***************
*** 0 ****
--- 1,191 ----
+ /*
+  *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"
+ 
+ #defineGHOSTSCRIPT"gs"
+ 
+ #defineDEV_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 {
+     Windowparent;
+     AtomGS_DONE;
+     AtomGS_PAGE;
+ };
+ 
+ static Booleancheck_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;
+ }
+ 
+ intpsfig_to_bitmap(gs)
+  struct gs_info*gs;
+ {
+     charparam[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 charenv[BUFSIZ];
+ char*argv[6];
+ inti;
+ intpipe[2];
+ 
+ sprintf(env, "DISPLAY=%s", XDisplayString(gs-> disp));
+ putEnv(strDup(env));
+ sprintf(env, "GHOSTVIEW=%d %d", gs-> parent, gs-> pix);
+ putEnv(strDup(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 */
+ XEventev;
+ struct gs_propprops;
+ 
+ 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;
+ }
+ 
+ #ifdef DEBUG
+ voidmain(argc, argv)
+  intargc;
+  char**argv;
+ {
+     struct gs_infogs;
+     GCgc;
+     int screen;
+ 
+     gs.width = 400;
+     gs.height = 400;
+ 
+     gs.disp = XOpenDisplay("");
+     screen = DefaultScreen();
+     gs.parent = XCreateSimpleWindow(gs.disp, DefaultRootWindow(gs.disp),
+     0, 0, gs.width, gs.height, 1,
+     BlackPixel(gs.disp, screen),
+     BlackPixel(gs.disp, screen));
+     XMapWindow(gs.disp, gs.parent);
+ 
+     gc = XCreateGC(gs.disp, gs.parent, 0, 0);
+     XSetForeground(gs.disp, gc, WhitePixel(gs.disp, screen));
+     XSetBackground(gs.disp, gc, BlackPixel(gs.disp, screen));
+ 
+     XFlush(gs.disp);
+ 
+     gs.psfile = argv[1];
+     get_bounding_box(gs.psfile, & gs.llx, & gs.lly, & gs.urx, & gs.ury);
+ 
+     printf("bounding box: llx:%d lly:%d urx:%d ury:%d\n",
+    gs.llx, gs.lly, gs.urx, gs.ury);
+ 
+     gs.pix = XCreatePixmap(gs.disp, gs.parent, gs.width, gs.height, 1);
+ 
+     psfig_to_bitmap(& gs);
+ 
+     XCopyArea(gs.disp, gs.pix, gs.parent, gc,
+       0, 0, 400, 400, 0, 0);
+     XFlush(gs.disp);
+ 
+     getchar();
+ 
+     exit(0);
+ }
+ #endif
+ 
+ /*
+  * $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
+  *
+  */
*** /dev/nullThu Sep 10 20:54:19 1992
--- xdvi-14j-ps/ps.cTue Sep  1 19:35:15 1992
***************
*** 0 ****
--- 1,188 ----
+ /*
+  *ps.c
+  *
+  *by hiro@jaist-east.ac.jp
+  *
+  *$Revision: 1.4 $
+  *$Date: 1992/09/01 10:35:37 $
+  */
+ 
+ #include <stdio.h>
+ #include <string.h>
+ 
+ #include "xdvi.h"
+ 
+ #include "gs-view.h"
+ 
+ char*dirname(f1, f2)
+  char*f1;
+  char*f2;
+ {
+     char*p1;
+     char*p2;
+     char*p3;
+     static charbuf[BUFSIZ];
+ 
+     for (p2 = buf, p1 = f1, p3 = f1; *f1; f1 ++, p2 ++) {
+ if (*f1 == '/')
+   p1 = f1 + 1;
+ *p2 = *f1;
+     }
+     strcpy(buf + (p1 - p3), f2);
+ 
+     return buf;
+ }
+ 
+ intget_bounding_box(psfile, llx, lly, urx, ury)
+  char*psfile;
+  unsigned int*llx;
+  unsigned int*lly;
+  unsigned int*urx;
+  unsigned int*ury;
+ {
+     FILE*fptr;
+     charbuf[BUFSIZ];
+ 
+     if ((fptr = fopen(psfile, "r")) == NULL)
+ if ((fptr = xfopen(psfile)) == NULL) {
+     perror(psfile);
+     return -1;
+ }
+ 
+     do {
+ if (fgets(buf, BUFSIZ, fptr) == NULL) {
+     fprintf(stderr, "%s:unexpected EOF.\n", psfile);
+     return -1;
+ }
+ #ifdef nodef
+ if (buf[0] != '%') {
+     fprintf(stderr, "%s:not a EPSF.\n", psfile);
+     return -1;
+ }
+ #endif
+ if (strncmp(buf, "%%BoundingBox:", 14) == 0) {
+ #ifdef DEBUG
+     printf("buf: %s\n", buf);
+ #endif
+     sscanf(buf + 14, "%d %d %d %d", llx, lly, urx, ury);
+     break;
+ }
+     }while(1);
+ 
+     fclose(fptr);
+ 
+     return 0;
+ }
+ 
+ intstrrncmp(s1, s2, n)
+  char*s1;
+  char*s2;
+  intn;
+ {
+     char*sl1;
+     char*sl2;
+ 
+     sl1 = s1 + strlen(s1) - 1;
+     sl2 = s2 + strlen(s2) - 1;
+     for ( ; n != 0 && *sl1 == *sl2; n --, sl1 --, sl2 --)
+       ;
+     return n;
+ }
+ 
+ intpsSpecial(cp)
+  char*cp;
+ {
+     struct psfig_infopsfile;
+     char*ptr;
+     int hsize = 0, vsize = 0;
+     floathscale = 0.0, vscale = 0.0;
+     doubleatof();
+ 
+     psfile.filename = NULL;
+     ptr = strtok(cp, " =");
+     while (ptr != NULL) {
+ #ifdef DEBUG
+ printf("ptr: %s\n", ptr);
+ #endif
+ if (strrncmp(ptr, "file", 4) == 0) {
+     psfile.filename = dirname(dvi_name, strtok(NULL, " "));
+     if (get_bounding_box(psfile.filename,
+  & psfile.llx, & psfile.lly,
+  & psfile.urx, & psfile.ury))
+       return 1;
+ }
+ else if (strcmp(ptr, "hsize") == 0)
+   hsize = atoi(strtok(NULL, " "));
+ else if (strcmp(ptr, "vsize") == 0)
+   vsize = atoi(strtok(NULL, " "));
+ else if (strcmp(ptr, "hscale") == 0) {
+     hscale = atof(strtok(NULL, " "));
+     if (vscale == 0.0)
+       vscale = hscale;
+ }
+ else if (strcmp(ptr, "vscale") == 0) {
+     vscale = atof(strtok(NULL, " "));
+     if (hscale == 0.0)
+       hscale = vscale;
+ }
+ ptr = strtok(NULL, " =");
+     }
+     if (psfile.filename == NULL) {
+ fprintf(stderr, "\\special:ERROR.\n");
+ return 1;
+     }
+     if (hsize != 0)
+       hscale = ((float)hsize) / (psfile.urx - psfile.llx);
+     if (vsize != 0)
+       vscale = ((float)vsize) / (psfile.ury - psfile.lly);
+     if (hscale == 0.0)
+       hscale = vscale;
+     if (vscale == 0.0)
+       vscale = hscale;
+     if (hscale == 0.0 && vscale == 0.0) {
+ psfile.hscale = 1.0;
+ psfile.vscale = 1.0;
+     }
+     else {
+ psfile.hscale = hscale;
+ psfile.vscale = vscale;
+     }
+ 
+ #ifdef DEBUG
+     printf("filename: %s\nllx: %d, lly: %d, urx: %d, ury: %d\nhscale: %f, vscale: %f\n",
+    psfile.filename, psfile.llx, psfile.lly,
+    psfile.urx, psfile.ury, psfile.hscale, psfile.vscale);
+ #endif
+ 
+ #ifdef DEBUG_XDVI_PS
+     printf("draw_ps(psfile=\"%s\", PXL_H=%d, PXL_V=%d)\n",
+    psfile, PXL_H, PXL_V);
+ #endif
+ 
+     draw_ps(& psfile, PXL_H, PXL_V);
+ 
+     return 0;
+ }
+ 
+ #ifdef DEBUG
+ main()
+ {
+     applicationDoSpecial("psfile=fig1.ps hscale=0.5 vsize=100");
+ }
+ #endif
+ 
+ /*
+  * $Log: ps.c,v $
+  * Revision 1.4  1992/09/01  10:35:37  hiro
+  * support TPIC.
+  *
+  * Revision 1.3  1992/08/31  08:40:38  hiro
+  * change 'get_bounding_box()'.
+  *
+  * Revision 1.2  1992/08/31  07:59:04  hiro
+  * change search path for PS file.
+  *
+  * Revision 1.1  1992/08/29  09:23:04  hiro
+  * Initial revision
+  *
+  */
diff -r -c2 xdvi-14j/Imakefile xdvi-14j-ps/Imakefile
*** xdvi-14j/ImakefileSat Aug 29 15:33:10 1992
--- xdvi-14j-ps/ImakefileThu Sep  3 17:07:17 1992
***************
*** 1,6 ****
! DEFAULT_FONT_PATH=.:/usr/share/lib/tex/pk/pk300:/usr/share/lib/tex/pk/jpk300
  DEFAULT_VF_PATH=
  DEFAULT_FONT_SIZES=240:300:328.6:360:432:518.4:622:746.4:895.8:1075
  DEFS=-DUSE_PK -DUSE_GF -DUSE_PXL -DMSBITFIRST -DBMSHORT -DBUTTONS -DGREY
  
  DEPLIBS=XawClientDepLibs
--- 1,14 ----
! 
! #definePS
! 
! DEFAULT_FONT_PATH=.:/usr/local/lib/tex/fonts:/usr/local/lib/tex/jfonts
  DEFAULT_VF_PATH=
  DEFAULT_FONT_SIZES=240:300:328.6:360:432:518.4:622:746.4:895.8:1075
+ 
+ #ifdef PS
+ DEFS=-DUSE_PK -DUSE_GF -DUSE_PXL -DMSBITFIRST -DBMSHORT -DBUTTONS -DGREY -DPS
+ #else
  DEFS=-DUSE_PK -DUSE_GF -DUSE_PXL -DMSBITFIRST -DBMSHORT -DBUTTONS -DGREY
+ #endif
  
  DEPLIBS=XawClientDepLibs
***************
*** 9,14 ****
  SYS_LIBRARIES=$(MATHLIB)
  LINTLIBS=$(LINTXAW) $(LINTXMU) $(LINTXTOOL) $(LINTEXTENSIONLIB) $(LINTXLIB) -lm
! SRCS=xdvi.c dvi_init.c dvi_draw.c fontfmts.c vf.c util.c font_open.c tpic.c
! OBJS=xdvi.o dvi_init.o dvi_draw.o fontfmts.o vf.o util.o font_open.o tpic.o
  DEFINES=$(DEFS) -DDEFAULT_FONT_PATH=\"$(DEFAULT_FONT_PATH)\" \
    -DDEFAULT_VF_PATH=\"$(DEFAULT_VF_PATH)\" \
--- 17,34 ----
  SYS_LIBRARIES=$(MATHLIB)
  LINTLIBS=$(LINTXAW) $(LINTXMU) $(LINTXTOOL) $(LINTEXTENSIONLIB) $(LINTXLIB) -lm
! 
! #ifdef PS
! #definePS_SRCgs-view.c ps.c
! #definePS_OBJgs-view.o ps.o
! #else
! #definePS_SRC
! #definePS_OBJ
! #endif
! 
! SRCS=xdvi.c dvi_init.c dvi_draw.c fontfmts.c vf.c util.c font_open.c \
!      PS_SRC tpic.c
! OBJS=xdvi.o dvi_init.o dvi_draw.o fontfmts.o vf.o util.o font_open.o \
!      PS_OBJ tpic.o
! 
  DEFINES=$(DEFS) -DDEFAULT_FONT_PATH=\"$(DEFAULT_FONT_PATH)\" \
    -DDEFAULT_VF_PATH=\"$(DEFAULT_VF_PATH)\" \
diff -r -c2 xdvi-14j/Makefile xdvi-14j-ps/Makefile
*** xdvi-14j/MakefileSun Feb 16 07:57:00 1992
--- xdvi-14j-ps/MakefileTue Sep  1 17:42:47 1992
***************
*** 5,12 ****
  # $Source: /u1/uus/vs2/xdvi/RCS/Makefile,v $
  #
! DEFAULT_FONT_PATH=/usr/local/tex/fonts
  DEFAULT_VF_PATH=/usr/local/tex/fonts/vf
  DEFAULT_FONT_SIZES=300:328.6:360:432:518.4:622:746.4
! DEFS=-DUSE_PK -DMSBITFIRST -DBMSHORT -DBUTTONS
  FONTDEFINES=-DDEFAULT_FONT_PATH=\"$(DEFAULT_FONT_PATH)\" \
    -DDEFAULT_VF_PATH=\"$(DEFAULT_VF_PATH)\" \
--- 5,12 ----
  # $Source: /u1/uus/vs2/xdvi/RCS/Makefile,v $
  #
! DEFAULT_FONT_PATH=/usr/local/lib/tex/fonts:/usr/local/lib/tex/jfonts/dm:/usr/local/lib/tex/jfonts/dg:/usr/local/lib/tex/local.fonts
  DEFAULT_VF_PATH=/usr/local/tex/fonts/vf
  DEFAULT_FONT_SIZES=300:328.6:360:432:518.4:622:746.4
! DEFS=-DUSE_PK -DMSBITFIRST -DBMSHORT -DBUTTONS -DPS
  FONTDEFINES=-DDEFAULT_FONT_PATH=\"$(DEFAULT_FONT_PATH)\" \
    -DDEFAULT_VF_PATH=\"$(DEFAULT_VF_PATH)\" \
***************
*** 13,17 ****
    -DDEFAULT_FONT_SIZES=\"$(DEFAULT_FONT_SIZES)\" \
    -DDEFAULT_SUBDIR_PATH=\"$(DEFAULT_SUBDIR_PATH)\"
! TOP=/usr/X11
  INCDIR=$(TOP)/include
  LIBDIR=$(TOP)/lib
--- 13,17 ----
    -DDEFAULT_FONT_SIZES=\"$(DEFAULT_FONT_SIZES)\" \
    -DDEFAULT_SUBDIR_PATH=\"$(DEFAULT_SUBDIR_PATH)\"
! TOP=/usr/local/X11R5
  INCDIR=$(TOP)/include
  LIBDIR=$(TOP)/lib
***************
*** 23,31 ****
  INCLUDES=-I$(INCDIR)
  CFLAGS=-O $(INCLUDES) $(DEFS)
! LIBS=-L$(LIBDIR) -lXaw $(XMULIB) -lXt $(EXTENSIONLIB) -lX11 -lm
  #LIBS=-L$(LIBDIR) -lX11 -lm
! SRCS=xdvi.c dvi_init.c dvi_draw.c fontfmts.c vf.c util.c font_open.c tpic.c
! OBJS=xdvi.o dvi_init.o dvi_draw.o fontfmts.o vf.o util.o font_open.o tpic.o
! CC=gcc
  LINT=lint
  # LINT=$(CC) -c -Wall -Wshadow -Wpointer-arith
--- 23,31 ----
  INCLUDES=-I$(INCDIR)
  CFLAGS=-O $(INCLUDES) $(DEFS)
! LIBS=-L$(LIBDIR) -lXaw $(XMULIB) -lXt $(EXTENSIONLIB) -lX11 -lm -lXwchar
  #LIBS=-L$(LIBDIR) -lX11 -lm
! SRCS=xdvi.c dvi_init.c dvi_draw.c fontfmts.c vf.c util.c font_open.c ps.c gs-view.c tpic.c
! OBJS=xdvi.o dvi_init.o dvi_draw.o fontfmts.o vf.o util.o font_open.o ps.o gs-view.o tpic.o
! CC=cc
  LINT=lint
  # LINT=$(CC) -c -Wall -Wshadow -Wpointer-arith
***************
*** 43,49 ****
  dvi_init.o:xdvi.h dvi.h
  dvi_draw.o:xdvi.h dvi.h
- tpic.o:xdvi.h
  fontfmts.o: xdvi.h pk.c gf.c pxl.c
  util.o:xdvi.h
  
  font_open.o:font_open.c xdvi.h
--- 43,50 ----
  dvi_init.o:xdvi.h dvi.h
  dvi_draw.o:xdvi.h dvi.h
  fontfmts.o: xdvi.h pk.c gf.c pxl.c
  util.o:xdvi.h
+ ps.o: gs-view.h xdvi.h
+ gs-view.o: gs-view.h xdvi.h
  
  font_open.o:font_open.c xdvi.h
diff -r -c2 xdvi-14j/tpic.c xdvi-14j-ps/tpic.c
*** xdvi-14j/tpic.cFri Sep  4 17:16:52 1992
--- xdvi-14j-ps/tpic.cTue Sep  1 17:21:14 1992
***************
*** 304,309 ****
  intxp, yp;
  intN;
! intlastx= -1;
! intlasty;
  intt1, t2, t3;
  intsteps;
--- 304,308 ----
  intxp, yp;
  intN;
! intlastx, lasty;
  intt1, t2, t3;
  intsteps;
***************
*** 311,317 ****
  register int i, w;
  
- #ifdeflint
- lasty = -1;
- #endif
  N = path_len + 1;
  xx[0] = xx[1];
--- 310,313 ----
***************
*** 331,335 ****
  xp = (t1*xx[i+2] + t2*xx[i+1] + t3*xx[i] + 50000) / 100000;
  yp = (t1*yy[i+2] + t2*yy[i+1] + t3*yy[i] + 50000) / 100000;
! if (lastx > -1) line_btw(lastx, lasty, xp, yp);
  lastx = xp;
  lasty = yp;
--- 327,331 ----
  xp = (t1*xx[i+2] + t2*xx[i+1] + t3*xx[i] + 50000) / 100000;
  yp = (t1*yy[i+2] + t2*yy[i+1] + t3*yy[i] + 50000) / 100000;
! if (i != 0 || j != 0) line_btw(lastx, lasty, xp, yp);
  lastx = xp;
  lasty = yp;
***************
*** 424,427 ****
--- 420,426 ----
  /* throw away the path -- jansteen */
  else if (strcmp(command, "ip") == 0) path_len = 0;
+ #ifdef PS
+ else if (psSpecial(orig_cp) == 0);
+ #endif
  else if (!hush_spec_now)
      Fprintf(stderr, "%s:  special \"%s\" not implemented\n", prog,
diff -r -c2 xdvi-14j/util.c xdvi-14j-ps/util.c
*** xdvi-14j/util.cSat Aug 29 15:33:12 1992
--- xdvi-14j-ps/util.cTue Sep  1 18:02:48 1992
***************
*** 210,211 ****
--- 210,256 ----
  return x;
  }
+ 
+ #ifdef PS
+ 
+ /*
+  *
+  */
+ 
+ extern char**environ;
+ 
+ char*strDup(str)
+  char*str;
+ {
+     char*ptr = xmalloc(strlen(str), "strdup");
+ 
+     return strcpy(ptr, str);
+ }
+ 
+ #ifdef BCOPY
+ #definememcpy(a, b, n)bcopy(b, a, n)
+ #endif
+ 
+ voidputEnv(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*)xmalloc(sizeof(char*) * (n + 2), "putenv");
+ 
+ memcpy(ptr, environ, sizeof(char*) * n);
+ environ = ptr;
+ environ[n] = env;
+ environ[n+1] = NULL;
+     }
+     else
+       environ[n] = env;
+ }
+ #endif
diff -r -c2 xdvi-14j/xdvi.c xdvi-14j-ps/xdvi.c
*** xdvi-14j/xdvi.cSat Aug 29 15:33:13 1992
--- xdvi-14j-ps/xdvi.cThu Sep 10 21:11:30 1992
***************
*** 552,555 ****
--- 552,560 ----
  #endif
  
+ #definetoint(x)((int) ((x) + 0.5))
+ #definexconv(x)(toint(specialConv*(x))/shrink_factor + PXL_H)
+ #defineyconv(y)(toint(specialConv*(y))/shrink_factor + PXL_V)
+ 
+ 
  /********************************
   *  tpic routines*
***************
*** 562,569 ****
  */
  
- #definetoint(x)((int) ((x) + 0.5))
- #definexconv(x)(toint(specialConv*(x))/shrink_factor + PXL_H)
- #defineyconv(y)(toint(specialConv*(y))/shrink_factor + PXL_V)
- 
  /*
   *Draw a line from (fx,fy) to (tx,ty).
--- 567,570 ----
***************
*** 625,628 ****
--- 626,805 ----
  }
  
+ #ifdef PS
+ 
+ #include <sys/stat.h>
+ #include "gs-view.h"
+ 
+ #definePSFIG_CACHE_SIZE16
+ 
+ struct psfig_cache_struct {
+     Pixmappix;
+ 
+     char*psfile;
+     unsigned intwidth, height;
+     time_tps_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 }};
+ 
+ static Booleanuse_ps_special = FALSE;
+ 
+ Pixmapget_cached_psfig(psfile, width, height, flag)
+  char*psfile;
+  unsigned intwidth, height;
+  Booleanflag;
+ {
+     int i;
+     int hash = 0;
+     struct psfig_cache_struct*cache;
+     struct statbuf;
+ 
+     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(DISP, cache-> pix);
+       cache-> pix = (Pixmap)0;
+       return (Pixmap)0;
+   }
+       }
+     return 0;
+ }
+ 
+ voidput_cache_psfig(pix, psfile, width, height)
+  Pixmappix;
+  char*psfile;
+  unsigned intwidth, height;
+ {
+     int i;
+     int hash = 0;
+     struct psfig_cache_struct*cache;
+     struct statbuf;
+ 
+     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*)xmalloc(sizeof(struct psfig_cache_struct),
+       "caching PSfig");
+ 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;
+     }
+ }
+ 
+ voiddraw_ps(psfile, x, y)
+  struct psfig_info*psfile;
+  intx, y;
+ {
+     struct gs_infogs;
+     int cx = x,
+                 cy = y;
+     static GCpix_gc = 0;
+ 
+     gs.psfile = psfile-> filename;
+ 
+     gs.width  = (psfile-> urx - psfile-> llx) * psfile-> hscale / 72.0
+       * specialConv * 1000.0 / shrink_factor;
+     gs.height = (psfile-> ury - psfile-> lly) * psfile-> vscale / 72.0
+       * specialConv * 1000.0 / shrink_factor;
+ 
+ #ifdef DEBUG_XDVI_PS
+     printf("specialConv: %f\n", specialConv);
+     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(gs.psfile, gs.width, gs.height);
+ if (gs.pix == 0) {
+     gs.disp = DISP;
+     gs.parent = WINDOW(currwin);
+     gs.pix = XCreatePixmap(DISP, WINDOW(currwin),
+    gs.width, gs.height,
+    DefaultDepthOfScreen(SCRN));
+     gs.llx = psfile-> llx;
+     gs.lly = psfile-> lly;
+     gs.urx = psfile-> urx;
+     gs.ury = psfile-> ury;
+ 
+      if (pix_gc == 0) {
+          pix_gc = XCreateGC(DISP, WINDOW(currwin), 0, 0);
+  XCopyGC(DISP, foreGC,
+  GCFunction | GCForeground | GCBackground, pix_gc);
+   
+  if (DefaultDepthOfScreen(SCRN) > 1) {
+      XSetFunction(DISP, pix_gc, GXcopy);
+  } else if (WhitePixelOfScreen(SCRN) == 1) {
+      if (reverse) {
+  XSetFunction(DISP, pix_gc, GXorInverted);
+      } else {
+  XSetFunction(DISP, pix_gc, GXand);
+      }
+  }
+      }
+ 
+     psfig_to_bitmap(& gs);
+ 
+     put_cache_psfig(gs.pix, gs.psfile, gs.width, gs.height);
+ }
+ 
+ XCopyArea(DISP, gs.pix, WINDOW(currwin), pix_gc,
+   0, 0, gs.width, gs.height,
+   cx - currwin.base_x, cy - currwin.base_y);
+     }
+     else {
+ XDrawRectangle(DISP, WINDOW(currwin), ruleGC,
+        cx - currwin.base_x, cy - currwin.base_y,
+        gs.width - 1, gs.height - 1);
+     }
+ }
+ 
+ #endif PS
+ 
  /*
   *Put a rectangle on the screen.  hl determines the GC.
***************
*** 1527,1530 ****
--- 1704,1713 ----
  break;
  #endif
+ #ifdef PS
+     case '\007':/* CTRL-G */
+ use_ps_special = ! use_ps_special;
+ --dvi_time;
+ break;
+ #endif
      case 'R':
  /* reread DVI file */
***************
*** 2048,2051 ****
--- 2231,2238 ----
  {"-mgs4",".magnifierSize4",XrmoptionSepArg,(caddr_t) NULL},
  {"-mgs5",".magnifierSize5",XrmoptionSepArg,(caddr_t) NULL},
+ #ifdefPS
+ {"-ps",".psSpecial",XrmoptionNoArg,(caddr_t) "on"},
+ {"+ps",".psSpecial",XrmoptionNoArg,(caddr_t) "off"},
+ #endif
  #ifdefGREY
  {"-nogrey",".grey",XrmoptionNoArg,(caddr_t) "off"},
***************
*** 2128,2131 ****
--- 2315,2322 ----
  {"magnifierSize5", "MagnifierSize", XtRInt, sizeof(int),
    (Cardinal) &mg_size[4], XtRInt, (caddr_t) &mg_size[4]},
+ #ifdefPS
+ {"psSpecial", "PsSpecial", XtRBoolean, sizeof(Boolean),
+   (Cardinal)&use_ps_special, XtRBoolean, (caddr_t) &use_ps_special},
+ #endif
  #ifdefGREY
  {"grey", "Grey", XtRBoolean, sizeof (Boolean),
--
                                               | $BKLN&@hC<2J3X5;=QBg3X1!Bg3X(B |
        by $B$R$m$T!<(B                            |    $B%=%U%H%&%'%"4pAC9V:B(B    |
                                               |          $B?9ED>;9((B          |
                                               |    hiro@jaist-east.ac.jp   |
