home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Bila Vrana
/
BILA_VRANA.iso
/
005A
/
4UTILS85.ZIP
/
4FF.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1995-05-07
|
18KB
|
555 lines
PROGRAM FileFind;
{$A+,B-,D-,E-,F-,G+,I-,L+,N-,O-,R-,S-,V-,X-}
{$M 16384,0,655360}
(* ----------------------------------------------------------------------
A 4DOS-aware file finder. It searches in various archives too.
(c) 1992, 1994 Copyright by David Frey,
Urdorferstrasse 30
8952 Schlieren ZH
Switzerland
Code created using Turbo Pascal 6.0 (c) Borland International 1990
DISCLAIMER: This program is freeware: you are allowed to use, copy
and change it free of charge, but you may not sell or hire
4FF. The copyright remains in my hands.
If you make any (considerable) changes to the source code,
please let me know. (send me a copy or a listing).
I would like to see what you have done.
I, David Frey, the author, provide absolutely no warranty of
any kind. The user of this software takes the entire risk of
damages, failures, data losses or other incidents.
NOTES: Turbo Pascal 6.0 required for compiling. (sorry, but I'm
using FormatStr for output)
ENHANCEMENTS: adapted to 4DOS 4.01 - when redirecting into files,
full descriptions will be shown, otherwise the
descriptions will be truncated at the right screen margin.
paging switch (/p) added.
Fast screen output when no redirected output has been used.
Searches for Read Only / Hidden directories, too.
ARJ File scanning added.
Supports now 4DOS 5.0, i.e. 200 characters description
length.
Old /d switch renamed to /f. /d stands now for description.
----------------------------------------------------------------------- *)
USES {$IFOPT G+} Test286, {$ENDIF}
Fix, Crt, Dos, Objects, Memory, Drivers,
StringDateHandling, DisplayKeyboardAndCursor, DescriptionHandling,
HandleINIFile,
ScanLZHFiles, ScanZIPFiles, ScanARJFiles, Globals;
CONST Header= '4FF 4DOS File Find 1.85 -- (c) David Frey 1992, 1995';
VAR ActDir, StartDir : STRING;
FileSpecArray : FileSpecArrayType;
DescFile : TEXT;
DescLine : STRING;
DescLineNr : WORD;
Desc : DescStr;
DescStart : BYTE;
DescEnd : BYTE;
DescFound : BOOLEAN;
i,l : WORD;
k : BYTE;
FileSpecs : BYTE;
ps,fs : STRING;
IORes : INTEGER;
Templ : STRING;
FormatTemplate : STRING;
OldCtrlBreakHandler : POINTER;
OldCtrlBreakState : BOOLEAN;
BrokeOut : BOOLEAN;
PROCEDURE MyCtrlBreakHandler; FAR;
BEGIN
ExitProc := OldCtrlBreakHandler; SetCBreak(OldCtrlBreakState);
{$I-}
ChDir(ActDir); IORes := IOResult;
IF BrokeOut THEN
BEGIN
WriteLn(Output);
WriteLn(Output,' EXITING - User broke out of program.');
WriteLn(Output);
END;
Close(Output);
IF NOT Redirected THEN NormVideo;
END;
PROCEDURE ShowFileData(Item: PFileData; VAR Path: PathStr);
VAR Index: INTEGER;
Date : DateStr;
Time : TimeStr;
BEGIN
IF BareOutput THEN
WriteLn(Output,Path,'\',Item^.Name)
ELSE
BEGIN
IF FileCount = 0 THEN
BEGIN
WriteLn(Output); IF DoPage THEN TestForMoreMsg;
WriteLn(Output,Path,'\'); IF DoPage THEN TestForMoreMsg;
END;
InfoArray[0] := @Item^.Name;
InfoArray[1] := @Item^.Ext;
IF Item^.Attr AND Directory = Directory THEN SizeStr := '<DIR>'
ELSE
SizeStr := FormattedLongIntStr(Item^.Size,10);
InfoArray[2] := @SizeStr;
Date := FormDate(Item^.DateRec); InfoArray[3] := @Date;
Time := FormTime(Item^.DateRec); InfoArray[4] := @Time;
AttrStr := '....';
IF Item^.Attr AND ReadOnly = ReadOnly THEN AttrStr[1] := 'r';
IF Item^.Attr AND Hidden = Hidden THEN AttrStr[2] := 'h';
IF Item^.Attr AND SysFile = SysFile THEN AttrStr[3] := 's';
IF Item^.Attr AND Archive = Archive THEN AttrStr[4] := 'a';
InfoArray[5] := @AttrStr;
InfoArray[6] := Item^.Desc;
FormatStr(s,FormatTemplate,InfoArray);
WriteLn(Output,s); IF DoPage THEN TestForMoreMsg;
INC(TotalSize,Item^.Size); INC(DirSize,Item^.Size);
INC(TotalFileCount); INC(FileCount);
END;
END; (* ShowFileData *)
PROCEDURE BuildList(Dir: DirStr; VAR FileSpec: FileSpecArrayType; FileSpecs: BYTE;
Attr: BYTE);
(* The starting point, dir, includes the drive *)
VAR Search: SearchRec;
DescFileExists: BOOLEAN;
DescFileList : PFileList;
l,i,k : BYTE;
PROCEDURE ExamineFile(Item: POINTER); FAR;
(* Print the file data, if the Attributes match *)
BEGIN
IF (((searchdesc = '') AND
(NOT ExactAttr OR
(ExactAttr AND (PFileData(Item)^.Attr = Attr)))) OR
(Pos(searchdesc,PFileData(Item)^.Desc^) > 0)) THEN
ShowFileData(PFileData(Item),Dir);
END;
BEGIN (* BuildList *)
FileCount := 0; DirSize := 0;
Attr := Attr AND NOT Directory AND NOT VolumeId;
OldLHFileName := ''; OldZipFileName := '';
s := Dir; l := Length(s);
IF (l>3) AND (s[l] = '\') THEN Delete(s,l,1);
l := Length(Dir); IF (s[l] = '\') THEN Delete(Dir,l,1);
{$I-}
ChDir(s); IORes := IOResult;
{$I+}
FOR k := 1 TO FileSpecs DO
BEGIN
DescFileList := NIL; DescFileList := New(PFileList,Init(Dir,FileSpec[k],0));
IF DescFileList = NIL THEN Abort('Unable to allocate DescFileList');
IF (FileList^.Status = ListTooManyFiles) OR
(FileList^.Status = ListOutofMem) THEN
BEGIN
IF FileList^.Status = ListTooManyFiles THEN
WriteLn('Warning! Too many files in directory, description file will be truncated!')
ELSE
WriteLn('Warning! Out of memory, description file will be truncated!');
END;
IF DescLong THEN
WriteLn('Warning! Some descriptions are too long; they will be truncated.');
DescFileList^.ForEach(@ExamineFile);
Dispose(DescFileList,Done);
END;
IF ScanLZHArchives THEN
BEGIN
FindFirst('????????.LZH',ReadOnly+Archive,Search);
WHILE DosError = 0 DO
BEGIN
SearchInLZHFile(FileSpec,FileSpecs,Dir,Search);
FindNext(Search);
END;
END;
IF ScanZIPArchives THEN
BEGIN
FindFirst('????????.ZIP',ReadOnly+Archive,Search);
WHILE DosError = 0 DO
BEGIN
SearchInZIPFile(FileSpec,FileSpecs,Dir,Search);
FindNext(Search);
END;
END;
IF ScanARJArchives THEN
BEGIN
FindFirst('????????.ARJ',ReadOnly+Archive,Search);
WHILE DosError = 0 DO
BEGIN
SearchInARJFile(FileSpec,FileSpecs,Dir,Search);
FindNext(Search);
END;
END;
IF NOT BareOutput AND (FileCount > 0) THEN
BEGIN
Templ := '%-4s entr';
IF FileCount = 1 THEN Templ := Templ + 'y, '
ELSE Templ := Templ + 'ies,';
Templ := Templ+' %10s Bytes';
FileStr := FormattedIntStr(FileCount,4); InfoArray[0] := @FileStr;
SizeStr := FormattedLongIntStr(DirSize,10); InfoArray[1] := @SizeStr;
FormatStr(s,Templ,InfoArray);
WriteLn(Output,s); IF DoPage THEN TestForMoreMsg;
END;
FindFirst('????????.???',Directory+ReadOnly+Hidden+SysFile,Search);
WHILE DosError = 0 DO
BEGIN
IF (Search.Attr AND Directory = Directory) AND
(Search.Name <> '.') AND (Search.Name <> '..') THEN
BuildList(Dir+'\'+Search.Name+'\',FileSpec,FileSpecs,Attr);
FindNext(Search);
END;
{$I-}
ChDir('..'); IORes := IOResult;
{$I+}
END; (* BuildList *)
FUNCTION DriveValid(C: CHAR): BOOLEAN; ASSEMBLER;
ASM
M