[BACK]Return to dba_read.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Annotation of mandoc/dba_read.c, Revision 1.1

1.1     ! schwarze    1: /*     $Id$ */
        !             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();
        !            48:        dba = dba_new(npages);
        !            49:        for (ip = 0; ip < npages; ip++) {
        !            50:                pdata = dbm_page_get(ip);
        !            51:                page = dba_page_new(dba->pages, pdata->name, pdata->sect,
        !            52:                    pdata->arch, pdata->desc, pdata->file + 1, *pdata->file);
        !            53:                cp = pdata->name;
        !            54:                while (*(cp = strchr(cp, '\0') + 1) != '\0')
        !            55:                        dba_page_add(page, DBP_NAME, cp);
        !            56:                cp = pdata->sect;
        !            57:                while (*(cp = strchr(cp, '\0') + 1) != '\0')
        !            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);
        !            62:                cp = pdata->file;
        !            63:                while (*(cp = strchr(cp, '\0') + 1) != '\0')
        !            64:                        dba_page_add(page, DBP_FILE, cp);
        !            65:        }
        !            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);
        !            70:                }
        !            71:        }
        !            72:        dbm_close();
        !            73:        return dba;
        !            74: }

CVSweb