Annotation of mandoc/action.c, Revision 1.49
1.49 ! kristaps 1: /* $Id: action.c,v 1.48 2009/03/21 09:48:29 kristaps Exp $ */
1.1 kristaps 2: /*
1.43 kristaps 3: * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org>
1.1 kristaps 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
7: * above copyright notice and this permission notice appear in all
8: * copies.
9: *
10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11: * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12: * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13: * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14: * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15: * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16: * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17: * PERFORMANCE OF THIS SOFTWARE.
18: */
1.31 kristaps 19: #include <sys/utsname.h>
20:
1.1 kristaps 21: #include <assert.h>
1.31 kristaps 22: #include <errno.h>
1.20 kristaps 23: #include <stdio.h>
1.1 kristaps 24: #include <stdlib.h>
1.20 kristaps 25: #include <string.h>
1.1 kristaps 26:
27: #include "private.h"
28:
1.14 kristaps 29: /*
30: * Actions are executed on macros after they've been post-validated: in
31: * other words, a macro will not be "acted upon" until all of its
32: * children have been filled in (post-fix order).
33: */
1.1 kristaps 34:
1.33 kristaps 35: enum mwarn {
36: WBADSEC,
37: WNOWIDTH,
38: WBADDATE
39: };
40:
1.44 kristaps 41: #define PRE_ARGS struct mdoc *m, const struct mdoc_node *n
42: #define POST_ARGS struct mdoc *m
43:
1.1 kristaps 44: struct actions {
1.44 kristaps 45: int (*pre)(PRE_ARGS);
46: int (*post)(POST_ARGS);
1.1 kristaps 47: };
48:
1.44 kristaps 49: static int pwarn(struct mdoc *, int, int, enum mwarn);
50:
51: static int post_ar(POST_ARGS);
52: static int post_bl(POST_ARGS);
53: static int post_bl_width(POST_ARGS);
54: static int post_bl_tagwidth(POST_ARGS);
55: static int post_dd(POST_ARGS);
1.46 kristaps 56: static int post_display(POST_ARGS);
1.44 kristaps 57: static int post_dt(POST_ARGS);
58: static int post_nm(POST_ARGS);
59: static int post_os(POST_ARGS);
60: static int post_prol(POST_ARGS);
61: static int post_sh(POST_ARGS);
62: static int post_std(POST_ARGS);
1.3 kristaps 63:
1.45 kristaps 64: static int pre_bd(PRE_ARGS);
1.46 kristaps 65: static int pre_dl(PRE_ARGS);
1.44 kristaps 66:
67: #define mwarn(m, t) pwarn((m), (m)->last->line, (m)->last->pos, (t))
1.42 kristaps 68:
1.1 kristaps 69: const struct actions mdoc_actions[MDOC_MAX] = {
1.44 kristaps 70: { NULL, NULL }, /* \" */
71: { NULL, post_dd }, /* Dd */
72: { NULL, post_dt }, /* Dt */
73: { NULL, post_os }, /* Os */
74: { NULL, post_sh }, /* Sh */
75: { NULL, NULL }, /* Ss */
76: { NULL, NULL }, /* Pp */
77: { NULL, NULL }, /* D1 */
1.46 kristaps 78: { pre_dl, post_display }, /* Dl */
79: { pre_bd, post_display }, /* Bd */
1.44 kristaps 80: { NULL, NULL }, /* Ed */
81: { NULL, post_bl }, /* Bl */
82: { NULL, NULL }, /* El */
83: { NULL, NULL }, /* It */
84: { NULL, NULL }, /* Ad */
85: { NULL, NULL }, /* An */
86: { NULL, post_ar }, /* Ar */
87: { NULL, NULL }, /* Cd */
88: { NULL, NULL }, /* Cm */
89: { NULL, NULL }, /* Dv */
90: { NULL, NULL }, /* Er */
91: { NULL, NULL }, /* Ev */
92: { NULL, post_std }, /* Ex */
93: { NULL, NULL }, /* Fa */
94: { NULL, NULL }, /* Fd */
95: { NULL, NULL }, /* Fl */
96: { NULL, NULL }, /* Fn */
97: { NULL, NULL }, /* Ft */
98: { NULL, NULL }, /* Ic */
99: { NULL, NULL }, /* In */
100: { NULL, NULL }, /* Li */
101: { NULL, NULL }, /* Nd */
102: { NULL, post_nm }, /* Nm */
103: { NULL, NULL }, /* Op */
104: { NULL, NULL }, /* Ot */
105: { NULL, NULL }, /* Pa */
106: { NULL, post_std }, /* Rv */
107: { NULL, NULL }, /* St */
108: { NULL, NULL }, /* Va */
109: { NULL, NULL }, /* Vt */
110: { NULL, NULL }, /* Xr */
111: { NULL, NULL }, /* %A */
112: { NULL, NULL }, /* %B */
113: { NULL, NULL }, /* %D */
114: { NULL, NULL }, /* %I */
115: { NULL, NULL }, /* %J */
116: { NULL, NULL }, /* %N */
117: { NULL, NULL }, /* %O */
118: { NULL, NULL }, /* %P */
119: { NULL, NULL }, /* %R */
120: { NULL, NULL }, /* %T */
121: { NULL, NULL }, /* %V */
122: { NULL, NULL }, /* Ac */
123: { NULL, NULL }, /* Ao */
124: { NULL, NULL }, /* Aq */
125: { NULL, NULL }, /* At */
126: { NULL, NULL }, /* Bc */
127: { NULL, NULL }, /* Bf */
128: { NULL, NULL }, /* Bo */
129: { NULL, NULL }, /* Bq */
130: { NULL, NULL }, /* Bsx */
131: { NULL, NULL }, /* Bx */
132: { NULL, NULL }, /* Db */
133: { NULL, NULL }, /* Dc */
134: { NULL, NULL }, /* Do */
135: { NULL, NULL }, /* Dq */
136: { NULL, NULL }, /* Ec */
137: { NULL, NULL }, /* Ef */
138: { NULL, NULL }, /* Em */
139: { NULL, NULL }, /* Eo */
140: { NULL, NULL }, /* Fx */
141: { NULL, NULL }, /* Ms */
142: { NULL, NULL }, /* No */
143: { NULL, NULL }, /* Ns */
144: { NULL, NULL }, /* Nx */
145: { NULL, NULL }, /* Ox */
146: { NULL, NULL }, /* Pc */
147: { NULL, NULL }, /* Pf */
148: { NULL, NULL }, /* Po */
149: { NULL, NULL }, /* Pq */
150: { NULL, NULL }, /* Qc */
151: { NULL, NULL }, /* Ql */
152: { NULL, NULL }, /* Qo */
153: { NULL, NULL }, /* Qq */
154: { NULL, NULL }, /* Re */
155: { NULL, NULL }, /* Rs */
156: { NULL, NULL }, /* Sc */
157: { NULL, NULL }, /* So */
158: { NULL, NULL }, /* Sq */
159: { NULL, NULL }, /* Sm */
160: { NULL, NULL }, /* Sx */
161: { NULL, NULL }, /* Sy */
162: { NULL, NULL }, /* Tn */
163: { NULL, NULL }, /* Ux */
164: { NULL, NULL }, /* Xc */
165: { NULL, NULL }, /* Xo */
166: { NULL, NULL }, /* Fo */
167: { NULL, NULL }, /* Fc */
168: { NULL, NULL }, /* Oo */
169: { NULL, NULL }, /* Oc */
170: { NULL, NULL }, /* Bk */
171: { NULL, NULL }, /* Ek */
172: { NULL, NULL }, /* Bt */
173: { NULL, NULL }, /* Hf */
174: { NULL, NULL }, /* Fr */
175: { NULL, NULL }, /* Ud */
176: { NULL, NULL }, /* Lb */
177: { NULL, NULL }, /* Ap */
178: { NULL, NULL }, /* Lp */
179: { NULL, NULL }, /* Lk */
180: { NULL, NULL }, /* Mt */
181: { NULL, NULL }, /* Brq */
182: { NULL, NULL }, /* Bro */
183: { NULL, NULL }, /* Brc */
184: { NULL, NULL }, /* %C */
185: { NULL, NULL }, /* Es */
186: { NULL, NULL }, /* En */
187: { NULL, NULL }, /* Dx */
1.47 kristaps 188: { NULL, NULL }, /* %Q */
1.1 kristaps 189: };
190:
191:
1.44 kristaps 192: int
193: mdoc_action_pre(struct mdoc *m, const struct mdoc_node *n)
194: {
195:
196: switch (n->type) {
197: case (MDOC_ROOT):
198: break;
199: case (MDOC_TEXT):
200: break;
201: default:
202: if (NULL == mdoc_actions[m->last->tok].pre)
203: break;
204: return((*mdoc_actions[m->last->tok].pre)(m, n));
205: }
206: return(1);
207: }
208:
209:
210: int
211: mdoc_action_post(struct mdoc *m)
212: {
213:
214: if (MDOC_ACTED & m->last->flags)
215: return(1);
216: m->last->flags |= MDOC_ACTED;
217:
218: switch (m->last->type) {
219: case (MDOC_TEXT):
220: break;
221: case (MDOC_ROOT):
222: break;
223: default:
224: if (NULL == mdoc_actions[m->last->tok].post)
225: break;
226: return((*mdoc_actions[m->last->tok].post)(m));
227: }
228: return(1);
229: }
230:
231:
1.33 kristaps 232: static int
1.44 kristaps 233: pwarn(struct mdoc *m, int line, int pos, enum mwarn type)
1.33 kristaps 234: {
235: char *p;
236: int c;
237:
238: p = NULL;
239: c = WARN_SYNTAX;
240:
241: switch (type) {
242: case (WBADSEC):
243: p = "inappropriate document section in manual section";
244: c = WARN_COMPAT;
245: break;
246: case (WNOWIDTH):
247: p = "cannot determine default width";
248: break;
249: case (WBADDATE):
250: p = "malformed date syntax";
251: break;
252: }
253:
254: assert(p);
1.44 kristaps 255: return(mdoc_pwarn(m, line, pos, c, p));
1.33 kristaps 256: }
257:
258:
1.3 kristaps 259: static int
1.44 kristaps 260: post_std(POST_ARGS)
1.29 kristaps 261: {
262:
263: /*
1.41 kristaps 264: * If '-std' is invoked without an argument, fill it in with our
265: * name (if it's been set).
1.29 kristaps 266: */
267:
1.44 kristaps 268: if (NULL == m->last->args)
1.29 kristaps 269: return(1);
1.44 kristaps 270: if (m->last->args->argv[0].sz)
1.29 kristaps 271: return(1);
272:
1.44 kristaps 273: assert(m->meta.name);
1.29 kristaps 274:
1.44 kristaps 275: m->last->args->argv[0].value = xcalloc(1, sizeof(char *));
276: m->last->args->argv[0].sz = 1;
277: m->last->args->argv[0].value[0] = xstrdup(m->meta.name);
1.29 kristaps 278: return(1);
279: }
280:
281:
282: static int
1.44 kristaps 283: post_nm(POST_ARGS)
1.10 kristaps 284: {
285: char buf[64];
286:
1.44 kristaps 287: if (m->meta.name)
1.10 kristaps 288: return(1);
289:
1.44 kristaps 290: (void)xstrlcpys(buf, m->last->child, sizeof(buf));
291: m->meta.name = xstrdup(buf);
1.10 kristaps 292:
1.31 kristaps 293: return(1);
1.10 kristaps 294: }
295:
296:
297: static int
1.44 kristaps 298: post_sh(POST_ARGS)
1.1 kristaps 299: {
1.10 kristaps 300: enum mdoc_sec sec;
301: char buf[64];
1.3 kristaps 302:
1.23 kristaps 303: /*
304: * We keep track of the current section /and/ the "named"
305: * section, which is one of the conventional ones, in order to
306: * check ordering.
307: */
308:
1.44 kristaps 309: if (MDOC_HEAD != m->last->type)
1.3 kristaps 310: return(1);
1.31 kristaps 311:
1.44 kristaps 312: (void)xstrlcpys(buf, m->last->child, sizeof(buf));
1.31 kristaps 313: if (SEC_CUSTOM != (sec = mdoc_atosec(buf)))
1.44 kristaps 314: m->lastnamed = sec;
1.31 kristaps 315:
1.44 kristaps 316: switch ((m->lastsec = sec)) {
1.23 kristaps 317: case (SEC_RETURN_VALUES):
318: /* FALLTHROUGH */
319: case (SEC_ERRORS):
1.44 kristaps 320: switch (m->meta.msec) {
1.31 kristaps 321: case (2):
1.23 kristaps 322: /* FALLTHROUGH */
1.31 kristaps 323: case (3):
1.23 kristaps 324: /* FALLTHROUGH */
1.31 kristaps 325: case (9):
1.23 kristaps 326: break;
327: default:
1.44 kristaps 328: return(mwarn(m, WBADSEC));
1.23 kristaps 329: }
330: break;
331: default:
332: break;
1.11 kristaps 333: }
1.23 kristaps 334: return(1);
1.1 kristaps 335: }
336:
1.3 kristaps 337:
1.4 kristaps 338: static int
1.44 kristaps 339: post_dt(POST_ARGS)
1.4 kristaps 340: {
1.5 kristaps 341: struct mdoc_node *n;
1.31 kristaps 342: const char *cp;
343: char *ep;
344: long lval;
345:
1.44 kristaps 346: if (m->meta.title)
347: free(m->meta.title);
348: if (m->meta.vol)
349: free(m->meta.vol);
350: if (m->meta.arch)
351: free(m->meta.arch);
1.31 kristaps 352:
1.44 kristaps 353: m->meta.title = m->meta.vol = m->meta.arch = NULL;
354: m->meta.msec = 0;
1.31 kristaps 355:
356: /* Handles: `.Dt'
357: * --> title = unknown, volume = local, msec = 0, arch = NULL
358: */
359:
1.44 kristaps 360: if (NULL == (n = m->last->child)) {
361: m->meta.title = xstrdup("unknown");
362: m->meta.vol = xstrdup("local");
363: return(post_prol(m));
1.31 kristaps 364: }
1.5 kristaps 365:
1.31 kristaps 366: /* Handles: `.Dt TITLE'
367: * --> title = TITLE, volume = local, msec = 0, arch = NULL
1.23 kristaps 368: */
369:
1.44 kristaps 370: m->meta.title = xstrdup(n->string);
1.31 kristaps 371:
372: if (NULL == (n = n->next)) {
1.44 kristaps 373: m->meta.vol = xstrdup("local");
374: return(post_prol(m));
1.31 kristaps 375: }
1.5 kristaps 376:
1.31 kristaps 377: /* Handles: `.Dt TITLE SEC'
378: * --> title = TITLE, volume = SEC is msec ?
379: * format(msec) : SEC,
380: * msec = SEC is msec ? atoi(msec) : 0,
381: * arch = NULL
382: */
383:
1.48 kristaps 384: cp = mdoc_a2msec(n->string);
385: if (cp) {
1.44 kristaps 386: m->meta.vol = xstrdup(cp);
1.31 kristaps 387: errno = 0;
1.33 kristaps 388: lval = strtol(n->string, &ep, 10);
389: if (n->string[0] != '\0' && *ep == '\0')
1.44 kristaps 390: m->meta.msec = (int)lval;
1.31 kristaps 391: } else
1.44 kristaps 392: m->meta.vol = xstrdup(n->string);
1.31 kristaps 393:
1.44 kristaps 394: if (NULL == (n = n->next))
395: return(post_prol(m));
1.4 kristaps 396:
1.31 kristaps 397: /* Handles: `.Dt TITLE SEC VOL'
398: * --> title = TITLE, volume = VOL is vol ?
399: * format(VOL) :
400: * VOL is arch ? format(arch) :
401: * VOL
402: */
1.4 kristaps 403:
1.48 kristaps 404: cp = mdoc_a2vol(n->string);
405: if (cp) {
1.44 kristaps 406: free(m->meta.vol);
407: m->meta.vol = xstrdup(cp);
1.31 kristaps 408: n = n->next;
409: } else {
1.33 kristaps 410: cp = mdoc_a2arch(n->string);
1.31 kristaps 411: if (NULL == cp) {
1.44 kristaps 412: free(m->meta.vol);
413: m->meta.vol = xstrdup(n->string);
1.31 kristaps 414: } else
1.44 kristaps 415: m->meta.arch = xstrdup(cp);
1.31 kristaps 416: }
1.4 kristaps 417:
1.31 kristaps 418: /* Ignore any subsequent parameters... */
1.15 kristaps 419:
1.44 kristaps 420: return(post_prol(m));
1.4 kristaps 421: }
422:
423:
424: static int
1.44 kristaps 425: post_os(POST_ARGS)
1.4 kristaps 426: {
1.10 kristaps 427: char buf[64];
1.31 kristaps 428: struct utsname utsname;
1.5 kristaps 429:
1.44 kristaps 430: if (m->meta.os)
431: free(m->meta.os);
1.23 kristaps 432:
1.44 kristaps 433: (void)xstrlcpys(buf, m->last->child, sizeof(buf));
1.5 kristaps 434:
1.31 kristaps 435: if (0 == buf[0]) {
436: if (-1 == uname(&utsname))
1.44 kristaps 437: return(mdoc_err(m, "utsname"));
1.31 kristaps 438: (void)xstrlcpy(buf, utsname.sysname, sizeof(buf));
439: (void)xstrlcat(buf, " ", sizeof(buf));
440: (void)xstrlcat(buf, utsname.release, sizeof(buf));
441: }
1.6 kristaps 442:
1.44 kristaps 443: m->meta.os = xstrdup(buf);
444: m->lastnamed = m->lastsec = SEC_BODY;
1.31 kristaps 445:
1.44 kristaps 446: return(post_prol(m));
1.4 kristaps 447: }
448:
449:
1.49 ! kristaps 450: /*
! 451: * Calculate the -width for a `Bl -tag' list if it hasn't been provided.
! 452: * Uses the first head macro.
! 453: */
1.20 kristaps 454: static int
1.44 kristaps 455: post_bl_tagwidth(struct mdoc *m)
1.20 kristaps 456: {
1.23 kristaps 457: struct mdoc_node *n;
458: int sz;
1.20 kristaps 459: char buf[32];
460:
1.23 kristaps 461: /*
462: * Use the text width, if a text node, or the default macro
463: * width if a macro.
464: */
465:
1.49 ! kristaps 466: n = m->last->head->child;
! 467: sz = 10; /* Default size. */
! 468:
1.48 kristaps 469: if (n) {
1.23 kristaps 470: if (MDOC_TEXT != n->type) {
1.33 kristaps 471: if (0 == (sz = (int)mdoc_macro2len(n->tok)))
1.49 ! kristaps 472: if ( ! mwarn(m, WNOWIDTH))
! 473: return(0);
1.23 kristaps 474: } else
1.33 kristaps 475: sz = (int)strlen(n->string) + 1;
1.49 ! kristaps 476: }
1.23 kristaps 477:
478: (void)snprintf(buf, sizeof(buf), "%dn", sz);
479:
480: /*
481: * We have to dynamically add this to the macro's argument list.
482: * We're guaranteed that a MDOC_Width doesn't already exist.
483: */
484:
1.49 ! kristaps 485: n = m->last;
! 486: assert(n->args);
1.33 kristaps 487:
488: (n->args->argc)++;
489: n->args->argv = xrealloc(n->args->argv,
1.49 ! kristaps 490: n->args->argc * sizeof(struct mdoc_argv));
1.23 kristaps 491:
1.49 ! kristaps 492: n->args->argv[n->args->argc - 1].arg = MDOC_Width;
! 493: n->args->argv[n->args->argc - 1].line = m->last->line;
! 494: n->args->argv[n->args->argc - 1].pos = m->last->pos;
! 495: n->args->argv[n->args->argc - 1].sz = 1;
! 496: n->args->argv[n->args->argc - 1].value = xcalloc(1, sizeof(char *));
! 497: n->args->argv[n->args->argc - 1].value[0] = xstrdup(buf);
1.23 kristaps 498:
499: return(1);
500: }
1.20 kristaps 501:
502:
1.23 kristaps 503: static int
1.33 kristaps 504: post_bl_width(struct mdoc *m)
1.23 kristaps 505: {
506: size_t width;
507: int i, tok;
508: char buf[32];
1.34 kristaps 509: char *p;
1.23 kristaps 510:
1.33 kristaps 511: if (NULL == m->last->args)
1.49 ! kristaps 512: return(1);
1.33 kristaps 513:
514: for (i = 0; i < (int)m->last->args->argc; i++)
515: if (MDOC_Width == m->last->args->argv[i].arg)
1.20 kristaps 516: break;
517:
1.33 kristaps 518: if (i == (int)m->last->args->argc)
1.49 ! kristaps 519: return(1);
1.33 kristaps 520:
1.34 kristaps 521: p = m->last->args->argv[i].value[0];
1.23 kristaps 522:
523: /*
524: * If the value to -width is a macro, then we re-write it to be
525: * the macro's width as set in share/tmac/mdoc/doc-common.
526: */
1.20 kristaps 527:
1.34 kristaps 528: if (xstrcmp(p, "Ds"))
1.26 kristaps 529: width = 8;
1.34 kristaps 530: else if (MDOC_MAX == (tok = mdoc_tokhash_find(m->htab, p)))
1.20 kristaps 531: return(1);
1.24 kristaps 532: else if (0 == (width = mdoc_macro2len(tok)))
1.33 kristaps 533: return(mwarn(m, WNOWIDTH));
1.20 kristaps 534:
1.23 kristaps 535: /* The value already exists: free and reallocate it. */
1.20 kristaps 536:
537: (void)snprintf(buf, sizeof(buf), "%zun", width);
538:
1.34 kristaps 539: free(m->last->args->argv[i].value[0]);
540: m->last->args->argv[i].value[0] = xstrdup(buf);
1.23 kristaps 541:
542: return(1);
543: }
544:
545:
546: static int
1.44 kristaps 547: post_bl(POST_ARGS)
1.23 kristaps 548: {
1.33 kristaps 549: int i, r, len;
1.23 kristaps 550:
1.44 kristaps 551: if (MDOC_BLOCK != m->last->type)
1.23 kristaps 552: return(1);
553:
554: /*
555: * These are fairly complicated, so we've broken them into two
556: * functions. post_bl_tagwidth() is called when a -tag is
557: * specified, but no -width (it must be guessed). The second
558: * when a -width is specified (macro indicators must be
559: * rewritten into real lengths).
560: */
561:
1.44 kristaps 562: len = (int)(m->last->args ? m->last->args->argc : 0);
1.33 kristaps 563:
564: for (r = i = 0; i < len; i++) {
1.44 kristaps 565: if (MDOC_Tag == m->last->args->argv[i].arg)
1.23 kristaps 566: r |= 1 << 0;
1.44 kristaps 567: if (MDOC_Width == m->last->args->argv[i].arg)
1.23 kristaps 568: r |= 1 << 1;
569: }
570:
571: if (r & (1 << 0) && ! (r & (1 << 1))) {
1.44 kristaps 572: if ( ! post_bl_tagwidth(m))
1.23 kristaps 573: return(0);
574: } else if (r & (1 << 1))
1.44 kristaps 575: if ( ! post_bl_width(m))
1.23 kristaps 576: return(0);
1.20 kristaps 577:
578: return(1);
579: }
580:
581:
1.4 kristaps 582: static int
1.44 kristaps 583: post_ar(POST_ARGS)
1.30 kristaps 584: {
585: struct mdoc_node *n;
586:
1.44 kristaps 587: if (m->last->child)
1.30 kristaps 588: return(1);
589:
1.44 kristaps 590: n = m->last;
591: m->next = MDOC_NEXT_CHILD;
592: if ( ! mdoc_word_alloc(m, m->last->line,
593: m->last->pos, "file"))
1.32 kristaps 594: return(0);
1.44 kristaps 595: m->next = MDOC_NEXT_SIBLING;
596: if ( ! mdoc_word_alloc(m, m->last->line,
597: m->last->pos, "..."))
1.32 kristaps 598: return(0);
1.30 kristaps 599:
1.44 kristaps 600: m->last = n;
601: m->next = MDOC_NEXT_SIBLING;
1.30 kristaps 602: return(1);
603: }
604:
605:
606: static int
1.44 kristaps 607: post_dd(POST_ARGS)
1.4 kristaps 608: {
1.15 kristaps 609: char buf[64];
1.4 kristaps 610:
1.44 kristaps 611: (void)xstrlcpys(buf, m->last->child, sizeof(buf));
1.5 kristaps 612:
1.44 kristaps 613: if (0 == (m->meta.date = mdoc_atotime(buf))) {
614: if ( ! mwarn(m, WBADDATE))
1.33 kristaps 615: return(0);
1.44 kristaps 616: m->meta.date = time(NULL);
1.33 kristaps 617: }
1.5 kristaps 618:
1.44 kristaps 619: return(post_prol(m));
1.4 kristaps 620: }
621:
622:
1.13 kristaps 623: static int
1.44 kristaps 624: post_prol(POST_ARGS)
1.13 kristaps 625: {
626: struct mdoc_node *n;
627:
1.23 kristaps 628: /*
629: * The end document shouldn't have the prologue macros as part
630: * of the syntax tree (they encompass only meta-data).
631: */
632:
1.44 kristaps 633: if (m->last->parent->child == m->last)
634: m->last->parent->child = m->last->prev;
635: if (m->last->prev)
636: m->last->prev->next = NULL;
637:
638: n = m->last;
639: assert(NULL == m->last->next);
640:
641: if (m->last->prev) {
642: m->last = m->last->prev;
643: m->next = MDOC_NEXT_SIBLING;
1.13 kristaps 644: } else {
1.44 kristaps 645: m->last = m->last->parent;
646: m->next = MDOC_NEXT_CHILD;
1.13 kristaps 647: }
648:
649: mdoc_node_freelist(n);
650: return(1);
651: }
652:
653:
1.44 kristaps 654: static int
1.46 kristaps 655: pre_dl(PRE_ARGS)
656: {
657:
658: if (MDOC_BODY != n->type)
659: return(1);
660: m->flags |= MDOC_LITERAL;
661: return(1);
662: }
663:
664:
665: static int
1.45 kristaps 666: pre_bd(PRE_ARGS)
1.3 kristaps 667: {
1.44 kristaps 668: int i;
1.3 kristaps 669:
1.44 kristaps 670: if (MDOC_BODY != n->type)
1.12 kristaps 671: return(1);
672:
1.44 kristaps 673: /*
674: * We ONLY enter a literal context if `Bd -literal' or `Bd
675: * -unfilled'.
676: */
677:
678: n = n->parent;
1.45 kristaps 679:
1.44 kristaps 680: for (i = 0; i < (int)n->args->argc; i++)
681: if (MDOC_Literal == n->args->argv[i].arg)
682: break;
683: else if (MDOC_Unfilled == n->args->argv[i].arg)
684: break;
685:
686: if (i < (int)n->args->argc)
687: m->flags |= MDOC_LITERAL;
688:
689: return(1);
690: }
691:
692:
693: static int
1.46 kristaps 694: post_display(POST_ARGS)
1.44 kristaps 695: {
696:
697: if (MDOC_BODY == m->last->type)
698: m->flags &= ~MDOC_LITERAL;
699: return(1);
1.3 kristaps 700: }
1.44 kristaps 701:
702:
CVSweb