home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Bila Vrana
/
BILA_VRANA.iso
/
005A
/
4UTILS85.ZIP
/
4DESC.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1995-05-07
|
39KB
|
1,108 lines
PROGRAM FileDescEditor;
{$A+,B-,D-,E-,F-,G+,L+,N-,O-,R+,S+,V-,X-}
{$M 8192,0,655360}
(* ----------------------------------------------------------------------
A Simple 4DOS File Description Editor
(c) 1992, 1993 Copyright by
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 program is freeware: you are allowed to use, copy
and change it free of charge, but you may not sell or hire
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.
----------------------------------------------------------------------- *)
USES {$IFOPT G+} Test286, {$ENDIF}
Fix, Crt, Dos, Memory, Drivers,
StringDateHandling, DisplayKeyboardAndCursor, HandleINIFile,
DescriptionHandling, dmouse;
CONST DelimiterTable : STRING = ',.();:-!?/[]{}+*=''`"@%&$_£';
VAR EdStart : BYTE; (* column where the description starts *)
ActDir : DirStr; (* current directory *)
StartDir : DirStr; (* directory where we started from *)
ResetDir : BOOLEAN; (* TRUE = return to StartDir on exit *)
StartIndex : INTEGER; (* index of entry at the top of the screen *)
Index : INTEGER; (* index of entry we are editing *)
CutPasteDesc: DescStr; (* cut, resp. pasted description *)
Changed : BOOLEAN; (* TRUE=the descriptions have been edited *)
IORes : INTEGER;
NewDir : DirStr; (* temporary storage for a directory path, *)
NewName : NameExtStr;(* used by view and others *)
FirstParam : STRING[8];
i : BYTE; (* variable for counting (index etc) *)
ShowHelp : BOOLEAN; (* TRUE = start in help mode [/h] *)
Querier : BOOLEAN; (* TRUE = ask user if he wants to save
the descriptions [/dontask] *)
PasteMovesToNextIndex: BOOLEAN; (* TRUE = Paste advances to next index *)
Overwrite : BOOLEAN; (* overwrite / Insert mode *)
s : STRING; (* temporary string variable *)
(*-------------------------------------------------------- Display-Routines *)
PROCEDURE DisplayFileEntry(Index: INTEGER; ox, x: BYTE;
Selection, Hilighted: BOOLEAN);
(* Displays the Index'th file entry. If the description is longer than
DispLen characters, DispLen characters - starting at character x of the
description - will be shown. (this feature is needed for scrolling).
Hilighted = TRUE will hilight the description.
When Selection is TRUE, we want to display the text we just put into
the buffer, ox (old x) gives us the start of the selection.
P.S. Scrolling implies hilighting, but this fact has not been exploited. *)
VAR FileEntry : PFileData;
xs,oxs,t : BYTE;
y,l : BYTE;
s : STRING;
BEGIN
y := 3+Index-StartIndex;
IF (Index >= 0) AND (Index < FileList^.Count) THEN
BEGIN
FileEntry := NILCheck(FileList^.At(Index));
IF x <= DispLen THEN xs := 1
ELSE
IF x <= 2*DispLen THEN xs := DispLen+1
ELSE
IF x <= 3*DispLen THEN xs := 2*DispLen+1
ELSE
IF x <= 4*DispLen THEN xs := 3*DispLen+1
ELSE xs := 4*DispLen+1;
(* I haven't found a simple formula yet, so I'm doing the
job with a table. That's the lazy's man solution .... *)
IF ox <= DispLen THEN oxs := 1
ELSE
IF ox <= 2*DispLen THEN oxs := DispLen+1
ELSE
IF ox <= 3*DispLen THEN oxs := 2*DispLen+1
ELSE
IF ox <= 4*DispLen THEN oxs := 3*DispLen+1
ELSE oxs := 4*DispLen+1;
IF Hilighted THEN
BEGIN TextColor(SelectFg); TextBackGround(SelectBg); END
ELSE
BEGIN
TextBackGround(NormBg);
IF FileEntry^.IsADir THEN TextColor(DirFg)
ELSE TextColor(NormFg)
END;
GotoXY(1,y);
s := FileEntry^.FormatScrollableDescription(xs,DispLen);
IF Selection THEN
BEGIN
IF ox > x THEN BEGIN t := x; x := ox; ox := t; END
ELSE t := x;
IF ox < xs THEN ox := xs;
Write(Copy(s,1,EdStart+ox-xs-1));
TextBackGround(NormFg); TextColor(NormBg); Write(Copy(s,EdStart+ox-xs,x-ox));
TextBackGround(SelectBg);TextColor(SelectFg); Write(Copy(s,EdStart+x-xs,255));
x := t;
END
ELSE Write(s);
l := Length(FileEntry^.GetDesc);
IF l-xs < DispLen THEN
ClrEol
ELSE
BEGIN
TextColor(WarnFg); Write(Chr(16)); TextColor(NormFg);
END;
(* IF x <= DispLen THEN GotoXY(EdStart+x-1,y)
ELSE GotoXY(EdStart+DispLen-1,y) *)
GotoXY(EdStart+x-xs,y);
END
ELSE BEGIN GotoXY(1,y); ClrEol; END;
END; (* DisplayFileEntry *)
PROCEDURE DrawDirLine(UpdateDir: BOOLEAN);
(* Draw the line, which tells us where in the directory tree we are. *)
BEGIN
IF UpdateDir THEN
BEGIN
GetDir(0,ActDir);
IF ActDir[Length(ActDir)] <> '\' THEN ActDir := ActDir + '\';
UpString(ActDir);
END;
TextColor(DirFg); TextBackGround(NormBg);
GotoXY(1,2); Write(ActDir); ClrEol;
END; (* DrawDirLine *)
PROCEDURE ReDrawScreen;
(* Redraws the full screen, needed after shelling out or after printing
the help screen. *)
VAR Index: INTEGER;
BEGIN
(* GetDir(0,ActDir); *)
FOR Index := StartIndex TO StartIndex+MaxLines-4 DO
DisplayFileEntry(Index,0,1,FALSE,FALSE);
END; (* ReDrawScreen *)
(*-------------------------------------------------------- Read-Directory *)
PROCEDURE ReadFiles;
(* Scan the current directory and read in the DESCRIPT.ION file. Build a
file list database and associate the right description.
Warn the user if there are too long descriptions or if there are too
much descriptions. *)
VAR i : BYTE;
ch : WORD;
Dir : PathStr;
BEGIN
Changed := FALSE;
DescLong := FALSE;
Index := 0;
StartIndex := 0;
Dir := FExpand('.');
IF FileList <> NIL THEN
BEGIN
Dispose(FileList,Done); FileList := NIL;
END;
TextColor(StatusFg); TextBackGround(StatusBg);
GotoXY(1,MaxLines);
IF (ScreenWidth-39-Length(Dir)) > 0 THEN
Write(Chars(' ',(ScreenWidth-39-Length(Dir)) DIV 2));
Write('Scanning directory ',Dir,' ..... please wait.');
ClrEol;
FileList := NIL; FileList := New(PFileList,Init(Dir,'*.*',0));
IF FileList = NIL THEN Abort('Unable to allocate FileList');
IF (FileList^.Status = ListTooManyFiles) OR
(FileList^.Status = ListOutofMem) THEN
BEGIN
TextColor(NormFg); TextBackGround(NormBg);
FOR i := 3 TO MaxLines-1 DO
BEGIN
GotoXY(1,i); ClrEol;
END;
IF FileList^.Status = ListTooManyFiles THEN
ReportError('Warning! Too many files in directory, description file will be truncated! (Key)',(CutPasteDesc <> ''),Changed)
ELSE
ReportError('Warning! Out of memory, description file will be truncated! (Key)',(CutPasteDesc <> ''),Changed);
END;
IF FileList^.Count > 0 THEN
BEGIN
DrawMainScreen(Index,FileList^.Count,1,0); DrawDirLine(TRUE);
END;
IF DescLong THEN
BEGIN
TextColor(NormFg); TextBackGround(NormBg);
FOR i := 3 TO MaxLines-1 DO
BEGIN
GotoXY(1,i); ClrEol;
END;