
GVG$VAXCIO                                                      30-MAR-1989 15:52:59    VAX C      V2.2-015                 Page 1
V1.0                                                            30-MAR-1989 15:48:57    GVG$VAXCIO.C;1 (1)



    1        	 
    2        	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    3        	 *	This file holds the entry points for:
    4        	 *		getchar, gets, fgetc, getw, and fgets.
    5        	 */
    6        	 
    7        	# include	"vmstermio.h"
  301        	 
  302        	# define	IFLAG(mask)	((index->termio->c_iflag & mask) != 0)
  303        	# define	OFLAG(mask)	((index->termio->c_oflag & mask) != 0)
  304        	 
  305        	extern struct vms_term_data	*gvg$special_read(), *gvg$special_write();	/* Functions. */
  306        	extern struct vms_term_data	*gvg$special_fread(), *gvg$special_fwrite();	/* Functions. */
  307        	 
  308        	 
  309        	#undef getchar
  310        	getchar ()
  311        	{
  312    1   		struct vms_term_data	*index;		/* Index into vms termio database. */
  313    1   		int			ch=0, och;
  314    1   		int			bytes_read=0;
  315    1   	 
  316    1   			/* See if we can issue regular C read. */
  317    1   		if (!(index = gvg$special_fread(stdin)))		/* If no special processing is needed...*/
  318    1   			return (___getchar());			/* ...call the standard read function. */
  319    1   	 
  320    1   			/* Get the information and put it into the output buffer. */
  321    1   		if (IFLAG(BRKINT)  ||  !OFLAG(OPOST))
  322    1   			bytes_read = gvg$do_qio_read1 (index, &ch, 1);		/* Direct read. */
  323    1   		else
  324    1   			bytes_read = gvg$do_qio_readn (index, &ch, 1, 0);	/* Buffered read. */
  325    1   		if ( bytes_read == 0 )
  326    1   			ch = EOF;
  327    1   	 
  328    1   			/* Post process the output buffer if necessary. */
  329    1   		gvg$do_post (index, &ch, bytes_read);
  330    1   	 
  331    1   			/* Return the character read. */
  332    1   		return (ch);
  333    1   	}
  334        	 
  335        	 
  336        	char *
  337        	gets (str)
  338        		char	*str;
  339        	{
  340    1   		struct vms_term_data	*index;		/* Index into vms termio database. */
  341    1   		char			*ptr;		/* Pointer into str. */
  342    1   		int			och;
  343    1   		int			bytes_read=0;
  344    1   	 
  345    1   			/* See if we can issue regular C read. */
  346    1   		if (!(index = gvg$special_fread(stdin)))	/* If no special processing is needed...*/
  347    1   			return (___gets(str));			/* ...call the standard read function. */
  348    1   	 

GVG$VAXCIO                                                      30-MAR-1989 15:52:59    VAX C      V2.2-015                 Page 2
V1.0                                                            30-MAR-1989 15:48:57    GVG$VAXCIO.C;1 (1)

  349    1   			/* Get the information and put it into the output buffer. */
  350    1   		if (str)
  351    1   		{	bytes_read = gvg$do_qio_readn (index, str, 65535, 0);
  352    2   	 
  353    2   				/* Post process the output buffer if necessary. */
  354    2   			gvg$do_post (index, str, bytes_read);
  355    2   	 
  356    2   				/* Terminate the string properly. */
  357    2   			if (bytes_read > 0)
  358    2   			{	ptr = &str[bytes_read-1];
  359    3   				if (*ptr == '\n')
  360    3   					*ptr = '\0';
  361    3   				else
  362    3   					str = 0;	/* EOF on input. */
  363    3   			}
  364    2   			else
  365    2   				str = 0;
  366    2   		}
  367    1   	 
  368    1   			/* Return the actual string read. */
  369    1   		return (str);
  370    1   	}
  371        	 
  372        	 
  373        	int
  374        	fgetc (filptr)
  375        		FILE	*filptr;
  376        	{
  377    1   		struct vms_term_data	*index;		/* Index into vms termio database. */
  378    1   		int			ch=0, och;
  379    1   		int			bytes_read=0;
  380    1   	 
  381    1   			/* See if we can issue regular C read. */
  382    1   		if (!(index = gvg$special_fread(filptr)))	/* If no special processing is needed...*/
  383    1   			return (___fgetc(filptr));		/* ...call the standard read function. */
  384    1   	 
  385    1   			/* Get the information and put it into the output buffer. */
  386    1   		if (IFLAG(BRKINT)  ||  !OFLAG(OPOST))
  387    1   			bytes_read = gvg$do_qio_read1 (index, &ch, 1);		/* Direct read. */
  388    1   		else
  389    1   			bytes_read = gvg$do_qio_readn (index, &ch, 1, 0);	/* Buffered read. */
  390    1   		if ( bytes_read == 0 )
  391    1   			ch = EOF;
  392    1   	 
  393    1   			/* Post process the output buffer if necessary. */
  394    1   		gvg$do_post (index, &ch, bytes_read);
  395    1   	 
  396    1   			/* Return the actual number of bytes read. */
  397    1   		return (ch);
  398    1   	}
  399        	 
  400        	 
  401        	int
  402        	getw (filptr)
  403        		FILE	*filptr;
  404        	{
  405    1   		struct vms_term_data	*index;		/* Index into vms termio database. */

GVG$VAXCIO                                                      30-MAR-1989 15:52:59    VAX C      V2.2-015                 Page 3
V1.0                                                            30-MAR-1989 15:48:57    GVG$VAXCIO.C;1 (1)

  406    1   		unsigned int		ch=0, och;
  407    1   		int			bytes_read=0;
  408    1   		char			*ptr;
  409    1   	 
  410    1   			/* See if we can issue regular C read. */
  411    1   		if (!(index = gvg$special_fread(filptr)))	/* If no special processing is needed...*/
  412    1   			return (___getw(filptr));		/* ...call the standard read function. */
  413    1   	 
  414    1   			/* Get the information and put it into the output buffer. */
  415    1   		if (IFLAG(BRKINT)  ||  !OFLAG(OPOST))
  416    1   			bytes_read = gvg$do_qio_read1 (index, &ch, 4);		/* Direct read. */
  417    1   		else
  418    1   			bytes_read = gvg$do_qio_readn (index, &ch, 4, 4);	/* Buffered read. */
  419    1   		if (bytes_read != 4)
  420    1   		{	ch = EOF;
  421    2   			bytes_read = 0;
  422    2   		}
  423    1   	 
  424    1   			/* Post process the output buffer if necessary. */
  425    1   		gvg$do_post (index, &ch, bytes_read);
  426    1   	 
  427    1   			/* Return the actual number of bytes read. */
  428    1   		return (ch);
  429    1   	}
  430        	 
  431        	 
  432        	char *
  433        	fgets (str, maxchar, filptr)
  434        		char	*str;
  435        		int	maxchar;
  436        		FILE	*filptr;
  437        	{
  438    1   		struct vms_term_data	*index;		/* Index into vms termio database. */
  439    1   		char			*ptr;		/* Pointer into str. */
  440    1   		int			och;
  441    1   		int			bytes_read=0;
  442    1   	 
  443    1   			/* See if we can issue regular C read. */
  444    1   		if (!(index = gvg$special_fread(filptr)))		/* If no special processing is needed...*/
  445    1   			return (___fgets(str, maxchar, filptr));	/* ...call the standard read function. */
  446    1   	 
  447    1   			/* Get the information and put it into the output buffer. */
  448    1   		if (str)
  449    1   		{	bytes_read = gvg$do_qio_readn (index, str, maxchar-1, 0);
  450    2   	 
  451    2   				/* Post process the output buffer if necessary. */
  452    2   			gvg$do_post (index, str, bytes_read);
  453    2   	 
  454    2   				/* Terminate the string properly. */
  455    2   			if (bytes_read > 0)
  456    2   			{	ptr = &str[bytes_read];
  457    3   				if (*(ptr-1) == '\n')
  458    3   					*ptr = '\0';
  459    3   				else
  460    3   					str = 0;	/* EOF on input. */
  461    3   			}
  462    2   			else

GVG$VAXCIO                                                      30-MAR-1989 15:52:59    VAX C      V2.2-015                 Page 4
V1.0                                                            30-MAR-1989 15:48:57    GVG$VAXCIO.C;1 (1)

  463    2   				str = 0;
  464    2   		}
  465    1   	 
  466    1   			/* Return the actual string read. */
  467    1   		return (str);
  468    1   	}
  469        	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  470        	 *	This file holds the entry points for:
  471        	 *		putchar, puts, fputc, putw, and fputs.
  472        	 */
  473        	 
  474        	# include	"vmstermio.h"
  511        	 
  512        	extern struct vms_term_data	*gvg$special_read(), *gvg$special_write();	/* Functions. */
  513        	extern struct vms_term_data	*gvg$special_fread(), *gvg$special_fwrite();	/* Functions. */
  514        	 
  515        	 
  516        	#undef putchar
  517        	putchar (ch)
  518        		char	ch;
  519        	{
  520    1   		struct vms_term_data	*index;			/* Index into vms termio database. */
  521    1   		int			bytes_written=0;
  522    1   	 
  523    1   			/* See if we can issue regular C write. */
  524    1   		if (!(index = gvg$special_fwrite(stdout)))	/* If no special processing is needed...*/
  525    1   			return (___putchar());			/* ...call the standard write function. */
  526    1   	 
  527    1   			/* Write the information. */
  528    1   		bytes_written = gvg$do_qio_write (index, &ch, 1);
  529    1   	 
  530    1   			/* Return with the appropriate status. */
  531    1   		if (bytes_written == 0)
  532    1   			return (-1);
  533    1   		else
  534    1   			return ((int)ch);
  535    1   	}
  536        	 
  537        	 
  538        	puts (str)
  539        		char	*str;
  540        	{
  541    1   		struct vms_term_data	*index;			/* Index into vms termio database. */
  542    1   		int			nbytes;			/* Number of bytes to write. */
  543    1   		int			bytes_written=0;	/* Number of bytes actually written. */
  544    1   	 
  545    1   			/* See if we can issue regular C write. */
  546    1   		if (!(index = gvg$special_fwrite(stdout)))	/* If no special processing is needed...*/
  547    1   			return (___puts(str));			/* ...call the standard write function. */
  548    1   	 
  549    1   			/* Set up buffer to write (with appended new-line). */
  550    1   		if (str)
  551    1   		{	nbytes = strlen(str);
  552    2   			str[nbytes] = '\n';
  553    2   			bytes_written = gvg$do_qio_write (index, str, nbytes+1);
  554    2   			str[nbytes] = '\0';
  555    2   		}

GVG$VAXCIO                                                      30-MAR-1989 15:52:59    VAX C      V2.2-015                 Page 5
V1.0                                                            30-MAR-1989 15:48:57    GVG$VAXCIO.C;1 (1)

  556    1   	 
  557    1   			/* Return the proper status. */
  558    1   		if (bytes_written-1 != nbytes)
  559    1   			return (-1);
  560    1   		else
  561    1   			return (0);
  562    1   	}
  563        	 
  564        	 
  565        	fputc (ch, filptr)
  566        		char	ch;
  567        		FILE	*filptr;
  568        	{
  569    1   		struct vms_term_data	*index;			/* Index into vms termio database. */
  570    1   		int			bytes_written=0;	/* Actual number of bytes written. */
  571    1   	 
  572    1   			/* See if we can issue regular C write. */
  573    1   		if (!(index = gvg$special_fwrite(filptr)))	/* If no special processing is needed...*/
  574    1   			return (___fputc(ch, filptr));		/* ...call the standard write function. */
  575    1   	 
  576    1   			/* Write the information. */
  577    1   		bytes_written = gvg$do_qio_write (index, &ch, 1);
  578    1   	 
  579    1   			/* Return with the appropriate status. */
  580    1   		if (bytes_written == 0)
  581    1   			return (-1);
  582    1   		else
  583    1   			return ((int)ch);
  584    1   	}
  585        	 
  586        	 
  587        	putw (word, filptr)
  588        		int	word;
  589        		FILE	*filptr;
  590        	{
  591    1   		struct vms_term_data	*index;		/* Index into vms termio database. */
  592    1   		int			bytes_written=0;
  593    1   	 
  594    1   			/* See if we can issue regular C write. */
  595    1   		if (!(index = gvg$special_fwrite(filptr)))	/* If no special processing is needed...*/
  596    1   			return (___putw(word, filptr));		/* ...call the standard write function. */
  597    1   	 
  598    1   			/* Write the information. */
  599    1   		bytes_written = gvg$do_qio_write (index, &word, 4);
  600    1   	 
  601    1   			/* Return with the appropriate status. */
  602    1   		if (bytes_written != 4)
  603    1   			return (-1);
  604    1   		else
  605    1   			return (word);
  606    1   	}
  607        	 
  608        	 
  609        	fputs (str, filptr)
  610        		char	*str;
  611        		FILE	*filptr;
  612        	{

GVG$VAXCIO                                                      30-MAR-1989 15:52:59    VAX C      V2.2-015                 Page 6
V1.0                                                            30-MAR-1989 15:48:57    GVG$VAXCIO.C;1 (1)

  613    1   		struct vms_term_data	*index;			/* Index into vms termio database. */
  614    1   		int			nbytes;			/* Number of bytes in the string. */
  615    1   		int			bytes_written=0;	/* Number of bytes actually written. */
  616    1   	 
  617    1   			/* See if we can issue regular C write. */
  618    1   		if (!(index = gvg$special_fwrite(filptr)))	/* If no special processing is needed...*/
  619    1   			return (___fputs(str, filptr));		/* ...call the standard write function. */
  620    1   	 
  621    1   			/* Write the information. */
  622    1   		if (str)
  623    1   		{	nbytes = strlen(str);
  624    2   			bytes_written = gvg$do_qio_write (index, str, nbytes);
  625    2   		}
  626    1   	 
  627    1   			/* Return with the appropriate status. */
  628    1   		if (bytes_written != nbytes)
  629    1   			return (-1);
  630    1   		else
  631    1   			return (0);
  632    1   	}
  633        	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  634        	 *	This file holds the entry points for:
  635        	 *		read and fread.
  636        	 */
  637        	 
  638        	# include	"vmstermio.h"
  675        	 
  676        	# define	IFLAG(mask)	((index->termio->c_iflag & mask) != 0)
  677        	# define	OFLAG(mask)	((index->termio->c_oflag & mask) != 0)
  678        	 
  679        	extern struct vms_term_data	*gvg$special_read(), *gvg$special_write();	/* Functions. */
  680        	extern struct vms_term_data	*gvg$special_fread(), *gvg$special_fwrite();	/* Functions. */
  681        	 
  682        	read (fildes, buff, nbytes)
  683        		int	fildes, nbytes;
  684        		char	*buff;
  685        	{
  686    1   		struct vms_term_data	*index;		/* Index into vms termio database. */
  687    1   		int			bytes_read;	/* # bytes read from file. */
  688    1   		char			*ptr;		/* Pointer into input buffer. */
  689    1   		int			och;
  690    1   	 
  691    1   			/* See if we can issue regular C read. */
  692    1   		if (!(index = gvg$special_read(fildes)))		/* If no special processing is needed...*/
  693    1   			return (___read (fildes, buff, nbytes));	/* ...call the standard read function. */
  694    1   	 
  695    1   			/* Get the information and put it into the output buffer. */
  696    1   		if (IFLAG(BRKINT)  ||  !OFLAG(OPOST))
  697    1   			bytes_read = gvg$do_qio_read1 (index, buff, 1);
  698    1   		else
  699    1   			bytes_read = gvg$do_qio_readn (index, buff, nbytes, 0);
  700    1   	 
  701    1   			/* Post process the output buffer if necessary. */
  702    1   		gvg$do_post (index, buff, bytes_read);
  703    1   	 
  704    1   			/* Return the actual number of bytes read. */
  705    1   		return (bytes_read);

GVG$VAXCIO                                                      30-MAR-1989 15:52:59    VAX C      V2.2-015                 Page 7
V1.0                                                            30-MAR-1989 15:48:57    GVG$VAXCIO.C;1 (1)

  706    1   	}
  707        	 
  708        	 
  709        	fread (buff, size, num, filptr)
  710        		char	*buff;
  711        		int	size, num;
  712        		FILE	*filptr;
  713        	{
  714    1   		struct vms_term_data	*index;		/* Index into vms termio database. */
  715    1   		int			bytes_read;	/* # bytes read from file. */
  716    1   		int			items_read;	/* # items read from file. */
  717    1   		char			*ptr;		/* Pointer into input buffer. */
  718    1   		int			och;
  719    1   	 
  720    1   			/* See if we can issue regular C read. */
  721    1   		if (!(index = gvg$special_fread(filptr)))		/* If no special processing is needed...*/
  722    1   			return (___fread (buff, size, num, filptr));	/* ...call the standard read function. */
  723    1   	 
  724    1   			/* Get the information and put it into the output buffer. */
  725    1   		if (size > 0)
  726    1   		{	if (IFLAG(BRKINT)  ||  !OFLAG(OPOST))
  727    2   				bytes_read = gvg$do_qio_read1 (index, buff, size);
  728    2   			else
  729    2   				bytes_read = gvg$do_qio_readn (index, buff, size*num, 0);
  730    2   			items_read = bytes_read / size;
  731    2   		}
  732    1   		else
  733    1   		{	bytes_read = 0;
  734    2   			items_read = 0;
  735    2   		}
  736    1   	 
  737    1   			/* Post process the output buffer if necessary. */
  738    1   		gvg$do_post (index, buff, bytes_read);
  739    1   	 
  740    1   			/* Return the actual number of bytes read. */
  741    1   		return (items_read);
  742    1   	}
  743        	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  744        	 *	This file holds the entry points for:
  745        	 *		write and fwrite.
  746        	 */
  747        	 
  748        	# include	"vmstermio.h"
  785        	 
  786        	extern struct vms_term_data	*gvg$special_read(), *gvg$special_write();	/* Functions. */
  787        	extern struct vms_term_data	*gvg$special_fread(), *gvg$special_fwrite();	/* Functions. */
  788        	 
  789        	write (fildes, buff, nbytes)
  790        		int	fildes, nbytes;
  791        		char	*buff;
  792        	{
  793    1   		struct vms_term_data	*index;		/* Index into vms termio database. */
  794    1   		int			bytes_written;	/* # bytes written to file. */
  795    1   		char			*ptr;		/* Pointer into output buffer. */
  796    1   		int			och;
  797    1   	 
  798    1   			/* See if we can issue regular C read. */

GVG$VAXCIO                                                      30-MAR-1989 15:52:59    VAX C      V2.2-015                 Page 8
V1.0                                                            30-MAR-1989 15:48:57    GVG$VAXCIO.C;1 (1)

  799    1   		if (!(index = gvg$special_write(fildes)))		/* If no special processing is needed...*/
  800    1   			return (___write (fildes, buff, nbytes));	/* ...call the standard write function. */
  801    1   	 
  802    1   			/* Write the information to the file. */
  803    1   		bytes_written = gvg$do_qio_write (index, buff, nbytes);
  804    1   	 
  805    1   			/* Return the actual number of bytes written. */
  806    1   		return (bytes_written);
  807    1   	}
  808        	 
  809        	 
  810        	fwrite (buff, size, nitems, filptr)
  811        		char	*buff;
  812        		int	size, nitems;
  813        		FILE	*filptr;
  814        	{
  815    1   		struct vms_term_data	*index;		/* Index into vms termio database. */
  816    1   		int			items_written;	/* # Items written to file. */
  817    1   		char			*ptr;		/* Pointer into output buffer. */
  818    1   		int			och;
  819    1   	 
  820    1   			/* See if we can issue regular C read. */
  821    1   		if (!(index = gvg$special_fwrite(filptr)))			/* If no special processing is needed...*/
  822    1   			return (___fwrite (buff, size, nitems, filptr));	/* ...call the standard write function. */
  823    1   	 
  824    1   			/* Write the information to the file. */
  825    1   		if (size > 0  &&  nitems > 0)
  826    1   			items_written = gvg$do_qio_write (index, buff, size*nitems) / size;
  827    1   		else
  828    1   			items_written = 0;
  829    1   	 
  830    1   			/* Return the actual number of items written. */
  831    1   		return (items_written);
  832    1   	}
  833        	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  834        	 *	This file holds the entry points for:
  835        	 *		printf and fprintf.
  836        	 */
  837        	 
  838        	# include	<varargs.h>
  858        	# include	"vmstermio.h"
  895        	 
  896        	extern struct vms_term_data	*gvg$special_read(), *gvg$special_write();	/* Functions. */
  897        	extern struct vms_term_data	*gvg$special_fread(), *gvg$special_fwrite();	/* Functions. */
  898        	extern int			sprintf(), ___printf(), ___fprintf();		/* Function addresses passed to va_call. */
  899        	 
  900        	 
  901        	printf (va_alist)
  902        		va_dcl
  903        	{
  904    1   		va_list			list_incr;	/* Argument list incrementor. */
  905    1   		char			**argv;		/* Actual arguments to this function. */
  906    1   		char			**pa;		/* Pointer into argument list. */
  907    1   		int			argc;		/* Number of arguments to this function. */
  908    1   		char			**orig_args;	/* Original argument list. */
  909    1   	 
  910    1   		struct vms_term_data	*index;		/* Index into vms termio database. */

GVG$VAXCIO                                                      30-MAR-1989 15:52:59    VAX C      V2.2-015                 Page 9
V1.0                                                            30-MAR-1989 15:48:57    GVG$VAXCIO.C;1 (1)

  911    1   		char			buff[513];	/* Temporary buffer for formatting. */
  912    1   		int			bytes_formatted; /* Number of byte formatted into temporary buffer. */
  913    1   		int			bytes_written;	/* Number of bytes written to terminal. */
  914    1   	 
  915    1   			/* Determine if we need to call the special routines! */
  916    1   		orig_args = ((char *) &va_alist) - 4;			/* Get original argument list. */
  917    1   	 
  918    1   			/* See if we can issue regular C printf. */
  919    1   		if (!(index = gvg$special_fwrite(stdout)))		/* If no special processing is needed...*/
  920    1   			return (va_call (___printf, orig_args));	/* ...call the standard fprintf function. */
  921    1   	 
  922    1   	/*
  923    1   	 *	The arguements are loaded starting at argv[2] instead of argv[0] since
  924    1   	 *	I want to pass the exact arguments to this routine to sprintf with
  925    1   	 *	my own temporary buffer.  Also, I want argv to be an actual argument
  926    1   	 *	list for VA_CALL.  This means argv[0] should hold the count of
  927    1   	 *	arguments in the argument list.
  928    1   	 */
  929    1   			/* Load the arguments to printf. */
  930    1   		va_start (list_incr);
  931    1   		va_count(argc);
  932    1   		argv = calloc (argc+2, sizeof(*argv));
  933    1   		for (pa=(char*)&(argv[2]);  pa < &(argv[argc+2]);  pa++)
  934    1   			*pa = va_arg(list_incr, char*);
  935    1   		va_end (list_incr);
  936    1   	 
  937    1   			/* Format the output buffer. */
  938    1   		argv[0] = (char *) (argc+1);
  939    1   		argv[1] = buff;
  940    1   		bytes_formatted = va_call (sprintf, argv);
  941    1   	 
  942    1   			/* Remove temporary argument list. */
  943    1   		cfree (argv);
  944    1   	 
  945    1   			/* Write the information. */
  946    1   		bytes_written = gvg$do_qio_write (index, buff, bytes_formatted);
  947    1   	 
  948    1   			/* Return with the appropriate status. */
  949    1   		return (bytes_written);
  950    1   	}
  951        	 
  952        	 
  953        	fprintf (va_alist)
  954        		va_dcl
  955        	{
  956    1   		char			**orig_args;	/* Argument list of original AP. */
  957    1   		FILE			*filptr;	/* One of the arguments (the first to be specific). */
  958    1   	 
  959    1   		struct vms_term_data	*index;		/* Index into vms termio database. */
  960    1   		char			buff[513];	/* Temporary buffer for formatting. */
  961    1   		int			bytes_formatted; /* Number of byte formatted into temporary buffer. */
  962    1   		int			bytes_written;	/* Number of bytes written to terminal. */
  963    1   	 
  964    1   			/* Determine if we need to call the special routines! */
  965    1   		orig_args = ((char *) &va_alist) - 4;			/* Get original argument list. */
  966    1   		filptr = (FILE *)orig_args[1];				/* First argument is "filptr". */
  967    1   	 

GVG$VAXCIO                                                      30-MAR-1989 15:52:59    VAX C      V2.2-015                 Page 10
V1.0                                                            30-MAR-1989 15:48:57    GVG$VAXCIO.C;1 (1)

  968    1   			/* See if we can issue regular C printf. */
  969    1   		if (!(index = gvg$special_fwrite(filptr)))		/* If no special processing is needed...*/
  970    1   			return (va_call (___fprintf, orig_args));	/* ...call the standard fprintf function. */
  971    1   	 
  972    1   	/*
  973    1   	 *	Fortunately, fprintf and sprintf have the same number of arguments
  974    1   	 *	in them.  Since I no longer have a need for "filptr" (because I am
  975    1   	 *	doing my own I/O), I can use the same argument list by replacing
  976    1   	 *	"filptr" for fprintf with a "memory buffer" for sprintf.
  977    1   	 */
  978    1   			/* Format the output buffer. */
  979    1   		orig_args[1] = buff;
  980    1   		bytes_formatted = va_call (sprintf, orig_args);
  981    1   	 
  982    1   			/* Write the information. */
  983    1   		bytes_written = gvg$do_qio_write (index, buff, bytes_formatted);
  984    1   	 
  985    1   			/* Return with the appropriate status. */
  986    1   		return (bytes_written);
  987    1   	}
  988        	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  989        	 *	This file holds the entry points for:
  990        	 *		close, fclose, dup, and dup2.
  991        	 */
  992        	 
  993        	# include	"vmstermio.h"
 1030        	 
 1031        	globalref struct vms_term_data	*vms_term_data_head;
 1032        	 
 1033        	# define	IFLAG(mask)	((index->termio->c_iflag & mask) != 0)
 1034        	# define	OFLAG(mask)	((index->termio->c_oflag & mask) != 0)
 1035        	 
 1036        	close (fildes)
 1037        		int	fildes;
 1038        	{
 1039    1   		struct vms_term_data	*index;
 1040    1   	 
 1041    1   			/* Find out if there was a VMS term data block for it. */
 1042    1   		for (index=vms_term_data_head;  index;  index=index->next)
 1043    1   			if (index->fildes == fildes) break;
 1044    1   	 
 1045    1   			/* Mark the data block inactive. */
 1046    1   		if (index)
 1047    1   		{	index->active = FALSE;
 1048    2   			index->_iobuf = 0;
 1049    2   		}
 1050    1   	 
 1051    1   			/* Return the close status. */
 1052    1   		return (___close(fildes));
 1053    1   	}
 1054        	 
 1055        	 
 1056        	fclose (filptr)
 1057        		FILE	*filptr;
 1058        	{
 1059    1   		struct vms_term_data	*index;
 1060    1   	 

GVG$VAXCIO                                                      30-MAR-1989 15:52:59    VAX C      V2.2-015                 Page 11
V1.0                                                            30-MAR-1989 15:48:57    GVG$VAXCIO.C;1 (1)

 1061    1   			/* Find out if there was a VMS term data block for it. */
 1062    1   		for (index=vms_term_data_head;  index;  index=index->next)
 1063    1   			if (index->_iobuf == *filptr) break;
 1064    1   	 
 1065    1   			/* Mark the data block inactive. */
 1066    1   		if (index)
 1067    1   		{	index->active = FALSE;
 1068    2   			index->_iobuf = 0;
 1069    2   		}
 1070    1   	 
 1071    1   			/* Return the close status. */
 1072    1   		return (___fclose(filptr));
 1073    1   	}
 1074        	 
 1075        	 
 1076        	dup (fildes)
 1077        		int	fildes;
 1078        	{
 1079    1   		int	fd;
 1080    1   		struct vms_term_data	*index, *new_index, *back_ptr;
 1081    1   	 
 1082    1   			/* "dup" it. */
 1083    1   		if ((fd = ___dup(fildes)) == -1)
 1084    1   			return (-1);
 1085    1   	 
 1086    1   			/* Get the VMS terminal data block for old file descriptor. */
 1087    1   		for (index=vms_term_data_head;  index;  index=index->next)
 1088    1   			if (index->fildes == fildes) break;
 1089    1   	 
 1090    1   			/* Make sure we had one! */
 1091    1   		if (!index)
 1092    1   			return (fd);
 1093    1   	 
 1094    1   			/* Now get the VMS terminal data block for new one. */
 1095    1   		for (new_index=vms_term_data_head;  new_index;  new_index=new_index->next)
 1096    1   		{	back_ptr = new_index;
 1097    2   			if (new_index->fildes == fd) break;
 1098    2   		}
 1099    1   	 
 1100    1   			/* If there wasn't one, allocate a new one. */
 1101    1   		if (!new_index)
 1102    1   		{	if (!(new_index = calloc (1, sizeof(*new_index))))
 1103    2   			{	___close (fd);		/* Pretend the "dup" was no good! */
 1104    3   				return (-1);
 1105    3   			}
 1106    2   			back_ptr->next = new_index;	/* Link it onto end of list. */
 1107    2   			new_index-> next = 0;		/* Terminate the list. */
 1108    2   		}
 1109    1   	 
 1110    1   			/* Now duplicate VMS pointers. */
 1111    1   		new_index->fildes = fd;				/* Update the file descriptor. */
 1112    1   		new_index->_iobuf = index->_iobuf;		/* Use same I/O buffers. */
 1113    1   		new_index->vmstermio = index->vmstermio;	/* Use same VMS termio data. */
 1114    1   		new_index->termio = index->termio;		/* Use same unix termio data. */
 1115    1   	}
 1116        	 
 1117        	 

GVG$VAXCIO                                                      30-MAR-1989 15:52:59    VAX C      V2.2-015                 Page 12
V1.0                                                            30-MAR-1989 15:48:57    GVG$VAXCIO.C;1 (1)

 1118        	dup2 (fildes, fildes2)
 1119        		int	fildes, fildes2;
 1120        	{
 1121    1   		int	fd;
 1122    1   		struct vms_term_data	*index, *new_index, *back_ptr;
 1123    1   	 
 1124    1   			/* "dup" it. */
 1125    1   		if ((fd = ___dup(fildes,fildes2)) == -1)
 1126    1   			return (-1);
 1127    1   	 
 1128    1   			/* Get the VMS terminal data block for old file descriptor. */
 1129    1   		for (index=vms_term_data_head;  index;  index=index->next)
 1130    1   			if (index->fildes == fildes) break;
 1131    1   	 
 1132    1   			/* Make sure we had one! */
 1133    1   		if (!index)
 1134    1   			return (fd);
 1135    1   	 
 1136    1   			/* Now get the VMS terminal data block for new one. */
 1137    1   		for (new_index=vms_term_data_head;  new_index;  new_index=new_index->next)
 1138    1   		{	back_ptr = new_index;
 1139    2   			if (new_index->fildes == fd) break;
 1140    2   		}
 1141    1   	 
 1142    1   			/* If there wasn't one, allocate a new one. */
 1143    1   		if (!new_index)
 1144    1   		{	if (!(new_index = calloc (1, sizeof(*new_index))))
 1145    2   			{	___close (fd);		/* Pretend the "dup" was no good! */
 1146    3   				return (-1);
 1147    3   			}
 1148    2   			back_ptr->next = new_index;	/* Link it onto end of list. */
 1149    2   			new_index-> next = 0;		/* Terminate the list. */
 1150    2   		}
 1151    1   	 
 1152    1   			/* Now duplicate VMS pointers. */
 1153    1   		new_index->fildes = fd;				/* Update the file descriptor. */
 1154    1   		new_index->_iobuf = index->_iobuf;		/* Use same I/O buffers. */
 1155    1   		new_index->vmstermio = index->vmstermio;	/* Use same VMS termio data. */
 1156    1   		new_index->termio = index->termio;		/* Use same unix termio data. */
 1157    1   	}

 
 
Command Line
------------
 
CC/LIST GVG$VAXCIO.C+GET.C+PUT.C+READ.C+WRITE.C+PRINT.C+MISC.C

