program LPCONV(input,output); {Convert a Register type file into a data base file for} {for the pascal suite} {Brian Gilmore September 1987} {Amended to allow 5 char house numbers} {October: Amended to new database file format} LABEL 1,999; TYPE fsa = array[1..4] OF integer; {$I lptype}; VAR source: text; filename, ofn, rfn, nfn, hfn, pfn, name: string[14]; ad1, sname, fsname, initial, ad2, ad3, ad4: sts; {string[40]} line,rname, snr, r2name, padd, add, this_add, last_add, code, last_line, house, regn, ad5, adx: string[80]; target, count, p1, p2, lno,vkey,row,col,spt,i,flag,dstart,rlen,lflag: s_integer; p3, labels, addno, pxptr, j: s_integer; nnptr, naptr, haptr: s_integer; field_size, field_max: fsa; key: char; go_db: boolean; PROCEDURE cursor(y,x: integer); external; PROCEDURE clearscreen;external; PROCEDURE to_lower_case(VAR s:sts); VAR i, j, q: s_integer; c: char; x: boolean; BEGIN q := length(s); if q > 0 then begin x := false; for i := 1 to q do begin c := s[i]; if (c>='A') and (c<='Z') then begin if x then s[i] := chr(ord(c)-ord('A')+ord('a')) else x := true; end else begin if c <> '''' then x := false; end; end; end; END; PROCEDURE plant(s: sts); VAR i, j: s_integer; BEGIN naptr := naptr+1; nafile^ := chr(length(s)); put(nafile); if length(s) > 0 then begin for i := 1 to length(s) do begin naptr := naptr+1; nafile^ := s[i]; put(nafile); end; end; END; PROCEDURE plantf(s:sts); {plant firstname} VAR i,j:s_integer; BEGIN haptr := haptr+1; fafile^ := chr(length(s)); put(fafile); if length(s) > 0 then begin for i := 1 to length(s) do begin haptr := haptr+1; fafile^ := s[i]; put(fafile); end; end; END; PROCEDURE push(n: byte); BEGIN haptr := haptr+1; fafile^ := chr(n); put(fafile); END; PROCEDURE put_birthday; {into firstname file} VAR i: byte; BEGIN if birthday[1] = 0 then push(0) else for i := 1 to 3 do push(birthday[i]); END; PROCEDURE insert_postcode; VAR i: byte; BEGIN if count > 1 then pofile^.r_no := count-1; {poll number of LAST voter} put(pofile); {store away again} pxptr := pxptr+1; p2 := length(ad5); if p2 > 8 then begin cursor(15, 0); writeln('Postcode? [', ad5, ']'); p2 := 8; end; if p2 > 0 then for i := 1 to p2 do pofile^.postcode[i] := ad5[i]; if p2+1 <= 8 then for i := p2+1 to 8 do pofile^.postcode[i] := ' '; END; {postcode is written to file at next entry (or end of prog)} BEGIN clearscreen; writeln('Convert Register file to Database format.'); writeln; writeln; write('Source Name File?'); readln(name); assign(source, name); reset (source); write('Database file base (no extension)?'); readln(ofn); rfn := concat(ofn,'.str'); nfn := concat(ofn,'.nam'); hfn := concat(ofn, '.fna'); pfn := concat(ofn, '.poc'); ofn := concat(ofn,'.dat'); writeln; write('Create ALL files?'); readln(ad1); if (ad1[1] = 'n') or (ad1[1] = 'N') then go_db := false else go_db := true; clearscreen; cursor(0,1); lno := 0; row := 1; col := 1; vkey:=0; dstart:=0; { assign(nat, 'KBD:'); reset(nat)}; {get at keyboard directly} assign(dbfile, ofn); rewrite(dbfile); seek(dbfile, 0); assign(rdfile, rfn); rewrite(rdfile); seek(rdfile, 0); assign(nafile, nfn); rewrite(nafile); seek(nafile, 0); assign(fafile, hfn); rewrite(fafile); seek(fafile, 0); assign(pofile, pfn); rewrite(pofile); seek(pofile, 0); put(rdfile); {1st entry dummy} flag := 0; count := 0; labels := 0; naptr := 0; haptr := 0; fsname := ''; last_add := ''; pxptr := 0; birthday[1] := 0; WHILE flag = 0 DO BEGIN readln(source, line); key := line[1]; if key = 'P' then begin reg := copy(line, 3, length(line)-2); writeln('Register ',reg); GOTO 999; end; if key = 'A' then begin add := copy(line, 3, length(line)-2); i := pos('!', add); if i>2 then begin ad2 := ''; ad3 := ''; ad4 := ''; ad5 := ''; ad1 := copy(add, 1, i-1); if i+2 < length(add) then begin add := copy(add, i+1, length(add)-i); i := pos('!', add); if (i>0) and (i+20) and (i+20) and (j+1 adx then begin {not just a postcode change} to_lower_case(ad2); to_lower_case(ad3); to_lower_case(ad4); cursor(10,0); write(' Street[',ad1,'] Postcode[',ad5,']', count:5, naptr:7, haptr:6); writeln(' '); p1 := length(ad1); for i := 1 to p1 do rdfile^.street[i] := ad1[i]; for i := p1+1 to 25 do rdfile^.street[i] := ' '; rdfile^.r_no := count; { pass in 1st poll no for this street} rdfile^.spare := 0; { dummy, for poll day program} rdfile^.postind := pxptr; {index to postcode file} rdfile^.restadr := naptr; put(rdfile); adx := ad1; {remember last street name} addno := addno+1; {Index to Address number} plant(ad2); plant(ad3); plant(ad4); {put address bits into the SURNAME file} insert_postcode ; end else insert_postcode; {postcode only changed} end; end; { if eoln(nat) then flag := 1 else begin read(nat, key); if ord(key)<>0 then flag :=2; end; } end else begin lno := lno+1; snr := ''; p1 := pos('!', line); if p1 > 1 then begin regn := copy(line, 1, p1-1); {get out the register number} if (regn = '0000') and (lno>1) then goto 999; {problem in register sy - gash name on the top!} end; rname := copy(line, p1+1, length(line)-p1); r2name := rname; p2 := pos('!', rname); p3 := p2; {get the house number/name} i := length(rname)-p3; this_add := ''; if i > 1 then this_add := copy(rname, p3+2, i-1) else writeln('ADR?',rname); field_size[3] := i; 1:; if p2 = 0 then goto 999; spt := 0; i := p2; REPEAT IF rname[i] = ' ' THEN BEGIN spt := i; END; i := i-1; UNTIL (spt>0) OR (i=1); IF spt > 0 THEN BEGIN sname := copy(rname, spt+1, p2-spt-1); if length(sname) < 4 then begin if (sname='JR.') OR (sname='SR.') then begin rname := copy(rname, 1, spt); rname[spt] := '!'; snr := concat(' ', sname); p2 := spt; goto 1; end; end; field_size[2] := p2-length(sname)-2; if field_size[2] <> 0 then initial := copy(rname, 1, field_size[2]); sname := concat(sname, snr); field_size[1] := length(sname); to_lower_case(sname); to_lower_case(initial); field_size[2] := length(initial); for i := 1 to 3 do begin if field_size[i] > field_max[i] then begin if count > 1 then begin field_max[i] := field_size[i]; cursor(0,1); writeln('name:',field_max[1],' first:',field_max[2], ' add:', field_max[3],' '); cursor(i+4, 0); case i of 1: writeln(sname); 2: writeln(initial); 3: writeln(this_add); end; end; end; end; p1 := length(sname); p2 := length(initial); p3 := length(this_add); if (sname <> fsname) or (this_add <> last_add) then begin dbfile^.namind := naptr; fsname := sname; last_add := this_add; nnptr := naptr; plant(sname); {not same as last, so add} plant(this_add); {house name/surname couple} end else dbfile^.namind := nnptr; dbfile^.fnameind := haptr; plantf(initial); {put first name into first name file} put_birthday; {put birthday if present into first name file} dbfile^.street := addno; dbfile^.xvote := 0; dbfile^.attr := []; dbfile^.style := 0; if go_db then put(dbfile); count := count+1 END; end; 999: if eof(source) then flag := 1; END; pofile^.r_no := count-1; put(pofile); seek(dbfile, 0); dbfile^.namind := count; dbfile^.fnameind := addno; put(dbfile); seek(rdfile, 0); rdfile^.r_no := addno; put(rdfile); cursor(15, 0); END.