| 1 |
/* |
| 2 |
* @progname st_db.li |
| 3 |
* @version 1.26 [of 2005-02-01] |
| 4 |
* @author Perry Rapp |
| 5 |
* @category self-test |
| 6 |
* @output none |
| 7 |
* @description |
| 8 |
* |
| 9 |
* Exercise some database functions. |
| 10 |
* Dumps some of each type of record, followed by all 3 gengedcoms. |
| 11 |
* |
| 12 |
*/ |
| 13 |
|
| 14 |
char_encoding("ASCII") |
| 15 |
|
| 16 |
require("lifelines-reports.version:1.3") |
| 17 |
option("explicitvars") /* Disallow use of undefined variables */ |
| 18 |
include("st_aux") |
| 19 |
|
| 20 |
global(dead) |
| 21 |
global(cutoff_yr) |
| 22 |
|
| 23 |
/* entry point in case not invoked via st_all.ll */ |
| 24 |
proc main() |
| 25 |
{ |
| 26 |
call exerciseDb() |
| 27 |
} |
| 28 |
|
| 29 |
proc exerciseDb() |
| 30 |
{ |
| 31 |
|
| 32 |
"database: " database() nl() |
| 33 |
"version: " version() nl() |
| 34 |
|
| 35 |
set(cutoff_yr, 1900) /* assume anyone born before this is dead */ |
| 36 |
|
| 37 |
set(N, 5) /* output this many of each type of record */ |
| 38 |
|
| 39 |
set(living,0) |
| 40 |
set(dead,0) |
| 41 |
|
| 42 |
/* count up # of living & dead indis, and output first N of each */ |
| 43 |
nl() nl() "*** PERSONS ***" nl() nl() |
| 44 |
indiset(iset) |
| 45 |
forindi (person, pnum) |
| 46 |
{ |
| 47 |
/* exercise indi stuff with the first person */ |
| 48 |
if (lt(add(living,dead),1)) |
| 49 |
{ |
| 50 |
call exerciseIndi(person) |
| 51 |
} |
| 52 |
/* output the first N living & first N dead people */ |
| 53 |
if (isLivingPerson(person)) |
| 54 |
{ |
| 55 |
set(living,add(living,1)) |
| 56 |
if (lt(living,N)) |
| 57 |
{ |
| 58 |
call outputLivingIndi(person) |
| 59 |
addtoset(iset,person,1) |
| 60 |
} |
| 61 |
} |
| 62 |
else |
| 63 |
{ |
| 64 |
set(dead,add(dead,1)) |
| 65 |
if (lt(dead,N)) |
| 66 |
{ |
| 67 |
call outputRec(person) |
| 68 |
addtoset(iset,person,0) |
| 69 |
} |
| 70 |
} |
| 71 |
} |
| 72 |
nl() "Live INDI: " d(living) nl() |
| 73 |
"Dead INDI: " d(dead) nl() |
| 74 |
|
| 75 |
set(living,0) |
| 76 |
set(dead,0) |
| 77 |
/* count up # of living & dead fams, and output first N of each */ |
| 78 |
|
| 79 |
nl() nl() "*** FAMILIES ***" nl() nl() |
| 80 |
forfam (fam, fnum) |
| 81 |
{ |
| 82 |
/* output the first N living & first N dead families */ |
| 83 |
if (isLivingFam(fam)) |
| 84 |
{ |
| 85 |
set(living,add(living,1)) |
| 86 |
if (lt(living,N)) |
| 87 |
{ |
| 88 |
call outputLivingFam(fam) |
| 89 |
} |
| 90 |
} |
| 91 |
else |
| 92 |
{ |
| 93 |
set(dead,add(dead,1)) |
| 94 |
if (lt(dead,N)) |
| 95 |
{ |
| 96 |
call outputRec(fam) |
| 97 |
} |
| 98 |
} |
| 99 |
} |
| 100 |
nl() "Live FAM: " d(living) nl() |
| 101 |
"Dead FAM: " d(dead) nl() |
| 102 |
|
| 103 |
nl() nl() "*** SOURCES ***" nl() nl() |
| 104 |
forsour (sour,snum) |
| 105 |
{ |
| 106 |
if (lt(snum,N)) |
| 107 |
{ |
| 108 |
call outputRec(sour) |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
nl() nl() "*** EVENTS ***" nl() nl() |
| 113 |
foreven (even,enum) |
| 114 |
{ |
| 115 |
if (lt(enum,N)) |
| 116 |
{ |
| 117 |
call outputRec(even) |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
nl() nl() "*** OTHERS ***" nl() nl() |
| 122 |
forothr (othr,onum) |
| 123 |
{ |
| 124 |
if (lt(onum,N)) |
| 125 |
{ |
| 126 |
call outputRec(othr) |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
nl() nl() "*** GENGEDCOM *** " nl() nl() |
| 131 |
gengedcom(iset) |
| 132 |
nl() nl() "*** GENGEDCOMWEAK *** " nl() nl() |
| 133 |
gengedcomweak(iset) |
| 134 |
nl() nl() "*** GENGEDCOMSTRONG *** " nl() nl() |
| 135 |
gengedcomstrong(iset) |
| 136 |
} |
| 137 |
|
| 138 |
/* Output entire record, except filter out SOUR & NOTE sections */ |
| 139 |
proc outputRec(record) |
| 140 |
{ |
| 141 |
traverse (root(record), node, level) |
| 142 |
{ |
| 143 |
if (or(eq(level,0),and(ne(tag(node),"SOUR"),ne(tag(node),"NOTE")))) |
| 144 |
{ |
| 145 |
d(level) " " xref(node) " " tag(node) " " value(node) |
| 146 |
nl() |
| 147 |
} |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
proc outputLivingIndi(indi) |
| 152 |
{ |
| 153 |
"0 @" key(indi) "@ INDI" nl() |
| 154 |
"1 NAME " fullname(indi,0,1,50) nl() |
| 155 |
fornodes(inode(indi), node) |
| 156 |
{ |
| 157 |
if (isFamilyPtr(node)) |
| 158 |
{ |
| 159 |
"1 " xref(node) " " tag(node) " " value(node) |
| 160 |
nl() |
| 161 |
} |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
proc outputLivingFam(fam) |
| 166 |
{ |
| 167 |
"0 @" key(fam) "@ FAM" nl() |
| 168 |
fornodes(root(fam), node) |
| 169 |
{ |
| 170 |
if (isMemberPtr(node)) |
| 171 |
{ |
| 172 |
"1 " xref(node) " " tag(node) " " value(node) |
| 173 |
nl() |
| 174 |
} |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
func isLivingFam(fam) |
| 179 |
{ |
| 180 |
fornodes(root(fam), node) |
| 181 |
{ |
| 182 |
if (isMemberPtr(node)) |
| 183 |
{ |
| 184 |
if (isLivingPerson(indi(value(node)))) { return (1) } |
| 185 |
} |
| 186 |
} |
| 187 |
return (0) |
| 188 |
} |
| 189 |
|
| 190 |
func isLivingPerson(indi) |
| 191 |
{ |
| 192 |
if (death(indi)) { return (0) } |
| 193 |
if (birth(indi)) |
| 194 |
{ |
| 195 |
list(placelist) |
| 196 |
extractplaces(birth(indi), placelist, count) |
| 197 |
extractdate(birth(indi),day,mon,yr) |
| 198 |
if (and(gt(yr,300),lt(yr,cutoff_yr))) { return (0) } |
| 199 |
} |
| 200 |
return (1) |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
func isFamilyPtr (node) |
| 205 |
{ |
| 206 |
if (eq(tag(node),"FAMC")) { return (1) } |
| 207 |
if (eq(tag(node),"FAMS")) { return (1) } |
| 208 |
return (0) |
| 209 |
} |
| 210 |
|
| 211 |
func isMemberPtr (node) |
| 212 |
{ |
| 213 |
if (eq(tag(node),"HUSB")) { return (1) } |
| 214 |
if (eq(tag(node),"WIFE")) { return (1) } |
| 215 |
if (eq(tag(node),"CHIL")) { return (1) } |
| 216 |
return (0) |
| 217 |
} |
| 218 |
|
| 219 |
/* Uses a lot of function calls */ |
| 220 |
proc exerciseIndi(indi) |
| 221 |
{ |
| 222 |
list(lst) |
| 223 |
set(em, empty(lst)) |
| 224 |
enqueue(lst, indi) |
| 225 |
push(lst, father(indi)) |
| 226 |
requeue(lst, mother(indi)) |
| 227 |
set(junk,pop(lst)) |
| 228 |
setel(lst, 1, nextsib(indi)) |
| 229 |
forlist(lst, el, count) |
| 230 |
{ |
| 231 |
name(el) " " d(count) nl() |
| 232 |
} |
| 233 |
table(tbl) |
| 234 |
insert(tbl, "bob", indi) |
| 235 |
set(thing, lookup(tbl, "bob")) |
| 236 |
indiset(iset) |
| 237 |
addtoset(iset,indi,"bob") |
| 238 |
set(iset,union(iset,parentset(iset))) |
| 239 |
addtoset(iset,indi,"jerry") |
| 240 |
addtoset(iset,father(indi), "dad") |
| 241 |
addtoset(iset,mother(indi), "mom") |
| 242 |
addtoset(iset,nextsib(indi), "bro") |
| 243 |
spouses(indi,spouse,fam,num) |
| 244 |
{ |
| 245 |
addtoset(iset,spouse,fam) |
| 246 |
"spouse: " fullname(spouse, true, true, 20) nl() |
| 247 |
} |
| 248 |
families(indi,fam,spouse,num) |
| 249 |
{ |
| 250 |
addtoset(iset,spouse,num) |
| 251 |
"family: " key(fam) nl() |
| 252 |
children(fam, chil, chilnum) |
| 253 |
{ |
| 254 |
addtoset(iset, chil, chilnum) |
| 255 |
"child: " key(chil) nl() |
| 256 |
} |
| 257 |
} |
| 258 |
addtoset(iset,nextindi(indi),"next") |
| 259 |
addtoset(iset,previndi(indi),"prev") |
| 260 |
set(ichildren, childset(iset)) |
| 261 |
set(isiblings, siblingset(iset)) |
| 262 |
set(ispouses, spouseset(iset)) |
| 263 |
set(iancestors, ancestorset(iset)) |
| 264 |
set(idescendants, descendentset(iset)) |
| 265 |
uniqueset(iancestors) |
| 266 |
indiset(jset) |
| 267 |
addtoset(jset, indi, "first") |
| 268 |
if (inset(jset, indi)) { |
| 269 |
addtoset(jset, indi, "second") |
| 270 |
} |
| 271 |
deletefromset(jset, indi, 0) |
| 272 |
namesort(iancestors) |
| 273 |
valuesort(iancestors) |
| 274 |
keysort(iancestors) |
| 275 |
set(kset, intersect(iset,iancestors)) |
| 276 |
set(kset, difference(iset,iancestors)) |
| 277 |
set(p,99) |
| 278 |
"name: " name(indi) nl() |
| 279 |
"title: " title(indi) nl() |
| 280 |
"key: " key(indi) nl() |
| 281 |
parents(indi) nl() |
| 282 |
"fullname(12): " fullname(indi,true,true,12) nl() |
| 283 |
"surname: " surname(indi) nl() |
| 284 |
"givens: " givens(indi) nl() |
| 285 |
"trimname(8): " trimname(indi,8) nl() |
| 286 |
lock(indi) |
| 287 |
call dumpnode("birth", birth(indi)) |
| 288 |
call dumpnodetr("death", death(indi)) |
| 289 |
unlock(indi) |
| 290 |
fornotes(inode(indi), notetext) { /* exercise fornotes */ |
| 291 |
set(currentext, notetext) |
| 292 |
} |
| 293 |
} |
| 294 |
|
| 295 |
proc dumpnode(desc, node) |
| 296 |
{ |
| 297 |
if (node) |
| 298 |
{ |
| 299 |
desc ": " xref(node) " " tag(node) " " value(node) |
| 300 |
fornodes(node, child) |
| 301 |
{ |
| 302 |
call dumpnode2(child) |
| 303 |
} |
| 304 |
} |
| 305 |
} |
| 306 |
|
| 307 |
proc dumpnode2(node) |
| 308 |
{ |
| 309 |
xref(node) " " tag(node) " " value(node) |
| 310 |
fornodes(node, child) |
| 311 |
{ |
| 312 |
call dumpnode2(child) |
| 313 |
} |
| 314 |
} |
| 315 |
|
| 316 |
proc dumpnodetr(desc, node) |
| 317 |
{ |
| 318 |
if (node) |
| 319 |
{ |
| 320 |
desc ": " xref(node) " " tag(node) " " value(node) nl() |
| 321 |
traverse(node, child,lvl) |
| 322 |
{ |
| 323 |
xref(node) " " tag(node) " " value(node) nl() |
| 324 |
} |
| 325 |
} |
| 326 |
} |
| 327 |
|
| 328 |
|