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