From:	CSBVAX::CSBVAX::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX"  8-NOV-1988 23:13
To:	MRGATE::"ARISIA::EVERHART"
Subj:	VAXCIO (VAXCIO.SHAR4_OF_5) Source


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


------------ cut -------------
$Part4:
$ File_is="SUPPORT.C"
$ Check_Sum_is=1949604291
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X/*
X *`009This module holds support routines that make life easy on
X *`009the VAXIO routines, but do not do a lot of hard work.  Currently
X *`009these are:
V *`009`009gvg$special_read (fd)`009- Returns index to vms termio block if fd ne
Xeds special I/O
X *`009`009`009`009`009  processing for read ops.
V *`009`009gvg$special_fread (fp)`009- Same as special_read but arg is a file po
Xinter.
V *`009`009gvg$special_write (fd)`009- Returns index to vms termio block if fd n
Xeeds special I/O
X *`009`009`009`009`009  processing for write ops.
V *`009`009gvg$special_fwrite (fp)`009- Same as special_write but arg is a file 
Xpointer.
X *`009`009gvg$do_flush_read (index)
V *`009`009`009`009`009- Flushes input on channel.  Returns TRUE if flush was su
Xccessful.
X *`009`009gvg$do_flush_write (index)
V *`009`009`009`009`009- Flushes output on channel.  Returns TRUE if flush was s
Xuccessful.
X *`009`009gvg$do_qio_read1 (index, buff, buff_size)
V *`009`009`009`009`009- Reads buff_size number of bytes into buff and returns t
Xhe actual
V *`009`009`009`009`009  number of bytes read.  The input is terminated when the
X specified
V *`009`009`009`009`009  number of bytes (or an EOF) is read.  This is considere
Xd a direct
X *`009`009`009`009`009  I/O operation.
X *`009`009gvg$do_qio_readn (index, buff, buff_size, min_size)
V *`009`009`009`009`009- Reads up to buff_size number of bytes into buff and ret
Xurns the
V *`009`009`009`009`009  actual number of bytes read.  This is a buffered input 
Xoperation.
V *`009`009`009`009`009  If an EOF condition is encountered before buff_size byt
Xes have
V *`009`009`009`009`009  been transfered to buff, the eof character is NOT appen
Xded and
V *`009`009`009`009`009  the routine returns the actual number of characters rea
Xd!
X *`009`009gvg$do_qio_write (index, buff, buff_size)
X *`009`009`009`009`009- Write buff_size number of characters from buff to chan.
X *`009`009gvg$do_post (index, buff, nbytes)
V *`009`009`009`009`009- Post process the buffer (usually after a read) accordin
Xg to
X *`009`009`009`009`009  current terminal settings.
X */
X
X# include`009<ctype.h>
X# include`009<errno.h>
X# include`009<iodef.h>
X# include`009<ssdef.h>
X# include`009"sys_struct.h"
X# include`009<trmdef.h>
X# include`009"vmstermio.h"
X# define`009bool`009char
X# define`009TRUE`009(1)
X# define`009FALSE`009(0)
X
Xglobalref struct vms_term_data`009`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
X# define`009CNT`009index->_iobuf->_cnt
X# define`009PTR`009index->_iobuf->_ptr
X# define`009BASE`009index->_iobuf->_base
X# define`009FLAG`009index->_iobuf->_flag
X
Xstruct vms_term_data *
Xgvg$special_read (fildes)
X`009int`009fildes;
X{
X`009struct vms_term_data`009*index;
X
X`009`009/* Get the structure for this particular file descriptor. */
X`009for (index=vms_term_data_head;  index;  index=index->next)
X`009{`009if (index->fildes == fildes)
X`009`009{`009if (index->active)
X`009`009`009`009return (index);
X`009`009`009else
X`009`009`009`009return (0);
X`009`009}
X`009}
X
V`009`009/* If it gets here, there is no structure yet.  (ioctl was not called y
Xet.) */
X`009return (0);
X}
X
X
X
Xstruct vms_term_data *
Xgvg$special_fread (filptr)
X`009FILE`009*filptr;
X{
X`009struct vms_term_data`009*index;
X
X`009`009/* Validate input parameter. */
X`009if (filptr < 0x200)
X`009`009return (0);
X
X`009`009/* Get the structure for this particular file pointer. */
X`009for (index=vms_term_data_head;  index;  index=index->next)
X`009{`009if (index->_iobuf == *filptr)
X`009`009{`009if (index->active)
X`009`009`009`009return (index);
X`009`009`009else
X`009`009`009`009return (0);
X`009`009}
X`009}
X
V`009`009/* If it gets here, there is no structure yet.  (ioctl was not called y
Xet.) */
X`009return (0);
X}
X
X
X
Xstruct vms_term_data *
Xgvg$special_write (fildes)
X`009int`009fildes;
X{
X`009struct vms_term_data`009*index;
X
X`009`009/* Get the structure for this particular file descriptor. */
X`009for (index=vms_term_data_head;  index;  index=index->next)
X`009{`009if (index->fildes == fildes)
X`009`009{`009if (!index->active)  return (0);
X`009`009`009if (OFLAG (OLCUC) || OFLAG (OCRNL) || !OFLAG(ONLCR))
X`009`009`009`009return (index);
X`009`009`009else
X`009`009`009`009return (0);
X`009`009}
X`009}
X
V`009`009/* If it gets here, there is no structure yet.  (ioctl was not called y
Xet.) */
X`009return (0);
X}
X
X
Xstruct vms_term_data *
Xgvg$special_fwrite (filptr)
X`009FILE`009*filptr;
X{
X`009struct vms_term_data`009*index;
X
X`009`009/* Validate input parameter. */
X`009if (filptr < 0x200)
X`009`009return (0);
X
X`009`009/* Get the structure for this particular file pointer. */
X`009for (index=vms_term_data_head;  index;  index=index->next)
X`009{`009if (index->_iobuf == *filptr)
X`009`009{`009if (!index->active)  return (0);
X`009`009`009if (OFLAG (OLCUC) || OFLAG (OCRNL) || !OFLAG(ONLCR))
X`009`009`009`009return (index);
X`009`009`009else
X`009`009`009`009return (0);
X`009`009}
X`009}
X
V`009`009/* If it gets here, there is no structure yet.  (ioctl was not called y
Xet.) */
X`009return (0);
X}
X
X
Xgvg$do_flush_read (index)
X`009struct vms_term_data`009*index;
X{
V`009unsigned short int`009func=0;`009`009`009/* QIO function code and modifiers
X. */
X`009unsigned short int`009chan;`009`009`009/* Channel for QIO. */
V`009unsigned int`009`009p1=0, p2=0, p3=0;`009/* QIO funciton dependent paramete
Xrs. */
V`009struct iosb_struct`009iosb;`009`009`009/* I/O status block for call to QIO.
X */
X`009unsigned int`009`009junk;`009`009`009/* Buffer...just in case! */
X
V`009func = IO$_READVBLK | IO$M_PURGE | IO$M_NOECHO | IO$M_TIMED;`009/* Function
X value to flush buffer. */
X`009chan = index->vmstermio->chan;
V`009p1 = junk;`009`009/* A buffer, just in case some data has to be written som
Xewhere! */
X`009p2 = 0;`009`009`009/* Indicate no room in buffer. */
X`009p3 = 0;`009`009`009/* timeout value (immediate timeout). */
V`009if ((vaxc$errno = sys$qiow (0, chan, func, &iosb, 0, 0, p1, p2, p3, 0, 0, 0
X)) != SS$_NORMAL)
X`009{`009if (vaxc$errno != SS$_TIMEOUT)
X`009`009{`009errno = EVMSERR;
X`009`009`009return (FALSE);
X`009`009}
X`009}
X`009if ((vaxc$errno = iosb.cond) != SS$_NORMAL)
X`009{`009if (vaxc$errno != SS$_TIMEOUT)
X`009`009{`009errno = EVMSERR;
X`009`009`009return (FALSE);
X`009`009}
X`009}
X`009CNT = 0;
X`009PTR = BASE;
X`009FLAG = 0;
X
X`009return (TRUE);
X}
X
X
Xgvg$do_flush_write (index)
X`009struct vms_term_data`009*index;
X{
X/*
X *`009This function writes out any data that has been buffered, resets the
X *`009buffer pointers and returns TRUE upon successful completion.
X */
V`009unsigned short int`009func=0;`009`009`009/* QIO function code and modifiers
X. */
X`009unsigned short int`009chan;`009`009`009/* Channel for QIO. */
V`009unsigned int`009`009p1=0, p2=0;`009`009/* QIO funciton dependent parameters
X. */
V`009struct iosb_struct`009iosb;`009`009`009/* I/O status block for call to QIO.
X */
X`009unsigned int`009`009junk;`009`009`009/* Buffer...just in case! */
X
X`009if (PTR-BASE)
X`009{`009chan = index->vmstermio->chan;
X`009`009func = IO$_WRITEVBLK;`009`009/* The QIO function type. */
X`009`009p1 = BASE;`009`009`009/* The output buffer. */
X`009`009p2 = PTR-BASE;
V`009`009if ((vaxc$errno = sys$qiow (0, chan, func, &iosb, 0, 0, p1, p2, 0, 0, 0
X, 0)) != SS$_NORMAL)
X`009`009{`009errno = EVMSERR;
X`009`009`009FLAG |= _IOERR;
X`009`009`009CNT = BUFSIZ;
X`009`009`009PTR = BASE;
X`009`009`009return (FALSE);
X`009`009}
X`009`009else if ((vaxc$errno = iosb.cond) != SS$_NORMAL)
X`009`009{`009errno = EVMSERR;
X`009`009`009FLAG |= _IOERR;
X`009`009`009CNT = BUFSIZ;
X`009`009`009PTR = BASE;
X`009`009`009return (FALSE);
X`009`009}
X`009}
X
X`009CNT = BUFSIZ;
X`009PTR = BASE;
X`009return (TRUE);
X}
X
X
Xgvg$do_qio_read1 (index, buff, buff_size)
X`009struct vms_term_data`009*index;
X`009char`009`009`009*buff;
X`009int`009`009`009buff_size;
X{
X`009unsigned short int`009chan=0;`009`009`009/* Channel for QIO. */
V`009unsigned short int`009func=0;`009`009`009/* QIO function code and modifiers
X. */
X`009char`009`009`009*p1;`009`009`009/* Buffer. */
V`009unsigned int`009`009p2, p3, p4[2];`009`009/* QIO funciton dependent paramet
Xers. */
V`009struct iosb_struct`009iosb;`009`009`009/* I/O status block for call to QIO.
X */
X`009bool`009`009`009done;`009`009`009/* True when EOF encountered. */
X
X`009`009/* Set up the QIO parameters. */
V`009chan = index->vmstermio->chan;`009`009`009/* This is the channel to operate
X on. */
V`009func = IO$_READVBLK | IO$M_NOFILTR;`009`009/* The QIO function type (no lin
Xe editing). */
V`009p2 = 1;`009`009`009`009`009`009/* Indicate buffer size, get one character a
Xt a time. */
X`009p3 = 0;`009`009`009`009`009`009/* Timout value...not used. */
V`009p4[0] = 0;`009`009`009`009`009/* Indicate short form for terminator mask. *
X/
V`009p4[1] = 0xffffffff;`009`009`009`009/* All control characters are terminator
Xs. */
X
X`009`009/* Issue the QIO and process any possible errors. */
X`009for (done=FALSE, p1=buff;  p1 < &(buff[buff_size]);  p1++)
V`009{`009if ((vaxc$errno = sys$qiow (0, chan, func, &iosb, 0, 0, p1, p2, p3, &p
X4, 0, 0)) != SS$_NORMAL)
X`009`009{`009errno = EVMSERR;
X`009`009`009FLAG |= _IOERR;
X`009`009`009return (0);
X`009`009}
X`009`009if ((vaxc$errno = iosb.cond) != SS$_NORMAL)
X`009`009{`009errno = EVMSERR;
X`009`009`009FLAG |= _IOERR;
X`009`009`009return (0);
X`009`009}
X`009`009if (*p1 == (char)0x1a  &&  OFLAG(OPOST))
X`009`009{`009done = TRUE;`009`009/* CTRL-Z */
X`009`009`009FLAG |= _IOEOF;
X`009`009}
X`009}
X
X`009`009/* Return the number of bytes actually read. */
X`009if (done)
X`009`009return (0);
X`009else
X`009`009return (p1-buff);
X}
X
X
Xgvg$do_qio_readn (index, buff, buff_size, min_size)
X`009struct vms_term_data`009*index;
X`009char`009`009`009*buff;
X`009int`009`009`009buff_size;
X`009int`009`009`009min_size;`009`009/* Minimum # bytes to be read in. */
X{
X`009unsigned short int`009chan=0;`009`009`009/* Channel for QIO. */
V`009unsigned short int`009func=0;`009`009`009/* QIO function code and modifiers
X. */
V`009unsigned int`009`009p1, p2, p3, p4, p5, p6;`009/* QIO funciton dependent pa
Xrameters. */
V`009struct iosb_struct`009iosb;`009`009`009/* I/O status block for call to QIO.
X */
V`009struct item_list_struct`009item_list[2] =`009{`009/* Item list for extended
X read function. */
V`009`009`009`009`009`009    { 0, TRM$_MODIFIERS, TRM$M_TM_NOEDIT | TRM$M_TM_NOR
XECALL, 0 },
X`009`009`009`009`009`009    { 0, TRM$_TERM, 0, 0 },
X`009`009`009`009`009`009};
V`009bool`009`009`009done;`009`009`009/* True when its O.K. to exit read loop. *
X/
X`009bool`009`009`009EOF_seen=FALSE;`009`009/* True if EOF terminator seen. */
X`009char`009`009`009*ptr;`009`009`009/* Pointer into user buffer. */
X
X`009`009/* Set up the QIO parameters. */
V`009chan = index->vmstermio->chan;`009`009`009/* This is the channel to operate
X on. */
V`009func = IO$_READVBLK | IO$M_EXTEND;`009`009/* The QIO function type (with it
Xemlist read). */
X`009p1 = (unsigned int) BASE;`009`009`009/* Base of internal buffer. */
X`009p2 = BUFSIZ;`009`009`009`009`009/* Indicate internal buffer size. */
X`009p3 = 0;`009`009`009`009`009`009/* Timout value...not used. */
X`009p4 = 0;
V`009item_list[1].buff_len = 0;`009`009`009/* Indicate short form for terminator
X mask. */
V`009item_list[1].buff_addr = 1 << 26;`009`009/* CTRL-Z is always a terminator. 
X*/
V`009if (IFLAG(ICRNL)) item_list[1].buff_addr |= 1 << '\r';`009/* CR is a termin
Xator in this case. */
V`009if (!IFLAG(INLCR)) item_list[1].buff_addr |= 1 << '\n';`009/* NL is a termi
Xnator in this case. */
X`009p5 = (unsigned int) item_list;
X`009p6 = sizeof(item_list);
X
X`009`009/* Transfer buffered input to user buffer until buffered input gone or
X`009`009   a terminator is seen. */
V`009for (done=FALSE, ptr=buff;  !done && (ptr < &(buff[buff_size]));  CNT--, PT
XR++, ptr++)
X`009{`009if (!CNT)`009/* No buffered input left...get some more! */
X`009`009`009`009/* Issue the QIO and process any possible errors. */
V`009`009{`009if ((vaxc$errno = sys$qiow (0, chan, func, &iosb, 0, 0, p1,p2,p3,p
X4,p5,p6)) != SS$_NORMAL)
X`009`009`009{`009errno = EVMSERR;
X`009`009`009`009FLAG |= _IOERR;
X`009`009`009`009return (ptr-buff);
X`009`009`009}
X`009`009`009if ((vaxc$errno = iosb.cond) != SS$_NORMAL)
X`009`009`009{`009errno = EVMSERR;
X`009`009`009`009FLAG |= _IOERR;
X`009`009`009`009return (ptr-buff);
X`009`009`009}
X`009`009`009PTR = BASE;
X`009`009`009CNT = iosb.variant.read.offset + iosb.variant.read.term_size;
X`009`009}
X`009`009*ptr = *PTR;
X`009`009if (*ptr < 32)`009/* Possible terminator. */
V`009`009{`009if ((1 << *ptr) & item_list[1].buff_addr)`009/* It IS a terminator
X! */
X`009`009`009`009if (ptr >= &(buff[min_size-1]))
X`009`009`009`009`009done = TRUE;
X`009`009`009if (*ptr == 26)
X`009`009`009`009EOF_seen = TRUE;
X`009`009}
X`009}
X`009if (EOF_seen)`009/* EOF character is never returned in buffered read. */
X`009{`009ptr--;
X`009`009FLAG |= _IOEOF;
X`009}
X
X`009`009/* Return the number of bytes actually read. */
X`009return (ptr-buff);
X}
X
X
Xgvg$do_qio_write (index, buff, nbytes)
X`009struct vms_term_data`009*index;
X`009char`009`009`009*buff;
X`009int`009`009`009nbytes;
X{
X`009unsigned short int`009chan;`009`009`009/* QIO channel number. */
V`009unsigned short int`009func=0;`009`009`009/* QIO function code and modifiers
X. */
V`009unsigned int`009`009p1=0, p2=0;`009`009/* QIO funciton dependent parameters
X. */
V`009struct iosb_struct`009iosb;`009`009`009/* I/O status block for call to QIO.
X */
V`009int`009`009`009bytes_written=0;`009/* Total number of bytes currently writt
Xen. */
X`009char`009`009`009*ptr, och;
X
X`009`009/* Set up the QIO parameters. */
X`009chan = index->vmstermio->chan;`009/* The QIO channel number. */
X`009func = IO$_WRITEVBLK;`009`009/* The QIO function type. */
X`009p1 = BASE;`009`009`009/* The output buffer. */
X
X`009`009/* Validate the output buffer. */
X`009if (PTR == 0  || CNT == 0)
X`009{`009PTR = BASE;
X`009`009CNT = BUFSIZ;
X`009}
X
X`009for (ptr=buff;  ptr < &(buff[nbytes]);  ptr++, PTR++, CNT--)
X`009{`009`009/* Xfer data to output buffer and convert if necessary. */
X`009`009och = *PTR = *ptr;
X`009`009if (OFLAG(ONLCR)  &&  och == '\n')
X`009`009{`009*PTR++ = '\r';  CNT--;
X`009`009`009*PTR = '\n';
X`009`009}
X`009`009if (OFLAG(OCRNL)  &&  och == '\r')
X`009`009`009*PTR = '\n';
X`009`009if (OFLAG(OLCUC)  &&  islower(och))
X`009`009`009*PTR = _toupper(och);
X
V`009`009`009/* Write the temporary buffer if it's full, done with I/O and un-bu
Xffered, or
X`009`009`009   buffered w/ newline and character is \n. */
X`009`009if ((CNT <= 1) ||
X`009`009    ((ptr == &(buff[nbytes-1])) && (FLAG&_IONBF != 0)) ||
X`009`009    (FLAG&_IONBF==0 && OFLAG(ONLCR) && *PTR=='\n') )
X`009`009{`009`009/* Issue the QIO and process any possible errors. */
X`009`009`009p2 = PTR-BASE + 1;
V`009`009`009if ((vaxc$errno = sys$qiow (0, chan, func, &iosb, 0, 0, p1, p2, 0, 
X0, 0, 0)) != SS$_NORMAL)
X`009`009`009{`009errno = EVMSERR;
X`009`009`009`009FLAG |= _IOERR;
X`009`009`009`009CNT = BUFSIZ;
X`009`009`009`009PTR = BASE;
X`009`009`009`009return (ptr-buff);
X`009`009`009}
X`009`009`009else if ((vaxc$errno = iosb.cond) != SS$_NORMAL)
X`009`009`009{`009errno = EVMSERR;
X`009`009`009`009FLAG |= _IOERR;
X`009`009`009`009CNT = BUFSIZ;
X`009`009`009`009PTR = BASE;
X`009`009`009`009return (ptr-buff);
X`009`009`009}
V`009`009`009CNT = BUFSIZ+1;`009`009`009/* Will get decremented at end of loop! 
X*/
V`009`009`009PTR = BASE;  PTR--;`009`009/* Will get incremented at end of loop! 
X*/
X`009`009}
X`009}
X
X`009`009/* Return the number of bytes actually written. */
X`009return (ptr-buff);
X}
X
X
Xgvg$do_post (index, buff, nbytes)
X`009struct vms_term_data`009*index;`009`009/* Pointer to I/O structure. */
V`009char`009`009`009*buff;`009`009/* Buffer that holds data to be post processe
Xd. */
X`009int`009`009`009nbytes;`009`009/* Number of bytes to post process. */
X{
X`009char`009*ptr, och;
X
X`009if ( IFLAG(INLCR) || IFLAG(IUCLC) || IFLAG(ICRNL) )
X`009{`009for (ptr=buff;  ptr < &(buff[nbytes]);  ptr++)
X`009`009{`009och = *ptr;
X`009`009`009if (IFLAG(INLCR) && och=='\n')
X`009`009`009`009*ptr = '\r';
X`009`009`009if (IFLAG(IUCLC) && isupper(och))
X`009`009`009`009*ptr = _tolower(och);
X`009`009`009if (IFLAG(ICRNL) && och == '\r')
X`009`009`009`009*ptr = '\n';
X`009`009}
X`009}
X}
X/*`009
X/*`009
X/*`009void
X/*`009startbuf (fildes)
X/*`009`009int`009fildes;
X/*`009{
X/*`009`009struct vms_term_data`009*index;
X/*`009
X/*`009`009`009/* Get the structure for this particular file descriptor. */
X/*`009`009for (index=vms_term_data_head;  index;  index=index->next)
X/*`009`009{`009if (index->fildes == fildes)
X/*`009`009`009{`009if (index->active)
X/*`009`009`009`009{`009FLAG &= ~_IONBF;
X/*`009`009`009`009`009return;
X/*`009`009`009`009}
X/*`009`009`009}
X/*`009`009}
X/*`009}
X/*`009
X/*`009
X/*`009void
X/*`009endbuf (fildes)
X/*`009`009int`009fildes;
X/*`009{
X/*`009`009struct vms_term_data`009*index;
X/*`009
X/*`009`009`009/* Get the structure for this particular file descriptor. */
X/*`009`009for (index=vms_term_data_head;  index;  index=index->next)
X/*`009`009{`009if (index->fildes == fildes)
X/*`009`009`009{`009if (index->active)
X/*`009`009`009`009{`009FLAG |= _IONBF;
X/*`009`009`009`009`009return;
X/*`009`009`009`009}
X/*`009`009`009}
X/*`009`009}
X/*`009}
X */
$ GoSub Convert_File
$ File_is="TEST.C"
$ Check_Sum_is=2002391326
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X# include`009<stdio.h>
X# include`009<vmstermio.h>
Xmain (argc, argv)
X`009char *argv[];
X{
X`009char str[100];
X`009struct termio`009save_termio;
X
X`009gtty(_tty_ch, &_tty);
X`009save_termio = _tty;
X`009if (argc > 1)
X`009{`009if (strchr(argv[1],'b'))  cbreak();
X`009`009if (strchr(argv[1],'n'))  nonl();
X`009`009if (strchr(argv[1],'r'))  raw();
X`009`009if (strchr(argv[1],'e'))  noecho();
X`009`009if (strchr(argv[1],'l'))  iuclc();
X`009`009if (strchr(argv[1],'u'))  olcuc();
X`009}
X`009printf ("\n***\n");
X`009printf ("%x\n", getw (stdin));
X`009if (feof(stdin)) printf ("EOF on stdin.\n");
X`009printf ("\n***\n");
X`009printf ("%x\n", getchar ());
X`009if (feof(stdin)) printf ("EOF on stdin.\n");
X`009printf ("\n***\n");
X`009stty(_tty_ch, &save_termio);
X}
$ GoSub Convert_File
$ File_is="TEST1.C"
$ Check_Sum_is=609640938
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X# include`009<stdio.h>
Xmain (argc, argv)
X`009char *argv[];
X{
X`009char str[100];
X
X`009printf ("\n***\n");
X`009printf ("%x\n", getw (stdin));
X`009if (feof(stdin)) printf ("EOF on stdin.\n");
X`009printf ("\n***\n");
X`009printf ("%x\n", getchar ());
X`009if (feof(stdin)) printf ("EOF on stdin.\n");
X`009printf ("\n***\n");
X}
$ GoSub Convert_File
$ File_is="VMS_TT_CHAR.C"
$ Check_Sum_is=577594841
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X/*
X *`009This routine sets the VMS terminal characteristics for strictly
X *`009VMS functions for a terminal already under ioctl control.
X */
X
X# include`009<errno.h>
X# include`009<iodef.h>
X# include`009<ssdef.h>
X# include`009"sys_struct.h"
X# include`009<ttdef.h>
X# include`009<tt2def.h>
X# include`009"vmstermio.h"`009/* Only structures defined. */
X# define`009bool`009char
X# define`009reg`009register
X
Xglobalref struct vms_term_data`009`009*vms_term_data_head;
X
V# define`009BITS(flag,mask)`009`009`009(index->vmstermio->char_buff.flag & mask
X)
X# define`009BTEST(flag,mask)`009`009(BITS(flag,mask) == mask)
V# define`009SETBITS(flag,mask)`009`009(index->vmstermio->char_buff.flag |= mask
X)
V# define`009RESETBITS(flag,mask)`009`009(index->vmstermio->char_buff.flag &= ~m
Xask)
X
X/*
X *`009This routine returns TRUE if a terminal characteristic is set.
X */
X
Xint
Xvms_has_tt_char (fildes, tt_char, second)
X`009int`009fildes;`009`009/* File descriptor to check it on. */
X`009int`009tt_char;`009/* Which characteristic to check. */
V`009bool`009second;`009`009/* TRUE to use second word of characteristics buffer
X. */
X{
V`009struct vms_term_data`009*index;`009`009`009`009/* Index into VMS terminal d
Xata block. */
X
X
X`009`009/* Get the structure for this particular file descriptor. */
X`009for (index=vms_term_data_head;  index;  index=index->next)
X`009{`009if (index->fildes == fildes)
X`009`009`009break;
X`009}
X`009if (!index)
X`009`009return 0;
X
X`009`009/* Check the bit. */
X`009if (!second)
X`009`009return (BTEST (term_char, tt_char));
X`009else
X`009`009return (BTEST (term_char2, tt_char));
X}
X
X
X/*
X *`009This routine sets a terminal characteristic.
X */
X
Xint
Xvms_set_tt_char (fildes, tt_char, second)
X`009int`009fildes;`009`009/* File descriptor to set it on. */
X`009int`009tt_char;`009/* Which characteristic to set. */
V`009bool`009second;`009`009/* TRUE to use second word of characteristics buffer
X. */
X{
V`009struct vms_term_data`009*index;`009`009`009/* Index into VMS terminal data 
Xblock. */
V `009unsigned short int`009func=0;`009`009`009/* QIO function code and modifier
Xs. */
X`009unsigned short int`009chan;
V`009unsigned int`009`009p1=0, p2=0, p3=0;`009/* QIO funciton dependent paramete
Xrs. */
V`009struct iosb_struct`009iosb;`009`009`009/* I/O status block for call to QIO.
X */
V`009bool`009`009`009changes;`009`009/* TRUE if VMS term. characteristics have c
Xhanged. */
X
X
X`009`009/* Get the structure for this particular file descriptor. */
X`009for (index=vms_term_data_head;  index;  index=index->next)
X`009{`009if (index->fildes == fildes)
X`009`009`009break;
X`009}
X`009if (!index)
X`009`009return 0;
X
X
X`009`009/* Set the bit(s). */
X`009if (!second)
X`009`009SETBITS (term_char, tt_char);
X`009else
X`009`009SETBITS (term_char2, tt_char);
X
X`009func = IO$_SETMODE;`009`009`009/* Set current terminal characteristics. */
V`009chan = index->vmstermio->chan;`009`009/* Channel for this particular QIO. *
X/
V`009p1 = &(index->vmstermio->char_buff);`009/* Address of characteristics buffe
Xr. */
X`009p2 = 12;`009`009`009`009/* Length of characteristics buffer. */
X`009p3 = index->vmstermio->baud;`009`009/* The (possibly new) baud rate. */
V`009if ((vaxc$errno = sys$qiow (0, chan, func, &iosb, 0, 0, p1, p2, p3, 0, 0, 0
X)) != SS$_NORMAL)
X`009{`009errno = EVMSERR;
X`009`009return (FALSE);
X`009}
X`009if ((vaxc$errno = iosb.cond) != SS$_NORMAL)
X`009{`009errno = EVMSERR;
X`009`009return (FALSE);
X`009}
X
X`009`009/* Return success. */
X`009return (TRUE);
X}
X
X
X/*
X *`009This routine resets a terminal characteristic.
X */
X
Xint
Xvms_reset_tt_char (fildes, tt_char, second)
X`009int`009fildes;`009`009/* File descriptor to reset it on. */
X`009int`009tt_char;`009/* Which characteristic to reset. */
V`009bool`009second;`009`009/* TRUE to use second word of characteristics buffer
X. */
X{
V`009struct vms_term_data`009*index;`009`009`009/* Index into VMS terminal data 
Xblock. */
V `009unsigned short int`009func=0;`009`009`009/* QIO function code and modifier
Xs. */
X`009unsigned short int`009chan;
V`009unsigned int`009`009p1=0, p2=0, p3=0;`009/* QIO funciton dependent paramete
Xrs. */
V`009struct iosb_struct`009iosb;`009`009`009/* I/O status block for call to QIO.
X */
V`009bool`009`009`009changes;`009`009/* TRUE if VMS term. characteristics have c
Xhanged. */
X
X
X`009`009/* Get the structure for this particular file descriptor. */
X`009for (index=vms_term_data_head;  index;  index=index->next)
X`009{`009if (index->fildes == fildes)
X`009`009`009break;
X`009}
X`009if (!index)
X`009`009return 0;
X
X
X`009`009/* Reset the bit(s). */
X`009if (!second)
X`009`009RESETBITS (term_char, tt_char);
X`009else
X`009`009RESETBITS (term_char2, tt_char);
X
X`009func = IO$_SETMODE;`009`009`009/* Set current terminal characteristics. */
V`009chan = index->vmstermio->chan;`009`009/* Channel for this particular QIO. *
X/
V`009p1 = &(index->vmstermio->char_buff);`009/* Address of characteristics buffe
Xr. */
X`009p2 = 12;`009`009`009`009/* Length of characteristics buffer. */
X`009p3 = index->vmstermio->baud;`009`009/* The (possibly new) baud rate. */
V`009if ((vaxc$errno = sys$qiow (0, chan, func, &iosb, 0, 0, p1, p2, p3, 0, 0, 0
X)) != SS$_NORMAL)
X`009{`009errno = EVMSERR;
X`009`009return (FALSE);
X`009}
X`009if ((vaxc$errno = iosb.cond) != SS$_NORMAL)
X`009{`009errno = EVMSERR;
X`009`009return (FALSE);
X`009}
X
X`009`009/* Return success. */
X`009return (TRUE);
X}
$ GoSub Convert_File
$ Goto Part5
------------ cut -------------
-- 
/* 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		*/

