-
Notifications
You must be signed in to change notification settings - Fork 0
/
LFN.PAS
executable file
·1262 lines (1153 loc) · 30.7 KB
/
LFN.PAS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{.$F+,I-,O+,X+,D+,L+}
{$F+,I-,O+,X+}
unit LFN;
interface
uses Dos, Strings;
type
lAPIType = (lDOS, lWIN95, lOS2);
lSearchRec = record
SR: SearchRec;
FileHandle: Word;
FullName: String;
FindFirstMode: lAPIType;
{ Other fields will be added later }
end;
TNameZ = Array[0..259] of Char;
lFile = record
F: File;
FullName: TNameZ;
AssignFileMode: lAPIType;
{ Other fields will be added later }
end;
lText = record
T: Text;
FullName: TNameZ;
AssignTextMode: lAPIType;
{ Other fields will be added later }
end;
const
lAPI: lAPIType = lDOS;
ltMod = 0;
ltAcc = 1;
ltCre = 2;
LFNTimes: Byte = ltMod;
function LFNDisabled(const Path: String): Boolean;
procedure lFindFirst(const Path: String; Attr: Word; var R: lSearchRec);
procedure lFindNext(var R: lSearchRec);
procedure lFindClose(var R: lSearchRec);
procedure lGetShortFileName(const Name: String; var ShortName: String);
procedure lGetLongFileName(const Name: String; var LongName: String);
procedure lGetFileNameForChangedAPI(FromAPI: lAPIType;
const Name: String; var NewName: String);
procedure lTrueName(const Name: String; var S: String);
procedure lAssignFile(var F: lFile; const Name: String);
procedure lAssignText(var T: lText; const Name: String);
procedure lResetFile(var F: lFile; RecSize: Word);
procedure lResetReadOnly(var F: lFile; RecSize: Word);
procedure lRewriteFile(var F: lFile; RecSize: Word);
procedure lEraseFile(var F: lFile);
procedure lEraseText(var T: lText);
procedure lRenameFile(var F: lFile; const NewName: String);
procedure lRenameText(var T: lText; const NewName: String);
procedure lGetFAttr(var F: lFile; var Attr: Word);
procedure lSetFAttr(var F: lFile; Attr: Word);
procedure lGetTAttr(var T: lText; var Attr: Word);
procedure lSetTAttr(var T: lText; Attr: Word);
procedure lMkDir(const Path: String);
procedure lRmDir(const Path: String);
procedure lChDir(const Path: String);
procedure lGetDir(D: Byte; var Path: String);
function lFExpand(const Path: String): String;
procedure lFSplit(const Path: String; var Dir, Name, Ext: String);
function lWIN95APIAllowed: Boolean;
implementation
uses DrvList, Disks, Defaults;
function LFNDisabled(const Path: String): Boolean;
var
Drive: Char;
Regs: Registers;
begin
if (Length(Path) > 1) and (Path[1] = '\') and (Path[2] = '\') then
LFNDisabled := (DriveListOptions and dlUserResources <> 0) and
UserResourceLFNDisabled(Path)
else if DriveListOptions and dlGetFromUser = 0 then
LFNDisabled := False
else
begin
if (Length(Path) > 1) and (Path[2] = ':') then
Drive := Upcase(Path[1])
else with Regs do
begin
AH := $19;
Intr($21, Regs);
Drive := Char(AL + $41);
end;
LFNDisabled := (Drive in ['A'..'Z']) and
(UserDrives[Drive] and udEnabled <> 0) and
(UserDrives[Drive] and udNoLFN <> 0);
end;
end;
procedure NameToNameZ(const Name: String; var NameZ: TNameZ);
begin
Move(Name[1], NameZ, Length(Name));
NameZ[Length(Name)] := #0;
end;
procedure CheckColonAndSlash(const Name: String; var S: String);
var
ColonPos: Integer;
begin
ColonPos := Pos(':', S);
if (ColonPos > 2) and (Name[2] = ':') then
begin
Delete(S, 1, ColonPos - 1);
S := Name[1] + S;
end;
if Name[Length(Name)] <> '\' then
while S[Length(S)] = '\' do Dec(S[0])
else if (Name[Length(Name)] = '\') and
(S[Length(S)] <> '\') and (Length(S) < 255) then
begin
Inc(S[0]);
S[Length(S)] := '\';
end;
end;
(*
Offset Size Description
00h DWORD file attributes
bits 0-6 standard DOS attributes
bit 8: temporary file
04h QWORD file creation time
(number of 100ns intervals since 1/1/1601)
0Ch QWORD last access time
14h QWORD last modification time
1Ch DWORD file size (high 32 bits)
20h DWORD file size (low 32 bits)
24h 8 BYTEs reserved
2Ch 260 BYTEs ASCIZ full filename
130h 14 BYTEs ASCIZ short filename (for backward compatibility)
*)
type
lFindDataRec = record
LoAttr: Word;
HiAttr: Word;
LoCreationTime: Longint;
HiCreationTime: Longint;
LoLastAccessTime: Longint;
HiLastAccessTime: Longint;
LoLastModificationTime: Longint;
HiLastModificationTime: Longint;
HiSize: Longint;
LoSize: Longint;
Reserved: Array[0..7] of Byte;
FullName: TNameZ;
ShortName: Array[0..13] of Char;
end;
procedure FindDataToSearchRec(var FindData: lFindDataRec; var R: lSearchRec);
begin
R.SR.Attr := FindData.LoAttr;
if LFNTimes = ltCre then R.SR.Time := FindData.LoCreationTime
else if LFNTimes = ltAcc then R.SR.Time := FindData.LoLastAccessTime
else R.SR.Time := FindData.LoLastModificationTime;
R.SR.Size := FindData.LoSize;
R.SR.Name := StrPas(FindData.ShortName);
R.FullName := StrPas(FindData.FullName);
if R.SR.Name = '' then
begin
R.SR.Name := R.FullName;
R.FullName := '';
end;
end;
(*
INT 21h AX=714E
INT 21 - Windows95 - LONG FILENAME - FIND FIRST MATCHING FILE
AX = 714Eh
CL = allowable-attributes mask (bits 0 and 5 ignored)
CH = required-attributes mask
SI = date/time format
DS:DX -> ASCIZ filespec (both "*" and "*.*" match any filename)
ES:DI -> FindData record
Return: CF clear if successful
AX = filefind handle (needed to continue search)
CX = Unicode conversion flags
CF set on error
AX = error code
7100h if function not supported
Notes: this function is only available when IFSMgr is running,
not under bare MS-DOS 7
the application should close the filefind handle
with AX=71A1h as soon as it has completed its search
*)
procedure lWIN95FindFirst(const Path: String; Attr: Word; var R: lSearchRec);
var
Regs: Registers;
FindData: lFindDataRec;
begin
NameToNameZ(Path, FindData.FullName);
with Regs do
begin
AX := $714E;
CX := Attr;
SI := 1;
DS := Seg(FindData.FullName);
DX := Ofs(FindData.FullName);
ES := Seg(FindData);
DI := Ofs(FindData);
asm
stc
end;
Intr($21, Regs);
if Flags and fCarry <> 0 then
begin
R.FileHandle := $FFFF;
DosError := AX;
end
else
begin
R.FileHandle := AX;
FindDataToSearchRec(FindData, R);
DosError := 0;
end;
end;
end;
(*
INT 21h AX=714F
INT 21 - Windows95 - LONG FILENAME - FIND NEXT MATCHING FILE
AX = 714Fh
BX = filefind handle (from AX=714Eh)
SI = date/time format
ES:DI -> buffer for FindData record
Return: CF clear if successful
CX = Unicode conversion flags
CF set on error
AX = error code
7100h if function not supported
Note: this function is only available when IFSMgr is running,
not under bare MS-DOS 7
*)
procedure lWIN95FindNext(var R: lSearchRec);
var
Regs: Registers;
FindData: lFindDataRec;
begin
with Regs do
begin
AX := $714F;
BX := R.FileHandle;
SI := 1;
ES := Seg(FindData);
DI := Ofs(FindData);
asm
stc
end;
Intr($21, Regs);
if Flags and fCarry <> 0 then DosError := AX
else
begin
FindDataToSearchRec(FindData, R);
DosError := 0;
end;
end;
end;
(*
INT 21h AX=71A1
INT 21 - Windows95 - LONG FILENAME - "FindClose" -
TERMINATE DIRECTORY SEARCH
AX = 71A1h
BX = filefind handle (from AX=714Eh)
Return: CF clear if successful
CF set on error
AX = error code
7100h if function not supported
Notes: this function must be called after starting a search
with AX=714Eh, to indicate that the search handle
returned by that function will no longer be used
this function is only available when IFSMgr is running,
not under bare MS-DOS 7
*)
procedure lWIN95FindClose(var R: lSearchRec);
var
Regs: Registers;
begin
if R.FileHandle <> $FFFF then with Regs do
begin
AX := $71A1;
BX := R.FileHandle;
Intr($21, Regs);
end;
end;
procedure lFindFirst(const Path: String; Attr: Word; var R: lSearchRec);
begin
R.FullName := '';
case lAPI of
lDOS:
begin
R.FindFirstMode := lDOS;
FindFirst(Path, Attr, R.SR);
end;
lWIN95:
if (DriveListOptions and (dlGetFromUser + dlUserResources) <> 0) and
LFNDisabled(Path) then
begin
R.FindFirstMode := lDOS;
FindFirst(Path, Attr, R.SR)
end
else
begin
R.FindFirstMode := lWIN95;
lWIN95FindFirst(Path, Attr, R);
end;
{ Other APIs will be added later }
end;
end;
procedure lFindNext(var R: lSearchRec);
begin
R.FullName := '';
case R.FindFirstMode of
lDOS: FindNext(R.SR);
lWIN95: lWIN95FindNext(R);
{ Other APIs will be added later }
end;
end;
procedure lFindClose(var R: lSearchRec);
begin
case R.FindFirstMode of
lDOS: ;
lWIN95: lWIN95FindClose(R);
{ Other APIs will be added later }
end;
end;
(*
INT 21h AX=7160 CL=01
INT 21 - Windows95 - LONG FILENAME - GET SHORT (8.3) FILENAME FOR FILE
AX = 7160h
CL = 01h
CH = SUBST expansion flag
00h return a path containing true path
for a SUBSTed drive letter
80h return a path containing the SUBSTed drive letter
DS:SI -> ASCIZ long filename or path
ES:DI -> 67-byte buffer for short filename
Return: CF set on error
AX = error code
02h invalid component in directory path
or drive letter only
03h malformed path or invalid drive letter
ES:DI buffer unchanged
CF clear if successful
ES:DI buffer filled with equivalent short filename
(full path, even if relative path given,
and all uppercase)
Note: this call returns the short name for any
long-filename portions of the provided pathname or filename
*)
(*
INT 21h AX=7160 CL=02
INT 21 - Windows95 - LONG FILENAME - GET CANONICAL LONG FILENAME OR PATH
AX = 7160h
CL = 02h
CH = SUBST expansion flag
00h return a path containing true path
for a SUBSTed drive letter
80h return a path containing the SUBSTed drive letter
DS:SI -> ASCIZ short filename or path
ES:DI -> 261-byte buffer for canonicalized long name
Return: CF set on error
AX = error code
02h invalid component in directory path
or drive letter only
03h malformed path or invalid drive letter
ES:DI buffer unchanged
CF clear if successful
ES:DI buffer filled with qualified long name
(can contain lowercase letters)
*)
procedure lWIN95GetFileNameFunc(const Name: String;
var S: String; AFunction: Byte);
var
Regs: Registers;
NameZ, GetNameZ: TNameZ;
begin
NameToNameZ(Name, NameZ);
with Regs do
begin
AX := $7160;
CL := AFunction;
CH := $80;
DS := Seg(NameZ);
SI := Ofs(NameZ);
ES := Seg(GetNameZ);
DI := Ofs(GetNameZ);
Intr($21, Regs);
if Flags and fCarry <> 0 then S := Name
else
begin
S := StrPas(GetNameZ);
CheckColonAndSlash(Name, S);
end;
end;
end;
procedure lGetShortFileName(const Name: String; var ShortName: String);
begin
case lAPI of
lDOS: ShortName := Name;
lWIN95:
if (DriveListOptions and (dlGetFromUser + dlUserResources) <> 0) and
LFNDisabled(Name) then ShortName := Name
else lWIN95GetFileNameFunc(Name, ShortName, 1);
{ Other APIs will be added later }
end;
end;
procedure lGetLongFileName(const Name: String; var LongName: String);
begin
case lAPI of
lDOS: LongName := Name;
lWIN95:
if (DriveListOptions and (dlGetFromUser + dlUserResources) <> 0) and
LFNDisabled(Name) then LongName := Name
else lWIN95GetFileNameFunc(Name, LongName, 2);
{ Other APIs will be added later }
end;
end;
procedure lGetFileNameForChangedAPI(FromAPI: lAPIType;
const Name: String; var NewName: String);
var
SaveAPI: lAPIType;
begin
SaveAPI := lAPI;
if lAPI = lDOS then lAPI := FromAPI;
if FromAPI = lDOS then lGetLongFileName(Name, NewName)
else lGetShortFileName(Name, NewName);
lAPI := SaveAPI;
end;
(*
INT 21h AH=60
INT 21 - DOS 3.0+ - "TRUENAME" - CANONICALIZE FILENAME OR PATH
AH = 60h
DS:SI -> ASCIZ filename or path
ES:DI -> 128-byte buffer for canonicalized name
Return: CF set on error
AX = error code
02h invalid component in directory path
or drive letter only
03h malformed path or invalid drive letter
ES:DI buffer unchanged
CF clear if successful
AH = 00h or 3Ah (DOS 6.1/6.2 for character device)
AL = destroyed (00h or 2Fh or 5Ch or last character
of current directory on drive)
buffer filled with qualified name of form
D:\PATH\FILE.EXT or \\MACHINE\PATH\FILE.EXT
Desc: determine the canonical name of the specified
filename or path, corresponding to the undocumented
TRUENAME command in COMMAND.COM
Notes: the input path need not actually exist
letters are uppercased, forward slashes converted
to backslashes, asterisks converted to appropriate
number of question marks, and file and directory
names are truncated to 8.3 if necessary.
*)
procedure DOSTrueName(const Name: String; var S: String);
var
Regs: Registers;
NameZ, GetNameZ: TNameZ;
begin
NameToNameZ(Name, NameZ);
with Regs do
begin
AH := $60;
DS := Seg(NameZ);
SI := Ofs(NameZ);
ES := Seg(GetNameZ);
DI := Ofs(GetNameZ);
Intr($21, Regs);
if Flags and fCarry <> 0 then S := Name
else
begin
S := StrPas(GetNameZ);
CheckColonAndSlash(Name, S);
end;
end;
end;
(*
INT 21h AX=7160 CL=00
INT 21 - Windows95 - LONG FILENAME - "TRUENAME" - CANONICALIZE PATH
AX = 7160h
CL = 00h
CH = SUBST expansion flag
00h return a path containing true path
for a SUBSTed drive letter
80h return a path containing the SUBSTed drive letter
DS:SI -> ASCIZ filename or path (either long name or short name)
ES:DI -> 261-byte buffer for canonicalized name
Return: CF set on error
AX = error code
02h invalid component in directory path
or drive letter only
03h malformed path or invalid drive letter
ES:DI buffer unchanged
CF clear if successful
ES:DI buffer filled with fully qualified name
AX destroyed
Desc: determine the canonical name of the specified
filename or path, corresponding to the undocumented
TRUENAME command in COMMAND.COM
Note: if a complete path is given, the result will be
a short-form complete path; otherwise, the given
relative path is appended to the short-form
current directory name, '.'/'..'/'...'/etc. are resolved,
and the final result uppercased without converting
any remaining long-form names to short-form
*)
procedure WIN95TrueName(const Name: String; var S: String);
var
Regs: Registers;
NameZ, GetNameZ: TNameZ;
begin
NameToNameZ(Name, NameZ);
with Regs do
begin
AX := $7160;
CL := 0;
CH := $00;
DS := Seg(NameZ);
SI := Ofs(NameZ);
ES := Seg(GetNameZ);
DI := Ofs(GetNameZ);
asm
stc
end;
Intr($21, Regs);
if Flags and fCarry <> 0 then S := Name
else
begin
S := StrPas(GetNameZ);
CheckColonAndSlash(Name, S);
end;
end;
end;
procedure lTrueName(const Name: String; var S: String);
begin
case lAPI of
lDOS: DOSTrueName(Name, S);
lWIN95:
if (DriveListOptions and (dlGetFromUser + dlUserResources) <> 0) and
LFNDisabled(Name) then DOSTrueName(Name, S)
else WIN95TrueName(Name, S);
{ Other APIs will be added later }
end;
end;
procedure lAssignFile(var F: lFile; const Name: String);
begin
case lAPI of
lDOS:
begin
F.AssignFileMode := lDOS;
Assign(F.F, Name);
end;
{ Other APIs will be added later }
else if (DriveListOptions and (dlGetFromUser + dlUserResources) <> 0) and
LFNDisabled(Name) then
begin
F.AssignFileMode := lDOS;
Assign(F.F, Name);
end
else
begin
F.AssignFileMode := lWIN95;
FileRec(F.F).Handle := 0;
FileRec(F.F).Mode := fmClosed;
NameToNameZ(Name, F.FullName);
end;
end;
end;
{$L W95TFIO.OBJ}
{$L W95TCTL.OBJ}
procedure FileRead; far; external;
procedure FileWrDev; far; external;
procedure FileWrite; far; external;
procedure FileClose; far; external;
procedure FileOpen; far; external;
procedure lAssignText(var T: lText; const Name: String);
begin
case lAPI of
lDOS:
begin
T.AssignTextMode := lDOS;
Assign(T.T, Name);
end;
{ Other APIs will be added later }
else if (DriveListOptions and (dlGetFromUser + dlUserResources) <> 0) and
LFNDisabled(Name) then
begin
T.AssignTextMode := lDOS;
Assign(T.T, Name);
end
else
begin
T.AssignTextMode := lWIN95;
Assign(T.T, '');
TextRec(T.T).Private := 1;
TextRec(T.T).OpenFunc := @FileOpen;
NameToNameZ(Name, T.FullName);
end;
end;
end;
(*
INT 21h AX=716C
INT 21 - Windows95 - LONG FILENAME - CREATE OR OPEN FILE
AX = 716Ch
BX = access mode and sharing flags
CX = attributes
DX = action
DS:SI -> ASCIZ filename
DI = alias hint
(number to append to short filename for disambiguation)
Return: CF clear if successful
AX = file handle
CX = action taken
0001h file opened
0002h file created
0003h file replaced
CF set on error
AX = error code
7100h if function not supported
*)
const
faOpen = 1;
faTruncate = 2;
faCreate = $10;
faRewrite = faTruncate + faCreate;
procedure lWIN95OpenFile(var F: lFile; RecSize: Word; Action: Byte);
var
Regs: Registers;
begin
if FileRec(F.F).Mode <> fmClosed then Close(F.F);
InOutRes := 0;
if F.FullName[0] = #0 then
begin
FileRec(F.F).Mode := fmInOut;
FileRec(F.F).RecSize := RecSize;
end
else with Regs do
begin
AX := $716C;
BX := FileMode;
CX := 0;
DX := Action;
DS := Seg(F.FullName);
SI := Ofs(F.FullName);
DI := 0;
Intr($21, Regs);
if Flags and fCarry <> 0 then InOutRes := AX
else
begin
FileRec(F.F).Mode := fmInOut;
FileRec(F.F).Handle := AX;
FileRec(F.F).RecSize := RecSize;
end;
end;
end;
procedure lResetFile(var F: lFile; RecSize: Word);
begin
case F.AssignFileMode of
lDOS: Reset(F.F, RecSize);
lWIN95: lWIN95OpenFile(F, RecSize, faOpen);
{ Other APIs will be added later }
end;
end;
procedure lResetReadOnly(var F: lFile; RecSize: Word);
var
SaveMode: Byte;
begin
SaveMode := FileMode;
FileMode := 64;
lResetFile(F, RecSize);
FileMode := SaveMode;
end;
procedure lRewriteFile(var F: lFile; RecSize: Word);
begin
case F.AssignFileMode of
lDOS: Rewrite(F.F, RecSize);
lWIN95: lWIN95OpenFile(F, RecSize, faRewrite);
{ Other APIs will be added later }
end;
end;
(*
INT 21h AX=7141
INT 21 - Windows95 - LONG FILENAME - DELETE FILE
AX = 7141h
DS:DX -> ASCIZ long name of file to delete
SI = wildcard and attributes flag
0000h wildcards are not allowed,
and search attributes are ignored
0001h wildcards are allowed,
and only files with matching
names and attributes are deleted
CL = search attributes
CH = must-match attributes
Return: CF clear if successful
CF set on error
AX = error code
7100h if function not supported
*)
procedure lWIN95EraseFile(var F: lFile);
var
Regs: Registers;
begin
with Regs do
begin
AX := $7141;
DS := Seg(F.FullName);
DX := Ofs(F.FullName);
SI := 0;
Intr($21, Regs);
if Flags and fCarry <> 0 then InOutRes := AX
else InOutRes := 0;
end;
end;
procedure lEraseFile(var F: lFile);
begin
case F.AssignFileMode of
lDOS: Erase(F.F);
lWIN95: lWIN95EraseFile(F);
{ Other APIs will be added later }
end;
end;
procedure lWIN95EraseText(var T: lText);
var
Regs: Registers;
begin
with Regs do
begin
AX := $7141;
DS := Seg(T.FullName);
DX := Ofs(T.FullName);
SI := 0;
Intr($21, Regs);
if Flags and fCarry <> 0 then InOutRes := AX
else InOutRes := 0;
end;
end;
procedure lEraseText(var T: lText);
begin
case T.AssignTextMode of
lDOS: Erase(T.T);
lWIN95: lWIN95EraseText(T);
{ Other APIs will be added later }
end;
end;
(*
INT 21h AX=7156
INT 21 - Windows95 - LONG FILENAME - RENAME FILE
AX = 7156h
DS:DX -> ASCIZ old file or directory name (long names allowed)
ES:DI -> ASCIZ new name (long names allowed)
Return: CF clear if successful
CF set on error
AX = error code
7100h if function not supported
Note: the file may be renamed into a different directory,
but not across disks
*)
procedure lWIN95RenameFile(var F: lFile; const NewName: String);
var
Regs: Registers;
NameZ: TNameZ;
begin
NameToNameZ(NewName, NameZ);
with Regs do
begin
AX := $7156;
DS := Seg(F.FullName);
DX := Ofs(F.FullName);
ES := Seg(NameZ);
DI := Ofs(NameZ);
Intr($21, Regs);
if Flags and fCarry <> 0 then InOutRes := AX
else InOutRes := 0;
end;
end;
procedure lRenameFile(var F: lFile; const NewName: String);
begin
case F.AssignFileMode of
lDOS: Rename(F.F, NewName);
lWIN95: lWIN95RenameFile(F, NewName);
{ Other APIs will be added later }
end;
end;
procedure lWIN95RenameText(var T: lText; const NewName: String);
var
Regs: Registers;
NameZ: TNameZ;
begin
NameToNameZ(NewName, NameZ);
with Regs do
begin
AX := $7156;
DS := Seg(T.FullName);
DX := Ofs(T.FullName);
ES := Seg(NameZ);
DI := Ofs(NameZ);
Intr($21, Regs);
if Flags and fCarry <> 0 then InOutRes := AX
else InOutRes := 0;
end;
end;
procedure lRenameText(var T: lText; const NewName: String);
begin
case T.AssignTextMode of
lDOS: Rename(T.T, NewName);
lWIN95: lWIN95RenameText(T, NewName);
{ Other APIs will be added later }
end;
end;
(*
INT 21h AX=7143
INT 21 - Windows95 - LONG FILENAME - EXTENDED GET/SET FILE ATTRIBUTES
AX = 7143h
DS:DX -> ASCIZ filename
BL = action
00h retrieve attributes
Return: CX = file attributes
01h set attributes
CX = attributes
02h get physical size of compressed file
Return: DX:AX = actual disk usage of file, in bytes
03h set last write date/time
DI = new last-write date
CX = new last-write time
04h get last write date/time
Return: CX = last write time
DI = last write date
05h set last access date
DI = new last-access date
06h get last access date
Return: DI = last access date
07h set creation date/time
DI = new creation date
CX = new creation time
SI = hundredths
(10-millisecond units past time in CX, 0-199)
08h get creation date/time
Return: CX = creation time
DI = creation date
SI = hundredths
(10-millisecond units past time in CX)
Return: CF clear if successful
CF set on error
AX = error code
7100h if function not supported
*)
const
faGetAttr = 0;
faSetAttr = 1;
procedure lWIN95FileAttrFunc(var F: lFile; var Attr: Word; Action: Byte);
var
Regs: Registers;
begin
with Regs do
begin
AX := $7143;
BL := Action;
if Action = faSetAttr then CX := Attr;
DS := Seg(F.FullName);
DX := Ofs(F.FullName);
Intr($21, Regs);
if Flags and fCarry <> 0 then DosError := AX
else
begin
if Action = faGetAttr then Attr := CX;
DosError := 0;
end;
end;
end;
procedure lGetFAttr(var F: lFile; var Attr: Word);
begin
case F.AssignFileMode of
lDOS: GetFAttr(F.F, Attr);
lWIN95: lWIN95FileAttrFunc(F, Attr, faGetAttr);
{ Other APIs will be added later }
end;
end;
procedure lSetFAttr(var F: lFile; Attr: Word);
begin
case F.AssignFileMode of
lDOS: SetFAttr(F.F, Attr);
lWIN95: lWIN95FileAttrFunc(F, Attr, faSetAttr);
{ Other APIs will be added later }
end;
end;
procedure lWIN95TextAttrFunc(var T: lText; var Attr: Word; Action: Byte);
var
Regs: Registers;
begin
with Regs do
begin
AX := $7143;
BL := Action;
if Action = faSetAttr then CX := Attr;
DS := Seg(T.FullName);
DX := Ofs(T.FullName);
Intr($21, Regs);
if Flags and fCarry <> 0 then DosError := AX
else
begin
if Action = faGetAttr then Attr := CX;
DosError := 0;
end;
end;
end;
procedure lGetTAttr(var T: lText; var Attr: Word);
begin
case T.AssignTextMode of
lDOS: GetFAttr(T.T, Attr);
lWIN95: lWIN95TextAttrFunc(T, Attr, faGetAttr);
{ Other APIs will be added later }
end;
end;
procedure lSetTAttr(var T: lText; Attr: Word);
begin
case T.AssignTextMode of
lDOS: SetFAttr(T.T, Attr);
lWIN95: lWIN95TextAttrFunc(T, Attr, faSetAttr);
{ Other APIs will be added later }
end;
end;
(*