File: igi-import.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 (411 lines) | stat: -rw-r--r-- 10,697 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
/*
 * @progname    igi-import.ll
 * @version     1.0
 * @author      baud@research.att.com
 * @category
 * @output      GedCom
 * @description
 *
 *      Convert igi gedcom to lifelines-standard gedcom
 *
 *      Igi gedcom contains a single NOTE record for each source, either
 *      on the INDI for a BIRT/CHR or on one of the spouses for a MARR.
 *      This report rearranges the source information into a SOUR record
 *      with the associated NOTE text attached to the appropriate source.
 *
 *      Convert UPPERCASE surnames to upper- and lowercase. Try to
 *      figure out von's and such, but otherwise simply capitalize the
 *      first letters. Remove periods used for abbreviations.
 *
 *      Dates of the form <ABT ...> have the angle brackets stripped.
 *
 *      Note that this report converts INDI/FAM records to INDI/FAM
 *      records, providing *conclusions* for your database. It would
 *      be quite easy, but not of interest to me, to produce a similar
 *      report that produces EVEN records, providing *evidence* for your
 *      database.
 *
 *      -> Use this report on igi gedcom data *before* igi-merge. <-
 *
 *      12 NOV 1994 (3.0.1)             baud@research.att.com
 */

proc main ()
{
  getstrmsg (msg, "IGI Version [default 3.02/1994]?")
  if (streq (msg, "")) {
    set (igiversion, "3.02")
    set (igidate, "1994")
  } else {
    if (i, index (msg, "/", 1)) {
      set (igiversion, save (trim (msg, sub (i, 1))))
      set (igidate, save (cut (msg, add(i, 1))))
    } else {
      set (igiversion, save (msg))
      set (igidate, "")
    }
  }

  "0 HEAD \n"
  "1 SOUR LIFELINES\n"
  "2 VER 3.0.1\n"
  "2 NAME IGI-IMPORT REPORT\n"
  "1 DEST LIFELINES\n"
  "2 VER 3.0.1\n"
  "1 DATE " date (gettoday ()) "\n"
  "1 COPR Copyright " date (gettoday ()) ". Permission is granted to repro"
    "duce any subset\n2 CONT of the data contained herein under the condit"
    "ion that this copyright\n2 CONT notice is preserved, that the origina"
    "l source citations referenced\n2 CONT in the subset are included, and"
    " that the submitter of this file is\n2 CONT credited with original au"
    "thorship as appropriate.\n"
  "1 CHAR ASCII\n"

  "0 @S1@ SOUR\n"
  "1 NAME International Genealogical Index\n"
  "1 PUBR The Church of Jesus Christ of Latter-day Saints\n"
  if (strlen (igiversion)) {
    "1 VER " igiversion "\n"
  }
  if (strlen (igidate)) {
    "1 DATE " igidate "\n"
  }

  print ("Processing nodes ...\n")
  forfam (fam, fn) {
    print ("f")
    igiimport (fam)
  }

  "0 TRLR \n"
}

func igiimport (fam)
{
  if (marriage (fam)) {
    if (note, subnode (inode (husband (fam)), "NOTE")) {
      deletenode (note)
    }
    elsif (note, subnode (inode (wife (fam)), "NOTE")) {
      deletenode (note)
    }
    set (parentsourcetext, "See marriage record.")
    catnode (marriage (fam), sourcifyNote (note))
  } else {
    children (fam, indi, nc) {
      if (note, subnode (inode (indi), "NOTE")) {
        deletenode (note)
      }
      set (childsourcetext, 0)
      if (birth (indi)) {
        set (childsourcetext, "See birth record.")
        catnode (birth (indi), sourcifyNote (note))
      }
      if (baptism (indi)) {
        set (childsourcetext, "See christening record.")
        catnode (baptism (indi), sourcifyNote (note))
      }
      reformatnames (inode (indi), childsourcetext)
      reformatdates (inode (indi))
      gedcomnode (inode (indi))
      set (parentsourcetext,
        save (concat ("See ",
                concat (cond (female (indi), "daughter", "son"),
                  concat (cond (strlen (givens (indi)), " ", ""),
                    concat (givens (indi),
                      concat ("'s ",
                        cond (birth (indi), "birth record.",
                          "christening record."))))))))
    }
  }
  if (indi, husband (fam)) {
    reformatnames (inode (indi), parentsourcetext)
    reformatdates (inode (indi))
    gedcomnode (inode (indi))
  }
  if (indi, wife (fam)) {
    reformatnames (inode (indi), parentsourcetext)
    reformatdates (inode (indi))
    gedcomnode (inode (indi))
  }
  reformatdates (fnode (fam))
  gedcomnode (fnode (fam))
  return (0)
}

func sourcifyNote (node) {
  if (node) {
    set (text, values (node))
    while (i, index (text, "#:", 1)) {
      set (text, save (concat3 (trim (text, sub (i, 1)),
                                "Number",
                                cut (text, add (i, 2)))))
    }
    if (streq (substring (text, sub (strlen (text), 5), strlen (text)),
               "Number")) {
      set (text, save (concat (text, " unknown")))
    }
    set (text, save (concat3 ("International Genealogical Index, ", text, ".")))
    set (node, createnodes ("SOUR", text))
    catnode (node, createnode ("SOUR", "@S1@"))
  } else {
    set (node, createnode ("SOUR", "@S1@"))
  }
  return (node)
}

/* common import/export functions */

func cond (x, a, b) {
  if (x) {
    return (a)
  } else {
    return (b)
  }
}

func gedcomnode (root) {
  traverse (root, node, level) {
    d (level)
    if (x, xref (node))  { " " x }
    if (x, tag (node))   { " " x }
    if (x, value (node)) { " " x }
    "\n"
  }
  return (0)
}

func denull (alist) {
  list (blist)
  forlist (alist, a, an) {
    if (a) { enqueue (blist, a) }
  }
  return (blist)
}

func reformatdates (root) {
  traverse (root, node, level) {
    if (streq (tag (node), "DATE")) {
      if (v, value (node)) {
        if (and (eq (index (v, "<", 1), 1),
                 eq (index (v, ">", 1), strlen (v)))) {
          replacenode
            (createnode ("DATE", save (substring (v, 2, sub (strlen (v), 1)))),
             subnode (node, "DATE"))
        }
      }
    }
  }
  return (0)
}

func reformatnames (root, sourcetext) {
  list (namelist)
  list (surnamelist)
  list (choppedsurnamelist)
  list (newchoppedsurnamelist)
  if (namenode, subnode (root, "NAME")) {
    extractnames (namenode, namelist, nameN, surnameN)
    set (lastnamenode, namenode)
    forlist (namelist, s, sn) {
      set (s, strremove (s, "."))
      set (s, strremove (s, "_"))
      setel (namelist, sn, s)
    }
    enqueue (surnamelist, getel (namelist, surnameN))
    while (surname, dequeue (surnamelist)) {
      set (choppedsurnamelist, strchop (surname, " "))
      forlist (choppedsurnamelist, s, sn) {
        if (streq ("VON", s)) {
          enqueue (newchoppedsurnamelist, s)
        } elsif (streq ("DER", s)) {
          enqueue (newchoppedsurnamelist, s)
        } elsif (and (eq (index (s, "(", 1), 1),
                      eq (index (s, ")", 1), strlen (s)))) {
          enqueue (surnamelist, save (substring (s, 2, sub (strlen (s), 1))))
        } else {
          enqueue (newchoppedsurnamelist, save (capitalize (lower (s))))
        }
      }
      set (newsurname, strjoin (newchoppedsurnamelist, " "))
      if (strlen (newsurname)) {
        if (i, index (newsurname, "Mc ", 1)) {
          set (newsurname, save (concat (trim (newsurname, add (i, 1)),
                                         cut (newsurname, add (i, 3)))))
        }
        set (newsurname, save (concat3 ("/", newsurname, "/")))
      }
      setel (namelist, surnameN, newsurname)
      set (newnamenode, createnode ("NAME", strjoin (namelist, " ")))
      addnode (newnamenode, parent (lastnamenode), lastnamenode)
      if (sourcetext) {
        catnode (newnamenode, createnode ("SOUR", sourcetext))
      }
      set (lastnamenode, newnamenode)
    }
    deletenode (namenode)
  }
  return (0)
}

func streq (x, y) {
  return (not (strcmp (x, y)))
}

func createnodes (tag, text) {
  set (text, trimspaces (text))
  if (le (strlen (text), 72)) {
    return (createnode (tag, text))
  } else {
    list (textlist)
    while (gt (strlen (text), 72)) {
      set (n, 1)
      if (i, index (text, " ", n)) {
        set (j, i)
      } else {
        set (j, add (strlen (text), 1))
      }
      while (and (i, lt (i, 73))) {
        incr (n)
        set (j, i)
        set (i, index (text, " ", n))
      }
      enqueue (textlist, save (trim (text, sub (j, 1))))
      set (text, save (cut (text, add (j, 1))))
    }
    if (gt (strlen (text), 0)) {
      enqueue (textlist, text)
    }
    set (root, createnode (tag, dequeue (textlist)))
    set (lastnode, 0)
    forlist (textlist, text, tn) {
      set (node, createnode ("CONT", text))
      addnode (node, root, lastnode)
      set (lastnode, node)
    }
    return (root)
  }
}

func trimspaces (text) {
  set (ss, 0)
  set (s0, 1)
  set (sn, strlen (text))
  while (and (le (s0, sn), streq (substring (text, s0, s0), " "))) {
    set (ss, 1)
    incr (s0)
  }
  while (and (le (s0, sn), streq (substring (text, sn, sn), " "))) {
    set (ss, 1)
    decr (sn)
  }
  if (ss) {
    return (save (substring (text, s0, sn)))
  } else {
    return (text)
  }
}

func catnode (root, newnode) {
  if (root) {
    set (lastnode, 0)
    fornodes (root, node) {
      set (lastnode, node)
    }
    addnode (newnode, root, lastnode)
  }
  return (0)
}

func strchop (s, d) {
  list (slist)
  set (dn, strlen (d))
  if (strlen (s)) {
    set (n, 1)
    set (s0, 1)
    while (sn, index (s, d, n)) {
      enqueue (slist, save (substring (s, s0, sub (sn, 1))))
      set (s0, add (sn, dn))
      incr (n)
    }
    enqueue (slist, save (cut (s, s0)))
  }
  return (slist)
}

func strjoin (slist, d) {
  forlist (slist, s, sn) {
    if (not (strlen (str))) {
      set (str, s)
    } elsif (strlen (s)) {
      set (str, save (concat3 (str, d, s)))
    }
  }
  return (str)
}

func subnode (root, tag) {
  if (root) {
    fornodes (root, node) {
      if (streq (tag (node), tag)) {
        return (node)
      }
    }
  }
  return (0)
}

func subnodes (root, tag) {
  list (nodelist)
  if (root) {
    fornodes (root, node) {
      if (streq (tag (node), tag)) {
        enqueue (nodelist, node)
      }
    }
  }
  return (nodelist)
}

func replacenode (newnode, oldnode) {
  if (newnode) {
    if (root, parent (oldnode)) {
      addnode (newnode, root, oldnode)
      deletenode (oldnode)
    }
  }
  return (0)
}

func concat3 (x, y, z) {
  return (concat (x, concat (y, z)))
}

func cut (s, n) {
  return (substring (s, n, strlen (s)))
}

func values (root) {
  if (root) {
    set (str, value (root))
    fornodes (root, node) {
      if (not (str)) {
        set (str, value (node))
      } elsif (strlen (value (node))) {
        set (str, save (concat3 (str, " ", value (node))))
      }
    }
    return (str)
  } else {
    return (0)
  }
}

func strremove (s, d) {
  if (strlen (s)) {
    while (i, index (s, d, 1)) {
      set (s, save (concat (trim (s, sub (i, 1)), cut (s, add (i, 1)))))
    }
  }
  return (s)
}