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

Annotation of mandoc/tbl.c, Revision 1.8

1.8     ! kristaps    1: /*     $Id: tbl.c,v 1.7 2010/12/29 14:53:31 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;
1.8     ! kristaps   66:        struct tbl_dat  *dp;
        !            67:        struct tbl_span *sp;
1.1       kristaps   68:
                     69:        cp = &p[offs];
                     70:        len = (int)strlen(cp);
                     71:
1.5       kristaps   72:        /*
                     73:         * If we're in the options section and we don't have a
                     74:         * terminating semicolon, assume we've moved directly into the
                     75:         * layout section.  No need to report a warning: this is,
                     76:         * apparently, standard behaviour.
                     77:         */
                     78:
                     79:        if (TBL_PART_OPTS == tbl->part && len)
1.1       kristaps   80:                if (';' != cp[len - 1])
                     81:                        tbl->part = TBL_PART_LAYOUT;
1.5       kristaps   82:
                     83:        /* Now process each logical section of the table.  */
                     84:
                     85:        switch (tbl->part) {
                     86:        case (TBL_PART_OPTS):
                     87:                return(tbl_option(tbl, ln, p) ? ROFF_IGN : ROFF_ERR);
1.6       kristaps   88:        case (TBL_PART_LAYOUT):
                     89:                return(tbl_layout(tbl, ln, p) ? ROFF_IGN : ROFF_ERR);
1.8     ! kristaps   90:        case (TBL_PART_DATA):
1.5       kristaps   91:                break;
1.8     ! kristaps   92:        }
        !            93:
        !            94:        /* XXX: throw away data for now. */
        !            95:        if (NULL != (sp = tbl_data(tbl, ln, p))) {
        !            96:                while (NULL != (dp = sp->first)) {
        !            97:                        sp->first = sp->first->next;
        !            98:                        if (dp->string)
        !            99:                                free(dp->string);
        !           100:                        free(dp);
        !           101:                }
        !           102:                free(sp);
1.5       kristaps  103:        }
1.1       kristaps  104:
1.2       kristaps  105:        return(ROFF_CONT);
1.1       kristaps  106: }
                    107:
                    108: struct tbl *
1.5       kristaps  109: tbl_alloc(void *data, const mandocmsg msg)
1.1       kristaps  110: {
                    111:        struct tbl      *p;
                    112:
1.6       kristaps  113:        p = mandoc_calloc(1, sizeof(struct tbl));
1.5       kristaps  114:        p->data = data;
                    115:        p->msg = msg;
1.1       kristaps  116:        tbl_init(p);
                    117:        return(p);
                    118: }
                    119:
                    120: void
                    121: tbl_free(struct tbl *p)
                    122: {
                    123:
                    124:        tbl_clear(p);
                    125:        free(p);
                    126: }
                    127:
                    128: void
                    129: tbl_reset(struct tbl *tbl)
                    130: {
                    131:
                    132:        tbl_clear(tbl);
                    133:        tbl_init(tbl);
1.7       kristaps  134: }
                    135:
                    136: void
                    137: tbl_restart(struct tbl *tbl)
                    138: {
                    139:
                    140:        tbl_clear(tbl);
                    141:        tbl->part = TBL_PART_LAYOUT;
1.1       kristaps  142: }
1.3       kristaps  143:

CVSweb