| 1 |
/* |
| 2 |
* @progname longlines.ll |
| 3 |
* @version 2.0 |
| 4 |
* @author Chandler |
| 5 |
* @category |
| 6 |
* @output Text |
| 7 |
* @description |
| 8 |
|
| 9 |
Find the maximal-length male and female lineages in the database. |
| 10 |
Optionally, find the maximal-length lineage through a specified ancestor. |
| 11 |
|
| 12 |
longlines |
| 13 |
|
| 14 |
Version 1 - 1994 May 19 - John F. Chandler |
| 15 |
Version 2 - 2000 May 4 - John F. Chandler |
| 16 |
|
| 17 |
This program works only with LifeLines. |
| 18 |
|
| 19 |
*/ |
| 20 |
global(len) /* current lineage length */ |
| 21 |
global(lenmax) /* longest lineage found */ |
| 22 |
global(ends) /* keys of last persons */ |
| 23 |
global(linsex) /* sex of lineage desired */ |
| 24 |
|
| 25 |
proc main(){ |
| 26 |
getindi(indi,"Enter specific ancestor, if any, whose longest line you want:") |
| 27 |
if(indi) { |
| 28 |
"Longest descent from " name(indi) " (" key(indi) ")\n\n" |
| 29 |
set(linsex,sex(indi)) |
| 30 |
set(len,1) |
| 31 |
call getline(indi) |
| 32 |
call dumplines() |
| 33 |
} else { |
| 34 |
"Longest lineages in database\n\n Male" |
| 35 |
call getall("M") |
| 36 |
call dumplines() |
| 37 |
"\n Female" |
| 38 |
call getall("F") |
| 39 |
call dumplines() |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
/* scan all offspring matching the sex of the input person, and |
| 44 |
return the longest lineage(s) from those -- if no matching |
| 45 |
offspring, just return the input person as a lineage */ |
| 46 |
proc getline(indi) |
| 47 |
{ |
| 48 |
incr(len) |
| 49 |
families(indi,fam,spou,num) { |
| 50 |
children(fam,child,numc) { |
| 51 |
if(eq(0,strcmp(linsex,sex(child)))) { |
| 52 |
set(found,1) |
| 53 |
call getline(child) |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
decr(len) |
| 58 |
if(and(not(found),ge(len,lenmax))) { |
| 59 |
if(gt(len,lenmax)) {list(ends)} |
| 60 |
enqueue(ends,save(key(indi))) |
| 61 |
set(lenmax,len) |
| 62 |
}} |
| 63 |
|
| 64 |
proc getall(this_sex) |
| 65 |
{ |
| 66 |
set(linsex,this_sex) |
| 67 |
set(lenmax,0) |
| 68 |
print("Starting ", linsex, " ...\n") |
| 69 |
|
| 70 |
/* find all eligible starting points */ |
| 71 |
/* assume that a nameless person doesn't count */ |
| 72 |
forindi (indi, num) { |
| 73 |
set(skip,"") |
| 74 |
if(eq(0,strcmp(linsex,"M"))) {set(par,father(indi))} |
| 75 |
else {set(par,mother(indi))} |
| 76 |
if(par) {set(skip,name(par))} |
| 77 |
if(and(eq(0,strcmp(linsex,sex(indi))),eq(0,strcmp("",skip)))) { |
| 78 |
set(len,1) |
| 79 |
call getline(indi) |
| 80 |
} |
| 81 |
}} |
| 82 |
|
| 83 |
proc dumplines() |
| 84 |
{ |
| 85 |
/* report results */ |
| 86 |
"\n Maximal length " d(lenmax) "\n" |
| 87 |
/* dump each lineage, starting with most recent person */ |
| 88 |
while(end, dequeue(ends)) { |
| 89 |
"\n" |
| 90 |
set(count, lenmax) |
| 91 |
set(line,indi(end)) |
| 92 |
while(line) { |
| 93 |
if(eq(count,0)) {" (extension of the requested line...)\n"} |
| 94 |
decr(count) |
| 95 |
if(eq(0,strcmp(name(line),""))) {"_____"} |
| 96 |
name(line) " (" key(line) ")" |
| 97 |
if(x, birth(line)) {" b. " year(x)} |
| 98 |
if(y, death(line)) { |
| 99 |
if(x) {","} |
| 100 |
" d. " year(y) |
| 101 |
} |
| 102 |
"\n" |
| 103 |
if(eq(0,strcmp(linsex,"M"))) {set(line,father(line))} |
| 104 |
else {set(line,mother(line))} |
| 105 |
} |
| 106 |
if(lt(count,0)) {" (length " d(sub(lenmax,count)) " with extension)\n"} |
| 107 |
}} |