File: xmlize.ll

package info (click to toggle)
lifelines 3.0.61-2.1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 12,572 kB
  • sloc: ansic: 59,805; xml: 8,960; sh: 4,459; makefile: 863; yacc: 601; perl: 170; sed: 16
file content (141 lines) | stat: -rwxr-xr-x 3,312 bytes parent folder | download | duplicates (7)
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
/*
 * @progname       xmlize2.ll
 * @version        2.2
 * @author         Rafal T. Prinke
 * @category       
 * @output         XML
 * @description

         This report converts all LifeLines records
         to XML tagged file, with <LLGEDCOM> as
         the root element.
         It is now more consistent with Mike Kay's GedML.
         References are all empty tags with IDREF attribute.
         The NAME element contains one S element - for
         surname (ie. it is a reserved tag and cannot be
         used elsewhere).

         I am leaving specific tags for vital events
         rather than converting them to attributes
         of generic EVEN tags as Mike does in GedML.

         The CONT tag is replaced with an empty <P/> tag
         to indicate a new paragraph and the CONC tag
         is replaced with a space to assure continuity
         of a paragraph.

   xmlize2.ll - v. 1.1 Rafal T. Prinke, 8 March 2001
                v. 2.0 - - , 28 April 2001
                v. 2.1 - - , 29 April 2001
                v. 2.2 - - , 30 June  2001 - changed REF to IDREF
*/


global(previous)
global(numery)
global(tagi)

proc main ()
{
  list(numery)
  list(tagi)
  set(previous,-1)

  "<?xml version=" qt() "1.0" qt()

/* remove the next line for Unicode encoding or
   edit for a different 8-bit encoding using one of these:
      ISO-8859-1       - ISO Latin-1 (Western Europe)
      ISO-8859-2       - ISO Latin-2 (Central-Eastern Europe)
      windows-1252     - Windows Lat-1 (Western Europe)
      windows-1250     - Windows Lat-2 (Central-Eastern Europe)
*/

  " encoding=" qt() "ISO-8859-2" qt()
  " standalone=" qt() "yes" qt() "?>"

  "\n"
  "<LLGEDCOM>"

  forindi(pers,x) {
      call out(pers)
  }
  forfam(fm,x) {
      call out(fm)
  }
  foreven(evn, n) {
      call out(evn)
  }
  forsour(src, n) {
      call out(src)
  }
  forothr(oth, n) {
      call out(oth)
  }

  "\n</LLGEDCOM>"
}


proc out(item)

{
  "\n"
  traverse(root(item),y,level) {

    if(eqstr(tag(y),"CONT")) { "<P/>" value(y) }

    elsif(eqstr(tag(y),"CONC")) { " " value(y) }

    else {

       while(and(le(level,previous),not(empty(tagi)))) {
           "</" pop(tagi) ">"
           set(nic,pop(numery))
           set(previous,sub(previous,1))
       }
       "<" tag(y)

       if(index(value(y),"@",1)) {
           set(wart,value(y))
           " IDREF=" qt() substring(wart,2,sub(strlen(wart),1)) qt()
"/>"
       }

       else {
           if(eq(level,0)) {
               " ID=" qt() substring(xref(y),2,sub(strlen(xref(y)),1))
qt()
           }
          ">"

/* insert tag S for surname with space before and after if necessary */

    if(eqstr(tag(y),"NAME")) {
      set(bef,substring(value(y),1,sub(index(value(y),"/",1),1)))
      bef
      if(nestr(substring(bef,strlen(bef),strlen(bef))," ")) { " " }
      "<S>"

substring(value(y),add(index(value(y),"/",1),1),sub(index(value(y),"/",2),1))
      "</S>"

set(aft,substring(value(y),add(index(value(y),"/",2),1),strlen(value(y))))
      if(and(nestr(substring(aft,1,1)," ") ,ne(strlen(aft),0) )) { " " }
      aft
    }

    else { value(y) }

          push(numery,level)
          push(tagi,tag(y))
          set(previous,level)
    }
  }
}

   while(not(empty(tagi))) {
      "</" pop(tagi) ">"
      set(nic,pop(numery))
   }
}