From:	CSBVAX::CSBVAX::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 19-NOV-1988 02:32
To:	MRGATE::"ARISIA::EVERHART"
Subj:	GNUplot (VMS 'C' bug)


Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Tue, 15 NOV 88 23:25:05 PDT
Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Tue, 15 Nov 88 23:00:47 PST
Received: by ucbvax.Berkeley.EDU (5.59/1.31)
	id AA13432; Sun, 13 Nov 88 11:08:10 PST
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 12 Nov 88 00:20:01 GMT
From: naucse!jdc@arizona.edu  (John Campbell)
Organization: Northern Arizona University, Flagstaff, AZ
Subject: GNUplot (VMS 'C' bug)
Message-Id: <1027@naucse.UUCP>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com


When you work with good code that has successfully moved to a lot of machines
it is really annoying to find VMS "broken".

For those of you running GNUPLOT on VMS, have you ever noticed that
SET OUTPUT (with no file name) does not restore terminal interaction?  If so,
then you have the version I have and the problem seems to be in how VMS
works with file descriptors.  (A fix is posted below.)

The version of GNUPLOT that I am discussing is the following:

        G N U P L O T
        VMS version 1.1.0
        last modified Mon Jan 26 16:58:24 EST 1987
        Copyright (C) 1986, 1987  Colin Kelley, Thomas Williams


The GNUPLOT code likes to do
     outfile = fdopen(dup(STDOUT),"w");
and then swap outfile with a file pointer from fopen and a dupped STDOUT
descriptor in the SET OUTPUT command.  This almost works on VMS, except
that any close on a dupped STDOUT descriptor seems to really close the
file.  I assume this is related to the link/unlink problem with VMS.

On unix, for instance, you can have a link count--and an unlink will just
decrement the count until the counter is less than 1 and the file is really
closed.  On VMS dup seems to not have a counter and really closes the file
pointer, even if another pointer is connected to the stream.  At least this
seems to be what happens.  Anyway, this model fits with the fix below.

Has any one else ever seen this behavior in the 'C' run-time library?
Can anyone prove I am right and suggest a proper SPR to send to Digital?

Finally, can anyone tell me why to leave the dup() stuff in the other
versions of GNUPLOT?   Removing it from VMS didn't seem to hurt anything.

====================Fix for SET OUTPUT behavior==========================
########################PLOT.C#######################
************
File USER2:[WP.GNUPLOT]PLOT.C_ORIG;1
  135    outfile = fdopen(dup(STDOUT),"w");
  136    (void) complex(&udv_pi.udv_value, Pi, 0.0);
******
File USER2:[WP.GNUPLOT]PLOT.C;2
  135   #ifdef VMS
  136    outfile = stdout; /* never close stdout--even if duped. */
  137   #else
  138    outfile = fdopen(dup(STDOUT),"w");
  139   #endif
  140    (void) complex(&udv_pi.udv_value, Pi, 0.0);
************

Number of difference sections found: 1
Number of difference records found: 5

DIFFERENCES /IGNORE=(SPACING,TRAILING_SPACES)/MERGED=1/OUTPUT=USER2:[WP.GNUPLOT]PLOT.DIFF_VMS;2-
    USER2:[WP.GNUPLOT]PLOT.C_ORIG;1-
    USER2:[WP.GNUPLOT]PLOT.C;2

########################COMMAND.C#################################
************
File USER2:[WP.GNUPLOT]COMMAND.C_ORIG;1
  309    (void) fclose(outfile);
  310    outfile = fdopen(dup(STDOUT), "w");
  311    term_init = FALSE;
******
File USER2:[WP.GNUPLOT]COMMAND.C;6
  309   #ifdef VMS
  310    if (outfile != stdout) /* Never close stdout */
  311   #endif
  312    (void) fclose(outfile);
  313   #ifdef VMS
  314    outfile = stdout; /* Avoid the dup... */
  315   #else
  316    outfile = fdopen(dup(STDOUT), "w");
  317   #endif
  318    term_init = FALSE;
************
************
File USER2:[WP.GNUPLOT]COMMAND.C_ORIG;1
  320    (void) fclose(outfile);
******
File USER2:[WP.GNUPLOT]COMMAND.C;6
  327   #ifdef VMS
  328    if (outfile != stdout) /* Never close stdout */
  329   #endif
  330    (void) fclose(outfile);
************

Number of difference sections found: 2
Number of difference records found: 12

DIFFERENCES /IGNORE=(SPACING,TRAILING_SPACES)/MERGED=1/OUTPUT=USER2:[WP.GNUPLOT]COMMAND.DIFF_VMS;2-
    USER2:[WP.GNUPLOT]COMMAND.C_ORIG;1-
    USER2:[WP.GNUPLOT]COMMAND.C;6
-- 
	John Campbell               ...!arizona!naucse!jdc

	unix?  Sure send me a dozen, all different colors.

