segment lpsrx(input,output); { Program to search for a voter name in a file in Database format} {Brian Gilmore September 1987} TYPE pns = string[40]; {$I lptype} VAR xa: xaf; s, target: string[40]; tgt, tgt2: string[4]; i,flag, max, last_address, indx, max_add: integer; {$i lpexti} PROCEDURE construct_index; VAR i: byte; BEGIN for i := 0 to 25 do begin seek(ndfile, i+1); xa[i] := ndfile^.r_no+27; end; xa[26] := max_val+27; END; FUNCTION try_match(x, y: s_integer): s_integer; VAR q: s_integer; BEGIN if y > (x+1) then q := (x+y) DIV 2 else q := x; seek(ndfile, q); cursor(21, 0); write('Low, high, C:',x:5,y:5,q:5,' [',tgt,'][',ndfile^.sname,']'); tgt2 := ndfile^.sname; if x<>q then begin if tgt < tgt2 then q := try_match(x, q) else begin if tgt > tgt2 then q := try_match(q+1, y); end; end; if pos(tgt,tgt2) = 0 then q := 0; try_match := q; END; FUNCTION test_voter(x,y: s_integer): s_integer; VAR i,j,n: s_integer; k: byte; BEGIN {target is incoming string} i := x; k := length(target); if k > 4 then k := 4; tgt := copy(target, 1, k); if y < x then i := 0 else i := try_match(x, y); n:= i; if i > 0 then begin seek(ndfile, i); if ndfile^.sname = tgt then begin REPEAT i := i-1; seek(ndfile, i); UNTIL ndfile^.sname <> tgt; i := i+1; seek(ndfile, i); {move back to 1st occurance of 'name'} end; REPEAT seek(ndfile, i); n := ndfile^.r_no; seek(dbfile, n); Get_names; s := surname; indx := i; {count := n; display_entry;} i := i+1; UNTIL (i>y) OR (pos(target,s)<>0); if i>y then n := 0; end; test_voter := n; END; PROCEDURE user_search(VAR n: s_integer); BEGIN clearline(23); if n=0 then begin cursor(10,10); write('No match for ''',target,''' '); end else begin Disp_form; REPEAT disp_Voter(n); cursor(23, 0); write('RETURN for next, or EXIT'); i := getint(23,24); if final <> 27 then begin if final <> 31 then begin {cursor up} indx := indx+1; end else indx := indx-1; if indx = 0 then indx := 1; if indx >= xa[26] then indx := indx-1; seek(ndfile, indx); n := ndfile^.r_no; seek(dbfile, n); end; UNTIL final=27; end; END; FUNCTION find_voter: integer; VAR i,j,k: integer; n, x, y: s_integer; c: char; s: string [40]; BEGIN n := 0; clearline(23); write('Enter (part) Voter Name:'); readln(s); clear_from_line(1); if s <> '' then begin c := s[1]; if (ord(c)>=ord('a')) AND (ord(c)<=ord('z')) then c := chr(ord(c)-32); if c = ' ' then c := 'A'; s[1] := c; {Convert 1st char to upper case only} { if length(s) < 4 then for i := length(s) to 4 do s := concat(s, ' ');} k := ord(c)-ord('A'); x := xa[k]; y := xa[k+1]-1; target := s; n := test_voter(x, y); user_search(n); end; find_voter := n; END; PROCEDURE ask_for_voter; VAR n: integer; BEGIN REPEAT n := find_voter; UNTIL n = 0; END; BEGIN END.