1 /*
2 Copyright (c) 1991-1999 Thomas T. Wetmore IV
3
4 Permission is hereby granted, free of charge, to any person
5 obtaining a copy of this software and associated documentation
6 files (the "Software"), to deal in the Software without
7 restriction, including without limitation the rights to use, copy,
8 modify, merge, publish, distribute, sublicense, and/or sell copies
9 of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be
13 included in all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 SOFTWARE.
23 */
24 /*============================================================
25 * choose.c -- Implements the choose operations
26 * Copyright(c) 1992-4 by T.T. Wetmore IV; all rights reserved
27 * 3.0.2 - 06 Dec 94 3.0.3 - 08 May 95
28 *==========================================================*/
29
30 #include "llstdlib.h"
31 #include "table.h"
32 #include "translat.h"
33 #include "gedcom.h"
34 #include "indiseq.h"
35 #include "liflines.h"
36 #include "feedback.h"
37
38 /*=================================================
39 * choose_child -- Choose child of person or family
40 * irec: [IN] parent (may be null if fam provided)
41 * frec: [IN] family (may be null if indi provided)
42 * msg0: [IN] message to display if no children
43 * msgn: [IN] title for choosing child from list
44 * ask1: [IN] whether to prompt if only one child
45 *===============================================*/
46 RECORD
choose_child(RECORD irec,RECORD frec,STRING msg0,STRING msgn,ASK1Q ask1)47 choose_child (RECORD irec, RECORD frec, STRING msg0, STRING msgn, ASK1Q ask1)
48 {
49 RECORD rec=0;
50 INDISEQ seq=0;
51
52 if (irec) seq = indi_to_children(nztop(irec));
53 if (!irec && frec) seq = fam_to_children(nztop(frec));
54 if (!seq) {
55 msg_error(msg0);
56 return NULL;
57 }
58 rec = choose_from_indiseq(seq, ask1, msgn, msgn);
59 remove_indiseq(seq);
60 return rec;
61 }
62 /*========================================
63 * choose_spouse -- Choose person's spouse
64 * irec: [IN] known person (gives up if this is null)
65 * msg0: [IN] message to display if no spouses
66 * msgn: [IN] title for choosing spouse from list
67 * asks if multiple
68 *======================================*/
69 RECORD
choose_spouse(RECORD irec,STRING msg0,STRING msgn)70 choose_spouse (RECORD irec, STRING msg0, STRING msgn)
71 {
72 RECORD rec=0;
73 INDISEQ seq=0;
74
75 if (!irec) return NULL;
76 if (!(seq = indi_to_spouses(nztop(irec)))) {
77 message(msg0);
78 return NULL;
79 }
80 rec = choose_from_indiseq(seq, NOASK1, NULL, msgn);
81 remove_indiseq(seq);
82 return rec;
83 }
84 /*========================================
85 * choose_source -- Choose any referenced source from some,
86 * presumably top level, node
87 * always asks
88 *======================================*/
89 RECORD
choose_source(RECORD current,STRING msg0,STRING msgn)90 choose_source (RECORD current, STRING msg0, STRING msgn)
91 {
92 INDISEQ seq;
93 RECORD rec;
94 if (!current) return NULL;
95 if (!(seq = node_to_sources(nztop(current)))) {
96 message(msg0);
97 return NULL;
98 }
99 rec = choose_from_indiseq(seq, DOASK1, msgn, msgn);
100 remove_indiseq(seq);
101 return rec;
102 }
103 /*========================================
104 * choose_note -- Choose any referenced note from some,
105 * presumably top level, node
106 * always asks
107 * Created: 2001/02/11, Perry Rapp
108 *======================================*/
109 RECORD
choose_note(RECORD current,STRING msg0,STRING msgn)110 choose_note (RECORD current, STRING msg0, STRING msgn)
111 {
112 INDISEQ seq;
113 RECORD rec;
114 if (!current) return NULL;
115 if (!(seq = node_to_notes(nztop(current)))) {
116 message(msg0);
117 return NULL;
118 }
119 rec = choose_from_indiseq(seq, DOASK1, msgn, msgn);
120 remove_indiseq(seq);
121 return rec;
122 }
123 /*========================================
124 * choose_pointer -- Choose any reference (pointer) from some,
125 * presumably top level, node
126 * always asks
127 * Created: 2001/02/24, Perry Rapp
128 * Returns addref'd record
129 *======================================*/
130 RECORD
choose_pointer(RECORD current,STRING msg0,STRING msgn)131 choose_pointer (RECORD current, STRING msg0, STRING msgn)
132 {
133 INDISEQ seq;
134 RECORD rec;
135 if (!current) return NULL;
136 if (!(seq = node_to_pointers(nztop(current)))) {
137 message(msg0);
138 return NULL;
139 }
140 rec = choose_from_indiseq(seq, DOASK1, msgn, msgn);
141 remove_indiseq(seq);
142 return rec;
143 }
144 /*==========================================================
145 * choose_family -- Choose family from person's FAMS/C lines
146 * asks if multiple
147 * irec: [IN] person of interest
148 * msg0: [IN] message to display if no families
149 * msgn: [IN] title if need to choose which family
150 * fams: [IN] want spousal families of indi ? (or families indi is child in)
151 *========================================================*/
152 RECORD
choose_family(RECORD irec,STRING msg0,STRING msgn,BOOLEAN fams)153 choose_family (RECORD irec, STRING msg0, STRING msgn, BOOLEAN fams)
154 {
155 RECORD rec=0;
156 INDISEQ seq = indi_to_families(nztop(irec), fams);
157 if (!seq) {
158 if (msg0)
159 msg_error(msg0);
160 return NULL;
161 }
162 rec = choose_from_indiseq(seq, NOASK1, NULL, msgn);
163 remove_indiseq(seq);
164 return rec;
165 }
166 /*===================================================
167 * choose_father -- Choose father of person or family
168 * irec: [IN] person of interest if non-null
169 * frec: [IN] family of interest if non-null
170 * msg0: [IN] message to display if no fathers
171 * msgn: [IN] title if need to choose which father
172 * ask1: [IN] whether or not to prompt if only one father found
173 *=================================================*/
174 RECORD
choose_father(RECORD irec,RECORD frec,STRING msg0,STRING msgn,ASK1Q ask1)175 choose_father (RECORD irec, RECORD frec, STRING msg0, STRING msgn, ASK1Q ask1)
176 {
177 RECORD rec=0;
178 INDISEQ seq=0;
179
180 if (irec) seq = indi_to_fathers(nztop(irec));
181 if (!irec && frec) seq = fam_to_fathers(nztop(frec));
182 if (!seq) {
183 msg_error(msg0);
184 return NULL;
185 }
186 rec = choose_from_indiseq(seq, ask1, msgn, msgn);
187 remove_indiseq(seq);
188 return rec;
189 }
190 /*===================================================
191 * choose_mother -- Choose mother of person or family
192 * irec: [IN] person of interest if non-null
193 * frec: [IN] family of interest if non-null
194 * msg0: [IN] message to display if no mothers
195 * msgn: [IN] title if need to choose which mother
196 * ask1: [IN] whether or not to prompt if only one mother found
197 *=================================================*/
198 RECORD
choose_mother(RECORD irec,RECORD frec,STRING msg0,STRING msgn,ASK1Q ask1)199 choose_mother (RECORD irec, RECORD frec, STRING msg0, STRING msgn, ASK1Q ask1)
200 {
201 RECORD rec=0;
202 INDISEQ seq=0;
203
204 if (irec) seq = indi_to_mothers(nztop(irec));
205 if (!irec && frec) seq = fam_to_mothers(nztop(frec));
206 if (!seq) {
207 msg_error(msg0);
208 return NULL;
209 }
210 rec = choose_from_indiseq(seq, ask1, msgn, msgn);
211 remove_indiseq(seq);
212 return rec;
213 }
214