From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 12-DEC-1989 11:51
To:	MRGATE::"ARISIA::EVERHART"
Subj:	Retrieve, part 2 of 5

Received: From NAC.NO by GIZMO.SRI.COM with TCP; Tue, 12 DEC 89 07:24:39 PDT
Received: from runix.runit.sintef.no by nac.no (5.61++/1.15) with SMTP 
	id AA14293; Tue, 12 Dec 89 16:22:29 +0100
Received: by runix.runit.sintef.no (norunix.EARN) (1.2/7.8)
	id AA19851;  Tue, 12 Dec 89 16:23:11 +0100
Date: 12 Dec 89 16:22 +0100
From: Jo Torsmyr <j_torsmyr%avh.unit.uninett@nac.no>
To: info-vax@kl.sri.com
Message-Id: <228*j_torsmyr@avh.unit.uninett>
Subject: Retrieve, part 2 of 5

+-+-+-+ Beginning of part 2 +-+-+-+
X`009call a procedure which must run in executive mode. The argument is
X`009called with the %IMMED mechanism specifier because the procedure (to
X`009be run in executive mode) needs no parameters.
X`009`009`009`009`009`009`009`009`009
X`009One should be very careful when changing the contents of the buffer
X`009and even more careful when changing the contents of the`009pointer to
X`009the buffer!`009`009`009`009`009`009
X`009`009`009`009`009`009`009`009`009
X`009NB: Note that if you use RETRIEVE from a command file, the last command
X`009in the buffer will be deleted because the commandstring which activated
X`009RETRIEVE is not saved by DCL! This isn't critical, but should be
X`009noticed.
X
X`009RETRIEVE, Version 1.0
X`009Extension/changes:
X
X`009No extensions or changes, first working version.
X
X`009RETRIEVE, Version 1.1
X`009Extension/changes:
X
X`0091. Fixed some bugs...
X
X`009RETRIEVE, Version 1.2
X`009Extension/changes:
X`009`009`009`009`009`009`009`009`009
X`0091. DCL prompt installed!
X`009   Due to a macro routine made by an unidentified VAX-hacker.
X
X`009RETRIEVE, Version 2.0
X`009Extension/changes:
X
X`0091. Line editing enabled. May now use arrowkeys to move around in
X`009   the recallbuffer.
X`0092. All I/O is done through (Sys)$QioW (Queue I/O request and Wait).
X`0093. DCL prompt retrieved using PASCAL procedure.
X`032
X`009RETRIEVE, Version 2.1
X`009Extension/changes:
X
X`0091. All WARNING/ERROR messages are displayed without concerning
X`009   the /LOG qualifier.
X
X`009RETRIEVE, Version 2.2
X`009Extension/changes:
X
X`0091. Removed the tests for recall buffer full, because it's never full.
X`009   This is so because the RETRIEVE command is deleted from the recall
X`009   buffer.
X
X`009RETRIEVE, Version 2.3
X`009Extension/changes:
X
X`0091. Address of RECALL pointer incremented by 2048 byte from version
X`009   4.x to version 5.x-y of VMS.
X
X`0092. Added qualifier /ALL (identical to /LIST=ALL) and /ERASE (identical
X`009   to /FLUSH).
X
X
X`009Installation dates for RETRIEVE on AVH's VAX-cluster:
X`009`169 Jo Torsmyr, UNIT AVH
X
X`009------------------------------------------------------------------
X
X`009Retrieve Version 1.0 - finished 22-DEC-1987, installed 22-DEC-1987
X`009Retrieve Version 1.1 - finished 31-DEC-1987, installed 20-JAN-1988
X`009Retrieve Version 1.2 - finished 22-JAN-1988, never installed
X`009Retrieve Version 2.0 - finished  5-AUG-1988, installed 29-SEP-1988
X`009Retrieve Version 2.1 - finished 25-OCT-1988, never installed
X`009Retrieve Version 2.2 - finished 13-NOV-1988, installed  6-DEC-1988
X`009Retrieve Version 2.3 - finished  9-JAN-1989, installed 11-JAN-1989
X
X`009------------------------------------------------------------------
X
XAUTHOR:
X`032
X    Jo Torsmyr, UNIT AVH
X`032
XCREATION DATE:`00930-NOV-1987
X`032
X`032
X`009    C H A N G E   L O G
X`032
X     Date     `124   Name  `124 Description
V--------------+---------+----------------------------------------------------
X---
V 26-JUL-1988  `124   JT    `124  Now using a PASCAL procedure to get the DCL
X prompt.
V--------------+---------+----------------------------------------------------
X---
V 26-JUL-1988  `124   JT    `124  GetCommand substituted by GetPrevCommand (fo
Xr up
V`009      `124`009`009`124  arrow key) and GetNextCommand (for down arrow key
X).
V--------------+---------+----------------------------------------------------
X---
X 26-JUL-1988  `124   JT    `124  Using $QioW for output & input.
V--------------+---------+----------------------------------------------------
X---
V 26-JUL-1988  `124   JT    `124  Added procedure LineEditor to edit command a
Xnd
X`009      `124`009`009`124  control arrow keys.
V--------------+---------+----------------------------------------------------
X---
V 26-JUL-1988  `124   JT    `124  Moved all UNBOUND procedures to the outermos
Xt level
X`009      `124`009`009`124  so that they are automatically UNBOUND.
V--------------+---------+----------------------------------------------------
X---
X 29-JUL-1988  `124   JT    `124  Log is no longer default.
V--------------+---------+----------------------------------------------------
X---
X 29-JUL-1988  `124   JT`009`124  Modified CheckValues.
V--------------+---------+----------------------------------------------------
X---
X 29-JUL-1988  `124   JT    `124  Completed procedure LineEditor.
V--------------+---------+----------------------------------------------------
X---
X  2-AUG-1988  `124   JT    `124  WriteCmds now leaves LogP pointing to NULL.
V--------------+---------+----------------------------------------------------
X---
X  2-AUG-1988  `124   JT    `124  WHILE loop replaced by REPEAT in ListCmds.
V--------------+---------+----------------------------------------------------
X---
V  2-AUG-1988  `124   JT    `124  Fixed bug in ListCmds & RecallCmd, EndOfBuf
X would
X`009`009`009`124  never be TRUE!
V--------------+---------+----------------------------------------------------
X---
V  5-AUG-1988  `124   JT    `124  Fixed bug in InsRetrCmd, now sure that PhysE
XndPointer
X`009`009`009`124  points to the correct byte.
V--------------+---------+----------------------------------------------------
X---
V 25-OCT-1988  `124   JT    `124  WARNING and ERROR messages is displayed with
Xout
X`009      `124`009`009`124  concerning the /LOG qualifier.
V--------------+---------+----------------------------------------------------
X---
V 13-NOV-1988  `124   JT    `124  Removed foolish tests in SkipCommands, ListC
Xmds &
X`009      `124`009`009`124  RecallCmd. The test LogP = LogEndPointer never
X`009      `124`009`009`124  succeeds because the recallbuffer is never full.
X`009      `124`009`009`124  This is because the command which invoked the
X`009      `124`009`009`124  program (RETR/LIS) is deleted!
V--------------+---------+----------------------------------------------------
X---
V  9-JAN-1988  `124   JT    `124  Physical addresses changed due to version 5.
Xx-y of
X`009      `124`009`009`124  VAX/VMS.
V--------------+---------+----------------------------------------------------
X---
X  9-JAN-1988  `124   JT    `124  Added qualifiers /ALL and /ERASE.
V--------------+---------+----------------------------------------------------
X---
X%[change_entry]%
X`125
X`032
X  CONST
X    Pas$K_Success   = 0 ;
X    Pas$K_InvSynInt = 32 ;
X
X    (* Command language interpreter constants *)
X    Cli$_Par1`009    = 'Command' ;
X    Cli$_All`009    = 'All' ;
X    Cli$_Erase`009    = 'Erase' ;
X    Cli$_Flush`009    = 'Flush' ;
X    Cli$_List`009    = 'List' ;
X    Cli$_List_Start = 'Start' ;
X    Cli$_List_End   = 'End' ;
X    Cli$_Log`009    = 'Log' ;
X    Cli$_Restore    = 'Restore' ;
X    Cli$_Save`009    = 'Save' ;
X    Cli$_Verify`009    = 'Verify' ;
X
X    (* Name of terminal *)
X    Terminal`009    = 'Tt:' ;
X
X    (* Logical constants for the recall buffer *)
X    BufferSize`009    = 1024 ;
X    BufferMod`009    = BufferSize + 1 ;
X
X    MaxCmdLen`009    = 251 ; (* 255 - 1 for space - 3 for number *)
X
X    LowByteValue    = 0 ;
X    HighByteValue   = 255 ;
X
X    Null`009    = Chr (0) ;
X
X    (* Static addresses for the recall buffer in virtual memory *)
X
X    (* Pointer to end of last command *)
X    PhysPointerAddr = 2147364107 ;
X    (* Starting address *)
X    PhysStartAddr   = 2147364111 ;
X    (* Ending address *)
X    PhysEndAddr`009    = 2147365135 ;
X
X  TYPE
X    $UBYTE`009    = [BYTE] LowByteValue..HighByteValue ;
X    $UWORD`009    = [WORD] 0..65535 ;
X    BufferInt`009    = 0..BufferSize ;
X    CmdInt`009    = 1..MaxCmdLen ;
X    VarCmdType`009    = VARYING [MaxCmdLen] OF CHAR ;
X    BufferType`009    = ARRAY [BufferInt] OF [UNSAFE] CHAR ;
X
X    RecallRecord    = RECORD
X`009`009`009RecArr`009: BufferType ;
X`009`009`009RecP`009: INTEGER ;
X`009`009      END (* of RECORD *) ;
X
X  VAR
X    (* External "constants" for the message file Ret_Msg.Msg *)
X    RETR_IllPhyVal,`009    (* Illegal physical (RECALL) pointer value *)
X    RETR_IllValRan,`009    (* Illegal list value range *)
X    RETR_NoComFou,`009    (* No commands found *)
X    RETR_TotOfCmds,`009    (* Total of X command(s) *)
X    RETR_CmdNoFou,`009    (* Command XXX not found *)
X    RETR_CmdNumNoFou,`009    (* Command number X not found *)
X    RETR_SavOnFil,`009    (* Commands saved on file XXX *)
X    RETR_ResFroFil,`009    (* Commands restored from file XXX *)
X    RETR_RecBufFlu,`009    (* Recallbuffer flushed *)
X    RETR_ErrDurOpen,`009    (* Error during open... *)
X    RETR_RetrVer`009    : [EXTERNAL, VALUE] UNSIGNED ;
X
X    (* AT (n) => The variable is assumed to reside at the exact address n *)
X
X    (* Pointer to last command (RECALL pointer) *)
X    PhysEndPointer  : [AT (PhysPointerAddr)] INTEGER ;
X
X    (* Address in virtual memory where the saved commands reside *)
X    RecallArray`009    : [AT (PhysStartAddr)] BufferType ;
X
X    (* The 3 next variables are declared global because they are used in *)
X    (* procedures which run in executive mode. *)
X
X    (* The length of the RETRIEVE command which invoked this program *)
X    (* Set in DelRetrCmd. Used in DeleteCommand (Executive mode) *)
X    RetrCmdLen`009    : [UNSAFE] CmdInt ;
X
X    (* Set in LoadCmds. Used in RestoreBuffer (Executive mode) *)
X    LoadPost`009    : RecallRecord ;
X
X    (* Set in Read_Exec_Cmd. Used in InsRetrCmd (executive mode) *)
X    GlobalCmd`009    : VarCmdType ;
X
X    (* String indicating the current version of RETRIEVE *)
X    VersionStr`009    : VarCmdType := 'V2.3' ;
X
X    (* Logical pointer to the end of the buffer. *)
X    LogEndPointer   : BufferInt ;
X    All,`009`009`009    (* ALL qualifier present *)
X    Erase,`009`009`009    (* Erase qualifier present *)
X    Flush,`009`009`009    (* FLUSH qualifier present *)
X    List,`009`009`009    (* LIST qualifier present *)
X    Log,`009`009`009    (* LOG qualifier present *)
X    Restore,`009`009`009    (* RESTORE qualifier present *)
X    Save,`009`009`009    (* Save qualifier present *)
X    Verify`009    : BOOLEAN ;`009    (* VERIFY qualifier present *)
X
X `032
X  PROCEDURE Get_DCL_Prompt (VAR DCL_Prompt : VARYING [A] OF CHAR) ;
X  `032
X      `123
X      FUNCTIONAL DESCRIPTION:`032
X      `032
X`009  Get_DCL_Prompt returns the current DCL prompt for the process.
X`009  Ctl$Ag_CliData is a constant which is found in the file
X`009  Sys$System:Sys.Stb (system table file). It is the address of Cli
X`009  data for the process.
X`009  The prompt address is in offset 628 and its length in offset 624.
X`009  Note that you must lin with Sys.Stb (using /SELECTIVE_SEARCH).
X
X      FORMAL PARAMETERS:`032
X      `032
X`009  DCL_Prompt - the DCL prompt is returned in this string. Maximum
X`009`009       length of a DCL prompt is 32 bytes.
X      `032
X      IMPLICIT INPUTS:
X      `032
X`009  NONE
X      `032
X      IMPLICIT OUTPUTS:
X      `032
X`009  NONE
X      `032
X      ROUTINE VALUE:
X      `032
X`009  NONE
X      `032
X      SIDE EFFECTS:
X      `032
X`009  NONE
X      `125
X  `032
X  `032
X    TYPE
X      PromptString`009= PACKED ARRAY [1..32] OF CHAR ;
X      Len_Pointer`009= `094$UBYTE ;
X      Str_Pointer`009= `094PromptString ;
X    VAR
X      Ctl$Ag_CliData`009: [EXTERNAL, VALUE] UNSIGNED ;
X      Str_Ptr`009`009: Str_Pointer ;
X      Len_Ptr`009`009: Len_Pointer ;
X    BEGIN
X      Len_Ptr`009`009:= (Ctl$Ag_CliData + 624)::Len_Pointer ;
X      Str_Ptr`009`009:= (Ctl$Ag_CliData + 628)::Str_Pointer ;
X      DCL_Prompt.Length`009:= Len_Ptr`094 - 3 ;
X      DCL_Prompt.Body`009:= Str_Ptr`094 ;
X  END (* of PROCEDURE Get_DCL_Prompt *) ;
X
X
X  FUNCTION Inc (VAR LP`009: BufferInt ; Count : INTEGER) : BufferInt ;
X  `032
X      `123
X      FUNCTIONAL DESCRIPTION:`032
X      `032
X`009  Inc is used to increment/decrement the logical pointer to the
X`009  buffer, wraps around if necessary. Legal values are 0-1024.
X`009  This function is used everywhere in the program.`009 `032
X      `032
X      FORMAL PARAMETERS:`032
X      `032
X`009  LP - Contains the updated logical pointer value.
X`009  Count - The increment/decrement value.
X      `032
X      IMPLICIT INPUTS:
X      `032
X`009  NONE
X      `032
X      IMPLICIT OUTPUTS:
X      `032
X`009  NONE
X      `032
X      ROUTINE VALUE:
X      `032
X`009  Returns the updated logical pointer value.
X      `032
X      SIDE EFFECTS:
X      `032
X`009  Updates LP.
X      `125
X  `032
X    BEGIN
X      Lp  := (BufferMod + Lp + Count) MOD BufferMod ;
X      Inc := LP ;
X  END (* of FUNCTION Inc *) ;
X
X
X  PROCEDURE GetPrevCommand (VAR ComStr  : VARYING [A] OF CHAR ;
X`009`009`009    VAR ArrayP  : BufferInt) ;
X  `032
X      `123
X      FUNCTIONAL DESCRIPTION:`032
X      `032
X`009  GetPrevCommand returns the previous command in the buffer. Therefore
X`009  the bufferpointer has to be decremented.
X`009  GetPrecCommand requires that ArrayP points to the command's trailing
X`009  length byte. When finished, ArrayP points to the NULL byte next to
X`009  the command's leading length byte.
X      `032
X`009  Illustration of the movement of the bufferpointer:
X
X`009  -------------------------------------
X`009  ... `124 0 `124 3 `124 D `124 I `124 R `124 3 `124 0 `124 ...
X`009  -------------------------------------
X`009`009`094`009`009    `094
X`009`009ArrayP`009    <---    ArrayP
X
X      FORMAL PARAMETERS:`032
X      `032
X`009  ComStr - Contains the returned commandstring.
X`009  ArrayP - The pointer to the recallbuffer.
X      `032
X      IMPLICIT INPUTS:
X      `032
X`009  RecallArray.
X      `032
X      IMPLICIT OUTPUTS:
X      `032
X`009  NONE
X      `032
X      ROUTINE VALUE:
X      `032
X`009  NONE
X      `032
X      SIDE EFFECTS:
X      `032
X`009  NONE
X      `125
X  `032
X    VAR
X      I`009: CmdInt ;
X    BEGIN
X      ComStr.Length := Ord (RecallArray[ArrayP]) ;
X
X      (* Extract the command from the recallbuffer... *)
X      FOR I := 1 TO ComStr.Length DO
X`009  ComStr[ComStr.Length - I + 1] := RecallArray[Inc (ArrayP, -1)] ;
X
X      (* 1 for the leading count byte, 1 for the NULL byte *)
X      Inc (ArrayP, -2) ;
X  END (* of PROCEDURE GetPrevCommand *) ;
X
X
X  PROCEDURE GetNextCommand (VAR ComStr  : VARYING [A] OF CHAR ;
X`009`009`009    VAR ArrayP  : BufferInt) ;
X
X      `123
X      FUNCTIONAL DESCRIPTION:`032
X      `032
X`009  GetNextCommand returns the next command from the recallbuffer.
X`009  Therefore the bufferpointer has to be incremented.
X`009  GetNextCommand requires that ArrayP points to the command's leading
X`009  length byte. When finished, ArrayP points to the NULL byte next to
X`009  the command's trailing length byte.
X      `032
X`009  Illustration of the movement of the bufferpointer:
X
X`009  -------------------------------------
X`009  ... `124 0 `124 3 `124 D `124 I `124 R `124 3 `124 0 `124 ...
X`009  -------------------------------------
X`009`009    `094`009`009`009`094
X`009`009    ArrayP  --->`009ArrayP
X
X
X      FORMAL PARAMETERS:`032
X      `032
X`009  ComStr - Contains the returned commandstring.
X`009  ArrayP - The pointer to the recallbuffer.
X
X      IMPLICIT INPUTS:
X      `032
-+-+-+-+-+ End of part 2 +-+-+-+-+-

