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

Annotation of mandoc/tbl.c, Revision 1.7

1.7     ! kristaps    1: /*     $Id: tbl.c,v 1.6 2010/12/29 14:38:14 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: {
1.6       kristaps   34:        struct tbl_row  *rp;
                     35:        struct tbl_cell *cp;
1.1       kristaps   36:
1.6       kristaps   37:        while (tbl->first) {
                     38:                rp = tbl->first;
                     39:                tbl->first = rp->next;
                     40:                while (rp->first) {
                     41:                        cp = rp->first;
                     42:                        rp->first = cp->next;
                     43:                        free(cp);
                     44:                }
                     45:                free(rp);
                     46:        }
                     47:
                     48:        tbl->last = NULL;
1.1       kristaps   49: }
                     50:
                     51: static void
                     52: tbl_init(struct tbl *tbl)
                     53: {
                     54:
                     55:        tbl->part = TBL_PART_OPTS;
1.5       kristaps   56:        tbl->tab = '\t';
                     57:        tbl->linesize = 12;
                     58:        tbl->decimal = '.';
1.1       kristaps   59: }
                     60:
                     61: enum rofferr
                     62: tbl_read(struct tbl *tbl, int ln, const char *p, int offs)
                     63: {
                     64:        int              len;
                     65:        const char      *cp;
                     66:
                     67:        cp = &p[offs];
                     68:        len = (int)strlen(cp);
                     69:
1.5       kristaps   70:        /*
                     71:         * If we're in the options section and we don't have a
                     72:         * terminating semicolon, assume we've moved directly into the
                     73:         * layout section.  No need to report a warning: this is,
                     74:         * apparently, standard behaviour.
                     75:         */
                     76:
                     77:        if (TBL_PART_OPTS == tbl->part && len)
1.1       kristaps   78:                if (';' != cp[len - 1])
                     79:                        tbl->part = TBL_PART_LAYOUT;
1.5       kristaps   80:
                     81:        /* Now process each logical section of the table.  */
                     82:
                     83:        switch (tbl->part) {
                     84:        case (TBL_PART_OPTS):
                     85:                return(tbl_option(tbl, ln, p) ? ROFF_IGN : ROFF_ERR);
1.6       kristaps   86:        case (TBL_PART_LAYOUT):
                     87:                return(tbl_layout(tbl, ln, p) ? ROFF_IGN : ROFF_ERR);
1.5       kristaps   88:        default:
                     89:                break;
                     90:        }
1.1       kristaps   91:
1.2       kristaps   92:        return(ROFF_CONT);
1.1       kristaps   93: }
                     94:
                     95: struct tbl *
1.5       kristaps   96: tbl_alloc(void *data, const mandocmsg msg)
1.1       kristaps   97: {
                     98:        struct tbl      *p;
                     99:
1.6       kristaps  100:        p = mandoc_calloc(1, sizeof(struct tbl));
1.5       kristaps  101:        p->data = data;
                    102:        p->msg = msg;
1.1       kristaps  103:        tbl_init(p);
                    104:        return(p);
                    105: }
                    106:
                    107: void
                    108: tbl_free(struct tbl *p)
                    109: {
                    110:
                    111:        tbl_clear(p);
                    112:        free(p);
                    113: }
                    114:
                    115: void
                    116: tbl_reset(struct tbl *tbl)
                    117: {
                    118:
                    119:        tbl_clear(tbl);
                    120:        tbl_init(tbl);
1.7     ! kristaps  121: }
        !           122:
        !           123: void
        !           124: tbl_restart(struct tbl *tbl)
        !           125: {
        !           126:
        !           127:        tbl_clear(tbl);
        !           128:        tbl->part = TBL_PART_LAYOUT;
1.1       kristaps  129: }
1.3       kristaps  130:

CVSweb