]>
git.cameronkatri.com Git - mandoc.git/blob - dba_read.c
1 /* $Id: dba_read.c,v 1.5 2020/06/22 19:20:40 schwarze Exp $ */
3 * Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
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.
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.
17 * Function to read the mandoc database from disk into RAM,
18 * such that data can be added or removed.
19 * The interface is defined in "dba.h".
20 * This file is seperate from dba.c because this also uses "dbm.h".
30 #include "mandoc_aux.h"
31 #include "mansearch.h"
32 #include "dba_array.h"
38 dba_read(const char *fname
)
41 struct dba_array
*page
;
42 struct dbm_page
*pdata
;
43 struct dbm_macro
*mdata
;
45 int32_t im
, ip
, iv
, npages
;
47 if (dbm_open(fname
) == -1)
49 npages
= dbm_page_count();
50 dba
= dba_new(npages
< 128 ? 128 : npages
);
51 for (ip
= 0; ip
< npages
; ip
++) {
52 pdata
= dbm_page_get(ip
);
53 page
= dba_page_new(dba
->pages
, pdata
->arch
,
54 pdata
->desc
, pdata
->file
+ 1, *pdata
->file
);
55 for (cp
= pdata
->name
; *cp
!= '\0'; cp
= strchr(cp
, '\0') + 1)
56 dba_page_add(page
, DBP_NAME
, cp
);
57 for (cp
= pdata
->sect
; *cp
!= '\0'; cp
= strchr(cp
, '\0') + 1)
58 dba_page_add(page
, DBP_SECT
, cp
);
59 if ((cp
= pdata
->arch
) != NULL
)
60 while (*(cp
= strchr(cp
, '\0') + 1) != '\0')
61 dba_page_add(page
, DBP_ARCH
, cp
);
63 while (*(cp
= strchr(cp
, '\0') + 1) != '\0')
64 dba_page_add(page
, DBP_FILE
, cp
);
66 for (im
= 0; im
< MACRO_MAX
; im
++) {
67 for (iv
= 0; iv
< dbm_macro_count(im
); iv
++) {
68 mdata
= dbm_macro_get(im
, iv
);
69 dba_macro_new(dba
, im
, mdata
->value
, mdata
->pp
);