Print this page
9718 update mandoc to 1.14.4
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.23 2017/07/31 16:14:10 schwarze Exp $ */
1 +/* $Id: tbl_html.c,v 1.24 2018/06/25 13:45:57 schwarze Exp $ */
2 2 /*
3 3 * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 4 * Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
5 5 *
6 6 * Permission to use, copy, modify, and distribute this software for any
7 7 * purpose with or without fee is hereby granted, provided that the above
8 8 * copyright notice and this permission notice appear in all copies.
9 9 *
10 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 17 */
18 18 #include "config.h"
19 19
20 20 #include <sys/types.h>
21 21
22 22 #include <assert.h>
23 23 #include <stdio.h>
24 24 #include <stdlib.h>
25 25 #include <string.h>
26 26
27 27 #include "mandoc.h"
28 28 #include "out.h"
29 29 #include "html.h"
30 30
31 31 static void html_tblopen(struct html *, const struct tbl_span *);
32 32 static size_t html_tbl_len(size_t, void *);
33 33 static size_t html_tbl_strlen(const char *, void *);
34 34 static size_t html_tbl_sulen(const struct roffsu *, void *);
35 35
36 36
37 37 static size_t
38 38 html_tbl_len(size_t sz, void *arg)
39 39 {
40 40 return sz;
41 41 }
42 42
43 43 static size_t
44 44 html_tbl_strlen(const char *p, void *arg)
45 45 {
46 46 return strlen(p);
47 47 }
48 48
49 49 static size_t
50 50 html_tbl_sulen(const struct roffsu *su, void *arg)
51 51 {
52 52 if (su->scale < 0.0)
53 53 return 0;
54 54
55 55 switch (su->unit) {
56 56 case SCALE_FS: /* 2^16 basic units */
57 57 return su->scale * 65536.0 / 24.0;
58 58 case SCALE_IN: /* 10 characters per inch */
59 59 return su->scale * 10.0;
60 60 case SCALE_CM: /* 2.54 cm per inch */
61 61 return su->scale * 10.0 / 2.54;
62 62 case SCALE_PC: /* 6 pica per inch */
63 63 case SCALE_VS:
64 64 return su->scale * 10.0 / 6.0;
65 65 case SCALE_EN:
66 66 case SCALE_EM:
67 67 return su->scale;
68 68 case SCALE_PT: /* 12 points per pica */
69 69 return su->scale * 10.0 / 6.0 / 12.0;
70 70 case SCALE_BU: /* 24 basic units per character */
71 71 return su->scale / 24.0;
↓ open down ↓ |
60 lines elided |
↑ open up ↑ |
72 72 case SCALE_MM: /* 1/1000 inch */
73 73 return su->scale / 100.0;
74 74 default:
75 75 abort();
76 76 }
77 77 }
78 78
79 79 static void
80 80 html_tblopen(struct html *h, const struct tbl_span *sp)
81 81 {
82 - struct tag *t;
83 - int ic;
84 -
85 82 if (h->tbl.cols == NULL) {
86 83 h->tbl.len = html_tbl_len;
87 84 h->tbl.slen = html_tbl_strlen;
88 85 h->tbl.sulen = html_tbl_sulen;
89 86 tblcalc(&h->tbl, sp, 0, 0);
90 87 }
91 -
92 88 assert(NULL == h->tblt);
93 89 h->tblt = print_otag(h, TAG_TABLE, "c", "tbl");
94 -
95 - t = print_otag(h, TAG_COLGROUP, "");
96 - for (ic = 0; ic < sp->opts->cols; ic++)
97 - print_otag(h, TAG_COL, "shw", h->tbl.cols[ic].width);
98 - print_tagq(h, t);
99 90 }
100 91
101 92 void
102 93 print_tblclose(struct html *h)
103 94 {
104 95
105 96 assert(h->tblt);
106 97 print_tagq(h, h->tblt);
107 98 h->tblt = NULL;
108 99 }
109 100
110 101 void
111 102 print_tbl(struct html *h, const struct tbl_span *sp)
112 103 {
113 104 const struct tbl_dat *dp;
114 105 struct tag *tt;
115 106 int ic;
116 107
117 108 /* Inhibit printing of spaces: we do padding ourselves. */
118 109
119 110 if (h->tblt == NULL)
120 111 html_tblopen(h, sp);
121 112
122 113 assert(h->tblt);
123 114
124 115 h->flags |= HTML_NONOSPACE;
125 116 h->flags |= HTML_NOSPACE;
126 117
127 118 tt = print_otag(h, TAG_TR, "");
128 119
129 120 switch (sp->pos) {
130 121 case TBL_SPAN_HORIZ:
131 122 case TBL_SPAN_DHORIZ:
132 123 print_otag(h, TAG_TD, "?", "colspan", "0");
133 124 break;
134 125 default:
135 126 dp = sp->first;
136 127 for (ic = 0; ic < sp->opts->cols; ic++) {
137 128 print_stagq(h, tt);
138 129 print_otag(h, TAG_TD, "");
139 130
140 131 if (dp == NULL || dp->layout->col > ic)
141 132 continue;
142 133 if (dp->layout->pos != TBL_CELL_DOWN)
143 134 if (dp->string != NULL)
144 135 print_text(h, dp->string);
145 136 dp = dp->next;
146 137 }
147 138 break;
148 139 }
149 140
150 141 print_tagq(h, tt);
151 142
152 143 h->flags &= ~HTML_NONOSPACE;
153 144
154 145 if (sp->next == NULL) {
155 146 assert(h->tbl.cols);
156 147 free(h->tbl.cols);
157 148 h->tbl.cols = NULL;
158 149 print_tblclose(h);
159 150 }
160 151
161 152 }
↓ open down ↓ |
53 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX