Annotation of mandoc/mdoc_macro.c, Revision 1.182
1.182 ! schwarze 1: /* $Id: mdoc_macro.c,v 1.181 2015/02/10 17:47:45 schwarze Exp $ */
1.1 kristaps 2: /*
1.116 schwarze 3: * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
1.162 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.8 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.8 kristaps 10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
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.40 kristaps 18: #include "config.h"
1.140 schwarze 19:
20: #include <sys/types.h>
1.40 kristaps 21:
1.1 kristaps 22: #include <assert.h>
23: #include <ctype.h>
24: #include <stdlib.h>
25: #include <stdio.h>
26: #include <string.h>
1.38 kristaps 27: #include <time.h>
1.1 kristaps 28:
1.106 kristaps 29: #include "mdoc.h"
1.68 kristaps 30: #include "mandoc.h"
1.1 kristaps 31: #include "libmdoc.h"
1.64 kristaps 32: #include "libmandoc.h"
1.1 kristaps 33:
1.151 schwarze 34: static void blk_full(MACRO_PROT_ARGS);
35: static void blk_exp_close(MACRO_PROT_ARGS);
36: static void blk_part_exp(MACRO_PROT_ARGS);
37: static void blk_part_imp(MACRO_PROT_ARGS);
38: static void ctx_synopsis(MACRO_PROT_ARGS);
39: static void in_line_eoln(MACRO_PROT_ARGS);
40: static void in_line_argn(MACRO_PROT_ARGS);
41: static void in_line(MACRO_PROT_ARGS);
42: static void phrase_ta(MACRO_PROT_ARGS);
1.53 kristaps 43:
1.150 schwarze 44: static void dword(struct mdoc *, int, int, const char *,
1.123 schwarze 45: enum mdelim, int);
1.150 schwarze 46: static void append_delims(struct mdoc *, int, int *, char *);
1.155 schwarze 47: static enum mdoct lookup(struct mdoc *, enum mdoct,
48: int, int, const char *);
1.153 schwarze 49: static int macro_or_word(MACRO_PROT_ARGS, int);
1.168 schwarze 50: static void make_pending(struct mdoc *, struct mdoc_node *,
51: struct mdoc_node *, int, int);
1.154 schwarze 52: static int parse_rest(struct mdoc *, enum mdoct,
53: int, int *, char *);
1.131 schwarze 54: static enum mdoct rew_alt(enum mdoct);
1.149 schwarze 55: static void rew_elem(struct mdoc *, enum mdoct);
56: static void rew_last(struct mdoc *, const struct mdoc_node *);
1.166 schwarze 57: static void rew_pending(struct mdoc *, const struct mdoc_node *);
1.1 kristaps 58:
59: const struct mdoc_macro __mdoc_macros[MDOC_MAX] = {
1.123 schwarze 60: { in_line_argn, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Ap */
1.1 kristaps 61: { in_line_eoln, MDOC_PROLOGUE }, /* Dd */
62: { in_line_eoln, MDOC_PROLOGUE }, /* Dt */
63: { in_line_eoln, MDOC_PROLOGUE }, /* Os */
1.123 schwarze 64: { blk_full, MDOC_PARSED | MDOC_JOIN }, /* Sh */
65: { blk_full, MDOC_PARSED | MDOC_JOIN }, /* Ss */
66: { in_line_eoln, 0 }, /* Pp */
67: { blk_part_imp, MDOC_PARSED | MDOC_JOIN }, /* D1 */
68: { blk_part_imp, MDOC_PARSED | MDOC_JOIN }, /* Dl */
1.1 kristaps 69: { blk_full, MDOC_EXPLICIT }, /* Bd */
1.123 schwarze 70: { blk_exp_close, MDOC_EXPLICIT | MDOC_JOIN }, /* Ed */
1.1 kristaps 71: { blk_full, MDOC_EXPLICIT }, /* Bl */
1.123 schwarze 72: { blk_exp_close, MDOC_EXPLICIT | MDOC_JOIN }, /* El */
73: { blk_full, MDOC_PARSED | MDOC_JOIN }, /* It */
74: { in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Ad */
75: { in_line, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* An */
1.1 kristaps 76: { in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Ar */
1.129 schwarze 77: { in_line, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Cd */
1.1 kristaps 78: { in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Cm */
1.123 schwarze 79: { in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Dv */
80: { in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Er */
81: { in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Ev */
1.1 kristaps 82: { in_line_eoln, 0 }, /* Ex */
1.123 schwarze 83: { in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Fa */
84: { in_line_eoln, 0 }, /* Fd */
1.1 kristaps 85: { in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Fl */
1.123 schwarze 86: { in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Fn */
87: { in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Ft */
1.128 schwarze 88: { in_line, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Ic */
1.18 kristaps 89: { in_line_argn, MDOC_CALLABLE | MDOC_PARSED }, /* In */
1.123 schwarze 90: { in_line, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Li */
91: { blk_full, MDOC_JOIN }, /* Nd */
92: { ctx_synopsis, MDOC_CALLABLE | MDOC_PARSED }, /* Nm */
1.1 kristaps 93: { blk_part_imp, MDOC_CALLABLE | MDOC_PARSED }, /* Op */
1.132 schwarze 94: { in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Ot */
1.1 kristaps 95: { in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Pa */
96: { in_line_eoln, 0 }, /* Rv */
1.123 schwarze 97: { in_line_argn, MDOC_CALLABLE | MDOC_PARSED }, /* St */
1.1 kristaps 98: { in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Va */
1.123 schwarze 99: { ctx_synopsis, MDOC_CALLABLE | MDOC_PARSED }, /* Vt */
1.42 kristaps 100: { in_line_argn, MDOC_CALLABLE | MDOC_PARSED }, /* Xr */
1.123 schwarze 101: { in_line_eoln, MDOC_JOIN }, /* %A */
102: { in_line_eoln, MDOC_JOIN }, /* %B */
103: { in_line_eoln, MDOC_JOIN }, /* %D */
104: { in_line_eoln, MDOC_JOIN }, /* %I */
105: { in_line_eoln, MDOC_JOIN }, /* %J */
1.1 kristaps 106: { in_line_eoln, 0 }, /* %N */
1.123 schwarze 107: { in_line_eoln, MDOC_JOIN }, /* %O */
1.1 kristaps 108: { in_line_eoln, 0 }, /* %P */
1.123 schwarze 109: { in_line_eoln, MDOC_JOIN }, /* %R */
110: { in_line_eoln, MDOC_JOIN }, /* %T */
1.1 kristaps 111: { in_line_eoln, 0 }, /* %V */
1.123 schwarze 112: { blk_exp_close, MDOC_CALLABLE | MDOC_PARSED |
113: MDOC_EXPLICIT | MDOC_JOIN }, /* Ac */
114: { blk_part_exp, MDOC_CALLABLE | MDOC_PARSED |
115: MDOC_EXPLICIT | MDOC_JOIN }, /* Ao */
116: { blk_part_imp, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Aq */
1.1 kristaps 117: { in_line_argn, MDOC_CALLABLE | MDOC_PARSED }, /* At */
1.123 schwarze 118: { blk_exp_close, MDOC_CALLABLE | MDOC_PARSED |
119: MDOC_EXPLICIT | MDOC_JOIN }, /* Bc */
120: { blk_full, MDOC_EXPLICIT }, /* Bf */
121: { blk_part_exp, MDOC_CALLABLE | MDOC_PARSED |
122: MDOC_EXPLICIT | MDOC_JOIN }, /* Bo */
123: { blk_part_imp, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Bq */
1.1 kristaps 124: { in_line_argn, MDOC_CALLABLE | MDOC_PARSED }, /* Bsx */
125: { in_line_argn, MDOC_CALLABLE | MDOC_PARSED }, /* Bx */
126: { in_line_eoln, 0 }, /* Db */
1.123 schwarze 127: { blk_exp_close, MDOC_CALLABLE | MDOC_PARSED |
128: MDOC_EXPLICIT | MDOC_JOIN }, /* Dc */
129: { blk_part_exp, MDOC_CALLABLE | MDOC_PARSED |
130: MDOC_EXPLICIT | MDOC_JOIN }, /* Do */
131: { blk_part_imp, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Dq */
132: { blk_exp_close, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Ec */
133: { blk_exp_close, MDOC_EXPLICIT | MDOC_JOIN }, /* Ef */
134: { in_line, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Em */
1.1 kristaps 135: { blk_part_exp, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Eo */
136: { in_line_argn, MDOC_CALLABLE | MDOC_PARSED }, /* Fx */
1.11 kristaps 137: { in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Ms */
1.144 schwarze 138: { in_line, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* No */
1.123 schwarze 139: { in_line_argn, MDOC_CALLABLE | MDOC_PARSED |
140: MDOC_IGNDELIM | MDOC_JOIN }, /* Ns */
1.1 kristaps 141: { in_line_argn, MDOC_CALLABLE | MDOC_PARSED }, /* Nx */
142: { in_line_argn, MDOC_CALLABLE | MDOC_PARSED }, /* Ox */
1.123 schwarze 143: { blk_exp_close, MDOC_CALLABLE | MDOC_PARSED |
144: MDOC_EXPLICIT | MDOC_JOIN }, /* Pc */
1.52 kristaps 145: { in_line_argn, MDOC_CALLABLE | MDOC_PARSED | MDOC_IGNDELIM }, /* Pf */
1.123 schwarze 146: { blk_part_exp, MDOC_CALLABLE | MDOC_PARSED |
147: MDOC_EXPLICIT | MDOC_JOIN }, /* Po */
148: { blk_part_imp, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Pq */
149: { blk_exp_close, MDOC_CALLABLE | MDOC_PARSED |
150: MDOC_EXPLICIT | MDOC_JOIN }, /* Qc */
151: { blk_part_imp, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Ql */
152: { blk_part_exp, MDOC_CALLABLE | MDOC_PARSED |
153: MDOC_EXPLICIT | MDOC_JOIN }, /* Qo */
154: { blk_part_imp, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Qq */
155: { blk_exp_close, MDOC_EXPLICIT | MDOC_JOIN }, /* Re */
1.1 kristaps 156: { blk_full, MDOC_EXPLICIT }, /* Rs */
1.123 schwarze 157: { blk_exp_close, MDOC_CALLABLE | MDOC_PARSED |
158: MDOC_EXPLICIT | MDOC_JOIN }, /* Sc */
159: { blk_part_exp, MDOC_CALLABLE | MDOC_PARSED |
160: MDOC_EXPLICIT | MDOC_JOIN }, /* So */
161: { blk_part_imp, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Sq */
1.147 schwarze 162: { in_line_argn, 0 }, /* Sm */
1.123 schwarze 163: { in_line, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Sx */
164: { in_line, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Sy */
1.1 kristaps 165: { in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Tn */
1.123 schwarze 166: { in_line_argn, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Ux */
1.1 kristaps 167: { blk_exp_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Xc */
168: { blk_part_exp, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Xo */
1.123 schwarze 169: { blk_full, MDOC_EXPLICIT | MDOC_CALLABLE }, /* Fo */
170: { blk_exp_close, MDOC_CALLABLE | MDOC_PARSED |
171: MDOC_EXPLICIT | MDOC_JOIN }, /* Fc */
172: { blk_part_exp, MDOC_CALLABLE | MDOC_PARSED |
173: MDOC_EXPLICIT | MDOC_JOIN }, /* Oo */
174: { blk_exp_close, MDOC_CALLABLE | MDOC_PARSED |
175: MDOC_EXPLICIT | MDOC_JOIN }, /* Oc */
1.1 kristaps 176: { blk_full, MDOC_EXPLICIT }, /* Bk */
1.123 schwarze 177: { blk_exp_close, MDOC_EXPLICIT | MDOC_JOIN }, /* Ek */
1.1 kristaps 178: { in_line_eoln, 0 }, /* Bt */
179: { in_line_eoln, 0 }, /* Hf */
1.132 schwarze 180: { in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Fr */
1.1 kristaps 181: { in_line_eoln, 0 }, /* Ud */
1.69 kristaps 182: { in_line, 0 }, /* Lb */
1.123 schwarze 183: { in_line_eoln, 0 }, /* Lp */
184: { in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Lk */
185: { in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Mt */
186: { blk_part_imp, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Brq */
187: { blk_part_exp, MDOC_CALLABLE | MDOC_PARSED |
188: MDOC_EXPLICIT | MDOC_JOIN }, /* Bro */
189: { blk_exp_close, MDOC_CALLABLE | MDOC_PARSED |
190: MDOC_EXPLICIT | MDOC_JOIN }, /* Brc */
191: { in_line_eoln, MDOC_JOIN }, /* %C */
1.132 schwarze 192: { in_line_argn, MDOC_CALLABLE | MDOC_PARSED }, /* Es */
193: { blk_part_imp, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* En */
1.1 kristaps 194: { in_line_argn, MDOC_CALLABLE | MDOC_PARSED }, /* Dx */
1.123 schwarze 195: { in_line_eoln, MDOC_JOIN }, /* %Q */
1.20 kristaps 196: { in_line_eoln, 0 }, /* br */
197: { in_line_eoln, 0 }, /* sp */
1.37 kristaps 198: { in_line_eoln, 0 }, /* %U */
1.123 schwarze 199: { phrase_ta, MDOC_CALLABLE | MDOC_PARSED | MDOC_JOIN }, /* Ta */
1.143 schwarze 200: { in_line_eoln, MDOC_PROLOGUE }, /* ll */
1.1 kristaps 201: };
202:
203: const struct mdoc_macro * const mdoc_macros = __mdoc_macros;
204:
205:
206: /*
207: * This is called at the end of parsing. It must traverse up the tree,
208: * closing out open [implicit] scopes. Obviously, open explicit scopes
209: * are errors.
210: */
1.151 schwarze 211: void
1.119 schwarze 212: mdoc_macroend(struct mdoc *mdoc)
1.1 kristaps 213: {
214: struct mdoc_node *n;
215:
216: /* Scan for open explicit scopes. */
217:
1.151 schwarze 218: n = mdoc->last->flags & MDOC_VALID ?
1.131 schwarze 219: mdoc->last->parent : mdoc->last;
1.1 kristaps 220:
1.94 schwarze 221: for ( ; n; n = n->parent)
1.151 schwarze 222: if (n->type == MDOC_BLOCK &&
223: mdoc_macros[n->tok].flags & MDOC_EXPLICIT)
1.137 schwarze 224: mandoc_msg(MANDOCERR_BLK_NOEND, mdoc->parse,
225: n->line, n->pos, mdoc_macronames[n->tok]);
1.1 kristaps 226:
1.32 kristaps 227: /* Rewind to the first. */
228:
1.149 schwarze 229: rew_last(mdoc, mdoc->first);
1.1 kristaps 230: }
231:
1.32 kristaps 232: /*
1.153 schwarze 233: * Look up the macro at *p called by "from",
234: * or as a line macro if from == MDOC_MAX.
1.32 kristaps 235: */
1.53 kristaps 236: static enum mdoct
1.155 schwarze 237: lookup(struct mdoc *mdoc, enum mdoct from, int line, int ppos, const char *p)
1.28 kristaps 238: {
1.58 kristaps 239: enum mdoct res;
1.1 kristaps 240:
1.153 schwarze 241: if (from == MDOC_MAX || mdoc_macros[from].flags & MDOC_PARSED) {
242: res = mdoc_hash_find(p);
1.155 schwarze 243: if (res != MDOC_MAX) {
244: if (mdoc_macros[res].flags & MDOC_CALLABLE)
245: return(res);
246: if (res != MDOC_br && res != MDOC_sp && res != MDOC_ll)
247: mandoc_msg(MANDOCERR_MACRO_CALL,
248: mdoc->parse, line, ppos, p);
249: }
1.153 schwarze 250: }
1.1 kristaps 251: return(MDOC_MAX);
252: }
253:
1.166 schwarze 254: /*
255: * Rewind up to and including a specific node.
256: */
1.149 schwarze 257: static void
1.32 kristaps 258: rew_last(struct mdoc *mdoc, const struct mdoc_node *to)
1.1 kristaps 259: {
1.100 kristaps 260: struct mdoc_node *n, *np;
1.1 kristaps 261:
262: assert(to);
263: mdoc->next = MDOC_NEXT_SIBLING;
264: while (mdoc->last != to) {
1.100 kristaps 265: /*
266: * Save the parent here, because we may delete the
1.119 schwarze 267: * mdoc->last node in the post-validation phase and reset
268: * it to mdoc->last->parent, causing a step in the closing
1.100 kristaps 269: * out to be lost.
270: */
271: np = mdoc->last->parent;
1.149 schwarze 272: mdoc_valid_post(mdoc);
1.99 kristaps 273: n = mdoc->last;
1.100 kristaps 274: mdoc->last = np;
1.1 kristaps 275: assert(mdoc->last);
1.99 kristaps 276: mdoc->last->last = n;
1.1 kristaps 277: }
1.149 schwarze 278: mdoc_valid_post(mdoc);
1.1 kristaps 279: }
280:
1.32 kristaps 281: /*
1.166 schwarze 282: * Rewind up to a specific block, including all blocks that broke it.
283: */
284: static void
285: rew_pending(struct mdoc *mdoc, const struct mdoc_node *n)
286: {
287:
288: rew_last(mdoc, n);
289:
290: if (n->type != MDOC_BLOCK)
291: return;
292:
293: while ((n = n->pending) != NULL) {
294: rew_last(mdoc, n);
295: if (n->type == MDOC_HEAD)
296: mdoc_body_alloc(mdoc, n->line, n->pos, n->tok);
297: }
298: }
299:
300: /*
1.84 schwarze 301: * For a block closing macro, return the corresponding opening one.
302: * Otherwise, return the macro itself.
1.32 kristaps 303: */
1.47 kristaps 304: static enum mdoct
305: rew_alt(enum mdoct tok)
1.1 kristaps 306: {
307: switch (tok) {
1.131 schwarze 308: case MDOC_Ac:
1.1 kristaps 309: return(MDOC_Ao);
1.131 schwarze 310: case MDOC_Bc:
1.1 kristaps 311: return(MDOC_Bo);
1.131 schwarze 312: case MDOC_Brc:
1.1 kristaps 313: return(MDOC_Bro);
1.131 schwarze 314: case MDOC_Dc:
1.1 kristaps 315: return(MDOC_Do);
1.131 schwarze 316: case MDOC_Ec:
1.1 kristaps 317: return(MDOC_Eo);
1.131 schwarze 318: case MDOC_Ed:
1.1 kristaps 319: return(MDOC_Bd);
1.131 schwarze 320: case MDOC_Ef:
1.1 kristaps 321: return(MDOC_Bf);
1.131 schwarze 322: case MDOC_Ek:
1.1 kristaps 323: return(MDOC_Bk);
1.131 schwarze 324: case MDOC_El:
1.1 kristaps 325: return(MDOC_Bl);
1.131 schwarze 326: case MDOC_Fc:
1.1 kristaps 327: return(MDOC_Fo);
1.131 schwarze 328: case MDOC_Oc:
1.1 kristaps 329: return(MDOC_Oo);
1.131 schwarze 330: case MDOC_Pc:
1.1 kristaps 331: return(MDOC_Po);
1.131 schwarze 332: case MDOC_Qc:
1.1 kristaps 333: return(MDOC_Qo);
1.131 schwarze 334: case MDOC_Re:
1.1 kristaps 335: return(MDOC_Rs);
1.131 schwarze 336: case MDOC_Sc:
1.1 kristaps 337: return(MDOC_So);
1.131 schwarze 338: case MDOC_Xc:
1.1 kristaps 339: return(MDOC_Xo);
340: default:
1.84 schwarze 341: return(tok);
1.1 kristaps 342: }
343: /* NOTREACHED */
344: }
345:
1.149 schwarze 346: static void
1.47 kristaps 347: rew_elem(struct mdoc *mdoc, enum mdoct tok)
1.1 kristaps 348: {
349: struct mdoc_node *n;
350:
351: n = mdoc->last;
352: if (MDOC_ELEM != n->type)
353: n = n->parent;
354: assert(MDOC_ELEM == n->type);
355: assert(tok == n->tok);
1.149 schwarze 356: rew_last(mdoc, n);
1.1 kristaps 357: }
358:
1.83 schwarze 359: /*
1.168 schwarze 360: * We are trying to close the block *breaker,
1.83 schwarze 361: * but the child block *broken is still open.
1.168 schwarze 362: * Thus, postpone closing the *breaker
1.167 schwarze 363: * until the rew_pending() call closing *broken.
1.83 schwarze 364: */
1.168 schwarze 365: static void
366: make_pending(struct mdoc *mdoc, struct mdoc_node *breaker,
367: struct mdoc_node *broken, int line, int ppos)
1.83 schwarze 368: {
1.168 schwarze 369: struct mdoc_node *n;
1.83 schwarze 370:
1.169 schwarze 371: mandoc_vmsg(MANDOCERR_BLK_NEST, mdoc->parse, line, ppos,
372: "%s breaks %s", mdoc_macronames[breaker->tok],
373: mdoc_macronames[broken->tok]);
1.168 schwarze 374:
1.169 schwarze 375: /*
376: * If the *broken block (Z) is already broken by a block (B)
377: * contained in the breaker (A), make the breaker pending
378: * on that inner breaker (B). Graphically,
379: *
380: * breaker=[A! broken=n=[B!->A (old broken=)[Z->B B] A] Z]
381: *
382: * In these graphics, "->" indicates the "pending" pointer and
383: * "!" indicates the MDOC_BREAK flag. Each of the cases gets
384: * one additional pointer (B->A) and one additional flag (A!).
385: */
1.83 schwarze 386:
1.169 schwarze 387: for (n = broken->parent; ; n = n->parent)
388: if (n == broken->pending)
1.168 schwarze 389: broken = n;
1.169 schwarze 390: else if (n == breaker)
391: break;
392:
393: /*
394: * Found the breaker.
395: *
396: * If another, outer breaker (X) is already pending on
397: * the *broken block (B), we must not clobber the link
398: * to the outer breaker, but make it pending on the new,
399: * now inner breaker (A). Graphically,
400: *
401: * [X! n=breaker=[A!->X broken=[B(->X)->A X] A] B].
402: */
1.83 schwarze 403:
1.169 schwarze 404: if (broken->pending != NULL) {
405: n = breaker;
1.83 schwarze 406:
407: /*
1.169 schwarze 408: * If the inner breaker (A) is already broken, too,
409: * it cannot take on the outer breaker (X) but must
410: * hand it on to its own breakers (Y). Graphically,
411: *
412: * [X! n=[Y!->X breaker=[A!->Y Y] broken=[B(->X)->A X] A] B]
1.83 schwarze 413: */
414:
1.169 schwarze 415: while (n->pending)
416: n = n->pending;
417: n->pending = broken->pending;
418: }
419:
420: /*
421: * Now we have reduced the situation to the simplest case:
422: * breaker=[A! broken=[B->A A] B].
423: */
1.158 schwarze 424:
1.169 schwarze 425: broken->pending = breaker;
426: breaker->flags |= MDOC_BREAK;
427: if (breaker->body != NULL)
428: breaker->body->flags |= MDOC_BREAK;
1.83 schwarze 429: }
430:
1.105 kristaps 431: /*
432: * Allocate a word and check whether it's punctuation or not.
433: * Punctuation consists of those tokens found in mdoc_isdelim().
434: */
1.150 schwarze 435: static void
1.123 schwarze 436: dword(struct mdoc *mdoc, int line, int col, const char *p,
437: enum mdelim d, int may_append)
1.105 kristaps 438: {
1.131 schwarze 439:
1.150 schwarze 440: if (d == DELIM_MAX)
1.105 kristaps 441: d = mdoc_isdelim(p);
442:
1.123 schwarze 443: if (may_append &&
1.150 schwarze 444: ! (mdoc->flags & (MDOC_SYNOPSIS | MDOC_KEEP | MDOC_SMOFF)) &&
445: d == DELIM_NONE && mdoc->last->type == MDOC_TEXT &&
446: mdoc_isdelim(mdoc->last->string) == DELIM_NONE) {
1.123 schwarze 447: mdoc_word_append(mdoc, p);
1.150 schwarze 448: return;
1.123 schwarze 449: }
450:
1.150 schwarze 451: mdoc_word_alloc(mdoc, line, col, p);
1.105 kristaps 452:
1.108 schwarze 453: /*
1.144 schwarze 454: * If the word consists of a bare delimiter,
455: * flag the new node accordingly,
456: * unless doing so was vetoed by the invoking macro.
457: * Always clear the veto, it is only valid for one word.
1.108 schwarze 458: */
459:
1.144 schwarze 460: if (d == DELIM_OPEN)
461: mdoc->last->flags |= MDOC_DELIMO;
462: else if (d == DELIM_CLOSE &&
463: ! (mdoc->flags & MDOC_NODELIMC) &&
1.131 schwarze 464: mdoc->last->parent->tok != MDOC_Fd)
1.119 schwarze 465: mdoc->last->flags |= MDOC_DELIMC;
1.144 schwarze 466: mdoc->flags &= ~MDOC_NODELIMC;
1.105 kristaps 467: }
1.1 kristaps 468:
1.150 schwarze 469: static void
1.119 schwarze 470: append_delims(struct mdoc *mdoc, int line, int *pos, char *buf)
1.1 kristaps 471: {
1.153 schwarze 472: char *p;
1.66 kristaps 473: int la;
1.1 kristaps 474:
1.150 schwarze 475: if (buf[*pos] == '\0')
476: return;
1.1 kristaps 477:
478: for (;;) {
1.66 kristaps 479: la = *pos;
1.153 schwarze 480: if (mdoc_args(mdoc, line, pos, buf, MDOC_MAX, &p) == ARGS_EOLN)
1.1 kristaps 481: break;
1.123 schwarze 482: dword(mdoc, line, la, p, DELIM_MAX, 1);
1.66 kristaps 483:
484: /*
485: * If we encounter end-of-sentence symbols, then trigger
486: * the double-space.
487: *
1.109 kristaps 488: * XXX: it's easy to allow this to propagate outward to
1.66 kristaps 489: * the last symbol, such that `. )' will cause the
490: * correct double-spacing. However, (1) groff isn't
491: * smart enough to do this and (2) it would require
492: * knowing which symbols break this behaviour, for
1.109 kristaps 493: * example, `. ;' shouldn't propagate the double-space.
1.66 kristaps 494: */
1.150 schwarze 495:
1.127 schwarze 496: if (mandoc_eos(p, strlen(p)))
1.119 schwarze 497: mdoc->last->flags |= MDOC_EOS;
1.1 kristaps 498: }
499: }
500:
501: /*
1.153 schwarze 502: * Parse one word.
503: * If it is a macro, call it and return 1.
504: * Otherwise, allocate it and return 0.
505: */
506: static int
507: macro_or_word(MACRO_PROT_ARGS, int parsed)
508: {
509: char *p;
510: enum mdoct ntok;
511:
512: p = buf + ppos;
513: ntok = MDOC_MAX;
1.157 schwarze 514: if (*p == '"')
1.153 schwarze 515: p++;
1.157 schwarze 516: else if (parsed && ! (mdoc->flags & MDOC_PHRASELIT))
1.155 schwarze 517: ntok = lookup(mdoc, tok, line, ppos, p);
1.153 schwarze 518:
519: if (ntok == MDOC_MAX) {
520: dword(mdoc, line, ppos, p, DELIM_MAX, tok == MDOC_MAX ||
521: mdoc_macros[tok].flags & MDOC_JOIN);
522: return(0);
523: } else {
524: if (mdoc_macros[tok].fp == in_line_eoln)
525: rew_elem(mdoc, tok);
526: mdoc_macro(mdoc, ntok, line, ppos, pos, buf);
527: if (tok == MDOC_MAX)
528: append_delims(mdoc, line, pos, buf);
529: return(1);
530: }
531: }
532:
533: /*
1.131 schwarze 534: * Close out block partial/full explicit.
1.1 kristaps 535: */
1.151 schwarze 536: static void
1.1 kristaps 537: blk_exp_close(MACRO_PROT_ARGS)
538: {
1.83 schwarze 539: struct mdoc_node *body; /* Our own body. */
1.148 schwarze 540: struct mdoc_node *endbody; /* Our own end marker. */
1.171 schwarze 541: struct mdoc_node *itblk; /* An It block starting later. */
1.83 schwarze 542: struct mdoc_node *later; /* A sub-block starting later. */
1.166 schwarze 543: struct mdoc_node *n; /* Search back to our block. */
1.83 schwarze 544:
1.171 schwarze 545: int j, lastarg, maxargs, nl;
1.55 kristaps 546: enum margserr ac;
1.83 schwarze 547: enum mdoct atok, ntok;
1.1 kristaps 548: char *p;
549:
1.119 schwarze 550: nl = MDOC_NEWLINE & mdoc->flags;
1.60 kristaps 551:
1.1 kristaps 552: switch (tok) {
1.131 schwarze 553: case MDOC_Ec:
1.1 kristaps 554: maxargs = 1;
555: break;
1.131 schwarze 556: case MDOC_Ek:
1.125 schwarze 557: mdoc->flags &= ~MDOC_KEEP;
1.151 schwarze 558: /* FALLTHROUGH */
1.1 kristaps 559: default:
560: maxargs = 0;
561: break;
562: }
563:
1.83 schwarze 564: /*
565: * Search backwards for beginnings of blocks,
566: * both of our own and of pending sub-blocks.
567: */
1.151 schwarze 568:
1.83 schwarze 569: atok = rew_alt(tok);
1.171 schwarze 570: body = endbody = itblk = later = NULL;
1.119 schwarze 571: for (n = mdoc->last; n; n = n->parent) {
1.161 schwarze 572: if (n->flags & (MDOC_VALID | MDOC_BREAK))
1.83 schwarze 573: continue;
574:
575: /* Remember the start of our own body. */
1.151 schwarze 576:
1.150 schwarze 577: if (n->type == MDOC_BODY && atok == n->tok) {
1.175 schwarze 578: if (n->end == ENDBODY_NOT)
1.83 schwarze 579: body = n;
580: continue;
581: }
582:
1.150 schwarze 583: if (n->type != MDOC_BLOCK || n->tok == MDOC_Nm)
1.83 schwarze 584: continue;
1.160 schwarze 585:
586: if (n->tok == MDOC_It) {
1.171 schwarze 587: itblk = n;
1.160 schwarze 588: continue;
589: }
590:
1.83 schwarze 591: if (atok == n->tok) {
592: assert(body);
593:
594: /*
595: * Found the start of our own block.
596: * When there is no pending sub block,
597: * just proceed to closing out.
598: */
1.151 schwarze 599:
1.160 schwarze 600: if (later == NULL ||
1.171 schwarze 601: (tok == MDOC_El && itblk == NULL))
1.83 schwarze 602: break;
603:
1.131 schwarze 604: /*
1.167 schwarze 605: * When there is a pending sub block, postpone
606: * closing out the current block until the
607: * rew_pending() closing out the sub-block.
1.83 schwarze 608: */
1.151 schwarze 609:
1.168 schwarze 610: make_pending(mdoc, n, later, line, ppos);
1.171 schwarze 611: if (tok == MDOC_El)
612: itblk->flags |= MDOC_BREAK;
1.83 schwarze 613:
614: /*
615: * Mark the place where the formatting - but not
616: * the scope - of the current block ends.
617: */
1.151 schwarze 618:
1.166 schwarze 619: endbody = mdoc_endbody_alloc(mdoc, line, ppos,
1.150 schwarze 620: atok, body, ENDBODY_SPACE);
1.151 schwarze 621:
622: /*
623: * If a block closing macro taking arguments
624: * breaks another block, put the arguments
1.166 schwarze 625: * into the end marker.
1.151 schwarze 626: */
627:
1.166 schwarze 628: if (maxargs)
1.148 schwarze 629: mdoc->next = MDOC_NEXT_CHILD;
1.83 schwarze 630: break;
1.182 ! schwarze 631: }
! 632:
! 633: /* Explicit blocks close out description lines. */
! 634:
! 635: if (n->tok == MDOC_Nd) {
! 636: rew_last(mdoc, n);
! 637: continue;
1.83 schwarze 638: }
639:
640: /*
641: * When finding an open sub block, remember the last
642: * open explicit block, or, in case there are only
643: * implicit ones, the first open implicit block.
644: */
1.151 schwarze 645:
1.160 schwarze 646: if (later == NULL ||
647: ! (mdoc_macros[later->tok].flags & MDOC_EXPLICIT))
1.83 schwarze 648: later = n;
649: }
1.166 schwarze 650:
651: if (body == NULL) {
652: mandoc_msg(MANDOCERR_BLK_NOTOPEN, mdoc->parse,
653: line, ppos, mdoc_macronames[tok]);
654: if (maxargs && endbody == NULL) {
655: /*
656: * Stray .Ec without previous .Eo:
657: * Break the output line, keep the arguments.
658: */
659: mdoc_elem_alloc(mdoc, line, ppos, MDOC_br, NULL);
660: rew_elem(mdoc, MDOC_br);
661: }
662: } else if (endbody == NULL) {
663: rew_last(mdoc, body);
664: if (maxargs)
665: mdoc_tail_alloc(mdoc, line, ppos, atok);
666: }
1.83 schwarze 667:
1.150 schwarze 668: if ( ! (mdoc_macros[tok].flags & MDOC_PARSED)) {
669: if (buf[*pos] != '\0')
1.136 schwarze 670: mandoc_vmsg(MANDOCERR_ARG_SKIP,
671: mdoc->parse, line, ppos,
672: "%s %s", mdoc_macronames[tok],
673: buf + *pos);
1.171 schwarze 674: if (endbody == NULL && n != NULL)
1.167 schwarze 675: rew_pending(mdoc, n);
1.151 schwarze 676: return;
1.1 kristaps 677: }
678:
1.166 schwarze 679: if (endbody != NULL)
680: n = endbody;
1.148 schwarze 681: for (j = 0; ; j++) {
1.1 kristaps 682: lastarg = *pos;
683:
1.166 schwarze 684: if (j == maxargs && n != NULL) {
685: rew_pending(mdoc, n);
686: n = NULL;
1.1 kristaps 687: }
688:
1.119 schwarze 689: ac = mdoc_args(mdoc, line, pos, buf, tok, &p);
1.150 schwarze 690: if (ac == ARGS_PUNCT || ac == ARGS_EOLN)
1.1 kristaps 691: break;
692:
1.155 schwarze 693: ntok = ac == ARGS_QWORD ? MDOC_MAX :
694: lookup(mdoc, tok, line, lastarg, p);
1.54 kristaps 695:
1.150 schwarze 696: if (ntok == MDOC_MAX) {
697: dword(mdoc, line, lastarg, p, DELIM_MAX,
698: MDOC_JOIN & mdoc_macros[tok].flags);
1.54 kristaps 699: continue;
700: }
1.1 kristaps 701:
1.166 schwarze 702: if (n != NULL) {
703: rew_pending(mdoc, n);
704: n = NULL;
1.54 kristaps 705: }
1.122 schwarze 706: mdoc->flags &= ~MDOC_NEWLINE;
1.151 schwarze 707: mdoc_macro(mdoc, ntok, line, lastarg, pos, buf);
1.54 kristaps 708: break;
1.1 kristaps 709: }
710:
1.166 schwarze 711: if (n != NULL)
712: rew_pending(mdoc, n);
1.150 schwarze 713: if (nl)
714: append_delims(mdoc, line, pos, buf);
1.1 kristaps 715: }
716:
1.151 schwarze 717: static void
1.1 kristaps 718: in_line(MACRO_PROT_ARGS)
719: {
1.144 schwarze 720: int la, scope, cnt, firstarg, mayopen, nc, nl;
1.53 kristaps 721: enum mdoct ntok;
1.55 kristaps 722: enum margserr ac;
1.67 schwarze 723: enum mdelim d;
1.53 kristaps 724: struct mdoc_arg *arg;
725: char *p;
1.1 kristaps 726:
1.119 schwarze 727: nl = MDOC_NEWLINE & mdoc->flags;
1.60 kristaps 728:
1.4 kristaps 729: /*
730: * Whether we allow ignored elements (those without content,
731: * usually because of reserved words) to squeak by.
732: */
1.45 kristaps 733:
1.4 kristaps 734: switch (tok) {
1.131 schwarze 735: case MDOC_An:
1.26 kristaps 736: /* FALLTHROUGH */
1.131 schwarze 737: case MDOC_Ar:
1.4 kristaps 738: /* FALLTHROUGH */
1.131 schwarze 739: case MDOC_Fl:
1.4 kristaps 740: /* FALLTHROUGH */
1.131 schwarze 741: case MDOC_Mt:
1.12 kristaps 742: /* FALLTHROUGH */
1.131 schwarze 743: case MDOC_Nm:
1.26 kristaps 744: /* FALLTHROUGH */
1.131 schwarze 745: case MDOC_Pa:
1.4 kristaps 746: nc = 1;
747: break;
748: default:
749: nc = 0;
750: break;
751: }
752:
1.152 schwarze 753: mdoc_argv(mdoc, line, tok, &arg, pos, buf);
1.1 kristaps 754:
1.144 schwarze 755: d = DELIM_NONE;
756: firstarg = 1;
1.142 schwarze 757: mayopen = 1;
1.70 kristaps 758: for (cnt = scope = 0;; ) {
1.1 kristaps 759: la = *pos;
1.119 schwarze 760: ac = mdoc_args(mdoc, line, pos, buf, tok, &p);
1.1 kristaps 761:
1.144 schwarze 762: /*
763: * At the end of a macro line,
764: * opening delimiters do not suppress spacing.
765: */
766:
767: if (ac == ARGS_EOLN) {
768: if (d == DELIM_OPEN)
769: mdoc->last->flags &= ~MDOC_DELIMO;
1.1 kristaps 770: break;
1.144 schwarze 771: }
772:
773: /*
774: * The rest of the macro line is only punctuation,
775: * to be handled by append_delims().
776: * If there were no other arguments,
777: * do not allow the first one to suppress spacing,
778: * even if it turns out to be a closing one.
779: */
780:
781: if (ac == ARGS_PUNCT) {
1.176 schwarze 782: if (cnt == 0 && (nc == 0 || tok == MDOC_An))
1.144 schwarze 783: mdoc->flags |= MDOC_NODELIMC;
1.1 kristaps 784: break;
1.144 schwarze 785: }
1.1 kristaps 786:
1.145 schwarze 787: ntok = (ac == ARGS_QWORD || (tok == MDOC_Fn && !cnt)) ?
1.155 schwarze 788: MDOC_MAX : lookup(mdoc, tok, line, la, p);
1.1 kristaps 789:
1.131 schwarze 790: /*
1.4 kristaps 791: * In this case, we've located a submacro and must
792: * execute it. Close out scope, if open. If no
793: * elements have been generated, either create one (nc)
794: * or raise a warning.
795: */
1.1 kristaps 796:
1.150 schwarze 797: if (ntok != MDOC_MAX) {
1.149 schwarze 798: if (scope)
799: rew_elem(mdoc, tok);
1.150 schwarze 800: if (nc && ! cnt) {
801: mdoc_elem_alloc(mdoc, line, ppos, tok, arg);
1.149 schwarze 802: rew_last(mdoc, mdoc->last);
1.150 schwarze 803: } else if ( ! nc && ! cnt) {
1.7 kristaps 804: mdoc_argv_free(arg);
1.135 schwarze 805: mandoc_msg(MANDOCERR_MACRO_EMPTY,
806: mdoc->parse, line, ppos,
807: mdoc_macronames[tok]);
1.7 kristaps 808: }
1.151 schwarze 809: mdoc_macro(mdoc, ntok, line, la, pos, buf);
1.150 schwarze 810: if (nl)
811: append_delims(mdoc, line, pos, buf);
1.151 schwarze 812: return;
1.131 schwarze 813: }
1.1 kristaps 814:
1.131 schwarze 815: /*
1.4 kristaps 816: * Non-quote-enclosed punctuation. Set up our scope, if
817: * a word; rewind the scope, if a delimiter; then append
1.131 schwarze 818: * the word.
1.4 kristaps 819: */
1.1 kristaps 820:
1.150 schwarze 821: d = ac == ARGS_QWORD ? DELIM_NONE : mdoc_isdelim(p);
1.3 kristaps 822:
1.70 kristaps 823: if (DELIM_NONE != d) {
824: /*
825: * If we encounter closing punctuation, no word
1.144 schwarze 826: * has been emitted, no scope is open, and we're
1.70 kristaps 827: * allowed to have an empty element, then start
1.142 schwarze 828: * a new scope.
1.70 kristaps 829: */
1.142 schwarze 830: if ((d == DELIM_CLOSE ||
831: (d == DELIM_MIDDLE && tok == MDOC_Fl)) &&
1.144 schwarze 832: !cnt && !scope && nc && mayopen) {
1.150 schwarze 833: mdoc_elem_alloc(mdoc, line, ppos, tok, arg);
1.70 kristaps 834: scope = 1;
1.142 schwarze 835: cnt++;
1.150 schwarze 836: if (tok == MDOC_Nm)
1.142 schwarze 837: mayopen = 0;
1.70 kristaps 838: }
839: /*
840: * Close out our scope, if one is open, before
841: * any punctuation.
842: */
1.149 schwarze 843: if (scope)
844: rew_elem(mdoc, tok);
1.70 kristaps 845: scope = 0;
1.145 schwarze 846: if (tok == MDOC_Fn)
847: mayopen = 0;
1.142 schwarze 848: } else if (mayopen && !scope) {
1.150 schwarze 849: mdoc_elem_alloc(mdoc, line, ppos, tok, arg);
1.70 kristaps 850: scope = 1;
1.142 schwarze 851: cnt++;
1.1 kristaps 852: }
1.105 kristaps 853:
1.150 schwarze 854: dword(mdoc, line, la, p, d,
855: MDOC_JOIN & mdoc_macros[tok].flags);
1.39 kristaps 856:
857: /*
1.144 schwarze 858: * If the first argument is a closing delimiter,
859: * do not suppress spacing before it.
860: */
861:
862: if (firstarg && d == DELIM_CLOSE && !nc)
863: mdoc->last->flags &= ~MDOC_DELIMC;
864: firstarg = 0;
865:
866: /*
1.39 kristaps 867: * `Fl' macros have their scope re-opened with each new
868: * word so that the `-' can be added to each one without
869: * having to parse out spaces.
870: */
1.150 schwarze 871: if (scope && tok == MDOC_Fl) {
1.149 schwarze 872: rew_elem(mdoc, tok);
1.70 kristaps 873: scope = 0;
1.39 kristaps 874: }
1.1 kristaps 875: }
876:
1.149 schwarze 877: if (scope)
878: rew_elem(mdoc, tok);
1.4 kristaps 879:
880: /*
881: * If no elements have been collected and we're allowed to have
882: * empties (nc), open a scope and close it out. Otherwise,
883: * raise a warning.
884: */
1.45 kristaps 885:
1.150 schwarze 886: if ( ! cnt) {
887: if (nc) {
888: mdoc_elem_alloc(mdoc, line, ppos, tok, arg);
889: rew_last(mdoc, mdoc->last);
890: } else {
891: mdoc_argv_free(arg);
892: mandoc_msg(MANDOCERR_MACRO_EMPTY, mdoc->parse,
893: line, ppos, mdoc_macronames[tok]);
894: }
1.7 kristaps 895: }
1.150 schwarze 896: if (nl)
897: append_delims(mdoc, line, pos, buf);
1.1 kristaps 898: }
899:
1.151 schwarze 900: static void
1.1 kristaps 901: blk_full(MACRO_PROT_ARGS)
902: {
1.153 schwarze 903: int la, nl, parsed;
1.1 kristaps 904: struct mdoc_arg *arg;
1.171 schwarze 905: struct mdoc_node *blk; /* Our own or a broken block. */
1.165 schwarze 906: struct mdoc_node *head; /* Our own head. */
907: struct mdoc_node *body; /* Our own body. */
1.47 kristaps 908: struct mdoc_node *n;
1.59 kristaps 909: enum margserr ac, lac;
1.1 kristaps 910: char *p;
911:
1.119 schwarze 912: nl = MDOC_NEWLINE & mdoc->flags;
1.138 schwarze 913:
1.177 schwarze 914: if (buf[*pos] == '\0' && (tok == MDOC_Sh || tok == MDOC_Ss)) {
915: mandoc_msg(MANDOCERR_MACRO_EMPTY, mdoc->parse,
916: line, ppos, mdoc_macronames[tok]);
917: return;
918: }
919:
1.171 schwarze 920: if ( ! (mdoc_macros[tok].flags & MDOC_EXPLICIT)) {
921:
922: /* Here, tok is one of Sh Ss Nm Nd It. */
923:
924: blk = NULL;
925: for (n = mdoc->last; n != NULL; n = n->parent) {
926: if (n->flags & (MDOC_VALID | MDOC_BREAK) ||
927: n->type != MDOC_BLOCK)
928: continue;
929: if (tok == MDOC_It && n->tok == MDOC_Bl) {
930: if (blk != NULL) {
931: mandoc_vmsg(MANDOCERR_BLK_BROKEN,
932: mdoc->parse, line, ppos,
933: "It breaks %s",
934: mdoc_macronames[blk->tok]);
935: rew_pending(mdoc, blk);
936: }
937: break;
938: }
939:
940: if (mdoc_macros[n->tok].flags & MDOC_EXPLICIT) {
941: switch (tok) {
942: case MDOC_Sh:
943: /* FALLTHROUGH */
944: case MDOC_Ss:
945: mandoc_vmsg(MANDOCERR_BLK_BROKEN,
946: mdoc->parse, line, ppos,
947: "%s breaks %s",
948: mdoc_macronames[tok],
949: mdoc_macronames[n->tok]);
950: rew_pending(mdoc, n);
1.180 schwarze 951: n = mdoc->last;
1.171 schwarze 952: continue;
953: case MDOC_It:
954: /* Delay in case it's astray. */
955: blk = n;
956: continue;
957: default:
958: break;
959: }
960: break;
961: }
962:
963: /* Here, n is one of Sh Ss Nm Nd It. */
1.138 schwarze 964:
1.171 schwarze 965: if (tok != MDOC_Sh && (n->tok == MDOC_Sh ||
966: (tok != MDOC_Ss && (n->tok == MDOC_Ss ||
967: (tok != MDOC_It && n->tok == MDOC_It)))))
1.138 schwarze 968: break;
1.171 schwarze 969:
970: /* Item breaking an explicit block. */
971:
972: if (blk != NULL) {
973: mandoc_vmsg(MANDOCERR_BLK_BROKEN,
974: mdoc->parse, line, ppos,
975: "It breaks %s",
976: mdoc_macronames[blk->tok]);
977: rew_pending(mdoc, blk);
1.172 schwarze 978: blk = NULL;
1.171 schwarze 979: }
980:
981: /* Close out prior implicit scopes. */
982:
983: rew_last(mdoc, n);
984: }
985:
986: /* Skip items outside lists. */
987:
988: if (tok == MDOC_It && (n == NULL || n->tok != MDOC_Bl)) {
1.138 schwarze 989: mandoc_vmsg(MANDOCERR_IT_STRAY, mdoc->parse,
990: line, ppos, "It %s", buf + *pos);
1.150 schwarze 991: mdoc_elem_alloc(mdoc, line, ppos, MDOC_br, NULL);
1.149 schwarze 992: rew_elem(mdoc, MDOC_br);
1.151 schwarze 993: return;
1.138 schwarze 994: }
1.1 kristaps 995: }
996:
1.45 kristaps 997: /*
1.109 kristaps 998: * This routine accommodates implicitly- and explicitly-scoped
1.45 kristaps 999: * macro openings. Implicit ones first close out prior scope
1000: * (seen above). Delay opening the head until necessary to
1001: * allow leading punctuation to print. Special consideration
1002: * for `It -column', which has phrase-part syntax instead of
1003: * regular child nodes.
1004: */
1005:
1.152 schwarze 1006: mdoc_argv(mdoc, line, tok, &arg, pos, buf);
1.165 schwarze 1007: blk = mdoc_block_alloc(mdoc, line, ppos, tok, arg);
1.49 kristaps 1008: head = body = NULL;
1.115 schwarze 1009:
1010: /*
1011: * Exception: Heads of `It' macros in `-diag' lists are not
1012: * parsed, even though `It' macros in general are parsed.
1013: */
1.151 schwarze 1014:
1.153 schwarze 1015: parsed = tok != MDOC_It ||
1016: mdoc->last->parent->tok != MDOC_Bl ||
1017: mdoc->last->parent->norm->Bl.type != LIST_diag;
1.1 kristaps 1018:
1.45 kristaps 1019: /*
1020: * The `Nd' macro has all arguments in its body: it's a hybrid
1021: * of block partial-explicit and full-implicit. Stupid.
1022: */
1.19 kristaps 1023:
1.150 schwarze 1024: if (tok == MDOC_Nd) {
1025: head = mdoc_head_alloc(mdoc, line, ppos, tok);
1.162 schwarze 1026: rew_last(mdoc, head);
1.150 schwarze 1027: body = mdoc_body_alloc(mdoc, line, ppos, tok);
1.123 schwarze 1028: }
1029:
1.150 schwarze 1030: if (tok == MDOC_Bk)
1.123 schwarze 1031: mdoc->flags |= MDOC_KEEP;
1.19 kristaps 1032:
1.150 schwarze 1033: ac = ARGS_PEND;
1034: for (;;) {
1.45 kristaps 1035: la = *pos;
1.150 schwarze 1036: lac = ac;
1.119 schwarze 1037: ac = mdoc_args(mdoc, line, pos, buf, tok, &p);
1.150 schwarze 1038: if (ac == ARGS_EOLN) {
1039: if (lac != ARGS_PPHRASE && lac != ARGS_PHRASE)
1.75 kristaps 1040: break;
1041: /*
1042: * This is necessary: if the last token on a
1043: * line is a `Ta' or tab, then we'll get
1044: * ARGS_EOLN, so we must be smart enough to
1045: * reopen our scope if the last parse was a
1046: * phrase or partial phrase.
1047: */
1.167 schwarze 1048: if (body != NULL)
1049: rew_last(mdoc, body);
1.150 schwarze 1050: body = mdoc_body_alloc(mdoc, line, ppos, tok);
1.1 kristaps 1051: break;
1.75 kristaps 1052: }
1.174 schwarze 1053: if (tok == MDOC_Bd || tok == MDOC_Bk) {
1054: mandoc_vmsg(MANDOCERR_ARG_EXCESS,
1055: mdoc->parse, line, la, "%s ... %s",
1056: mdoc_macronames[tok], buf + la);
1057: break;
1058: }
1.173 schwarze 1059: if (tok == MDOC_Rs) {
1060: mandoc_vmsg(MANDOCERR_ARG_SKIP, mdoc->parse,
1061: line, la, "Rs %s", buf + la);
1062: break;
1063: }
1064: if (ac == ARGS_PUNCT)
1065: break;
1.45 kristaps 1066:
1.131 schwarze 1067: /*
1.73 kristaps 1068: * Emit leading punctuation (i.e., punctuation before
1069: * the MDOC_HEAD) for non-phrase types.
1070: */
1.45 kristaps 1071:
1.150 schwarze 1072: if (head == NULL &&
1073: ac != ARGS_PEND &&
1074: ac != ARGS_PHRASE &&
1075: ac != ARGS_PPHRASE &&
1076: ac != ARGS_QWORD &&
1077: mdoc_isdelim(p) == DELIM_OPEN) {
1078: dword(mdoc, line, la, p, DELIM_OPEN, 0);
1.45 kristaps 1079: continue;
1080: }
1081:
1.74 kristaps 1082: /* Open a head if one hasn't been opened. */
1.45 kristaps 1083:
1.150 schwarze 1084: if (head == NULL)
1085: head = mdoc_head_alloc(mdoc, line, ppos, tok);
1.45 kristaps 1086:
1.150 schwarze 1087: if (ac == ARGS_PHRASE ||
1088: ac == ARGS_PEND ||
1089: ac == ARGS_PPHRASE) {
1.151 schwarze 1090:
1.73 kristaps 1091: /*
1.74 kristaps 1092: * If we haven't opened a body yet, rewind the
1093: * head; if we have, rewind that instead.
1094: */
1095:
1.167 schwarze 1096: rew_last(mdoc, body == NULL ? head : body);
1.150 schwarze 1097: body = mdoc_body_alloc(mdoc, line, ppos, tok);
1.74 kristaps 1098:
1099: /*
1.73 kristaps 1100: * Process phrases: set whether we're in a
1101: * partial-phrase (this effects line handling)
1102: * then call down into the phrase parser.
1103: */
1.74 kristaps 1104:
1.150 schwarze 1105: if (ac == ARGS_PPHRASE)
1.119 schwarze 1106: mdoc->flags |= MDOC_PPHRASE;
1.150 schwarze 1107: if (ac == ARGS_PEND && lac == ARGS_PPHRASE)
1.119 schwarze 1108: mdoc->flags |= MDOC_PPHRASE;
1.154 schwarze 1109: parse_rest(mdoc, MDOC_MAX, line, &la, buf);
1.119 schwarze 1110: mdoc->flags &= ~MDOC_PPHRASE;
1.1 kristaps 1111: continue;
1112: }
1113:
1.153 schwarze 1114: if (macro_or_word(mdoc, tok, line, la, pos, buf, parsed))
1.151 schwarze 1115: break;
1.45 kristaps 1116: }
1.1 kristaps 1117:
1.165 schwarze 1118: if (blk->flags & MDOC_VALID)
1119: return;
1.150 schwarze 1120: if (head == NULL)
1121: head = mdoc_head_alloc(mdoc, line, ppos, tok);
1.174 schwarze 1122: if (nl && tok != MDOC_Bd && tok != MDOC_Bl && tok != MDOC_Rs)
1.150 schwarze 1123: append_delims(mdoc, line, pos, buf);
1.151 schwarze 1124: if (body != NULL)
1.77 kristaps 1125: goto out;
1.19 kristaps 1126:
1.47 kristaps 1127: /*
1.49 kristaps 1128: * If there is an open (i.e., unvalidated) sub-block requiring
1129: * explicit close-out, postpone switching the current block from
1.167 schwarze 1130: * head to body until the rew_pending() call closing out that
1.49 kristaps 1131: * sub-block.
1.47 kristaps 1132: */
1.119 schwarze 1133: for (n = mdoc->last; n && n != head; n = n->parent) {
1.151 schwarze 1134: if (n->type == MDOC_BLOCK &&
1135: mdoc_macros[n->tok].flags & MDOC_EXPLICIT &&
1136: ! (n->flags & MDOC_VALID)) {
1.47 kristaps 1137: n->pending = head;
1.151 schwarze 1138: return;
1.47 kristaps 1139: }
1140: }
1141:
1.45 kristaps 1142: /* Close out scopes to remain in a consistent state. */
1143:
1.167 schwarze 1144: rew_last(mdoc, head);
1145: body = mdoc_body_alloc(mdoc, line, ppos, tok);
1.77 kristaps 1146: out:
1.150 schwarze 1147: if (mdoc->flags & MDOC_FREECOL) {
1.167 schwarze 1148: rew_last(mdoc, body);
1149: rew_last(mdoc, blk);
1.150 schwarze 1150: mdoc->flags &= ~MDOC_FREECOL;
1151: }
1.1 kristaps 1152: }
1153:
1.151 schwarze 1154: static void
1.1 kristaps 1155: blk_part_imp(MACRO_PROT_ARGS)
1156: {
1.63 kristaps 1157: int la, nl;
1.55 kristaps 1158: enum margserr ac;
1.1 kristaps 1159: char *p;
1.43 kristaps 1160: struct mdoc_node *blk; /* saved block context */
1161: struct mdoc_node *body; /* saved body context */
1162: struct mdoc_node *n;
1.1 kristaps 1163:
1.119 schwarze 1164: nl = MDOC_NEWLINE & mdoc->flags;
1.63 kristaps 1165:
1.43 kristaps 1166: /*
1167: * A macro that spans to the end of the line. This is generally
1168: * (but not necessarily) called as the first macro. The block
1169: * has a head as the immediate child, which is always empty,
1170: * followed by zero or more opening punctuation nodes, then the
1171: * body (which may be empty, depending on the macro), then zero
1172: * or more closing punctuation nodes.
1173: */
1.32 kristaps 1174:
1.150 schwarze 1175: blk = mdoc_block_alloc(mdoc, line, ppos, tok, NULL);
1.162 schwarze 1176: rew_last(mdoc, mdoc_head_alloc(mdoc, line, ppos, tok));
1.1 kristaps 1177:
1.43 kristaps 1178: /*
1179: * Open the body scope "on-demand", that is, after we've
1180: * processed all our the leading delimiters (open parenthesis,
1181: * etc.).
1182: */
1.1 kristaps 1183:
1.43 kristaps 1184: for (body = NULL; ; ) {
1.32 kristaps 1185: la = *pos;
1.119 schwarze 1186: ac = mdoc_args(mdoc, line, pos, buf, tok, &p);
1.150 schwarze 1187: if (ac == ARGS_EOLN || ac == ARGS_PUNCT)
1.1 kristaps 1188: break;
1189:
1.150 schwarze 1190: if (body == NULL && ac != ARGS_QWORD &&
1191: mdoc_isdelim(p) == DELIM_OPEN) {
1192: dword(mdoc, line, la, p, DELIM_OPEN, 0);
1.1 kristaps 1193: continue;
1.123 schwarze 1194: }
1.1 kristaps 1195:
1.150 schwarze 1196: if (body == NULL)
1197: body = mdoc_body_alloc(mdoc, line, ppos, tok);
1.43 kristaps 1198:
1.153 schwarze 1199: if (macro_or_word(mdoc, tok, line, la, pos, buf, 1))
1.151 schwarze 1200: break;
1.1 kristaps 1201: }
1.150 schwarze 1202: if (body == NULL)
1203: body = mdoc_body_alloc(mdoc, line, ppos, tok);
1.43 kristaps 1204:
1.83 schwarze 1205: /*
1206: * If there is an open sub-block requiring explicit close-out,
1.167 schwarze 1207: * postpone closing out the current block until the
1208: * rew_pending() call closing out the sub-block.
1.83 schwarze 1209: */
1.151 schwarze 1210:
1.119 schwarze 1211: for (n = mdoc->last; n && n != body && n != blk->parent;
1.131 schwarze 1212: n = n->parent) {
1.150 schwarze 1213: if (n->type == MDOC_BLOCK &&
1214: mdoc_macros[n->tok].flags & MDOC_EXPLICIT &&
1215: ! (n->flags & MDOC_VALID)) {
1.168 schwarze 1216: make_pending(mdoc, blk, n, line, ppos);
1.150 schwarze 1217: mdoc_endbody_alloc(mdoc, line, ppos,
1218: tok, body, ENDBODY_NOSPACE);
1.151 schwarze 1219: return;
1.83 schwarze 1220: }
1221: }
1.134 schwarze 1222: assert(n == body);
1.164 schwarze 1223: rew_last(mdoc, body);
1.150 schwarze 1224: if (nl)
1225: append_delims(mdoc, line, pos, buf);
1.166 schwarze 1226: rew_pending(mdoc, blk);
1.117 schwarze 1227:
1228: /* Move trailing .Ns out of scope. */
1229:
1230: for (n = body->child; n && n->next; n = n->next)
1231: /* Do nothing. */ ;
1.150 schwarze 1232: if (n && n->tok == MDOC_Ns)
1.119 schwarze 1233: mdoc_node_relink(mdoc, n);
1.1 kristaps 1234: }
1235:
1.151 schwarze 1236: static void
1.1 kristaps 1237: blk_part_exp(MACRO_PROT_ARGS)
1238: {
1.60 kristaps 1239: int la, nl;
1.55 kristaps 1240: enum margserr ac;
1.43 kristaps 1241: struct mdoc_node *head; /* keep track of head */
1.1 kristaps 1242: char *p;
1243:
1.119 schwarze 1244: nl = MDOC_NEWLINE & mdoc->flags;
1.60 kristaps 1245:
1.43 kristaps 1246: /*
1247: * The opening of an explicit macro having zero or more leading
1248: * punctuation nodes; a head with optional single element (the
1249: * case of `Eo'); and a body that may be empty.
1250: */
1.32 kristaps 1251:
1.150 schwarze 1252: mdoc_block_alloc(mdoc, line, ppos, tok, NULL);
1.163 schwarze 1253: head = NULL;
1254: for (;;) {
1.32 kristaps 1255: la = *pos;
1.119 schwarze 1256: ac = mdoc_args(mdoc, line, pos, buf, tok, &p);
1.150 schwarze 1257: if (ac == ARGS_PUNCT || ac == ARGS_EOLN)
1.1 kristaps 1258: break;
1.43 kristaps 1259:
1260: /* Flush out leading punctuation. */
1261:
1.150 schwarze 1262: if (head == NULL && ac != ARGS_QWORD &&
1263: mdoc_isdelim(p) == DELIM_OPEN) {
1264: dword(mdoc, line, la, p, DELIM_OPEN, 0);
1.43 kristaps 1265: continue;
1.123 schwarze 1266: }
1.43 kristaps 1267:
1.150 schwarze 1268: if (head == NULL) {
1269: head = mdoc_head_alloc(mdoc, line, ppos, tok);
1.163 schwarze 1270: if (tok == MDOC_Eo) /* Not parsed. */
1.150 schwarze 1271: dword(mdoc, line, la, p, DELIM_MAX, 0);
1.163 schwarze 1272: rew_last(mdoc, head);
1273: mdoc_body_alloc(mdoc, line, ppos, tok);
1.150 schwarze 1274: if (tok == MDOC_Eo)
1.43 kristaps 1275: continue;
1.1 kristaps 1276: }
1.43 kristaps 1277:
1.153 schwarze 1278: if (macro_or_word(mdoc, tok, line, la, pos, buf, 1))
1.151 schwarze 1279: break;
1.1 kristaps 1280: }
1281:
1.43 kristaps 1282: /* Clean-up to leave in a consistent state. */
1.32 kristaps 1283:
1.163 schwarze 1284: if (head == NULL) {
1285: rew_last(mdoc, mdoc_head_alloc(mdoc, line, ppos, tok));
1.150 schwarze 1286: mdoc_body_alloc(mdoc, line, ppos, tok);
1.1 kristaps 1287: }
1.150 schwarze 1288: if (nl)
1289: append_delims(mdoc, line, pos, buf);
1.1 kristaps 1290: }
1291:
1.151 schwarze 1292: static void
1.1 kristaps 1293: in_line_argn(MACRO_PROT_ARGS)
1294: {
1.53 kristaps 1295: struct mdoc_arg *arg;
1296: char *p;
1.181 schwarze 1297: enum margserr ac;
1.53 kristaps 1298: enum mdoct ntok;
1.181 schwarze 1299: int state; /* arg#; -1: not yet open; -2: closed */
1300: int la, maxargs, nl;
1.1 kristaps 1301:
1.156 schwarze 1302: nl = mdoc->flags & MDOC_NEWLINE;
1.60 kristaps 1303:
1.46 kristaps 1304: /*
1305: * A line macro that has a fixed number of arguments (maxargs).
1306: * Only open the scope once the first non-leading-punctuation is
1307: * found (unless MDOC_IGNDELIM is noted, like in `Pf'), then
1308: * keep it open until the maximum number of arguments are
1309: * exhausted.
1310: */
1.1 kristaps 1311:
1312: switch (tok) {
1.131 schwarze 1313: case MDOC_Ap:
1.1 kristaps 1314: /* FALLTHROUGH */
1.131 schwarze 1315: case MDOC_Ns:
1.1 kristaps 1316: /* FALLTHROUGH */
1.131 schwarze 1317: case MDOC_Ux:
1.1 kristaps 1318: maxargs = 0;
1319: break;
1.131 schwarze 1320: case MDOC_Bx:
1.101 kristaps 1321: /* FALLTHROUGH */
1.132 schwarze 1322: case MDOC_Es:
1323: /* FALLTHROUGH */
1.131 schwarze 1324: case MDOC_Xr:
1.42 kristaps 1325: maxargs = 2;
1326: break;
1.1 kristaps 1327: default:
1328: maxargs = 1;
1329: break;
1330: }
1331:
1.152 schwarze 1332: mdoc_argv(mdoc, line, tok, &arg, pos, buf);
1.1 kristaps 1333:
1.181 schwarze 1334: state = -1;
1.156 schwarze 1335: p = NULL;
1336: for (;;) {
1.32 kristaps 1337: la = *pos;
1.119 schwarze 1338: ac = mdoc_args(mdoc, line, pos, buf, tok, &p);
1.181 schwarze 1339:
1340: if (ac == ARGS_WORD && state == -1 &&
1341: ! (mdoc_macros[tok].flags & MDOC_IGNDELIM) &&
1342: mdoc_isdelim(p) == DELIM_OPEN) {
1343: dword(mdoc, line, la, p, DELIM_OPEN, 0);
1344: continue;
1345: }
1346:
1347: if (state == -1 && tok != MDOC_In &&
1348: tok != MDOC_St && tok != MDOC_Xr) {
1349: mdoc_elem_alloc(mdoc, line, ppos, tok, arg);
1350: state = 0;
1351: }
1352:
1.156 schwarze 1353: if (ac == ARGS_PUNCT || ac == ARGS_EOLN) {
1.181 schwarze 1354: if (abs(state) < 2 && tok == MDOC_Pf)
1.156 schwarze 1355: mandoc_vmsg(MANDOCERR_PF_SKIP,
1356: mdoc->parse, line, ppos, "Pf %s",
1357: p == NULL ? "at eol" : p);
1.1 kristaps 1358: break;
1.156 schwarze 1359: }
1.1 kristaps 1360:
1.181 schwarze 1361: if (state == maxargs) {
1.149 schwarze 1362: rew_elem(mdoc, tok);
1.181 schwarze 1363: state = -2;
1.46 kristaps 1364: }
1365:
1.181 schwarze 1366: ntok = (ac == ARGS_QWORD || (tok == MDOC_Pf && state == 0)) ?
1.156 schwarze 1367: MDOC_MAX : lookup(mdoc, tok, line, la, p);
1.54 kristaps 1368:
1.150 schwarze 1369: if (ntok != MDOC_MAX) {
1.181 schwarze 1370: if (state >= 0) {
1.149 schwarze 1371: rew_elem(mdoc, tok);
1.181 schwarze 1372: state = -2;
1373: }
1.151 schwarze 1374: mdoc_macro(mdoc, ntok, line, la, pos, buf);
1.1 kristaps 1375: break;
1376: }
1377:
1.181 schwarze 1378: if (ac == ARGS_QWORD ||
1379: mdoc_macros[tok].flags & MDOC_IGNDELIM ||
1380: mdoc_isdelim(p) == DELIM_NONE) {
1381: if (state == -1) {
1382: mdoc_elem_alloc(mdoc, line, ppos, tok, arg);
1383: state = 1;
1384: } else if (state >= 0)
1385: state++;
1386: } else if (state >= 0) {
1.149 schwarze 1387: rew_elem(mdoc, tok);
1.181 schwarze 1388: state = -2;
1.1 kristaps 1389: }
1.42 kristaps 1390:
1.150 schwarze 1391: dword(mdoc, line, la, p, DELIM_MAX,
1392: MDOC_JOIN & mdoc_macros[tok].flags);
1.1 kristaps 1393: }
1394:
1.181 schwarze 1395: if (state == -1) {
1396: mandoc_msg(MANDOCERR_MACRO_EMPTY, mdoc->parse,
1397: line, ppos, mdoc_macronames[tok]);
1398: return;
1.156 schwarze 1399: }
1.181 schwarze 1400:
1401: if (state == 0 && tok == MDOC_Pf)
1402: append_delims(mdoc, line, pos, buf);
1403: if (state >= 0)
1.149 schwarze 1404: rew_elem(mdoc, tok);
1.150 schwarze 1405: if (nl)
1406: append_delims(mdoc, line, pos, buf);
1.1 kristaps 1407: }
1408:
1.151 schwarze 1409: static void
1.1 kristaps 1410: in_line_eoln(MACRO_PROT_ARGS)
1411: {
1.170 schwarze 1412: struct mdoc_node *n;
1413: struct mdoc_arg *arg;
1.1 kristaps 1414:
1.170 schwarze 1415: if ((tok == MDOC_Pp || tok == MDOC_Lp) &&
1416: ! (mdoc->flags & MDOC_SYNOPSIS)) {
1417: n = mdoc->last;
1418: if (mdoc->next == MDOC_NEXT_SIBLING)
1419: n = n->parent;
1420: if (n->tok == MDOC_Nm)
1421: rew_last(mdoc, mdoc->last->parent);
1.178 schwarze 1422: }
1423:
1.179 schwarze 1424: if (buf[*pos] == '\0' &&
1425: (tok == MDOC_Fd || mdoc_macronames[tok][0] == '%')) {
1.178 schwarze 1426: mandoc_msg(MANDOCERR_MACRO_EMPTY, mdoc->parse,
1.179 schwarze 1427: line, ppos, mdoc_macronames[tok]);
1.178 schwarze 1428: return;
1.170 schwarze 1429: }
1.90 schwarze 1430:
1.152 schwarze 1431: mdoc_argv(mdoc, line, tok, &arg, pos, buf);
1.150 schwarze 1432: mdoc_elem_alloc(mdoc, line, ppos, tok, arg);
1.154 schwarze 1433: if (parse_rest(mdoc, tok, line, pos, buf))
1434: return;
1435: rew_elem(mdoc, tok);
1436: }
1437:
1438: /*
1439: * The simplest argument parser available: Parse the remaining
1440: * words until the end of the phrase or line and return 0
1441: * or until the next macro, call that macro, and return 1.
1442: */
1443: static int
1444: parse_rest(struct mdoc *mdoc, enum mdoct tok, int line, int *pos, char *buf)
1445: {
1446: int la;
1.1 kristaps 1447:
1448: for (;;) {
1449: la = *pos;
1.153 schwarze 1450: if (mdoc_args(mdoc, line, pos, buf, tok, NULL) == ARGS_EOLN)
1.154 schwarze 1451: return(0);
1.153 schwarze 1452: if (macro_or_word(mdoc, tok, line, la, pos, buf, 1))
1.154 schwarze 1453: return(1);
1.1 kristaps 1454: }
1455: }
1456:
1.151 schwarze 1457: static void
1.41 kristaps 1458: ctx_synopsis(MACRO_PROT_ARGS)
1459: {
1.60 kristaps 1460:
1.151 schwarze 1461: if (~mdoc->flags & (MDOC_SYNOPSIS | MDOC_NEWLINE))
1462: in_line(mdoc, tok, line, ppos, pos, buf);
1463: else if (tok == MDOC_Nm)
1464: blk_full(mdoc, tok, line, ppos, pos, buf);
1465: else {
1466: assert(tok == MDOC_Vt);
1467: blk_part_imp(mdoc, tok, line, ppos, pos, buf);
1468: }
1.1 kristaps 1469: }
1470:
1.24 kristaps 1471: /*
1472: * Phrases occur within `Bl -column' entries, separated by `Ta' or tabs.
1473: * They're unusual because they're basically free-form text until a
1474: * macro is encountered.
1475: */
1.151 schwarze 1476: static void
1.75 kristaps 1477: phrase_ta(MACRO_PROT_ARGS)
1478: {
1.167 schwarze 1479: struct mdoc_node *body, *n;
1.75 kristaps 1480:
1.121 schwarze 1481: /* Make sure we are in a column list or ignore this macro. */
1.151 schwarze 1482:
1.167 schwarze 1483: body = NULL;
1484: for (n = mdoc->last; n != NULL; n = n->parent) {
1485: if (n->flags & (MDOC_VALID | MDOC_BREAK))
1486: continue;
1487: if (n->tok == MDOC_It && n->type == MDOC_BODY)
1488: body = n;
1489: if (n->tok == MDOC_Bl)
1490: break;
1491: }
1492:
1.151 schwarze 1493: if (n == NULL || n->norm->Bl.type != LIST_column) {
1.137 schwarze 1494: mandoc_msg(MANDOCERR_TA_STRAY, mdoc->parse,
1.139 schwarze 1495: line, ppos, "Ta");
1.151 schwarze 1496: return;
1.121 schwarze 1497: }
1.75 kristaps 1498:
1.121 schwarze 1499: /* Advance to the next column. */
1.150 schwarze 1500:
1.167 schwarze 1501: rew_last(mdoc, body);
1.150 schwarze 1502: mdoc_body_alloc(mdoc, line, ppos, MDOC_It);
1.154 schwarze 1503: parse_rest(mdoc, MDOC_MAX, line, pos, buf);
1.75 kristaps 1504: }
CVSweb