home *** CD-ROM | disk | FTP | other *** search
- program fetch42; { ljr }
-
- { tss text file database fetch and show, ver 1.00, 2/20/89 }
- { install file lock/unlock for LAN }
- { modify, 7/25/89 }
-
- {$M 16384,1024,16384}
-
- USES DOS, CRT, MAXVAR, MAXUTIL, MAXKBRD, MAXDBF;
-
- const
- NormalVideo = $07;
- ReverseVideo = $70;
-
- type
- str80 = string[80];
- var
- KeyHead : word absolute $0000:$041A;
- KeyTail : word absolute $0000:$041C;
- PrgmName : string[12];
- WFetchF : string[12];
- FetchF : array [1..20] of string[12];
- Dbf : dFile;
- F : str255;
- FileName : string[12];
- Key_1 : string[12];
- FetchK1 : array [1..20] of string[12];
- Key_2 : string[12];
- FetchK2 : array [1..20] of string[12];
- Key_3 : string[12];
- FetchK3 : array [1..20] of string[12];
- Key_4 : string[12];
- FetchK4 : array [1..20] of string[12];
- Buffer : array [1..61] of char;
- StrBuf : array [1..5] of Str80;
- FldName : array [1..5] of Str10;
- RecNum : RecNr;
- Status : integer;
- KeyWord1 : string[12];
- KeyWord2 : string[12];
- KeyWord3 : string[12];
- KeyWord4 : string[12];
- NmbrofKeys : byte;
- NmbrofMatches : byte;
- ii : byte;
- iii : byte;
- Ch : char;
- Match : boolean;
- Abort : boolean;
- EscPress : boolean;
-
- Procedure Beep;
- begin
- Sound(554); Delay(25);
- NoSound; Delay(25);
- Sound(415); Delay(50);
- NoSound;
- end;
-
- Procedure Scrn;
- begin
- ClrScr;
- TextAttr := ReverseVideo;
- GoToXY(5,1);
- WriteLn(' TEXT FILE ''FETCH'' ( text file fetch and display program ) ver 1.10 ');
- TextAttr := NormalVideo;
- GoToXY (1,25); Write(' ');
- GoToXY(12,25); Write('TO EXIT THE PROGRAM, JUST PRESS <RTN> ONLY! ');
- end;
-
- Procedure OpenFile;
- begin
- F := 'FETCH.DBF';
- Result := dp_OpenDBF(F,dplShared,Dbf);
- if Result <> Success then
- begin
- GoToXY (25,12); Beep; Write( ' ERROR WITH FILE ',F,'.');
- GoToXY (34,14); Write( ' Error #',Result:3,'.');
- GoToXY (30,16); Write( ' Program terminating.');
- Halt;
- end;
- end;
-
- Procedure CloseFile;
- begin
- Result := dp_CloseDBF(Dbf);
- Delay(500);
- if Result <> Success then
- begin
- GoToXY (25,12); Beep; Write( ' ERROR WITH FILE ',F,'.');
- GoToXY (34,14); Write( ' Error #',Result:3,'.');
- Delay(3000);
- end;
- end;
-
- Procedure FldNm;
- begin
- FldName[1] := 'FILENAME';
- FldName[2] := 'KEY_1';
- FldName[3] := 'KEY_2';
- FldName[4] := 'KEY_3';
- FldName[5] := 'KEY_4';
- end;
-
- Procedure ClrStrBuf;
- var
- i : integer;
- begin
- For i := 1 to 5 do StrBuf[i,0] := #0;
- end;
-
- Procedure ClrVar;
- begin
- FileName[0] := #0;
- Key_1[0] := #0;
- Key_2[0] := #0;
- Key_3[0] := #0;
- Key_4[0] := #0;
- end;
-
- Procedure ClrFetchF;
- var
- i : integer;
- begin
- For i := 1 to 20 do FetchF[i,0] := #0;
- end;
-
- Procedure GetKeyWords;
- begin
- Scrn;
- NmbrofKeys := 0;
- KeyWord1[0] := #0;
- KeyWord2[0] := #0;
- KeyWord3[0] := #0;
- KeyWord4[0] := #0;
- GoToXY(20,3);
- Write( 'Please enter the 1st key word: ');
- ReadLn(KeyWord1);
- if KeyWord1 <> '' then
- begin
- NmbrofKeys := succ(NmbrofKeys); { I got the first one, bump the count }
- GoToXY(1,4); { now go ask for the second }
- Write( 'Please enter the 2nd key word, or <RTN> to start: ');
- ReadLn(KeyWord2);
- if KeyWord2 <> '' then
- begin
- NmbrofKeys := succ(NmbrofKeys); { got the second, bump the count }
- GoToXY(1,5); { now ask for the third }
- Write( 'Please enter the 3rd key word, or <RTN> to start: ');
- ReadLn(KeyWord3);
- if KeyWord3 <> '' then
- begin
- NmbrofKeys := succ(NmbrofKeys); { got the third }
- GoToXY(1,6); { ask for fourth }
- Write( 'Please enter the 4th key word, or <RTN> to start: ');
- ReadLn(KeyWord4);
- if KeyWord4 <> '' then
- NmbrofKeys := succ(NmbrofKeys); { got the fourth and last one! }
- end;
- end;
- end;
- end;
-
- Procedure GetValues;
- var
- X : Char;
- i : integer;
- begin
- For i := 1 to 5 do
- begin
- Result := dp_Value(Dbf,FldName[i],X,Buffer,StrBuf[i]);
- if Result <> Success then
- begin
- GoToXY (25,12); Beep; Write( ' ERROR WITH FILE ',F,'.');
- GoToXY (34,14); Write( ' Error #',Result:3,'.');
- GoToXY (26,16); Write( 'Values Not Fetched From Buffer !');
- GoToXY (28,18); Write( 'Field Name: ',FldName[i]:10,'.');
- Delay(3000);
- end;
- end;
- end;
-
- Procedure ReadRecord;
- begin
- Abort := TRUE;
- Result := dp_GetRec(Dbf,RecNum,Buffer,Status);
- if Result <> Success then
- begin
- GoToXY (25,12); Beep; Write( ' ERROR WITH FILE ',F,'.');
- GoToXY (34,14); Write( ' Error #',Result:3,'.');
- GoToXY (26,16); Write( ' - Can`t Get Record! ');
- Delay(3000);
- end;
- if Status <> Active then exit;
- GetValues;
- Abort := FALSE;
- end;
-
- Function StripBlankEnds( var s : str80) : str80;
- var
- slen : byte absolute s;
- stop : integer;
- begin
- stop := slen;
- while (s[stop] = ' ') do
- dec(stop);
- slen := stop;
- StripBlankEnds := s;
- end;
-
- Procedure Extract;
- begin
- FileName := StripBlankEnds(Strbuf[1]);
- Key_1 := StripBlankEnds(Strbuf[2]);
- Key_2 := StripBlankEnds(Strbuf[3]);
- Key_3 := StripBlankEnds(Strbuf[4]);
- Key_4 := StripBlankEnds(Strbuf[5]);
- end;
-
- Procedure MatchTest;
- begin
- Match := false;
- if (Key_1 = KeyWord1) then
- if NmbrofKeys > 1 then
- if (Key_2 = KeyWord2) then
- if NmbrofKeys > 2 then
- if (Key_3 = KeyWord3) then
- if NmbrofKeys > 3 then
- if (Key_4 = KeyWord4) then
- begin
- WFetchF := FileName; { match 4 }
- Match := true;
- end
- else Match := false { 4th keyword failed match, switch T to F }
- else { match 3 and no more key to test }
- begin
- WFetchF := FileName;
- Match := true;
- end
- else Match := false { 3rd keyword failed match }
- else { match 2 and no more key to test }
- begin
- WFetchF := FileName;
- Match := true;
- end
- else Match := false { 2nd keyword failed match }
- else { match 1 and no more key to test }
- begin
- WFetchF := FileName;
- Match := true;
- end;
- end;
-
- Procedure ScanDbf;
- var
- i,
- total : integer;
- begin
- i := 0;
- RecNum := 1;
- total := Dbf^.hdr.RecCnt;
- GoToXY (1,3);
- Write(' ');
- GoToXY (1,4);
- Write(' ');
- GoToXY (1,5);
- Write(' ');
- GoToXY (1,6);
- Write(' ');
- GoToXY (1,3);
- WriteLn('Total Records being scanned are ',total,'.');
- GoToXY (1,4);
- WriteLn('════════════════════════════════════════════════════════════════════════════════');
- repeat
- repeat
- begin
- ReadRecord;
- Extract;
- MatchTest;
- RecNum := RecNum + 1;
- end;
- until (Match) or (RecNum = succ(total));
-
- if (match) and (i < 20) then { only allow 20 max }
- begin
- i := succ(i);
- FetchF[i] := WFetchF;
- FetchK1[i] := Key_1;
- FetchK2[i] := Key_2;
- FetchK3[i] := Key_3;
- FetchK4[i] := Key_4;
- GoToXY(1,4 + i);
- if i < 10 then
- Write('Match: ')
- else
- Write('Match:');
- Write(i,'=> ',FileName,', ',Key_1,', ',
- Key_2,', ',Key_3,', ',Key_4);
- Match := false;
- end;
-
- if (match) and (i = 20) then { only allow 20 max }
- begin
- GoToXY (1,25); Write(' ');
- GoToXY (22,25);
- Beep;
- TextAttr := ReverseVideo;
- Write(' MORE THAN 20 MATCHES FOUND! ');
- delay(4000);
- TextAttr := NormalVideo;
- GoToXY (22,25);
- Write(' ');
-
- { because it has collected 20, lets force the loop to a stop }
- RecNum := succ(total);
- { i := pred(i); }
- Match := false;
- end;
-
- until RecNum = succ(total);
- NmbrofMatches := i;
- if WFetchF = '' then
- begin
- TextAttr := ReverseVideo;
- GoToXY (18,12); Beep; Write( ' NO MATCHES FOUND IN ',F,'.');
- delay(2000);
- TextAttr := NormalVideo;
- GoToXY (18,12); Write(' ');
- end;
- end;
-
- procedure Showit;
- begin
- WFetchF := FetchF[ii];
- GoToXY(1,4 + ii);
- if ii < 10 then
- Write('Match: ')
- else
- Write('Match:');
- Write(ii,'=> ',FetchF[ii],', ',FetchK1[ii],', ',
- FetchK2[ii],', ',FetchK3[ii],', ',FetchK4[ii]);
- end;
-
- begin { M A I N }
- directvideo := false;
- TextAttr := (NormalVideo);
- FileMode := $42; { hex number: sharing mode = full access permitted }
- { see INT 21, function 3D, open a file }
- OpenFile;
- FldNm;
- ClrStrBuf;
- ClrVar;
- ClrFetchF;
- PrgmName := 'XLIST.COM';
- WFetchF[0] := #0;
- repeat
- GetKeyWords;
- if KeyWord1 <> '' then ScanDbf; { scan all the db's, find all matches }
-
- if WFetchF <> '' then
- begin
- ii := 0;
- GoToXY (1,25); Write(' ');
- GoToXY (1,25); Write('PRESS HOME, END, UP/DOWN ARROW TO SELECT: <RTN> TO VIEW: <ESC> TO EXIT!');
-
- repeat { the main loop }
- EscPress := false;
- ii := succ(ii);
- iii := 0;
- GoToXY (1,3);
- Write('Total Records scanned were ',Dbf^.hdr.RecCnt,'.');
- WriteLn(' Total Matches found were ',NmbrofMatches,'.');
- GoToXY (1,4);
- WriteLn('════════════════════════════════════════════════════════════════════════════════');
-
- repeat { a sub loop, to show all the matches found }
- iii := succ(iii);
- WFetchF := FetchF[iii];
- GoToXY(1,4 + iii);
- if iii < 10 then
- Write('Match: ')
- else
- Write('Match:');
- Write(iii,'=> ',FetchF[iii],', ',FetchK1[iii],', ',
- FetchK2[iii],', ',FetchK3[iii],', ',FetchK4[iii]);
- until iii = NmbrofMatches;
-
- repeat
- TextAttr := ReverseVideo; { initially, highlight the top one }
- ShowIt;
- TextAttr := NormalVideo;
-
- Ch := ReadKey;
- if Ch = #27 then
- begin
- EscPress := true;
- Ch := #13;
- end;
- if Ch = #0 then begin
- Ch := ReadKey;
- case Ch of
- #71 : if (ii <> 1) then {go to the top}
- begin
- ShowIt; { un-highlight the current one }
- ii := 1;
- TextAttr := ReverseVideo; { now highlight the top one }
- ShowIt;
- TextAttr := NormalVideo;
- end;
- #72, #73 : if (ii > 1) then {go upward}
- begin
- ShowIt;
- Dec(ii);
- TextAttr := ReverseVideo; { highlight the next one }
- ShowIt;
- TextAttr := NormalVideo;
- end;
- #79 : if (ii <> NmbrofMatches) then {go to the bottom}
- begin
- ShowIt;
- ii := NmbrofMatches;
- TextAttr := ReverseVideo; { highlight the bottom one }
- ShowIt;
- TextAttr := NormalVideo;
- end;
- #80, #81 : if (ii < NmbrofMatches) then {go downward}
- begin
- ShowIt;
- Inc(ii);
- TextAttr := ReverseVideo; { highlight the top one }
- ShowIt;
- TextAttr := NormalVideo;
- end;
- end; { case }
- end; { if ch = #0 }
- until ch = #13;
-
- if EscPress then
- begin
- ii := NmbrofMatches;
- end
- else
- begin
-
- SwapVectors;
- KeyTail := KeyHead; { clr the keyboard buffer, via pointers }
- Exec( PrgmName, WFetchF );
- SwapVectors;
-
- end;
- Scrn;
- GoToXY (1,25); Write('PRESS HOME, END, UP/DOWN ARROW TO SELECT: <RTN> TO VIEW: <ESC> TO EXIT!');
- until ii = NmbrofMatches;
-
- WFetchF[0] := #0; { re-zero the file name }
- ClrScr; { to wash the xlist screen away }
- if DosError <> 0 then
- begin
- WriteLn('Dos error #', DosError);
- WriteLn('Couldn''t find the XLIST program');
- end;
- WriteLn;
- end;
- until KeyWord1 = '';
- CloseFile;
- ClrScr;
- end.