Debian Codegraph @

reports/ged_write.li

raw
1 /*
2 * @progname ged_write.li
3 * @version 3
4 * @author Paul B. McBride ([email protected])
5 * @category
6 * @output GEDCOM
7 * @description
8
9 LifeLines GEDCOM file generating subroutine library.
10 This file defines a procedure ged_write() which extends the gengedcom()
11 builtin function of LifeLines by adding header and trailer records,
12 and outputting other level 0 record types which are referenced
13 within the individual and family records that would be output by
14 gengedcom(). If these records are not output to the GEDCOM file then
15 LifeLines would report links to undefined records, and not load the file
16 into the database. This is particularly useful for SOURce records
17 but also handles REPO, NOTE, EVENt, SUBMitter, other references
18 to INDIvidual and FAMily records, etc.
19
20 The gengedcom() function of LifeLines outputs a GEDCOM file for
21 the specified set of INDIviduals. It handles standard links for
22 FAMilies, and from FAMilies back to INDIviduals. It does not generate
23 the "0 HEAD" records, or the "0 TRLR" record. Also if there are
24 other links ("@xx@") to records of other types, or links to INDIviduals
25 in other structure elements, the records they point to are not output.
26 Requirements:
27 LifeLines 3.0.5 or later or 3.0.3-*win32*
28 Notes:
29 To use this with 3.0.2 to 3.0.4:
30 1) remove lines with "free(...)"
31 2) add an inlist(...)" function. (see example at end)
32 Files:
33 Two other files are also required, samples of which are at the end
34 of this file:
35 header.ged, submit.ged
36 Bugs:
37 Links to FAMilies with tags other than "FAMC" and "FAMS"
38 may cause duplicate FAMily records in some cases.
39
40 08 Sep 1995 v1 add SOUR records to GEDCOM file
41 08 Feb 1996 v2 add REPO records and other records linked within SOUR records
42 17 Feb 2000 v3 resolve all other links to records (if possible)
43 */
44
45 global(ged_other_list)
46 global(ged_other_set)
47 global(ged_other_setlist)
48
49 proc ged_write(gset)
50 {
51 copyfile("header.ged") /* header file (references @SM1@) */
52
53 "1 DATE " stddate(gettoday()) nl()
54
55 copyfile("submit.ged") /* submitter file (defines @SM1@) */
56
57 /* find other records and people referenced by the set */
58
59 set(slen, lengthset(gset))
60 print("Writing GEDCOM file for ", d(slen), " people...")
61 call ged_other_init()
62 call ged_other_addset(gset)
63 if(ne(lengthset(gset), slen)) {
64 print(" ", d(sub(lengthset(gset),slen)), " added...")
65 }
66
67 gengedcom(gset) /* output set as GEDCOM file (INDI and FAM records) */
68
69 /* add other types of records (including SOURces) */
70
71 call ged_other_write()
72
73 "0 TRLR" nl() /* trailer */
74
75 print(nl())
76 }
77
78 proc ged_other_init()
79 {
80 /* for earlier versions of LifeLines remove lines with free() */
81 if(ged_other_list) { free(ged_other_list) }
82 if(ged_other_set) { free(ged_other_set) }
83 if(ged_other_setlist) { free(ged_other_setlist) }
84 /* end of lines to be removed for earlier versions of LifeLines */
85
86 list(ged_other_list)
87 indiset(ged_other_set)
88 list(ged_other_setlist)
89 }
90
91 proc ged_other_addset(s)
92 {
93 /* make a list of each person and family in the set. These
94 * are the INDI and FAM records that gengedcom() will output.
95 */
96 forindiset (s, i, a, n) {
97 set(v, save(concat("@", key(i), "@")))
98 enqueue(ged_other_setlist, v)
99 families(i, f, sp, m) {
100 set(v, save(concat("@", key(f), "@")))
101 enqueue(ged_other_setlist, v)
102 call ged_other_add(root(f))
103 }
104 }
105 /* process each INDI and FAM record to see if it contains references
106 * to other records. We need to add any other record that is referenced
107 * to the GEDCOM file.
108 */
109 forindiset (s, i, a, n) {
110 call ged_other_add(root(i))
111 families(i, f, sp, m) {
112 call ged_other_add(root(f))
113 }
114 }
115 /* add any new people into the original set */
116 forindiset (ged_other_set, i, a, n) {
117 addtoset(s, i, 1)
118 }
119 }
120
121 /* ged_other_add() adds the other records referenced */
122
123 proc ged_other_add(n)
124 {
125 traverse(n, m, l) {
126 if(gt(l, 0)) {
127 if(eq(l, 1)) {
128 if (eqstr("FAMC", tag(m))) { continue() }
129 if (eqstr("FAMS", tag(m))) { continue() }
130 if (eqstr("HUSB", tag(m))) { continue() }
131 if (eqstr("CHIL", tag(m))) { continue() }
132 if (eqstr("WIFE", tag(m))) { continue() }
133 }
134 set(v, value(m))
135 if(reference(v)) {
136 if(eqstr(substring(v,2,2),"I")) {
137 /* process other references to individuals */
138 if(inlist(ged_other_setlist, v)) { continue() }
139 set(v, save(v))
140 enqueue(ged_other_setlist, v)
141 addtoset(ged_other_set, indi(v), 1)
142 call ged_other_add(dereference(v))
143 /* this persons families will also be included */
144 families(indi(v), f, sp, m) {
145 set(fv, save(concat("@", key(f), "@")))
146 enqueue(ged_other_setlist, fv)
147 call ged_other_add(root(f))
148 }
149 continue()
150 }
151 if(eqstr(substring(v,2,2),"F")) {
152 /* process other references to families */
153 /* force a family to be included by adding in one
154 * of the parents.
155 */
156 if(inlist(ged_other_setlist, v)) { continue() }
157 set(v, save(v))
158 enqueue(ged_other_setlist, v)
159 call ged_other_add(dereference(v))
160 set(spseen, 0)
161 set(fs, 0)
162 fornodes(dereference(v), fn) {
163 if(or(eqstr(tag(fn), "HUSB"),eqstr(tag(fn), "WIFE"))) {
164 set(fv, value(fn))
165 if(reference(fv)) {
166 set(fs, save(fv))
167 if(inlist(ged_other_setlist, fs)) {
168 /* this individual is already in the set, so
169 * this family will be output
170 */
171 set(spseen, 1)
172 break()
173 }
174 }
175 }
176 }
177 if(spseen) { continue() }
178 if(fs) {
179 /* force this family to be included by adding a parent
180 * to the set
181 */
182 enqueue(ged_other_setlist, fs)
183 addtoset(ged_other_set, indi(fs), 1)
184 call ged_other_add(dereference(fs))
185 /* this persons families will also be included */
186 families(indi(fs), f, sp, m) {
187 set(fv, save(concat("@", key(f), "@")))
188 enqueue(ged_other_setlist, fv)
189 call ged_other_add(root(f))
190 }
191 continue()
192 }
193 /* family had no parents. add it to the list of others */
194 }
195 if (inlist(ged_other_list, v)) { continue() }
196 set(v, save(v))
197 enqueue(ged_other_list, v)
198 }
199 }
200 }
201 }
202
203 /* ged_other_write() outputs the current list of other records in GEDCOM format */
204
205 proc ged_other_write()
206 {
207 forlist(ged_other_list, k, n) {
208 if(reference(k)) {
209 set(r, dereference(k))
210 traverse(r, s, l) {
211 d(l)
212 if (xref(s)) { " " xref(s) }
213 " " tag(s)
214 if (v, value(s)) {
215 " " v
216 }
217 "\n"
218 }
219 }
220 }
221 }
222
223 /* sample inlist() function for other versions of LifeLines
224
225 func inlist(alist, str)
226 {
227 forlist(alist, any, n) {
228 if(eqstr(any, str)) { return(1) }
229 }
230 return(0)
231 }
232 * end of sample inlist() function */
233
234 /* sample header.ged
235 0 HEAD
236 1 SOUR LIFELINES
237 2 VERS 3.0.5
238 2 NAME LifeLines
239 2 CORP T. T. Wetmore
240 3 ADDR [email protected]
241 1 SUBM @SM1@
242 1 GEDC
243 2 VERS 5.5
244 2 FORM Lineage-Linked
245 1 CHAR ASCII
246 * end of sample header.ged */
247
248 /* sample submit.ged
249 0 @SM1@ SUBM
250 1 NAME Your Name Here
251 1 ADDR Your Street Address
252 2 CONT Your City, State and Zip Code
253 2 CONT E-mail: [email protected]
254 * end of sample submit.ged */
255