home *** CD-ROM | disk | FTP | other *** search
- {$R+}
- program tareport; {test turbo database toolkit }
-
- uses
- dos,crt,taccess,printer;
-
- CONST
- {***** key code constants - 2 byte keys *****
- ***** have null stripped and 128 added *****}
- f1 = #187; f2 = #188; f3 = #189; f4 = #190; f5 = #191;
- f6 = #192; f7 = #193; f8 = #194; f9 = #195; f10 = #196;
- csr_r = #205; pgup = #201; pgdn = #209; Ins = #210; del = #211;
- _home = #199; _end = #207; tab = #9 ; esc = #27 ; Bksp = #8 ;
- csr_up = #200; csr_dn= #208; sh_tab = #143; Altf2 = #233; csr_l = #203;
- enter = #13; SubMenu = #255;
-
-
- TYPE
- ketstr = string[1];
-
- DataRec = record
- RecStatus : longint;
- dstate : byte;
- dummy : array[1..3] of byte; {dummy out other keys}
- dcount : longint;
- dummy2 : integer;
- end;{DataRec}
-
- MaxDataType = DataRec;
- MaxKeyType = ketstr;
-
- flagarray = array[0..11000] of byte;
- flagptr = ^flagarray;
-
- VAR
- ibuff : DataRec;
- DugFile : DataFile;
- StateIdx,
- Sicidx,
- empidx,
- dugidx : IndexFile;
- recnum : longint;
- done : boolean;
- keystate : array[0..52] of boolean;
- keydug : array[0..3] of boolean;
- keystr : string[1];
- cmd : char;
- searchrec : flagptr;
- c : byte;
-
- {*************************
- test a bit in a byte
- *************************}
- function bit( n,b : byte) : boolean; { test nth bit of b }
-
- BEGIN
- bit := ((b shr (n-1)) and 1 = 1);
- END;{bit}
-
- {*************************
- set a bit in a byte
- *************************}
- procedure set_bit(n : byte; b : integer; flag : flagptr);
-
- var
- work : ^byte;
-
- BEGIN
- work := ptr(seg(flag^),ofs(flag^)+b);
- work^ := work^ or (1 shl (n-1));
- END;{set_bit}
-
- {***************************
- WAIT FOR A KEY
- ***************************}
- procedure waitforkey;
- BEGIN
- if not keypressed then
- repeat until keypressed;
- cmd := readkey;
- if (cmd = #0) then begin
- cmd := readkey;
- cmd := char(ord(cmd)+128);
- end;{if}
- END;
-
- {***************************
- search database
- ***************************}
- procedure report;
-
- VAR
- x : byte;
- subtot,
- total : real;
- c,
- first,
- last,
- recnum : longint;
- b : byte;
-
- begin
- x := 0;
- total := 0.0;
- for c := 0 to 52 do {loop by state}
- if keystate[c] then begin {selected state ?}
- fillchar(searchrec^,11000,0); {reset flags}
- subtot := 0.0; {reset}
- first := 0; {counters &}
- last := 0; {totals}
- keystr[1] := char(c); {set search key}
- findkey(stateidx,recnum,keystr); {do search for 1st key}
- if ok then begin {successfull search ?}
- set_bit(1+(recnum mod 8),trunc(recnum/8),searchrec); {flag record}
- first := trunc(recnum/8); {store pos}
- last := trunc(recnum/8); {in flag array}
- writeln('key found - record number is ',recnum);
- end
- else begin
- writeln('key not found');
- first := 1; {disable}
- last := 0; {search}
- end;
-
- while (ord(keystr[1]) = c) and ok do begin {while we find the current key}
- NextKey(stateidx,recnum,keystr); {get next key}
- if ok and (ord(keystr[1]) = c) then begin {still ok ?}
- set_bit(1+(recnum mod 8),trunc(recnum/8),searchrec); {flag recnum}
- if first > trunc(recnum/8) then {test for new}
- first := trunc(recnum/8); {start}
- if last < trunc(recnum/8) then {test for new}
- last := trunc(recnum/8); {end}
- end;
- end;{while}
- writeln('first ',first,' last = ',last); {dump 1st & last flag bytes}
- for recnum := first to last do {loop for searching flags}
- for b := 1 to 8 do {loop by bit}
- if bit(b,searchrec^[recnum]) then begin {was record # flagged ?}
- getrec(DugFile,recnum*8+b-1,ibuff); {get it}
- subtot := subtot + ibuff.dcount; {increment subtotal}
- end;
- writeln('total for state ',c,' is ',subtot:10:0); {dump}
- writeln(lst,'total for state ',c,' is ',subtot:10:0); {it}
- total := total + subtot; {increment total}
- end;{if}
- writeln('total = ',total:10:0);
- end;
-
- {***************************
- main
- ***************************}
- BEGIN
- new(searchrec);
- fillchar(keystate,sizeof(keystate),1); {for test - set all states to TRUE}
- OpenFile(DugFile,'tatest.dat',sizeof(DataRec));
- OpenIndex(StateIdx,'state.idx',1,duplicates);
- if not ok then begin
- writeln('file error ',#7);
- halt;
- end;
- done := false;
- keystr := ' ';
- repeat
- clrscr;
- write('states : ');
- for c := 0 to 52 do if keystate[c] then write(c:4);
- writeln;
- writeln(' 1 - specify state ');
- writeln(' 2 - run report ');
- writeln(' 3 - clear states ');
- writeln(' 4 - quit (Esc) ');
- writeln;
- waitforkey;
- case cmd of
- f1,'1' : begin
- repeat
- write('Enter state # (0-52) =>');
- readln(c);
- until c in [0..52];
- keystate[c] := true;
- end;
- f2,'2' : report;
- f3,'3' : fillchar(keystate,sizeof(keystate),0); {set all states to FALSE}
- f4,'4',
- Esc : done := true;
- end;{case}
- until done;
- closefile(DugFile);
- closeindex(StateIdx);
- END.