Debian Codegraph @

reports/sources_bib.ll

raw
1 /*
2 * @progname sources_bib.ll
3 * @version 1999-02
4 * @author Dennis Nicklaus ([email protected])
5 * @category
6 * @output LaTeX
7 * @description
8
9 Lifelines report program.
10 Write out a LaTex bibliography entry line for each source referenced
11 by an indi or family record in the whole database.
12 This is pretty slow.
13 The bibliography printed out is useful for the html.dn programs
14 (if you first run it through my bib2html.c program)
15 or for a Latex document.
16
17 The bibliography is pretty much the same as that generated as part of
18 the book-latex code. (But book-latex generates its own bibliography,
19 so you don't need this for that.)
20
21 Most of the code for this report program was copied directly from book-latex.
22
23 Deficiency?: May not generate an entry for a source which is only referenced
24 from within another source. I don't know.
25 */
26
27 global (bibList)
28 global (bibTable)
29 global (sourceList)
30 global (gotValue)
31 global (gottenNode)
32 global (gottenValue)
33 global(sour_list)
34 global(sour_table)
35
36 proc main ()
37 {
38 list (bibList)
39 table (bibTable)
40 list (sourceList)
41 table(sour_table)
42 list(sour_list)
43
44 call sour_addset()
45 call sour_ged()
46
47 while (b, dequeue (bibList)) { b }
48
49 }
50
51
52
53
54 proc sour_addset()
55 {
56 forindi(person, number) {
57 print(".")
58 traverse(root(person),m,l) {
59 call print_sources(m)
60 }
61 families(person, f, sp, m) {
62 traverse(root(f),m,l) {
63 call print_sources(m)
64 }
65 }
66 }
67
68 }
69
70 /* sour_ged() outputs the current source list in GEDCOM format */
71
72 proc sour_ged()
73 {
74 table(other_table)
75 list(other_list)
76
77 forlist(sour_list, k, n) {
78 set(r, dereference(k))
79 traverse(r, s, l) {
80 d(l)
81 if (xref(s)) { " " xref(s) }
82 " " tag(s)
83 if (v, value(s)) {
84 " " v
85 if(reference(v)) {
86 if (ne(0, lookup(other_table, v))) { continue() }
87 if (ne(0, lookup(sour_table, v))) { continue() }
88 set(v, save(v))
89 insert(other_table, v, 1)
90 enqueue(other_list, v)
91 }
92 }
93 "\n"
94 }
95 }
96 forlist(other_list, k, n) {
97 set(r, dereference(k))
98 traverse(r, s, l) {
99 d(l)
100 if (xref(s)) { " " xref(s) }
101 " " tag(s)
102 if (v, value(s)) { " " v }
103 "\n"
104 }
105 }
106 }
107 /* print_sources (root)
108 Prints all sources (SOUR lines) associated with the given GEDCOM line. The
109 sources are formated as LaTeX footnotes. This routine prints each SOUR line
110 as a separate footnote, which is not correct. This should be corrected so
111 that all sources are combined into a single footnote. */
112
113 proc print_sources (root)
114 {
115 enqueue(sourceList,root)
116 call sourceIt(sourceList)
117 }
118
119 proc getValue (root, t) {
120 set (gotValue, 0)
121 if (root) {
122 fornodes (root, node) {
123 if (and (not (gotValue), not (strcmp (tag (node), t)))) {
124 set (gotValue, 1)
125 set (gottenNode, node)
126 set (gottenValue, save (value (node)))
127 }
128 }
129 }
130 }
131
132 proc getValueCont (root, t) {
133 set (gotValue, 0)
134 if (root) {
135 fornodes (root, node) {
136 if (and (not (gotValue), not (strcmp (tag (node), t)))) {
137 set (gotValue, 1)
138 set (gottenNode, node)
139 set (gottenValue, save (value (node)))
140 fornodes (node, subnode) {
141 if (not (strcmp ("CONT", tag (subnode)))) {
142 if (strlen (value (subnode))) {
143 set (gottenValue,
144 save (concat (gottenValue, concat ("\n", value (subnode)))))
145 }
146 } elsif (not (strcmp ("CONC", tag (subnode)))) {
147 if (strlen (value (subnode))) {
148 set (gottenValue,
149 save (concat (gottenValue, value (subnode))))
150 }
151 }
152 }
153 }
154 }
155 }
156 }
157
158 proc getValueCommaCont (root, t) {
159 set (gotValue, 0)
160 if (root) {
161 fornodes (root, node) {
162 if (and (not (gotValue), not (strcmp (tag (node), t)))) {
163 set (gotValue, 1)
164 set (gottenNode, node)
165 set (gottenValue, save (value (node)))
166 fornodes (node, subnode) {
167 if (not (strcmp ("CONT", tag (subnode)))) {
168 if (strlen (value (subnode))) {
169 set (gottenValue,
170 save (concat (gottenValue, concat (",\n", value (subnode)))))
171 }
172 } elsif (not (strcmp ("CONC", tag (subnode)))) {
173 if (strlen (value (subnode))) {
174 set (gottenValue,
175 save (concat (gottenValue, value (subnode))))
176 }
177 }
178 }
179 }
180 }
181 }
182 }
183
184
185
186
187 proc sourceIt (sourceList) {
188 list (cList)
189 list (fList)
190 while (root, dequeue (sourceList)) {
191 fornodes (root, node) {
192 if (not (strcmp (tag (node), "SOUR"))) {
193 set (footnote, 1)
194 set (val, value (node))
195 if (val) {
196 if (reference(val)){
197 call bibliographize (dereference(val))
198 }
199 }
200 if (xref (node)) {
201 call bibliographize (node)
202 set (val, xref (node))
203 }
204 if (val) {
205 set (a1, index (val, "@", 1))
206 set (a2, index (val, "@", 2))
207 if (and (eq (a1, 1), eq (a2, strlen (val)))) {
208 set (c, save (substring (val, 2, sub (strlen (val), 1))))
209 enqueue (cList, c)
210 incr (cn)
211 set (footnote, 0)
212 }
213 } else {
214 set (subnodecount, 0)
215 fornodes (node, subnode) {
216 if (strcmp (tag (subnode), "SOUR")) {
217 incr (subnodecount)
218 }
219 }
220 if (eq (subnodecount, 0)) {
221 fornodes (node, subnode) {
222 set (val, value (subnode))
223 /* With loadsources, this is needed here. It is technically
224 illegal gedcom. */
225 if (xref (subnode)) {
226 call bibliographize (subnode)
227 set (val, xref (subnode))
228 }
229 if (val) {
230 set (a1, index (val, "@", 1))
231 set (a2, index (val, "@", 2))
232 if (and (eq (a1, 1), eq (a2, strlen (val)))) {
233 set (c, save (substring (val, 2, sub (strlen (val), 1))))
234 enqueue (cList, c)
235 incr (cn)
236 }
237 }
238 }
239 set (footnote, 0)
240 }
241 }
242 if (footnote) {
243 enqueue (fList, node)
244 }
245 }
246 }
247 }
248 while (cn) {
249 forlist (cList, c, n) {
250 if (and (ne (n, cn), not (strcmp (c, getel(cList, cn))))) {
251 setel (cList, cn, "")
252 }
253 }
254 decr (cn)
255 }
256 }
257
258 proc bibliographize (root) {
259 set (val, xref (root))
260 set (c, save (substring (val, 2, sub (strlen (val), 1))))
261
262 if (not (lookup (bibTable, c))) {
263 insert (bibTable, c, 1)
264
265 /* call getValueCont (root, "TEXT")
266 if (figureFlag, gotValue) {
267 enqueue (figureCiteList, c)
268 enqueue (figureNodeList, gottenNode)
269 }*/
270 set (cref, save (concat ("\\protect\\ref{", concat (c, "}"))))
271 set (pref, save (concat ("\\protect\\pageref{", concat (c, "}"))))
272
273 set (b, "\\bibitem")
274 if (figureFlag) {
275 set (b, save (concat (b, concat ("[", concat (cref, "]")))))
276 }
277 set (b, save (concat (b, concat ("{", concat (c, "} ")))))
278 call getValueCont (root, "TITL")
279 if (gotValue) {
280 set (b, save (concat (b, concat ("{\\em ", concat (gottenValue, "}, ")))))
281 }
282 call getValueCont (root, "AUTH")
283 if (gotValue) {
284 set (b, save (concat (b, concat (" ", concat (gottenValue, ", ")))))
285 }
286 call getValueCont (root, "PUBL")
287 if (gotValue) {
288 set(pubnode,gottenNode)
289 call getValueCont (pubnode, "NAME")
290 if (gotValue) {
291 set (b, save (concat (b, concat ("in {\\em ", concat (gottenValue, "}, ")))))
292 }
293 call getValueCommaCont (pubnode, "ADDR")
294 if (gotValue) { set (b, save (concat (b, concat (gottenValue, ": ")))) }
295 call getValueCont (pubnode, "PUBR")
296 if (gotValue) { set (b, save (concat (b, concat (gottenValue, ", ")))) }
297 call getValueCont (pubnode, "PHON")
298 if (gotValue) { set (b, save (concat (b, concat (gottenValue, ", ")))) }
299 call getValueCont (pubnode, "DATE")
300 if (gotValue) { set (b, save (concat (b, concat (gottenValue, ", ")))) }
301 call getValueCont (pubnode, "VOLU")
302 if (gotValue) {
303 set (word, "Volume ")
304 if (or (index (gottenValue, "-", 1),
305 or (index (gottenValue, ",", 1),
306 index (gottenValue, "and ", 1)))) {
307 set (word, "Volumes ")
308 }
309 set (b, save (concat (b, concat (word, concat (gottenValue, ", ")))))
310 }
311 call getValueCont (pubnode, "NUM")
312 if (gotValue) {
313 set (word, "Number ")
314 if (or (index (gottenValue, "-", 1),
315 or (index (gottenValue, ",", 1),
316 index (gottenValue, "and ", 1)))) {
317 set (word, "Numbers ")
318 }
319 set (b, save (concat (b, concat (word, concat (gottenValue, ", ")))))
320 }
321 call getValueCont (root, "LCCN")
322 if (gotValue) {
323 set (b, save (concat (b, concat ("Call Number ", concat (gottenValue, ", ")))))
324 }
325
326 }
327 call getValueCont (root, "PAGE")
328 if (gotValue) {
329 set (word, "page ")
330 if (or (index (gottenValue, "-", 1),
331 or (index (gottenValue, ",", 1),
332 index (gottenValue, "and ", 1)))) {
333 set (word, "pages ")
334 }
335 set (b, save (concat (b, concat (word, concat (gottenValue, ", ")))))
336 }
337 call getValueCont (root, "FILM")
338 if (gotValue) {
339 set (b, save (concat (b,
340 concat ("Filmed by the Church of Jesus Christ of Latter Day Saints, Microfilm Number ",
341 concat (gottenValue, ", ")))))
342 }
343 call getValueCont (root, "FICH")
344 if (gotValue) {
345 set (b, save (concat (b,
346 concat ("Filmed by the Church of Jesus Christ of Latter Day Saints, Microfiche Number ",
347 concat (gottenValue, ", ")))))
348 }
349 call getValueCont (root, "REPO")
350 if (gotValue) {
351 set (b, save (concat (b, concat ("at ", concat (gottenValue, ", ")))))
352 }
353
354
355 if (index (b, ", ", 1)) {
356 set (b, save (concat (save (substring (b, 1, sub (strlen (b), 2))), ".")))
357 }
358
359 call getValueCont (root, "NOTE")
360 if (gotValue) { set (b, save (concat (b, concat (" ", gottenValue)))) }
361
362 call getValueCont (root, "TEXT")
363 if (gotValue) { set (b, save (concat (b, concat (" ", gottenValue)))) }
364
365 call getValueCont (root, "SOUR")
366 if (gotValue) {
367 set (bb, "?")
368 if (gottenValue) {
369 set (a1, index (gottenValue, "@", 1))
370 set (a2, index (gottenValue, "@", 2))
371 if (and (eq (a1, 1), eq (a2, strlen (gottenValue)))) {
372 set (bb,
373 save (substring (gottenValue, 2, sub (strlen (gottenValue), 1))))
374 }
375 }
376 set (b, save (concat (b, concat ("\\cite{", concat (bb, "}")))))
377 }
378
379 if (figureFlag) {
380 set (b,
381 save (concat (b, concat (" See figure on page~", concat (pref, ".")))))
382 }
383
384 while (i, index (b, "\n", 1)) {
385 set (b, save (concat (substring (b, 1, sub (i, 1)),
386 concat (" ",
387 substring (b, add (i, 1), strlen (b))))))
388 }
389
390 enqueue (bibList, save (concat (b, "\n")))
391 }
392 }
393
394
395