From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 23-AUG-1990 23:02:55.17
To:	MRGATE::"ARISIA::EVERHART"
CC:	
Subj:	Re: Dcl command editor

Received:  by crdgw1.ge.com (5.57/GE 1.70)
	 id AA15383; Thu, 23 Aug 90 22:47:40 EDT
Received: From DANPOST.UNI-C.DK by CRVAX.SRI.COM with TCP; Thu, 23 AUG 90 14:37:19 PDT
Received: from vms2.uni-c.dk by danpost.uni-c.dk (5.61/4.7)
	id AA04630; Thu, 23 Aug 90 21:31:49 GMT
Date: Thu, 23 Aug 90 23:34 +0200
From: ISIS08@ecostat.aau.dk
Subject: Re: Dcl command editor
To: INFO-VAX@SRI.COM, REGY106@CANTERBURY.AC.NZ
Message-Id: <45A71E5A1CDF20FB0B@vms2.uni-c.dk>
X-Envelope-To: REGY106@CANTERBURY.AC.NZ, INFO-VAX@SRI.COM
X-Vms-To: IN::"INFO-VAX@SRI.COM"
X-Vms-Cc: IN::"REGY106@CANTERBURY.AC.NZ"

> Hi,
> 
> 	I am looking for a command editor.  I want to edit DCL commands.
> 
> 	In some of the layered products such as RDO and DTR you can go:
> 		edit 2
> 	This puts you into an editor with your last 2 commands.  You can
> then change those commands.  When you exit the 2 commands are re-executed.
> 
> 	I want to be able to do this from the $ prompt.  It would be useful
> when I have long commands which I want to change just slightly.

This is a good example of a question, which seems to be simple, but have
some tricky aspects.

First try was to use RECALL/ALL and redirect output to a file.
But RECALL does not work inside a COM-file. 

Now I was getting a little stubborn, so I made a program, which reads
from the RECALL-buffer, writes the commands to a file, edits that file
and execute that file. It is defined as a foreign command and called
as "DCLEDIT 3", if you want to edit the last 3 commands.

The program is following as a VMS_SHARE file (only 146 lines). It is not
completely finished, but it illustrates the idea. Feel free to use it
and modify it to your needs. Plese send me a copy, if you find some
genious ideas of how to improve it.

                                                               Arne

Arne Vajhxj                             Internet: ISIS08@ECOSTAT.AAU.DK
Institute of Economics and Statistics   PSI:      DATAPAX.23830211371400::ISIS08
Aarhus University
Denmark

------------------------------------------------------------------------------
$! ------------------ CUT HERE -----------------------
$ v='f$verify(f$trnlnm("SHARE_VERIFY"))'
$!
$! This archive created by VMS_SHARE Version 7.2-007  22-FEB-1990
$!   On 23-AUG-1990 23:15:22.40   By user ISIS08 
$!
$! This VMS_SHARE Written by:
$!    Andy Harper, Kings College London UK
$!
$! Acknowledgements to:
$!    James Gray       - Original VMS_SHARE
$!    Michael Bednarek - Original Concept and implementation
$!
$! TO UNPACK THIS SHARE FILE, CONCATENATE ALL PARTS IN ORDER
$! AND EXECUTE AS A COMMAND PROCEDURE  (  @name  )
$!
$! THE FOLLOWING FILE(S) WILL BE CREATED AFTER UNPACKING:
$!       1. BUILD.COM;1
$!       2. DCLEDIT.FOR;1
$!       3. GETCMD.MAR;1
$!
$set="set"
$set symbol/scope=(nolocal,noglobal)
$f=f$parse("SHARE_TEMP","SYS$SCRATCH:.TMP_"+f$getjpi("","PID"))
$e="write sys$error  ""%UNPACK"", "
$w="write sys$output ""%UNPACK"", "
$ if f$trnlnm("SHARE_LOG") then $ w = "!"
$ ve=f$getsyi("version")
$ if ve-f$extract(0,1,ve) .ges. "4.4" then $ goto START
$ e "-E-OLDVER, Must run at least VMS 4.4"
$ v=f$verify(v)
$ exit 44
$UNPACK: SUBROUTINE ! P1=filename, P2=checksum
$ if f$search(P1) .eqs. "" then $ goto file_absent
$ e "-W-EXISTS, File ''P1' exists. Skipped."
$ delete 'f'*
$ exit
$file_absent:
$ if f$parse(P1) .nes. "" then $ goto dirok
$ dn=f$parse(P1,,,"DIRECTORY")
$ w "-I-CREDIR, Creating directory ''dn'."
$ create/dir 'dn'
$ if $status then $ goto dirok
$ e "-E-CREDIRFAIL, Unable to create ''dn'. File skipped."
$ delete 'f'*
$ exit
$dirok:
$ w "-I-PROCESS, Processing file ''P1'."
$ if .not. f$verify() then $ define/user sys$output nl:
$ EDIT/TPU/NOSEC/NODIS/COM=SYS$INPUT 'f'/OUT='P1'
PROCEDURE Unpacker ON_ERROR ENDON_ERROR;SET(FACILITY_NAME,"UNPACK");SET(
SUCCESS,OFF);SET(INFORMATIONAL,OFF);f:=GET_INFO(COMMAND_LINE,"file_name");b:=
CREATE_BUFFER(f,f);p:=SPAN(" ")@r&LINE_END;POSITION(BEGINNING_OF(b));
LOOP EXITIF SEARCH(p,FORWARD)=0;POSITION(r);ERASE(r);ENDLOOP;POSITION(
BEGINNING_OF(b));g:=0;LOOP EXITIF MARK(NONE)=END_OF(b);x:=ERASE_CHARACTER(1);
IF g=0 THEN IF x="X" THEN MOVE_VERTICAL(1);ENDIF;IF x="V" THEN APPEND_LINE;
MOVE_HORIZONTAL(-CURRENT_OFFSET);MOVE_VERTICAL(1);ENDIF;IF x="+" THEN g:=1;
ERASE_LINE;ENDIF;ELSE IF x="-" THEN IF INDEX(CURRENT_LINE,"+-+-+-+-+-+-+-+")=
1 THEN g:=0;ENDIF;ENDIF;ERASE_LINE;ENDIF;ENDLOOP;t:="0123456789ABCDEF";
POSITION(BEGINNING_OF(b));LOOP r:=SEARCH("`",FORWARD);EXITIF r=0;POSITION(r);
ERASE(r);x1:=INDEX(t,ERASE_CHARACTER(1))-1;x2:=INDEX(t,ERASE_CHARACTER(1))-1;
COPY_TEXT(ASCII(16*x1+x2));ENDLOOP;WRITE_FILE(b,GET_INFO(COMMAND_LINE,
"output_file"));ENDPROCEDURE;Unpacker;QUIT;
$ delete/nolog 'f'*
$ CHECKSUM 'P1'
$ IF CHECKSUM$CHECKSUM .eqs. P2 THEN $ EXIT
$ e "-E-CHKSMFAIL, Checksum of ''P1' failed."
$ ENDSUBROUTINE
$START:
$ create 'f'
X$ fortran dcledit
X$ macro getcmd
X$ link dcledit+getcmd
X$ dcledit:==$sys$disk:`5B`5Ddcledit
X$ exit
$ CALL UNPACK BUILD.COM;1 846991917
$ create 'f'
X      PROGRAM DCLEDIT
X      INTEGER*4 MAXCMD
X      PARAMETER (MAXCMD=100)
X      CHARACTER*11 COMFIL
X      PARAMETER (COMFIL='DCLEDIT.COM')
X      INTEGER*4 LCMD(MAXCMD),NCMD,L,N,I
X      CHARACTER*16 K
X      CHARACTER*256 CMD(MAXCMD)
X      CALL LIB$GET_FOREIGN(K,'Commands: ',L)
X      READ(K(1:L),*) N
X      CALL GETCMD(CMD,LCMD,NCMD)
X      OPEN(UNIT=1,FILE=COMFIL,STATUS='NEW')
X      DO 100 I=1+N,2,-1
X        WRITE(1,'(A<2+LCMD(I)>)') '$ '//CMD(I)(1:LCMD(I))
X100   CONTINUE
X      WRITE(1,'(A22)') '$ delete '//COMFIL//';*'
X      CLOSE(UNIT=1)
X      CALL EDT$EDIT(COMFIL)
X      CALL LIB$DO_COMMAND('@'//COMFIL)
X      END
$ CALL UNPACK DCLEDIT.FOR;1 374479973
$ create 'f'
X        .title  getcmd
X        .link   "sys$system:sys.stb"/selective_search
X        .link   "sys$system:dcldef.stb"/selective_search
X        .psect  $LOCAL long,pic,con,lcl,noshr,noexe,wrt
XPRC_C_CMDBUFSIZ=1025
Xbuf1:   .blkb   PRC_C_CMDBUFSIZ
Xbuf2:   .blkb   PRC_C_CMDBUFSIZ
X        .psect  $CODE long,pic,con,lcl,shr,exe,nowrt
X        .entry  getcmd,`5Em<iv,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11>
X        movl    B`5E4(ap),r11
X        cvtwl   (r11),r8
X        movl    B`5E4(r11),r11
X        movl    B`5E8(ap),r10
X        movl    #0,r9
X        movl    #CTL$AG_CLIDATA,r0
X        movl    W`5EPPD$L_PRC(r0),r0
X        movl    W`5EPRC_L_RECALLPTR(r0),r7
X        moval   W`5EPRC_G_COMMANDS(r0),r0
X        subl2   r0,r7
X        moval   buf1,r1
X        movc3   #PRC_C_CMDBUFSIZ,(r0),(r1)
X        moval   buf1,r1
X        moval   buf2,r2
X        movc3   #PRC_C_CMDBUFSIZ,(r1),(r2)
X        moval   buf2,r6
X        addl2   r6,r7
X        subl3   #PRC_C_CMDBUFSIZ,r7,r6
X100$:   decl    r7
X        cmpl    r7,r6
X        blss    200$
X        tstb    (r7)
X        bleq    200$
X        cvtbl   (r7),(r10)
X        subl2   (r10),r7
X        movc3   (r10),(r7),(r11)
X        decl    r7
X        decl    r7
X        addl2   #4,r10
X        addl2   r8,r11
X        incl    r9
X        brb     100$
X200$:   movl    r9,@B`5E12(ap)
X        ret
X        .end
$ CALL UNPACK GETCMD.MAR;1 573900894
$ v=f$verify(v)
$ EXIT

