***************************************************************************************
* ParentToDest subroutine for DOpusFuncs.s					      *
***************************************************************************************
ParentToDest
	Tst.l	ParentToDest_S(a5)
	Bne.s	ParentToDest_DoIt
	RTS
ParentToDest_DoIt
	Sub.l	d0,d0			Abort if there isn't a source lister.
	Bsr	GetSourceHandle		Get the source lister's handle -> Source_Handle
	Moveq	#1,d0			Open new dest if one doesn't exist.
	Bsr	GetDestHandle		Get the dest lister's handle -> Dest_Handle
;-------------------------------------------------------------------------------------;
; Build full path of first selected directory in the source lister.		      ;
;-------------------------------------------------------------------------------------;
	Lea	Source_Handle(a5),a0	Handle to get the path of.
	Lea	PathBuffer1(a5),a1	Buffer to write path into.
	Move.w	#PathBuffer1Len,d7	Size of above buffer.
	Bsr	GetListerPath		Path -> buffer.
;-------------------------------------------------------------------------------------;
	Bsr	Create_NIB		Create a new NudelInfoBlock for Lock()ing...
	Move.l	Active_NIB(a5),a1	NIB Pointer to a1
	Move.l	a1,BaseDir_NIB(a5)	Store our NIB pointer.

	Bsr	Create_NIB		Create a new NudelInfoBlock for Lock()ing...
	Move.l	Active_NIB(a5),a1	NIB Pointer to a1
	Move.l	a1,ParentDir_NIB(a5)	Store our NIB pointer.
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
	Lea	PathBuffer1(a5),a0	-.
	Move.l	BaseDir_NIB(a5),a1	 |- Set name in BaseDir NIB for Lock()...
	Move.l	a0,NIB_NameAdrs(a1)	-'
	Move.l	a1,Active_NIB(a5)	Use this NIB for the Lock_NIB routine.
	Moveq	#ACCESS_READ,d2		Read (shared) mode.
	Bsr	Lock_NIB		Get a Lock() on the path.
	Tst.l	d0
	Beq_ErrorE	ErrAct_Lock(pc),BaseDir_NIB(a5)
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
	Move.l	BaseDir_NIB(a5),a0	-._ Lock to get
	Move.l	NIB_Lock(a0),d1		-'  the parent of.
	N_CallDOS	ParentDir	Parent-Lock -> d0
	Move.l	ParentDir_NIB(a5),a0	-._ Store new lock in NIB
	Move.l	d0,NIB_Lock(a0)		-'  for automatic UnLock()

;;;;;;;	If d0 = zero, NameFromLock() will return "SYS:".
;;;;;;;	However, in this case, it would be better to call DOpus5's DeviceList command.
	Tst.l	d0
	Beq.s	ParentToDest_DeviceList

	Move.l	d0,d1			Lock to get name of.
	Lea	PathBuffer2(a5),a0	-._ Buffer to write
	Move.l	a0,d2			-'  it into.
	Move.l	#PathBuffer2Len,d3	Length of buffer.
	N_CallDOS	NameFromLock	Write the name into the buffer.
	Tst.l	d0
	Beq_ErrorE	ErrAct_ParentDir(pc),BaseDir_NIB(a5)
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
	Move.l	BaseDir_NIB(a5),Active_NIB(a5)	-.
	Bsr	Delete_NIB			 |_ Free both of the NIBs
	Move.l	ParentDir_NIB(a5),Active_NIB(a5) |  Includes UnLock()ing.
	Bsr	Delete_NIB			-'
;-------------------------------------------------------------------------------------;
	Lea	Dest_Handle(a5),a0	Handle to read path into.
	Lea	PathBuffer2(a5),a1	Path to read.
	Sub.l	d0,d0			Don't force into current path buffer.
	Bra	ReadListerPath		Read the path into the destination lister.

;;;;;;;	RTS for us.
;-------------------------------------------------------------------------------------;
ParentToDest_DeviceList
	Move.l	BaseDir_NIB(a5),Active_NIB(a5)	-.
	Bsr	Delete_NIB			 |_ Free both of the NIBs
	Move.l	ParentDir_NIB(a5),Active_NIB(a5) |  Includes UnLock()ing.
	Bsr	Delete_NIB			-'

	Lea	Dest_Handle(a5),a0		Handle of lister.
	Lea	Set_Source_SubCommand(pc),a1	Want to make it the source lister.
	Sub.l	a2,a2				Don't lock it.
	Bsr	ListerSet

	Lea	Device_List_Command(pc),a1	-._ Get a FULL
	Bsr	FillAndSendNudelRexxMsg		-'  device list.

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

	Lea	Source_Handle(a5),a0		-._ Wait for the DeviceList
	Bsr	ListerWait			-'  to complete.

	Lea	Source_Handle(a5),a0		Handle of lister.
	Lea	Set_Source_SubCommand(pc),a1	Want to make it the source lister.
	Sub.l	a2,a2				Don't lock it.
	Bra	ListerSet
;;;;;;;	RTS for us.
;-------------------------------------------------------------------------------------;
ErrAct_ParentDir
	Dc.b	"Could not get parent dir of ",0
Device_List_Command
	Dc.b	"command devicelist FULL",0
	Even
