***************************************************************************************
* Directory Opus 5 ARexx Routines						      *
***************************************************************************************

;=====================================================================================;
; Directory Opus 5 Subroutines.							      ;
;=====================================================================================;
;DO5_GetSource	; Get first source handle.
;DO5_GetSource_OnlyToBuffer
;DO5_GetDest	; Get first destination handle.
;DO5_GetDest_OnlyToBuffer
;DO5_GetPath	; Get the path of a lister.
;DO5_GetFSelDir	; Get first selected directory in a lister.
;DO5_GetFSelEnt	; Get first selected entry in a lister.
;DO5_SetPath	; Set (read) a new path into a lister.
;DO5_Refesh	; Refresh a lister.
;DO5_Select	; (De)select a lister entry.
;DO5_NewLister	; Open a new lister.
;DO5_ListerSet	; Generic "Lister Set..." routine.
;DO5_Command	; Generic "command..." routine.
;DO5_GenError	; Error message for things which really shouldn't go wrong.
;DO5_ListerWait	; Wait for a lister to finish what it's doing.
;DO5_DOpusFront	; Move the DOpus screen to the front, unless "NoFront/S"
;DO5_ListClose	; Close a lister (does "wait" first).
;	Include	ASM:Source/Routines/DOpus5_ARexx.s



	IFD	DO5_GetSource
*= Get Source Handle =**************************************************= 9-Sep-1995 =*
*  Inputs: Source_Handle(a5) - Buffer of length #Source_HandleLen.w bytes.	      *
*	   d0 - #0 = Error message and abort if no lister.			      *
*	        #1 = Open a new source lister if there isn't one.		      *
*	   Buffer2(a5) - May be used as temp storage.				      *
* Outputs: Source_Handle(a5) - Contains ONE ASCII source handle.		      *
*   Notes: Buffer Overflow will cause program to abort.				      *
*= Get Source Handle To Buffer =****************************************= 9-Sep-1995 =*
*  Inputs: (a1) - Buffer to write source handle into.				      *
*	   d7.w - Size of buffer.						      *
***************************************************************************************
	IFND	DO5_GetSource_OnlyToBuffer
GetSourceHandle
	Lea	Source_Handle(a5),a1
	Move.w	#Source_HandleLen,d7
	ENDC
GetSourceHandle_ToBuffer
	Movem.l	a1/d7,-(SP)			Preserve buffer/size to write into.
	Lea	Get_Source_Command(pc),a1	Get string of source handle(s)
	Move.l	d0,-(SP)		Preserve opennew-switch
	Bsr	FillAndSendNudelRexxMsg	Send it off.
	Move.l	(SP)+,d0		Restore opennew-switch

	Move.l	NudelRexxMsg(a5),a0	-.
	Tst.l	rm_Result1(a0)		 |- If RC != 0, "No source lister"
	Bne.s	No_Source_Error		-'
	Tst.l	rm_Result2(a0)		-._ Also, make sure we got a
	Beq.s	No_Source_Error		-'  string in Result2.

;;;;;;;	Note: Opus puts a space after the first handle, even if there is only one.
;;;;;;; Note: We must copy the rm_Result2 field, as it may not be modified and cannot
;;;;;;;       be used after another RexxMsg has been sent.
	Move.l	rm_Result2(a0),a0	Returned string of lister handles to a0.
	Move.b	#" ",d0			End copy on a space (after 1st handle).
	Movem.l	(SP)+,a1/d7		Restore buffer/size to write into.
	Bra	CopyChr_Null		Copy null-term until space.
;;;;;;;	RTS for us.

;;;;;;;	Buffer_Overflow and null-termination handled automatically.
;;;;;;;	Now we have _one_ source handle, null-terminated, in Source_Handle(a5).
;-------------------------------------------------------------------------------------;
No_Source_Error
	Tst.l	d0
	Beq.s	No_Source_Error_Error	If OpenNew switch off, send error msg.
	BTst	#SF1_NewListers,STD_F_1(a5)
	Beq.s	No_Source_Error_Error	If OpenNew not allowed, send error msg.

	Cmpi.l	#1,d0			-._ Internal error if didn't
	Bne	Internal		-'  get either #0 or #1.

	Movem.l	(SP)+,a2/d7		Restore buffer/size to write into.
;;;;;;;	Note: Buffer pointer is in a2 now, as required, not a1.
	Move.l	a2,-(SP)		Save it again.
	Sub.l	a0,a0			No path.
	Move.l	a0,a1			Default size.
	Bsr	NewLister		Open new lister

	Move.l	(SP)+,a0		Lister Handle -> (a0).
	Lea	Set_Source_SubCommand(pc),a1	"Source"
	Sub.l	a2,a2			No second argument.
	Bra	ListerSet		lister set source.
;;;;;;;	RTS for us.
;-------------------------------------------------------------------------------------;
No_Source_Error_Error
	BSet	#SF1_ErrorDop,STD_F_1(a5)	Send next error message to DOpus5-req.
	Moveq	#0,d1				-._ No string returned
	N_CallDOS	SetIoErr		-'  by Fault().
	Bra_ErrorE	ErrAct_NoSource(pc),#0
;-------------------------------------------------------------------------------------;
Get_Source_Command
	Dc.b	"lister query source",0
ErrAct_NoSource
	Dc.b	"You must have a SOURCE lister!",0
	Even
	ENDC


	IFD	DO5_GetDest
*= Get Dest Handle =****************************************************= 9-Sep-1995 =*
*  Inputs: Dest_Handle(a5) - Buffer of length #Dest_HandleLen.w bytes.		      *
*	   d0 - #0 = Error message and abort if no lister.			      *
*	        #1 = Open a new destination lister if there isn't one.		      *
*	   Buffer2(a5) - May be used as temp storage.				      *
* Outputs: Dest_Handle(a5) - Contains ONE ASCII dest handle.			      *
*   Notes: Buffer Overflow will cause program to abort.				      *
*= Get Dest Handle To Buffer =******************************************= 9-Sep-1995 =*
*  Inputs: (a1) - Buffer to write dest handle into.				      *
*	          DO NOT USE Buffer2(a5)!					      *
*	   d7.w - Size of buffer.						      *
***************************************************************************************
	IFND	DO5_GetDest_OnlyToBuffer
GetDestHandle
	Lea	Dest_Handle(a5),a1
	Move.w	#Dest_HandleLen,d7
	ENDC
GetDestHandle_ToBuffer
	Movem.l	a1/d7,-(SP)			Preserve buffer/size to write into.
	Lea	Get_Dest_Command(pc),a1	Get string of dest handle(s)
	Move.l	d0,-(SP)		Preserve opennew-switch
	Bsr	FillAndSendNudelRexxMsg	Send it off.
	Move.l	(SP)+,d0		Restore opennew-switch

	Move.l	NudelRexxMsg(a5),a0	-.
	Tst.l	rm_Result1(a0)		 |- If RC != 0, "No dest lister"
	Bne.s	No_Dest_Error		-'
	Tst.l	rm_Result2(a0)		-._ Also, make sure we got a
	Beq.s	No_Dest_Error		-'  string in Result2.
	Move.l	rm_Result2(a0),a0	Returned string of lister handles to a0.
	Move.b	#" ",d0			End copy on a space (after 1st handle).
	Movem.l	(SP)+,a1/d7		Restore buffer/size to write into.
	Bra	CopyChr_Null		Copy null-term until space.
;;;;;;;	RTS for us.
;-------------------------------------------------------------------------------------;
No_Dest_Error
	Tst.l	d0
	Beq.s	No_Dest_Error_Error	If OpenNew switch off, send error msg.
	BTst	#SF1_NewListers,STD_F_1(a5)
	Beq.s	No_Dest_Error_Error	If OpenNew not allowed, send error msg.

	Cmpi.l	#1,d0			-._ Internal error if didn't
	Bne	Internal		-'  get either #0 or #1.

	Movem.l	(SP)+,a2/d7		Restore buffer/size to write into.
;;;;;;;	Note: Buffer pointer is in a2 now, as required, not a1.
	Move.l	a2,-(SP)		Save it again.
	Sub.l	a0,a0			No path.
	Move.l	a0,a1			Default size.
	Bsr	NewLister		Open new lister

	Move.l	(SP)+,a0		Lister Handle -> (a0).
	Lea	Set_Dest_SubCommand(pc),a1	"Dest"
	Sub.l	a2,a2			No second argument.
	Bra	ListerSet		lister set dest.
;;;;;;;	RTS for us.
;-------------------------------------------------------------------------------------;
No_Dest_Error_Error
	BSet	#SF1_ErrorDop,STD_F_1(a5)	Send next error message to DOpus5-req.
	Moveq	#0,d1				-._ No string returned
	N_CallDOS	SetIoErr		-'  by Fault().
	Bra_ErrorE	ErrAct_NoDest(pc),#0
;-------------------------------------------------------------------------------------;
Get_Dest_Command
	Dc.b	"lister query dest",0
ErrAct_NoDest
	Dc.b	"You must have a DESTINATION lister!",0
	Even
	ENDC


	IFD	DO5_GetPath
*= Get Lister Path =***************************************************= 16-Aug-1995 =*
*  Inputs: Buffer2(a5) - Temporary storage.					      *
*          (a0) - Handle to get path of.					      *
*          (a1) - Buffer to write path into.					      *
*                 (CAN be Buffer2(a5))						      *
*          d7.w - Length of (a1) buffer.					      *
* Outputs: Buffer contains path string.						      *
*   Notes: Buffer Overflow will cause program to abort.				      *
***************************************************************************************
GetListerPath
	Movem.l	a1/d7,-(SP)			Preserve final output buffer/size.

	Move.l	a0,RDF_1_Long(a5)		String ptr to data array for RawDoFmt()

	Lea	Get_Path_Command(pc),a0		Input string.
	Lea	RDF_Array(a5),a1		DataArray
	Lea	Buffer2(a5),a3			-._ Output
	Move.l	a3,RDF_Adrs(a5)			-'  Buffer
	Move.l	#Buffer2Len,RDF_Size(a5)	Size of output buffer.
	Bsr	NudelRawDoFmt

	Lea	Buffer2(a5),a1		-._ Lister path
	Bsr	FillAndSendNudelRexxMsg	-'  -> rm_Result2

	Move.l	NudelRexxMsg(a5),a0
	Tst.l	rm_Result1(a0)
	Bne.s	No_Lister_Path_Error
	Tst.l	rm_Result2(a0)
	Beq.s	No_Lister_Path_Error

;;;;;;;	Must not use Buffer2(a5) from here on.
	Movem.l	(SP)+,a1/d7			Restore final output buffer/size.

	Move.l	rm_Result2(a0),a0		(a0) - Lister path to be copied.
;;;;;;;	Move.l	a1,a1				Dest buffer
;;;;;;;	Move.w	d7,d7				Size of dest buffer.
	Bsr	CopyCNT				Copy it, including the null.
	Cmpi.w	#-1,d7				-._ Abort program on
	Beq	Buffer_Overflow			-'  Buffer Overflow.
	RTS
;-------------------------------------------------------------------------------------;
No_Lister_Path_Error
	BSet	#SF1_ErrorDop,STD_F_1(a5)	Send next error message to DOpus5-req.
	Moveq	#0,d1				-._ No string returned
	N_CallDOS	SetIoErr		-'  by Fault().
	Bra_ErrorE	ErrAct_GetListerPath(pc),#0
;-------------------------------------------------------------------------------------;
Get_Path_Command
	Dc.b	"lister query %s path",0
ErrAct_GetListerPath
	Dc.b	"Couldn't get lister path",0
	Even
	ENDC



	IFD	DO5_GetFSelDir
*= Get First Selected Directory Path =*********************************= 18-Aug-1995 =*
*  Inputs: Buffer2(a5) - Temporary storage.					      *
*          (a0) - Handle to get first-sel-dir from.				      *
*          (a1) - Buffer to write into.						      *
*                 (CAN be Buffer2(a5))						      *
*          d7.w - Length of (a1) buffer.					      *
* Outputs: Buffer contains dirname string (quotes stripped).			      *
*   Notes: Buffer Overflow will cause program to abort.				      *
***************************************************************************************
GetFirstSelDir
	Movem.l	a1/d7,-(SP)			Preserve final output buffer/size.

	Move.l	a0,RDF_1_Long(a5)		String ptr to data array for RawDoFmt()

	Lea	Get_SelDirs_Command(pc),a0	Input string.
	Lea	RDF_Array(a5),a1		DataArray
	Lea	Buffer2(a5),a3			-._ Output
	Move.l	a3,RDF_Adrs(a5)			-'  Buffer
	Move.l	#Buffer2Len,RDF_Size(a5)	Size of output buffer.
	Bsr	NudelRawDoFmt

	Lea	Buffer2(a5),a1		-._ List of selected dir(s)
	Bsr	FillAndSendNudelRexxMsg	-'  -> rm_Result2

	Move.l	NudelRexxMsg(a5),a0
	Tst.l	rm_Result1(a0)
	Bne.s	No_SelDirs
	Tst.l	rm_Result2(a0)
	Beq.s	No_SelDirs

;;;;;;;	Must not use Buffer2(a5) from here on.
	Movem.l	(SP)+,a1/d7			Restore final output buffer/size.

	Move.l	rm_Result2(a0),a0		(a0) - Directory name(s)
;;;;;;;	Move.l	a1,a1				Dest buffer
;;;;;;;	Move.w	d7,d7				Size of dest buffer.
	Cmpi.b	#'"',(a0)+			Skip past the first quote.
	Bne.s	No_SelDirs			Error if no quote.
	Move.b	#'"',d0			End copy at second quote.
	Bra	CopyChr_Null		Copy null-term until quote.
;;;;;;;	Buffer_Overflow handled automatically.
;;;;;;;	RTS for us.
;-------------------------------------------------------------------------------------;
No_SelDirs
	BSet	#SF1_ErrorDop,STD_F_1(a5)	Send next error message to DOpus5-req.
	Moveq	#0,d1				-._ No string returned
	N_CallDOS	SetIoErr		-'  by Fault().
	Bra_ErrorE	ErrAct_GetSelDirs(pc),#0
;-------------------------------------------------------------------------------------;
Get_SelDirs_Command
	Dc.b	"lister query %s seldirs",0
ErrAct_GetSelDirs
	Dc.b	"No selected directory",0
	Even
	ENDC


	IFD	DO5_GetFSelEnt
*= Get First Selected Entry =******************************************= 27-Aug-1995 =*
*  Inputs: Buffer2(a5) - Temporary storage.					      *
*          (a0) - Handle to get first-sel-entry from.				      *
*          (a1) - Buffer to write into.						      *
*                 (CAN be Buffer2(a5))						      *
*          d7.w - Length of (a1) buffer.					      *
* Outputs: Buffer contains entry-name string (quotes stripped).			      *
*   Notes: Buffer Overflow will cause program to abort.				      *
***************************************************************************************
GetFirstSelEntry
	Movem.l	a1/d7,-(SP)			Preserve final output buffer/size.

	Move.l	a0,RDF_1_Long(a5)		String ptr to data array for RawDoFmt()

	Lea	Get_FSelEnt_Command(pc),a0	Input string.
	Lea	RDF_Array(a5),a1		DataArray
	Lea	Buffer2(a5),a3			-._ Output
	Move.l	a3,RDF_Adrs(a5)			-'  Buffer
	Move.l	#Buffer2Len,RDF_Size(a5)	Size of output buffer.
	Bsr	NudelRawDoFmt

	Lea	Buffer2(a5),a1		-._ Name of FIRST selected entry
	Bsr	FillAndSendNudelRexxMsg	-'  -> rm_Result2

	Move.l	NudelRexxMsg(a5),a0
	Tst.l	rm_Result1(a0)
	Bne.s	No_SelEnt
	Tst.l	rm_Result2(a0)
	Beq.s	No_SelEnt

;;;;;;;	Must not use Buffer2(a5) from here on.
	Movem.l	(SP)+,a1/d7			Restore final output buffer/size.

	Move.l	rm_Result2(a0),a0		(a0) - Entry name
;;;;;;;	Move.l	a1,a1				Dest buffer
;;;;;;;	Move.w	d7,d7				Size of dest buffer.
	Cmpi.b	#'"',(a0)+			Skip past the first quote.
	Bne.s	No_SelEnt			Error if no quote.
	Move.b	#'"',d0			End copy at second quote.
	Bra	CopyChr_Null		Copy null-term until quote.
;;;;;;;	Buffer_Overflow handled automatically.
;;;;;;;	RTS for us.
;-------------------------------------------------------------------------------------;
No_SelEnt
	BSet	#SF1_ErrorDop,STD_F_1(a5)	Send next error message to DOpus5-req.
	Moveq	#0,d1				-._ No string returned
	N_CallDOS	SetIoErr		-'  by Fault().
	Bra_ErrorE	ErrAct_GetSelEnt(pc),#0
;-------------------------------------------------------------------------------------;
Get_FSelEnt_Command
	Dc.b	"lister query %s firstsel",0
ErrAct_GetSelEnt
	Dc.b	"No selected entry",0
	Even
	ENDC


	IFD	DO5_SetPath
*= Read Lister Path =**************************************************= 24-Sep-1995 =*
*  Inputs: Buffer2(a5) - Temporary storage.					      *
*	   (a0) - Lister handle.						      *
*	   (a1) - Path to read.							      *
*	    d0  - #0 = Normal, #1 = "Force" option added.			      *
* Outputs: Lister reads the new path.						      *
*   Notes: The path is not checked for validity, however DOpus handles this for us.   *
***************************************************************************************
ReadListerPath
	Move.l	a0,RDF_1_Long(a5)		Lister handle.
	Move.l	a0,-(SP)			Preserve lister handle.
	Move.l	a1,RDF_2_Long(a5)		Path to read.

	Move.l	d0,RDF_3_Long(a5)		Clear it, if null.
	Beq.s	ReadListerPath_S1		If null, leave it cleared (no "force").
	Cmpi.l	#1,d0				-._ Internal error if
	Bne	Internal			-'  not #0 or #1.
	Lea	Force_SubCommand(pc),a0		-._ Else, append " full"
	Move.l	a0,RDF_3_Long(a5)		-'  to the command line.
ReadListerPath_S1

	Lea	Set_Path_Command(pc),a0		Input string.
	Lea	RDF_Array(a5),a1		DataArray
	Lea	Buffer2(a5),a3			-._ Output
	Move.l	a3,RDF_Adrs(a5)			-'  Buffer
	Move.l	#Buffer2Len,RDF_Size(a5)	Size of output buffer.
	Bsr	NudelRawDoFmt

	Lea	Buffer2(a5),a1		-._ Read in the
	Bsr	FillAndSendNudelRexxMsg	-'  new path.

	Move.l	NudelRexxMsg(a5),a0
	Tst.l	rm_Result1(a0)
	Bne	General_DOpus_Error

	Move.l	(SP)+,a0			Restore lister handle.
	Bra	ListerWait			Wait for lister to read the path in.
;;;;;;;	RTS for us.
;-------------------------------------------------------------------------------------;
Set_Path_Command
	Dc.b	"lister read %s '%s'%s",0
Force_SubCommand
	Dc.b	" force",0
	Even
	ENDC


	IFD	DO5_Refesh
*= Lister Refresh =****************************************************= 24-Sep-1995 =*
*  Inputs: Buffer2(a5) - Temporary storage.					      *
*	   (a0) - Lister handle.						      *
*	    d0  - #0 = Normal refresh,  #1 = "full" refresh			      *
* Outputs: Lister is refreshed.							      *
*   Notes: 									      *
***************************************************************************************
ListerRefresh
	Move.l	a0,RDF_1_Long(a5)		Lister handle.

	Move.l	d0,RDF_2_Long(a5)		Clear it, if null.
	Beq.s	ListerRefresh_S1		If null, leave it cleared (no "full").
	Cmpi.l	#1,d0				-._ Internal error if
	Bne	Internal			-'  not #0 or #1.
	Lea	Full_SubCommand(pc),a0		-._ Else, append " full"
	Move.l	a0,RDF_2_Long(a5)		-'  to the command line.
ListerRefresh_S1

	Lea	Lister_Refresh_Command(pc),a0	Input string.
	Lea	RDF_Array(a5),a1		DataArray
	Lea	Buffer2(a5),a3			-._ Output
	Move.l	a3,RDF_Adrs(a5)			-'  Buffer
	Move.l	#Buffer2Len,RDF_Size(a5)	Size of output buffer.
	Bsr	NudelRawDoFmt

	Lea	Buffer2(a5),a1			-._ Refresh
	Bsr	FillAndSendNudelRexxMsg		-'  the lister.

	Move.l	NudelRexxMsg(a5),a0
	Tst.l	rm_Result1(a0)
	Bne	General_DOpus_Error
	RTS
;-------------------------------------------------------------------------------------;
Lister_Refresh_Command
	Dc.b	"lister refresh %s%s",0
Full_SubCommand
	Dc.b	" full",0
	Even
	ENDC



	IFD	DO5_Select
*= Lister Select =*****************************************************= 18-Aug-1995 =*
*  Inputs: Buffer2(a5) - Temporary storage.					      *
*	   (a0) - Lister handle.						      *
*	   (a1) - Name of entry to (de)select.						      *
*	    d0  - #0 = deselect, #1 = select.					      *
* Outputs: Entry is (de)selected.						      *
*   Notes: Lister my be refreshed to display the changes.			      *
***************************************************************************************
ListerSelect
	Move.l	a0,RDF_1_Long(a5)		Lister handle.
	Move.l	a1,RDF_2_Long(a5)		Entry name.
	Move.l	d0,RDF_3_Long(a5)		Select/Deselect.

	Lea	Lister_Select_Command(pc),a0	Input string.
	Lea	RDF_Array(a5),a1		DataArray
	Lea	Buffer2(a5),a3			-._ Output
	Move.l	a3,RDF_Adrs(a5)			-'  Buffer
	Move.l	#Buffer2Len,RDF_Size(a5)	Size of output buffer.
	Bsr	NudelRawDoFmt

	Lea	Buffer2(a5),a1		-._ (De)Select
	Bsr	FillAndSendNudelRexxMsg	-'  the entry.

	Move.l	NudelRexxMsg(a5),a0
	Tst.l	rm_Result1(a0)
	Bne	General_DOpus_Error
	RTS
;-------------------------------------------------------------------------------------;
Lister_Select_Command
	Dc.b	"lister select %s %s %ld",0
	Even
	ENDC


	IFD	DO5_NewLister
*= New Lister =********************************************************= 18-Aug-1995 =*
*  Inputs: NoFront_S(a5) - ReadArgs() switch, if on DOpus5 screen not moved to front. *
*	   Buffer2(a5) - Temporary storage.					      *
*	    a0  - Pointer to Path to read, or NULL.				      *
*	    a1  - Pointer to Dimensions string, or NULL.			      *
*	    a2  - Pointer to Buffer to write new handle to, or NULL.		      *
*	   d7.w - Length of d2-Buffer, if a2 not NULL.				      *
* Outputs: A new lister is created and it's handle written out to (a2).		      *
***************************************************************************************
NewLister
	Movem.l	a2/d7,-(SP)			Preserve buffer to write new handle to.
	Movem.l	a0/a1,-(SP)			Preserve Dimenstions/Path string ptrs.

	Bsr	DOpusFront			Move DOpus screen to front.

	Movem.l	(SP)+,a0/a1			Restore Dimenstions/Path string ptrs.

	Move.l	a1,RDF_1_Long(a5)		Dimensions string, or null.
;;;;;;;	Note: If they didn't give it, nothing will be input here (valid).
	Move.l	a0,RDF_2_Long(a5)		Path string, or null.
;;;;;;;	Note: If they didn't give it, nothing will be input here (valid).
	Lea	Lister_New_Command(pc),a0	Input string.
	Lea	RDF_Array(a5),a1		DataArray
	Lea	Buffer2(a5),a3			-._ Output
	Move.l	a3,RDF_Adrs(a5)			-'  Buffer
	Move.l	#Buffer2Len,RDF_Size(a5)	Size of output buffer.
	Bsr	NudelRawDoFmt

	Lea	Buffer2(a5),a1		-._ Open the new lister.
	Bsr	FillAndSendNudelRexxMsg	-'  New-handle -> rm_Result2

	Move.l	NudelRexxMsg(a5),a0
	Tst.l	rm_Result1(a0)
	Bne.s	No_NewLister
	Tst.l	rm_Result2(a0)
	Beq.s	No_NewLister
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
	Movem.l	(SP)+,a2/d7			Restore buffer to write new handle to.

	Move.l	a2,d0				-._ If null, don't
	Tst.l	d0				(Just in case)
	Beq.s	NewLister_Skip_HandleStore	-'  store the handle.

	Move.l	NudelRexxMsg(a5),a0		-._ Copy the
	Move.l	rm_Result2(a0),a0		-'  new handle...
	Move.l	a2,a1				...to where they asked...
;;;;;;;	Move.w	d7,d7				...which is this long.
	Bsr	CopyCNT				-.
	Cmpi.w	#-1,d7				 |- Store the handle.
	Beq	Buffer_Overflow			-'
NewLister_Skip_HandleStore

	Move.l	NudelRexxMsg(a5),a0		-._ New lister's
	Move.l	rm_Result2(a0),a0		-'  handle...
	Bra	ListerWait			Wait for new lister to be ready.
;;;;;;;	RTS for us.
;-------------------------------------------------------------------------------------;
No_NewLister
	BSet	#SF1_ErrorDop,STD_F_1(a5)	Send next error message to DOpus5-req.
	Moveq	#0,d1				-._ No string returned
	N_CallDOS	SetIoErr		-'  by Fault().
	Bra_ErrorE	ErrAct_NewLister(pc),#0

Lister_New_Command
	Dc.b	'lister new %s %s',0
ErrAct_NewLister
	Dc.b	"Could not open a new lister",0
	Even
	ENDC


	IFD	DO5_ListerSet
*= Lister Set =********************************************************= 18-Aug-1995 =*
*  Inputs: (a0) - Lister handle.						      *
*	    a1  - Pointer to first command word, or NULL.			      *
*	    a2  - Pointer to second command word, or NULL.			      *
* Outputs: None.								      *
***************************************************************************************
ListerSet
	Move.l	a0,RDF_1_Long(a5)		Lister handle.
	Move.l	a1,RDF_2_Long(a5)		1st command word, or NULL.
	Move.l	a2,RDF_3_Long(a5)		2nd command word, or NULL.

	Lea	Lister_Set_Command(pc),a0	Input string.
	Lea	RDF_Array(a5),a1		DataArray
	Lea	Buffer2(a5),a3			-._ Output
	Move.l	a3,RDF_Adrs(a5)			-'  Buffer
	Move.l	#Buffer2Len,RDF_Size(a5)	Size of output buffer.
	Bsr	NudelRawDoFmt

	Lea	Buffer2(a5),a1			-._ Do the set
	Bsr	FillAndSendNudelRexxMsg		-'  command.

	Move.l	NudelRexxMsg(a5),a0
	Tst.l	rm_Result1(a0)
	Bne.s	General_DOpus_Error
	RTS
;-------------------------------------------------------------------------------------;
Lister_Set_Command
	Dc.b	'lister set %s %s %s',0
Set_Dest_SubCommand
	Dc.b	'dest',0
Set_Source_SubCommand
	Dc.b	'source',0
Set_Lock_SubCommand
	Dc.b	'lock',0
	Even
	ENDC


	IFD	DO5_Command
*= Command =***********************************************************= 27-Dec-1995 =*
*  Inputs: (a0) - Lister handle (MUST BE GIVEN! But is not used).		      *
*	    a1  - Pointer to first command word, or NULL.			      *
*	    a2  - Pointer to second command word, or NULL.			      *
* Outputs: None.								      *
***************************************************************************************
ListerCommand
	Sub.l	a0,a0
	Move.l	a1,RDF_1_Long(a5)		1st command word, or NULL.
	Move.l	a2,RDF_2_Long(a5)		2nd command word, or NULL.

	Lea	Command_Command(pc),a0		Input string.
	Lea	RDF_Array(a5),a1		DataArray
	Lea	Buffer2(a5),a3			-._ Output
	Move.l	a3,RDF_Adrs(a5)			-'  Buffer
	Move.l	#Buffer2Len,RDF_Size(a5)	Size of output buffer.
	Bsr	NudelRawDoFmt

	Lea	Buffer2(a5),a1			-._ Do the set
	Bsr	FillAndSendNudelRexxMsg		-'  command.

	Move.l	NudelRexxMsg(a5),a0
	Tst.l	rm_Result1(a0)
	Bne.s	General_DOpus_Error
	RTS
;-------------------------------------------------------------------------------------;
Command_Command
	Dc.b	'command %s %s',0
	Even
	ENDC


	IFD	DO5_GenError
*= General DOpus Error ************************************************= 18-Aug-1995 =*
*   Notes: This is intended to catch errors which should only occur if the user does  *
*	   something stupid like closes the lister half-way through an operation.     *
*	   In these cases it isn't worth wasting space with an error message	      *
*	   describing exactly what was going on.				      *
***************************************************************************************
General_DOpus_Error
	BSet	#SF1_ErrorDop,STD_F_1(a5)	Send next error message to DOpus5-req.
	Moveq	#0,d1				-._ No string returned
	N_CallDOS	SetIoErr		-'  by Fault().
	Bra_ErrorE	ErrAct_DOpus_General(pc),#0

ErrAct_DOpus_General
	Dc.b	"Something failed which shouldn't have:",10
	Dc.b	"You're either low on memory or playing with the listers",10
	Dc.b	"(or there is a bug in "
	PROGNAM
	Dc.b	")",0
	Even
	ENDC


	IFD	DO5_ListerWait
*= Lister Wait =*******************************************************= 19-Aug-1995 =*
*  Inputs: (a0) - Lister handle.						      *
* Outputs: Waits for lister to become non-busy.					      *
*   Notes: If non-busy to start with, waits up to two seconds for it to become busy.  *
***************************************************************************************
ListerWait
	Move.l	a0,RDF_1_Long(a5)

	Lea	Lister_Wait_Command(pc),a0	Input string.
	Lea	RDF_Array(a5),a1		DataArray
	Lea	Buffer2(a5),a3			-._ Output
	Move.l	a3,RDF_Adrs(a5)			-'  Buffer
	Move.l	#Buffer2Len,RDF_Size(a5)	Size of output buffer.
	Bsr	NudelRawDoFmt

	Lea	Buffer2(a5),a1			-._ Copy the
	Bsr	FillAndSendNudelRexxMsg		-'  lister.

	Move.l	NudelRexxMsg(a5),a0
	Tst.l	rm_Result1(a0)
	Bne	General_DOpus_Error
	RTS
;-------------------------------------------------------------------------------------;
Lister_Wait_Command
	Dc.b	'lister wait %s',0
	Even
	ENDC


	IFD	DO5_DOpusFront
*= DOpus Front =*******************************************************= 19-Aug-1995 =*
*  Inputs: NoFront_S(a5) - If set, routine is skipped.				      *
* Outputs: DOpus screen moved to front.						      *
***************************************************************************************
DOpusFront
	Tst.l	NoFront_S(a5)			-._ If they asked for the screen
	Bne.s	NewLister_NoFront		-'  to be left, leave it alone.
	Lea	Dopus_Front_Command(pc),a1	-._ Else, pop
	Bsr	FillAndSendNudelRexxMsg		-'  it to front.
;;;;;;;	Note: Dopus_Front_Command is part of the System.s/Error routine.
	Move.l	NudelRexxMsg(a5),a0
	Tst.l	rm_Result1(a0)
	Bne	General_DOpus_Error
NewLister_NoFront
	RTS
	ENDC


	IFD	DO5_ListClose
*= Lister Close =******************************************************= 27-Dec-1995 =*
*  Inputs: (a0) - Lister handle.						      *
* Outputs: Waits for lister to become non-busy and then closes it.		      *
*   Notes: If non-busy to start with, waits up to two seconds for it to become busy.  *
***************************************************************************************
ListerClose
	Move.l	a0,-(SP)		Preserve lister handle.
	Bsr.s	ListerWait		Wait for lister to become non-busy.
	Move.l	(SP)+,a0		Restore lister handle.

	Move.l	a0,RDF_1_Long(a5)	Lister handle for RawDoFmt()

	Lea	Lister_Close_Command(pc),a0	Input string.
	Lea	RDF_Array(a5),a1		DataArray
	Lea	Buffer2(a5),a3			-._ Output
	Move.l	a3,RDF_Adrs(a5)			-'  Buffer
	Move.l	#Buffer2Len,RDF_Size(a5)	Size of output buffer.
	Bsr	NudelRawDoFmt

	Lea	Buffer2(a5),a1			-._ Copy the
	Bsr	FillAndSendNudelRexxMsg		-'  lister.

	Move.l	NudelRexxMsg(a5),a0
	Tst.l	rm_Result1(a0)
	Bne	General_DOpus_Error
	RTS
;-------------------------------------------------------------------------------------;
Lister_Close_Command
	Dc.b	'lister close %s',0
	Even
	ENDC
