xref: /illumos-gate/usr/src/cmd/mandoc/dba_array.h (revision a40ea1a7d80eee1b409e9dcc2e48c730988147ea)
1 /*	$Id: dba_array.h,v 1.1 2016/07/19 21:31:55 schwarze Exp $ */
2 /*
3  * Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  *
17  * Public interface for allocation-based arrays
18  * for the mandoc database, for read-write access.
19  * To be used by dba*.c and by makewhatis(8).
20  */
21 
22 struct dba_array;
23 
24 #define	DBA_STR		0x01	/* Map contains strings, not pointers. */
25 #define	DBA_GROW	0x02	/* Allow the array to grow. */
26 
27 #define	dba_array_FOREACH(a, e) \
28 	dba_array_start(a); \
29 	while (((e) = dba_array_next(a)) != NULL)
30 
31 typedef int dba_compare_func(const void *, const void *);
32 
33 struct dba_array *dba_array_new(int32_t, int);
34 void		 dba_array_free(struct dba_array *);
35 void		 dba_array_set(struct dba_array *, int32_t, void *);
36 void		 dba_array_add(struct dba_array *, void *);
37 void		*dba_array_get(struct dba_array *, int32_t);
38 void		 dba_array_start(struct dba_array *);
39 void		*dba_array_next(struct dba_array *);
40 void		 dba_array_del(struct dba_array *);
41 void		 dba_array_undel(struct dba_array *);
42 void		 dba_array_setpos(struct dba_array *, int32_t, int32_t);
43 int32_t		 dba_array_getpos(struct dba_array *);
44 void		 dba_array_sort(struct dba_array *, dba_compare_func);
45 int32_t		 dba_array_writelen(struct dba_array *, int32_t);
46 void		 dba_array_writepos(struct dba_array *);
47 void		 dba_array_writelst(struct dba_array *);
48