| 1 |
/* |
| 2 |
* @progname pointers |
| 3 |
* @version 1.0 |
| 4 |
* @author Chandler |
| 5 |
* @category |
| 6 |
* @output Text |
| 7 |
* @description |
| 8 |
|
| 9 |
Test a database for reciprocity of pointers between persons and families. |
| 10 |
|
| 11 |
Report any failures, primarily the following: |
| 12 |
|
| 13 |
Person Inn is a spouse/child in Fnn, but Fnn has no corresponding pointer. |
| 14 |
Family Fnn has HUSB/WIFE/CHIL Inn, but Inn has no corresponding pointer. |
| 15 |
|
| 16 |
Some failures are supposed to be impossible, but are covered here |
| 17 |
nonetheless: |
| 18 |
|
| 19 |
Family Fnn has HUSB/WIFE/CHIL Inn, but Inn does not exist. |
| 20 |
Family Fnn has a null HUSB/WIFE/CHIL line. |
| 21 |
Person Inn is a spouse/child in Fnn, but Fnn does not exist. |
| 22 |
Person Inn has a null FAMS/FAMC line. |
| 23 |
|
| 24 |
Version 1.0 - 2003 Jul 2 - John F. Chandler |
| 25 |
|
| 26 |
This program works only with LifeLines. |
| 27 |
|
| 28 |
*/ |
| 29 |
|
| 30 |
global(pointers) |
| 31 |
|
| 32 |
proc main() { |
| 33 |
table(spou) /* each entry is the list of spouses in the keyed family */ |
| 34 |
table(chil) /* each entry is the list of children in the keyed family */ |
| 35 |
|
| 36 |
"Testing database " qt() database() qt() " for pointer reciprocity\n" |
| 37 |
|
| 38 |
set(pointers,0) |
| 39 |
|
| 40 |
/* loop through persons and note all the families they belong to */ |
| 41 |
forindi(i,n) { |
| 42 |
set(k,save(key(i))) |
| 43 |
fornodes(root(i),node) { |
| 44 |
set(type,tag(node)) |
| 45 |
if(eqstr(type,"FAMC")) { |
| 46 |
call tally(type,"child",chil,node,k) |
| 47 |
} elsif(eqstr(type,"FAMS")) { |
| 48 |
call tally(type,"spouse",spou,node,k) |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
/* loop through families and compare the members against the list |
| 53 |
compiled by scanning persons -- flag any mismatches */ |
| 54 |
forfam(f,n) { |
| 55 |
set(id,save(key(f))) |
| 56 |
set(cl,lookup(chil,id)) |
| 57 |
set(sl,lookup(spou,id)) |
| 58 |
fornodes(root(f),node) { |
| 59 |
set(type,tag(node)) |
| 60 |
if(eqstr(type,"CHIL")) { call checkoff(type,cl,id,node) } |
| 61 |
elsif(or(eqstr(type,"HUSB"),eqstr(type,"WIFE"))) { |
| 62 |
call checkoff(type,sl,id,node) |
| 63 |
} |
| 64 |
} |
| 65 |
/* any remaining list elements are errors */ |
| 66 |
if(sl) { |
| 67 |
while(k,dequeue(sl)) { |
| 68 |
"\nPerson " k " is a spouse in " id |
| 69 |
", but " id " has no corresponding pointer." |
| 70 |
} |
| 71 |
} |
| 72 |
if(cl) { |
| 73 |
while(k,dequeue(cl)) { |
| 74 |
"\nPerson " k " is a child in " id |
| 75 |
", but " id " has no corresponding pointer." |
| 76 |
} |
| 77 |
} |
| 78 |
} |
| 79 |
"\n\nFinished after checking " d(pointers) " pointers.\n" |
| 80 |
|
| 81 |
} |
| 82 |
|
| 83 |
/* check a family member against the expected list. |
| 84 |
anyone not on the list is an error. |
| 85 |
remove each person from the list when found here. */ |
| 86 |
proc checkoff(type,list,id,node) { |
| 87 |
incr(pointers) |
| 88 |
if(eq(mod(pointers,500),0)) { print(".") } |
| 89 |
if(k,value(node)) { |
| 90 |
set(key,substring(k,2,sub(strlen(k),1))) |
| 91 |
if(list) { |
| 92 |
set(count,length(list)) |
| 93 |
while(gt(count,0)) { |
| 94 |
decr(count) |
| 95 |
set(c,dequeue(list)) |
| 96 |
if(eqstr(c,key)) { set(count,-1) } |
| 97 |
else { enqueue(list,c) } |
| 98 |
} |
| 99 |
} |
| 100 |
if(eq(count,0)) { |
| 101 |
"\nFamily " id " has " type " " key ", but " key |
| 102 |
if(reference(k)) { " has no corresponding pointer." } |
| 103 |
else { " does not exist." } |
| 104 |
} |
| 105 |
} else { "\nFamily " id " has a null " type " line." } |
| 106 |
} |
| 107 |
|
| 108 |
/* build a list of persons who belong to families */ |
| 109 |
proc tally(type,member,table,node,k) { |
| 110 |
incr(pointers) |
| 111 |
if(eq(mod(pointers,500),0)) { print(".") } |
| 112 |
set(id,value(node)) |
| 113 |
if(reference(id)) { |
| 114 |
set(id,save(substring(id,2,sub(strlen(id),1)))) |
| 115 |
if(l,lookup(table,id)) { enqueue(l,k) } |
| 116 |
else { |
| 117 |
list(l) |
| 118 |
enqueue(l,k) |
| 119 |
insert(table,id,l) |
| 120 |
} |
| 121 |
} elsif(id) { |
| 122 |
"\nPerson " k " is a " member " in " id |
| 123 |
", but " id " does not exist." |
| 124 |
} else { "\nPerson " k " has a null " type " line." } |
| 125 |
} |
| 126 |
|