File: altern.ll

package info (click to toggle)
lifelines 3.0.50-2
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 11,140 kB
  • ctags: 6,517
  • sloc: ansic: 57,468; xml: 8,014; sh: 4,255; makefile: 848; yacc: 601; perl: 170; sed: 16
file content (78 lines) | stat: -rw-r--r-- 2,113 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
 * @progname    altern.ll
 * @version     2.0
 * @author      Rafal T. Prinke
 * @category
 * @output      Text
 * @description
 *      find the longest line of alternating male/female links
 *
        v.1.0  Rafal T. Prinke - 14 APR 1997
        v.2.0  Rafal T. Prinke - 16 NOV 1999
*/

global(who)
global(was)
global(final)

proc main()

{
        set(final,0)
        list(who)
        table(was)
        forfam(f, y) {
                if(eq(nchildren,0)) {
                        if(husband(f)) {
                                call line(husband(f))
                                insert(was, key(husband(f)), 1)
                        }
                        if(wife(f))    {
                                call line(wife(f))
                                insert(was, key(wife(f)), 1)
                        }
                }
        }

"The longest alternating ancestral lines are: \n\n"

        while(not(empty(who))) {
                set(n, dequeue(who))
                set(count, 1)
                d(count) ". " name(n, 0) "\n"
                while(parents(n)) {
                        set(count, add(count, 1))
                        if (eqstr(sex(n),"M")) {
                                set(n, mother(n))
                        }
                        else { set(n, father(n)) }
                        d(count) ". " name(n, 0) "\n"
                }
        "\n"
        }
}



proc line (x) {
        if(not(lookup(was,key(x)))) {
                set(p, x)
                set(count,1)
                while(parents(x)) {
                        if (eqstr(sex(x),"M")) {
                                set(x, mother(x))
                        }
                        else { set(x, father(x))
                        }
                        set(count,add(count,1))
                }
                if (eq(count, final)) {
                        enqueue(who, p)
                }
                if (gt(count, final)) {
                        list(who)
                        enqueue(who, p)
                        set(final, count)
                }
        }
}