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