Debian Codegraph @

reports/indiv.ll

raw
1 /*
2 * @progname indiv.ll
3 * @version 3.2
4 * @author Simms
5 * @category
6 * @output Text
7 * @description
8 *
9 * Report on individual with all his families
10
11 Written by: Robert Simms, 27 Mar 1996
12 [email protected], http://www.math.clemson.edu/~rsimms
13
14 Produces an indented report on an individual and all families associated
15 with that individual. Details on individuals include NOTE lines.
16 Linewrapping is done with indenting maintained.
17
18 At the beginning of main() is provided the means to easily change page width,
19 tab size, left margin, and whether or not to include notes in output.
20 ______________
21
22 Version 2: 5 April 96 -- Unknown spouses can be returned by the family
23 function, so a check had to be added to make sure that
24 individuals exist before trying to print information on them.
25 Now it's fixed to return _____ _____ as the name of an
26 unknown person. -- Robert Simms
27
28 Version 3: 16 Feb 2000 -- Two spaces at the end of a sentence could result
29 in a leading space after line-wrap. Added a loop to
30 eliminate leading spaces after line-wrap. Care had to be taken
31 to use the strsave() function to get it working correctly.
32 Also fixed it so that page_width really is the maximum
33 line length, not one less.
34 -- Robert Simms
35
36 Version 3.1: 30 May 2001, fixed the concatenation of multiple notes
37 so that two spaces are inserted before every note
38 after the first. Thanks to M.W. Poirier for pointing this out.
39
40 To-do: Option to maintain blank lines (paragraphing) in notes.
41 Once that is done, it will be possible to separate multiple
42 notes with a blank line, easily.
43 */
44
45 global(page_width)
46 global(tab_size)
47 global(left_margin)
48 global(note_flag)
49
50 proc main() {
51 set(page_width, 80)
52 set(tab_size, 3)
53 set(left_margin, 1)
54 set(note_flag, 1) /*set equal to 1 to include notes, 0 not to include notes*/
55
56
57 getindi(indi)
58 set(x, 0)
59 set(skip, left_margin)
60 set(x, outfam(indi, skip, x))
61
62 nl()
63 " -------------------------------------"
64 nl()
65 }
66
67 func outfam(indi, skip, x) {
68 set(x, outpers(indi, skip, x))
69 if(gt(nfamilies(indi), 0)) {
70 set(skip, add(skip, tab_size))
71 families(indi, fam, sp, num) {
72 set(x, 0)
73 set(x, outline(concat("Family #", d(num)), skip, x))
74 if(date(marriage(fam))) {
75 set(x, outline(concat(", ", date(marriage(fam))), skip, x))
76 }
77 set(x, 0)
78 set(skip, add(skip, tab_size))
79 /* if multiple spouses in a marriage, this will only pick up
80 the first one
81 */
82 set(x, outpers(sp, skip, x))
83 if(gt(nchildren(fam), 0)) {
84 set(x, outline("Children", skip, x))
85 set(x, 0)
86 set(skip, add(skip, tab_size))
87 children(fam, child, no) {
88 set(x, outpers(child, skip, x))
89 }
90 set(skip, sub(skip, tab_size))
91 }
92 set(skip, sub(skip, tab_size))
93 }
94 }
95 return(x)
96 }
97
98 func outpers(indi, skip, x) {
99 if(indi) {
100 print(name(indi), nl())
101 set(x, 0)
102 set(x, outline(name(indi), skip, x))
103 set(skip, add(skip, tab_size))
104 set(s, "")
105 if(birth(indi)) {
106 set(s, concat(", b. ", long(birth(indi))))
107 }
108 if(death(indi)) {
109 set(s, concat(s, ", d. ", long(death(indi))))
110 }
111 if(burial(indi)) {
112 set(s, concat(s, ", buried at ", place(burial(indi))))
113 }
114 set(s, concat(s, ". "))
115 set(x, outline(s, skip, x))
116 if(note_flag) {
117 set(s, "")
118 set(note_separator, "")
119 fornotes(inode(indi), note) {
120 set(s, concat(s, note_separator, note))
121 set(note_separator, " ")
122 }
123 set(x, outtxt(s, skip, x))
124 set(skip, sub(skip, tab_size))
125 }
126 } else {
127 print("_____ _____", nl())
128 set(x, 0)
129 set(x, outline("_____ _____", skip, x))
130 }
131 set(x, 0)
132 return(x)
133 }
134
135 /* outtxt -- removes new line chars from text and sends it to output
136 via the outline function
137 */
138 func outtxt(txt, skip, x) {
139 set(cr, index(txt, nl(), 1))
140 while(ne(cr, 0)) {
141 set(txt, save(txt))
142 set(txt2, concat(substring(txt, 1, sub(cr, 1)), " "))
143 set(x, outline(txt2, skip, x))
144 set(txt, substring(txt, add(cr, 1), strlen(txt)))
145 set(cr, index(txt, nl(), 1))
146 }
147 if(gt(strlen(txt), 0)) {
148 set(x, outline(txt, skip, x))
149 }
150 return(x)
151 }
152
153 /* outline -- buffered text output with linewrapping and and indentation
154 preservation
155 the vars: x -- the column up to which text has been written
156 on the current line
157 skip -- current indentation, added to x at the start of a new
158 line
159 */
160 func outline(text, skip, x) {
161 if(eq(x, 0)) {
162 col(add(skip, 1))
163 set(x, skip)
164 }
165 set(max, sub(page_width, x))
166 if(gt(strlen(text), max)) {
167 set(space, breakpoint(text, max))
168 if(eq(space, 0)) {
169 if(eq(x, skip)) {
170 set(text, strsave(text))
171 substring(text, 1, sub(max, 1)) "-"
172 set(x, 0)
173 set(text, substring(text, max, strlen(text)))
174 set(x, outline(text, skip, x))
175 } else {
176 set(x, 0)
177 set(x, outline(text, skip, x))
178 }
179 } else { /* space gt 0 -- good break point found*/
180 set(text, strsave(text))
181 substring(text, 1, sub(space, 1))
182 set(x, 0)
183 set(text, strsave(substring(text, add(space, 1), strlen(text))))
184 while(eqstr(" ", substring(text, 1, 1))) { /* strip leading spaces */
185 set(text, strsave(substring(text, 2, strlen(text))))
186 }
187 set(x, outline(text, skip, x))
188 }
189 } else {
190 text
191 set(x, add(x, strlen(text)))
192 }
193 return(x)
194 }
195
196 func breakpoint(text, max) {
197 set(space, 0)
198 set(occ, 1)
199 set(next, index(text, " ", occ))
200 incr(occ)
201 while ( and(le(next, add(max, 1)), ne (next, 0))) {
202 set(space, next)
203 set(next, index(text, " ", occ))
204 incr(occ)
205 }
206 return(space)
207 }