Debian Codegraph @

reports/relate.ll

raw
1 /*
2 * @progname relate.ll
3 * @version 1.0
4 * @author Wetmore
5 * @category
6 * @output Text
7 * @description
8 *
9 * Finds a shortest path between two persons in a LifeLines database.
10 * Inspiration from Jim Eggert's relation program.
11
12
13 relate - Finds a shortest path between two persons in a LifeLines
14 database.
15 by Tom Wetmore ([email protected])
16 Inspiration from Jim Eggert's relation program
17 Version 1, 07 September 1993
18 */
19
20 proc main ()
21 {
22 getindimsg(from, "Please identify starting person.")
23 getindimsg(to, "Please identify ending person.")
24 if (and(from, to)) {
25 print("Computing relationship between:\n ")
26 print(name(from)) print(" and ")
27 print(name(to)) print(".\n\nThis may take awhile -- ")
28 print("each dot is a person.\n")
29
30 set(fkey, save(key(from)))
31 set(tkey, save(key(to)))
32 call relate(tkey, fkey)
33 } else {
34 print("We're ready when you are.")
35 }
36 }
37
38 global(links)
39 global(rels)
40 global(klist)
41
42 proc relate (fkey, tkey)
43 {
44 table(links) /* table of links back one person */
45 table(rels) /* table of relationships back one person */
46 list(klist) /* list of persons not linked back to */
47
48 insert(links, fkey, fkey)
49 insert(rels, fkey, ".")
50 enqueue(klist, fkey)
51 set(again, 1)
52
53 while (and(again, not(empty(klist)))) {
54 set(key, dequeue(klist))
55 set(indi, indi(key))
56 call include(key, father(indi), ", father of")
57 call include(key, mother(indi), ", mother of")
58 families(indi, fam, spouse, num1) {
59 children(fam, child, num2) {
60 call include(key, child, ", child of")
61 }
62 if (spouse) {
63 call include(key, spouse, ", spouse of")
64 }
65 }
66 if (fam, parents(indi)) {
67 children(fam, child, num2) {
68 call include(key, child, ", sibling of")
69 }
70 }
71 if (key, lookup(links, tkey)) {
72 call foundpath(tkey)
73 set(again, 0)
74 }
75 }
76 if (again) {
77 print("They are not related to one another.")
78 }
79 }
80
81 proc include (key, indi, tag)
82 {
83 if (and(indi, not(lookup(links, key(indi))))) {
84 print(".")
85 set(new, save(key(indi)))
86 insert(links, new, key)
87 insert(rels, new, tag)
88 enqueue(klist, new)
89 }
90 }
91
92 proc foundpath (key)
93 {
94 print("\n\nA relationship between them was found:\n\n")
95 set(again, 1)
96 while (again) {
97 print(" ")
98 print(name(indi(key)))
99 print(lookup(rels, key))
100 print("\n")
101 set(new, lookup(links, key))
102 if (eq(0, strcmp(key, new))) {
103 set(again, 0)
104 } else {
105 set(key, new)
106 }
107 }
108 }