[BACK]Return to tbl_html.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mandoc

Annotation of src/usr.bin/mandoc/tbl_html.c, Revision 1.13

1.13    ! schwarze    1: /*     $OpenBSD: tbl_html.c,v 1.12 2015/10/06 18:30:44 schwarze Exp $ */
1.1       schwarze    2: /*
1.5       schwarze    3:  * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
1.12      schwarze    4:  * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
1.1       schwarze    5:  *
                      6:  * Permission to use, copy, modify, and distribute this software for any
                      7:  * purpose with or without fee is hereby granted, provided that the above
                      8:  * copyright notice and this permission notice appear in all copies.
                      9:  *
                     10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     13:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     14:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     15:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     16:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     17:  */
1.8       schwarze   18: #include <sys/types.h>
                     19:
1.1       schwarze   20: #include <assert.h>
                     21: #include <stdio.h>
                     22: #include <stdlib.h>
                     23: #include <string.h>
                     24:
                     25: #include "mandoc.h"
                     26: #include "out.h"
                     27: #include "html.h"
                     28:
1.4       schwarze   29: static void     html_tblopen(struct html *, const struct tbl_span *);
1.2       schwarze   30: static size_t   html_tbl_len(size_t, void *);
                     31: static size_t   html_tbl_strlen(const char *, void *);
                     32:
1.7       schwarze   33:
1.2       schwarze   34: static size_t
                     35: html_tbl_len(size_t sz, void *arg)
                     36: {
1.7       schwarze   37:
1.12      schwarze   38:        return sz;
1.2       schwarze   39: }
                     40:
                     41: static size_t
                     42: html_tbl_strlen(const char *p, void *arg)
                     43: {
                     44:
1.12      schwarze   45:        return strlen(p);
1.2       schwarze   46: }
                     47:
1.4       schwarze   48: static void
                     49: html_tblopen(struct html *h, const struct tbl_span *sp)
                     50: {
                     51:        struct htmlpair  tag;
                     52:        struct roffsu    su;
                     53:        struct roffcol  *col;
1.10      schwarze   54:        int              ic;
1.4       schwarze   55:
1.11      schwarze   56:        if (h->tbl.cols == NULL) {
1.4       schwarze   57:                h->tbl.len = html_tbl_len;
                     58:                h->tbl.slen = html_tbl_strlen;
1.8       schwarze   59:                tblcalc(&h->tbl, sp, 0);
1.4       schwarze   60:        }
                     61:
                     62:        assert(NULL == h->tblt);
                     63:        PAIR_CLASS_INIT(&tag, "tbl");
                     64:        h->tblt = print_otag(h, TAG_TABLE, 1, &tag);
                     65:
1.10      schwarze   66:        for (ic = 0; ic < sp->opts->cols; ic++) {
1.4       schwarze   67:                bufinit(h);
1.10      schwarze   68:                col = h->tbl.cols + ic;
1.4       schwarze   69:                SCALE_HS_INIT(&su, col->width);
                     70:                bufcat_su(h, "width", &su);
                     71:                PAIR_STYLE_INIT(&tag, h);
                     72:                print_otag(h, TAG_COL, 1, &tag);
                     73:        }
                     74:
                     75:        print_otag(h, TAG_TBODY, 0, NULL);
                     76: }
                     77:
                     78: void
                     79: print_tblclose(struct html *h)
                     80: {
                     81:
                     82:        assert(h->tblt);
                     83:        print_tagq(h, h->tblt);
                     84:        h->tblt = NULL;
                     85: }
                     86:
1.1       schwarze   87: void
                     88: print_tbl(struct html *h, const struct tbl_span *sp)
                     89: {
                     90:        const struct tbl_dat *dp;
1.4       schwarze   91:        struct htmlpair  tag;
1.2       schwarze   92:        struct tag      *tt;
1.10      schwarze   93:        int              ic;
1.2       schwarze   94:
                     95:        /* Inhibit printing of spaces: we do padding ourselves. */
                     96:
1.9       schwarze   97:        if (h->tblt == NULL)
1.4       schwarze   98:                html_tblopen(h, sp);
                     99:
                    100:        assert(h->tblt);
                    101:
1.2       schwarze  102:        h->flags |= HTML_NONOSPACE;
                    103:        h->flags |= HTML_NOSPACE;
                    104:
1.4       schwarze  105:        tt = print_otag(h, TAG_TR, 0, NULL);
1.1       schwarze  106:
                    107:        switch (sp->pos) {
1.7       schwarze  108:        case TBL_SPAN_HORIZ:
                    109:        case TBL_SPAN_DHORIZ:
1.4       schwarze  110:                PAIR_INIT(&tag, ATTR_COLSPAN, "0");
                    111:                print_otag(h, TAG_TD, 1, &tag);
1.2       schwarze  112:                break;
1.1       schwarze  113:        default:
1.2       schwarze  114:                dp = sp->first;
1.10      schwarze  115:                for (ic = 0; ic < sp->opts->cols; ic++) {
1.4       schwarze  116:                        print_stagq(h, tt);
                    117:                        print_otag(h, TAG_TD, 0, NULL);
                    118:
1.10      schwarze  119:                        if (dp == NULL || dp->layout->col > ic)
                    120:                                continue;
1.9       schwarze  121:                        if (dp->layout->pos != TBL_CELL_DOWN)
                    122:                                if (dp->string != NULL)
1.6       schwarze  123:                                        print_text(h, dp->string);
                    124:                        dp = dp->next;
1.2       schwarze  125:                }
1.1       schwarze  126:                break;
                    127:        }
                    128:
1.4       schwarze  129:        print_tagq(h, tt);
                    130:
1.2       schwarze  131:        h->flags &= ~HTML_NONOSPACE;
1.1       schwarze  132:
1.11      schwarze  133:        if (sp->next == NULL) {
1.2       schwarze  134:                assert(h->tbl.cols);
                    135:                free(h->tbl.cols);
                    136:                h->tbl.cols = NULL;
1.4       schwarze  137:                print_tblclose(h);
1.1       schwarze  138:        }
1.4       schwarze  139:
1.1       schwarze  140: }