Annotation of mandoc/mdoc_action.c, Revision 1.86
1.86 ! kristaps 1: /* $Id: mdoc_action.c,v 1.85 2010/11/29 16:06:46 kristaps Exp $ */
1.1 kristaps 2: /*
1.76 schwarze 3: * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
1.1 kristaps 4: *
5: * Permission to use, copy, modify, and distribute this software for any
1.8 kristaps 6: * purpose with or without fee is hereby granted, provided that the above
7: * copyright notice and this permission notice appear in all copies.
1.1 kristaps 8: *
1.8 kristaps 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.
1.1 kristaps 16: */
1.50 kristaps 17: #ifdef HAVE_CONFIG_H
18: #include "config.h"
19: #endif
20:
1.44 kristaps 21: #ifndef OSNAME
1.1 kristaps 22: #include <sys/utsname.h>
1.44 kristaps 23: #endif
1.1 kristaps 24:
25: #include <assert.h>
26: #include <stdio.h>
27: #include <stdlib.h>
28: #include <string.h>
1.44 kristaps 29: #include <time.h>
1.1 kristaps 30:
1.59 kristaps 31: #include "mandoc.h"
1.1 kristaps 32: #include "libmdoc.h"
1.46 kristaps 33: #include "libmandoc.h"
1.72 kristaps 34:
35: /*
36: * FIXME: this file is deprecated. All future "actions" should be
37: * pushed into mdoc_validate.c.
38: */
1.1 kristaps 39:
1.35 kristaps 40: #define POST_ARGS struct mdoc *m, struct mdoc_node *n
1.60 kristaps 41: #define PRE_ARGS struct mdoc *m, struct mdoc_node *n
1.1 kristaps 42:
1.46 kristaps 43: #define NUMSIZ 32
44: #define DATESIZ 32
45:
1.1 kristaps 46: struct actions {
47: int (*pre)(PRE_ARGS);
48: int (*post)(POST_ARGS);
49: };
50:
1.46 kristaps 51: static int concat(struct mdoc *, char *,
52: const struct mdoc_node *, size_t);
1.39 kristaps 53:
1.1 kristaps 54: static int post_bl(POST_ARGS);
1.25 kristaps 55: static int post_bl_tagwidth(POST_ARGS);
1.70 kristaps 56: static int post_bl_width(POST_ARGS);
1.1 kristaps 57: static int post_dd(POST_ARGS);
58: static int post_dt(POST_ARGS);
59: static int post_os(POST_ARGS);
60: static int post_prol(POST_ARGS);
61: static int post_std(POST_ARGS);
62:
1.37 kristaps 63: static const struct actions mdoc_actions[MDOC_MAX] = {
1.12 kristaps 64: { NULL, NULL }, /* Ap */
1.1 kristaps 65: { NULL, post_dd }, /* Dd */
66: { NULL, post_dt }, /* Dt */
67: { NULL, post_os }, /* Os */
1.81 kristaps 68: { NULL, NULL }, /* Sh */
1.1 kristaps 69: { NULL, NULL }, /* Ss */
70: { NULL, NULL }, /* Pp */
71: { NULL, NULL }, /* D1 */
1.84 kristaps 72: { NULL, NULL }, /* Dl */
73: { NULL, NULL }, /* Bd */
1.1 kristaps 74: { NULL, NULL }, /* Ed */
1.68 kristaps 75: { NULL, post_bl }, /* Bl */
1.1 kristaps 76: { NULL, NULL }, /* El */
77: { NULL, NULL }, /* It */
78: { NULL, NULL }, /* Ad */
79: { NULL, NULL }, /* An */
1.80 kristaps 80: { NULL, NULL }, /* Ar */
1.35 kristaps 81: { NULL, NULL }, /* Cd */
1.1 kristaps 82: { NULL, NULL }, /* Cm */
83: { NULL, NULL }, /* Dv */
84: { NULL, NULL }, /* Er */
85: { NULL, NULL }, /* Ev */
86: { NULL, post_std }, /* Ex */
87: { NULL, NULL }, /* Fa */
88: { NULL, NULL }, /* Fd */
89: { NULL, NULL }, /* Fl */
90: { NULL, NULL }, /* Fn */
91: { NULL, NULL }, /* Ft */
92: { NULL, NULL }, /* Ic */
93: { NULL, NULL }, /* In */
1.80 kristaps 94: { NULL, NULL }, /* Li */
1.1 kristaps 95: { NULL, NULL }, /* Nd */
1.85 kristaps 96: { NULL, NULL }, /* Nm */
1.1 kristaps 97: { NULL, NULL }, /* Op */
98: { NULL, NULL }, /* Ot */
1.85 kristaps 99: { NULL, NULL }, /* Pa */
1.1 kristaps 100: { NULL, post_std }, /* Rv */
1.84 kristaps 101: { NULL, NULL }, /* St */
1.1 kristaps 102: { NULL, NULL }, /* Va */
103: { NULL, NULL }, /* Vt */
104: { NULL, NULL }, /* Xr */
105: { NULL, NULL }, /* %A */
106: { NULL, NULL }, /* %B */
107: { NULL, NULL }, /* %D */
108: { NULL, NULL }, /* %I */
109: { NULL, NULL }, /* %J */
110: { NULL, NULL }, /* %N */
111: { NULL, NULL }, /* %O */
112: { NULL, NULL }, /* %P */
113: { NULL, NULL }, /* %R */
114: { NULL, NULL }, /* %T */
115: { NULL, NULL }, /* %V */
116: { NULL, NULL }, /* Ac */
117: { NULL, NULL }, /* Ao */
118: { NULL, NULL }, /* Aq */
1.82 kristaps 119: { NULL, NULL }, /* At */
1.1 kristaps 120: { NULL, NULL }, /* Bc */
121: { NULL, NULL }, /* Bf */
122: { NULL, NULL }, /* Bo */
123: { NULL, NULL }, /* Bq */
124: { NULL, NULL }, /* Bsx */
125: { NULL, NULL }, /* Bx */
126: { NULL, NULL }, /* Db */
127: { NULL, NULL }, /* Dc */
128: { NULL, NULL }, /* Do */
129: { NULL, NULL }, /* Dq */
130: { NULL, NULL }, /* Ec */
131: { NULL, NULL }, /* Ef */
132: { NULL, NULL }, /* Em */
133: { NULL, NULL }, /* Eo */
134: { NULL, NULL }, /* Fx */
135: { NULL, NULL }, /* Ms */
136: { NULL, NULL }, /* No */
137: { NULL, NULL }, /* Ns */
138: { NULL, NULL }, /* Nx */
139: { NULL, NULL }, /* Ox */
140: { NULL, NULL }, /* Pc */
141: { NULL, NULL }, /* Pf */
142: { NULL, NULL }, /* Po */
143: { NULL, NULL }, /* Pq */
144: { NULL, NULL }, /* Qc */
145: { NULL, NULL }, /* Ql */
146: { NULL, NULL }, /* Qo */
147: { NULL, NULL }, /* Qq */
148: { NULL, NULL }, /* Re */
1.79 kristaps 149: { NULL, NULL }, /* Rs */
1.1 kristaps 150: { NULL, NULL }, /* Sc */
151: { NULL, NULL }, /* So */
152: { NULL, NULL }, /* Sq */
153: { NULL, NULL }, /* Sm */
154: { NULL, NULL }, /* Sx */
155: { NULL, NULL }, /* Sy */
156: { NULL, NULL }, /* Tn */
157: { NULL, NULL }, /* Ux */
158: { NULL, NULL }, /* Xc */
159: { NULL, NULL }, /* Xo */
160: { NULL, NULL }, /* Fo */
161: { NULL, NULL }, /* Fc */
162: { NULL, NULL }, /* Oo */
163: { NULL, NULL }, /* Oc */
164: { NULL, NULL }, /* Bk */
165: { NULL, NULL }, /* Ek */
166: { NULL, NULL }, /* Bt */
167: { NULL, NULL }, /* Hf */
168: { NULL, NULL }, /* Fr */
169: { NULL, NULL }, /* Ud */
1.83 kristaps 170: { NULL, NULL }, /* Lb */
1.1 kristaps 171: { NULL, NULL }, /* Lp */
1.44 kristaps 172: { NULL, NULL }, /* Lk */
1.1 kristaps 173: { NULL, NULL }, /* Mt */
174: { NULL, NULL }, /* Brq */
175: { NULL, NULL }, /* Bro */
176: { NULL, NULL }, /* Brc */
177: { NULL, NULL }, /* %C */
178: { NULL, NULL }, /* Es */
179: { NULL, NULL }, /* En */
180: { NULL, NULL }, /* Dx */
181: { NULL, NULL }, /* %Q */
1.30 kristaps 182: { NULL, NULL }, /* br */
183: { NULL, NULL }, /* sp */
1.43 kristaps 184: { NULL, NULL }, /* %U */
1.64 kristaps 185: { NULL, NULL }, /* Ta */
1.1 kristaps 186: };
187:
1.2 kristaps 188:
1.1 kristaps 189: int
1.60 kristaps 190: mdoc_action_pre(struct mdoc *m, struct mdoc_node *n)
1.1 kristaps 191: {
192:
193: switch (n->type) {
194: case (MDOC_ROOT):
1.2 kristaps 195: /* FALLTHROUGH */
1.1 kristaps 196: case (MDOC_TEXT):
1.2 kristaps 197: return(1);
198: default:
1.1 kristaps 199: break;
200: }
1.2 kristaps 201:
1.6 kristaps 202: if (NULL == mdoc_actions[n->tok].pre)
1.2 kristaps 203: return(1);
1.6 kristaps 204: return((*mdoc_actions[n->tok].pre)(m, n));
1.1 kristaps 205: }
206:
207:
208: int
209: mdoc_action_post(struct mdoc *m)
210: {
211:
212: if (MDOC_ACTED & m->last->flags)
213: return(1);
214: m->last->flags |= MDOC_ACTED;
215:
216: switch (m->last->type) {
217: case (MDOC_TEXT):
1.2 kristaps 218: /* FALLTHROUGH */
1.1 kristaps 219: case (MDOC_ROOT):
1.2 kristaps 220: return(1);
221: default:
1.1 kristaps 222: break;
223: }
1.2 kristaps 224:
225: if (NULL == mdoc_actions[m->last->tok].post)
226: return(1);
1.35 kristaps 227: return((*mdoc_actions[m->last->tok].post)(m, m->last));
1.2 kristaps 228: }
229:
230:
1.46 kristaps 231: /*
232: * Concatenate sibling nodes together. All siblings must be of type
233: * MDOC_TEXT or an assertion is raised. Concatenation is separated by a
234: * single whitespace.
235: */
1.2 kristaps 236: static int
1.46 kristaps 237: concat(struct mdoc *m, char *p, const struct mdoc_node *n, size_t sz)
1.2 kristaps 238: {
239:
1.46 kristaps 240: assert(sz);
241: p[0] = '\0';
1.2 kristaps 242: for ( ; n; n = n->next) {
243: assert(MDOC_TEXT == n->type);
1.59 kristaps 244: /*
245: * XXX: yes, these can technically be resized, but it's
246: * highly unlikely that we're going to get here, so let
247: * it slip for now.
248: */
249: if (strlcat(p, n->string, sz) >= sz) {
250: mdoc_nmsg(m, n, MANDOCERR_MEM);
251: return(0);
252: }
1.2 kristaps 253: if (NULL == n->next)
254: continue;
1.59 kristaps 255: if (strlcat(p, " ", sz) >= sz) {
256: mdoc_nmsg(m, n, MANDOCERR_MEM);
257: return(0);
258: }
1.2 kristaps 259: }
260:
1.1 kristaps 261: return(1);
262: }
263:
264:
1.46 kristaps 265: /*
266: * Macros accepting `-std' as an argument have the name of the current
267: * document (`Nm') filled in as the argument if it's not provided.
268: */
1.1 kristaps 269: static int
270: post_std(POST_ARGS)
271: {
1.59 kristaps 272: struct mdoc_node *nn;
1.1 kristaps 273:
1.35 kristaps 274: if (n->child)
1.1 kristaps 275: return(1);
1.59 kristaps 276: if (NULL == m->meta.name)
277: return(1);
1.35 kristaps 278:
279: nn = n;
280: m->next = MDOC_NEXT_CHILD;
1.59 kristaps 281:
1.35 kristaps 282: if ( ! mdoc_word_alloc(m, n->line, n->pos, m->meta.name))
283: return(0);
284: m->last = nn;
1.1 kristaps 285: return(1);
286: }
287:
1.46 kristaps 288: /*
289: * Parse out the contents of `Dt'. See in-line documentation for how we
290: * handle the various fields of this macro.
291: */
1.1 kristaps 292: static int
293: post_dt(POST_ARGS)
294: {
1.35 kristaps 295: struct mdoc_node *nn;
1.1 kristaps 296: const char *cp;
297:
298: if (m->meta.title)
299: free(m->meta.title);
300: if (m->meta.vol)
301: free(m->meta.vol);
302: if (m->meta.arch)
303: free(m->meta.arch);
304:
305: m->meta.title = m->meta.vol = m->meta.arch = NULL;
306: /* Handles: `.Dt'
307: * --> title = unknown, volume = local, msec = 0, arch = NULL
308: */
309:
1.35 kristaps 310: if (NULL == (nn = n->child)) {
1.46 kristaps 311: /* XXX: make these macro values. */
1.58 kristaps 312: /* FIXME: warn about missing values. */
1.63 kristaps 313: m->meta.title = mandoc_strdup("UNKNOWN");
314: m->meta.vol = mandoc_strdup("LOCAL");
1.58 kristaps 315: m->meta.msec = mandoc_strdup("1");
1.35 kristaps 316: return(post_prol(m, n));
1.1 kristaps 317: }
318:
319: /* Handles: `.Dt TITLE'
320: * --> title = TITLE, volume = local, msec = 0, arch = NULL
321: */
322:
1.63 kristaps 323: m->meta.title = mandoc_strdup
324: ('\0' == nn->string[0] ? "UNKNOWN" : nn->string);
1.1 kristaps 325:
1.35 kristaps 326: if (NULL == (nn = nn->next)) {
1.58 kristaps 327: /* FIXME: warn about missing msec. */
1.46 kristaps 328: /* XXX: make this a macro value. */
1.63 kristaps 329: m->meta.vol = mandoc_strdup("LOCAL");
1.58 kristaps 330: m->meta.msec = mandoc_strdup("1");
1.35 kristaps 331: return(post_prol(m, n));
1.1 kristaps 332: }
333:
334: /* Handles: `.Dt TITLE SEC'
335: * --> title = TITLE, volume = SEC is msec ?
336: * format(msec) : SEC,
337: * msec = SEC is msec ? atoi(msec) : 0,
338: * arch = NULL
339: */
340:
1.35 kristaps 341: cp = mdoc_a2msec(nn->string);
1.1 kristaps 342: if (cp) {
1.46 kristaps 343: m->meta.vol = mandoc_strdup(cp);
1.58 kristaps 344: m->meta.msec = mandoc_strdup(nn->string);
1.59 kristaps 345: } else if (mdoc_nmsg(m, n, MANDOCERR_BADMSEC)) {
1.46 kristaps 346: m->meta.vol = mandoc_strdup(nn->string);
1.58 kristaps 347: m->meta.msec = mandoc_strdup(nn->string);
348: } else
349: return(0);
1.1 kristaps 350:
1.35 kristaps 351: if (NULL == (nn = nn->next))
352: return(post_prol(m, n));
1.1 kristaps 353:
354: /* Handles: `.Dt TITLE SEC VOL'
355: * --> title = TITLE, volume = VOL is vol ?
356: * format(VOL) :
357: * VOL is arch ? format(arch) :
358: * VOL
359: */
360:
1.35 kristaps 361: cp = mdoc_a2vol(nn->string);
1.1 kristaps 362: if (cp) {
363: free(m->meta.vol);
1.46 kristaps 364: m->meta.vol = mandoc_strdup(cp);
1.1 kristaps 365: } else {
1.58 kristaps 366: /* FIXME: warn about bad arch. */
1.35 kristaps 367: cp = mdoc_a2arch(nn->string);
1.1 kristaps 368: if (NULL == cp) {
369: free(m->meta.vol);
1.46 kristaps 370: m->meta.vol = mandoc_strdup(nn->string);
371: } else
372: m->meta.arch = mandoc_strdup(cp);
1.1 kristaps 373: }
374:
375: /* Ignore any subsequent parameters... */
1.46 kristaps 376: /* FIXME: warn about subsequent parameters. */
1.1 kristaps 377:
1.35 kristaps 378: return(post_prol(m, n));
1.1 kristaps 379: }
380:
381:
1.46 kristaps 382: /*
383: * Set the operating system by way of the `Os' macro. Note that if an
384: * argument isn't provided and -DOSNAME="\"foo\"" is provided during
385: * compilation, this value will be used instead of filling in "sysname
386: * release" from uname().
387: */
1.1 kristaps 388: static int
389: post_os(POST_ARGS)
390: {
1.46 kristaps 391: char buf[BUFSIZ];
392: #ifndef OSNAME
1.1 kristaps 393: struct utsname utsname;
1.42 kristaps 394: #endif
395:
1.1 kristaps 396: if (m->meta.os)
397: free(m->meta.os);
1.4 kristaps 398:
1.46 kristaps 399: if ( ! concat(m, buf, n->child, BUFSIZ))
1.2 kristaps 400: return(0);
1.1 kristaps 401:
1.59 kristaps 402: /* XXX: yes, these can all be dynamically-adjusted buffers, but
403: * it's really not worth the extra hackery.
404: */
405:
1.46 kristaps 406: if ('\0' == buf[0]) {
407: #ifdef OSNAME
1.59 kristaps 408: if (strlcat(buf, OSNAME, BUFSIZ) >= BUFSIZ) {
409: mdoc_nmsg(m, n, MANDOCERR_MEM);
410: return(0);
411: }
1.46 kristaps 412: #else /*!OSNAME */
1.1 kristaps 413: if (-1 == uname(&utsname))
1.59 kristaps 414: return(mdoc_nmsg(m, n, MANDOCERR_UTSNAME));
415:
416: if (strlcat(buf, utsname.sysname, BUFSIZ) >= BUFSIZ) {
417: mdoc_nmsg(m, n, MANDOCERR_MEM);
418: return(0);
419: }
420: if (strlcat(buf, " ", 64) >= BUFSIZ) {
421: mdoc_nmsg(m, n, MANDOCERR_MEM);
422: return(0);
423: }
424: if (strlcat(buf, utsname.release, BUFSIZ) >= BUFSIZ) {
425: mdoc_nmsg(m, n, MANDOCERR_MEM);
426: return(0);
427: }
1.46 kristaps 428: #endif /*!OSNAME*/
1.1 kristaps 429: }
430:
1.46 kristaps 431: m->meta.os = mandoc_strdup(buf);
1.35 kristaps 432: return(post_prol(m, n));
1.1 kristaps 433: }
434:
435:
436: /*
437: * Calculate the -width for a `Bl -tag' list if it hasn't been provided.
1.46 kristaps 438: * Uses the first head macro. NOTE AGAIN: this is ONLY if the -width
439: * argument has NOT been provided. See post_bl_width() for converting
440: * the -width string.
1.1 kristaps 441: */
442: static int
1.35 kristaps 443: post_bl_tagwidth(POST_ARGS)
1.1 kristaps 444: {
1.46 kristaps 445: struct mdoc_node *nn;
1.69 kristaps 446: size_t sz, ssz;
1.46 kristaps 447: int i;
448: char buf[NUMSIZ];
1.1 kristaps 449:
1.69 kristaps 450: sz = 10;
1.61 joerg 451:
452: for (nn = n->body->child; nn; nn = nn->next) {
1.69 kristaps 453: if (MDOC_It != nn->tok)
454: continue;
1.46 kristaps 455:
1.35 kristaps 456: assert(MDOC_BLOCK == nn->type);
457: nn = nn->head->child;
1.78 joerg 458:
459: if (nn == NULL) {
460: /* No -width for .Bl and first .It is emtpy */
461: if ( ! mdoc_nmsg(m, n, MANDOCERR_NOWIDTHARG))
462: return(0);
463: break;
464: }
1.69 kristaps 465:
466: if (MDOC_TEXT == nn->type) {
1.46 kristaps 467: sz = strlen(nn->string) + 1;
1.69 kristaps 468: break;
469: }
470:
471: if (0 != (ssz = mdoc_macro2len(nn->tok)))
472: sz = ssz;
473: else if ( ! mdoc_nmsg(m, n, MANDOCERR_NOWIDTHARG))
474: return(0);
475:
476: break;
1.1 kristaps 477: }
478:
1.69 kristaps 479: /* Defaults to ten ens. */
480:
1.46 kristaps 481: snprintf(buf, NUMSIZ, "%zun", sz);
1.1 kristaps 482:
483: /*
484: * We have to dynamically add this to the macro's argument list.
485: * We're guaranteed that a MDOC_Width doesn't already exist.
486: */
487:
1.70 kristaps 488: assert(n->args);
489: i = (int)(n->args->argc)++;
490:
491: n->args->argv = mandoc_realloc(n->args->argv,
492: n->args->argc * sizeof(struct mdoc_argv));
1.1 kristaps 493:
1.70 kristaps 494: n->args->argv[i].arg = MDOC_Width;
495: n->args->argv[i].line = n->line;
496: n->args->argv[i].pos = n->pos;
497: n->args->argv[i].sz = 1;
498: n->args->argv[i].value = mandoc_malloc(sizeof(char *));
499: n->args->argv[i].value[0] = mandoc_strdup(buf);
1.1 kristaps 500:
1.70 kristaps 501: /* Set our width! */
1.74 kristaps 502: n->data.Bl->width = n->args->argv[i].value[0];
1.1 kristaps 503: return(1);
504: }
505:
506:
1.46 kristaps 507: /*
508: * Calculate the real width of a list from the -width string, which may
509: * contain a macro (with a known default width), a literal string, or a
510: * scaling width.
511: */
1.1 kristaps 512: static int
1.70 kristaps 513: post_bl_width(POST_ARGS)
1.1 kristaps 514: {
515: size_t width;
1.70 kristaps 516: int i;
1.51 kristaps 517: enum mdoct tok;
1.46 kristaps 518: char buf[NUMSIZ];
1.1 kristaps 519:
520: /*
521: * If the value to -width is a macro, then we re-write it to be
522: * the macro's width as set in share/tmac/mdoc/doc-common.
523: */
524:
1.74 kristaps 525: if (0 == strcmp(n->data.Bl->width, "Ds"))
1.18 kristaps 526: width = 6;
1.74 kristaps 527: else if (MDOC_MAX == (tok = mdoc_hash_find(n->data.Bl->width)))
1.1 kristaps 528: return(1);
529: else if (0 == (width = mdoc_macro2len(tok)))
1.59 kristaps 530: return(mdoc_nmsg(m, n, MANDOCERR_BADWIDTH));
1.1 kristaps 531:
532: /* The value already exists: free and reallocate it. */
533:
1.70 kristaps 534: assert(n->args);
535:
536: for (i = 0; i < (int)n->args->argc; i++)
537: if (MDOC_Width == n->args->argv[i].arg)
538: break;
539:
540: assert(i < (int)n->args->argc);
541:
1.46 kristaps 542: snprintf(buf, NUMSIZ, "%zun", width);
1.70 kristaps 543: free(n->args->argv[i].value[0]);
544: n->args->argv[i].value[0] = mandoc_strdup(buf);
545:
546: /* Set our width! */
1.74 kristaps 547: n->data.Bl->width = n->args->argv[i].value[0];
1.1 kristaps 548: return(1);
549: }
550:
551:
1.14 kristaps 552: static int
1.1 kristaps 553: post_bl(POST_ARGS)
554: {
555:
1.35 kristaps 556: if (MDOC_BLOCK != n->type)
1.1 kristaps 557: return(1);
558:
559: /*
560: * These are fairly complicated, so we've broken them into two
561: * functions. post_bl_tagwidth() is called when a -tag is
562: * specified, but no -width (it must be guessed). The second
563: * when a -width is specified (macro indicators must be
564: * rewritten into real lengths).
565: */
566:
1.74 kristaps 567: if (LIST_tag == n->data.Bl->type && NULL == n->data.Bl->width) {
1.35 kristaps 568: if ( ! post_bl_tagwidth(m, n))
1.1 kristaps 569: return(0);
1.74 kristaps 570: } else if (NULL != n->data.Bl->width) {
1.70 kristaps 571: if ( ! post_bl_width(m, n))
1.1 kristaps 572: return(0);
1.70 kristaps 573: } else
574: return(1);
575:
1.74 kristaps 576: assert(n->data.Bl->width);
1.1 kristaps 577: return(1);
578: }
579:
1.46 kristaps 580: /*
1.49 kristaps 581: * Parse the date field in `Dd'.
1.46 kristaps 582: */
1.1 kristaps 583: static int
584: post_dd(POST_ARGS)
585: {
1.46 kristaps 586: char buf[DATESIZ];
1.77 kristaps 587:
588: if (NULL == n->child) {
589: m->meta.date = time(NULL);
590: return(post_prol(m, n));
591: }
1.1 kristaps 592:
1.46 kristaps 593: if ( ! concat(m, buf, n->child, DATESIZ))
1.2 kristaps 594: return(0);
1.1 kristaps 595:
1.49 kristaps 596: m->meta.date = mandoc_a2time
597: (MTIME_MDOCDATE | MTIME_CANONICAL, buf);
598:
1.46 kristaps 599: if (0 == m->meta.date) {
1.59 kristaps 600: if ( ! mdoc_nmsg(m, n, MANDOCERR_BADDATE))
1.1 kristaps 601: return(0);
602: m->meta.date = time(NULL);
603: }
604:
1.35 kristaps 605: return(post_prol(m, n));
1.1 kristaps 606: }
607:
608:
1.46 kristaps 609: /*
610: * Remove prologue macros from the document after they're processed.
611: * The final document uses mdoc_meta for these values and discards the
612: * originals.
613: */
1.1 kristaps 614: static int
615: post_prol(POST_ARGS)
616: {
1.34 kristaps 617:
1.53 kristaps 618: mdoc_node_delete(m, n);
1.34 kristaps 619: if (m->meta.title && m->meta.date && m->meta.os)
620: m->flags |= MDOC_PBODY;
1.39 kristaps 621: return(1);
622: }
CVSweb