From:	CSBVAX::CSBVAX::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX"  9-NOV-1988 03:32
To:	MRGATE::"ARISIA::EVERHART"
Subj:	VAXCIO (VAXCIO.SHAR3_OF_5) Source.


Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Tue,  8 NOV 88 18:25:00 PDT
Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Tue, 8 Nov 88 17:56:31 PST
Received: by ucbvax.Berkeley.EDU (5.59/1.31)
	id AA07435; Mon, 7 Nov 88 23:24:36 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: 7 Nov 88 19:01:58 GMT
From: tektronix!gvgpsa!gvgpvd!tony@ucbvax.Berkeley.EDU  (Tony Ivanov)
Organization: Grass Valley Group, Inc., Grass Valley, CA
Subject: VAXCIO (VAXCIO.SHAR3_OF_5) Source.
Message-Id: <890@gvgpvd.GVG.TEK.COM>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com


--------------- cut here --------------
$Part3:
$ File_is="MISC.C"
$ Check_Sum_is=530835
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
V/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X~~~~~~~~~~~
X *`009This file holds the entry points for:
X *`009`009close, fclose, dup, and dup2.
X */
X
X# include`009"vmstermio.h"
X
Xglobalref struct vms_term_data`009*vms_term_data_head;
X
X# define`009IFLAG(mask)`009((index->termio->c_iflag & mask) != 0)
X# define`009OFLAG(mask)`009((index->termio->c_oflag & mask) != 0)
X
Xclose (fildes)
X`009int`009fildes;
X{
X`009struct vms_term_data`009*index;
X
X`009`009/* Find out if there was a VMS term data block for it. */
X`009for (index=vms_term_data_head;  index;  index=index->next)
X`009`009if (index->fildes == fildes) break;
X
X`009`009/* Mark the data block inactive. */
X`009if (index)
X`009{`009index->active = FALSE;
X`009`009index->_iobuf = 0;
X`009}
X
X`009`009/* Return the close status. */
X`009return (___close(fildes));
X}
X
X
Xfclose (filptr)
X`009FILE`009*filptr;
X{
X`009struct vms_term_data`009*index;
X
X`009`009/* Find out if there was a VMS term data block for it. */
X`009for (index=vms_term_data_head;  index;  index=index->next)
X`009`009if (index->_iobuf == *filptr) break;
X
X`009`009/* Mark the data block inactive. */
X`009if (index)
X`009{`009index->active = FALSE;
X`009`009index->_iobuf = 0;
X`009}
X
X`009`009/* Return the close status. */
X`009return (___fclose(filptr));
X}
X
X
Xdup (fildes)
X`009int`009fildes;
X{
X`009int`009fd;
X`009struct vms_term_data`009*index, *new_index, *back_ptr;
X
X`009`009/* "dup" it. */
X`009if ((fd = ___dup(fildes)) == -1)
X`009`009return (-1);
X
X`009`009/* Get the VMS terminal data block for old file descriptor. */
X`009for (index=vms_term_data_head;  index;  index=index->next)
X`009`009if (index->fildes == fildes) break;
X
X`009`009/* Make sure we had one! */
X`009if (!index)
X`009`009return (fd);
X
X`009`009/* Now get the VMS terminal data block for new one. */
X`009for (new_index=vms_term_data_head;  new_index;  new_index=new_index->next)
X`009{`009back_ptr = new_index;
X`009`009if (new_index->fildes == fd) break;
X`009}
X
X`009`009/* If there wasn't one, allocate a new one. */
X`009if (!new_index)
X`009{`009if (!(new_index = calloc (1, sizeof(*new_index))))
X`009`009{`009___close (fd);`009`009/* Pretend the "dup" was no good! */
X`009`009`009return (-1);
X`009`009}
X`009`009back_ptr->next = new_index;`009/* Link it onto end of list. */
X`009`009new_index-> next = 0;`009`009/* Terminate the list. */
X`009}
X
X`009`009/* Now duplicate VMS pointers. */
X`009new_index->fildes = fd;`009`009`009`009/* Update the file descriptor. */
X`009new_index->_iobuf = index->_iobuf;`009`009/* Use same I/O buffers. */
X`009new_index->vmstermio = index->vmstermio;`009/* Use same VMS termio data. */
X`009new_index->termio = index->termio;`009`009/* Use same unix termio data. */
X}
X
X
Xdup2 (fildes, fildes2)
X`009int`009fildes, fildes2;
X{
X`009int`009fd;
X`009struct vms_term_data`009*index, *new_index, *back_ptr;
X
X`009`009/* "dup" it. */
X`009if ((fd = ___dup(fildes,fildes2)) == -1)
X`009`009return (-1);
X
X`009`009/* Get the VMS terminal data block for old file descriptor. */
X`009for (index=vms_term_data_head;  index;  index=index->next)
X`009`009if (index->fildes == fildes) break;
X
X`009`009/* Make sure we had one! */
X`009if (!index)
X`009`009return (fd);
X
X`009`009/* Now get the VMS terminal data block for new one. */
X`009for (new_index=vms_term_data_head;  new_index;  new_index=new_index->next)
X`009{`009back_ptr = new_index;
X`009`009if (new_index->fildes == fd) break;
X`009}
X
X`009`009/* If there wasn't one, allocate a new one. */
X`009if (!new_index)
X`009{`009if (!(new_index = calloc (1, sizeof(*new_index))))
X`009`009{`009___close (fd);`009`009/* Pretend the "dup" was no good! */
X`009`009`009return (-1);
X`009`009}
X`009`009back_ptr->next = new_index;`009/* Link it onto end of list. */
X`009`009new_index-> next = 0;`009`009/* Terminate the list. */
X`009}
X
X`009`009/* Now duplicate VMS pointers. */
X`009new_index->fildes = fd;`009`009`009`009/* Update the file descriptor. */
X`009new_index->_iobuf = index->_iobuf;`009`009/* Use same I/O buffers. */
X`009new_index->vmstermio = index->vmstermio;`009/* Use same VMS termio data. */
X`009new_index->termio = index->termio;`009`009/* Use same unix termio data. */
X}
$ GoSub Convert_File
$ File_is="PRINT.C"
$ Check_Sum_is=1014366628
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
V/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X~~~~~~~~~~~
X *`009This file holds the entry points for:
X *`009`009printf and fprintf.
X */
X
X# include`009<varargs.h>
X# include`009"vmstermio.h"
X
Vextern struct vms_term_data`009*gvg$special_read(), *gvg$special_write();`009/*
X Functions. */
Vextern struct vms_term_data`009*gvg$special_fread(), *gvg$special_fwrite();`009
X/* Functions. */
Vextern int`009`009`009sprintf(), ___printf(), ___fprintf();`009`009/* Function 
Xaddresses passed to va_call. */
X
X
Xprintf (va_alist)
X`009va_dcl
X{
X`009va_list`009`009`009list_incr;`009/* Argument list incrementor. */
X`009char`009`009`009**argv;`009`009/* Actual arguments to this function. */
X`009char`009`009`009**pa;`009`009/* Pointer into argument list. */
X`009int`009`009`009argc;`009`009/* Number of arguments to this function. */
X`009char`009`009`009**orig_args;`009/* Original argument list. */
X
V`009struct vms_term_data`009*index;`009`009/* Index into vms termio database. *
X/
X`009char`009`009`009buff[513];`009/* Temporary buffer for formatting. */
V`009int`009`009`009bytes_formatted; /* Number of byte formatted into temporary 
Xbuffer. */
X`009int`009`009`009bytes_written;`009/* Number of bytes written to terminal. */
X
X`009`009/* Determine if we need to call the special routines! */
V`009orig_args = ((char *) &va_alist) - 4;`009`009`009/* Get original argument l
Xist. */
X
X`009`009/* See if we can issue regular C printf. */
V`009if (!(index = gvg$special_fwrite(stdout)))`009`009/* If no special processi
Xng is needed...*/
V`009`009return (va_call (___printf, orig_args));`009/* ...call the standard fpr
Xintf function. */
X
X/*
X *`009The arguements are loaded starting at argv[2] instead of argv[0] since
X *`009I want to pass the exact arguments to this routine to sprintf with
X *`009my own temporary buffer.  Also, I want argv to be an actual argument
X *`009list for VA_CALL.  This means argv[0] should hold the count of
X *`009arguments in the argument list.
X */
X`009`009/* Load the arguments to printf. */
X`009va_start (list_incr);
X`009va_count(argc);
X`009argv = calloc (argc+2, sizeof(*argv));
X`009for (pa=(char*)&(argv[2]);  pa < &(argv[argc+2]);  pa++)
X`009`009*pa = va_arg(list_incr, char*);
X`009va_end (list_incr);
X
X`009`009/* Format the output buffer. */
X`009argv[0] = (char *) (argc+1);
X`009argv[1] = buff;
X`009bytes_formatted = va_call (sprintf, argv);
X
X`009`009/* Remove temporary argument list. */
X`009cfree (argv);
X
X`009`009/* Write the information. */
X`009bytes_written = gvg$do_qio_write (index, buff, bytes_formatted);
X
X`009`009/* Return with the appropriate status. */
X`009return (bytes_written);
X}
X
X
Xfprintf (va_alist)
X`009va_dcl
X{
X`009char`009`009`009**orig_args;`009/* Argument list of original AP. */
V`009FILE`009`009`009*filptr;`009/* One of the arguments (the first to be specif
Xic). */
X
V`009struct vms_term_data`009*index;`009`009/* Index into vms termio database. *
X/
X`009char`009`009`009buff[513];`009/* Temporary buffer for formatting. */
V`009int`009`009`009bytes_formatted; /* Number of byte formatted into temporary 
Xbuffer. */
X`009int`009`009`009bytes_written;`009/* Number of bytes written to terminal. */
X
X`009`009/* Determine if we need to call the special routines! */
V`009orig_args = ((char *) &va_alist) - 4;`009`009`009/* Get original argument l
Xist. */
V`009filptr = (FILE *)orig_args[1];`009`009`009`009/* First argument is "filptr"
X. */
X
X`009`009/* See if we can issue regular C printf. */
V`009if (!(index = gvg$special_fwrite(filptr)))`009`009/* If no special processi
Xng is needed...*/
V`009`009return (va_call (___fprintf, orig_args));`009/* ...call the standard fp
Xrintf function. */
X
X/*
X *`009Fortunately, fprintf and sprintf have the same number of arguments
X *`009in them.  Since I no longer have a need for "filptr" (because I am
X *`009doing my own I/O), I can use the same argument list by replacing
X *`009"filptr" for fprintf with a "memory buffer" for sprintf.
X */
X`009`009/* Format the output buffer. */
X`009orig_args[1] = buff;
X`009bytes_formatted = va_call (sprintf, orig_args);
X
X`009`009/* Write the information. */
X`009bytes_written = gvg$do_qio_write (index, buff, bytes_formatted);
X
X`009`009/* Return with the appropriate status. */
X`009return (bytes_written);
X}
$ GoSub Convert_File
$ File_is="PUT.C"
$ Check_Sum_is=1717806590
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
V/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X~~~~~~~~~~~
X *`009This file holds the entry points for:
X *`009`009putchar, puts, fputc, putw, and fputs.
X */
X
X# include`009"vmstermio.h"
X
Vextern struct vms_term_data`009*gvg$special_read(), *gvg$special_write();`009/*
X Functions. */
Vextern struct vms_term_data`009*gvg$special_fread(), *gvg$special_fwrite();`009
X/* Functions. */
X
X
X#undef putchar
Xputchar (ch)
X`009char`009ch;
X{
V`009struct vms_term_data`009*index;`009`009`009/* Index into vms termio databas
Xe. */
X`009int`009`009`009bytes_written=0;
X
X`009`009/* See if we can issue regular C write. */
V`009if (!(index = gvg$special_fwrite(stdout)))`009/* If no special processing i
Xs needed...*/
V`009`009return (___putchar());`009`009`009/* ...call the standard write functio
Xn. */
X
X`009`009/* Write the information. */
X`009bytes_written = gvg$do_qio_write (index, &ch, 1);
X
X`009`009/* Return with the appropriate status. */
X`009if (bytes_written == 0)
X`009`009return (-1);
X`009else
X`009`009return ((int)ch);
X}
X
X
Xputs (str)
X`009char`009*str;
X{
V`009struct vms_term_data`009*index;`009`009`009/* Index into vms termio databas
Xe. */
X`009int`009`009`009nbytes;`009`009`009/* Number of bytes to write. */
X`009int`009`009`009bytes_written=0;`009/* Number of bytes actually written. */
X
X`009`009/* See if we can issue regular C write. */
V`009if (!(index = gvg$special_fwrite(stdout)))`009/* If no special processing i
Xs needed...*/
V`009`009return (___puts(str));`009`009`009/* ...call the standard write functio
Xn. */
X
X`009`009/* Set up buffer to write (with appended new-line). */
X`009if (str)
X`009{`009nbytes = strlen(str);
X`009`009str[nbytes] = '\n';
X`009`009bytes_written = gvg$do_qio_write (index, str, nbytes+1);
X`009`009str[nbytes] = '\0';
X`009}
X
X`009`009/* Return the proper status. */
X`009if (bytes_written-1 != nbytes)
X`009`009return (-1);
X`009else
X`009`009return (0);
X}
X
X
Xfputc (ch, filptr)
X`009char`009ch;
X`009FILE`009*filptr;
X{
V`009struct vms_term_data`009*index;`009`009`009/* Index into vms termio databas
Xe. */
X`009int`009`009`009bytes_written=0;`009/* Actual number of bytes written. */
X
X`009`009/* See if we can issue regular C write. */
V`009if (!(index = gvg$special_fwrite(filptr)))`009/* If no special processing i
Xs needed...*/
V`009`009return (___fputc(ch, filptr));`009`009/* ...call the standard write fun
Xction. */
X
X`009`009/* Write the information. */
X`009bytes_written = gvg$do_qio_write (index, &ch, 1);
X
X`009`009/* Return with the appropriate status. */
X`009if (bytes_written == 0)
X`009`009return (-1);
X`009else
X`009`009return ((int)ch);
X}
X
X
Xputw (word, filptr)
X`009int`009word;
X`009FILE`009*filptr;
X{
V`009struct vms_term_data`009*index;`009`009/* Index into vms termio database. *
X/
X`009int`009`009`009bytes_written=0;
X
X`009`009/* See if we can issue regular C write. */
V`009if (!(index = gvg$special_fwrite(filptr)))`009/* If no special processing i
Xs needed...*/
V`009`009return (___putw(word, filptr));`009`009/* ...call the standard write fu
Xnction. */
X
X`009`009/* Write the information. */
X`009bytes_written = gvg$do_qio_write (index, &word, 4);
X
X`009`009/* Return with the appropriate status. */
X`009if (bytes_written != 4)
X`009`009return (-1);
X`009else
X`009`009return (word);
X}
X
X
Xfputs (str, filptr)
X`009char`009*str;
X`009FILE`009*filptr;
X{
V`009struct vms_term_data`009*index;`009`009`009/* Index into vms termio databas
Xe. */
X`009int`009`009`009nbytes;`009`009`009/* Number of bytes in the string. */
X`009int`009`009`009bytes_written=0;`009/* Number of bytes actually written. */
X
X`009`009/* See if we can issue regular C write. */
V`009if (!(index = gvg$special_fwrite(filptr)))`009/* If no special processing i
Xs needed...*/
V`009`009return (___fputs(str, filptr));`009`009/* ...call the standard write fu
Xnction. */
X
X`009`009/* Write the information. */
X`009if (str)
X`009{`009nbytes = strlen(str);
X`009`009bytes_written = gvg$do_qio_write (index, str, nbytes);
X`009}
X
X`009`009/* Return with the appropriate status. */
X`009if (bytes_written != nbytes)
X`009`009return (-1);
X`009else
X`009`009return (0);
X}
$ GoSub Convert_File
$ File_is="READ.C"
$ Check_Sum_is=604908454
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
V/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X~~~~~~~~~~~
X *`009This file holds the entry points for:
X *`009`009read and fread.
X */
X
X# include`009"vmstermio.h"
X
X# define`009IFLAG(mask)`009((index->termio->c_iflag & mask) != 0)
X# define`009OFLAG(mask)`009((index->termio->c_oflag & mask) != 0)
X
Vextern struct vms_term_data`009*gvg$special_read(), *gvg$special_write();`009/*
X Functions. */
Vextern struct vms_term_data`009*gvg$special_fread(), *gvg$special_fwrite();`009
X/* Functions. */
X
Xread (fildes, buff, nbytes)
X`009int`009fildes, nbytes;
X`009char`009*buff;
X{
V`009struct vms_term_data`009*index;`009`009/* Index into vms termio database. *
X/
X`009int`009`009`009bytes_read;`009/* # bytes read from file. */
X`009char`009`009`009*ptr;`009`009/* Pointer into input buffer. */
X`009int`009`009`009och;
X
X`009`009/* See if we can issue regular C read. */
V`009if (!(index = gvg$special_read(fildes)))`009`009/* If no special processing
X is needed...*/
V`009`009return (___read (fildes, buff, nbytes));`009/* ...call the standard rea
Xd function. */
X
X`009`009/* Get the information and put it into the output buffer. */
X`009if (IFLAG(BRKINT)  ||  !OFLAG(OPOST))
X`009`009bytes_read = gvg$do_qio_read1 (index, buff, 1);
X`009else
X`009`009bytes_read = gvg$do_qio_readn (index, buff, nbytes, 0);
X
X`009`009/* Post process the output buffer if necessary. */
X`009gvg$do_post (index, buff, bytes_read);
X
X`009`009/* Return the actual number of bytes read. */
X`009return (bytes_read);
X}
X
X
Xfread (buff, size, num, filptr)
X`009char`009*buff;
X`009int`009size, num;
X`009FILE`009*filptr;
X{
V`009struct vms_term_data`009*index;`009`009/* Index into vms termio database. *
X/
X`009int`009`009`009bytes_read;`009/* # bytes read from file. */
X`009int`009`009`009items_read;`009/* # items read from file. */
X`009char`009`009`009*ptr;`009`009/* Pointer into input buffer. */
X`009int`009`009`009och;
X
X`009`009/* See if we can issue regular C read. */
V`009if (!(index = gvg$special_fread(filptr)))`009`009/* If no special processin
Xg is needed...*/
V`009`009return (___fread (buff, size, num, filptr));`009/* ...call the standard
X read function. */
X
X`009`009/* Get the information and put it into the output buffer. */
X`009if (size > 0)
X`009{`009if (IFLAG(BRKINT)  ||  !OFLAG(OPOST))
X`009`009`009bytes_read = gvg$do_qio_read1 (index, buff, size);
X`009`009else
X`009`009`009bytes_read = gvg$do_qio_readn (index, buff, size*num, 0);
X`009`009items_read = bytes_read / size;
X`009}
X`009else
X`009{`009bytes_read = 0;
X`009`009items_read = 0;
X`009}
X
X`009`009/* Post process the output buffer if necessary. */
X`009gvg$do_post (index, buff, bytes_read);
X
X`009`009/* Return the actual number of bytes read. */
X`009return (items_read);
X}
$ GoSub Convert_File
$ Goto Part4
--------------- cut here --------------
-- 
/* My opinions...               *	Tony Ivanov   MS-4B		*/
/* shared by my company?!...    *	Grass Valley Group, Inc.	*/
/* you've got to be kidding!    *	P.O. Box 1114			*/
/* "tony@gvgpvd.GVG.TEK.COM"    *	Grass Valley, CA  95945		*/

