| 1 |
/* |
| 2 |
* @progname familycheck.ll |
| 3 |
* @version 2000-03-02 |
| 4 |
* @author Dennis Nicklaus [email protected] |
| 5 |
* @category |
| 6 |
* @output Text, 80 cols |
| 7 |
* @description |
| 8 |
* |
| 9 |
Consistency checks between indi records and family records |
| 10 |
(making sure links between kids and spouses go both ways.) |
| 11 |
make sure each family that a person says he is a spouse of |
| 12 |
has him as a spouse, and, vice-versa, |
| 13 |
make sure each person that a family says is a spouse thinks he |
| 14 |
is a spouse of that family |
| 15 |
It also checks when a person says he is a child in a family that |
| 16 |
the family has that person as a child. |
| 17 |
And vice-versa, that every child in a family thinks he |
| 18 |
is a child of that family. |
| 19 |
|
| 20 |
Written by Dennis Nicklaus [email protected], 1997. |
| 21 |
*/ |
| 22 |
/* Modifications: |
| 23 |
* 02-mar-00 pbm report multiple HUSB, WIFE, FAMC |
| 24 |
* 01-mar-00 pbm optionally allow SEX U, and missing SEX records |
| 25 |
* 25-sep-99 pbm check for a child in a family more than once |
| 26 |
* 19-feb-99 pbm check for multiple SEX records |
| 27 |
* 13-feb-99 pbm report a child in family when reporting a family with |
| 28 |
* no parents. |
| 29 |
* always show keys of family and individual involved. |
| 30 |
* display all messages on screen and write to file. |
| 31 |
*/ |
| 32 |
|
| 33 |
global(ALLOWSEXU) /* set to 1 if "SEX U" is allowed */ |
| 34 |
global(WARNNOSEX) /* set to 1 to warn about INDIs with no SEX record */ |
| 35 |
|
| 36 |
proc main () |
| 37 |
{ |
| 38 |
/* user customization section. change the following if desired: */ |
| 39 |
set(ALLOWSEXU, 1) /* 1: "SEX U" should not generate a warning */ |
| 40 |
set(WARNNOSEX, 0) /* 0: don't warn if INDI has no SEX record */ |
| 41 |
/* end of user customization section */ |
| 42 |
|
| 43 |
print("processing each person and family in the database...") |
| 44 |
|
| 45 |
forindi(person, number) { |
| 46 |
|
| 47 |
call checksex(person) |
| 48 |
families(person, fam, spouse, nfam) { |
| 49 |
set(okboss,0) |
| 50 |
set(s, child(root(fam))) |
| 51 |
while(s) { |
| 52 |
if(or(eqstr(tag(s), "HUSB"), eqstr(tag(s), "WIFE"))) { |
| 53 |
if(v, value(s)) { |
| 54 |
if(reference(v)) { |
| 55 |
if(eqstr(substring(v, 2,sub(strlen(v),1)),key(person))){ |
| 56 |
set(okboss, add(okboss,1)) |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
set(s, sibling(s)) |
| 62 |
} |
| 63 |
if (eq(0,okboss)){ |
| 64 |
print("\nperson ",key(person)," is not a spouse in ",key(fam)) |
| 65 |
"person " key(person) " is not a spouse in " key(fam) nl() |
| 66 |
} |
| 67 |
elsif(ne(1,okboss)){ |
| 68 |
print("\nperson ",key(person)," is a spouse in ",key(fam), |
| 69 |
" ",d(okboss)," times") |
| 70 |
"person " key(person) " is a spouse in " key(fam) |
| 71 |
" " d(okboss) " times" nl() |
| 72 |
} |
| 73 |
|
| 74 |
} |
| 75 |
/* now check that this person is a child in the family |
| 76 |
he thinks he is (and only once) */ |
| 77 |
set(fcnt, 0) |
| 78 |
set(s, child(root(person))) |
| 79 |
while(s) { |
| 80 |
if(eqstr(tag(s), "FAMC")) { |
| 81 |
if(v, value(s)) { |
| 82 |
set(fcnt, add(fcnt, 1)) |
| 83 |
if(reference(v)) { |
| 84 |
set(okboss,0) |
| 85 |
children(fam(v),child,num){ |
| 86 |
if (eq(person,child)) {set(okboss, add(okboss,1))} |
| 87 |
} |
| 88 |
set(x, substring(v, 2, sub(strlen(v),1))) |
| 89 |
if (eq(0,okboss)){ |
| 90 |
print("\nperson ",key(person)," is not in family ", x) |
| 91 |
"person " key(person) " is not in family " x nl() |
| 92 |
} |
| 93 |
if (gt(okboss, 1)) { |
| 94 |
print("\nperson ",key(person)," is in family ",x," ", |
| 95 |
d(okboss), " times") |
| 96 |
"person " key(person) " is in family " x " " |
| 97 |
d(okboss) " times" nl() |
| 98 |
} |
| 99 |
} |
| 100 |
} |
| 101 |
} |
| 102 |
set(s, sibling(s)) |
| 103 |
} |
| 104 |
if(gt(fcnt, 1)) { |
| 105 |
print("\nperson ",key(person)," is a child in ", d(fcnt), " families") |
| 106 |
"person " key(person) " is a child in " d(fcnt) " families" nl() |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
/* now check families so that for every spouse the family says is in the |
| 111 |
family, that spouse also thinks he/she is in the family. */ |
| 112 |
/* the family keys aren't terribly useful in LL (or out since LL |
| 113 |
will change the key numbers on import), so print out the key |
| 114 |
of the indi involved, also */ |
| 115 |
|
| 116 |
forfam(fam, number) { |
| 117 |
set(wcnt,0) |
| 118 |
set(hcnt,0) |
| 119 |
set(s, child(root(fam))) |
| 120 |
while(s) { |
| 121 |
if(or(eqstr(tag(s), "HUSB"), eqstr(tag(s), "WIFE"))) { |
| 122 |
if(eqstr(tag(s), "HUSB")) { |
| 123 |
set(hcnt, add(hcnt,1)) |
| 124 |
if(gt(hcnt, 1)) { |
| 125 |
print("\nfamily ",key(fam)," has more then one husband ", |
| 126 |
substring(value(s), 2, sub(strlen(value(s)),1))) |
| 127 |
"family " key(fam) " has more then one husband " |
| 128 |
substring(value(s), 2, sub(strlen(value(s)),1)) |
| 129 |
} |
| 130 |
} |
| 131 |
if(eqstr(tag(s), "WIFE")) { |
| 132 |
set(wcnt, add(wcnt,1)) |
| 133 |
if(gt(wcnt, 1)) { |
| 134 |
print("\nfamily ",key(fam)," has more then one wife ", |
| 135 |
substring(value(s), 2, sub(strlen(value(s)),1))) |
| 136 |
"family " key(fam) " has more then one wife " |
| 137 |
substring(value(s), 2, sub(strlen(value(s)),1)) |
| 138 |
} |
| 139 |
} |
| 140 |
if(v, value(s)) { |
| 141 |
if(reference(v)) { |
| 142 |
set(i, indi(v)) |
| 143 |
if(eq(i,0)) { |
| 144 |
print("\nmissing person ",v," in family ",key(fam)) |
| 145 |
"missing person " v " in family " key(fam) nl() |
| 146 |
} |
| 147 |
else { |
| 148 |
set(okboss,0) |
| 149 |
families(i, fam2, spouse, nfam) { |
| 150 |
if (eq(fam,fam2)){ set(okboss,add(okboss,1))} |
| 151 |
} |
| 152 |
if(eq(okboss, 0)) { |
| 153 |
print("\nperson ",key(i), |
| 154 |
" is not linked as a spouse to family ", key(fam)) |
| 155 |
"person " key(i) |
| 156 |
" is not linked as a spouse to family " key(fam) |
| 157 |
} |
| 158 |
if(gt(okboss, 1)) { |
| 159 |
print("\nperson ",key(i), |
| 160 |
" is linked as a spouse to family ", key(fam), |
| 161 |
" ",d(okboss)," times") |
| 162 |
"person " key(i) |
| 163 |
" is linked as a spouse to family " key(fam) |
| 164 |
" " d(okboss) " times" |
| 165 |
} |
| 166 |
} |
| 167 |
} |
| 168 |
} |
| 169 |
} |
| 170 |
set(s, sibling(s)) |
| 171 |
} |
| 172 |
if (eq(add(hcnt, wcnt),0)) { |
| 173 |
print("\nno parents in family ",key(fam)) |
| 174 |
"no parents in family " key(fam) |
| 175 |
children(fam,child,num){ |
| 176 |
print(" ",key(child)) |
| 177 |
" " key(child) |
| 178 |
break() |
| 179 |
} |
| 180 |
nl() |
| 181 |
} |
| 182 |
children(fam,child,num) { |
| 183 |
set(ccnt, 0) |
| 184 |
set(s, child(root(child))) |
| 185 |
while(s) { |
| 186 |
if(eqstr(tag(s), "FAMC")) { |
| 187 |
if(v, value(s)) { |
| 188 |
if(reference(v)) { |
| 189 |
if(eqstr(substring(v,2,sub(strlen(v),1)), key(fam))) { |
| 190 |
set(ccnt, add(ccnt, 1)) |
| 191 |
} |
| 192 |
} |
| 193 |
} |
| 194 |
} |
| 195 |
set(s, sibling(s)) |
| 196 |
} |
| 197 |
if(eq(ccnt,0)) { |
| 198 |
print("\nchild ",key(child)," is not linked to family ",key(fam)) |
| 199 |
"child " key(child) " is not linked to family " key(fam) nl() |
| 200 |
} |
| 201 |
if(gt(ccnt,1)) { |
| 202 |
print("\nchild ",key(child)," is linked to family ",key(fam), |
| 203 |
" ", d(ccnt)," times") |
| 204 |
"child " key(child) " is linked to family " key(fam) |
| 205 |
" " d(ccnt) " times" nl() |
| 206 |
} |
| 207 |
} |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
proc checksex(i) |
| 212 |
{ |
| 213 |
set(val, "") |
| 214 |
set(count, 0) |
| 215 |
set(r, inode(i)) |
| 216 |
traverse (r, n, x) { |
| 217 |
if(eqstr(tag(n), "SEX")) { |
| 218 |
set(count, add(count,1)) |
| 219 |
if(eq(value(n),0)) { |
| 220 |
print("\nSEX record with no value ",key(i)) |
| 221 |
"SEX record with no value " key(i) nl() |
| 222 |
} |
| 223 |
elsif(or(eqstr(value(n), "M"), eqstr(value(n), "F"), |
| 224 |
eqstr(value(n), "?"), |
| 225 |
and(ALLOWSEXU,eqstr(value(n), "U")))) { |
| 226 |
if(and(ne(count, 1),not(eqstr(value(n),val)))) { |
| 227 |
print("\nconflicting SEX records ",val," and ",value(n)," ",key(i)) |
| 228 |
"conflicting SEX records " val " and " value(n) " " key(i) nl() |
| 229 |
} |
| 230 |
set(val,value(n)) |
| 231 |
} |
| 232 |
else { |
| 233 |
print("\nSEX record with unrecognize value ",value(n)," ",key(i)) |
| 234 |
"SEX record with unrecognize value " value(n) " " key(i) nl() |
| 235 |
set(val,value(n)) |
| 236 |
} |
| 237 |
} |
| 238 |
} |
| 239 |
if(and(WARNNOSEX, eq(count, 0))) { |
| 240 |
print("\nno SEX record ",key(i)) |
| 241 |
"no SEX record " key(i) nl() |
| 242 |
} |
| 243 |
elsif(gt(count,1)) { |
| 244 |
print("\ntoo many SEX records (",d(count),") ",key(i)) |
| 245 |
"too many SEX records (" d(count) ") " key(i) nl() |
| 246 |
} |
| 247 |
} |
| 248 |
|
| 249 |
proc countnodes(n) |
| 250 |
{ |
| 251 |
set(count, 0) |
| 252 |
if(n) { |
| 253 |
set(count, 1) |
| 254 |
set(t, tag(n)) |
| 255 |
while(s, sibling(n)) { |
| 256 |
if(eqstr(tag(s), t)) { |
| 257 |
set(count, add(count,1)) |
| 258 |
} |
| 259 |
} |
| 260 |
} |
| 261 |
return(count) |
| 262 |
} |