Print this page
5051 import mdocml-1.12.3
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Approved by: TBD
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/mandoc/tbl_html.c
+++ new/usr/src/cmd/mandoc/tbl_html.c
1 -/* $Id: tbl_html.c,v 1.9 2011/09/18 14:14:15 schwarze Exp $ */
1 +/* $Id: tbl_html.c,v 1.10 2012/05/27 17:54:54 schwarze Exp $ */
2 2 /*
3 3 * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 4 *
5 5 * Permission to use, copy, modify, and distribute this software for any
6 6 * purpose with or without fee is hereby granted, provided that the above
7 7 * copyright notice and this permission notice appear in all copies.
8 8 *
9 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 16 */
17 17 #ifdef HAVE_CONFIG_H
18 18 #include "config.h"
19 19 #endif
20 20
21 21 #include <assert.h>
22 22 #include <stdio.h>
23 23 #include <stdlib.h>
24 24 #include <string.h>
25 25
26 26 #include "mandoc.h"
27 27 #include "out.h"
28 28 #include "html.h"
29 29
30 30 static void html_tblopen(struct html *, const struct tbl_span *);
31 31 static size_t html_tbl_len(size_t, void *);
32 32 static size_t html_tbl_strlen(const char *, void *);
33 33
34 34 /* ARGSUSED */
35 35 static size_t
36 36 html_tbl_len(size_t sz, void *arg)
37 37 {
38 38
39 39 return(sz);
40 40 }
41 41
42 42 /* ARGSUSED */
43 43 static size_t
44 44 html_tbl_strlen(const char *p, void *arg)
45 45 {
46 46
47 47 return(strlen(p));
48 48 }
49 49
50 50 static void
51 51 html_tblopen(struct html *h, const struct tbl_span *sp)
52 52 {
53 53 const struct tbl_head *hp;
54 54 struct htmlpair tag;
55 55 struct roffsu su;
56 56 struct roffcol *col;
57 57
58 58 if (TBL_SPAN_FIRST & sp->flags) {
59 59 h->tbl.len = html_tbl_len;
60 60 h->tbl.slen = html_tbl_strlen;
61 61 tblcalc(&h->tbl, sp);
62 62 }
63 63
64 64 assert(NULL == h->tblt);
65 65 PAIR_CLASS_INIT(&tag, "tbl");
66 66 h->tblt = print_otag(h, TAG_TABLE, 1, &tag);
67 67
68 68 for (hp = sp->head; hp; hp = hp->next) {
69 69 bufinit(h);
70 70 col = &h->tbl.cols[hp->ident];
71 71 SCALE_HS_INIT(&su, col->width);
72 72 bufcat_su(h, "width", &su);
73 73 PAIR_STYLE_INIT(&tag, h);
74 74 print_otag(h, TAG_COL, 1, &tag);
75 75 }
76 76
77 77 print_otag(h, TAG_TBODY, 0, NULL);
78 78 }
79 79
80 80 void
81 81 print_tblclose(struct html *h)
82 82 {
83 83
84 84 assert(h->tblt);
85 85 print_tagq(h, h->tblt);
86 86 h->tblt = NULL;
87 87 }
88 88
89 89 void
90 90 print_tbl(struct html *h, const struct tbl_span *sp)
91 91 {
92 92 const struct tbl_head *hp;
93 93 const struct tbl_dat *dp;
94 94 struct htmlpair tag;
95 95 struct tag *tt;
96 96
97 97 /* Inhibit printing of spaces: we do padding ourselves. */
98 98
99 99 if (NULL == h->tblt)
100 100 html_tblopen(h, sp);
101 101
102 102 assert(h->tblt);
103 103
104 104 h->flags |= HTML_NONOSPACE;
105 105 h->flags |= HTML_NOSPACE;
106 106
107 107 tt = print_otag(h, TAG_TR, 0, NULL);
108 108
109 109 switch (sp->pos) {
110 110 case (TBL_SPAN_HORIZ):
111 111 /* FALLTHROUGH */
↓ open down ↓ |
100 lines elided |
↑ open up ↑ |
112 112 case (TBL_SPAN_DHORIZ):
113 113 PAIR_INIT(&tag, ATTR_COLSPAN, "0");
114 114 print_otag(h, TAG_TD, 1, &tag);
115 115 break;
116 116 default:
117 117 dp = sp->first;
118 118 for (hp = sp->head; hp; hp = hp->next) {
119 119 print_stagq(h, tt);
120 120 print_otag(h, TAG_TD, 0, NULL);
121 121
122 - switch (hp->pos) {
123 - case (TBL_HEAD_VERT):
124 - /* FALLTHROUGH */
125 - case (TBL_HEAD_DVERT):
126 - continue;
127 - case (TBL_HEAD_DATA):
128 - if (NULL == dp)
129 - break;
130 - if (TBL_CELL_DOWN != dp->layout->pos)
131 - if (dp->string)
132 - print_text(h, dp->string);
133 - dp = dp->next;
122 + if (NULL == dp)
134 123 break;
135 - }
124 + if (TBL_CELL_DOWN != dp->layout->pos)
125 + if (dp->string)
126 + print_text(h, dp->string);
127 + dp = dp->next;
136 128 }
137 129 break;
138 130 }
139 131
140 132 print_tagq(h, tt);
141 133
142 134 h->flags &= ~HTML_NONOSPACE;
143 135
144 136 if (TBL_SPAN_LAST & sp->flags) {
145 137 assert(h->tbl.cols);
146 138 free(h->tbl.cols);
147 139 h->tbl.cols = NULL;
148 140 print_tblclose(h);
149 141 }
150 142
151 143 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX