Annotation of mandoc/mdoc.c, Revision 1.249
1.249 ! schwarze 1: /* $Id: mdoc.c,v 1.248 2015/04/19 14:00:19 schwarze Exp $ */
1.1 kristaps 2: /*
1.182 schwarze 3: * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
1.237 schwarze 4: * Copyright (c) 2010, 2012-2015 Ingo Schwarze <schwarze@openbsd.org>
1.1 kristaps 5: *
6: * Permission to use, copy, modify, and distribute this software for any
1.75 kristaps 7: * purpose with or without fee is hereby granted, provided that the above
8: * copyright notice and this permission notice appear in all copies.
1.1 kristaps 9: *
1.241 schwarze 10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
1.75 kristaps 11: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1.241 schwarze 12: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
1.75 kristaps 13: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1 kristaps 17: */
1.114 kristaps 18: #include "config.h"
19:
1.106 kristaps 20: #include <sys/types.h>
21:
1.1 kristaps 22: #include <assert.h>
1.211 schwarze 23: #include <ctype.h>
1.1 kristaps 24: #include <stdarg.h>
1.73 kristaps 25: #include <stdio.h>
1.1 kristaps 26: #include <stdlib.h>
27: #include <string.h>
1.120 kristaps 28: #include <time.h>
1.1 kristaps 29:
1.239 schwarze 30: #include "mandoc_aux.h"
31: #include "mandoc.h"
32: #include "roff.h"
1.187 kristaps 33: #include "mdoc.h"
1.239 schwarze 34: #include "libmandoc.h"
1.247 schwarze 35: #include "roff_int.h"
1.70 kristaps 36: #include "libmdoc.h"
1.1 kristaps 37:
1.216 schwarze 38: const char *const __mdoc_macronames[MDOC_MAX + 1] = {
1.248 schwarze 39: "text",
1.82 kristaps 40: "Ap", "Dd", "Dt", "Os",
1.1 kristaps 41: "Sh", "Ss", "Pp", "D1",
42: "Dl", "Bd", "Ed", "Bl",
43: "El", "It", "Ad", "An",
44: "Ar", "Cd", "Cm", "Dv",
45: "Er", "Ev", "Ex", "Fa",
46: "Fd", "Fl", "Fn", "Ft",
47: "Ic", "In", "Li", "Nd",
48: "Nm", "Op", "Ot", "Pa",
49: "Rv", "St", "Va", "Vt",
1.114 kristaps 50: "Xr", "%A", "%B", "%D",
51: "%I", "%J", "%N", "%O",
52: "%P", "%R", "%T", "%V",
1.1 kristaps 53: "Ac", "Ao", "Aq", "At",
54: "Bc", "Bf", "Bo", "Bq",
55: "Bsx", "Bx", "Db", "Dc",
56: "Do", "Dq", "Ec", "Ef",
57: "Em", "Eo", "Fx", "Ms",
58: "No", "Ns", "Nx", "Ox",
59: "Pc", "Pf", "Po", "Pq",
60: "Qc", "Ql", "Qo", "Qq",
61: "Re", "Rs", "Sc", "So",
62: "Sq", "Sm", "Sx", "Sy",
63: "Tn", "Ux", "Xc", "Xo",
64: "Fo", "Fc", "Oo", "Oc",
65: "Bk", "Ek", "Bt", "Hf",
1.82 kristaps 66: "Fr", "Ud", "Lb", "Lp",
67: "Lk", "Mt", "Brq", "Bro",
1.114 kristaps 68: "Brc", "%C", "Es", "En",
69: "Dx", "%Q", "br", "sp",
1.248 schwarze 70: "%U", "Ta", "ll",
71: };
1.1 kristaps 72:
1.213 schwarze 73: const char *const __mdoc_argnames[MDOC_ARG_MAX] = {
1.1 kristaps 74: "split", "nosplit", "ragged",
1.213 schwarze 75: "unfilled", "literal", "file",
76: "offset", "bullet", "dash",
77: "hyphen", "item", "enum",
78: "tag", "diag", "hang",
79: "ohang", "inset", "column",
80: "width", "compact", "std",
1.52 kristaps 81: "filled", "words", "emphasis",
1.108 kristaps 82: "symbolic", "nested", "centered"
1.1 kristaps 83: };
84:
1.248 schwarze 85: const char * const *mdoc_macronames = __mdoc_macronames + 1;
1.1 kristaps 86: const char * const *mdoc_argnames = __mdoc_argnames;
87:
1.242 schwarze 88: static int mdoc_ptext(struct roff_man *, int, char *, int);
89: static int mdoc_pmacro(struct roff_man *, int, char *, int);
1.88 kristaps 90:
1.1 kristaps 91:
1.234 schwarze 92: void
1.242 schwarze 93: mdoc_endparse(struct roff_man *mdoc)
1.20 kristaps 94: {
95:
1.232 schwarze 96: mdoc_macroend(mdoc);
1.181 kristaps 97: }
98:
1.50 kristaps 99: /*
1.53 kristaps 100: * Main parse routine. Parses a single line -- really just hands off to
1.123 kristaps 101: * the macro (mdoc_pmacro()) or text parser (mdoc_ptext()).
1.50 kristaps 102: */
1.20 kristaps 103: int
1.242 schwarze 104: mdoc_parseln(struct roff_man *mdoc, int ln, char *buf, int offs)
1.1 kristaps 105: {
106:
1.239 schwarze 107: if (mdoc->last->type != ROFFT_EQN || ln > mdoc->last->line)
1.228 schwarze 108: mdoc->flags |= MDOC_NEWLINE;
1.153 schwarze 109:
110: /*
111: * Let the roff nS register switch SYNOPSIS mode early,
112: * such that the parser knows at all times
113: * whether this mode is on or off.
114: * Note that this mode is also switched by the Sh macro.
115: */
1.204 schwarze 116: if (roff_getreg(mdoc->roff, "nS"))
117: mdoc->flags |= MDOC_SYNOPSIS;
118: else
119: mdoc->flags &= ~MDOC_SYNOPSIS;
1.153 schwarze 120:
1.203 schwarze 121: return(roff_getcontrol(mdoc->roff, buf, &offs) ?
1.213 schwarze 122: mdoc_pmacro(mdoc, ln, buf, offs) :
123: mdoc_ptext(mdoc, ln, buf, offs));
1.1 kristaps 124: }
125:
1.232 schwarze 126: void
1.148 kristaps 127: mdoc_macro(MACRO_PROT_ARGS)
1.88 kristaps 128: {
1.248 schwarze 129: assert(tok > TOKEN_NONE && tok < MDOC_MAX);
1.122 kristaps 130:
1.223 schwarze 131: if (mdoc->flags & MDOC_PBODY) {
132: if (tok == MDOC_Dt) {
133: mandoc_vmsg(MANDOCERR_DT_LATE,
134: mdoc->parse, line, ppos,
135: "Dt %s", buf + *pos);
1.232 schwarze 136: return;
1.223 schwarze 137: }
138: } else if ( ! (mdoc_macros[tok].flags & MDOC_PROLOGUE)) {
139: if (mdoc->meta.title == NULL) {
140: mandoc_vmsg(MANDOCERR_DT_NOTITLE,
141: mdoc->parse, line, ppos, "%s %s",
142: mdoc_macronames[tok], buf + *pos);
143: mdoc->meta.title = mandoc_strdup("UNTITLED");
144: }
1.203 schwarze 145: if (NULL == mdoc->meta.vol)
146: mdoc->meta.vol = mandoc_strdup("LOCAL");
147: mdoc->flags |= MDOC_PBODY;
1.120 kristaps 148: }
1.232 schwarze 149: (*mdoc_macros[tok].fp)(mdoc, tok, line, ppos, pos, buf);
1.73 kristaps 150: }
151:
1.231 schwarze 152: void
1.242 schwarze 153: mdoc_tail_alloc(struct roff_man *mdoc, int line, int pos, int tok)
1.17 kristaps 154: {
1.240 schwarze 155: struct roff_node *p;
1.17 kristaps 156:
1.247 schwarze 157: p = roff_node_alloc(mdoc, line, pos, ROFFT_TAIL, tok);
158: roff_node_append(mdoc, p);
1.242 schwarze 159: mdoc->next = ROFF_NEXT_CHILD;
1.152 schwarze 160: }
161:
1.240 schwarze 162: struct roff_node *
1.242 schwarze 163: mdoc_endbody_alloc(struct roff_man *mdoc, int line, int pos, int tok,
1.240 schwarze 164: struct roff_node *body, enum mdoc_endbody end)
1.152 schwarze 165: {
1.240 schwarze 166: struct roff_node *p;
1.152 schwarze 167:
1.237 schwarze 168: body->flags |= MDOC_ENDED;
169: body->parent->flags |= MDOC_ENDED;
1.247 schwarze 170: p = roff_node_alloc(mdoc, line, pos, ROFFT_BODY, tok);
1.237 schwarze 171: p->body = body;
1.202 schwarze 172: p->norm = body->norm;
1.152 schwarze 173: p->end = end;
1.247 schwarze 174: roff_node_append(mdoc, p);
1.242 schwarze 175: mdoc->next = ROFF_NEXT_SIBLING;
1.235 schwarze 176: return(p);
1.1 kristaps 177: }
178:
1.240 schwarze 179: struct roff_node *
1.242 schwarze 180: mdoc_block_alloc(struct roff_man *mdoc, int line, int pos,
1.240 schwarze 181: int tok, struct mdoc_arg *args)
1.1 kristaps 182: {
1.240 schwarze 183: struct roff_node *p;
1.1 kristaps 184:
1.247 schwarze 185: p = roff_node_alloc(mdoc, line, pos, ROFFT_BLOCK, tok);
1.77 kristaps 186: p->args = args;
187: if (p->args)
1.53 kristaps 188: (args->refcnt)++;
1.172 kristaps 189:
190: switch (tok) {
1.213 schwarze 191: case MDOC_Bd:
1.172 kristaps 192: /* FALLTHROUGH */
1.213 schwarze 193: case MDOC_Bf:
1.172 kristaps 194: /* FALLTHROUGH */
1.213 schwarze 195: case MDOC_Bl:
1.217 schwarze 196: /* FALLTHROUGH */
197: case MDOC_En:
1.173 kristaps 198: /* FALLTHROUGH */
1.213 schwarze 199: case MDOC_Rs:
1.172 kristaps 200: p->norm = mandoc_calloc(1, sizeof(union mdoc_data));
201: break;
202: default:
203: break;
204: }
1.247 schwarze 205: roff_node_append(mdoc, p);
1.242 schwarze 206: mdoc->next = ROFF_NEXT_CHILD;
1.231 schwarze 207: return(p);
1.1 kristaps 208: }
209:
1.231 schwarze 210: void
1.242 schwarze 211: mdoc_elem_alloc(struct roff_man *mdoc, int line, int pos,
1.240 schwarze 212: int tok, struct mdoc_arg *args)
1.1 kristaps 213: {
1.240 schwarze 214: struct roff_node *p;
1.1 kristaps 215:
1.247 schwarze 216: p = roff_node_alloc(mdoc, line, pos, ROFFT_ELEM, tok);
1.77 kristaps 217: p->args = args;
218: if (p->args)
1.53 kristaps 219: (args->refcnt)++;
1.172 kristaps 220:
221: switch (tok) {
1.213 schwarze 222: case MDOC_An:
1.172 kristaps 223: p->norm = mandoc_calloc(1, sizeof(union mdoc_data));
224: break;
225: default:
226: break;
227: }
1.247 schwarze 228: roff_node_append(mdoc, p);
1.242 schwarze 229: mdoc->next = ROFF_NEXT_CHILD;
1.175 kristaps 230: }
1.1 kristaps 231:
1.231 schwarze 232: void
1.242 schwarze 233: mdoc_node_relink(struct roff_man *mdoc, struct roff_node *p)
1.201 schwarze 234: {
235:
1.247 schwarze 236: roff_node_unlink(mdoc, p);
237: roff_node_append(mdoc, p);
1.1 kristaps 238: }
239:
1.53 kristaps 240: /*
241: * Parse free-form text, that is, a line that does not begin with the
242: * control character.
243: */
244: static int
1.242 schwarze 245: mdoc_ptext(struct roff_man *mdoc, int line, char *buf, int offs)
1.1 kristaps 246: {
1.240 schwarze 247: struct roff_node *n;
1.142 kristaps 248: char *c, *ws, *end;
249:
1.203 schwarze 250: assert(mdoc->last);
251: n = mdoc->last;
1.142 kristaps 252:
253: /*
1.144 kristaps 254: * Divert directly to list processing if we're encountering a
1.239 schwarze 255: * columnar ROFFT_BLOCK with or without a prior ROFFT_BLOCK entry
256: * (a ROFFT_BODY means it's already open, in which case we should
1.144 kristaps 257: * process within its context in the normal way).
1.142 kristaps 258: */
259:
1.239 schwarze 260: if (n->tok == MDOC_Bl && n->type == ROFFT_BODY &&
1.238 schwarze 261: n->end == ENDBODY_NOT && n->norm->Bl.type == LIST_column) {
1.144 kristaps 262: /* `Bl' is open without any children. */
1.203 schwarze 263: mdoc->flags |= MDOC_FREECOL;
1.232 schwarze 264: mdoc_macro(mdoc, MDOC_It, line, offs, &offs, buf);
265: return(1);
1.142 kristaps 266: }
267:
1.239 schwarze 268: if (n->tok == MDOC_It && n->type == ROFFT_BLOCK &&
1.213 schwarze 269: NULL != n->parent &&
270: MDOC_Bl == n->parent->tok &&
271: LIST_column == n->parent->norm->Bl.type) {
1.144 kristaps 272: /* `Bl' has block-level `It' children. */
1.203 schwarze 273: mdoc->flags |= MDOC_FREECOL;
1.232 schwarze 274: mdoc_macro(mdoc, MDOC_It, line, offs, &offs, buf);
275: return(1);
1.142 kristaps 276: }
1.124 kristaps 277:
1.137 schwarze 278: /*
279: * Search for the beginning of unescaped trailing whitespace (ws)
280: * and for the first character not to be output (end).
281: */
1.139 kristaps 282:
283: /* FIXME: replace with strcspn(). */
1.137 schwarze 284: ws = NULL;
285: for (c = end = buf + offs; *c; c++) {
286: switch (*c) {
287: case ' ':
288: if (NULL == ws)
289: ws = c;
290: continue;
291: case '\t':
292: /*
293: * Always warn about trailing tabs,
294: * even outside literal context,
295: * where they should be put on the next line.
296: */
297: if (NULL == ws)
298: ws = c;
299: /*
300: * Strip trailing tabs in literal context only;
301: * outside, they affect the next line.
302: */
1.203 schwarze 303: if (MDOC_LITERAL & mdoc->flags)
1.137 schwarze 304: continue;
305: break;
306: case '\\':
307: /* Skip the escaped character, too, if any. */
308: if (c[1])
309: c++;
310: /* FALLTHROUGH */
311: default:
312: ws = NULL;
313: break;
314: }
315: end = c + 1;
316: }
317: *end = '\0';
1.91 kristaps 318:
1.137 schwarze 319: if (ws)
1.218 schwarze 320: mandoc_msg(MANDOCERR_SPACE_EOL, mdoc->parse,
321: line, (int)(ws-buf), NULL);
1.115 kristaps 322:
1.231 schwarze 323: if (buf[offs] == '\0' && ! (mdoc->flags & MDOC_LITERAL)) {
1.218 schwarze 324: mandoc_msg(MANDOCERR_FI_BLANK, mdoc->parse,
325: line, (int)(c - buf), NULL);
1.124 kristaps 326:
1.119 kristaps 327: /*
1.165 schwarze 328: * Insert a `sp' in the case of a blank line. Technically,
1.124 kristaps 329: * blank lines aren't allowed, but enough manuals assume this
330: * behaviour that we want to work around it.
1.119 kristaps 331: */
1.231 schwarze 332: mdoc_elem_alloc(mdoc, line, offs, MDOC_sp, NULL);
1.242 schwarze 333: mdoc->next = ROFF_NEXT_SIBLING;
1.230 schwarze 334: mdoc_valid_post(mdoc);
335: return(1);
1.119 kristaps 336: }
1.68 kristaps 337:
1.249 ! schwarze 338: roff_word_alloc(mdoc, line, offs, buf+offs);
1.91 kristaps 339:
1.231 schwarze 340: if (mdoc->flags & MDOC_LITERAL)
1.137 schwarze 341: return(1);
1.128 kristaps 342:
343: /*
344: * End-of-sentence check. If the last character is an unescaped
345: * EOS character, then flag the node as being the end of a
346: * sentence. The front-end will know how to interpret this.
347: */
1.132 kristaps 348:
1.137 schwarze 349: assert(buf < end);
350:
1.207 schwarze 351: if (mandoc_eos(buf+offs, (size_t)(end-buf-offs)))
1.203 schwarze 352: mdoc->last->flags |= MDOC_EOS;
1.128 kristaps 353: return(1);
1.1 kristaps 354: }
355:
1.53 kristaps 356: /*
357: * Parse a macro line, that is, a line beginning with the control
358: * character.
359: */
1.155 kristaps 360: static int
1.242 schwarze 361: mdoc_pmacro(struct roff_man *mdoc, int ln, char *buf, int offs)
1.1 kristaps 362: {
1.240 schwarze 363: struct roff_node *n;
1.229 schwarze 364: const char *cp;
1.240 schwarze 365: int tok;
1.188 kristaps 366: int i, sv;
1.144 kristaps 367: char mac[5];
1.63 kristaps 368:
1.188 kristaps 369: sv = offs;
1.130 kristaps 370:
1.213 schwarze 371: /*
1.162 schwarze 372: * Copy the first word into a nil-terminated buffer.
1.229 schwarze 373: * Stop when a space, tab, escape, or eoln is encountered.
1.160 kristaps 374: */
1.1 kristaps 375:
1.188 kristaps 376: i = 0;
1.229 schwarze 377: while (i < 4 && strchr(" \t\\", buf[offs]) == NULL)
1.188 kristaps 378: mac[i++] = buf[offs++];
379:
380: mac[i] = '\0';
381:
1.248 schwarze 382: tok = (i > 1 && i < 4) ? mdoc_hash_find(mac) : TOKEN_NONE;
1.1 kristaps 383:
1.248 schwarze 384: if (tok == TOKEN_NONE) {
1.222 schwarze 385: mandoc_msg(MANDOCERR_MACRO, mdoc->parse,
386: ln, sv, buf + sv - 1);
1.58 kristaps 387: return(1);
1.53 kristaps 388: }
1.1 kristaps 389:
1.229 schwarze 390: /* Skip a leading escape sequence or tab. */
1.160 kristaps 391:
1.229 schwarze 392: switch (buf[offs]) {
393: case '\\':
394: cp = buf + offs + 1;
395: mandoc_escape(&cp, NULL, NULL);
396: offs = cp - buf;
397: break;
398: case '\t':
1.188 kristaps 399: offs++;
1.229 schwarze 400: break;
401: default:
402: break;
403: }
1.160 kristaps 404:
405: /* Jump to the next non-whitespace word. */
1.1 kristaps 406:
1.188 kristaps 407: while (buf[offs] && ' ' == buf[offs])
408: offs++;
1.1 kristaps 409:
1.213 schwarze 410: /*
1.125 kristaps 411: * Trailing whitespace. Note that tabs are allowed to be passed
412: * into the parser as "text", so we only warn about spaces here.
413: */
1.115 kristaps 414:
1.188 kristaps 415: if ('\0' == buf[offs] && ' ' == buf[offs - 1])
1.218 schwarze 416: mandoc_msg(MANDOCERR_SPACE_EOL, mdoc->parse,
417: ln, offs - 1, NULL);
1.115 kristaps 418:
1.144 kristaps 419: /*
420: * If an initial macro or a list invocation, divert directly
421: * into macro processing.
422: */
423:
1.232 schwarze 424: if (NULL == mdoc->last || MDOC_It == tok || MDOC_El == tok) {
425: mdoc_macro(mdoc, tok, ln, sv, &offs, buf);
426: return(1);
427: }
1.144 kristaps 428:
1.203 schwarze 429: n = mdoc->last;
430: assert(mdoc->last);
1.144 kristaps 431:
432: /*
433: * If the first macro of a `Bl -column', open an `It' block
434: * context around the parsed macro.
435: */
436:
1.239 schwarze 437: if (n->tok == MDOC_Bl && n->type == ROFFT_BODY &&
1.238 schwarze 438: n->end == ENDBODY_NOT && n->norm->Bl.type == LIST_column) {
1.203 schwarze 439: mdoc->flags |= MDOC_FREECOL;
1.232 schwarze 440: mdoc_macro(mdoc, MDOC_It, ln, sv, &sv, buf);
441: return(1);
1.144 kristaps 442: }
443:
444: /*
445: * If we're following a block-level `It' within a `Bl -column'
446: * context (perhaps opened in the above block or in ptext()),
447: * then open an `It' block context around the parsed macro.
1.98 kristaps 448: */
1.144 kristaps 449:
1.239 schwarze 450: if (n->tok == MDOC_It && n->type == ROFFT_BLOCK &&
1.213 schwarze 451: NULL != n->parent &&
452: MDOC_Bl == n->parent->tok &&
453: LIST_column == n->parent->norm->Bl.type) {
1.203 schwarze 454: mdoc->flags |= MDOC_FREECOL;
1.232 schwarze 455: mdoc_macro(mdoc, MDOC_It, ln, sv, &sv, buf);
456: return(1);
1.144 kristaps 457: }
458:
459: /* Normal processing of a macro. */
460:
1.232 schwarze 461: mdoc_macro(mdoc, tok, ln, sv, &offs, buf);
1.208 schwarze 462:
463: /* In quick mode (for mandocdb), abort after the NAME section. */
464:
465: if (mdoc->quick && MDOC_Sh == tok &&
466: SEC_NAME != mdoc->last->sec)
467: return(2);
1.1 kristaps 468:
1.53 kristaps 469: return(1);
1.1 kristaps 470: }
1.100 kristaps 471:
1.186 kristaps 472: enum mdelim
473: mdoc_isdelim(const char *p)
474: {
475:
476: if ('\0' == p[0])
477: return(DELIM_NONE);
478:
479: if ('\0' == p[1])
480: switch (p[0]) {
1.213 schwarze 481: case '(':
1.186 kristaps 482: /* FALLTHROUGH */
1.213 schwarze 483: case '[':
1.186 kristaps 484: return(DELIM_OPEN);
1.213 schwarze 485: case '|':
1.186 kristaps 486: return(DELIM_MIDDLE);
1.213 schwarze 487: case '.':
1.186 kristaps 488: /* FALLTHROUGH */
1.213 schwarze 489: case ',':
1.186 kristaps 490: /* FALLTHROUGH */
1.213 schwarze 491: case ';':
1.186 kristaps 492: /* FALLTHROUGH */
1.213 schwarze 493: case ':':
1.186 kristaps 494: /* FALLTHROUGH */
1.213 schwarze 495: case '?':
1.186 kristaps 496: /* FALLTHROUGH */
1.213 schwarze 497: case '!':
1.186 kristaps 498: /* FALLTHROUGH */
1.213 schwarze 499: case ')':
1.186 kristaps 500: /* FALLTHROUGH */
1.213 schwarze 501: case ']':
1.186 kristaps 502: return(DELIM_CLOSE);
503: default:
504: return(DELIM_NONE);
505: }
506:
507: if ('\\' != p[0])
508: return(DELIM_NONE);
1.100 kristaps 509:
1.186 kristaps 510: if (0 == strcmp(p + 1, "."))
511: return(DELIM_CLOSE);
1.200 schwarze 512: if (0 == strcmp(p + 1, "fR|\\fP"))
1.186 kristaps 513: return(DELIM_MIDDLE);
514:
515: return(DELIM_NONE);
1.211 schwarze 516: }
517:
518: void
1.240 schwarze 519: mdoc_deroff(char **dest, const struct roff_node *n)
1.211 schwarze 520: {
521: char *cp;
522: size_t sz;
523:
1.239 schwarze 524: if (n->type != ROFFT_TEXT) {
1.211 schwarze 525: for (n = n->child; n; n = n->next)
526: mdoc_deroff(dest, n);
527: return;
528: }
529:
530: /* Skip leading whitespace. */
531:
532: for (cp = n->string; '\0' != *cp; cp++)
533: if (0 == isspace((unsigned char)*cp))
534: break;
535:
536: /* Skip trailing whitespace. */
537:
538: for (sz = strlen(cp); sz; sz--)
539: if (0 == isspace((unsigned char)cp[sz-1]))
540: break;
541:
542: /* Skip empty strings. */
543:
544: if (0 == sz)
545: return;
546:
547: if (NULL == *dest) {
548: *dest = mandoc_strndup(cp, sz);
549: return;
550: }
551:
552: mandoc_asprintf(&cp, "%s %*s", *dest, (int)sz, cp);
553: free(*dest);
554: *dest = cp;
1.186 kristaps 555: }
CVSweb