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

Annotation of mandoc/dummy.c, Revision 1.3

1.3     ! kristaps    1: /* $Id: dummy.c,v 1.2 2008/11/24 08:50:33 kristaps Exp $ */
1.1       kristaps    2: /*
                      3:  * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
                      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
                      7:  * above copyright notice and this permission notice appear in all
                      8:  * copies.
                      9:  *
                     10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
                     11:  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
                     12:  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
                     13:  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
                     14:  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
                     15:  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
                     16:  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
                     17:  * PERFORMANCE OF THIS SOFTWARE.
                     18:  */
                     19: #include <assert.h>
1.3     ! kristaps   20: #include <err.h>
1.1       kristaps   21: #include <stdlib.h>
                     22:
                     23: #include "libmdocml.h"
                     24: #include "private.h"
                     25:
                     26:
1.3     ! kristaps   27: struct md_dummy {
        !            28:        struct rofftree *tree;
        !            29: };
        !            30:
        !            31:
        !            32: int
        !            33: md_line_dummy(void *arg, char *buf, size_t sz)
        !            34: {
        !            35:        struct md_dummy *p;
        !            36:
        !            37:        p = (struct md_dummy *)arg;
        !            38:        return(roff_engine(p->tree, buf, sz));
        !            39: }
        !            40:
        !            41:
1.1       kristaps   42: int
1.3     ! kristaps   43: md_exit_dummy(void *data, int flush)
        !            44: {
        !            45:        int              c;
        !            46:        struct md_dummy *p;
        !            47:
        !            48:        p = (struct md_dummy *)data;
        !            49:        c = roff_free(p->tree, flush);
        !            50:        free(p);
        !            51:
        !            52:        return(c);
        !            53: }
        !            54:
        !            55:
        !            56: void *
        !            57: md_init_dummy(const struct md_args *args,
        !            58:                struct md_mbuf *mbuf, const struct md_rbuf *rbuf)
1.1       kristaps   59: {
1.3     ! kristaps   60:        struct md_dummy *p;
1.1       kristaps   61:
1.3     ! kristaps   62:        if (NULL == (p = malloc(sizeof(struct md_dummy)))) {
        !            63:                warn("malloc");
        !            64:                return(NULL);
        !            65:        }
        !            66:
        !            67:        if (NULL == (p->tree = roff_alloc(args, mbuf, rbuf))) {
        !            68:                free(p);
        !            69:                return(NULL);
        !            70:        }
1.1       kristaps   71:
1.3     ! kristaps   72:        return(p);
1.1       kristaps   73: }

CVSweb