home *** CD-ROM | disk | FTP | other *** search
- {$R+,S+,I-,D+,T-,F-,V-,B-,N-,L+ }
- {$M 16384,0,655360 }
- {############################## PullDir.PAS #################################}
-
- Unit PullDir;
-
- Interface
-
- Uses Dos,
- TPDos,
- TPCrt,
- TPMenu,
- TPEdit,
- TPString,
- PullVar;
-
- TYPE
- FrameCharType = (ULeft,LLeft,MLeft,URight,LRight,MRight,MTop,MBot,Horiz,Vert);
- FrameArray = Array[FrameCharType] of Char;
-
- CONST
- ON : Boolean= True;
- OFF : Boolean= False;
- Frame1 : FrameArray = '╔╚╞╗╝╡╦╩═║';
-
- VAR Z: Byte; { global loop variable }
-
- FUNCTION GetDirectory(VAR Mask,Name: String): Word;
- PROCEDURE Beep(Freq,Del: Integer);
- PROCEDURE HorizontalLine(HrzChar: char; LeftCol,LeftRow,Width,Color: Byte);
- PROCEDURE VerticalLine(VrtChar: char; TopCol,TopRow,Depth,Color: Byte);
-
- Implementation
-
- PROCEDURE Beep{(Freq,Del: Integer)};
- BEGIN
- sound(Freq);
- delay(del);
- nosound;
- END;
-
- PROCEDURE HorizontalLine{(HrzChar: char; LeftCol,LeftRow,Width,Color: Byte)};
- BEGIN
- FastWrite(Frame1[MLeft],LeftRow,LeftCol,Color);
- For Z:=1 to Width-2 do FastWrite(Frame1[Horiz],LeftRow,LeftCol+Z,Color);
- FastWrite(Frame1[MRight],LeftRow,LeftCol+Z+1,Color);
- END;
-
- PROCEDURE VerticalLine{(VrtChar: char; TopCol,TopRow,Depth,Color: Byte)};
- BEGIN
- FastWrite(Frame1[MTop],TopRow,TopCol,Color);
- For Z:=1 to Depth-2 do BEGIN
- FastWrite(Frame1[Vert],TopRow+Z,TopCol,Color);
- END;
- FastWrite(Frame1[MBot],TopRow+Z+1,TopCol,Color);
- END;
-
- FUNCTION GetDirectory{(VAR Mask: St80; VAR Name: St15): Word};
- { Main function that will return the most recent searching mask and the
- filename selected. It returns the key pressed along with its scan code
- for specific command implementation. }
-
- CONST
- cl : Byte = 1;
- ln : Byte = 1;
- hg : Byte = 25;
- wd : Byte = 80;
- CR : Char = ^M;
- ESC : Char = ^[;
-
- TYPE
- DPtr = ^DirDat;
- DirDat= Record { record of directory entry }
- DName: String[8];
- DExt: String[4];
- DSize: String[7];
- DDate: String[8];
- DTime: String[7];
- Next: DPtr;
- Prev: DPtr;
- END;
-
-
- VAR
- DCol,DRow,Col,Row,DotPos,H: Byte;
- DirRec: DirDat;
- HeadPtr,TailPtr,TempPtr,
- ThisPtr,PagePtr,ShowPtr: DPtr; { pointers to directory entries }
- SRec: SearchRec;
- TName: String[12];
- TExt: String[4];
- DT: DateTime;
- Pm: String[2];
- DKey,FuncKey: Word;
- Escaped,DoRead,DirDone: Boolean;
- InPath,ScPath,LdPath: String[80];
- MaxLin,BotLin: Byte;
-
- PROCEDURE PutScreen; { Draws main screen }
- VAR PAttr: Byte;
- BEGIN
- ClrScr;
- FrameWindow(cl,ln,wd,hg,Clr1[Bor],Clr1[Tit],'');
- HorizontalLine('S',cl,ln+2,wd,Clr1[Bor]);
- HorizontalLine('S',cl,ln+22,wd,Clr1[Bor]);
- VerticalLine('S',cl+45,ln+2,hg-4,Clr1[Bor]);
- For Z:=Row to Row+18 do ChangeAttribute(44,Z,Col-1, Clr1[Bk1]);
- For Z:=Row to Row+18 do ChangeAttribute(33,Z,Col+44,Clr1[Bk2]);
- For Z:=1 to 19 do BEGIN
- Case Z of
- 1..3: PAttr:=Clr1[Nor];
- 4: PAttr:=Clr1[Tit];
- 5..13: PAttr:=Clr1[Key];
- 14..19: PAttr:=Clr1[Cmd];
- End;
- FastWrite(EditArray[Z],Z+3,Col+44,PAttr);
- END;
- END;
-
- PROCEDURE PutDir(APtr: DPtr; Col,Row: Byte; Bar: Boolean);
- { Writes a single directory entry to screen }
-
- CONST EmpStr: String = ' ';
- VAR TempStr: String;
- BEGIN
- If Not Bar then With APtr^ do BEGIN
- FastWrite(EmpStr,Row,Col-1,Clr1[Bk1]);
- FastWrite(DName,Row,Col+ 1,Clr1[Nam]);
- FastWrite(DExt, Row,Col+10,Clr1[Ext]);
- If DSize=' <DIR>' then FastWrite(DSize,Row,Col+15,Clr1[Dir])
- ELSE FastWrite(DSize,Row,Col+15,Clr1[Siz]);
- FastWrite(DDate,Row,Col+24,Clr1[Dat]);
- FastWrite(DTime,Row,Col+34,Clr1[Tim]);
- END ELSE With APtr^ do BEGIN
- TempStr:=' '+DName+' '+DExt+' '+DSize+' '+DDate+' '+DTime+' ';
- FastWrite(TempStr,Row,Col,Clr1[Sel]);
- END;
- END;
-
- PROCEDURE PutPage(PPtr: DPtr; PCol,PRow: Byte);
- { Writes a one page of directory entries to screen }
- BEGIN
- While PRow<BotLin+1 do BEGIN
- If PPtr<>NIL then BEGIN
- PutDir(PPtr,PCol,PRow,OFF);
- PPtr:=PPtr^.Next;
- END ELSE FastWrite(Pad('',43),PRow,PCol,Clr1[Bk1]);
- PRow:=Succ(PRow);
- END;
- END;
-
- FUNCTION PutLead(I: Byte): String;
- BEGIN
- If I >= 10 THEN PutLead:=Long2Str(I)
- Else PutLead:='0'+Long2Str(I);
- END;
-
- PROCEDURE NewRec( VAR NewPtr: DPtr);
- BEGIN
- NEW (NewPtr);
- NewPtr^.Next := NIL;
- NewPtr^.Prev := NIL;
- END;
-
- PROCEDURE NewBefore (VAR HeadPtr, TailPtr, SPtr, TempPtr: DPtr);
- { Inserts an entry in front of SPtr position }
-
- VAR PrevP: DPtr;
- BEGIN
- IF (SPtr = NIL) THEN BEGIN
- HeadPtr := TempPtr;
- TailPtr := TempPtr;
- END
- ELSE BEGIN
- IF (SPtr = HeadPtr) THEN BEGIN
- SPtr^.Prev := TempPtr;
- TempPtr^.Next := SPtr;
- TempPtr^.Prev := NIL;
- HeadPtr := TempPtr;
- END
- ELSE BEGIN
- PrevP := SPtr^.Prev;
- TempPtr^.Prev := PrevP;
- TempPtr^.Next := SPtr;
- PrevP^.Next := TempPtr;
- SPtr^.Prev := TempPtr;
- END
- END;
- SPtr := TempPtr;
- END;
-
- PROCEDURE NewAfter (VAR HeadPtr, TailPtr, SPtr, TempPtr: DPtr);
- { Inserts an entry after SPtr position }
-
- VAR NextP : DPtr;
- BEGIN
- IF (SPtr = NIL) THEN BEGIN
- HeadPtr := TempPtr;
- TailPtr := TempPtr;
- END
- ELSE BEGIN
- IF (SPtr = TailPtr) THEN BEGIN
- SPtr^.Next := TempPtr;
- TempPtr^.Prev := SPtr;
- TempPtr^.Next := NIL;
- TailPtr := TempPtr;
- END
- ELSE BEGIN
- NextP := SPtr^.Next;
- TempPtr^.Next := NextP;
- TempPtr^.Prev := SPtr;
- NextP^.Prev := TempPtr;
- SPtr^.Next := TempPtr;
- END
- END;
- SPtr := TempPtr;
- END;
-
- PROCEDURE SortDir(TempPtr: DPtr); { Sorts entries as they are loaded }
- VAR SPtr: DPtr;
- Done: Boolean;
- DStr,SStr: String;
-
- PROCEDURE Insert(VAR SPtr,TempPtr: DPtr; Place: Char);
- BEGIN
- If Place='A' THEN NewAfter(HeadPtr,TailPtr,SPtr,TempPtr) ELSE
- If Place='H' THEN NewBefore(HeadPtr,TailPtr,HeadPtr,TempPtr) ELSE
- NewBefore(HeadPtr,TailPtr,SPtr,TempPtr);
- Done:=TRUE;
- END;
-
- BEGIN
- Done:=FALSE;
- SPtr:=TailPtr;
- If (SPtr=NIL) THEN BEGIN
- HeadPtr:=TempPtr;
- TailPtr:=TempPtr;
- ThisPtr:=TempPtr;
- Done:=TRUE;
- END ELSE BEGIN
- While (SPtr<>NIL) and (not Done) do BEGIN
- DStr:=TempPtr^.DName+TempPtr^.DExt;
- SStr:=SPtr^. DName+SPtr^. DExt;
- If CompUCString(DStr,SStr)= Greater then Insert(SPtr,TempPtr,'A')
- ELSE SPtr:=SPtr^.Prev;
- END;
- END;
- If not Done then Insert(HeadPtr,TempPtr,'B');
- END;
-
- FUNCTION LoadDir(Mask: String): Boolean;
- { Loads a given mask of directories }
-
- BEGIN
- If Mask <> '' THEN BEGIN
- HeadPtr:=NIL;
- TailPtr:=NIL;
- ThisPtr:=NIL;
- TempPtr:=NIL;
- FindFirst(Mask,AnyFile,SRec);
- If DosError=0 then While DosError = 0 do BEGIN
- NewRec(TempPtr);
- TName:=SRec.Name;
- DotPos:= Pos('.',TName);
- If DotPos <> 0 THEN BEGIN
- TExt:= '.'+Copy(TName,DotPos+1,Length(TName)-DotPos);
- Delete(TName,DotPos,1+Length(TName)-DotPos);
- END Else TExt:= '';
- TempPtr^.DName:=Pad(TName,8);
- TempPtr^.DExt:=Pad(TExt,4);
- If (SRec.Attr and Directory) <> 0 THEN TempPtr^.DSize:=' <DIR>'
- ELSE TempPtr^.DSize:=LeftPad(Long2Str(SRec.Size),7);
- UnpackTime(SRec.Time,DT);
- TempPtr^.DDate:=PutLead(DT.Month)+'-'+PutLead(DT.Day)+'-'+PutLead(DT.Year MOD 100);
- If DT.Hour >= 12 THEN Pm:= 'pm' Else Pm:= 'am';
- H:= DT.Hour MOD 12;
- If H= 0 THEN H:= 12;
- TempPtr^.DTime:=PutLead(H)+':'+PutLead(DT.Min)+Pm;
- SortDir(TempPtr);
- FindNext(SRec);
- LoadDir:=TRUE;
- END ELSE LoadDir:=FALSE;
- END;
- END;
-
- FUNCTION GetFile: Word; { Selects a filename or subdirectory }
- BEGIN
- DRow:=Row;
- DCol:=Col;
- PutPage(PagePtr,Col,Row);
- PutDir(ThisPtr,DCol,DRow,ON);
- REPEAT
- FuncKey:=ReadKeyWord;
- Case Chr(Lo(FuncKey)) of
- ^W: Hi(FuncKey):=71;
- ^Z: Hi(FuncKey):=79;
- ^R: Hi(FuncKey):=73;
- ^C: Hi(FuncKey):=81;
- ^E: Hi(FuncKey):=72;
- ^X: Hi(FuncKey):=80;
- END;
- Case Hi(FuncKey) of
- 71: BEGIN {Home}
- PagePtr:=HeadPtr;
- ThisPtr:=HeadPtr;
- DRow:=Row;
- END;
- 79: BEGIN {END}
- PagePtr:=TailPtr;
- DRow:=Row;
- For Z:=1 to MaxLin-1 do
- If PagePtr^.Prev<>NIL then BEGIN
- PagePtr:=PagePtr^.Prev;
- DRow:=Succ(DRow);
- END;
- ThisPtr:=TailPtr;
- END;
- 73: BEGIN {PgUp}
- For Z:=1 to MaxLin-1 do
- If PagePtr^.Prev<>NIL then BEGIN
- PagePtr:=PagePtr^.Prev;
- ThisPtr:=PagePtr;
- DRow:=Row;
- END;
- END;
- 81: BEGIN {PgDn}
- For Z:=1 to MaxLin-1 do
- If PagePtr^.Next<>NIL then BEGIN
- PagePtr:=PagePtr^.Next;
- ThisPtr:=PagePtr;
- DRow:=Row;
- END;
- If PagePtr^.Next=NIL then BEGIN
- DRow:=Row;
- For Z:=1 to MaxLin-1 do
- If PagePtr^.Prev<>NIL then BEGIN
- PagePtr:=PagePtr^.Prev;
- DRow:=Succ(DRow);
- END;
- ThisPtr:=TailPtr;
- END;
- END;
- 72: BEGIN {Up}
- If (ThisPtr^.Prev<>NIL) and (DRow>Row) then BEGIN
- PutDir(ThisPtr,DCol,DRow,OFF);
- ThisPtr:=ThisPtr^.Prev;
- DRow:=Pred(DRow);
- END ELSE If ThisPtr^.Prev<>NIL then BEGIN
- PutDir(ThisPtr,DCol,DRow,OFF);
- ScrollWindowDown(Col,Row,Col+42,BotLin,1);
- ThisPtr:=ThisPtr^.Prev;
- END;
- END;
- 80: BEGIN {Down}
- If (ThisPtr^.Next<>NIL) and (DRow<BotLin) then BEGIN
- PutDir(ThisPtr,DCol,DRow,OFF);
- ThisPtr:=ThisPtr^.Next;
- DRow:=Succ(DRow);
- END ELSE If ThisPtr^.Next<>NIL then BEGIN
- PutDir(ThisPtr,DCol,DRow,OFF);
- ScrollWindowUp(Col,Row,Col+42,BotLin,1);
- ThisPtr:=ThisPtr^.Next;
- END;
- END;
- END;
- If Hi(FuncKey) in [71,79,73,81] then PutPage(PagePtr,Col,Row);
- PutDir(ThisPtr,DCol,DRow,ON);
- UNTIL (Lo(FuncKey)=27) or (Lo(FuncKey)=13);
- GetFile:=FuncKey;
- END;
-
- PROCEDURE PutStat; { Shows disk & memory parameters }
- BEGIN
- FastWrite(Pad('',78),BotLin+2,Col-1,Clr1[Mem]);
- FastWrite(' Disk Size: ',BotLin+2,Col,Clr1[Mem]);
- FastWrite(Long2Str(DiskSize(0)),BotLin+2,Col+12,Clr1[Num]);
- FastWrite(' Disk Free: ',BotLin+2,Col+23,Clr1[Mem]);
- FastWrite(Long2Str(DiskFree(0)),BotLin+2,Col+35,Clr1[Num]);
- FastWrite(' Free Memory : ',BotLin+2,Col+45,Clr1[Mem]);
- FastWrite(Long2Str(MemAvail),BotLin+2,Col+60,Clr1[Num]);
- END;
-
- BEGIN
- CheckBreak:=TRUE; DoRead:=FALSE; DirDone:=FALSE;
- Col:=cl+2; Row:=ln+3; PutScreen;
- DCol:=Col; DRow:=Row; ForceUpper:=TRUE;
- ScPath:=''; LdPath:=''; MaxLin:=19;
- BotLin:=Row+MaxLin-1;
- GetDir(0,InPath);
- PutStat;
- If ParsePath(InPath,ScPath,LdPath) then
- ReadString('Enter mask: ',ln+1,cl+1,66,Clr1[Ask],Clr1[Msk],Clr1[Nor],Escaped,ScPath);
- If not Escaped then
- REPEAT
- PutStat;
- If DoRead then BEGIN
- GetDir(0,InPath);
- If ParsePath(InPath,ScPath,LdPath) then
- ReadString('Enter mask: ',ln+1,cl+1,66,Clr1[Ask],Clr1[Msk],Clr1[Nor],Escaped,ScPath);
- DoRead:=FALSE;
- If Escaped then DirDone:=TRUE;
- END;
- If LoadDir(ScPath) then BEGIN
- FastWrite(ScPath+' ',ln+1,cl+13,Clr1[Msk]);
- ThisPtr:=HeadPtr;
- PagePtr:=HeadPtr;
- DKey:=GetFile;
- If Chr(Lo(DKey))=CR then BEGIN
- Name:=ThisPtr^.DName+'.'+ThisPtr^.DExt;
- Mask:=ScPath;
- GetDirectory:=DKey;
- If ThisPtr^.DSize<>' <DIR>' then DirDone:=TRUE;
- END ELSE If Chr(Lo(DKey))=ESC then DirDone:=TRUE;
- END ELSE BEGIN
- Beep(600,100);
- GetDir(0,InPath);
- END;
- If ThisPtr^.DSize=' <DIR>' then BEGIN
- If ThisPtr^.DExt='. ' then BEGIN
- GetDir(0,InPath);
- If ParsePath(InPath,ScPath,LdPath) then DoRead:=FALSE;
- END ELSE If ThisPtr^.DExt='.. ' then BEGIN
- ChDir('..');
- GetDir(0,InPath);
- If ParsePath(InPath,ScPath,LdPath) then DoRead:=FALSE;
- END ELSE BEGIN
- GetDir(0,InPath);
- If ParsePath(InPath,ScPath,LdPath) then BEGIN
- InPath:=LdPath+TrimTrail(ThisPtr^.DName);
- ChDir(InPath);
- GetDir(0,InPath);
- END;
- If ParsePath(InPath,ScPath,LdPath) then BEGIN
- DoRead:=FALSE;
- DirDone:=FALSE;
- ThisPtr:=HeadPtr;
- While ThisPtr^.Next<>NIL do BEGIN
- ThisPtr:=ThisPtr^.Next;
- Dispose(ThisPtr^.Prev);
- END;
- Dispose(ThisPtr);
- END;
- END;
- END;
- FastWrite(Pad(ScPath,66),ln+1,cl+13,Clr1[Msk]);
- UNTIL DirDone;
- END;
-
- END.