From:	CSBVAX::MRGATE!@KL.SRI.Com:info-vax-request@kl.sri.com@SMTP 25-OCT-1987 14:34
To:	EVERHART
Subj:	VI in TPU part 5/14

Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Sat 24 Oct 87 15:57:50-PDT
Received: by ucbvax.Berkeley.EDU (5.58/1.27)
	id AA03194; Sat, 24 Oct 87 15:59:48 PDT
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: 21 Oct 87 05:51:05 GMT
From: pbox!okstate!gregg@rutgers.edu  (Gregg Wonderly)
Organization: Oklahoma State Univ., Stillwater
Subject: VI in TPU part 5/14
Message-Id: <2717@okstate.UUCP>
References: gregg@nemo.math.okstate.edu
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

$!=============================================================================
$! VAX/VMS archive file created by VMS_SHAR V-4.03 05-Aug-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 GREGG
$!      on Tuesday 20-OCT-1987 22:26:38.16
$!
$! It contains the following 5 files:
$! DO.COM MAILEDIT.COM VI.CLD VI.COM VISETUP.COM
$!=============================================================================
$ 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;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="[.EXE]DO.COM"
$ Check_Sum_is=388123797
$ if f$search("EXE.DIR;1") .eqs. "" then -
     CREATE/LOG/DIRECTORY [.EXE]
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X$ v=f$verify(0)
X$!
X$!	DO.COM
X$!
X$!	Written by Gregg Wonderly 30-Oct-1986
X$!
X$! write sys$output "$ ''P1' ''P2' ''P3' ''P4' ''P5' ''P6' ''P7' ''P8'"
X$ write sys$output "$ ",P1," ",P2," ",P3," ",P4," ",P5," ",P6," ",P7," ",P8
X$ 'P1' 'P2' 'P3' 'P4' 'P5' 'P6' 'P7' 'P8'
X$ EXIT $status+('f$verify(v)'*0)
$ GoSub Convert_File
$ File_is="[.EXE]MAILEDIT.COM"
$ Check_Sum_is=740363787
$ if f$search("EXE.DIR;1") .eqs. "" then -
     CREATE/LOG/DIRECTORY [.EXE]
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X$ !
X$ ! Command procedure to invoke an editor for MAIL.
X$ !
X$ ! Inputs:
X$ !
X$ !	P1 = Input file name.
X$ !	P2 = Output file name.
X$ !
X$ ! If MAIL$EDIT is undefined, MAIL will invoke callable EDT.
X$ ! If MAIL$EDITis defined to be a command procedure,
X$ ! MAIL will create a subprocess to edit the mail.
X$ !
X$ ! Note that this procedure is run in the context of a subprocess.
X$ ! LOGIN.COM is not executed.  However, all process logical names
X$ ! and DCL global symbols are copied.
X$ !
X$ ! The default directory is the same as the parent process
X$ !
X$	IF P1 .EQS. "" THEN GOTO NOINPUT
X$	@VI$ROOT:[EXE]VI 'P1' /OUTPUT='P2' "" "" "" "" "" "NOSPAWN"
X$	EXIT
X$ NOINPUT:
X$	@VI$ROOT:[EXE]VI 'P2' "" "" "" "" "" "" "NOSPAWN"
X$	EXIT
$ GoSub Convert_File
$ File_is="[.EXE]VI.CLD"
$ Check_Sum_is=694572112
$ if f$search("EXE.DIR;1") .eqs. "" then -
     CREATE/LOG/DIRECTORY [.EXE]
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X!
X!  CLD for VI.  Derived from the CLD for the EDIT command
X!  This CLD redefines the default values for the parameters to EDIT/TPU so
X!  that VI is the default section file instead of EVE.
X!
Xdefine verb vi
X   image VI$ROOT:[EXE]VI.EXE
X   parameter P1 , label=FILE_NAME , prompt="File"
X      value (list,type=$infile)
X   qualifier SECTION
X      default
X      value (default="VISECINI",type=$infile)
X   qualifier LISTING
X      value (type=$outfile)
X   qualifier OUTPUT
X      value (type=$outfile)
X   qualifier READ_ONLY
X   qualifier UPDATE
X      value (list)
X      placement=local
X   qualifier COMMAND
X      default
X      value (DEFAULT="VIINI",TYPE=$INFILE)
X   qualifier RECOVER
X   qualifier JOURNAL
X      default
X      value (type=$infile)
X   qualifier DISPLAY
X      default
X      value (list,type=$infile)
X   qualifier CREATE
X      default
X   qualifier TPU
X      default
$ GoSub Convert_File
$ File_is="[.EXE]VI.COM"
$ Check_Sum_is=156378540
$ if f$search("EXE.DIR;1") .eqs. "" then -
     CREATE/LOG/DIRECTORY [.EXE]
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X$!
X$!	VI.COM
X$!
X$!	Written by Gregg Wonderly  30-OCT-1986
X$!
X$!  A command file to run VI as a subprocess to the current DCL process.
X$!
X$!	Check to see if the process already exists
X$!
X$		VI = "EDIT/TPU"
X$!   OR VI = "VI" if you are using VI.EXE
X$!
X$		TT = F$GETDVI("SYS$COMMAND","DEVNAM") - "_" - "-" - ":"
X$		EDIT_NAME = "Edit_" + TT
X$		PRIV_LIST = F$SETPRV("NOGROUP,NOWORLD")
X$		PID = 0
X$!
X$	LOOP:
X$		MPID = F$PID(PID)
X$		PROC = F$GETJPI(MPID,"PRCNAM")
X$!
X$! If process is there, then go attach to it
X$!
X$		IF PROC .EQS. EDIT_NAME THEN GOTO ATTACH
X$		IF PID .NE. 0 THEN GOTO LOOP
X$!
X$! If we fall through, then no such process, so spawn the editor
X$!
X$	SPAWN:
X$		PRIV_LIST = F$SETPRV(PRIV_LIST)
X$		DEFINE/NOLOG SYS$INPUT SYS$COMMAND:
X$		T1 = F$EDIT(P2 + " " + P3 + " " + P4 + " " + P5 + " " -
X                    + P6 + " " + P7, "UPCASE,COLLAPSE")
X$		T1 = "''T1' ''P1'"
X$		DEFINE/JOB/NOLOG TPU$ATTACH_NAME "''f$getjpi("","prcnam")'"
X$		DEFINE/JOB/NOLOG TPU$SEARCH " "
X$		DEFINE/JOB/NOLOG TPU$LINE " "
X$		DEFINE/JOB/NOLOG TPU$OUTPUT " "
X$		DEFINE/JOB/NOLOG TPU$ARGS " "
X$		DEFINE/JOB/NOLOG TPU$NEWCMD " "
X$		IF ("''P8'" .EQS. "NOSPAWN") THEN GOTO NOSPAWN
X$			WRITE SYS$ERROR "[Spawning a new kept editor]"
X$			SPAWN/PROCESS="''EDIT_NAME'"/NOLOG VI 'T1'
X$			SUSPEND/NAME="''EDIT_NAME'"
X$			WRITE SYS$ERROR "[Back from edit]"
X$			GOTO DONE
X$!
X$!  Startup the editor without spawning
X$!
X$	NOSPAWN:
X$		WRITE SYS$OUTPUT T1
X$		DEFINE/NOLOG/JOB TPU$NOSUBPROC 1
X$		VI 'T1'
X$		DEASSIGN/JOB TPU$NOSUBPROC
X$		GOTO DONE
X$!
X$! Come here if subprocess already exists.
X$!
X$	ATTACH:
X$!
X$!	For the attach, we allow some parameters to be passed to the editor,
X$!  other than the filename.  Specifically, a string to search for, or
X$!  a line number to go to.
X$!
X$		PRIV_LIST = F$SETPRV(PRIV_LIST)
X$		LINENO = " "
X$		SEARCH = " "
X$		OUTPUT = " "
X$		NEWCMD = " "
X$		LIST== F$EDIT ("''P1' ''P2' ''P3' ''P4' ''P5' ''P6' ''P7'", -
V									
X			"UPCASE,TRIM,COMPRESS")
X$ 		START = F$LOCATE ("/OUT", LIST)
X$ 		IF (START .EQ. F$LENGTH(LIST)) THEN GOTO NOOUT
X$			REMAIN = F$EXTRACT (START,255,LIST)
X$			END = F$LOCATE ("=", REMAIN)
X$			IF (END .NE. F$LENGTH (REMAIN)) THEN GOTO OUT_1
X$				WRITE SYS$ERROR F$MESSAGE(%X38150)
X$				WRITE SYS$ERROR " \OUTPUT\"
X$				EXIT
X$!
X$		OUT_1:
V$			OUTPUT=F$EXTRACT(END+1,F$LOCATE(" ",REMAIN)-END-1,REMAI
XN)
X$			LIST = F$EXTRACT (0,START,LIST) + -
V					F$EXTRACT(END+2+F$LENGTH(OUTPUT),255,RE
XMAIN)
X$!
X$	NOOUT:
X$		IF (F$EXTRACT(0,1,P1) .NES. "+") THEN GOTO NO_LINE
X$			IF (F$EXTRACT(1,1,P1) .NES. "/") .AND. -
V					(F$EXTRACT(1,1,P1) .NES. "?") THEN GOTO
X NO_SEARCH
X$				SEARCH = F$EXTRACT (1,255,P1)
X$				P1=" "
X$				GOTO NO_ALTS
X$!
X$	NO_SEARCH:     
X$		IF (F$EXTRACT(1,1,P1) .NES. "$") THEN GOTO NO_CMD
X$			NEWCMD = F$EXTRACT (2,255,P1)
X$			P1=" "
X$			GOTO NO_ALTS
X$	NO_CMD:
X$		LINENO = F$EXTRACT (1,255,P1)
X$		p1=""
X$!
X$	NO_ALTS:
X$		LIST== F$EDIT ("''P2' ''P3' ''P4' ''P5' ''P6' ''P7'", -
V									"UPCASE
X,COMPRESS,TRIM")
X$	NO_LINE:
X$!
X$!  Parameters are passed through the JOB logical table.
X$!
X$		DEFINE/JOB/NOLOG TPU$SEARCH "''SEARCH'"
X$		DEFINE/JOB/NOLOG TPU$LINE "''LINENO'"
X$		DEFINE/JOB/NOLOG TPU$OUTPUT "''OUTPUT'"
X$		DEFINE/JOB/NOLOG TPU$ARGS " ''LIST'"
X$		DEFINE/JOB/NOLOG TPU$NEWCMD "''NEWCMD'"
X$		DEFINE/JOB/NOLOG TPU$ATTACH_NAME "''f$getjpi("","prcnam")'"
X$!
X$!  Restore all prior privileges.
X$!
X$		WRITE SYS$ERROR "[Attaching to editor]"
X$		DEFINE/NOLOG SYS$INPUT SYS$COMMAND:
X$		RESUME/NAME="''EDIT_NAME'"
X$		ATTACH "''EDIT_NAME'"
X$		WRITE SYS$ERROR "[Back from edit]"
X$		SUSPEND/NAME="''EDIT_NAME'"
X$!
X$!  Exit the editor, deleting the journal files.
X$!
X$   DONE:
X$		DEASSIGN/JOB TPU$ATTACH_NAME
X$		DEASSIGN/JOB TPU$SEARCH
X$		DEASSIGN/JOB TPU$LINE
X$		DEASSIGN/JOB TPU$OUTPUT
X$		DEASSIGN/JOB TPU$ARGS
X$		DEASSIGN/JOB TPU$NEWCMD
X$		EXIT
$ GoSub Convert_File
$ File_is="[.EXE]VISETUP.COM"
$ Check_Sum_is=729501141
$ if f$search("EXE.DIR;1") .eqs. "" then -
     CREATE/LOG/DIRECTORY [.EXE]
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X$ !
X$ !	VISETUP.COM  -  Set up to use the VI TPU interface.
X$ !
X$ !  Written by Gregg Wonderly JUN-30-1987
X$ !
X$ DEFINE/NOLOG/TRANS=CONCEAL 	VI$ROOT	MATH0:[PUBLIC.VI.]
X$ DEFINE TPUSECINI				VI$ROOT:[EXE]VI.GBL
X$ DEFINE TPU$CALLUSER			VI$ROOT:[EXE]TPUSUBS.EXE
X$ DEFINE/NOLOG VISECINI			VI$ROOT:[EXE]VI.GBL
X$ DEFINE/NOLOG VI$CALLUSER		VI$ROOT:[EXE]TPUSUBS.EXE
X$ DEFINE/NOLOG MAIL$EDIT		VI$ROOT:[EXE]MAILEDIT.COM
X$!
X$! This symbol gets you a NON-SPAWNED VI
X$! Delete this if you are using VI.EXE and VI.CLD
X$!
X$ VI ==							"EDIT/TPU"
X$! This symbol gets you a SPAWNED VI
X$ VIS ==						"@VI$ROOT:[EXE]VI.COM"
X$!
X$! This gets you a readonly version of the file.
X$!
X$ IF F$TYPE (VI) .EQS. "" THEN VI="VI"
X$ VIEW == "''VI'/READONLY"
X$ EXIT
$ GoSub Convert_File
$ Exit
