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  * indiseq.h -- Header file for the INDISEQ data type
26  * Copyright(c) 1993-94 by T.T. Wetmore IV; all rights reserved
27  * pre-SourceForge version information:
28  *   2.3.4 - 24 Jun 93    2.3.5 - 03 Aug 93
29  *   3.0.2 - 06 Dec 94    3.0.3 - 08 Aug 95
30  *===========================================================*/
31 
32 #ifndef _INDISEQ_H
33 #define _INDISEQ_H
34 
35 #include "standard.h"		/* for INT, STRING, etc */
36 #include "gedcom.h"		/* for NODE */
37 
38 typedef struct tag_sortel *SORTEL;
39 
40 
41 typedef INT (*ELCMPFNC)(SORTEL el1, SORTEL el2, VPTR param);
42 
43 /*=================================================
44  * Custom functions for caller-specified handling of values
45  * (These cater to the interpreter, which stores PVALUEs)
46  *===============================================*/
47 
48 /*====================
49  * indiseq val types
50  *  NULL means it has no typed values yet
51  *==================*/
52 #define ISVAL_INT 1
53 #define ISVAL_STR 2
54 #define ISVAL_PTR 3
55 #define ISVAL_NUL 4
56 
57 /*
58 	value function table functions for INDISEQ
59 	change with set_indiseq_value_funcs
60 	Default ones (exposed as default_xxx below):
61 		copy produces null values except for int type values
62 		delete only deletes string type values
63 		create_gen creates null values except for int type values
64 */
65 /*
66 	copy a value
67 	(union will use copy from the first operand for keys in both operands)
68 */
69 typedef UNION (*SEQ_COPY_VALUE_FNC)(UNION uval, INT valtype);
70 /* delete a value (failing uniqueness check in append */
71 typedef void (*SEQ_DELETE_VALUE)(UNION uval, INT valtype);
72 /* create a value for ancestors or descendants (may change value type from NUL) */
73 typedef UNION (*SEQ_CREATE_GEN_VALUE)(INT gen, INT * valtype);
74 /* compare two values */
75 typedef INT (*SEQ_COMPARE_VALUES)(VPTR ptr1, VPTR ptr2, INT valtype);
76 /* function table for handling values in INDISEQ */
77 typedef struct tag_indiseq_value_fnctable
78 {
79 	SEQ_COPY_VALUE_FNC copy_fnc;
80 	SEQ_DELETE_VALUE delete_fnc;
81 	SEQ_CREATE_GEN_VALUE create_gen_fnc;
82 	SEQ_COMPARE_VALUES compare_val_fnc;
83 } * INDISEQ_VALUE_FNCTABLE;
84 
85 
86 /*=================================================
87  * INDISEQ -- Data type for an entire indi sequence
88  *===============================================*/
89 struct tag_indiseq {
90 	INT is_refcnt;     /* for interp */
91 	INT is_size;       /* current length of list  */
92 	INT is_max;        /* max length before increment */
93 	INT is_flags;      /* attribute flags */
94 	SORTEL *is_data;   /*  actual list of items */
95 	INT is_prntype;    /* for special cases (spouseseq & famseq) */
96 	INT is_valtype;    /* int, string, pointer */
97 	STRING is_locale;  /* used by namesort */
98 	INDISEQ_VALUE_FNCTABLE is_valfnctbl;
99 };
100 #ifndef INDISEQ_type_defined
101 typedef struct tag_indiseq *INDISEQ;
102 #define INDISEQ_type_defined
103 #endif
104 
105 #define IRefcnt(s)   ((s)->is_refcnt)
106 #define ISize(s)     ((s)->is_size)
107 #define IMax(s)      ((s)->is_max)
108 #define IFlags(s)    ((s)->is_flags)
109 #define IData(s)     ((s)->is_data)
110 #define IPrntype(s)  ((s)->is_prntype)
111 #define IValtype(s)  ((s)->is_valtype)
112 #define ILocale(s)   ((s)->is_locale)
113 #define IValfnctbl(s) ((s)->is_valfnctbl)
114 
115 #define KEYSORT       (1<<0)
116 #define NAMESORT      (1<<1)
117 #define UNIQUED       (1<<2)
118 #define VALUESORT     (1<<3)
119 #define CANONKEYSORT  (1<<4)
120 #define WITHNAMES     (1<<5)
121 #define ALLSORTS (KEYSORT+NAMESORT+VALUESORT+CANONKEYSORT)
122 
123 #define length_indiseq(seq)  (ISize(seq))
124 
125 /*=====================
126  * INDISEQ -- Functions
127  *===================*/
128 
129 void add_browse_list(STRING, INDISEQ);
130 void addref_indiseq(INDISEQ seq);
131 INDISEQ ancestor_indiseq(INDISEQ seq);
132 void append_indiseq_null(INDISEQ, STRING key, CNSTRING name, BOOLEAN sure, BOOLEAN alloc);
133 void append_indiseq_ival(INDISEQ, STRING key, STRING name, INT val, BOOLEAN sure, BOOLEAN alloc);
134 void append_indiseq_pval(INDISEQ, STRING key, STRING name, VPTR val, BOOLEAN sure);
135 void append_indiseq_sval(INDISEQ, STRING key, CNSTRING name, STRING sval, BOOLEAN sure, BOOLEAN alloc);
136 void calc_indiseq_names(INDISEQ seq);
137 void canonkeysort_indiseq(INDISEQ);
138 INDISEQ child_indiseq(INDISEQ);
139 INDISEQ copy_indiseq(INDISEQ seq);
140 INDISEQ create_indiseq_ival(void);
141 INDISEQ create_indiseq_null(void);
142 INDISEQ create_indiseq_pval(void);
143 INDISEQ create_indiseq_sval(void);
144 UNION default_copy_value(UNION uval, INT valtype);
145 void default_delete_value(UNION uval, INT valtype);
146 UNION default_create_gen_value(INT gen, INT * valtype);
147 INT default_compare_values(VPTR ptr1, VPTR ptr2, INT valtype);
148 BOOLEAN delete_indiseq(INDISEQ, STRING, STRING, INT);
149 INDISEQ descendent_indiseq(INDISEQ seq);
150 INDISEQ difference_indiseq(INDISEQ, INDISEQ);
151 INT element_ikey(SORTEL el);
152 BOOLEAN element_indiseq(INDISEQ seq, INT index, STRING *pkey, STRING *pname);
153 BOOLEAN element_indiseq_ival(INDISEQ seq, INT index, STRING*, INT *, STRING*);
154 CNSTRING element_key_indiseq(INDISEQ seq, INT index);
155 CNSTRING element_name(SORTEL el);
156 VPTR element_pval(SORTEL el);
157 CNSTRING element_skey(SORTEL el);
158 CNSTRING element_sval(SORTEL el);
159 INDISEQ fam_to_children(NODE);
160 INDISEQ fam_to_fathers(NODE);
161 INDISEQ fam_to_mothers(NODE);
162 INDISEQ fam_to_spouses(NODE fam);
163 INDISEQ find_named_seq(STRING);
164 INDISEQ get_all_even(void);
165 INDISEQ get_all_othe(void);
166 INDISEQ get_all_sour(void);
167 INT get_indiseq_ival(INDISEQ seq, INT i);
168 INT getpivot(INT, INT);
169 BOOLEAN in_indiseq(INDISEQ, STRING);
170 INDISEQ indi_to_children(NODE);
171 INDISEQ indi_to_families(NODE, BOOLEAN);
172 INDISEQ indi_to_fathers(NODE);
173 INDISEQ indi_to_mothers(NODE);
174 INDISEQ indi_to_spouses(NODE);
175 BOOLEAN indiseq_is_valtype_ival(INDISEQ);
176 BOOLEAN indiseq_is_valtype_null(INDISEQ);
177 INDISEQ intersect_indiseq(INDISEQ, INDISEQ);
178 INDISEQ key_to_indiseq(STRING name, char ctype);
179 void keysort_indiseq(INDISEQ);
180 INDISEQ name_to_indiseq(STRING);
181 void namesort_indiseq(INDISEQ);
182 void new_write_node(INT, NODE, BOOLEAN);
183 INDISEQ node_to_notes(NODE);
184 INDISEQ node_to_pointers(NODE node);
185 INDISEQ node_to_sources(NODE);
186 INDISEQ parent_indiseq(INDISEQ);
187 void partition_sort(SORTEL*, INT, ELCMPFNC func, VPTR param);
188 void preprint_indiseq(INDISEQ, INT len, RFMT rfmt);
189 void print_indiseq_element (INDISEQ seq, INT i, STRING buf, INT len, RFMT rfmt);
190 INDISEQ refn_to_indiseq(STRING, INT letr, INT sort);
191 void remove_browse_list(STRING, INDISEQ);
192 void remove_indiseq(INDISEQ);
193 void rename_indiseq(INDISEQ, STRING);
194 void set_element_pval(SORTEL el, VPTR ptr);
195 void set_indiseq_value_funcs(INDISEQ seq, INDISEQ_VALUE_FNCTABLE valfnctbl);
196 INDISEQ sibling_indiseq(INDISEQ, BOOLEAN);
197 INDISEQ spouse_indiseq(INDISEQ);
198 INDISEQ str_to_indiseq(STRING name, char ctype);
199 void unique_indiseq(INDISEQ);
200 INDISEQ union_indiseq(INDISEQ one, INDISEQ two);
201 void update_browse_list(STRING, INDISEQ);
202 void valuesort_indiseq(INDISEQ, BOOLEAN*);
203 void write_family(STRING, TABLE);
204 void write_nonlink_indi(NODE);
205 
206 
207 /*==================
208  * INDISEQ -- Macros
209  *================*/
210 
211 #define FORINDISEQ(s,e,i)\
212 	{	int i, _n;\
213 		SORTEL e, *_d;\
214 		_d = IData((INDISEQ)s);\
215 		for (i = 0, _n = ISize((INDISEQ)s); i < _n; i++) {\
216 			e = _d[i];
217 #define ENDINDISEQ }}
218 
219 #endif /* _INDISEQ_H */
220