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

Annotation of mandoc/tbl.c, Revision 1.5

1.5     ! kristaps    1: /*     $Id: tbl.c,v 1.4 2010/12/28 13:47:38 kristaps Exp $ */
1.1       kristaps    2: /*
1.4       kristaps    3:  * Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
1.1       kristaps    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: #include <assert.h>
1.3       kristaps   18: #include <stdio.h>
1.1       kristaps   19: #include <stdlib.h>
                     20: #include <string.h>
                     21: #include <time.h>
                     22:
                     23: #include "mandoc.h"
                     24: #include "roff.h"
                     25: #include "libmandoc.h"
                     26: #include "libroff.h"
                     27:
                     28: static void             tbl_init(struct tbl *);
                     29: static void             tbl_clear(struct tbl *);
                     30:
                     31: static void
                     32: tbl_clear(struct tbl *tbl)
                     33: {
                     34:
                     35: }
                     36:
                     37: static void
                     38: tbl_init(struct tbl *tbl)
                     39: {
                     40:
                     41:        tbl->part = TBL_PART_OPTS;
1.5     ! kristaps   42:        tbl->tab = '\t';
        !            43:        tbl->linesize = 12;
        !            44:        tbl->decimal = '.';
1.1       kristaps   45: }
                     46:
                     47: enum rofferr
                     48: tbl_read(struct tbl *tbl, int ln, const char *p, int offs)
                     49: {
                     50:        int              len;
                     51:        const char      *cp;
                     52:
                     53:        cp = &p[offs];
                     54:        len = (int)strlen(cp);
                     55:
1.5     ! kristaps   56:        /*
        !            57:         * If we're in the options section and we don't have a
        !            58:         * terminating semicolon, assume we've moved directly into the
        !            59:         * layout section.  No need to report a warning: this is,
        !            60:         * apparently, standard behaviour.
        !            61:         */
        !            62:
        !            63:        if (TBL_PART_OPTS == tbl->part && len)
1.1       kristaps   64:                if (';' != cp[len - 1])
                     65:                        tbl->part = TBL_PART_LAYOUT;
1.5     ! kristaps   66:
        !            67:        /* Now process each logical section of the table.  */
        !            68:
        !            69:        switch (tbl->part) {
        !            70:        case (TBL_PART_OPTS):
        !            71:                return(tbl_option(tbl, ln, p) ? ROFF_IGN : ROFF_ERR);
        !            72:        default:
        !            73:                break;
        !            74:        }
1.1       kristaps   75:
1.2       kristaps   76:        return(ROFF_CONT);
1.1       kristaps   77: }
                     78:
                     79: struct tbl *
1.5     ! kristaps   80: tbl_alloc(void *data, const mandocmsg msg)
1.1       kristaps   81: {
                     82:        struct tbl      *p;
                     83:
                     84:        p = mandoc_malloc(sizeof(struct tbl));
1.5     ! kristaps   85:        p->data = data;
        !            86:        p->msg = msg;
1.1       kristaps   87:        tbl_init(p);
                     88:        return(p);
                     89: }
                     90:
                     91: void
                     92: tbl_free(struct tbl *p)
                     93: {
                     94:
                     95:        tbl_clear(p);
                     96:        free(p);
                     97: }
                     98:
                     99: void
                    100: tbl_reset(struct tbl *tbl)
                    101: {
                    102:
                    103:        tbl_clear(tbl);
                    104:        tbl_init(tbl);
                    105: }
1.3       kristaps  106:

CVSweb