From: kaneko@rcais.tohoku.ac.jp (Yutaka Kaneko)
Newsgroups: fj.lang.postscript,fj.sources,fj.sys.news
Subject: unofficial patch for Ghostscript 2.4
Date: 11 Apr 92 06:57:03 GMT
Followup-To: fj.lang.postscript
Distribution: fj
Organization: Research Center for Applied Information Sciences, Tohoku
	University


  fj.lang.postscript, fj.sources, fj.sys.news $@$K(Jcross post$@$7$^$9!#(J

  Ghostscript 2.4 $@$G(J $@=PNO%U%!%$%k$H$7$F(J "/dev/fd/#" $@$r;XDj$G(J
$@$-$k$h$&$K$9$k$?$a$N(J un-official patch $@$G$9!#(J

  gdevn533.c$@$,$^$H$b$KF0$/$h$&$K$9$k(Jpatch$@$b4^$_$^$9!#(J

  nwp533$@MQ(Jpatch$@$O(J Hannu.ARonsson@cs.hut.fi$@;a$N$b$N$,$=$N$^$^(J
gs2.4$@$G$bF0$/$H;W$o$l$^$9$,!"(Jgs2.4$@$G!"(J-sOUTPUTFILE= option$@$,(J
$@DI2C$5$l(J$@$?$N$G$=$l$KBP1~$7$F$_$^$7$?!#$^$?!"(JOUTPUTFILE$@$H$7$F!"(J
file descriptor (/dev/fd/$@?t;z(J)$@$r2r<a$9$k$h$&$K(J$@$7$^$7$?$N$G!"(J
nwp533$@$K8B$i$:!"(Jlpr, lp$@MQ$N(Jprinter filter$@$,=q$-$d$9$/$J$k$O(J
$@$:$G$9!#(J

  $@6=L#$,$"$j$^$7(J$@$?$i$*;n$7$/$@$5$$!#(J

--
$@ElKLBg3X!&1~>p8&!J>pJs9)3X@l96(J  ($@#47n$+$i$b(J)$@#D#C#3!K(J
$@6b;R!!M5(J (kaneko@rcais.tohoku.ac.jp)
--
#!/bin/sh
# This is a shell archive (produced by shar 3.49)
# To extract the files from this archive, save it to a file, remove
# everything above the "!/bin/sh" line above, and type "sh file_name".
#
# made 04/11/1992 06:13 UTC by kaneko@east
# Source directory /usr4/pds/gs-2.4/PATCH
#
# existing files will NOT be overwritten unless -c is specified
#
# This shar contains:
# length  mode       name
# ------ ---------- ------------------------------------------
#   2940 -rw-r--r-- README
#    368 -rw-r--r-- PATCH.gp_unix.c
#   1143 -rw-r--r-- PATCH.lpf_gs533
#   6261 -rw-r--r-- PATCH.nwp533
#
# ============= README ==============
if test -f 'README' -a X"$1" != X"-c"; then
	echo 'x - skipping README (File already exists)'
else
echo 'x - extracting README (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'README' &&
Subject: unofficial patch for Ghostscript 2.4
X
X  Ghostscript 2.4 $@$G(J $@=PNO%U%!%$(J$@%k$H$7$F(J "/dev/fd/#" $@$r;XDj$G(J
X$@$-$k$h$&$K$9$k$?$a$N(J un-official patch $@$G$9!#(Jgdevn533.c$@$,$^(J
X$@$H$b$KF0$/(J$@$h$&$K$9$k(Jpatch$@$b4^$_$^$9!#(J
X
X  patch$@$O(J3$@$D$"$j$^$9!#(J
X
X  (1)$@$O(Junix$@$G%G%P%$%9$H$7$F(Jprinter$@$r;H$C$F$$(J$@$k$H$-$K$@$1!"M-(J
X$@8z$G$9!#(J(2), (3)$@$O(Jsony news$@$N(Jnwp533$@%W%j%s%?MQ$G$9!#(J
X
X
(1) PATCH.gp_unix.c
X
X  Ghostscript 2.4$@$O!"=PNO%G%P%$%9$,(Jprinter$@$N$H$-(J -s
OUTPUTFILE= $@%*%W%7%g%s$r;XDj$9$k$H=PNO$r;XDj$7$?%U%!%$(J$@%k$KAw(J
X$@$k$3$H$,=PMh$^$9(J($@>\$7$/$O(Jgs24/use.doc$@$r;2>H$7$F$/$@$5$$(J)$@!#(J
X
X  lpr(BSD-1)$@$d!"(Jlp(SystemV-1)$@$+(J$@$i(Jghostscript$@$r8F$S=P$;$k$h$&(J
X$@$K$9$k$H$-$K!"(J/bin/sh$@$N(Jfile descriptor$@$NJ#@=5!G=$r;H$($k$h$&(J
X$@$K!"=PNO(J$@$r;XDj$7$?(Jfile descriptor$@$KAw$l$k$h$&$K$7$F$_$?$N$,!"(J
X$@$3$N(Jpatch$@$G$9!#(JOUTPUTFILE $@$H$7$F!"(J"/dev/fd/$@?t;z(J"$@$r;XDj$9$k$H!"(J
X$@$=$N(Jfile descriptor$@$r(Jfdopen(3)$@$7$F!"$=$3$K=PNO$7$^$9!#(J
X  
X  lpr(BSD-1)$@!"(Jlp(SystemV-1)$@$J$I$G;H$o$l$k3F<o(Jprinter$@MQ(Jfilter
X$@$N$h$&$K!"(JGhostscript$@$N=PNO$rI8=`=PNO$K=P$7$?$$>l9g!"(J/bin/sh
script$@$r:n$j!"$=$NCf$G<!$N$h$&$K$9$l$P$h$$$G$7$g$&!#(J
X
X    (/usr/local/bin/gs24 -dQUIET -sDEVICE=printer-device \
X        -dNOPAUSE -sOUTPUTFILE=/dev/fd/3 - 3>&1 1>&2) 2>/tmp/gsout$$
X
X
(2) PATCH.nwp533
X
X  sony$@$N(Jnwp533 printer$@MQ$N(Jpatch$@!#(J
X
X  Hannu.ARonsson@cs.hut.fi $@;a$N(Jnwp533$@MQ(Jpatch$@$O$=$N$^$^!"(J
ghostscript 2.4$@$G$bF0:n$9$k$H;W$o$l$^$9$,!"$3$l$r>e5-(J
X$@$N(J-sOUTPUTFILE=file $@%*%W%7%g%s$,F0:n$9$k$h$&$K2~(J$@B$$7$^$7$?!#(J
X$@$J$*!"4D6-JQ?t(J PRINTERFILTER $@$O;2>H$5$l$J$/$J$j$^$7$?!#(J
X
X  patch$@$O%*%j%8%J%k$N(Jghostscript 2.4$@Fb(Jgdevn533.c$@$KBP$9$k$b$N(J
X$@$G$9!#(J
X
X  SONY NEWS$@$G%3%s%Q%$%k$7$?>l9g(JOUTPUTFILE$@$,;XDj$5$l$J$1$l(J$@$P(J
"/dev/lbp"$@$,;H$o$l$k!#(JSONY NEWS$@0J30$G$O!"B>$N(Jprinter device
X$@$HF1$8$K(Jscratch file$@$,:n$i$l$^$9!#(J
X
X  $@$o$,8&5f<<$N$h$&$K(Jnwp533$@$,(JNEWS 830$@$K(Jghostscript$@$OB.$$%^%7(J
X$@%s(J(HP-9000/730$@$,$"$k$N$@(J(^^) )$@Ey$GF0$+$7(J$@!"(Jbitmap$@$N$_$r(JNEWS$@$K(J
X$@Aw$k!"$H$$$&;v$b2DG=$K$J$k$O$:$G$"$k!#(J
X
X
(3) PATCH.lpf_gs533
X
X  Hannu.ARonsson@cs.hut.fi $@;a$N(J lpf_gs533$@$KBP$9$k(Jpatch$@$G$9!#(J
X
X
(4) $@JdB-!&$=$NB>(J
X
X  Hannu.ARonsson@cs.hut.fi $@;a(J$@$N(Jpatch$@$H$O0J2<$N5-;v$G$"$k!#0J(J
X$@2<$N5-;v$K4^$^$l$k(JPATCH.gs_init$@!"(JPATCH.newsfb$@$O$3$N5-;v$K$O(J
X$@4^$^$l$J(J$@$$!#(J
X
X    From: Hannu.ARonsson@cs.hut.fi (haa)
X    Newsgroups: gnu.ghostscript.bug
X    Subject: Sony nwp533 and frame buffer diffs for 2.2 (Re: sony nwp533 driver)
X    Message-ID: <HAA.91Aug8175552@zen.hut.fi>
X    Date: 8 Aug 91 21:55:52 GMT
X    References: Hannu.ARonsson@cs.hut.fi (haa)
X    Sender: gnulists@ai.mit.edu
X    Distribution: gnu
X    Organization: Helsinki University of Technology, Finland
X    Lines: 496
X    Approved: bug-ghostscript@prep.ai.mit.edu
X
X
X  $@$3$N(Jpatch$@$K$h$j@8$8$?(J$@%P%0$N@UG$$O;d$K$"$j$^$9!#O"Mm$r$$$?(J
X$@$@$1$l$PA1=h$7$^$9!#$?$@$7!"@UG$$NM-L5$K$h$i$:!";HMQCfH/@8$7(J
X$@$?(J$@B;32$NJ]>Z$O$7$^$;$s!#2~B$$7$?>l9g$O!"$3$N5-;v$N(Jheader$@$r0z(J
X$@MQ$7!"2~B$%u=j$rL@5-$7$F$/$@$5$$!#$=$NB>$O(JGNU$@$N(JCopyright$@$K=>(J
X$@$$$^$9!#(J
X
X  sony_news$@0J30$G$N(Jgdevn533.c$@$N%3%s%Q%$%k$*$h$SF0:n!"(Jnwp533
X$@$N0[>o(J($@;f(J$@@Z$l!";f5M$^$j!"8N>c(J)$@;~$NF0:n$O$"$^$j<+?.$,$"$j$^$;(J
X$@$s!#(J
X
X
X$@J8@U!'(J $@6b;RM5(J(kaneko@rcais.tohoku.ac.jp)
SHAR_EOF
chmod 0644 README ||
echo 'restore of README failed'
Wc_c="`wc -c < 'README'`"
test 2252 -eq "$Wc_c" ||
	echo 'README: original size 2252, current size' "$Wc_c"
fi
# ============= PATCH.gp_unix.c ==============
if test -f 'PATCH.gp_unix.c' -a X"$1" != X"-c"; then
	echo 'x - skipping PATCH.gp_unix.c (File already exists)'
else
echo 'x - extracting PATCH.gp_unix.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'PATCH.gp_unix.c' &&
*** gp_unix.c.orig	Fri Apr 10 15:34:47 1992
--- gp_unix.c	Fri Apr 10 17:11:55 1992
***************
*** 111,116 ****
--- 111,118 ----
X  	   gp_open_scratch_file(gp_scratch_file_name_prefix, fname, "wb") :
X  	   fname[0] == '|' ?
X  	   popen(fname + 1, "wb") :
+ 	   !strncmp(fname, "/dev/fd/", 8) ?
+ 	   fdopen(atoi(fname+8), "wb") :
X  	   fopen(fname, "wb"));
X  }
X  
SHAR_EOF
chmod 0644 PATCH.gp_unix.c ||
echo 'restore of PATCH.gp_unix.c failed'
Wc_c="`wc -c < 'PATCH.gp_unix.c'`"
test 368 -eq "$Wc_c" ||
	echo 'PATCH.gp_unix.c: original size 368, current size' "$Wc_c"
fi
# ============= PATCH.lpf_gs533 ==============
if test -f 'PATCH.lpf_gs533' -a X"$1" != X"-c"; then
	echo 'x - skipping PATCH.lpf_gs533 (File already exists)'
else
echo 'x - extracting PATCH.lpf_gs533 (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'PATCH.lpf_gs533' &&
*** old/lpf_gs533	Sat Apr 11 13:55:36 1992
--- lpf_gs533	Sat Apr 11 13:55:12 1992
***************
*** 4,9 ****
--- 4,13 ----
X  #
X  # Authors: haa, kivinen
X  #
+ #
+ # for Ghostscript 2.4 with '/dev/fd/# patch'
+ #     Modified By Y. kaneko
+ #
X  
X  NAME="unknown"
X  HOST="unknown"
***************
*** 19,26 ****
X  
X  rm -f /tmp/gsout$$
X  # Gs writes to fd3, stdin goes to stderr.
! (PRINTERFILTER=3 /p/src2/gs-2.2-j/gs -dQUIET -sDEVICE=nwp533 \
! 	-dNOPAUSE -dDITHERPPI=32.5 - 3>&1 1>&2) 2>/tmp/gsout$$
X  (echo "Your GhostScript job has finished. [version gs-2.2-j]"
X   awk '	/^in nwp533 open/ { next; }
X  	/^in nwp533 output page / { pages++; next; }
--- 23,35 ----
X  
X  rm -f /tmp/gsout$$
X  # Gs writes to fd3, stdin goes to stderr.
! #(PRINTERFILTER=3 /p/src2/gs-2.2-j/gs -dQUIET -sDEVICE=nwp533 \
! #	-dNOPAUSE -dDITHERPPI=32.5 - 3>&1 1>&2) 2>/tmp/gsout$$
! 
! # By Y. Kaneko
! (/p/src2/gs-2.4/gs -dQUIET -sDEVICE=nwp533 \
! 	-dNOPAUSE -sOUTPUTFILE=/dev/fd/3 - 3>&1 1>&2) 2>/tmp/gsout$$
! 
X  (echo "Your GhostScript job has finished. [version gs-2.2-j]"
X   awk '	/^in nwp533 open/ { next; }
X  	/^in nwp533 output page / { pages++; next; }
SHAR_EOF
chmod 0644 PATCH.lpf_gs533 ||
echo 'restore of PATCH.lpf_gs533 failed'
Wc_c="`wc -c < 'PATCH.lpf_gs533'`"
test 1143 -eq "$Wc_c" ||
	echo 'PATCH.lpf_gs533: original size 1143, current size' "$Wc_c"
fi
# ============= PATCH.nwp533 ==============
if test -f 'PATCH.nwp533' -a X"$1" != X"-c"; then
	echo 'x - skipping PATCH.nwp533 (File already exists)'
else
echo 'x - extracting PATCH.nwp533 (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'PATCH.nwp533' &&
*** gdevn533.c.orig	Sat Feb 29 05:43:32 1992
--- gdevn533.c	Fri Apr 10 22:55:50 1992
***************
*** 20,29 ****
--- 20,32 ----
X  /* gdevn533.c */
X  /* Sony NWP-533 driver for GhostScript */
X  #include "gdevprn.h"
+ #include "gp.h"
X  #include <sys/file.h>
X  #include <sys/ioctl.h>
X  #include <newsiop/lbp.h>
X  
+ #include <errno.h>
+ 
X  /* The device descriptor */
X  private dev_proc_open_device(nwp533_open);
X  private dev_proc_output_page(nwp533_output_page);
***************
*** 40,45 ****
--- 43,49 ----
X  	1, 0);
X  
X  private int printer_file = -1;
+ private int is_dev_lbp = 1;
X  
X  /* return True if should retry - False if should quit */
X  private int
***************
*** 51,56 ****
--- 55,62 ----
X    int waiting;
X    int retry_after_return;
X  
+   if(!is_dev_lbp) return ( 0 == 0 );
+ 
X    if(ioctl(printer_file, LBIOCRESET, 0) < 0)
X      return (0 == 1);
X    if(ioctl(printer_file, LBIOCSTATUS, &status) < 0)
***************
*** 92,100 ****
X  	}
X        if(waiting)
X  	{
! 	  ioctl(1, LBIOCRESET, 0);
X  	  sleep(5);
! 	  ioctl(1, LBIOCSTATUS, &status);
X  	}
X      }
X    while(waiting);
--- 98,106 ----
X  	}
X        if(waiting)
X  	{
! 	  ioctl(printer_file, LBIOCRESET, 0);	/* fd was 1 --haa */
X  	  sleep(5);
! 	  ioctl(printer_file, LBIOCSTATUS, &status);
X  	}
X      }
X    while(waiting);
***************
*** 104,115 ****
X  private int
X  nwp533_open(gx_device *dev)
X  {
X    fprintf(stderr, "in nwp533 open\n");
X  
-   if(printer_file < 0)
-     if((printer_file = open("/dev/lbp", O_WRONLY)) < 0)
-       return printer_file;
- 
X    return gdev_prn_open(dev);
X  }
X  
--- 110,119 ----
X  private int
X  nwp533_open(gx_device *dev)
X  {
+ #if 0
X    fprintf(stderr, "in nwp533 open\n");
+ #endif
X  
X    return gdev_prn_open(dev);
X  }
X  
***************
*** 116,125 ****
X  private int
X  nwp533_close(gx_device *dev)
X  {
X    fprintf(stderr, "in nwp533 close\n");
X  
!   if(printer_file >= 0)
X      {
X        close(printer_file);
X        printer_file = -1;
X      }
--- 120,141 ----
X  private int
X  nwp533_close(gx_device *dev)
X  {
+ #if 0
X    fprintf(stderr, "in nwp533 close\n");
+ #endif
X  
!   if(is_dev_lbp)
!       if(printer_file >= 0)
X      {
+ 	 /* Wait for the current printing to finish before close --haa*/
+     c_restart:
+ 	 if(ioctl(printer_file, LBIOCSTOP, 0) < 0)
+ 	 {
+ 	      if(analyze_error())
+ 		   goto c_restart;
+ 	      perror("Waiting for device");
+ 	      /* return -1;	/* maybe not wise in *_close(?) */
+ 	 }
X        close(printer_file);
X        printer_file = -1;
X      }
***************
*** 127,158 ****
X    return gdev_prn_close(dev);
X  }
X  
X  /* Send the page to the printer. */
X  private int
X  nwp533_output_page(gx_device *dev, int num_copies, int flush)
X  {
!   fprintf(stderr, "in nwp533 output page [%d, %d]\n",
! 	  dev->width, dev->height);
X  
X   restart:
!   if(ioctl(printer_file, LBIOCSTOP, 0) < 0)
!     {
!       if(analyze_error())
! 	goto restart;
!       perror("Waiting for device");
!       return -1;
!     }
!   lseek(printer_file, 0, 0);
X  
!   if(write(printer_file, prn_dev->mem.base,
! 	   (dev->width * dev->height) / 8) !=
!      (dev->width * dev->height) / 8)
!     {
!       perror("Writting to output");
!       return -1;
X      }
X   retry:
!   if(ioctl(printer_file, LBIOCSTART, 0) < 0)
X      {
X        if(analyze_error())
X  	goto retry;
--- 143,224 ----
X    return gdev_prn_close(dev);
X  }
X  
+ private int
+ nwp533_open_printer(gx_device *dev)
+ {       char *fname = prn_dev->fname;
+         char pfname[sizeof(prn_dev->fname) + 10];
+         if ( strchr(fname, '%') )
+            {    sprintf(pfname, fname, prn_dev->page_count);
+                 fname = pfname;
+            }
+         if ( prn_dev->file == NULL )
+            {    if (fname[0] == '\0') fname = "/dev/lbp";
+ 		prn_dev->file = gp_open_printer(fname);
+                 if ( prn_dev->file == NULL ) return -1;
+            }
+         return 0;
+ }
+ 
+ private int
+ nwp533_close_printer(gx_device *dev)
+ {
+       return gdev_prn_close_printer(dev);
+ }
+ 
X  /* Send the page to the printer. */
X  private int
X  nwp533_output_page(gx_device *dev, int num_copies, int flush)
X  {
!   int code;
!   extern int errno;
! 
!   prn_dev->page_count++;
!   code = nwp533_open_printer(dev);
!   if ( code < 0 ) return code;
X  
+   printer_file = fileno(prn_dev->file);
+ 
X   restart:
!   if (is_dev_lbp) 
!       if(ioctl(printer_file, LBIOCSTOP, 0) < 0)
! 	if ( errno == ENOTTY ) 
! 	{
! 	    is_dev_lbp = 0;
! 	}
! 	else 
! 	{
! 	  if(analyze_error())
! 	    goto restart;
! 	  perror("Waiting for device");
! 	  return -1;
! 	}
X  
!   if (is_dev_lbp) 
!       fprintf(stderr, "in nwp533 output page [%d, %d]\n",
! 	      dev->width, dev->height);
! 
!   if (is_dev_lbp) 
!       lseek(printer_file, 0, 0);
!   {
!     int lnum;
!     uint line_size = gdev_mem_bytes_per_scan_line(dev);
!     byte *in = (byte *)gs_malloc(line_size, 1, "nwp533_print_page(in)");
!     for ( lnum = 0; lnum < prn_dev->height; lnum++ ) {
! 	gdev_prn_copy_scan_lines(prn_dev, lnum, in, line_size);
! 	if(write(printer_file, (char *)in, line_size) != line_size) {
! 	    {
! 	      perror("Writing to output");  /* s/tt/t/ --haa */
! 	      gs_free((char *)in, line_size, 1, "nwp533_print_page(in)");
! 	      return -1;
! 	    }
! 	};
X      }
+     gs_free((char *)in, line_size, 1, "nwp533_print_page(in)");
+   }
+ 
X   retry:
!   if (is_dev_lbp) 
!       if(ioctl(printer_file, LBIOCSTART, 0) < 0)
X      {
X        if(analyze_error())
X  	goto retry;
***************
*** 160,164 ****
--- 226,234 ----
X        return -1;
X      }
X  
+     code = nwp533_close_printer(dev);
+     if ( code < 0 ) return code;
+ 
X    return 0;
+ 
X  }
*** gdevprn.h.orig	Fri Apr 10 15:56:15 1992
--- gdevprn.h	Fri Apr 10 15:57:22 1992
***************
*** 133,140 ****
X  	sizeof(gx_device_printer),\
X  	&procs,\
X  	dev_name,\
! 	(int)((long)width_10ths * x_dpi / 10),	/* width */\
! 	(int)((long)height_10ths * y_dpi / 10),	/* height */\
X  	x_dpi,\
X  	y_dpi,\
X  	l_margin, b_margin, r_margin, t_margin,\
--- 133,140 ----
X  	sizeof(gx_device_printer),\
X  	&procs,\
X  	dev_name,\
! 	(int)((double)width_10ths * x_dpi / 10),	/* width */\
! 	(int)((double)height_10ths * y_dpi / 10),	/* height */\
X  	x_dpi,\
X  	y_dpi,\
X  	l_margin, b_margin, r_margin, t_margin,\
SHAR_EOF
chmod 0644 PATCH.nwp533 ||
echo 'restore of PATCH.nwp533 failed'
Wc_c="`wc -c < 'PATCH.nwp533'`"
test 6261 -eq "$Wc_c" ||
	echo 'PATCH.nwp533: original size 6261, current size' "$Wc_c"
fi
exit 0
--
$@ElKLBg3X!&1~>p8&!J>p(J$@Js9)3X@l96(J  ($@#47n$+$i$b(J)$@#D#C#3!K(J
$@6b;R!!M5(J (kaneko@rcais.tohoku.ac.jp)