From:	CSBVAX::MRGATE!info-vax-request@kl.sri.com@SMTP 18-JAN-1988 23:00
To:	ARISIA::EVERHART
Subj:	Re: Getting DCL prompt within program


Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Mon 18 Jan 88 11:28:50-PST
Received: by ucbvax.Berkeley.EDU (5.58/1.26)
	id AA17957; Mon, 18 Jan 88 10:45:20 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: 12 Jan 88 19:13:58 GMT
From: unmvax!nmtsun!hydrovax@ucbvax.Berkeley.EDU  (M. Warner Losh)
Organization: NMT Hydrology program
Subject: Re: Getting DCL prompt within program
Message-Id: <1223@nmtsun.nmt.edu>
References: <248*l_andenes@avh.unit.uninett>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

In article <248*l_andenes@avh.unit.uninett>, l_andenes%avh.unit.uninett@TOR.NTA.NO (Leiv Arild Andenes) writes:
> Hi!
> I wonder if anyone out there could tell me if there exists a system
> (or Run Time Library) routine to get the DCL prompt string.
> 

I would also like to know if there is a sanktioned interface to go
through.  Later in this article I give a method to "get the job done".
I posted a request just before Christmas, and haven't seen a single
responce.

Here is a small snipet of MACRO code that is a subroutine to SET the
prompt.  To set your prompt you need CMKRNL priv, but to read it, you
don't.


A brief explination of the code.  It gets the address of the cli data
space.  This is contained in the memory location CTL$AG_CLIDATA that
is defined SOMEWHERE (don't know exactly where).  Then it dereferences
the address with an offset of PPD$Q_CLIREG+4.  This address is places
into R3.  This gives the PRC block for the process.  Now then, the
prompt is contained in two parts.  The first part is it's length, that
is found in PRC_B_PROMPTLEN (offset from R3).  The actual text can be
no longer than 30 characters (in this implementation) and is contained
at the offset PRC_G_PROMPT.

I know that this explination is a bit scketchy, but I stole the code
from a DECUS tape a few years back (fall 1985 I think) and hacked it
so I could use it for a "SD" command that was written in 'C', that
intelligently set your prompt to the current directory.  So I don't
understand all of the implications of the code.

STANDARD DISCLAIMER ABOUT VMS 5.0 : this may break when you upgrade to
5.0, as it is using structures that I couldn't find in the Orange
Binders.  It may not even work at all.  It seems to work correctly on
VMS 4.4 on a VAXstation II.  There don't appear to be (at least to my
eye) any trojan activity going on.  If you find any, LET ME KNOW ASAP.

--------------*<---------------cut here------------>*------------------

	.LINK	'SYS$SYSTEM:SYS.STB'/SELECTIVE_SEARCH
	.LINK	'SYS$SYSTEM:DCLDEF.STB'/SELECTIVE_SEARCH

	.PSECT	DATA RD, WRT, NOEXE, PIC, LONG

ARGS:	.LONG 2
	.ADDRESS LEN
	.ADDRESS BUFF_PTR_PTR
	            
LEN:	.BYTE 	0
BUFF_PTR_PTR: .LONG 0

	.PSECT	CODE RD,NOWRT,EXE,PIC,LONG

;
; Test.  A routine to attempt to set the prompt of the current process.
;
	LENGTH = 4
	NEWPRMT = 8

	.ENTRY NEW_PROMPT ^M<>
	MOVL	LENGTH(AP), LEN
	MOVL	NEWPRMT(AP), BUFF_PTR_PTR
	$CMKRNL_S ROUTIN=SET_PROMPT, ARGLST=ARGS
	$EXIT_S R0
	RET

	.ENTRY SET_PROMPT	^M<R3>
	PUSHR	#^M<R4, R5>
	MOVAB	G^CTL$AG_CLIDATA, R3		; Get cli data space.
	MOVL	PPD$Q_CLIREG+4(R3), R3		; Get address of proc work area
	MOVL	LENGTH(AP), R0			; New prompt length ptr.
	MOVB	(R0), R0			; New prompt length.
	ADDB3	#3, R0, PRC_B_PROMPTLEN(R3)	; Store new prompt length.
	MOVL	NEWPRMT(AP), R1			; Pointer to new prompt.
	MOVL	(R1), R1
	MOVC5	R0, (R1), #32, #32, PRC_G_PROMPT(R3) ; Store new prompt.
	POPR	#^M<R4, R5>
	MOVZWL	#SS$_NORMAL, R0			; Normal exit.
	RET

	.END
--------------*<---------------cut here------------>*------------------

-- 
bitnet:	lush@nmt.csnet			M. Warner Losh
csnet:	warner%hydrovax@nmtsun
uucp:	...{cmcl2, ihnp4}!lanl!unmvax!nmtsun!warner%hydrovax
	...{cmcl2, ihnp4}!lanl!unmvax!nmtsun!hydrovax
Warning:  Hydrovax is both a machine, and an account, so be careful.
