Debian Codegraph @

reports/grand.ll

raw
1 /*
2 * @progname grand
3 * @version 1.1
4 * @author Stephen Dum
5 * @category
6 * @output text
7 * @description
8
9 For a selected individual this program outputs a list of children,
10 grand children, great grand children and great great grand children.
11
12 Output format is simple text, roughly 80 columns. Each list is sorted
13 by date person 'entered' the family either by birth date or adoption.
14
15 Note - if multiple children have the same birth date, they are all given
16 the same rank. Thus numbering can appear to repeat. I.E. you might see
17 1., 2., 2., 4. ... if the second and third child were born on the same date.
18
19 grand - a LifeLines database program
20 by Stephen Dum [email protected]
21 Version 1, 15 December 2002
22 Version 1.1, 3 June 2007 - minor update
23 */
24
25 global(gkdates) /* list of numeric versions of dates for sorting */
26 global(refind) /* list used to hold indexes of dates sorted*/
27 global(adopt_event)
28 proc main()
29 {
30 dayformat(0) /* leave spaces in single digit days */
31 monthformat(4) /* print month as Jan... */
32 dateformat(0) /* use 'da mon year' order */
33
34 list(gkdates)
35 list(refind)
36
37 /* for finding children */
38 list(par) /* list of selected individual */
39 list(kids) /* children of selected individual */
40 list(kids_par) /* and their parent -- unused and all same but
41 needed for compatibility with later calls */
42 list(kids_adop) /* list of adoption flag */
43
44 /* for finding grand children. at a given index is person in gkids
45 * and at the same index in gkids_par is the parent */
46 list(gkids) /* list of grand children */
47 list(gkids_par) /* index into kids array to parent */
48 list(gkids_adop) /* adoption flag */
49
50 /* for finding great grand children */
51 list(ggkids) /* list of great grand children */
52 list(ggkids_par) /* index into gkids array to the parent */
53 list(ggkids_adop) /* adoption flag */
54
55 /* for finding great great grand children */
56 list(gggkids) /* list of great great grand children */
57 list(gggkids_par) /* index into ggkids array so we can get parent */
58 list(gggkids_adop) /* adoption flag */
59
60 /* for finding great great great grand children */
61 list(ggggkids) /* list of great great great grand children */
62 list(ggggkids_par) /* index into gggkids array so we can get parent */
63 list(ggggkids_adop) /* adoption flag */
64
65 /* select individual for report */
66 set(indi0, NULL)
67 set(count,5)
68 while (not(indi0)) {
69 getindi(indi0,"Enter person to find grand children for:")
70 if (not(indi0)) {
71 print("Individual not found in database.",nl())
72 decr(count)
73 if (not(count)) {
74 print("aborting", nl())
75 return(0)
76 }
77 }
78 }
79 enqueue(par,indi0)
80
81 /* put out header */
82 call print_header(indi0)
83
84 /* compute children of selected individual */
85 call compute_child(par,kids,kids_par,kids_adop)
86
87 /* and print children */
88 if (not(length(kids))) {
89 print("No children!",nl())
90 return(0)
91 }
92 /* for children only 1st 3 params and last are used */
93 call print_kids(kids, kids_par, kids_adop, kids, kids_par,
94 kids, kids_par, kids, 0)
95
96 /* compute grand children */
97 call compute_child(kids,gkids,gkids_par,gkids_adop)
98 if(length(gkids)) {
99 call print_kids(gkids, gkids_par, gkids_adop, kids, kids_par,
100 kids, kids_par, kids, 1)
101
102 /* compute great grand children */
103 call compute_child(gkids,ggkids,ggkids_par,ggkids_adop)
104 if(length(ggkids)) {
105 /* print grand children */
106 call print_kids(ggkids, ggkids_par, ggkids_adop, gkids, gkids_par,
107 kids, kids_par, kids, 2)
108
109 /* compute great great grand children */
110 call compute_child(ggkids,gggkids,gggkids_par,gggkids_adop)
111 if (length(gggkids)) {
112 call print_kids(gggkids, gggkids_par, gggkids_adop,
113 ggkids, ggkids_par,
114 gkids, gkids_par, kids, 3)
115
116 /* compute great great great grand children */
117 call compute_child(gggkids,ggggkids,ggggkids_par,ggggkids_adop)
118 if (length(ggggkids)) {
119 call print_kids(ggggkids, ggggkids_par, ggggkids_adop,
120 gggkids, gggkids_par,
121 ggkids, ggkids_par, gkids, 4)
122 }
123 }
124 }
125 }
126 }
127
128 /* compute children from list of parents
129 * p - list of parents
130 * c - children being computed
131 * c_p - indexes into p corresponding to each child
132 * a - list of adoption dates (or null) for each child
133 *
134 * p is passed in, c,c_p and a are outputs and assumed to be zero lenght
135 * at call
136 * gkdates - dates to sort by
137 */
138 proc compute_child(p,c,c_p,a) {
139 /* clear out the gkdates list - easy it's global*/
140 list(gkdates)
141
142 forlist(p, e, i) {
143 families(e, f, indi, j) {
144 children(f, nextchild, k) {
145 /* if child is already in the list, we want the
146 * one with the earliest date only
147 * This is rare, we could set adopt to -1 and use
148 * as a flag to print twice, but not count twice
149 */
150 if (birth(nextchild)) {
151 set(sortdate,get_date(birth(nextchild)))
152 } else {
153 set(sortdate,0)
154 }
155 if (x,isadopted(nextchild,f,e)) {
156 /*
157 * if adopted, put adopt_date into gkdates
158 * This makes listing
159 * include adopted as date joined family
160 */
161 if (date(adopt_event)) {
162 set(sortdate, get_date(adopt_event))
163 }
164 }
165 if (dupind,finddup(c,nextchild)) {
166 /* found duplicate
167 * if new sortdate is smaller than previous, use it
168 */
169 if (lt(sortdate,getel(gkdates,dupind))) {
170 setel(c_p,dupind,i)
171 setel(a,dupind,x)
172 setel(gkdates,dupind,sortdate)
173 }
174 } else {
175 enqueue(gkdates, sortdate)
176 enqueue(c, nextchild)
177 enqueue(c_p,i)
178 enqueue(a,x)
179 }
180 }
181 }
182 }
183 }
184
185 /* finddup(clist,ind_child)
186 * see if ind_child is already in the list, if so, return
187 * the index for the child - we could use inlist() but
188 * it doesn't give us the index of the match
189 */
190 func finddup(clist,ind_child) {
191 forlist(clist,e, i) {
192 if (eq(e,ind_child)) { return(i) }
193 }
194 return(0)
195 }
196
197 /* print_kids - for lower levels not all arrays are used
198 * k1 - list of children being printed
199 * g1 - index into k2 for parents of children
200 * a - list of adopted flags
201 * k2 - list of parents of children
202 * g2 - index into k3 for grand parents
203 * k3 - list of grandparents
204 * g3 - index into k4 for great grandparents
205 * k4 - list of great grandparents
206 * index - how many levels to print
207 */
208 proc print_kids(k1, g1, a, k2, g2, k3, g3, k4, level) {
209 list(refind)
210 set(adopted, 0) /* count number of adopted children */
211 /* refind is used to get to names corresponding to elements of
212 * the gkdates list after sorting
213 */
214 set(len,length(gkdates))
215 set(index,len)
216 while(index) {
217 setel(refind,index,index)
218 decr(index)
219 }
220 sort(refind,gkdates)
221
222 set(dups,0)
223
224 /* print out the title for the section */
225 set(title,start_section(level))
226
227 /* Iterate over values in refind and print out the data
228 * lasti - last printed rank for individual
229 * lastd - birth date of previous entry for same date check
230 * count - child rank
231 *
232 * index - child rank to print for this individual
233 */
234 set(lasti,1)
235 set(lastd,getel(gkdates,1))
236 set(count,0)
237 forlist(refind, ind, i) {
238 set(cur_per, getel(k1, ind))
239 set(cur_per_par_ind, getel(g1, ind))
240
241 /* list all children with same birth date as same number
242 * also, second marriages and adoptions may cause child to be
243 * listed twice, it's easiest to remove here, since data is sorted
244 * by birthdate.
245 */
246 incr(count)
247 if (ne(lastd,getel(gkdates,i))) {
248 /* dates are different */
249 set(index,count)
250 set(lasti,count)
251 set(lastd,getel(gkdates,i))
252 } else {
253 /* date same, keep using same index value */
254 set(index,lasti)
255 }
256 set(adopt,getel(a,ind))
257 /* uncomment next 3 lines if you want adopted children to listed,
258 * but not counted
259 if (adopt) {
260 "--"
261 decr(count)
262 }
263 */
264 d(index)
265 /* print first line */
266 "." col(5) name(cur_per,false)
267 col(36) date(birth(cur_per))
268 if (eq(level, 0)) {
269 if(adopt) {
270 incr(adopted)
271 col(49) "Adopt:" adopt
272 }
273 nl()
274 } else {
275 col(49) name(getel(k2,cur_per_par_ind),false) nl()
276 if(adopt) {
277 incr(adopted)
278 col(5) "Adopt:" adopt
279 }
280 nl()
281 }
282 if (ne(date(death(cur_per)), 0)) {
283 col(5) "died: " date(death(cur_per))
284 if (lt(level,2)) {
285 nl()
286 }
287 }
288 if (gt(level, 1)) {
289 set(gpar,getel(g2,cur_per_par_ind))
290 col(23) name(getel(k3,gpar),false)
291 }
292 if (gt(level,2)) {
293 col(49) name(getel(k4,getel(g3,gpar)),false)
294 }
295 if (gt(level,1)) {
296 nl()
297 }
298 }
299
300 /* print section summary */
301 set(count,sub(length(k1),dups))
302 nl()
303 d(count) " " title
304 if (adopted) { " (" d(adopted) " adopted)" }
305 nl()
306 print(d(count), " ", title)
307 if (adopted) { print(" (",d(adopted)," adopted)") }
308 print(nl())
309 }
310
311 proc print_header(parent) {
312 col(30) "Children of" nl()
313 col(30) name(parent,false) nl()
314 families(parent, f, ind, i) {
315 col(30) "Spouse: " name(ind, false) nl()
316 }
317 }
318 func start_section(level) {
319 nl()
320 if (eq(level,0)) {
321 set(title,"Children")
322 print_ref(title)
323 nl()
324 col(5) "Name" col(36) "Birth" nl()
325 } elsif (eq(level,1)) {
326 set(title,"Grand Children")
327 print_ref(title)
328 nl()
329 col(5) "Name" col(36) "Birth" col(49) "Parent" nl()
330 } elsif (eq(level,2)) {
331 set(title,"Great Grand Children")
332 print_ref(title)
333 nl()
334 col(5) "Name" col(36) "Birth" col(49) "Parent" nl()
335 col(23) "Grand Parent" nl()
336 } elsif (eq(level,3)) {
337 set(title,"Great Great Grand Children")
338 print_ref(title)
339 nl()
340 col(5) "Name" col(36) "Birth" col(49) "Parent" nl()
341 col(23) "Grand Parent" col(49) "Great Grand Parent" nl()
342 } else {
343 set(title,"Great Great Great Grand Children")
344 print_ref(title)
345 nl()
346 col(5) "Name" col(36) "Birth" col(49) "Parent" nl()
347 col(23) "Grand Parent" col(49) "Great Grand Parent" nl()
348 }
349 return(title)
350 }
351
352 func print_ref(title) {
353 set(l,div(sub(80,strlen(title)),2))
354 col(l) title nl()
355 set(name, concat(" (Compiled by ",getproperty("user.fullname")," ",
356 stddate(gettoday()),")",nl()))
357 set(l, add(26,strlen(name)))
358 set(l,div(sub(80,strlen(name)),2))
359 col(l) name
360 }
361
362 /* check to see if person in family fam is adopted by par */
363 /* returns 0 if not adopted */
364 func isadopted(per,fam, par) {
365 /*
366 * in gedcom 5.5 the structure is
367 * 1 INDI
368 * 2 ADOP
369 * 3 FAMC
370 * 4 ADOP (BOTH|HUSB|WIFE)
371 */
372 set(x,xref(fnode(fam)))
373 fornodes(inode(per),e) {
374 if(eqstr(tag(e),"ADOP")) {
375 /*
376 print("adopt record for ",name(per),nl())
377 */
378 fornodes(e,fam) {
379 /* check for 'FAMC' with value x */
380 if(and(eqstr(tag(fam),"FAMC"),eqstr(value(fam),x))) {
381 /* now see if famc has a adop record */
382 /*
383 print("... match FAMC ",x,nl())
384 */
385 fornodes(fam,a) {
386 if(eqstr(tag(a),"ADOP")) {
387 /*
388 print("... ADOP ",value(a)," par=",name(par))
389 if (male(par)) { print(" m") }
390 if (female(par)) { print (" f") }
391 print(nl())
392 */
393 set(adopt_event,e)
394 if(eqstr(value(a),"HUSB")) {
395 if(male(par)) {
396 if(da,date(e)) { return(da) }
397 return("-")
398 }
399 } elsif(eqstr(value(a),"WIFE")) {
400 if(female(par)) {
401 if(da,date(e)) { return(da) }
402 return("-")
403 }
404 } else {
405 /*
406 if(eqstr(value(a),"BOTH")) { .... }
407 must be "BOTH" (note this has side effect that ""
408 is treated as both
409 */
410 if(da,date(e)) { return(da) }
411 else { return("-")}
412 }
413 }
414 }
415 }
416 }
417 }
418 }
419 return(0)
420 }
421
422 /* hack together a integer that can be sorted to represent the date */
423 func get_date(datenode)
424 {
425 extractdate(datenode,day,month,year)
426 return(add(mul(add(mul(year,100), month),100),day))
427 }