program LPCOUNT(input,output); { Program to calculate promise figures from a file in Database format} {Brian Gilmore August 1987} {October - Modified for new database file format} TYPE nums = ARRAY[1..2,0..10] of 0..60000; diffs = ARRAY[0..9, 0..9] of 0..60000; fsa = ARRAY[1..4] OF integer; {$I lptype} VAR x_party, t_party: nums; diff: diffs; s, old_street: string[40]; target, count, c_option, i, flag,dstart,rlen,lflag: integer; x_now, p3, labels, addno, last_address: integer; field_size, field_max: fsa; x_option: byte; ib, jb: byte; key: char; {$i lpexti} {$i lpprii} FUNCTION get_attribute: integer; VAR i,j, n: integer; BEGIN show_attributes; REPEAT cursor(22, 0); write('Attribute no (1-',max_attr:2,')?'); n := getint(22, 21); if (n=-1) and (final=13) then n := 0; if n>max_attr then begin cursor(23,30); write('Invalid!'); end; UNTIL n > 0; get_attribute := n; END; FUNCTION new_street(n: integer): BOOLEAN; BEGIN get_address(dbfile^.street); if rdfile^.street <> old_street then begin new_street := true; end else new_street := false; END; PROCEDURE add_this_record; VAR t, p: 0..255; BEGIN t := dbfile^.xvote MOD 16; p := dbfile^.xvote DIV 16; if t = 0 then begin if dbfile^.attr * [1] <> [] then begin {moved/dead} t := 9; end; end; x_party[1, t] := x_party[1, t]+1; x_party[2, p] := x_party[2, p]+1; t_party[1, t] := t_party[1, t]+1; t_party[2, p] := t_party[2, p]+1; if (t<>0) and (p<>0) then begin {diff array} diff[p, t] := diff[p, t]+1; end; END; PROCEDURE zero_street; VAR i: byte; BEGIN for i := 0 to 10 do begin x_party[1, i] := 0; x_party[2, i] := 0; end END; PROCEDURE print_stats(w: integer); VAR i: byte; x, y, z: real; begin for i := 1 to 9 do begin if i<>5 then write(out, x_party[w, i]:5); end; y := x_party[w,1]+x_party[w,6]+x_party[w,8]+x_party[w,7]; x := 0; if y > 0 then x := (x_party[w, 1]*100)/y; {%lab} write(out, x:6:1,'%'); y := y+x_party[w,9]; {include moved/dead in %can} x := y*100/(y+x_party[w, 0]); { if x = 0 then z := 0 else z := x_party[w, 1]/x; } writeln(out, x:5:1,'%', x_party[w,0]:5); end; PROCEDURE pr_street(q: integer); VAR i:byte; s: string[40]; BEGIN for i := 2 to 5 do begin x_party[1, 6] := x_party[1, 6]+x_party[1, i]; x_party[2, 6] := x_party[2, 6]+x_party[2, i]; end; s := old_street; if length(s) > 19 then s := copy(s, 1, 19); write(out, s); if q <> 2 then begin print_stats(1); if q = 3 then write(out,'Previous Canvass '); end; if q <> 1 then print_stats(2); if q = 3 then writeln(out); END; PROCEDURE print_totals(q: integer); {q=1 - overall only} VAR i,j: byte; k: s_integer; BEGIN old_street := 'Totals '; for i := 0 to 10 do begin x_party[1, i] := t_party[1, i]; x_party[2, i] := t_party[2, i]; end; pr_street(q); writeln(out); writeln(out,'Previous/ Current'); write(out, ' '); for i := 1 to 8 do begin write(out, party[i],' '); end; writeln(out); for i := 1 to 8 do begin write(out, party[i], ' '); k := 0; for j := 1 to 8 do k := k+diff[i, j]; write(out, k:6); for j := 1 to 8 do begin write(out, diff[i, j]:6); end; writeln(out); end; writeln(out); write(out, 'Total Current '); for j := 1 to 8 do begin k := 0; for i := 1 to 8 do k := k+diff[i, j]; write(out, k:6); end; for i:= 1 to 4 do writeln(out); END; PROCEDURE add_canvas(q: integer); VAR i, j, n, ad, end_f: s_integer; key: char; BEGIN I := 1; end_f := 0; write(out, 'Register:',reg,' '); if x_option = 0 then writeln(out) else writeln(out, 'Selected on [', attrn[x_option],']'); writeln(out); write(out, ' '); writeln(out, 'Lab Con All SNP AGT Pos D/N M/D %Lab %Can ToDo'); REPEAT seek(dbfile,i); if eof(dbfile) then begin end_f := 1; end else begin if dbfile^.street <> ad then begin {may be a new street} if new_street(ad) then begin {it is} if (i > 1) and (c_option>1) then pr_street(q); cursor(15,40); write('Processing:',old_street); old_street := rdfile^.street; zero_street; end; ad := dbfile^.street; end; if x_option <> 0 then begin if dbfile^.attr * [x_option] <> [] then add_this_record; end else add_this_record; end; i := i+1; UNTIL (i = max_val) OR (Test_Input) OR (end_f<>0); cursor(10,0); write('Last Register Number:', i-1); print_totals(q); END; PROCEDURE U_attr; BEGIN cursor(0,40); write('Filter by Attibute'); clear_from_line(1); x_option := get_attribute; END; PROCEDURE count_options; VAR i,j,n: integer; BEGIN title := 'Total Canvas Results'; mess[0].s := 'Main Menu '; mess[1].s := 'Count Current Canvas'; mess[2].s := 'Count Previous Canvas'; mess[3].s := 'Count BOTH '; j := get_option(0,3, 0); case j OF 0: ; 1, 2, 3: add_canvas(j); end; clear_from_line(1); END; PROCEDURE Typ_menu; VAR i,j: integer; BEGIN title := 'Detailed or Summary'; mess[1].s := 'Total Canvas Results - overall '; mess[2].s := 'Total Canvas Results - per street'; j := get_option(1, 2, 0); CASE j of 1: begin c_option := j; Count_options; end; 2: begin c_option := 2; Count_options; end; END; END; PROCEDURE Main_menu; VAR i,j: integer; x, y: byte; BEGIN set_viewport(1); REPEAT for x := 1 to 2 do for y := 0 to 10 do begin x_party[x, y] := 0; t_party[x, y] := 0; end; for x := 0 to 9 do for y := 0 to 9 do diff[x, y] := 0; x_option := 0; {mask on count} title := 'Main Menu'; mess[0].s := 'Exit Program '; mess[1].s := 'Straight Count '; mess[2].s := 'Use Attribute Information'; mess[3].s := 'Select NEW Register '; j := get_option(0, 3, 0); CASE j of 0: ; 1: typ_menu; 2: begin U_attr; typ_menu; end; 3: begin Close_Register; Request_register; writeln(out); writeln(out); writeln(out); end; END; UNTIL j = 0; END; BEGIN set_party; Ready_Keyboard; File_Or_Printer; Request_Register; reset_viewport; set_viewport(1); main_menu; close_Printer; back_to_menu; END.