home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Bila Vrana
/
BILA_VRANA.iso
/
005A
/
4UTILS85.ZIP
/
DESCRIPT.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1995-05-07
|
22KB
|
692 lines
UNIT DescriptionHandling;
{$L+,X+,V-}
(* ----------------------------------------------------------------------
Part of 4DESC - A Simple 4DOS File Description Editor
and 4FF - 4DOS File Finder
David Frey, & Tom Bowden
Urdorferstrasse 30 1575 Canberra Drive
8952 Schlieren ZH Stone Mountain, GA 30088-3629
Switzerland USA
Code created using Turbo Pascal 7.0 (c) Borland International 1992
DISCLAIMER: This unit is freeware: you are allowed to use, copy
and change it free of charge, but you may not sell or hire
this part of 4DESC. The copyright remains in our hands.
If you make any (considerable) changes to the source code,
please let us know. (send a copy or a listing).
We would like to see what you have done.
We, David Frey and Tom Bowden, the authors, provide absolutely
no warranty of any kind. The user of this software takes the
entire risk of damages, failures, data losses or other
incidents.
This unit stores/retrieves the file data and descriptions by using
a TCollection (a Turbo Vision Object).
----------------------------------------------------------------------- *)
INTERFACE USES Objects, Dos, StringDateHandling;
CONST MaxDescLen = 200; (* 4DOS maximum description length *)
DirSize = ' <DIR> ';
CONST SortByName = 1;
SortByExt = 2;
SortBySize = 3;
SortByDate = 4;
SortByNameRev = 5;
SortByExtRev = 6;
SortBySizeRev = 7;
SortByDateRev = 8;
TYPE NameExtStr = STRING[1+8+1+3];
SizeStr = STRING[9];
DescStr = STRING[MaxDescLen];
ProgInfo = STRING;
SortKeyStr = STRING[14];
VAR DescLong : BOOLEAN;
DispLen : BYTE;
Template : STRING;
TYPE PFileData = ^TFileData;
TFileData = OBJECT(TObject)
IsADir : BOOLEAN;
Name : NameStr;
Ext : ExtStr;
Size : LONGINT;
DateRec : DateTime;
Attr : BYTE;
ProgInfo : PString; (* ^STRING; *)
Desc : PString; (* ^DescStr; *)
CONSTRUCTOR Init(Search: SearchRec);
CONSTRUCTOR AssignValues(AnIsADir: BOOLEAN;
AName : NameStr; AnExt: ExtStr;
ASize : LONGINT; ADateRec: DateTime;
AnAttr: BYTE; AProgInfo: STRING;
ADesc : DescStr);
DESTRUCTOR Done; VIRTUAL;
PROCEDURE AssignDesc(ADesc: DescStr);
PROCEDURE AssignProgInfo(AProgInfo: STRING);
FUNCTION GetDesc: DescStr;
FUNCTION GetProgInfo: STRING;
FUNCTION FormatScrollableDescription(off,len: BYTE): STRING;
END;
CONST ListOK = 0;
ListTooManyFiles = 1;
ListOutOfMem = 2;
TYPE PFileList = ^TFileList;
TFileList = OBJECT(TSortedCollection)
Status : BYTE;
MaxFileLimit: WORD;
CONSTRUCTOR Init(Path: PathStr; FileMask: NameExtStr;
ALimit: INTEGER);
FUNCTION Compare(key1,key2: POINTER): INTEGER; VIRTUAL;
END;
(* these constants are used for the new Justification entry in 4UTILS.INI *)
CONST Left = 0;
LeftLeft = 1;
RightLeft = 2;
VAR Justify : BYTE;
FullSize : BOOLEAN;
UseHidden: BOOLEAN;
VAR FileList : PFileList;
SortKey : BYTE;
PROCEDURE Abort(msg: STRING);
FUNCTION NILCheck(APtr: POINTER): POINTER;
(* APtr = NIL ? If yes, give a fatal error message and abort. *)
PROCEDURE ResortFileList;
(* Resorts the current File List *)
PROCEDURE EvaluateINIFileSettings;
IMPLEMENTATION USES Memory, Drivers,
HandleINIFile;
(* Allocate a 2KB text buffer for faster reads of DESCRIPT.ION *)
VAR Buffer: ARRAY[1..2048] OF CHAR;
VAR HelpStr1 : DescStr;
HelpStr2 : SizeStr;
HelpStr3 : NameExtStr;
PROCEDURE Abort(msg: STRING);
(* Fatal error, abort the program and return an errorlevel of -1 *)
BEGIN
(* NormVideo;
ClrScr; *)
Write(msg);
HALT(255);
END;
{$F+}
FUNCTION HeapFunc(Size: WORD): INTEGER;
(* This is Turbo Pascal Heap Function, which is called whenever the heap
manager is unable to complete an allocation request. *)
BEGIN
HeapFunc := 1; (* Return NIL if out of heap *)
END;
{$F-}
FUNCTION NILCheck(APtr: POINTER): POINTER;
(* Aborts when a NIL pointer has been detected. This prevents
deferencing a NIL pointer, which could be catastrophic
(spontaneous rebooting etc.) *)
BEGIN
IF APtr = NIL THEN Abort('NIL Pointer detected!')
ELSE NILCheck := APtr;
END;
(*---------------------------------------------------------------------*)
(* The real work starts here. *)
CONSTRUCTOR TFileData.Init(Search: SearchRec);
(* Regular Constructor method. Constructs a FileData "object" on
the heap and fills in the appropriate values.
Called from TFileList.Init *)
VAR TimeRec : DateTime;
Dir : DirStr;
s : STRING;
BEGIN
TObject.Init;
FSplit(Search.Name,Dir,Name,Ext);
UnpackTime(Search.Time,DateRec);
Attr := Search.Attr;
ProgInfo := NIL;
Desc := NIL;
Size := Search.Size;
IsADir := (Search.Attr AND Directory = Directory);
IF IsADir THEN
IF (Name = '') THEN (* Name = '' holds for the . and .. entries *)
BEGIN
Name := UpStr(Ext); Ext := '';
END
ELSE
BEGIN
UpString(Name); UpString(Ext);
END;
END;
CONSTRUCTOR TFileData.AssignValues(AnIsADir: BOOLEAN;
AName : NameStr; AnExt: ExtStr;
ASize : LONGINT; ADateRec: DateTime;
AnAttr: BYTE; AProgInfo: STRING;
ADesc : DescStr);
(* Alternate Constructor method. Constructs a FileData "object" on
the heap and fills in the appropriate values.
Called form ReSortFileList when re-sorting a file list. *)
BEGIN
TObject.Init;
IsADir := AnIsADir;
Name := AName; Ext := AnExt; Size := ASize; DateRec := ADateRec;
Attr := AnAttr;
ProgInfo := NIL; ProgInfo := NewStr(AProgInfo);
Desc := NIL; Desc := NewStr(ADesc);
END;
DESTRUCTOR TFileData.Done;
(* Removes a FileData object from the heap. *)
BEGIN
DisposeStr(ProgInfo); ProgInfo := NIL;
DisposeStr(Desc); Desc := NIL;
TObject.Done;
END;
PROCEDURE TFileData.AssignDesc(ADesc: DescStr);
(* Dynamic version of "Desc := ADesc" *)
BEGIN
IF Desc <> NIL THEN BEGIN DisposeStr(Desc); Desc := NIL; END;
Desc := NewStr(ADesc);
IF (ADesc <> '') AND (Desc = NIL) THEN
Abort('AssignDesc: NIL Pointer detected!')
END;
PROCEDURE TFileData.AssignProgInfo(AProgInfo: STRING);
(* Dynamic version of "ProgInfo := AProgInfo" *)
BEGIN
IF ProgInfo <> NIL THEN BEGIN DisposeStr(ProgInfo); ProgInfo := NIL; END;
ProgInfo := NewStr(AProgInfo);
IF (AProgInfo <> '') AND (ProgInfo = NIL) THEN
Abort('AssignProgInfo: NIL Pointer detected!')
END;
FUNCTION TFileData.GetDesc: DescStr;
(* Returns the description of a file *)
BEGIN
IF Desc <> NIL THEN GetDesc := Desc^
ELSE GetDesc := '';
END;
FUNCTION TFileData.GetProgInfo: STRING;
(* Returns the program information *)
BEGIN
IF ProgInfo <> NIL THEN GetProgInfo := ProgInfo^
ELSE GetProgInfo := '';
END;
FUNCTION TFileData.FormatScrollableDescription(off,len: BYTE): STRING;
(* Formats a d