unit lfn;
{pascal unit for _full_ access to the LFN API, no fallbacks}
{Names and parameter lists are similar but not equal to Win32 API}
{$W-,S-,G+}
{$IFDEF Windows}
{$C MOVEABLE PRELOAD PERMANENT} {gleiche Attribute wie Unit SYSTEM}
{$ENDIF}
interface
uses WinDos{$IFDEF Windows},WinProcs,WinTypes,Win31{$ENDIF};
{$IFNDEF Windows}
type
Bool=WordBool;
{$ENDIF}
var
ExtraInfo:Word; {CX value for FindFirst, FindNext, CreateFile}
const
DateFormat: Bool=true; {DOS time format for FindFirst, FindNext (SI)}
var
AliasHint: Word absolute DateFormat; {also: AliasHint for CreateFile}
type
LongRec=record
lo,hi:Word;
end;
LongLong=record
lo,hi:LongInt;
end;
PWin32FindData=^TWin32FindData;
TWin32FindData=record
attr: LongInt;
timec: LongLong;
timea: LongLong;
timem: LongLong;
sizeh,sizel: LongInt;
rsv: LongLong;
namel: array[0..259] of Char;
names: array[0..13] of Char;
end;
PVolumeInformation=^TVolumeInformation;
TVolumeInformation=record
fsname:array[0..15] of Char;
max_path:Word;
max_file:Word;
fs_flags:Word;
end;
const
MAX_PATH=260;
type
TLfnBuf=array[0..MAX_PATH-1] of Char;
const {ExtraInfo code for FindFirst/FindNext}
CF_NoConvert=1;
const {indices for Get/SetFileAttributes}
FA_GetAttr=0;
FA_SetAttr=1;
FA_GetPhysSize=2;
FA_SetTimeM=3;
FA_GetTimeM=4;
FA_SetTimeA=5;
FA_GetTimeA=6;
FA_SetTimeC=7;
FA_GetTimeC=8;
const {ExtraInfo codes for CreateFile}
CF_Opened=1;
CF_Created=2;
CF_Truncated=3;
const {TranslateName codes}
TN_SubstDrive=$8000;
TN_Truename=0;
TN_Longname=1;
TN_Shortname=2;
function MakeDirectory(dname:PChar):Boolean;
function RemoveDirectory(dname:PChar):Boolean;
function ChangeDirectory(dname:PChar):Boolean;
function GetCurrentDirectory(drive:Byte; dname:PChar):Boolean;
function DeleteFile(fname:PChar):Boolean;
function DeleteFiles(filter:PChar; attr:Word):Boolean;
function GetFileAttributes(fname:PChar; index:Word; var fa:LongInt):Boolean;
function SetFileAttributes(fname:PChar; index:Word; fa:LongInt):Boolean;
function MoveFile(src,dst:PChar):Boolean;
function FindFirstFile(filter:PChar; attr:Word; var fd:TWin32FindData):Word;
function FindNextFile(h: Word; var fd: TWin32FindData):Boolean;
function FindClose(h: Word):Boolean;
function CreateFile(fname:PChar; attr,creat,share:Word):Word;
function TranslateName(fname,tname:PChar;how:Word):Boolean;
{function CreateAlias(fname,alias:PChar):Boolean;}
function GetVolumeInformation(fname:PChar; var vi:TVolumeInformation):Boolean;
function FileTimeConvert(var t:LongLong; how:Boolean):Boolean;
implementation
function SetDOSError:Boolean; assembler;
asm mov dx,0
jc @@err
xchg dx,ax {ohne Fehler [DosError]=0 und DX=Handle}
@@err: mov [DosError],ax
db 0D6h {SetALC}
inc al
end;
{$IFDEF Windows}
procedure AnsiOemSt; near; assembler;
{Name ES:SI auf Stack konvertieren, PA: SS:SP=OEM-Name, VR: alle auer AX}
asm pop di {Rcksprung!}
push ax
push es
push es
push si
call lstrlen {Lnge in AX}
pop es
pop cx
inc ax
inc ax
and al,not 1 {gerade aufrunden}
sub sp,ax
mov ax,sp
push cx
push es
push si
push ss
push ax
call AnsiToOem
pop ax
jmp di
end;
procedure AnsiOem; assembler; {von DS:SI nach SS:AX}
asm push es
push ds
push si
push ss
push ax
call AnsiToOem
pop es
end;
procedure CallDOS_DSDX; assembler;
var
OemBuf: TLfnBuf;
asm push ds
pusha {hier: AX,BX,CX,DX,SI}
mov si,dx
lds si,ss:[si]
lea ax,OemBuf
call AnsiOem
popa
push ss
pop ds
lea dx,OemBuf
stc
int 21h
pop ds
call SetDosError
end;
procedure CallDOS_DSSI; assembler;
var
OemBuf: TLfnBuf;
asm push ds
pusha {hier: AX,BX,CX,DX}
lds si,ss:[si]
lea ax,OemBuf
call AnsiOem
popa
push ss
pop ds
lea si,OemBuf
stc
int 21h
pop ds
call SetDosError
end;
procedure OemAnsi; assembler;
asm push ax
push es
push bx
push es
push bx
call OemToAnsi
pop ax
end;
{$ELSE}
procedure CallDOS_DSDX; assembler;
asm push ds
push si
mov si,dx
lds dx,ss:[si]
pop si
stc
int 21h
pop ds
call SetDosError
end;
procedure CallDOS_DSSI; assembler;
asm push ds
lds si,ss:[si]
stc
int 21h
pop ds
call SetDosError
end;
{$ENDIF}
function MakeDirectory(dname:PChar):Boolean; assembler;
asm lea dx,dname
mov ax,7139h
call CallDOS_DSDX
end;
function RemoveDirectory(dname:PChar):Boolean; assembler;
asm lea dx,dname
mov ax,713Ah
call CallDOS_DSDX
end;
function ChangeDirectory(dname:PChar):Boolean; assembler;
asm lea dx,dname
mov ax,713Bh
call CallDOS_DSDX
end;
function GetCurrentDirectory(drive:Byte; dname:PChar):Boolean; assembler;
asm push ds
mov dl,[drive] {0=current, 1='A' etc.}
mov al,dl
dec al
jns @@1
mov ah,19h
int 21h
@@1: add al,'A'
lds si,[dname]
mov byte ptr [si],al
inc si
mov word ptr [si],'\:'
inc si
inc si
mov ax,7147h
stc
int 21h
pop ds
call SetDosError
{$IFDEF Windows}
jc @@e
les bx,[dname]
call OemAnsi
@@e:
{$ENDIF}
end;
function DeleteFile(fname:PChar):Boolean; assembler;
asm xor si,si
lea dx,fname
mov ax,7141h
call CallDOS_DSDX
end;
function DeleteFiles(filter:PChar; attr:Word):Boolean; assembler;
asm mov si,1
lea dx,filter
mov cx,[attr]
mov ax,7141h
call CallDOS_DSDX
end;
function GetFileAttributes(fname:PChar; index:Word; var fa:LongInt):Boolean; assembler;
asm
end;
function SetFileAttributes(fname:PChar; index:Word; fa:LongInt):Boolean; assembler;
asm
end;
function MoveFile(src,dst:PChar):Boolean; assembler;
{$IFDEF Windows}
var
OemBuf: TLfnBuf;
{$ENDIF}
asm les di,[dst]
{$IFDEF Windows}
lea bx,OemBuf
push ss
push bx
push es
push di
push ss
push bx
call AnsiToOem
pop di
pop es
{$ENDIF}
mov ax,7156h
lea dx,src
call CallDOS_DSDX
end;
procedure EndSearch; assembler;
asm jc @@e
mov [ExtraInfo],cx
{$IFDEF Windows}
lea bx,TWin32FindData[di].namel
push es
call OemAnsi
pop es
lea bx,TWin32FindData[di].names
call OemAnsi
{$ENDIF}
@@e:
end;
function FindFirstFile; assembler;
asm mov cx,[attr]
lea dx,filter
mov si,[DateFormat]
les di,[fd]
mov ax,714Eh
call CallDOS_DSDX
xchg dx,ax
call EndSearch
end;
function FindNextFile; assembler;
asm mov bx,[h]
mov si,[DateFormat]
les di,[fd]
stc
mov ax,714Fh
int 21h
call SetDosError
call EndSearch
end;
function FindClose; assembler;
asm mov bx,[h]
stc
mov ax,71A1h
int 21h
call SetDosError
end;
function TranslateName; assembler;
asm xor bx,bx
mov cx,[how]
xchg bl,cl
lea si,fname
les di,[tname]
mov ax,7160h
call CallDOS_DSSI
{$IFDEF Windows}
jc @@e
mov bx,di
call OemAnsi
@@e:
{$ENDIF}
end;
function CreateFile(fname:PChar; attr,creat,share:Word):Word; assembler;
asm mov bx,[creat]
mov cx,[attr]
mov dx,[share]
lea si,fname
mov di,[AliasHint]
mov ax,716Ch
call CallDOS_DSSI
xchg dx,ax
jc @@e
mov [ExtraInfo],cx
@@e:
end;
function GetVolumeInformation(fname:PChar; var vi:TVolumeInformation):Boolean; assembler;
asm mov cx,16
lea dx,fname
les di,[vi]
mov ax,71A0h
call CallDOS_DSDX
jc @@e
mov es:TVolumeInformation[di].max_path,dx
mov es:TVolumeInformation[di].max_file,cx
mov es:TVolumeInformation[di].fs_flags,bx
@@e:
end;
function FileTimeConvert(var t:LongLong; how:Boolean):Boolean; assembler;
asm mov bl,[how]
end;
end.
Detected encoding: UTF-8 | 0
|