$include (..\lib\compStch.ext)

/*
 *============================================================================
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
 *
 *  Permission to use for any purpose, modify, copy, and make enhancements
 *  and derivative works of the software is granted if attribution is given to
 *  R.M. Gillmore, dba the ACME Software Deli, as the author
 *
 *  While the ACME Software Deli does not work for money, there is nonetheless
 *  a significant amount of work involved.  The ACME Software Deli maintains the
 *  rights to all code written, though it may be used and distributed as long as
 *  the following conditions are maintained.
 *
 *  1.  The copyright statement at the top of each code block is maintained in
 *      your distribution.
 *  2.  You do not identify yourself as the ACME Software Deli
 *  3.  Any changes made to the software are sent to the ACME Software Deli
 *============================================================================
 */


dirFunctModule:
do;
$if not noID
declare IDString	(*) byte data
	( '@(#)dirFunct.p86  $Author: rmgillmore $ $Date:: 2025-05-04 19:35:39#$:', 0 );
$endif

$set ( DIRFUNCT_IMPLEMENTATION )

$include (..\lib\sysCalls.ext)
$include (..\lib\string.ext)
$include (..\lib\fileIO.ext)
$include (..\lib\mem.ext)
$include (..\lib\dirFunct.ext)

/*
 *	LONG FILENAME FUNCTIONS
 *	AH = 71h
 *	AL = function
 *	0Dh reset drive (see AX=710Dh)
 *	39h create directory (see AX=7139h)
 *	3Ah remove directory (see AX=713Ah)
 *	3Bh set current directory (see AX=713Bh)
 *	41h delete file (see AX=7141h)
 *	43h get/set file attributes (see AX=7143h)
 *	47h get current directory (see AX=7147h)
 *	4Eh find first file (see AX=714Eh)
 *	4Fh find next file (see AX=714Fh)
 *	56h move (rename) file (see AX=7156h)
 *	60h truename (see AX=7160h/CL=00h,AX=7160h/CL=02h)
 *	6Ch create/open file (see AX=716Ch)
 *	A0h get volume information (see AX=71A0h)
 *	A1h terminate FindFirst/FindNext (see AX=71A1h)
 *	A6h get file information (see AX=71A6h)
 *	A7h time conversion (see AX=71A7h/BL=00h,AX=71A7h/BL=01h)
 *	A8h generate short filename (see AX=71A8h)
 *	A9h server create/open file (see AX=71A9h)
 *	AAh create/terminate SUBST (see AX=71AAh/BH=00h,AX=71AAh/BH=02h)
 *
 *	Return:CF set on error
 *		AX = error code (see #01680)
 *		7100h if function not supported
 *		CF clear if successful
 *
 *	other registers as for corresponding "old" DOS function
 *
 *	Notes:	If error 7100h is returned, the old-style function should be called.
 *			AX=714Eh returns a "search handle" which must be passed to AX=714Fh;
 *			when the search is complete, AX=71A1h must be called to terminate the search. For
 *			compatibility with DOS versions prior to v7.00, the carry flag should be set on call
 *			to ensure that it is set on exit.
 *
 *			Caldera's DPMS-enabled LONGNAME.EXE BETA 1 extension for DR-DOS 7
 */

rename:
procedure ( pathStringOld, pathStringNew ) word reentrant public;
	declare pathStringOld	pointer,
			pathStringNew	pointer,
			returnCode		word,
			cpuRegisters;

	wordRegs.AX = 07156h;
	wordRegs.DX = offset$of( pathStringOld );
	wordRegs.DS = selector$of( pathStringOld );
	wordRegs.DI = offset$of( pathStringNew );
	wordRegs.ES = selector$of( pathStringNew );
	call int86( DOS_CALL, @wordRegs );
	if ( not carryClear( @wordRegs ) ) then
	do;
		returnCode,
			errno = wordRegs.AX;
	end;
	else do;
		returnCode,
			errno = 0;
	end;
	return ( returnCode );
end rename;

delete:
procedure ( pathString ) word reentrant public;
	declare pathString		pointer,
			returnCode		word,
			cpuRegisters;

	wordRegs.AX = 07141h;
	wordRegs.DS = selector$of( pathString );
	wordRegs.DX = offset$of( pathString );
	call int86( DOS_CALL, @wordRegs );
	if ( not carryClear( @wordRegs ) ) then
	do;
		returnCode,
			errno = wordRegs.AX;
	end;
	else do;
		returnCode,
			errno = 0;
	end;

	return ( returnCode );
end delete;

end dirFunctModule;