Annotation of mandoc/dba_read.c, Revision 1.3
1.3 ! schwarze 1: /* $Id: dba_read.c,v 1.2 2016/08/04 09:33:57 schwarze Exp $ */
1.1 schwarze 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: * 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".
21: */
22: #include <regex.h>
23: #include <stdint.h>
24: #include <stdlib.h>
25: #include <stdio.h>
26: #include <string.h>
27:
28: #include "mandoc_aux.h"
29: #include "mansearch.h"
30: #include "dba_array.h"
31: #include "dba.h"
32: #include "dbm.h"
33:
34:
35: struct dba *
36: dba_read(const char *fname)
37: {
38: struct dba *dba;
39: struct dba_array *page;
40: struct dbm_page *pdata;
41: struct dbm_macro *mdata;
42: const char *cp;
43: int32_t im, ip, iv, npages;
44:
45: if (dbm_open(fname) == -1)
46: return NULL;
47: npages = dbm_page_count();
1.2 schwarze 48: dba = dba_new(npages < 128 ? 128 : npages);
1.1 schwarze 49: for (ip = 0; ip < npages; ip++) {
50: pdata = dbm_page_get(ip);
1.3 ! schwarze 51: page = dba_page_new(dba->pages, NULL, pdata->sect,
1.1 schwarze 52: pdata->arch, pdata->desc, pdata->file + 1, *pdata->file);
1.3 ! schwarze 53: for (cp = pdata->name; *cp != '\0'; cp = strchr(cp, '\0') + 1)
1.1 schwarze 54: dba_page_add(page, DBP_NAME, cp);
55: cp = pdata->sect;
56: while (*(cp = strchr(cp, '\0') + 1) != '\0')
57: dba_page_add(page, DBP_SECT, cp);
58: if ((cp = pdata->arch) != NULL)
59: while (*(cp = strchr(cp, '\0') + 1) != '\0')
60: dba_page_add(page, DBP_ARCH, cp);
61: cp = pdata->file;
62: while (*(cp = strchr(cp, '\0') + 1) != '\0')
63: dba_page_add(page, DBP_FILE, cp);
64: }
65: for (im = 0; im < MACRO_MAX; im++) {
66: for (iv = 0; iv < dbm_macro_count(im); iv++) {
67: mdata = dbm_macro_get(im, iv);
68: dba_macro_new(dba, im, mdata->value, mdata->pp);
69: }
70: }
71: dbm_close();
72: return dba;
73: }
CVSweb