	.title	k11cm1	overlay for some command dispatching
	.ident	/2.23/

;	16-Oct-84  15:38:31  Brian Nelson
;
;	Creation: 16-Oct-84  15:38:44
;
;
;	Copyright (C) 1983 1984   Change Software, Inc.
;	
;	
;	This software is furnished under a license and may
;	be  used  and  copied  only in accordance with the
;	terms of such license and with  the  inclusion  of
;	the  above copyright notice.  This software or any
;	other copies thereof may not be provided or other-
;	wise made available to any other person.  No title
;	to and ownership of the software is hereby  trans-
;	ferred.
;	
;	The information in this  software  is  subject  to
;	change  without notice and should not be construed
;	as a commitment by the author.
;
;	12-Sep-86  10:39:27 BDN Convert for I/D space



	.if ndf, K11INC
	.ift
	.include	/IN:K11MAC.MAC/
	.include	/IN:K11CDF.MAC/
	.endc

	.enabl	gbl
	.psect
	.psect	$code



	.sbttl	the set command
	.enabl	lsb

;	Note:  For edit /41/ the call to GETPRV for MicroRSX has been
;	placed in ASSDEV, which is ONLY called from SET LINE (SET$LI)


c$set::	$name	<SET>
	call	loaset
	calls	getcm0	,<argbuf,r0>
	mov	r0	,r2
	bmi	110$
	call	loaset
	calls	getcm1	,<argbuf,r0,r2>
	tst	r0
	bmi	110$
	jsr	pc	,@r1
	tst	r0
	beq	100$
	message	<Invalid value for SET>,cr
	inc	status
100$:	return
110$:	message	<Unknown/invalid Set command>,cr
	inc	status
	return


	.dsabl	lsb



	.sbttl	the connect command

c$conn::$name	<CON>
	tst	con$dsp			; /44/ SET [RSX] [CONNECT] done?
	bne	1$			; /44/ Yes
	mov	#doconn	,con$dsp	; /44/ No, insert default routine
1$:	tstb	@argbuf			; anything in the arg buffer?
	beq	5$			; no
	call	set$li			; set the line then
5$:	tst	conesc			; an escape character set ?
	bne	10$			; yes
	movb	#con$esc,conesc		; no, set the default in
10$:	copyz	#ttdial	,#ttname	; insure correct name
	clr	remote			; insure remote flag set
	mov	recdlm	,-(sp)		; /56/ Save RMS record delimiter
	mov	#12	,recdlm		; /56/ Change to write on line feeds
	call	@con$dsp		; /44/ Call the user's choice
	mov	(sp)+	,recdlm		; /56/ Restore put$ trigger char
	message				; a cr/lf
	return				; back to command parser

	GLOBAL	<argbuf,conesc,doconn,remote,ttdial,ttname> ; /44/
	GLOBAL	<con$es,con$ds,set$li>			    ; /44/
	GLOBAL	<recdlm>				    ; /56/




	.sbttl	the local directory and type commands
	.enabl	lsb

c$dir::	$name	<DIR>
	tstb	defdir
	beq	10$
	message	<Current default is >
	print	#defdir
	message
10$:	calls	dodir	,<argbuf,#0>	; get the passed filespec for dir
	tst	r0			; do the directoty. did it work ?
	beq	100$			; yes
	direrr	r0			; no, print the error
100$:	return				; bye

	.dsabl	lsb


c$who::	calls	systat	,<#0>
	return


c$tran::calls	transf	,<argbuf,#0>
	return



	.sbttl	the take command
	.enabl	lsb


c$take::$name	<TAKE>
	sub	#filsiz	,sp		; save current def dir
	mov	sp	,r1		; point to it
	copyz	#defdir	,r1		; done
	tst	cmdlun			; indirect file already open ?
	beq	10$			; no
	tst	sy.ini			; during init from INI file?
	bne	5$			; yes, don't bother with message
	tst	infomsg			; /41/ How verbose are we today?
	beq	5$			; /41/ Not very
	message	<Previous TAKE file closed>,cr
5$:	clr	sy.ini			; not in an init file anymore
	calls	close	,<#lun.ta>	; yes, please close it now
	clr	cmdlun			; assume the next open will fail?

10$:	copyz	#200$	,#defdir	; stuff take defaults in now
	calls	open	,<argbuf,#lun.ta,#text>
	tst	r0			; did the open for command file work?
	bne	90$			; no, print error and exit
20$:	mov	#lun.ta	,cmdlun		; yes, stuff the unit number in
	br	100$			; bye


90$:	direrr	r0			; print a error message and exit
	clr	cmdlun			; force input from KB:

100$:	mov	sp	,r1		; restore old default directory
	copyz	r1	,#defdir	; simple
	add	#filsiz	,sp		; copy def dir save area back
	return				; bye

	.save
	.psect	$PDATA	,D
200$:	.asciz	/SY:*.CMD/
	.even
	.restore
	.dsabl	lsb

	global	<infomsg>



	.sbttl	the SYSTEM command
	.enabl	lsb

c$sys::	$name	<SYS>
	tstb	@argbuf			; need something in ARGBUF
	bne	10$			; oops
	message	<The SYSTEM command requires a command to execute>,cr
	return
10$:	strlen	argbuf			; get the current length so we
	add	argbuf	,r0		; can stuff a carriage return
	movb	#cr	,(r0)+		; and a null in
	clrb	@r0			; all set now
	mov	argbuf	,200$+2
	mov	#200$	,r5		; call the PK driver
	call	runjob			; simple
	tst	r0			; did it work ?
	beq	100$			; yes
	message	<Error from spawning command >
	decout	r0
	message
100$:	message
	return



;	ierr = runjob(buffer,mode,10,timout)
;
;	 All parameters for  RSTS are  used so we can use the
;	generalized PK code used also in MINITAB (C) and TED.
;	For RSX11M/M+, only the first argument is needed.

	.save
	.psect	$PDATA	,D
200$:	.word	4,0,220$,230$,240$	; parameter list
220$:	.word	100305			; internal mode for running on the PK
230$:	.word	10.			; first free logical unit number
240$:	.word	10.			; ten minutes and i kill the PK's job
	.restore
	.dsabl	lsb

	global	<argbuf	,runjob>




c$spac::$name	<SPA>
	sub	#120	,sp		; allocate space for a buffer
	mov	sp	,r1		; point to it
	calls	dskuse	,<r1>		; get the usage string
	print	r1			; print it
	message				; a crlf
	add	#120	,sp		; pop the local buffer
	return				; and exit




	.sbttl	the local type command
	.enabl	lsb
	.save
	.psect	buffer	,rw,d,lcl,rel,con
buffer:	.blkb	1000
	.restore

c$type::$name	<TYP>
	mov	#buffer	,r4		; and point to it of course
	calls	fparse	,<argbuf,r4>	; parse the filename please
	tst	r0			; did the $parse work ok ?
	bne	90$			; no
	print	r4			; yes, print the expanded name out
	message

5$:	clr	r2			; assume file not open
	calls	open	,<argbuf,#lun.in,#text>; try to open passed filename
	tst	r0			; but did the open work out ?
	bne	90$			; no
	com	r2			; flag it as being open please

10$:	tst	cccnt			; control C typed ?
	bne	90$			; yes, abort this
	calls	getrec	,<r4,#lun.in>	; get the next record
	tst	r0			; did it work ?
	bne	90$			; no
20$:	tst	r1			; null record (ie, cr/lf only) ?
	beq	30$			; yep
	print	r4,r1			; dump the record
30$:	message				; a cr/lf
	br	10$			; next record please

90$:	tst	r0			; forced exit ?
	beq	95$			; yes
	cmp	r0	,#ER$EOF	; end of file ?
	beq	95$			; yes, its ok
	direrr	r0			; no, print the error out
95$:	tst	r2			; is the type file open ?
	beq	100$			; no
96$:	calls	close	,<#lun.in>	; yes, please close it up now
100$:	return


	global	<argbuf	,cccnt	,defdir	,ER$EOF	,lun.in>

	.dsabl	lsb


	.sbttl	print command


c$prin::calls	qspool	,<argbuf,#lun.in>
	direrr	r0
	return


	.end
