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/mdoc_html.c
+++ new/usr/src/cmd/mandoc/mdoc_html.c
1 -/* $Id: mdoc_html.c,v 1.182 2011/11/03 20:37:00 schwarze Exp $ */
1 +/* $Id: mdoc_html.c,v 1.186 2013/12/24 20:45:27 schwarze Exp $ */
2 2 /*
3 3 * Copyright (c) 2008, 2009, 2010, 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 <sys/types.h>
22 22
23 23 #include <assert.h>
24 24 #include <ctype.h>
25 25 #include <stdio.h>
26 26 #include <stdlib.h>
27 27 #include <string.h>
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
28 28 #include <unistd.h>
29 29
30 30 #include "mandoc.h"
31 31 #include "out.h"
32 32 #include "html.h"
33 33 #include "mdoc.h"
34 34 #include "main.h"
35 35
36 36 #define INDENT 5
37 37
38 -#define MDOC_ARGS const struct mdoc_meta *m, \
38 +#define MDOC_ARGS const struct mdoc_meta *meta, \
39 39 const struct mdoc_node *n, \
40 40 struct html *h
41 41
42 42 #ifndef MIN
43 43 #define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
44 44 #endif
45 45
46 46 struct htmlmdoc {
47 47 int (*pre)(MDOC_ARGS);
48 48 void (*post)(MDOC_ARGS);
49 49 };
50 50
51 51 static void print_mdoc(MDOC_ARGS);
52 52 static void print_mdoc_head(MDOC_ARGS);
53 53 static void print_mdoc_node(MDOC_ARGS);
54 54 static void print_mdoc_nodelist(MDOC_ARGS);
55 55 static void synopsis_pre(struct html *,
56 56 const struct mdoc_node *);
57 57
58 58 static void a2width(const char *, struct roffsu *);
59 59 static void a2offs(const char *, struct roffsu *);
60 60
61 61 static void mdoc_root_post(MDOC_ARGS);
62 62 static int mdoc_root_pre(MDOC_ARGS);
63 63
64 64 static void mdoc__x_post(MDOC_ARGS);
65 65 static int mdoc__x_pre(MDOC_ARGS);
66 66 static int mdoc_ad_pre(MDOC_ARGS);
67 67 static int mdoc_an_pre(MDOC_ARGS);
68 68 static int mdoc_ap_pre(MDOC_ARGS);
69 69 static int mdoc_ar_pre(MDOC_ARGS);
70 70 static int mdoc_bd_pre(MDOC_ARGS);
71 71 static int mdoc_bf_pre(MDOC_ARGS);
72 72 static void mdoc_bk_post(MDOC_ARGS);
73 73 static int mdoc_bk_pre(MDOC_ARGS);
74 74 static int mdoc_bl_pre(MDOC_ARGS);
75 75 static int mdoc_bt_pre(MDOC_ARGS);
76 76 static int mdoc_bx_pre(MDOC_ARGS);
77 77 static int mdoc_cd_pre(MDOC_ARGS);
78 78 static int mdoc_d1_pre(MDOC_ARGS);
79 79 static int mdoc_dv_pre(MDOC_ARGS);
80 80 static int mdoc_fa_pre(MDOC_ARGS);
81 81 static int mdoc_fd_pre(MDOC_ARGS);
82 82 static int mdoc_fl_pre(MDOC_ARGS);
83 83 static int mdoc_fn_pre(MDOC_ARGS);
84 84 static int mdoc_ft_pre(MDOC_ARGS);
85 85 static int mdoc_em_pre(MDOC_ARGS);
86 86 static int mdoc_er_pre(MDOC_ARGS);
87 87 static int mdoc_ev_pre(MDOC_ARGS);
88 88 static int mdoc_ex_pre(MDOC_ARGS);
89 89 static void mdoc_fo_post(MDOC_ARGS);
90 90 static int mdoc_fo_pre(MDOC_ARGS);
91 91 static int mdoc_ic_pre(MDOC_ARGS);
92 92 static int mdoc_igndelim_pre(MDOC_ARGS);
93 93 static int mdoc_in_pre(MDOC_ARGS);
94 94 static int mdoc_it_pre(MDOC_ARGS);
95 95 static int mdoc_lb_pre(MDOC_ARGS);
96 96 static int mdoc_li_pre(MDOC_ARGS);
97 97 static int mdoc_lk_pre(MDOC_ARGS);
98 98 static int mdoc_mt_pre(MDOC_ARGS);
99 99 static int mdoc_ms_pre(MDOC_ARGS);
100 100 static int mdoc_nd_pre(MDOC_ARGS);
101 101 static int mdoc_nm_pre(MDOC_ARGS);
102 102 static int mdoc_ns_pre(MDOC_ARGS);
103 103 static int mdoc_pa_pre(MDOC_ARGS);
104 104 static void mdoc_pf_post(MDOC_ARGS);
105 105 static int mdoc_pp_pre(MDOC_ARGS);
106 106 static void mdoc_quote_post(MDOC_ARGS);
107 107 static int mdoc_quote_pre(MDOC_ARGS);
108 108 static int mdoc_rs_pre(MDOC_ARGS);
109 109 static int mdoc_rv_pre(MDOC_ARGS);
110 110 static int mdoc_sh_pre(MDOC_ARGS);
111 111 static int mdoc_sm_pre(MDOC_ARGS);
112 112 static int mdoc_sp_pre(MDOC_ARGS);
113 113 static int mdoc_ss_pre(MDOC_ARGS);
114 114 static int mdoc_sx_pre(MDOC_ARGS);
115 115 static int mdoc_sy_pre(MDOC_ARGS);
116 116 static int mdoc_ud_pre(MDOC_ARGS);
117 117 static int mdoc_va_pre(MDOC_ARGS);
118 118 static int mdoc_vt_pre(MDOC_ARGS);
119 119 static int mdoc_xr_pre(MDOC_ARGS);
120 120 static int mdoc_xx_pre(MDOC_ARGS);
121 121
122 122 static const struct htmlmdoc mdocs[MDOC_MAX] = {
123 123 {mdoc_ap_pre, NULL}, /* Ap */
124 124 {NULL, NULL}, /* Dd */
125 125 {NULL, NULL}, /* Dt */
126 126 {NULL, NULL}, /* Os */
127 127 {mdoc_sh_pre, NULL }, /* Sh */
128 128 {mdoc_ss_pre, NULL }, /* Ss */
129 129 {mdoc_pp_pre, NULL}, /* Pp */
130 130 {mdoc_d1_pre, NULL}, /* D1 */
131 131 {mdoc_d1_pre, NULL}, /* Dl */
132 132 {mdoc_bd_pre, NULL}, /* Bd */
133 133 {NULL, NULL}, /* Ed */
134 134 {mdoc_bl_pre, NULL}, /* Bl */
135 135 {NULL, NULL}, /* El */
136 136 {mdoc_it_pre, NULL}, /* It */
137 137 {mdoc_ad_pre, NULL}, /* Ad */
138 138 {mdoc_an_pre, NULL}, /* An */
139 139 {mdoc_ar_pre, NULL}, /* Ar */
140 140 {mdoc_cd_pre, NULL}, /* Cd */
141 141 {mdoc_fl_pre, NULL}, /* Cm */
142 142 {mdoc_dv_pre, NULL}, /* Dv */
143 143 {mdoc_er_pre, NULL}, /* Er */
144 144 {mdoc_ev_pre, NULL}, /* Ev */
145 145 {mdoc_ex_pre, NULL}, /* Ex */
146 146 {mdoc_fa_pre, NULL}, /* Fa */
147 147 {mdoc_fd_pre, NULL}, /* Fd */
148 148 {mdoc_fl_pre, NULL}, /* Fl */
149 149 {mdoc_fn_pre, NULL}, /* Fn */
150 150 {mdoc_ft_pre, NULL}, /* Ft */
151 151 {mdoc_ic_pre, NULL}, /* Ic */
152 152 {mdoc_in_pre, NULL}, /* In */
153 153 {mdoc_li_pre, NULL}, /* Li */
154 154 {mdoc_nd_pre, NULL}, /* Nd */
155 155 {mdoc_nm_pre, NULL}, /* Nm */
156 156 {mdoc_quote_pre, mdoc_quote_post}, /* Op */
157 157 {NULL, NULL}, /* Ot */
158 158 {mdoc_pa_pre, NULL}, /* Pa */
159 159 {mdoc_rv_pre, NULL}, /* Rv */
160 160 {NULL, NULL}, /* St */
161 161 {mdoc_va_pre, NULL}, /* Va */
162 162 {mdoc_vt_pre, NULL}, /* Vt */
163 163 {mdoc_xr_pre, NULL}, /* Xr */
164 164 {mdoc__x_pre, mdoc__x_post}, /* %A */
165 165 {mdoc__x_pre, mdoc__x_post}, /* %B */
166 166 {mdoc__x_pre, mdoc__x_post}, /* %D */
167 167 {mdoc__x_pre, mdoc__x_post}, /* %I */
168 168 {mdoc__x_pre, mdoc__x_post}, /* %J */
169 169 {mdoc__x_pre, mdoc__x_post}, /* %N */
170 170 {mdoc__x_pre, mdoc__x_post}, /* %O */
171 171 {mdoc__x_pre, mdoc__x_post}, /* %P */
172 172 {mdoc__x_pre, mdoc__x_post}, /* %R */
173 173 {mdoc__x_pre, mdoc__x_post}, /* %T */
174 174 {mdoc__x_pre, mdoc__x_post}, /* %V */
175 175 {NULL, NULL}, /* Ac */
176 176 {mdoc_quote_pre, mdoc_quote_post}, /* Ao */
177 177 {mdoc_quote_pre, mdoc_quote_post}, /* Aq */
178 178 {NULL, NULL}, /* At */
179 179 {NULL, NULL}, /* Bc */
180 180 {mdoc_bf_pre, NULL}, /* Bf */
181 181 {mdoc_quote_pre, mdoc_quote_post}, /* Bo */
182 182 {mdoc_quote_pre, mdoc_quote_post}, /* Bq */
183 183 {mdoc_xx_pre, NULL}, /* Bsx */
184 184 {mdoc_bx_pre, NULL}, /* Bx */
185 185 {NULL, NULL}, /* Db */
186 186 {NULL, NULL}, /* Dc */
187 187 {mdoc_quote_pre, mdoc_quote_post}, /* Do */
188 188 {mdoc_quote_pre, mdoc_quote_post}, /* Dq */
189 189 {NULL, NULL}, /* Ec */ /* FIXME: no space */
190 190 {NULL, NULL}, /* Ef */
191 191 {mdoc_em_pre, NULL}, /* Em */
192 192 {mdoc_quote_pre, mdoc_quote_post}, /* Eo */
193 193 {mdoc_xx_pre, NULL}, /* Fx */
194 194 {mdoc_ms_pre, NULL}, /* Ms */
195 195 {mdoc_igndelim_pre, NULL}, /* No */
196 196 {mdoc_ns_pre, NULL}, /* Ns */
197 197 {mdoc_xx_pre, NULL}, /* Nx */
198 198 {mdoc_xx_pre, NULL}, /* Ox */
199 199 {NULL, NULL}, /* Pc */
200 200 {mdoc_igndelim_pre, mdoc_pf_post}, /* Pf */
201 201 {mdoc_quote_pre, mdoc_quote_post}, /* Po */
202 202 {mdoc_quote_pre, mdoc_quote_post}, /* Pq */
203 203 {NULL, NULL}, /* Qc */
204 204 {mdoc_quote_pre, mdoc_quote_post}, /* Ql */
205 205 {mdoc_quote_pre, mdoc_quote_post}, /* Qo */
206 206 {mdoc_quote_pre, mdoc_quote_post}, /* Qq */
207 207 {NULL, NULL}, /* Re */
208 208 {mdoc_rs_pre, NULL}, /* Rs */
209 209 {NULL, NULL}, /* Sc */
210 210 {mdoc_quote_pre, mdoc_quote_post}, /* So */
211 211 {mdoc_quote_pre, mdoc_quote_post}, /* Sq */
212 212 {mdoc_sm_pre, NULL}, /* Sm */
213 213 {mdoc_sx_pre, NULL}, /* Sx */
214 214 {mdoc_sy_pre, NULL}, /* Sy */
215 215 {NULL, NULL}, /* Tn */
216 216 {mdoc_xx_pre, NULL}, /* Ux */
217 217 {NULL, NULL}, /* Xc */
218 218 {NULL, NULL}, /* Xo */
219 219 {mdoc_fo_pre, mdoc_fo_post}, /* Fo */
220 220 {NULL, NULL}, /* Fc */
221 221 {mdoc_quote_pre, mdoc_quote_post}, /* Oo */
222 222 {NULL, NULL}, /* Oc */
223 223 {mdoc_bk_pre, mdoc_bk_post}, /* Bk */
224 224 {NULL, NULL}, /* Ek */
225 225 {mdoc_bt_pre, NULL}, /* Bt */
226 226 {NULL, NULL}, /* Hf */
227 227 {NULL, NULL}, /* Fr */
228 228 {mdoc_ud_pre, NULL}, /* Ud */
229 229 {mdoc_lb_pre, NULL}, /* Lb */
230 230 {mdoc_pp_pre, NULL}, /* Lp */
231 231 {mdoc_lk_pre, NULL}, /* Lk */
232 232 {mdoc_mt_pre, NULL}, /* Mt */
233 233 {mdoc_quote_pre, mdoc_quote_post}, /* Brq */
234 234 {mdoc_quote_pre, mdoc_quote_post}, /* Bro */
235 235 {NULL, NULL}, /* Brc */
236 236 {mdoc__x_pre, mdoc__x_post}, /* %C */
237 237 {NULL, NULL}, /* Es */ /* TODO */
238 238 {NULL, NULL}, /* En */ /* TODO */
239 239 {mdoc_xx_pre, NULL}, /* Dx */
240 240 {mdoc__x_pre, mdoc__x_post}, /* %Q */
241 241 {mdoc_sp_pre, NULL}, /* br */
242 242 {mdoc_sp_pre, NULL}, /* sp */
243 243 {mdoc__x_pre, mdoc__x_post}, /* %U */
244 244 {NULL, NULL}, /* Ta */
245 245 };
246 246
247 247 static const char * const lists[LIST_MAX] = {
248 248 NULL,
249 249 "list-bul",
250 250 "list-col",
251 251 "list-dash",
252 252 "list-diag",
↓ open down ↓ |
204 lines elided |
↑ open up ↑ |
253 253 "list-enum",
254 254 "list-hang",
255 255 "list-hyph",
256 256 "list-inset",
257 257 "list-item",
258 258 "list-ohang",
259 259 "list-tag"
260 260 };
261 261
262 262 void
263 -html_mdoc(void *arg, const struct mdoc *m)
263 +html_mdoc(void *arg, const struct mdoc *mdoc)
264 264 {
265 265
266 - print_mdoc(mdoc_meta(m), mdoc_node(m), (struct html *)arg);
266 + print_mdoc(mdoc_meta(mdoc), mdoc_node(mdoc),
267 + (struct html *)arg);
267 268 putchar('\n');
268 269 }
269 270
270 271
271 272 /*
272 273 * Calculate the scaling unit passed in a `-width' argument. This uses
273 274 * either a native scaling unit (e.g., 1i, 2m) or the string length of
274 275 * the value.
275 276 */
276 277 static void
277 278 a2width(const char *p, struct roffsu *su)
278 279 {
279 280
280 281 if ( ! a2roffsu(p, su, SCALE_MAX)) {
281 282 su->unit = SCALE_BU;
282 283 su->scale = html_strlen(p);
283 284 }
284 285 }
285 286
286 287
287 288 /*
288 289 * See the same function in mdoc_term.c for documentation.
289 290 */
290 291 static void
291 292 synopsis_pre(struct html *h, const struct mdoc_node *n)
292 293 {
293 294
294 295 if (NULL == n->prev || ! (MDOC_SYNPRETTY & n->flags))
295 296 return;
296 297
297 298 if (n->prev->tok == n->tok &&
298 299 MDOC_Fo != n->tok &&
299 300 MDOC_Ft != n->tok &&
300 301 MDOC_Fn != n->tok) {
301 302 print_otag(h, TAG_BR, 0, NULL);
302 303 return;
303 304 }
304 305
305 306 switch (n->prev->tok) {
306 307 case (MDOC_Fd):
307 308 /* FALLTHROUGH */
308 309 case (MDOC_Fn):
309 310 /* FALLTHROUGH */
310 311 case (MDOC_Fo):
311 312 /* FALLTHROUGH */
312 313 case (MDOC_In):
313 314 /* FALLTHROUGH */
314 315 case (MDOC_Vt):
315 316 print_otag(h, TAG_P, 0, NULL);
316 317 break;
317 318 case (MDOC_Ft):
318 319 if (MDOC_Fn != n->tok && MDOC_Fo != n->tok) {
319 320 print_otag(h, TAG_P, 0, NULL);
320 321 break;
321 322 }
322 323 /* FALLTHROUGH */
323 324 default:
324 325 print_otag(h, TAG_BR, 0, NULL);
325 326 break;
326 327 }
327 328 }
328 329
329 330
330 331 /*
331 332 * Calculate the scaling unit passed in an `-offset' argument. This
332 333 * uses either a native scaling unit (e.g., 1i, 2m), one of a set of
333 334 * predefined strings (indent, etc.), or the string length of the value.
334 335 */
335 336 static void
336 337 a2offs(const char *p, struct roffsu *su)
337 338 {
338 339
339 340 /* FIXME: "right"? */
340 341
341 342 if (0 == strcmp(p, "left"))
342 343 SCALE_HS_INIT(su, 0);
343 344 else if (0 == strcmp(p, "indent"))
344 345 SCALE_HS_INIT(su, INDENT);
345 346 else if (0 == strcmp(p, "indent-two"))
346 347 SCALE_HS_INIT(su, INDENT * 2);
347 348 else if ( ! a2roffsu(p, su, SCALE_MAX))
348 349 SCALE_HS_INIT(su, html_strlen(p));
349 350 }
350 351
351 352
352 353 static void
353 354 print_mdoc(MDOC_ARGS)
↓ open down ↓ |
77 lines elided |
↑ open up ↑ |
354 355 {
355 356 struct tag *t, *tt;
356 357 struct htmlpair tag;
357 358
358 359 PAIR_CLASS_INIT(&tag, "mandoc");
359 360
360 361 if ( ! (HTML_FRAGMENT & h->oflags)) {
361 362 print_gen_decls(h);
362 363 t = print_otag(h, TAG_HTML, 0, NULL);
363 364 tt = print_otag(h, TAG_HEAD, 0, NULL);
364 - print_mdoc_head(m, n, h);
365 + print_mdoc_head(meta, n, h);
365 366 print_tagq(h, tt);
366 367 print_otag(h, TAG_BODY, 0, NULL);
367 368 print_otag(h, TAG_DIV, 1, &tag);
368 369 } else
369 370 t = print_otag(h, TAG_DIV, 1, &tag);
370 371
371 - print_mdoc_nodelist(m, n, h);
372 + print_mdoc_nodelist(meta, n, h);
372 373 print_tagq(h, t);
373 374 }
374 375
375 376
376 377 /* ARGSUSED */
377 378 static void
378 379 print_mdoc_head(MDOC_ARGS)
379 380 {
380 381
381 382 print_gen_head(h);
382 383 bufinit(h);
383 - bufcat_fmt(h, "%s(%s)", m->title, m->msec);
384 + bufcat_fmt(h, "%s(%s)", meta->title, meta->msec);
384 385
385 - if (m->arch)
386 - bufcat_fmt(h, " (%s)", m->arch);
386 + if (meta->arch)
387 + bufcat_fmt(h, " (%s)", meta->arch);
387 388
388 389 print_otag(h, TAG_TITLE, 0, NULL);
389 390 print_text(h, h->buf);
390 391 }
391 392
392 393
393 394 static void
394 395 print_mdoc_nodelist(MDOC_ARGS)
395 396 {
396 397
397 - print_mdoc_node(m, n, h);
398 + print_mdoc_node(meta, n, h);
398 399 if (n->next)
399 - print_mdoc_nodelist(m, n->next, h);
400 + print_mdoc_nodelist(meta, n->next, h);
400 401 }
401 402
402 403
403 404 static void
404 405 print_mdoc_node(MDOC_ARGS)
405 406 {
406 407 int child;
407 408 struct tag *t;
408 409
409 410 child = 1;
410 411 t = h->tags.head;
411 412
412 413 switch (n->type) {
413 414 case (MDOC_ROOT):
414 - child = mdoc_root_pre(m, n, h);
415 + child = mdoc_root_pre(meta, n, h);
415 416 break;
416 417 case (MDOC_TEXT):
417 418 /* No tables in this mode... */
418 419 assert(NULL == h->tblt);
419 420
420 421 /*
421 422 * Make sure that if we're in a literal mode already
422 423 * (i.e., within a <PRE>) don't print the newline.
423 424 */
424 425 if (' ' == *n->string && MDOC_LINE & n->flags)
425 426 if ( ! (HTML_LITERAL & h->flags))
426 427 print_otag(h, TAG_BR, 0, NULL);
427 428 if (MDOC_DELIMC & n->flags)
428 429 h->flags |= HTML_NOSPACE;
429 430 print_text(h, n->string);
430 431 if (MDOC_DELIMO & n->flags)
431 432 h->flags |= HTML_NOSPACE;
432 433 return;
433 434 case (MDOC_EQN):
434 435 print_eqn(h, n->eqn);
435 436 break;
436 437 case (MDOC_TBL):
437 438 /*
438 439 * This will take care of initialising all of the table
439 440 * state data for the first table, then tearing it down
440 441 * for the last one.
441 442 */
442 443 print_tbl(h, n->span);
443 444 return;
444 445 default:
445 446 /*
446 447 * Close out the current table, if it's open, and unset
↓ open down ↓ |
22 lines elided |
↑ open up ↑ |
447 448 * the "meta" table state. This will be reopened on the
448 449 * next table element.
449 450 */
450 451 if (h->tblt) {
451 452 print_tblclose(h);
452 453 t = h->tags.head;
453 454 }
454 455
455 456 assert(NULL == h->tblt);
456 457 if (mdocs[n->tok].pre && ENDBODY_NOT == n->end)
457 - child = (*mdocs[n->tok].pre)(m, n, h);
458 + child = (*mdocs[n->tok].pre)(meta, n, h);
458 459 break;
459 460 }
460 461
461 462 if (HTML_KEEP & h->flags) {
462 - if (n->prev && n->prev->line != n->line) {
463 + if (n->prev ? (n->prev->lastline != n->line) :
464 + (n->parent && n->parent->line != n->line)) {
463 465 h->flags &= ~HTML_KEEP;
464 466 h->flags |= HTML_PREKEEP;
465 - } else if (NULL == n->prev) {
466 - if (n->parent && n->parent->line != n->line) {
467 - h->flags &= ~HTML_KEEP;
468 - h->flags |= HTML_PREKEEP;
469 - }
470 467 }
471 468 }
472 469
473 470 if (child && n->child)
474 - print_mdoc_nodelist(m, n->child, h);
471 + print_mdoc_nodelist(meta, n->child, h);
475 472
476 473 print_stagq(h, t);
477 474
478 475 switch (n->type) {
479 476 case (MDOC_ROOT):
480 - mdoc_root_post(m, n, h);
477 + mdoc_root_post(meta, n, h);
481 478 break;
482 479 case (MDOC_EQN):
483 480 break;
484 481 default:
485 482 if (mdocs[n->tok].post && ENDBODY_NOT == n->end)
486 - (*mdocs[n->tok].post)(m, n, h);
483 + (*mdocs[n->tok].post)(meta, n, h);
487 484 break;
488 485 }
489 486 }
490 487
491 488 /* ARGSUSED */
492 489 static void
493 490 mdoc_root_post(MDOC_ARGS)
494 491 {
495 492 struct htmlpair tag[3];
496 493 struct tag *t, *tt;
497 494
498 495 PAIR_SUMMARY_INIT(&tag[0], "Document Footer");
499 496 PAIR_CLASS_INIT(&tag[1], "foot");
500 497 PAIR_INIT(&tag[2], ATTR_WIDTH, "100%");
501 498 t = print_otag(h, TAG_TABLE, 3, tag);
↓ open down ↓ |
5 lines elided |
↑ open up ↑ |
502 499 PAIR_INIT(&tag[0], ATTR_WIDTH, "50%");
503 500 print_otag(h, TAG_COL, 1, tag);
504 501 print_otag(h, TAG_COL, 1, tag);
505 502
506 503 print_otag(h, TAG_TBODY, 0, NULL);
507 504
508 505 tt = print_otag(h, TAG_TR, 0, NULL);
509 506
510 507 PAIR_CLASS_INIT(&tag[0], "foot-date");
511 508 print_otag(h, TAG_TD, 1, tag);
512 - print_text(h, m->date);
509 + print_text(h, meta->date);
513 510 print_stagq(h, tt);
514 511
515 512 PAIR_CLASS_INIT(&tag[0], "foot-os");
516 513 PAIR_INIT(&tag[1], ATTR_ALIGN, "right");
517 514 print_otag(h, TAG_TD, 2, tag);
518 - print_text(h, m->os);
515 + print_text(h, meta->os);
519 516 print_tagq(h, t);
520 517 }
521 518
522 519
523 520 /* ARGSUSED */
524 521 static int
525 522 mdoc_root_pre(MDOC_ARGS)
526 523 {
527 524 struct htmlpair tag[3];
528 525 struct tag *t, *tt;
529 526 char b[BUFSIZ], title[BUFSIZ];
530 527
531 - strlcpy(b, m->vol, BUFSIZ);
528 + strlcpy(b, meta->vol, BUFSIZ);
532 529
533 - if (m->arch) {
530 + if (meta->arch) {
534 531 strlcat(b, " (", BUFSIZ);
535 - strlcat(b, m->arch, BUFSIZ);
532 + strlcat(b, meta->arch, BUFSIZ);
536 533 strlcat(b, ")", BUFSIZ);
537 534 }
538 535
539 - snprintf(title, BUFSIZ - 1, "%s(%s)", m->title, m->msec);
536 + snprintf(title, BUFSIZ - 1, "%s(%s)", meta->title, meta->msec);
540 537
541 538 PAIR_SUMMARY_INIT(&tag[0], "Document Header");
542 539 PAIR_CLASS_INIT(&tag[1], "head");
543 540 PAIR_INIT(&tag[2], ATTR_WIDTH, "100%");
544 541 t = print_otag(h, TAG_TABLE, 3, tag);
545 542 PAIR_INIT(&tag[0], ATTR_WIDTH, "30%");
546 543 print_otag(h, TAG_COL, 1, tag);
547 544 print_otag(h, TAG_COL, 1, tag);
548 545 print_otag(h, TAG_COL, 1, tag);
549 546
550 547 print_otag(h, TAG_TBODY, 0, NULL);
551 548
552 549 tt = print_otag(h, TAG_TR, 0, NULL);
553 550
554 551 PAIR_CLASS_INIT(&tag[0], "head-ltitle");
555 552 print_otag(h, TAG_TD, 1, tag);
556 553 print_text(h, title);
557 554 print_stagq(h, tt);
558 555
559 556 PAIR_CLASS_INIT(&tag[0], "head-vol");
560 557 PAIR_INIT(&tag[1], ATTR_ALIGN, "center");
561 558 print_otag(h, TAG_TD, 2, tag);
562 559 print_text(h, b);
563 560 print_stagq(h, tt);
564 561
565 562 PAIR_CLASS_INIT(&tag[0], "head-rtitle");
566 563 PAIR_INIT(&tag[1], ATTR_ALIGN, "right");
567 564 print_otag(h, TAG_TD, 2, tag);
568 565 print_text(h, title);
569 566 print_tagq(h, t);
570 567 return(1);
571 568 }
572 569
573 570
574 571 /* ARGSUSED */
575 572 static int
576 573 mdoc_sh_pre(MDOC_ARGS)
577 574 {
578 575 struct htmlpair tag;
579 576
580 577 if (MDOC_BLOCK == n->type) {
581 578 PAIR_CLASS_INIT(&tag, "section");
582 579 print_otag(h, TAG_DIV, 1, &tag);
583 580 return(1);
584 581 } else if (MDOC_BODY == n->type)
585 582 return(1);
586 583
587 584 bufinit(h);
588 585 bufcat(h, "x");
589 586
590 587 for (n = n->child; n && MDOC_TEXT == n->type; ) {
591 588 bufcat_id(h, n->string);
592 589 if (NULL != (n = n->next))
593 590 bufcat_id(h, " ");
594 591 }
595 592
596 593 if (NULL == n) {
597 594 PAIR_ID_INIT(&tag, h->buf);
598 595 print_otag(h, TAG_H1, 1, &tag);
599 596 } else
600 597 print_otag(h, TAG_H1, 0, NULL);
601 598
602 599 return(1);
603 600 }
604 601
605 602 /* ARGSUSED */
606 603 static int
607 604 mdoc_ss_pre(MDOC_ARGS)
608 605 {
609 606 struct htmlpair tag;
610 607
611 608 if (MDOC_BLOCK == n->type) {
612 609 PAIR_CLASS_INIT(&tag, "subsection");
613 610 print_otag(h, TAG_DIV, 1, &tag);
614 611 return(1);
615 612 } else if (MDOC_BODY == n->type)
616 613 return(1);
617 614
618 615 bufinit(h);
619 616 bufcat(h, "x");
620 617
621 618 for (n = n->child; n && MDOC_TEXT == n->type; ) {
622 619 bufcat_id(h, n->string);
623 620 if (NULL != (n = n->next))
624 621 bufcat_id(h, " ");
625 622 }
626 623
627 624 if (NULL == n) {
628 625 PAIR_ID_INIT(&tag, h->buf);
629 626 print_otag(h, TAG_H2, 1, &tag);
630 627 } else
631 628 print_otag(h, TAG_H2, 0, NULL);
632 629
633 630 return(1);
634 631 }
635 632
636 633
637 634 /* ARGSUSED */
638 635 static int
639 636 mdoc_fl_pre(MDOC_ARGS)
640 637 {
641 638 struct htmlpair tag;
642 639
643 640 PAIR_CLASS_INIT(&tag, "flag");
644 641 print_otag(h, TAG_B, 1, &tag);
645 642
646 643 /* `Cm' has no leading hyphen. */
647 644
648 645 if (MDOC_Cm == n->tok)
649 646 return(1);
650 647
651 648 print_text(h, "\\-");
652 649
653 650 if (n->child)
654 651 h->flags |= HTML_NOSPACE;
655 652 else if (n->next && n->next->line == n->line)
656 653 h->flags |= HTML_NOSPACE;
657 654
658 655 return(1);
659 656 }
660 657
661 658
662 659 /* ARGSUSED */
663 660 static int
664 661 mdoc_nd_pre(MDOC_ARGS)
665 662 {
666 663 struct htmlpair tag;
667 664
668 665 if (MDOC_BODY != n->type)
669 666 return(1);
670 667
671 668 /* XXX: this tag in theory can contain block elements. */
672 669
673 670 print_text(h, "\\(em");
674 671 PAIR_CLASS_INIT(&tag, "desc");
675 672 print_otag(h, TAG_SPAN, 1, &tag);
676 673 return(1);
677 674 }
678 675
679 676
680 677 static int
681 678 mdoc_nm_pre(MDOC_ARGS)
↓ open down ↓ |
132 lines elided |
↑ open up ↑ |
682 679 {
683 680 struct htmlpair tag;
684 681 struct roffsu su;
685 682 int len;
686 683
687 684 switch (n->type) {
688 685 case (MDOC_ELEM):
689 686 synopsis_pre(h, n);
690 687 PAIR_CLASS_INIT(&tag, "name");
691 688 print_otag(h, TAG_B, 1, &tag);
692 - if (NULL == n->child && m->name)
693 - print_text(h, m->name);
689 + if (NULL == n->child && meta->name)
690 + print_text(h, meta->name);
694 691 return(1);
695 692 case (MDOC_HEAD):
696 693 print_otag(h, TAG_TD, 0, NULL);
697 - if (NULL == n->child && m->name)
698 - print_text(h, m->name);
694 + if (NULL == n->child && meta->name)
695 + print_text(h, meta->name);
699 696 return(1);
700 697 case (MDOC_BODY):
701 698 print_otag(h, TAG_TD, 0, NULL);
702 699 return(1);
703 700 default:
704 701 break;
705 702 }
706 703
707 704 synopsis_pre(h, n);
708 705 PAIR_CLASS_INIT(&tag, "synopsis");
709 706 print_otag(h, TAG_TABLE, 1, &tag);
710 707
711 708 for (len = 0, n = n->child; n; n = n->next)
712 709 if (MDOC_TEXT == n->type)
713 710 len += html_strlen(n->string);
714 711
715 - if (0 == len && m->name)
716 - len = html_strlen(m->name);
712 + if (0 == len && meta->name)
713 + len = html_strlen(meta->name);
717 714
718 715 SCALE_HS_INIT(&su, (double)len);
719 716 bufinit(h);
720 717 bufcat_su(h, "width", &su);
721 718 PAIR_STYLE_INIT(&tag, h);
722 719 print_otag(h, TAG_COL, 1, &tag);
723 720 print_otag(h, TAG_COL, 0, NULL);
724 721 print_otag(h, TAG_TBODY, 0, NULL);
725 722 print_otag(h, TAG_TR, 0, NULL);
726 723 return(1);
727 724 }
728 725
729 726
730 727 /* ARGSUSED */
731 728 static int
732 729 mdoc_xr_pre(MDOC_ARGS)
733 730 {
734 731 struct htmlpair tag[2];
735 732
736 733 if (NULL == n->child)
737 734 return(0);
738 735
739 736 PAIR_CLASS_INIT(&tag[0], "link-man");
740 737
741 738 if (h->base_man) {
742 739 buffmt_man(h, n->child->string,
743 740 n->child->next ?
744 741 n->child->next->string : NULL);
745 742 PAIR_HREF_INIT(&tag[1], h->buf);
746 743 print_otag(h, TAG_A, 2, tag);
747 744 } else
748 745 print_otag(h, TAG_A, 1, tag);
749 746
750 747 n = n->child;
751 748 print_text(h, n->string);
752 749
753 750 if (NULL == (n = n->next))
754 751 return(0);
755 752
756 753 h->flags |= HTML_NOSPACE;
757 754 print_text(h, "(");
758 755 h->flags |= HTML_NOSPACE;
759 756 print_text(h, n->string);
760 757 h->flags |= HTML_NOSPACE;
761 758 print_text(h, ")");
762 759 return(0);
763 760 }
764 761
765 762
766 763 /* ARGSUSED */
767 764 static int
768 765 mdoc_ns_pre(MDOC_ARGS)
769 766 {
770 767
771 768 if ( ! (MDOC_LINE & n->flags))
772 769 h->flags |= HTML_NOSPACE;
773 770 return(1);
774 771 }
775 772
776 773
777 774 /* ARGSUSED */
778 775 static int
779 776 mdoc_ar_pre(MDOC_ARGS)
780 777 {
781 778 struct htmlpair tag;
782 779
783 780 PAIR_CLASS_INIT(&tag, "arg");
784 781 print_otag(h, TAG_I, 1, &tag);
785 782 return(1);
786 783 }
787 784
788 785
789 786 /* ARGSUSED */
790 787 static int
791 788 mdoc_xx_pre(MDOC_ARGS)
792 789 {
793 790 const char *pp;
794 791 struct htmlpair tag;
795 792 int flags;
796 793
797 794 switch (n->tok) {
798 795 case (MDOC_Bsx):
799 796 pp = "BSD/OS";
800 797 break;
801 798 case (MDOC_Dx):
802 799 pp = "DragonFly";
803 800 break;
804 801 case (MDOC_Fx):
805 802 pp = "FreeBSD";
806 803 break;
807 804 case (MDOC_Nx):
808 805 pp = "NetBSD";
809 806 break;
810 807 case (MDOC_Ox):
811 808 pp = "OpenBSD";
812 809 break;
813 810 case (MDOC_Ux):
814 811 pp = "UNIX";
815 812 break;
816 813 default:
817 814 return(1);
818 815 }
819 816
820 817 PAIR_CLASS_INIT(&tag, "unix");
821 818 print_otag(h, TAG_SPAN, 1, &tag);
822 819
823 820 print_text(h, pp);
824 821 if (n->child) {
825 822 flags = h->flags;
826 823 h->flags |= HTML_KEEP;
827 824 print_text(h, n->child->string);
828 825 h->flags = flags;
829 826 }
830 827 return(0);
831 828 }
832 829
833 830
834 831 /* ARGSUSED */
835 832 static int
836 833 mdoc_bx_pre(MDOC_ARGS)
837 834 {
838 835 struct htmlpair tag;
839 836
840 837 PAIR_CLASS_INIT(&tag, "unix");
841 838 print_otag(h, TAG_SPAN, 1, &tag);
842 839
843 840 if (NULL != (n = n->child)) {
844 841 print_text(h, n->string);
845 842 h->flags |= HTML_NOSPACE;
846 843 print_text(h, "BSD");
847 844 } else {
848 845 print_text(h, "BSD");
849 846 return(0);
850 847 }
851 848
852 849 if (NULL != (n = n->next)) {
853 850 h->flags |= HTML_NOSPACE;
854 851 print_text(h, "-");
855 852 h->flags |= HTML_NOSPACE;
856 853 print_text(h, n->string);
857 854 }
858 855
859 856 return(0);
860 857 }
861 858
862 859 /* ARGSUSED */
863 860 static int
864 861 mdoc_it_pre(MDOC_ARGS)
865 862 {
866 863 struct roffsu su;
867 864 enum mdoc_list type;
868 865 struct htmlpair tag[2];
869 866 const struct mdoc_node *bl;
870 867
871 868 bl = n->parent;
872 869 while (bl && MDOC_Bl != bl->tok)
873 870 bl = bl->parent;
874 871
875 872 assert(bl);
876 873
877 874 type = bl->norm->Bl.type;
878 875
879 876 assert(lists[type]);
880 877 PAIR_CLASS_INIT(&tag[0], lists[type]);
881 878
882 879 bufinit(h);
883 880
884 881 if (MDOC_HEAD == n->type) {
885 882 switch (type) {
886 883 case(LIST_bullet):
887 884 /* FALLTHROUGH */
888 885 case(LIST_dash):
889 886 /* FALLTHROUGH */
890 887 case(LIST_item):
891 888 /* FALLTHROUGH */
892 889 case(LIST_hyphen):
893 890 /* FALLTHROUGH */
894 891 case(LIST_enum):
895 892 return(0);
896 893 case(LIST_diag):
897 894 /* FALLTHROUGH */
898 895 case(LIST_hang):
899 896 /* FALLTHROUGH */
900 897 case(LIST_inset):
901 898 /* FALLTHROUGH */
902 899 case(LIST_ohang):
903 900 /* FALLTHROUGH */
904 901 case(LIST_tag):
905 902 SCALE_VS_INIT(&su, ! bl->norm->Bl.comp);
906 903 bufcat_su(h, "margin-top", &su);
907 904 PAIR_STYLE_INIT(&tag[1], h);
908 905 print_otag(h, TAG_DT, 2, tag);
909 906 if (LIST_diag != type)
910 907 break;
911 908 PAIR_CLASS_INIT(&tag[0], "diag");
912 909 print_otag(h, TAG_B, 1, tag);
913 910 break;
914 911 case(LIST_column):
915 912 break;
916 913 default:
917 914 break;
918 915 }
919 916 } else if (MDOC_BODY == n->type) {
920 917 switch (type) {
921 918 case(LIST_bullet):
922 919 /* FALLTHROUGH */
923 920 case(LIST_hyphen):
924 921 /* FALLTHROUGH */
925 922 case(LIST_dash):
926 923 /* FALLTHROUGH */
927 924 case(LIST_enum):
928 925 /* FALLTHROUGH */
929 926 case(LIST_item):
930 927 SCALE_VS_INIT(&su, ! bl->norm->Bl.comp);
931 928 bufcat_su(h, "margin-top", &su);
932 929 PAIR_STYLE_INIT(&tag[1], h);
933 930 print_otag(h, TAG_LI, 2, tag);
934 931 break;
935 932 case(LIST_diag):
936 933 /* FALLTHROUGH */
937 934 case(LIST_hang):
938 935 /* FALLTHROUGH */
939 936 case(LIST_inset):
940 937 /* FALLTHROUGH */
941 938 case(LIST_ohang):
942 939 /* FALLTHROUGH */
943 940 case(LIST_tag):
944 941 if (NULL == bl->norm->Bl.width) {
945 942 print_otag(h, TAG_DD, 1, tag);
946 943 break;
947 944 }
948 945 a2width(bl->norm->Bl.width, &su);
949 946 bufcat_su(h, "margin-left", &su);
950 947 PAIR_STYLE_INIT(&tag[1], h);
951 948 print_otag(h, TAG_DD, 2, tag);
952 949 break;
953 950 case(LIST_column):
954 951 SCALE_VS_INIT(&su, ! bl->norm->Bl.comp);
955 952 bufcat_su(h, "margin-top", &su);
956 953 PAIR_STYLE_INIT(&tag[1], h);
957 954 print_otag(h, TAG_TD, 2, tag);
958 955 break;
959 956 default:
960 957 break;
961 958 }
962 959 } else {
963 960 switch (type) {
964 961 case (LIST_column):
965 962 print_otag(h, TAG_TR, 1, tag);
966 963 break;
967 964 default:
968 965 break;
969 966 }
970 967 }
971 968
972 969 return(1);
973 970 }
↓ open down ↓ |
247 lines elided |
↑ open up ↑ |
974 971
975 972 /* ARGSUSED */
976 973 static int
977 974 mdoc_bl_pre(MDOC_ARGS)
978 975 {
979 976 int i;
980 977 struct htmlpair tag[3];
981 978 struct roffsu su;
982 979 char buf[BUFSIZ];
983 980
984 - bufinit(h);
985 -
986 981 if (MDOC_BODY == n->type) {
987 982 if (LIST_column == n->norm->Bl.type)
988 983 print_otag(h, TAG_TBODY, 0, NULL);
989 984 return(1);
990 985 }
991 986
992 987 if (MDOC_HEAD == n->type) {
993 988 if (LIST_column != n->norm->Bl.type)
994 989 return(0);
995 990
996 991 /*
997 992 * For each column, print out the <COL> tag with our
998 993 * suggested width. The last column gets min-width, as
999 994 * in terminal mode it auto-sizes to the width of the
1000 995 * screen and we want to preserve that behaviour.
1001 996 */
1002 997
1003 998 for (i = 0; i < (int)n->norm->Bl.ncols; i++) {
999 + bufinit(h);
1004 1000 a2width(n->norm->Bl.cols[i], &su);
1005 1001 if (i < (int)n->norm->Bl.ncols - 1)
1006 1002 bufcat_su(h, "width", &su);
1007 1003 else
1008 1004 bufcat_su(h, "min-width", &su);
1009 1005 PAIR_STYLE_INIT(&tag[0], h);
1010 1006 print_otag(h, TAG_COL, 1, tag);
1011 1007 }
1012 1008
1013 1009 return(0);
1014 1010 }
1015 1011
1016 1012 SCALE_VS_INIT(&su, 0);
1013 + bufinit(h);
1017 1014 bufcat_su(h, "margin-top", &su);
1018 1015 bufcat_su(h, "margin-bottom", &su);
1019 1016 PAIR_STYLE_INIT(&tag[0], h);
1020 1017
1021 1018 assert(lists[n->norm->Bl.type]);
1022 1019 strlcpy(buf, "list ", BUFSIZ);
1023 1020 strlcat(buf, lists[n->norm->Bl.type], BUFSIZ);
1024 1021 PAIR_INIT(&tag[1], ATTR_CLASS, buf);
1025 1022
1026 1023 /* Set the block's left-hand margin. */
1027 1024
1028 1025 if (n->norm->Bl.offs) {
1029 1026 a2offs(n->norm->Bl.offs, &su);
1030 1027 bufcat_su(h, "margin-left", &su);
1031 1028 }
1032 1029
1033 1030 switch (n->norm->Bl.type) {
1034 1031 case(LIST_bullet):
1035 1032 /* FALLTHROUGH */
1036 1033 case(LIST_dash):
1037 1034 /* FALLTHROUGH */
1038 1035 case(LIST_hyphen):
1039 1036 /* FALLTHROUGH */
1040 1037 case(LIST_item):
1041 1038 print_otag(h, TAG_UL, 2, tag);
1042 1039 break;
1043 1040 case(LIST_enum):
1044 1041 print_otag(h, TAG_OL, 2, tag);
1045 1042 break;
1046 1043 case(LIST_diag):
1047 1044 /* FALLTHROUGH */
1048 1045 case(LIST_hang):
1049 1046 /* FALLTHROUGH */
1050 1047 case(LIST_inset):
1051 1048 /* FALLTHROUGH */
1052 1049 case(LIST_ohang):
1053 1050 /* FALLTHROUGH */
1054 1051 case(LIST_tag):
1055 1052 print_otag(h, TAG_DL, 2, tag);
1056 1053 break;
1057 1054 case(LIST_column):
1058 1055 print_otag(h, TAG_TABLE, 2, tag);
1059 1056 break;
1060 1057 default:
1061 1058 abort();
1062 1059 /* NOTREACHED */
1063 1060 }
1064 1061
1065 1062 return(1);
1066 1063 }
1067 1064
1068 1065 /* ARGSUSED */
1069 1066 static int
1070 1067 mdoc_ex_pre(MDOC_ARGS)
1071 1068 {
1072 1069 struct tag *t;
1073 1070 struct htmlpair tag;
1074 1071 int nchild;
1075 1072
1076 1073 if (n->prev)
1077 1074 print_otag(h, TAG_BR, 0, NULL);
1078 1075
1079 1076 PAIR_CLASS_INIT(&tag, "utility");
1080 1077
1081 1078 print_text(h, "The");
1082 1079
1083 1080 nchild = n->nchild;
1084 1081 for (n = n->child; n; n = n->next) {
1085 1082 assert(MDOC_TEXT == n->type);
1086 1083
1087 1084 t = print_otag(h, TAG_B, 1, &tag);
1088 1085 print_text(h, n->string);
1089 1086 print_tagq(h, t);
1090 1087
1091 1088 if (nchild > 2 && n->next) {
1092 1089 h->flags |= HTML_NOSPACE;
1093 1090 print_text(h, ",");
1094 1091 }
1095 1092
1096 1093 if (n->next && NULL == n->next->next)
1097 1094 print_text(h, "and");
1098 1095 }
1099 1096
1100 1097 if (nchild > 1)
1101 1098 print_text(h, "utilities exit");
1102 1099 else
1103 1100 print_text(h, "utility exits");
1104 1101
1105 1102 print_text(h, "0 on success, and >0 if an error occurs.");
1106 1103 return(0);
1107 1104 }
1108 1105
1109 1106
1110 1107 /* ARGSUSED */
1111 1108 static int
1112 1109 mdoc_em_pre(MDOC_ARGS)
1113 1110 {
1114 1111 struct htmlpair tag;
1115 1112
1116 1113 PAIR_CLASS_INIT(&tag, "emph");
1117 1114 print_otag(h, TAG_SPAN, 1, &tag);
1118 1115 return(1);
1119 1116 }
1120 1117
1121 1118
1122 1119 /* ARGSUSED */
1123 1120 static int
1124 1121 mdoc_d1_pre(MDOC_ARGS)
1125 1122 {
1126 1123 struct htmlpair tag[2];
1127 1124 struct roffsu su;
1128 1125
1129 1126 if (MDOC_BLOCK != n->type)
1130 1127 return(1);
1131 1128
1132 1129 SCALE_VS_INIT(&su, 0);
1133 1130 bufinit(h);
1134 1131 bufcat_su(h, "margin-top", &su);
1135 1132 bufcat_su(h, "margin-bottom", &su);
1136 1133 PAIR_STYLE_INIT(&tag[0], h);
1137 1134 print_otag(h, TAG_BLOCKQUOTE, 1, tag);
1138 1135
1139 1136 /* BLOCKQUOTE needs a block body. */
1140 1137
1141 1138 PAIR_CLASS_INIT(&tag[0], "display");
1142 1139 print_otag(h, TAG_DIV, 1, tag);
1143 1140
1144 1141 if (MDOC_Dl == n->tok) {
1145 1142 PAIR_CLASS_INIT(&tag[0], "lit");
1146 1143 print_otag(h, TAG_CODE, 1, tag);
1147 1144 }
1148 1145
1149 1146 return(1);
1150 1147 }
1151 1148
1152 1149
1153 1150 /* ARGSUSED */
1154 1151 static int
1155 1152 mdoc_sx_pre(MDOC_ARGS)
1156 1153 {
1157 1154 struct htmlpair tag[2];
1158 1155
1159 1156 bufinit(h);
1160 1157 bufcat(h, "#x");
1161 1158
1162 1159 for (n = n->child; n; ) {
1163 1160 bufcat_id(h, n->string);
1164 1161 if (NULL != (n = n->next))
1165 1162 bufcat_id(h, " ");
1166 1163 }
1167 1164
1168 1165 PAIR_CLASS_INIT(&tag[0], "link-sec");
1169 1166 PAIR_HREF_INIT(&tag[1], h->buf);
1170 1167
1171 1168 print_otag(h, TAG_I, 1, tag);
1172 1169 print_otag(h, TAG_A, 2, tag);
1173 1170 return(1);
1174 1171 }
1175 1172
1176 1173
1177 1174 /* ARGSUSED */
1178 1175 static int
1179 1176 mdoc_bd_pre(MDOC_ARGS)
1180 1177 {
1181 1178 struct htmlpair tag[2];
1182 1179 int comp, sv;
1183 1180 const struct mdoc_node *nn;
1184 1181 struct roffsu su;
1185 1182
1186 1183 if (MDOC_HEAD == n->type)
1187 1184 return(0);
1188 1185
1189 1186 if (MDOC_BLOCK == n->type) {
1190 1187 comp = n->norm->Bd.comp;
1191 1188 for (nn = n; nn && ! comp; nn = nn->parent) {
1192 1189 if (MDOC_BLOCK != nn->type)
1193 1190 continue;
1194 1191 if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
1195 1192 comp = 1;
1196 1193 if (nn->prev)
1197 1194 break;
1198 1195 }
1199 1196 if ( ! comp)
1200 1197 print_otag(h, TAG_P, 0, NULL);
1201 1198 return(1);
1202 1199 }
1203 1200
1204 1201 SCALE_HS_INIT(&su, 0);
1205 1202 if (n->norm->Bd.offs)
1206 1203 a2offs(n->norm->Bd.offs, &su);
1207 1204
1208 1205 bufinit(h);
1209 1206 bufcat_su(h, "margin-left", &su);
1210 1207 PAIR_STYLE_INIT(&tag[0], h);
1211 1208
1212 1209 if (DISP_unfilled != n->norm->Bd.type &&
1213 1210 DISP_literal != n->norm->Bd.type) {
1214 1211 PAIR_CLASS_INIT(&tag[1], "display");
1215 1212 print_otag(h, TAG_DIV, 2, tag);
1216 1213 return(1);
1217 1214 }
↓ open down ↓ |
191 lines elided |
↑ open up ↑ |
1218 1215
1219 1216 PAIR_CLASS_INIT(&tag[1], "lit display");
1220 1217 print_otag(h, TAG_PRE, 2, tag);
1221 1218
1222 1219 /* This can be recursive: save & set our literal state. */
1223 1220
1224 1221 sv = h->flags & HTML_LITERAL;
1225 1222 h->flags |= HTML_LITERAL;
1226 1223
1227 1224 for (nn = n->child; nn; nn = nn->next) {
1228 - print_mdoc_node(m, nn, h);
1225 + print_mdoc_node(meta, nn, h);
1229 1226 /*
1230 1227 * If the printed node flushes its own line, then we
1231 1228 * needn't do it here as well. This is hacky, but the
1232 1229 * notion of selective eoln whitespace is pretty dumb
1233 1230 * anyway, so don't sweat it.
1234 1231 */
1235 1232 switch (nn->tok) {
1236 1233 case (MDOC_Sm):
1237 1234 /* FALLTHROUGH */
1238 1235 case (MDOC_br):
1239 1236 /* FALLTHROUGH */
1240 1237 case (MDOC_sp):
1241 1238 /* FALLTHROUGH */
1242 1239 case (MDOC_Bl):
1243 1240 /* FALLTHROUGH */
1244 1241 case (MDOC_D1):
1245 1242 /* FALLTHROUGH */
1246 1243 case (MDOC_Dl):
1247 1244 /* FALLTHROUGH */
1248 1245 case (MDOC_Lp):
1249 1246 /* FALLTHROUGH */
1250 1247 case (MDOC_Pp):
1251 1248 continue;
1252 1249 default:
1253 1250 break;
1254 1251 }
1255 1252 if (nn->next && nn->next->line == nn->line)
1256 1253 continue;
1257 1254 else if (nn->next)
1258 1255 print_text(h, "\n");
1259 1256
1260 1257 h->flags |= HTML_NOSPACE;
1261 1258 }
1262 1259
1263 1260 if (0 == sv)
1264 1261 h->flags &= ~HTML_LITERAL;
1265 1262
1266 1263 return(0);
1267 1264 }
1268 1265
1269 1266
1270 1267 /* ARGSUSED */
1271 1268 static int
1272 1269 mdoc_pa_pre(MDOC_ARGS)
1273 1270 {
1274 1271 struct htmlpair tag;
1275 1272
1276 1273 PAIR_CLASS_INIT(&tag, "file");
1277 1274 print_otag(h, TAG_I, 1, &tag);
1278 1275 return(1);
1279 1276 }
1280 1277
1281 1278
1282 1279 /* ARGSUSED */
1283 1280 static int
1284 1281 mdoc_ad_pre(MDOC_ARGS)
1285 1282 {
1286 1283 struct htmlpair tag;
1287 1284
1288 1285 PAIR_CLASS_INIT(&tag, "addr");
1289 1286 print_otag(h, TAG_I, 1, &tag);
1290 1287 return(1);
1291 1288 }
1292 1289
1293 1290
1294 1291 /* ARGSUSED */
1295 1292 static int
1296 1293 mdoc_an_pre(MDOC_ARGS)
1297 1294 {
1298 1295 struct htmlpair tag;
1299 1296
1300 1297 /* TODO: -split and -nosplit (see termp_an_pre()). */
1301 1298
1302 1299 PAIR_CLASS_INIT(&tag, "author");
1303 1300 print_otag(h, TAG_SPAN, 1, &tag);
1304 1301 return(1);
1305 1302 }
1306 1303
1307 1304
1308 1305 /* ARGSUSED */
1309 1306 static int
1310 1307 mdoc_cd_pre(MDOC_ARGS)
1311 1308 {
1312 1309 struct htmlpair tag;
1313 1310
1314 1311 synopsis_pre(h, n);
1315 1312 PAIR_CLASS_INIT(&tag, "config");
1316 1313 print_otag(h, TAG_B, 1, &tag);
1317 1314 return(1);
1318 1315 }
1319 1316
1320 1317
1321 1318 /* ARGSUSED */
1322 1319 static int
1323 1320 mdoc_dv_pre(MDOC_ARGS)
1324 1321 {
1325 1322 struct htmlpair tag;
1326 1323
1327 1324 PAIR_CLASS_INIT(&tag, "define");
1328 1325 print_otag(h, TAG_SPAN, 1, &tag);
1329 1326 return(1);
1330 1327 }
1331 1328
1332 1329
1333 1330 /* ARGSUSED */
1334 1331 static int
1335 1332 mdoc_ev_pre(MDOC_ARGS)
1336 1333 {
1337 1334 struct htmlpair tag;
1338 1335
1339 1336 PAIR_CLASS_INIT(&tag, "env");
1340 1337 print_otag(h, TAG_SPAN, 1, &tag);
1341 1338 return(1);
1342 1339 }
1343 1340
1344 1341
1345 1342 /* ARGSUSED */
1346 1343 static int
1347 1344 mdoc_er_pre(MDOC_ARGS)
1348 1345 {
1349 1346 struct htmlpair tag;
1350 1347
1351 1348 PAIR_CLASS_INIT(&tag, "errno");
1352 1349 print_otag(h, TAG_SPAN, 1, &tag);
1353 1350 return(1);
1354 1351 }
1355 1352
1356 1353
1357 1354 /* ARGSUSED */
1358 1355 static int
1359 1356 mdoc_fa_pre(MDOC_ARGS)
1360 1357 {
1361 1358 const struct mdoc_node *nn;
1362 1359 struct htmlpair tag;
1363 1360 struct tag *t;
1364 1361
1365 1362 PAIR_CLASS_INIT(&tag, "farg");
1366 1363 if (n->parent->tok != MDOC_Fo) {
1367 1364 print_otag(h, TAG_I, 1, &tag);
1368 1365 return(1);
1369 1366 }
1370 1367
1371 1368 for (nn = n->child; nn; nn = nn->next) {
1372 1369 t = print_otag(h, TAG_I, 1, &tag);
1373 1370 print_text(h, nn->string);
1374 1371 print_tagq(h, t);
1375 1372 if (nn->next) {
1376 1373 h->flags |= HTML_NOSPACE;
1377 1374 print_text(h, ",");
1378 1375 }
1379 1376 }
1380 1377
1381 1378 if (n->child && n->next && n->next->tok == MDOC_Fa) {
1382 1379 h->flags |= HTML_NOSPACE;
1383 1380 print_text(h, ",");
1384 1381 }
1385 1382
1386 1383 return(0);
1387 1384 }
1388 1385
1389 1386
1390 1387 /* ARGSUSED */
1391 1388 static int
1392 1389 mdoc_fd_pre(MDOC_ARGS)
1393 1390 {
1394 1391 struct htmlpair tag[2];
1395 1392 char buf[BUFSIZ];
1396 1393 size_t sz;
1397 1394 int i;
1398 1395 struct tag *t;
1399 1396
1400 1397 synopsis_pre(h, n);
1401 1398
1402 1399 if (NULL == (n = n->child))
1403 1400 return(0);
1404 1401
1405 1402 assert(MDOC_TEXT == n->type);
1406 1403
1407 1404 if (strcmp(n->string, "#include")) {
1408 1405 PAIR_CLASS_INIT(&tag[0], "macro");
1409 1406 print_otag(h, TAG_B, 1, tag);
1410 1407 return(1);
1411 1408 }
1412 1409
1413 1410 PAIR_CLASS_INIT(&tag[0], "includes");
1414 1411 print_otag(h, TAG_B, 1, tag);
1415 1412 print_text(h, n->string);
1416 1413
1417 1414 if (NULL != (n = n->next)) {
1418 1415 assert(MDOC_TEXT == n->type);
1419 1416 strlcpy(buf, '<' == *n->string || '"' == *n->string ?
1420 1417 n->string + 1 : n->string, BUFSIZ);
1421 1418
1422 1419 sz = strlen(buf);
1423 1420 if (sz && ('>' == buf[sz - 1] || '"' == buf[sz - 1]))
1424 1421 buf[sz - 1] = '\0';
1425 1422
1426 1423 PAIR_CLASS_INIT(&tag[0], "link-includes");
1427 1424
1428 1425 i = 1;
1429 1426 if (h->base_includes) {
1430 1427 buffmt_includes(h, buf);
1431 1428 PAIR_HREF_INIT(&tag[i], h->buf);
1432 1429 i++;
1433 1430 }
1434 1431
1435 1432 t = print_otag(h, TAG_A, i, tag);
1436 1433 print_text(h, n->string);
1437 1434 print_tagq(h, t);
1438 1435
1439 1436 n = n->next;
1440 1437 }
1441 1438
1442 1439 for ( ; n; n = n->next) {
1443 1440 assert(MDOC_TEXT == n->type);
1444 1441 print_text(h, n->string);
1445 1442 }
1446 1443
1447 1444 return(0);
1448 1445 }
1449 1446
1450 1447
1451 1448 /* ARGSUSED */
1452 1449 static int
1453 1450 mdoc_vt_pre(MDOC_ARGS)
1454 1451 {
1455 1452 struct htmlpair tag;
1456 1453
1457 1454 if (MDOC_BLOCK == n->type) {
1458 1455 synopsis_pre(h, n);
1459 1456 return(1);
1460 1457 } else if (MDOC_ELEM == n->type) {
1461 1458 synopsis_pre(h, n);
1462 1459 } else if (MDOC_HEAD == n->type)
1463 1460 return(0);
1464 1461
1465 1462 PAIR_CLASS_INIT(&tag, "type");
1466 1463 print_otag(h, TAG_SPAN, 1, &tag);
1467 1464 return(1);
1468 1465 }
1469 1466
1470 1467
1471 1468 /* ARGSUSED */
1472 1469 static int
1473 1470 mdoc_ft_pre(MDOC_ARGS)
1474 1471 {
1475 1472 struct htmlpair tag;
1476 1473
1477 1474 synopsis_pre(h, n);
1478 1475 PAIR_CLASS_INIT(&tag, "ftype");
1479 1476 print_otag(h, TAG_I, 1, &tag);
1480 1477 return(1);
1481 1478 }
1482 1479
1483 1480
1484 1481 /* ARGSUSED */
1485 1482 static int
1486 1483 mdoc_fn_pre(MDOC_ARGS)
1487 1484 {
1488 1485 struct tag *t;
1489 1486 struct htmlpair tag[2];
1490 1487 char nbuf[BUFSIZ];
1491 1488 const char *sp, *ep;
1492 1489 int sz, i, pretty;
1493 1490
1494 1491 pretty = MDOC_SYNPRETTY & n->flags;
1495 1492 synopsis_pre(h, n);
1496 1493
1497 1494 /* Split apart into type and name. */
1498 1495 assert(n->child->string);
1499 1496 sp = n->child->string;
1500 1497
1501 1498 ep = strchr(sp, ' ');
1502 1499 if (NULL != ep) {
1503 1500 PAIR_CLASS_INIT(&tag[0], "ftype");
1504 1501 t = print_otag(h, TAG_I, 1, tag);
1505 1502
1506 1503 while (ep) {
1507 1504 sz = MIN((int)(ep - sp), BUFSIZ - 1);
1508 1505 (void)memcpy(nbuf, sp, (size_t)sz);
1509 1506 nbuf[sz] = '\0';
1510 1507 print_text(h, nbuf);
1511 1508 sp = ++ep;
1512 1509 ep = strchr(sp, ' ');
1513 1510 }
1514 1511 print_tagq(h, t);
1515 1512 }
1516 1513
1517 1514 PAIR_CLASS_INIT(&tag[0], "fname");
1518 1515
1519 1516 /*
1520 1517 * FIXME: only refer to IDs that we know exist.
1521 1518 */
1522 1519
1523 1520 #if 0
1524 1521 if (MDOC_SYNPRETTY & n->flags) {
1525 1522 nbuf[0] = '\0';
1526 1523 html_idcat(nbuf, sp, BUFSIZ);
1527 1524 PAIR_ID_INIT(&tag[1], nbuf);
1528 1525 } else {
1529 1526 strlcpy(nbuf, "#", BUFSIZ);
1530 1527 html_idcat(nbuf, sp, BUFSIZ);
1531 1528 PAIR_HREF_INIT(&tag[1], nbuf);
1532 1529 }
1533 1530 #endif
1534 1531
1535 1532 t = print_otag(h, TAG_B, 1, tag);
1536 1533
1537 1534 if (sp) {
1538 1535 strlcpy(nbuf, sp, BUFSIZ);
1539 1536 print_text(h, nbuf);
1540 1537 }
1541 1538
1542 1539 print_tagq(h, t);
1543 1540
1544 1541 h->flags |= HTML_NOSPACE;
1545 1542 print_text(h, "(");
1546 1543 h->flags |= HTML_NOSPACE;
1547 1544
1548 1545 PAIR_CLASS_INIT(&tag[0], "farg");
1549 1546 bufinit(h);
1550 1547 bufcat_style(h, "white-space", "nowrap");
1551 1548 PAIR_STYLE_INIT(&tag[1], h);
1552 1549
1553 1550 for (n = n->child->next; n; n = n->next) {
1554 1551 i = 1;
1555 1552 if (MDOC_SYNPRETTY & n->flags)
1556 1553 i = 2;
1557 1554 t = print_otag(h, TAG_I, i, tag);
1558 1555 print_text(h, n->string);
1559 1556 print_tagq(h, t);
1560 1557 if (n->next) {
1561 1558 h->flags |= HTML_NOSPACE;
1562 1559 print_text(h, ",");
1563 1560 }
1564 1561 }
1565 1562
1566 1563 h->flags |= HTML_NOSPACE;
1567 1564 print_text(h, ")");
1568 1565
1569 1566 if (pretty) {
1570 1567 h->flags |= HTML_NOSPACE;
1571 1568 print_text(h, ";");
1572 1569 }
1573 1570
1574 1571 return(0);
1575 1572 }
1576 1573
1577 1574
1578 1575 /* ARGSUSED */
1579 1576 static int
1580 1577 mdoc_sm_pre(MDOC_ARGS)
1581 1578 {
1582 1579
1583 1580 assert(n->child && MDOC_TEXT == n->child->type);
1584 1581 if (0 == strcmp("on", n->child->string)) {
1585 1582 /*
1586 1583 * FIXME: no p->col to check. Thus, if we have
1587 1584 * .Bd -literal
1588 1585 * .Sm off
1589 1586 * 1 2
1590 1587 * .Sm on
1591 1588 * 3
1592 1589 * .Ed
1593 1590 * the "3" is preceded by a space.
1594 1591 */
1595 1592 h->flags &= ~HTML_NOSPACE;
1596 1593 h->flags &= ~HTML_NONOSPACE;
1597 1594 } else
1598 1595 h->flags |= HTML_NONOSPACE;
1599 1596
1600 1597 return(0);
1601 1598 }
1602 1599
1603 1600 /* ARGSUSED */
1604 1601 static int
1605 1602 mdoc_pp_pre(MDOC_ARGS)
1606 1603 {
1607 1604
1608 1605 print_otag(h, TAG_P, 0, NULL);
1609 1606 return(0);
1610 1607
1611 1608 }
1612 1609
1613 1610 /* ARGSUSED */
1614 1611 static int
1615 1612 mdoc_sp_pre(MDOC_ARGS)
1616 1613 {
1617 1614 struct roffsu su;
1618 1615 struct htmlpair tag;
1619 1616
1620 1617 SCALE_VS_INIT(&su, 1);
1621 1618
1622 1619 if (MDOC_sp == n->tok) {
1623 1620 if (NULL != (n = n->child))
1624 1621 if ( ! a2roffsu(n->string, &su, SCALE_VS))
1625 1622 SCALE_VS_INIT(&su, atoi(n->string));
1626 1623 } else
1627 1624 su.scale = 0;
1628 1625
1629 1626 bufinit(h);
1630 1627 bufcat_su(h, "height", &su);
1631 1628 PAIR_STYLE_INIT(&tag, h);
1632 1629 print_otag(h, TAG_DIV, 1, &tag);
1633 1630
1634 1631 /* So the div isn't empty: */
1635 1632 print_text(h, "\\~");
1636 1633
1637 1634 return(0);
1638 1635
1639 1636 }
1640 1637
1641 1638 /* ARGSUSED */
1642 1639 static int
1643 1640 mdoc_lk_pre(MDOC_ARGS)
1644 1641 {
1645 1642 struct htmlpair tag[2];
1646 1643
1647 1644 if (NULL == (n = n->child))
1648 1645 return(0);
1649 1646
1650 1647 assert(MDOC_TEXT == n->type);
1651 1648
1652 1649 PAIR_CLASS_INIT(&tag[0], "link-ext");
1653 1650 PAIR_HREF_INIT(&tag[1], n->string);
1654 1651
1655 1652 print_otag(h, TAG_A, 2, tag);
1656 1653
1657 1654 if (NULL == n->next)
1658 1655 print_text(h, n->string);
1659 1656
1660 1657 for (n = n->next; n; n = n->next)
1661 1658 print_text(h, n->string);
1662 1659
1663 1660 return(0);
1664 1661 }
1665 1662
1666 1663
1667 1664 /* ARGSUSED */
1668 1665 static int
1669 1666 mdoc_mt_pre(MDOC_ARGS)
1670 1667 {
1671 1668 struct htmlpair tag[2];
1672 1669 struct tag *t;
1673 1670
1674 1671 PAIR_CLASS_INIT(&tag[0], "link-mail");
1675 1672
1676 1673 for (n = n->child; n; n = n->next) {
1677 1674 assert(MDOC_TEXT == n->type);
1678 1675
1679 1676 bufinit(h);
1680 1677 bufcat(h, "mailto:");
1681 1678 bufcat(h, n->string);
1682 1679
1683 1680 PAIR_HREF_INIT(&tag[1], h->buf);
1684 1681 t = print_otag(h, TAG_A, 2, tag);
1685 1682 print_text(h, n->string);
1686 1683 print_tagq(h, t);
1687 1684 }
1688 1685
1689 1686 return(0);
1690 1687 }
1691 1688
1692 1689
1693 1690 /* ARGSUSED */
1694 1691 static int
1695 1692 mdoc_fo_pre(MDOC_ARGS)
1696 1693 {
1697 1694 struct htmlpair tag;
1698 1695 struct tag *t;
1699 1696
1700 1697 if (MDOC_BODY == n->type) {
1701 1698 h->flags |= HTML_NOSPACE;
1702 1699 print_text(h, "(");
1703 1700 h->flags |= HTML_NOSPACE;
1704 1701 return(1);
1705 1702 } else if (MDOC_BLOCK == n->type) {
1706 1703 synopsis_pre(h, n);
1707 1704 return(1);
1708 1705 }
1709 1706
1710 1707 /* XXX: we drop non-initial arguments as per groff. */
1711 1708
1712 1709 assert(n->child);
1713 1710 assert(n->child->string);
1714 1711
1715 1712 PAIR_CLASS_INIT(&tag, "fname");
1716 1713 t = print_otag(h, TAG_B, 1, &tag);
1717 1714 print_text(h, n->child->string);
1718 1715 print_tagq(h, t);
1719 1716 return(0);
1720 1717 }
1721 1718
1722 1719
1723 1720 /* ARGSUSED */
1724 1721 static void
1725 1722 mdoc_fo_post(MDOC_ARGS)
1726 1723 {
1727 1724
1728 1725 if (MDOC_BODY != n->type)
1729 1726 return;
1730 1727 h->flags |= HTML_NOSPACE;
1731 1728 print_text(h, ")");
1732 1729 h->flags |= HTML_NOSPACE;
1733 1730 print_text(h, ";");
1734 1731 }
1735 1732
1736 1733
1737 1734 /* ARGSUSED */
1738 1735 static int
1739 1736 mdoc_in_pre(MDOC_ARGS)
1740 1737 {
1741 1738 struct tag *t;
1742 1739 struct htmlpair tag[2];
1743 1740 int i;
1744 1741
1745 1742 synopsis_pre(h, n);
1746 1743
1747 1744 PAIR_CLASS_INIT(&tag[0], "includes");
1748 1745 print_otag(h, TAG_B, 1, tag);
1749 1746
1750 1747 /*
1751 1748 * The first argument of the `In' gets special treatment as
1752 1749 * being a linked value. Subsequent values are printed
1753 1750 * afterward. groff does similarly. This also handles the case
1754 1751 * of no children.
1755 1752 */
1756 1753
1757 1754 if (MDOC_SYNPRETTY & n->flags && MDOC_LINE & n->flags)
1758 1755 print_text(h, "#include");
1759 1756
1760 1757 print_text(h, "<");
1761 1758 h->flags |= HTML_NOSPACE;
1762 1759
1763 1760 if (NULL != (n = n->child)) {
1764 1761 assert(MDOC_TEXT == n->type);
1765 1762
1766 1763 PAIR_CLASS_INIT(&tag[0], "link-includes");
1767 1764
1768 1765 i = 1;
1769 1766 if (h->base_includes) {
1770 1767 buffmt_includes(h, n->string);
1771 1768 PAIR_HREF_INIT(&tag[i], h->buf);
1772 1769 i++;
1773 1770 }
1774 1771
1775 1772 t = print_otag(h, TAG_A, i, tag);
1776 1773 print_text(h, n->string);
1777 1774 print_tagq(h, t);
1778 1775
1779 1776 n = n->next;
1780 1777 }
1781 1778
1782 1779 h->flags |= HTML_NOSPACE;
1783 1780 print_text(h, ">");
1784 1781
1785 1782 for ( ; n; n = n->next) {
1786 1783 assert(MDOC_TEXT == n->type);
1787 1784 print_text(h, n->string);
1788 1785 }
1789 1786
1790 1787 return(0);
1791 1788 }
1792 1789
1793 1790
1794 1791 /* ARGSUSED */
1795 1792 static int
1796 1793 mdoc_ic_pre(MDOC_ARGS)
1797 1794 {
1798 1795 struct htmlpair tag;
1799 1796
1800 1797 PAIR_CLASS_INIT(&tag, "cmd");
1801 1798 print_otag(h, TAG_B, 1, &tag);
1802 1799 return(1);
1803 1800 }
1804 1801
1805 1802
1806 1803 /* ARGSUSED */
1807 1804 static int
1808 1805 mdoc_rv_pre(MDOC_ARGS)
1809 1806 {
1810 1807 struct htmlpair tag;
1811 1808 struct tag *t;
1812 1809 int nchild;
1813 1810
1814 1811 if (n->prev)
1815 1812 print_otag(h, TAG_BR, 0, NULL);
1816 1813
1817 1814 PAIR_CLASS_INIT(&tag, "fname");
1818 1815
1819 1816 print_text(h, "The");
1820 1817
1821 1818 nchild = n->nchild;
1822 1819 for (n = n->child; n; n = n->next) {
1823 1820 assert(MDOC_TEXT == n->type);
1824 1821
1825 1822 t = print_otag(h, TAG_B, 1, &tag);
1826 1823 print_text(h, n->string);
1827 1824 print_tagq(h, t);
1828 1825
1829 1826 h->flags |= HTML_NOSPACE;
1830 1827 print_text(h, "()");
1831 1828
1832 1829 if (nchild > 2 && n->next) {
1833 1830 h->flags |= HTML_NOSPACE;
1834 1831 print_text(h, ",");
1835 1832 }
1836 1833
1837 1834 if (n->next && NULL == n->next->next)
1838 1835 print_text(h, "and");
1839 1836 }
1840 1837
1841 1838 if (nchild > 1)
1842 1839 print_text(h, "functions return");
1843 1840 else
1844 1841 print_text(h, "function returns");
1845 1842
1846 1843 print_text(h, "the value 0 if successful; otherwise the value "
1847 1844 "-1 is returned and the global variable");
1848 1845
1849 1846 PAIR_CLASS_INIT(&tag, "var");
1850 1847 t = print_otag(h, TAG_B, 1, &tag);
1851 1848 print_text(h, "errno");
1852 1849 print_tagq(h, t);
1853 1850 print_text(h, "is set to indicate the error.");
1854 1851 return(0);
1855 1852 }
1856 1853
1857 1854
1858 1855 /* ARGSUSED */
1859 1856 static int
1860 1857 mdoc_va_pre(MDOC_ARGS)
1861 1858 {
1862 1859 struct htmlpair tag;
1863 1860
1864 1861 PAIR_CLASS_INIT(&tag, "var");
1865 1862 print_otag(h, TAG_B, 1, &tag);
1866 1863 return(1);
1867 1864 }
1868 1865
1869 1866
1870 1867 /* ARGSUSED */
1871 1868 static int
1872 1869 mdoc_ap_pre(MDOC_ARGS)
1873 1870 {
1874 1871
1875 1872 h->flags |= HTML_NOSPACE;
1876 1873 print_text(h, "\\(aq");
1877 1874 h->flags |= HTML_NOSPACE;
1878 1875 return(1);
1879 1876 }
1880 1877
1881 1878
1882 1879 /* ARGSUSED */
1883 1880 static int
1884 1881 mdoc_bf_pre(MDOC_ARGS)
1885 1882 {
1886 1883 struct htmlpair tag[2];
1887 1884 struct roffsu su;
1888 1885
1889 1886 if (MDOC_HEAD == n->type)
1890 1887 return(0);
1891 1888 else if (MDOC_BODY != n->type)
1892 1889 return(1);
1893 1890
1894 1891 if (FONT_Em == n->norm->Bf.font)
1895 1892 PAIR_CLASS_INIT(&tag[0], "emph");
1896 1893 else if (FONT_Sy == n->norm->Bf.font)
1897 1894 PAIR_CLASS_INIT(&tag[0], "symb");
1898 1895 else if (FONT_Li == n->norm->Bf.font)
1899 1896 PAIR_CLASS_INIT(&tag[0], "lit");
1900 1897 else
1901 1898 PAIR_CLASS_INIT(&tag[0], "none");
1902 1899
1903 1900 /*
1904 1901 * We want this to be inline-formatted, but needs to be div to
1905 1902 * accept block children.
1906 1903 */
1907 1904 bufinit(h);
1908 1905 bufcat_style(h, "display", "inline");
1909 1906 SCALE_HS_INIT(&su, 1);
1910 1907 /* Needs a left-margin for spacing. */
1911 1908 bufcat_su(h, "margin-left", &su);
1912 1909 PAIR_STYLE_INIT(&tag[1], h);
1913 1910 print_otag(h, TAG_DIV, 2, tag);
1914 1911 return(1);
1915 1912 }
1916 1913
1917 1914
1918 1915 /* ARGSUSED */
1919 1916 static int
1920 1917 mdoc_ms_pre(MDOC_ARGS)
1921 1918 {
1922 1919 struct htmlpair tag;
1923 1920
1924 1921 PAIR_CLASS_INIT(&tag, "symb");
1925 1922 print_otag(h, TAG_SPAN, 1, &tag);
1926 1923 return(1);
1927 1924 }
1928 1925
1929 1926
1930 1927 /* ARGSUSED */
1931 1928 static int
1932 1929 mdoc_igndelim_pre(MDOC_ARGS)
1933 1930 {
1934 1931
1935 1932 h->flags |= HTML_IGNDELIM;
1936 1933 return(1);
1937 1934 }
1938 1935
1939 1936
1940 1937 /* ARGSUSED */
1941 1938 static void
1942 1939 mdoc_pf_post(MDOC_ARGS)
1943 1940 {
1944 1941
1945 1942 h->flags |= HTML_NOSPACE;
1946 1943 }
1947 1944
1948 1945
1949 1946 /* ARGSUSED */
1950 1947 static int
1951 1948 mdoc_rs_pre(MDOC_ARGS)
1952 1949 {
1953 1950 struct htmlpair tag;
1954 1951
1955 1952 if (MDOC_BLOCK != n->type)
1956 1953 return(1);
1957 1954
1958 1955 if (n->prev && SEC_SEE_ALSO == n->sec)
1959 1956 print_otag(h, TAG_P, 0, NULL);
1960 1957
1961 1958 PAIR_CLASS_INIT(&tag, "ref");
1962 1959 print_otag(h, TAG_SPAN, 1, &tag);
1963 1960 return(1);
1964 1961 }
1965 1962
1966 1963
1967 1964
1968 1965 /* ARGSUSED */
1969 1966 static int
1970 1967 mdoc_li_pre(MDOC_ARGS)
1971 1968 {
1972 1969 struct htmlpair tag;
1973 1970
1974 1971 PAIR_CLASS_INIT(&tag, "lit");
1975 1972 print_otag(h, TAG_CODE, 1, &tag);
1976 1973 return(1);
1977 1974 }
1978 1975
1979 1976
1980 1977 /* ARGSUSED */
1981 1978 static int
1982 1979 mdoc_sy_pre(MDOC_ARGS)
1983 1980 {
1984 1981 struct htmlpair tag;
1985 1982
1986 1983 PAIR_CLASS_INIT(&tag, "symb");
1987 1984 print_otag(h, TAG_SPAN, 1, &tag);
1988 1985 return(1);
1989 1986 }
1990 1987
1991 1988
1992 1989 /* ARGSUSED */
1993 1990 static int
1994 1991 mdoc_bt_pre(MDOC_ARGS)
1995 1992 {
1996 1993
1997 1994 print_text(h, "is currently in beta test.");
1998 1995 return(0);
1999 1996 }
2000 1997
2001 1998
2002 1999 /* ARGSUSED */
2003 2000 static int
2004 2001 mdoc_ud_pre(MDOC_ARGS)
2005 2002 {
2006 2003
2007 2004 print_text(h, "currently under development.");
2008 2005 return(0);
2009 2006 }
2010 2007
2011 2008
2012 2009 /* ARGSUSED */
2013 2010 static int
2014 2011 mdoc_lb_pre(MDOC_ARGS)
2015 2012 {
2016 2013 struct htmlpair tag;
2017 2014
2018 2015 if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags && n->prev)
2019 2016 print_otag(h, TAG_BR, 0, NULL);
2020 2017
2021 2018 PAIR_CLASS_INIT(&tag, "lib");
2022 2019 print_otag(h, TAG_SPAN, 1, &tag);
2023 2020 return(1);
2024 2021 }
2025 2022
2026 2023
2027 2024 /* ARGSUSED */
2028 2025 static int
2029 2026 mdoc__x_pre(MDOC_ARGS)
2030 2027 {
2031 2028 struct htmlpair tag[2];
2032 2029 enum htmltag t;
2033 2030
2034 2031 t = TAG_SPAN;
2035 2032
2036 2033 switch (n->tok) {
2037 2034 case(MDOC__A):
2038 2035 PAIR_CLASS_INIT(&tag[0], "ref-auth");
2039 2036 if (n->prev && MDOC__A == n->prev->tok)
2040 2037 if (NULL == n->next || MDOC__A != n->next->tok)
2041 2038 print_text(h, "and");
2042 2039 break;
2043 2040 case(MDOC__B):
2044 2041 PAIR_CLASS_INIT(&tag[0], "ref-book");
2045 2042 t = TAG_I;
2046 2043 break;
2047 2044 case(MDOC__C):
2048 2045 PAIR_CLASS_INIT(&tag[0], "ref-city");
2049 2046 break;
2050 2047 case(MDOC__D):
2051 2048 PAIR_CLASS_INIT(&tag[0], "ref-date");
2052 2049 break;
2053 2050 case(MDOC__I):
2054 2051 PAIR_CLASS_INIT(&tag[0], "ref-issue");
2055 2052 t = TAG_I;
2056 2053 break;
2057 2054 case(MDOC__J):
2058 2055 PAIR_CLASS_INIT(&tag[0], "ref-jrnl");
2059 2056 t = TAG_I;
2060 2057 break;
2061 2058 case(MDOC__N):
2062 2059 PAIR_CLASS_INIT(&tag[0], "ref-num");
2063 2060 break;
2064 2061 case(MDOC__O):
2065 2062 PAIR_CLASS_INIT(&tag[0], "ref-opt");
2066 2063 break;
2067 2064 case(MDOC__P):
2068 2065 PAIR_CLASS_INIT(&tag[0], "ref-page");
2069 2066 break;
2070 2067 case(MDOC__Q):
2071 2068 PAIR_CLASS_INIT(&tag[0], "ref-corp");
2072 2069 break;
2073 2070 case(MDOC__R):
2074 2071 PAIR_CLASS_INIT(&tag[0], "ref-rep");
2075 2072 break;
2076 2073 case(MDOC__T):
2077 2074 PAIR_CLASS_INIT(&tag[0], "ref-title");
2078 2075 break;
2079 2076 case(MDOC__U):
2080 2077 PAIR_CLASS_INIT(&tag[0], "link-ref");
2081 2078 break;
2082 2079 case(MDOC__V):
2083 2080 PAIR_CLASS_INIT(&tag[0], "ref-vol");
2084 2081 break;
2085 2082 default:
2086 2083 abort();
2087 2084 /* NOTREACHED */
2088 2085 }
2089 2086
2090 2087 if (MDOC__U != n->tok) {
2091 2088 print_otag(h, t, 1, tag);
2092 2089 return(1);
2093 2090 }
2094 2091
2095 2092 PAIR_HREF_INIT(&tag[1], n->child->string);
2096 2093 print_otag(h, TAG_A, 2, tag);
2097 2094
2098 2095 return(1);
2099 2096 }
2100 2097
2101 2098
2102 2099 /* ARGSUSED */
2103 2100 static void
2104 2101 mdoc__x_post(MDOC_ARGS)
2105 2102 {
2106 2103
2107 2104 if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok)
2108 2105 if (NULL == n->next->next || MDOC__A != n->next->next->tok)
2109 2106 if (NULL == n->prev || MDOC__A != n->prev->tok)
2110 2107 return;
2111 2108
2112 2109 /* TODO: %U */
2113 2110
2114 2111 if (NULL == n->parent || MDOC_Rs != n->parent->tok)
2115 2112 return;
2116 2113
2117 2114 h->flags |= HTML_NOSPACE;
2118 2115 print_text(h, n->next ? "," : ".");
2119 2116 }
2120 2117
2121 2118
2122 2119 /* ARGSUSED */
2123 2120 static int
2124 2121 mdoc_bk_pre(MDOC_ARGS)
2125 2122 {
2126 2123
2127 2124 switch (n->type) {
2128 2125 case (MDOC_BLOCK):
2129 2126 break;
2130 2127 case (MDOC_HEAD):
2131 2128 return(0);
2132 2129 case (MDOC_BODY):
2133 2130 if (n->parent->args || 0 == n->prev->nchild)
2134 2131 h->flags |= HTML_PREKEEP;
2135 2132 break;
2136 2133 default:
2137 2134 abort();
2138 2135 /* NOTREACHED */
2139 2136 }
2140 2137
2141 2138 return(1);
2142 2139 }
2143 2140
2144 2141
2145 2142 /* ARGSUSED */
2146 2143 static void
2147 2144 mdoc_bk_post(MDOC_ARGS)
2148 2145 {
2149 2146
2150 2147 if (MDOC_BODY == n->type)
2151 2148 h->flags &= ~(HTML_KEEP | HTML_PREKEEP);
2152 2149 }
2153 2150
2154 2151
2155 2152 /* ARGSUSED */
2156 2153 static int
2157 2154 mdoc_quote_pre(MDOC_ARGS)
2158 2155 {
2159 2156 struct htmlpair tag;
2160 2157
2161 2158 if (MDOC_BODY != n->type)
2162 2159 return(1);
2163 2160
2164 2161 switch (n->tok) {
2165 2162 case (MDOC_Ao):
2166 2163 /* FALLTHROUGH */
2167 2164 case (MDOC_Aq):
2168 2165 print_text(h, "\\(la");
2169 2166 break;
2170 2167 case (MDOC_Bro):
2171 2168 /* FALLTHROUGH */
2172 2169 case (MDOC_Brq):
2173 2170 print_text(h, "\\(lC");
2174 2171 break;
2175 2172 case (MDOC_Bo):
2176 2173 /* FALLTHROUGH */
2177 2174 case (MDOC_Bq):
2178 2175 print_text(h, "\\(lB");
2179 2176 break;
2180 2177 case (MDOC_Oo):
2181 2178 /* FALLTHROUGH */
2182 2179 case (MDOC_Op):
2183 2180 print_text(h, "\\(lB");
2184 2181 h->flags |= HTML_NOSPACE;
2185 2182 PAIR_CLASS_INIT(&tag, "opt");
2186 2183 print_otag(h, TAG_SPAN, 1, &tag);
2187 2184 break;
2188 2185 case (MDOC_Eo):
2189 2186 break;
2190 2187 case (MDOC_Do):
2191 2188 /* FALLTHROUGH */
2192 2189 case (MDOC_Dq):
2193 2190 /* FALLTHROUGH */
2194 2191 case (MDOC_Qo):
2195 2192 /* FALLTHROUGH */
2196 2193 case (MDOC_Qq):
2197 2194 print_text(h, "\\(lq");
2198 2195 break;
2199 2196 case (MDOC_Po):
2200 2197 /* FALLTHROUGH */
2201 2198 case (MDOC_Pq):
2202 2199 print_text(h, "(");
2203 2200 break;
2204 2201 case (MDOC_Ql):
2205 2202 print_text(h, "\\(oq");
2206 2203 h->flags |= HTML_NOSPACE;
2207 2204 PAIR_CLASS_INIT(&tag, "lit");
2208 2205 print_otag(h, TAG_CODE, 1, &tag);
2209 2206 break;
2210 2207 case (MDOC_So):
2211 2208 /* FALLTHROUGH */
2212 2209 case (MDOC_Sq):
2213 2210 print_text(h, "\\(oq");
2214 2211 break;
2215 2212 default:
2216 2213 abort();
2217 2214 /* NOTREACHED */
2218 2215 }
2219 2216
2220 2217 h->flags |= HTML_NOSPACE;
2221 2218 return(1);
2222 2219 }
2223 2220
2224 2221
2225 2222 /* ARGSUSED */
2226 2223 static void
2227 2224 mdoc_quote_post(MDOC_ARGS)
2228 2225 {
2229 2226
2230 2227 if (MDOC_BODY != n->type)
2231 2228 return;
2232 2229
2233 2230 h->flags |= HTML_NOSPACE;
2234 2231
2235 2232 switch (n->tok) {
2236 2233 case (MDOC_Ao):
2237 2234 /* FALLTHROUGH */
2238 2235 case (MDOC_Aq):
2239 2236 print_text(h, "\\(ra");
2240 2237 break;
2241 2238 case (MDOC_Bro):
2242 2239 /* FALLTHROUGH */
2243 2240 case (MDOC_Brq):
2244 2241 print_text(h, "\\(rC");
2245 2242 break;
2246 2243 case (MDOC_Oo):
2247 2244 /* FALLTHROUGH */
2248 2245 case (MDOC_Op):
2249 2246 /* FALLTHROUGH */
2250 2247 case (MDOC_Bo):
2251 2248 /* FALLTHROUGH */
2252 2249 case (MDOC_Bq):
2253 2250 print_text(h, "\\(rB");
2254 2251 break;
2255 2252 case (MDOC_Eo):
2256 2253 break;
2257 2254 case (MDOC_Qo):
2258 2255 /* FALLTHROUGH */
2259 2256 case (MDOC_Qq):
2260 2257 /* FALLTHROUGH */
2261 2258 case (MDOC_Do):
2262 2259 /* FALLTHROUGH */
2263 2260 case (MDOC_Dq):
2264 2261 print_text(h, "\\(rq");
2265 2262 break;
↓ open down ↓ |
1027 lines elided |
↑ open up ↑ |
2266 2263 case (MDOC_Po):
2267 2264 /* FALLTHROUGH */
2268 2265 case (MDOC_Pq):
2269 2266 print_text(h, ")");
2270 2267 break;
2271 2268 case (MDOC_Ql):
2272 2269 /* FALLTHROUGH */
2273 2270 case (MDOC_So):
2274 2271 /* FALLTHROUGH */
2275 2272 case (MDOC_Sq):
2276 - print_text(h, "\\(aq");
2273 + print_text(h, "\\(cq");
2277 2274 break;
2278 2275 default:
2279 2276 abort();
2280 2277 /* NOTREACHED */
2281 2278 }
2282 2279 }
2283 2280
2284 2281
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX