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


Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Tue,  8 NOV 88 17:55:09 PDT
Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Tue, 8 Nov 88 17:42:59 PST
Received: by ucbvax.Berkeley.EDU (5.59/1.31)
	id AA06923; Mon, 7 Nov 88 22:48:55 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 18:58:36 GMT
From: tektronix!gvgpsa!gvgpvd!tony@ucbvax.Berkeley.EDU  (Tony Ivanov)
Organization: Grass Valley Group, Inc., Grass Valley, CA
Subject: VAXCIO (VAXCIO.SHAR1_OF_5) Source.
Message-Id: <888@gvgpvd.GVG.TEK.COM>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com


	Following will be two VMS shar packages: MISC.SHAR and
VAXCIO.SHAR (parts 1 through 5).

	I would recommend puting MISC.SHAR in a blank directory (for
future reference, call it vaxcio root-directory) and VAXCIO.SHAR%_of_%
in a subdirectory (for future reference, call it vaxcio sub-directory).
Unpack MISC.SHAR with:
	$ @MISC.SHAR
Get into the vaxcio sub-directory and unpack VAXCIO.SHAR%_of_% with:
	$ COPY VAXCIO.SHAR* VAXCIO.SHAR
	$ DELETE VAXCIO.SHAR%*;*
	$ @VAXCIO.SHAR

	After you have unpacked everything, you must do some footwork
before compiling, etc.  In particular, the entry point names I used
are the actual C names from the RTL (printf, write, etc.).  I did this
so that if you already had object modules, you could write a wrapper
routine to change the TT characteristics and link the object which you
already had with mine, thus getting the desired unix-like I/O effects.
I was hoping this would work with the VMS curses stuff, but they use
the SMG$... routines and NOT the C RTL I/O routines; I didn't feel like
re-writing the SMG$... routines, too :-).

	What this means is that you must change the entry point names
in the VAX C RTL.  I have taken great precaution to make sure that my
routines call the VAX C RTL routines if no special I/O processing has
been established.  Basically what you need to do is change some of the
I/O routines to be preceded with three underbars (___).  Here is the
procedure to change the entry point names:
   1)	First, get to the vaxcio root-directory.
   2)	$ COPY SYS$LIBRARY:VAXCRTL.OLB []
   3)	$ LIBRARY/EXTRACT=C$VAXCIO/OUT=C$VAXCIO.OBJ VAXCRTL.OLB
   4)	$ FORTRAN MOD_ENTRY_NAME
   5)	$ LINK MOD_ENTRY_NAME
   5)	$ RUN MOD_ENTRY_NAME
	    Object file is C$VAXCIO.OBJ
	    Change the following entry points:
		CLOSE DUP DUP2 FCLOSE FGETC FGETS FPRINTF FPUTC FPUTS
		FREAD FWRITE GETCHAR GETS GETW PRINTF PUTCHAR PUTS
		PUTW READ WRITE
   6)	$ LIBRARY VAXCRTL.OLB C$VAXCIO.OBJ

	Now you can build my I/O routines.  This part is simple. If you
don't have VMS "make", I can send you a copy.  In the mean-time, the
make file is very straight forward, you can do what it says by hand.
If you do have a "make", do this:
    1)	Get to the vaxcio sub-directory.
    2)	$ COPY SYS$LIBRARY_TERMIO.H SYS$LIBRARY:TERMIO.H
    3)	$ COPY SYS$LIBRARY_VMSTERMIO.H SYS$LIBRARY:VMSTERMIO.H
    4)	$ MAKE
This step will insert my modules into [-]VAXCRTL.OLB.  If you haven't
changed the old entry point names or have missed one, the "make" will
fail.  Simply go back and run MOD_ENTRY_NAME again, change the culprit,
and re-run MAKE.

	When you have successfully entered my routines in [-]VAXCRTL,
you can link directly with it or you can copy it the SYS$LIBRARY with
a new name (I used SYS$LIBRARY:GVG$VAXCRTL.OLB).

	I have included some test programs.  They are called TEST*.C
and DOIT*.C.  If you have any problems/questions, go ahead and call
me: (916)478-3238.  Good luck,
			-- Tony
			tony@gvgpvd.GVG.TEK.COM

$!..............................................................................
$! VAX/VMS archive file created by VMS_SHAR V-5.01 01-Oct-1987
$! which was written by Michael Bednarek (U3369429@ucsvc.dn.mu.oz.au)
$! To unpack, simply save and execute (@) this file.
$!
$! This archive was created by TONY
$! on Wednesday 2-NOV-1988 11:22:27.30
$!
$! ATTENTION: To keep each article below 26112 bytes, this program
$! has been transmitted in 5 parts.
$! You should concatenate ALL parts to ONE file and execute (@) that file.
$!
$! It contains the following 23 files:
$! $$$README. MAKEFILE. DOIT.C GET.C GVG$IOCTL.C GVG$SUPPORT.C GVG$TT_CHAR.C
$! GVG$VAXCIO.C IOCTL.C MISC.C PRINT.C PUT.C READ.C SUPPORT.C TEST.C TEST1.C
$! VMS_TT_CHAR.C WRITE.C SYS$LIBRARY_TERMIO.H SYS$LIBRARY_VMSTERMIO.H
$! SYS_STRUCT.H VMSTERMIO.H GVG$MACRO_SUPPORT.MAR
$!==============================================================================
$ Set Symbol/Scope=(NoLocal,NoGlobal)
$ Version=F$GetSYI("VERSION") ! See what VMS version we have here:
$ If Version.ges."V4.4" then goto Version_OK
$ Write SYS$Output "Sorry, you are running VMS ",Version, -
                ", but this procedure requires V4.4 or higher."
$ Exit 44
$Version_OK: CR[0,8]=13
$ Pass_or_Failed="failed!,passed."
$ Goto Start
$Convert_File:
$ Read/Time_Out=0/Error=No_Error1/Prompt="creating ''File_is'" SYS$Command ddd
$No_Error1: Define/User_Mode SYS$Output NL:
$ Edit/TPU/NoSection/NoDisplay/Command=SYS$Input/Output='File_is' -
        VMS_SHAR_DUMMY.DUMMY
f:=Get_Info(Command_Line,"File_Name");b:=Create_Buffer("",f);
o:=Get_Info(Command_Line,"Output_File");Set(Output_File,b,o);
Position(Beginning_of(b));Loop x:=Erase_Character(1);Loop ExitIf x<>"V";
Move_Vertical(1);x:=Erase_Character(1);Append_Line;
Move_Horizontal(-Current_Offset);EndLoop;Move_Vertical(1);
ExitIf Mark(None)=End_of(b) EndLoop;Position(Beginning_of(b));Loop
x:=Search("`",Forward,Exact);ExitIf x=0;Position(x);Erase_Character(1);
If Current_Character='`' then Move_Horizontal(1);else
Copy_Text(ASCII(INT(Erase_Character(3))));EndIf;EndLoop;Exit;
$ Delete VMS_SHAR_DUMMY.DUMMY;*
$ Checksum 'File_is
$ Success=F$Element(Check_Sum_is.eq.CHECKSUM$CHECKSUM,",",Pass_or_Failed)+CR
$ Read/Time_Out=0/Error=No_Error2/Prompt=" CHECKSUM ''Success'" SYS$Command ddd
$No_Error2: Return
$Start:
$ File_is="$$$README."
$ Check_Sum_is=220272647
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X/*
V *`009This module holds the VMS specific routines necessary to make the VMS ter
Xminal I/O look
V *`009more like unix System V I/O.  This allows things like cbreak, raw, echo, 
Xnonl, etc. to work
V *`009as if on a unix system.  In order for this to happen, the user needs to i
Xnclude the
X *`009vmstermio.h module as in the following example:
X *`009`009#include`009<vmstermio.h>
X *`009This file will reside in sys$library.
X *
V *`009Once the above inclusion is established, and a call to "gtty()" is made, 
Xterminal input functions
V *`009will be processed through the special I/O procedures.  Only I/O to the te
Xrminal will get
X *`009special processing; all other I/O will use standard VAX C routines.
X *
X *`009Here is a list of procedures:
V *`009`009ioctl`009- Similar to ioctl in unix.  Only terminal control is suppor
Xted.
X *`009`009fread`009- Read from a file.
X *`009`009fwrite`009- Write to a file.
X *`009`009fgetc`009- Reads a character from a file.
X *`009`009fputc`009- Writes a character to a file.
X *`009`009fgets`009- Reads a string from a file.
X *`009`009fputs`009- Writes a string to a file.
X *`009`009fprintf`009- Write formatted string to file.
X *`009`009fclose`009- Close a file.
X *`009`009dup`009- Duplicate a file pointer.
X *`009`009dup2`009- Duplicate a file pointer.
X *`009`009read`009- Read from a file.
X *`009`009write`009- Write to a file.
X *`009    *`009getc`009- Get a character from stdin.
X *`009`009getchar`009- Get a character from stdin.
X *`009`009getw`009- Get a word from stdin.
X *`009`009gets`009- Get a string from stdin.
X *`009    *`009putc`009- Put a character to a file.
X *`009`009putchar`009- Put a character to stdout.
X *`009`009putw`009- Put a word to a file.
X *`009`009puts`009- Put a string to stdout.
X *`009`009printf`009- Print a formatted string to stdout.
X *`009`009close`009- Close a file.
X *
V *`009    *`009items preceded by an asterisk (*) are implemented not as procedu
Xres but
X *`009`009as macro definitions.
X *
X *`009Modification history:
V *`009`009June 2, 1987`009Anton Ivanov`009`009Grass Valley Group, Grass Valley,
X CA 95945
V *`009`009`009Original coding.  Functions currently supported are:  ioctl, frea
Xd, fwrite,
V *`009`009`009fgetc, fputc fgets, fputs, fprintf, fclose, dup, dup2, read, writ
Xe, getc,
X *`009`009`009getchar, getw, gets, putc, putchar, putw, puts, printf, close.
X *
X */
X
$ GoSub Convert_File
$ File_is="MAKEFILE."
$ Check_Sum_is=1446934722
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X#
X#`009Make file for GVG VAX C I/O routines.
X#
XLIBRARY`009`009= [-]VAXCRTL.OLB
XIOCTL`009`009= gvg$$ioctl.c+ioctl.c
XSUPPORT`009`009= gvg$$support.c+support.c
XVAXCIO`009`009= gvg$$vaxcio.c+get.c+put.c+read.c+write.c+print.c+misc.c
XMACRO`009`009= gvg$$macro_support.mar
XTT_CHAR`009`009= gvg$$tt_char.c+vms_tt_char.c
VOBJS =`009`009GVG$$IOCTL.OBJ, GVG$$SUPPORT.OBJ, GVG$$VAXCIO.OBJ, GVG$$MACRO_SUP
XPORT.OBJ, GVG$$TT_CHAR.OBJ
X
X.PRECIOUS:`009$(LIBRARY)
X
V$(LIBRARY):`009`009$(LIBRARY)(gvg$$ioctl) $(LIBRARY)(gvg$$support) $(LIBRARY)(g
Xvg$$vaxcio) \
X`009`009`009$(LIBRARY)(gvg$$macro_support) $(LIBRARY)(gvg$$tt_char)
X
X$(LIBRARY)(GVG$$IOCTL):`009`009GVG$$IOCTL.OBJ
X`009lib $(LIBRARY) gvg$$ioctl.obj
X$(LIBRARY)(GVG$$SUPPORT):`009GVG$$SUPPORT.OBJ
X`009lib $(LIBRARY) gvg$$support.obj
X$(LIBRARY)(GVG$$VAXCIO):`009GVG$$VAXCIO.OBJ
X`009lib $(LIBRARY) gvg$$vaxcio.obj
X$(LIBRARY)(GVG$$MACRO_SUPPORT):`009GVG$$MACRO_SUPPORT.OBJ
X`009lib $(LIBRARY) gvg$$macro_support.obj
X$(LIBRARY)(GVG$$TT_CHAR):`009GVG$$TT_CHAR.OBJ
X`009lib $(LIBRARY) gvg$$tt_char.obj
X
XGVG$$IOCTL.OBJ:`009`009$(IOCTL)`009vmstermio.h sys_struct.h
X`009$(CC) $(CFLAGS) $(IOCTL)
XGVG$$SUPPORT.OBJ:`009$(SUPPORT)`009vmstermio.h sys_struct.h
X`009$(CC) $(CFLAGS) $(SUPPORT)
XGVG$$VAXCIO.OBJ:`009$(VAXCIO)`009vmstermio.h
X`009$(CC) $(CFLAGS) $(VAXCIO)
XGVG$$MACRO_SUPPORT.OBJ:`009$(MACRO)
X`009macro/list $(MACRO)
XGVG$$TT_CHAR.OBJ:`009$(TT_CHAR)`009vmstermio.h sys_struct.h
X`009$(CC) $(CFLAGS) $(TT_CHAR)
$ GoSub Convert_File
$ File_is="DOIT.C"
$ Check_Sum_is=35076302
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X# include stdio
X
Xglobalref struct _iobuf`009`009**IO_POINTER;
X
Xmain (argc)
X{`009int`009fd;
X
X`009isatty(fileno(stdin));
X
X`009printf ("_flags = %x\n",(*stdin)->_flag);
X`009printf ("_flags = %x\n",(*stdout)->_flag);
X`009printf ("_flags = %x\n",(*stderr)->_flag);
X}
$ GoSub Convert_File
$ File_is="GET.C"
$ Check_Sum_is=2103119022
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
V/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X~~~~~~~~~~~
X *`009This file holds the entry points for:
X *`009`009getchar, gets, fgetc, getw, and fgets.
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
X
X#undef getchar
Xgetchar ()
X{
V`009struct vms_term_data`009*index;`009`009/* Index into vms termio database. *
X/
X`009int`009`009`009ch=0, och;
X`009int`009`009`009bytes_read=0;
X
X`009`009/* See if we can issue regular C read. */
V`009if (!(index = gvg$special_fread(stdin)))`009`009/* If no special processing
X is needed...*/
V`009`009return (___getchar());`009`009`009/* ...call the standard read function
X. */
X
X`009`009/* Get the information and put it into the output buffer. */
X`009if (IFLAG(BRKINT)  ||  !OFLAG(OPOST))
V`009`009bytes_read = gvg$do_qio_read1 (index, &ch, 1);`009`009/* Direct read. *
X/
X`009else
V`009`009bytes_read = gvg$do_qio_readn (index, &ch, 1, 0);`009/* Buffered read. 
X*/
X`009if ( bytes_read == 0 )
X`009`009ch = EOF;
X
X`009`009/* Post process the output buffer if necessary. */
X`009gvg$do_post (index, &ch, bytes_read);
X
X`009`009/* Return the character read. */
X`009return (ch);
X}
X
X
Xchar *
Xgets (str)
X`009char`009*str;
X{
V`009struct vms_term_data`009*index;`009`009/* Index into vms termio database. *
X/
X`009char`009`009`009*ptr;`009`009/* Pointer into str. */
X`009int`009`009`009och;
X`009int`009`009`009bytes_read=0;
X
X`009`009/* See if we can issue regular C read. */
V`009if (!(index = gvg$special_fread(stdin)))`009/* If no special processing is 
Xneeded...*/
V`009`009return (___gets(str));`009`009`009/* ...call the standard read function
X. */
X
X`009`009/* Get the information and put it into the output buffer. */
X`009if (str)
X`009{`009bytes_read = gvg$do_qio_readn (index, str, 65535, 0);
X
X`009`009`009/* Post process the output buffer if necessary. */
X`009`009gvg$do_post (index, str, bytes_read);
X
X`009`009`009/* Terminate the string properly. */
X`009`009if (bytes_read > 0)
X`009`009{`009ptr = str[bytes_read-1];
X`009`009`009if (*ptr == '\n')
X`009`009`009`009*ptr = '\0';
X`009`009`009else
X`009`009`009`009str = 0;`009/* EOF on input. */
X`009`009}
X`009`009else
X`009`009`009str = 0;
X`009}
X
X`009`009/* Return the actual string read. */
X`009return (str);
X}
X
X
Xint
Xfgetc (filptr)
X`009FILE`009*filptr;
X{
V`009struct vms_term_data`009*index;`009`009/* Index into vms termio database. *
X/
X`009int`009`009`009ch=0, och;
X`009int`009`009`009bytes_read=0;
X
X`009`009/* See if we can issue regular C read. */
V`009if (!(index = gvg$special_fread(filptr)))`009/* If no special processing is
X needed...*/
V`009`009return (___fgetc(filptr));`009`009/* ...call the standard read function
X. */
X
X`009`009/* Get the information and put it into the output buffer. */
X`009if (IFLAG(BRKINT)  ||  !OFLAG(OPOST))
V`009`009bytes_read = gvg$do_qio_read1 (index, &ch, 1);`009`009/* Direct read. *
X/
X`009else
V`009`009bytes_read = gvg$do_qio_readn (index, &ch, 1, 0);`009/* Buffered read. 
X*/
X`009if ( bytes_read == 0 )
X`009`009ch = EOF;
X
X`009`009/* Post process the output buffer if necessary. */
X`009gvg$do_post (index, &ch, bytes_read);
X
X`009`009/* Return the actual number of bytes read. */
X`009return (ch);
X}
X
X
Xint
Xgetw (filptr)
X`009FILE`009*filptr;
X{
V`009struct vms_term_data`009*index;`009`009/* Index into vms termio database. *
X/
X`009unsigned int`009`009ch=0, och;
X`009int`009`009`009bytes_read=0;
X`009char`009`009`009*ptr;
X
X`009`009/* See if we can issue regular C read. */
V`009if (!(index = gvg$special_fread(filptr)))`009/* If no special processing is
X needed...*/
V`009`009return (___getw(filptr));`009`009/* ...call the standard read function.
X */
X
X`009`009/* Get the information and put it into the output buffer. */
X`009if (IFLAG(BRKINT)  ||  !OFLAG(OPOST))
V`009`009bytes_read = gvg$do_qio_read1 (index, &ch, 4);`009`009/* Direct read. *
X/
X`009else
V`009`009bytes_read = gvg$do_qio_readn (index, &ch, 4, 4);`009/* Buffered read. 
X*/
X`009if (bytes_read != 4)
X`009{`009ch = EOF;
X`009`009bytes_read = 0;
X`009}
X
X`009`009/* Post process the output buffer if necessary. */
X`009gvg$do_post (index, &ch, bytes_read);
X
X`009`009/* Return the actual number of bytes read. */
X`009return (ch);
X}
X
X
Xchar *
Xfgets (str, maxchar, filptr)
X`009char`009*str;
X`009int`009maxchar;
X`009FILE`009*filptr;
X{
V`009struct vms_term_data`009*index;`009`009/* Index into vms termio database. *
X/
X`009char`009`009`009*ptr;`009`009/* Pointer into str. */
X`009int`009`009`009och;
X`009int`009`009`009bytes_read=0;
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 (___fgets(str, maxchar, filptr));`009/* ...call the standard rea
Xd function. */
X
X`009`009/* Get the information and put it into the output buffer. */
X`009if (str)
X`009{`009bytes_read = gvg$do_qio_readn (index, str, maxchar-1, 0);
X
X`009`009`009/* Post process the output buffer if necessary. */
X`009`009gvg$do_post (index, str, bytes_read);
X
X`009`009`009/* Terminate the string properly. */
X`009`009if (bytes_read > 0)
X`009`009{`009ptr = str[bytes_read];
X`009`009`009if (*(ptr-1) == '\n')
X`009`009`009`009*ptr = '\0';
X`009`009`009else
X`009`009`009`009str = 0;`009/* EOF on input. */
X`009`009}
X`009`009else
X`009`009`009str = 0;
X`009}
X
X`009`009/* Return the actual string read. */
X`009return (str);
X}
$ GoSub Convert_File
$ File_is="GVG$IOCTL.C"
$ Check_Sum_is=0
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X
$ GoSub Convert_File
$ File_is="GVG$SUPPORT.C"
$ Check_Sum_is=0
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X
$ GoSub Convert_File
$ File_is="GVG$TT_CHAR.C"
$ Check_Sum_is=0
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X
$ GoSub Convert_File
$ File_is="GVG$VAXCIO.C"
$ Check_Sum_is=0
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X
$ GoSub Convert_File
$ Goto Part2
-- 
/* 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		*/

