version 1.150, 2014/11/28 03:14:18 |
version 1.165, 2015/02/02 04:04:45 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2010, 2012-2015 Ingo Schwarze <schwarze@openbsd.org> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
* purpose with or without fee is hereby granted, provided that the above |
* purpose with or without fee is hereby granted, provided that the above |
Line 40 enum rew { /* see rew_dohalt() */ |
|
Line 40 enum rew { /* see rew_dohalt() */ |
|
REWIND_ERROR |
REWIND_ERROR |
}; |
}; |
|
|
static int blk_full(MACRO_PROT_ARGS); |
static void blk_full(MACRO_PROT_ARGS); |
static int blk_exp_close(MACRO_PROT_ARGS); |
static void blk_exp_close(MACRO_PROT_ARGS); |
static int blk_part_exp(MACRO_PROT_ARGS); |
static void blk_part_exp(MACRO_PROT_ARGS); |
static int blk_part_imp(MACRO_PROT_ARGS); |
static void blk_part_imp(MACRO_PROT_ARGS); |
static int ctx_synopsis(MACRO_PROT_ARGS); |
static void ctx_synopsis(MACRO_PROT_ARGS); |
static int in_line_eoln(MACRO_PROT_ARGS); |
static void in_line_eoln(MACRO_PROT_ARGS); |
static int in_line_argn(MACRO_PROT_ARGS); |
static void in_line_argn(MACRO_PROT_ARGS); |
static int in_line(MACRO_PROT_ARGS); |
static void in_line(MACRO_PROT_ARGS); |
static int phrase_ta(MACRO_PROT_ARGS); |
static void phrase_ta(MACRO_PROT_ARGS); |
|
|
static void dword(struct mdoc *, int, int, const char *, |
static void dword(struct mdoc *, int, int, const char *, |
enum mdelim, int); |
enum mdelim, int); |
static void append_delims(struct mdoc *, int, int *, char *); |
static void append_delims(struct mdoc *, int, int *, char *); |
static enum mdoct lookup(enum mdoct, const char *); |
static enum mdoct lookup(struct mdoc *, enum mdoct, |
static enum mdoct lookup_raw(const char *); |
int, int, const char *); |
|
static int macro_or_word(MACRO_PROT_ARGS, int); |
static int make_pending(struct mdoc_node *, enum mdoct, |
static int make_pending(struct mdoc_node *, enum mdoct, |
struct mdoc *, int, int); |
struct mdoc *, int, int); |
static int phrase(struct mdoc *, int, int, char *); |
static int parse_rest(struct mdoc *, enum mdoct, |
|
int, int *, char *); |
static enum mdoct rew_alt(enum mdoct); |
static enum mdoct rew_alt(enum mdoct); |
static enum rew rew_dohalt(enum mdoct, enum mdoc_type, |
static enum rew rew_dohalt(enum mdoct, enum mdoc_type, |
const struct mdoc_node *); |
const struct mdoc_node *); |
Line 218 const struct mdoc_macro * const mdoc_macros = __mdoc_m |
|
Line 220 const struct mdoc_macro * const mdoc_macros = __mdoc_m |
|
* closing out open [implicit] scopes. Obviously, open explicit scopes |
* closing out open [implicit] scopes. Obviously, open explicit scopes |
* are errors. |
* are errors. |
*/ |
*/ |
int |
void |
mdoc_macroend(struct mdoc *mdoc) |
mdoc_macroend(struct mdoc *mdoc) |
{ |
{ |
struct mdoc_node *n; |
struct mdoc_node *n; |
|
|
/* Scan for open explicit scopes. */ |
/* Scan for open explicit scopes. */ |
|
|
n = MDOC_VALID & mdoc->last->flags ? |
n = mdoc->last->flags & MDOC_VALID ? |
mdoc->last->parent : mdoc->last; |
mdoc->last->parent : mdoc->last; |
|
|
for ( ; n; n = n->parent) |
for ( ; n; n = n->parent) |
if (MDOC_BLOCK == n->type && |
if (n->type == MDOC_BLOCK && |
MDOC_EXPLICIT & mdoc_macros[n->tok].flags) |
mdoc_macros[n->tok].flags & MDOC_EXPLICIT) |
mandoc_msg(MANDOCERR_BLK_NOEND, mdoc->parse, |
mandoc_msg(MANDOCERR_BLK_NOEND, mdoc->parse, |
n->line, n->pos, mdoc_macronames[n->tok]); |
n->line, n->pos, mdoc_macronames[n->tok]); |
|
|
/* Rewind to the first. */ |
/* Rewind to the first. */ |
|
|
rew_last(mdoc, mdoc->first); |
rew_last(mdoc, mdoc->first); |
return(1); |
|
} |
} |
|
|
/* |
/* |
* Look up a macro from within a subsequent context. |
* Look up the macro at *p called by "from", |
|
* or as a line macro if from == MDOC_MAX. |
*/ |
*/ |
static enum mdoct |
static enum mdoct |
lookup(enum mdoct from, const char *p) |
lookup(struct mdoc *mdoc, enum mdoct from, int line, int ppos, const char *p) |
{ |
{ |
|
|
if ( ! (MDOC_PARSED & mdoc_macros[from].flags)) |
|
return(MDOC_MAX); |
|
return(lookup_raw(p)); |
|
} |
|
|
|
/* |
|
* Lookup a macro following the initial line macro. |
|
*/ |
|
static enum mdoct |
|
lookup_raw(const char *p) |
|
{ |
|
enum mdoct res; |
enum mdoct res; |
|
|
if (MDOC_MAX == (res = mdoc_hash_find(p))) |
if (from == MDOC_MAX || mdoc_macros[from].flags & MDOC_PARSED) { |
return(MDOC_MAX); |
res = mdoc_hash_find(p); |
if (MDOC_CALLABLE & mdoc_macros[res].flags) |
if (res != MDOC_MAX) { |
return(res); |
if (mdoc_macros[res].flags & MDOC_CALLABLE) |
|
return(res); |
|
if (res != MDOC_br && res != MDOC_sp && res != MDOC_ll) |
|
mandoc_msg(MANDOCERR_MACRO_CALL, |
|
mdoc->parse, line, ppos, p); |
|
} |
|
} |
return(MDOC_MAX); |
return(MDOC_MAX); |
} |
} |
|
|
Line 367 rew_dohalt(enum mdoct tok, enum mdoc_type type, |
|
Line 363 rew_dohalt(enum mdoct tok, enum mdoc_type type, |
|
* When starting to rewind, skip plain text |
* When starting to rewind, skip plain text |
* and nodes that have already been rewound. |
* and nodes that have already been rewound. |
*/ |
*/ |
if (MDOC_TEXT == p->type || MDOC_VALID & p->flags) |
if (p->type == MDOC_TEXT || p->flags & (MDOC_VALID | MDOC_BREAK)) |
return(REWIND_MORE); |
return(REWIND_MORE); |
|
|
/* |
/* |
Line 482 make_pending(struct mdoc_node *broken, enum mdoct tok, |
|
Line 478 make_pending(struct mdoc_node *broken, enum mdoct tok, |
|
for (breaker = broken->parent; breaker; breaker = breaker->parent) { |
for (breaker = broken->parent; breaker; breaker = breaker->parent) { |
|
|
/* |
/* |
* If the *broken block had already been broken before |
* If the *broken block (Z) is already broken and we |
* and we encounter its breaker, make the tok block |
* encounter its breaker (B), make the tok block (A) |
* pending on the inner breaker. |
* pending on that inner breaker (B). |
* Graphically, "[A breaker=[B broken=[C->B B] tok=A] C]" |
* Graphically, [A breaker=[B! broken=[Z->B B] tok=A] Z] |
* becomes "[A broken=[B [C->B B] tok=A] C]" |
* becomes breaker=[A broken=[B! [Z->B B] tok=A] Z] |
* and finally "[A [B->A [C->B B] A] C]". |
* and finally [A! [B!->A [Z->B B] A] Z]. |
|
* In these graphics, "->" indicates the "pending" |
|
* pointer and "!" indicates the MDOC_BREAK flag. |
|
* Each of the cases gets one additional pointer (B->A) |
|
* and one additional flag (A!). |
*/ |
*/ |
if (breaker == broken->pending) { |
if (breaker == broken->pending) { |
broken = breaker; |
broken = breaker; |
Line 501 make_pending(struct mdoc_node *broken, enum mdoct tok, |
|
Line 501 make_pending(struct mdoc_node *broken, enum mdoct tok, |
|
|
|
/* |
/* |
* Found the breaker. |
* Found the breaker. |
* If another, outer breaker is already pending on |
* If another, outer breaker (X) is already pending on |
* the *broken block, we must not clobber the link |
* the *broken block (B), we must not clobber the link |
* to the outer breaker, but make it pending on the |
* to the outer breaker, but make it pending on the |
* new, now inner breaker. |
* new, now inner breaker (A). |
* Graphically, "[A breaker=[B broken=[C->A A] tok=B] C]" |
* Graphically, [X! breaker=[A broken=[B->X X] tok=A] B] |
* becomes "[A breaker=[B->A broken=[C A] tok=B] C]" |
* becomes [X! breaker=[A->X broken=[B X] tok=A] B] |
* and finally "[A [B->A [C->B A] B] C]". |
* and finally [X! [A!->X [B->A X] A] B]. |
*/ |
*/ |
if (broken->pending) { |
if (broken->pending) { |
struct mdoc_node *taker; |
struct mdoc_node *taker; |
|
|
/* |
/* |
* If the breaker had also been broken before, |
* If the inner breaker (A) is already broken, |
* it cannot take on the outer breaker itself, |
* too, it cannot take on the outer breaker (X) |
* but must hand it on to its own breakers. |
* but must hand it on to its own breakers (Y): |
* Graphically, this is the following situation: |
* [X! [Y! breaker=[A->Y Y] broken=[B->X X] tok=A] B] |
* "[A [B breaker=[C->B B] broken=[D->A A] tok=C] D]" |
* [X! take=[Y!->X brea=[A->Y Y] brok=[B X] tok=A] B] |
* "[A taker=[B->A breaker=[C->B B] [D->C A] C] D]" |
* and finally [X! [Y!->X [A!->Y Y] [B->A X] A] B]. |
*/ |
*/ |
taker = breaker; |
taker = breaker; |
while (taker->pending) |
while (taker->pending) |
taker = taker->pending; |
taker = taker->pending; |
taker->pending = broken->pending; |
taker->pending = broken->pending; |
} |
} |
|
|
|
/* |
|
* Now we have reduced the situation to the simplest |
|
* case, which is just breaker=[A broken=[B tok=A] B] |
|
* and becomes [A! [B->A A] B]. |
|
*/ |
broken->pending = breaker; |
broken->pending = breaker; |
|
breaker->flags |= MDOC_BREAK; |
mandoc_vmsg(MANDOCERR_BLK_NEST, mdoc->parse, line, ppos, |
mandoc_vmsg(MANDOCERR_BLK_NEST, mdoc->parse, line, ppos, |
"%s breaks %s", mdoc_macronames[tok], |
"%s breaks %s", mdoc_macronames[tok], |
mdoc_macronames[broken->tok]); |
mdoc_macronames[broken->tok]); |
|
|
rew_sub(enum mdoc_type t, struct mdoc *mdoc, |
rew_sub(enum mdoc_type t, struct mdoc *mdoc, |
enum mdoct tok, int line, int ppos) |
enum mdoct tok, int line, int ppos) |
{ |
{ |
struct mdoc_node *n; |
struct mdoc_node *n, *to; |
|
|
|
to = NULL; |
n = mdoc->last; |
n = mdoc->last; |
while (n) { |
while (n) { |
switch (rew_dohalt(tok, t, n)) { |
switch (rew_dohalt(tok, t, n)) { |
case REWIND_NONE: |
case REWIND_NONE: |
return; |
if (to == NULL) |
|
return; |
|
n = to; |
|
break; |
case REWIND_THIS: |
case REWIND_THIS: |
n->lastline = line - |
n->lastline = line - |
(mdoc->flags & MDOC_NEWLINE && |
(mdoc->flags & MDOC_NEWLINE && |
Line 564 rew_sub(enum mdoc_type t, struct mdoc *mdoc, |
|
Line 575 rew_sub(enum mdoc_type t, struct mdoc *mdoc, |
|
case REWIND_MORE: |
case REWIND_MORE: |
n->lastline = line - |
n->lastline = line - |
(mdoc->flags & MDOC_NEWLINE ? 1 : 0); |
(mdoc->flags & MDOC_NEWLINE ? 1 : 0); |
|
to = n; |
n = n->parent; |
n = n->parent; |
continue; |
continue; |
case REWIND_LATER: |
case REWIND_LATER: |
Line 634 dword(struct mdoc *mdoc, int line, int col, const char |
|
Line 646 dword(struct mdoc *mdoc, int line, int col, const char |
|
static void |
static void |
append_delims(struct mdoc *mdoc, int line, int *pos, char *buf) |
append_delims(struct mdoc *mdoc, int line, int *pos, char *buf) |
{ |
{ |
int la; |
|
enum margserr ac; |
|
char *p; |
char *p; |
|
int la; |
|
|
if (buf[*pos] == '\0') |
if (buf[*pos] == '\0') |
return; |
return; |
|
|
for (;;) { |
for (;;) { |
la = *pos; |
la = *pos; |
ac = mdoc_zargs(mdoc, line, pos, buf, &p); |
if (mdoc_args(mdoc, line, pos, buf, MDOC_MAX, &p) == ARGS_EOLN) |
if (ac == ARGS_EOLN) |
|
break; |
break; |
dword(mdoc, line, la, p, DELIM_MAX, 1); |
dword(mdoc, line, la, p, DELIM_MAX, 1); |
|
|
Line 666 append_delims(struct mdoc *mdoc, int line, int *pos, c |
|
Line 676 append_delims(struct mdoc *mdoc, int line, int *pos, c |
|
} |
} |
|
|
/* |
/* |
* Close out block partial/full explicit. |
* Parse one word. |
|
* If it is a macro, call it and return 1. |
|
* Otherwise, allocate it and return 0. |
*/ |
*/ |
static int |
static int |
|
macro_or_word(MACRO_PROT_ARGS, int parsed) |
|
{ |
|
char *p; |
|
enum mdoct ntok; |
|
|
|
p = buf + ppos; |
|
ntok = MDOC_MAX; |
|
if (*p == '"') |
|
p++; |
|
else if (parsed && ! (mdoc->flags & MDOC_PHRASELIT)) |
|
ntok = lookup(mdoc, tok, line, ppos, p); |
|
|
|
if (ntok == MDOC_MAX) { |
|
dword(mdoc, line, ppos, p, DELIM_MAX, tok == MDOC_MAX || |
|
mdoc_macros[tok].flags & MDOC_JOIN); |
|
return(0); |
|
} else { |
|
if (mdoc_macros[tok].fp == in_line_eoln) |
|
rew_elem(mdoc, tok); |
|
mdoc_macro(mdoc, ntok, line, ppos, pos, buf); |
|
if (tok == MDOC_MAX) |
|
append_delims(mdoc, line, pos, buf); |
|
return(1); |
|
} |
|
} |
|
|
|
/* |
|
* Close out block partial/full explicit. |
|
*/ |
|
static void |
blk_exp_close(MACRO_PROT_ARGS) |
blk_exp_close(MACRO_PROT_ARGS) |
{ |
{ |
struct mdoc_node *body; /* Our own body. */ |
struct mdoc_node *body; /* Our own body. */ |
Line 676 blk_exp_close(MACRO_PROT_ARGS) |
|
Line 718 blk_exp_close(MACRO_PROT_ARGS) |
|
struct mdoc_node *later; /* A sub-block starting later. */ |
struct mdoc_node *later; /* A sub-block starting later. */ |
struct mdoc_node *n; /* For searching backwards. */ |
struct mdoc_node *n; /* For searching backwards. */ |
|
|
int j, lastarg, maxargs, flushed, nl; |
int flushed, have_it, j, lastarg, maxargs, nl; |
enum margserr ac; |
enum margserr ac; |
enum mdoct atok, ntok; |
enum mdoct atok, ntok; |
char *p; |
char *p; |
Line 689 blk_exp_close(MACRO_PROT_ARGS) |
|
Line 731 blk_exp_close(MACRO_PROT_ARGS) |
|
break; |
break; |
case MDOC_Ek: |
case MDOC_Ek: |
mdoc->flags &= ~MDOC_KEEP; |
mdoc->flags &= ~MDOC_KEEP; |
|
/* FALLTHROUGH */ |
default: |
default: |
maxargs = 0; |
maxargs = 0; |
break; |
break; |
Line 698 blk_exp_close(MACRO_PROT_ARGS) |
|
Line 741 blk_exp_close(MACRO_PROT_ARGS) |
|
* Search backwards for beginnings of blocks, |
* Search backwards for beginnings of blocks, |
* both of our own and of pending sub-blocks. |
* both of our own and of pending sub-blocks. |
*/ |
*/ |
|
|
|
have_it = 0; |
atok = rew_alt(tok); |
atok = rew_alt(tok); |
body = endbody = later = NULL; |
body = endbody = later = NULL; |
for (n = mdoc->last; n; n = n->parent) { |
for (n = mdoc->last; n; n = n->parent) { |
if (n->flags & MDOC_VALID) |
if (n->flags & (MDOC_VALID | MDOC_BREAK)) |
continue; |
continue; |
|
|
/* Remember the start of our own body. */ |
/* Remember the start of our own body. */ |
|
|
if (n->type == MDOC_BODY && atok == n->tok) { |
if (n->type == MDOC_BODY && atok == n->tok) { |
if (n->end == ENDBODY_NOT) |
if (n->end == ENDBODY_NOT) |
body = n; |
body = n; |
Line 713 blk_exp_close(MACRO_PROT_ARGS) |
|
Line 759 blk_exp_close(MACRO_PROT_ARGS) |
|
|
|
if (n->type != MDOC_BLOCK || n->tok == MDOC_Nm) |
if (n->type != MDOC_BLOCK || n->tok == MDOC_Nm) |
continue; |
continue; |
|
|
|
if (n->tok == MDOC_It) { |
|
have_it = 1; |
|
continue; |
|
} |
|
|
if (atok == n->tok) { |
if (atok == n->tok) { |
assert(body); |
assert(body); |
|
|
Line 721 blk_exp_close(MACRO_PROT_ARGS) |
|
Line 773 blk_exp_close(MACRO_PROT_ARGS) |
|
* When there is no pending sub block, |
* When there is no pending sub block, |
* just proceed to closing out. |
* just proceed to closing out. |
*/ |
*/ |
if (later == NULL) |
|
|
if (later == NULL || |
|
(tok == MDOC_El && !have_it)) |
break; |
break; |
|
|
/* |
/* |
Line 729 blk_exp_close(MACRO_PROT_ARGS) |
|
Line 783 blk_exp_close(MACRO_PROT_ARGS) |
|
* postpone closing out the current block |
* postpone closing out the current block |
* until the rew_sub() closing out the sub-block. |
* until the rew_sub() closing out the sub-block. |
*/ |
*/ |
|
|
make_pending(later, tok, mdoc, line, ppos); |
make_pending(later, tok, mdoc, line, ppos); |
|
|
/* |
/* |
* Mark the place where the formatting - but not |
* Mark the place where the formatting - but not |
* the scope - of the current block ends. |
* the scope - of the current block ends. |
*/ |
*/ |
|
|
mdoc_endbody_alloc(mdoc, line, ppos, |
mdoc_endbody_alloc(mdoc, line, ppos, |
atok, body, ENDBODY_SPACE); |
atok, body, ENDBODY_SPACE); |
|
|
|
/* |
|
* If a block closing macro taking arguments |
|
* breaks another block, put the arguments |
|
* into the end marker and remeber the |
|
* end marker in order to close it out. |
|
*/ |
|
|
if (maxargs) { |
if (maxargs) { |
endbody = mdoc->last; |
endbody = mdoc->last; |
mdoc->next = MDOC_NEXT_CHILD; |
mdoc->next = MDOC_NEXT_CHILD; |
Line 749 blk_exp_close(MACRO_PROT_ARGS) |
|
Line 813 blk_exp_close(MACRO_PROT_ARGS) |
|
* open explicit block, or, in case there are only |
* open explicit block, or, in case there are only |
* implicit ones, the first open implicit block. |
* implicit ones, the first open implicit block. |
*/ |
*/ |
if (later && |
|
mdoc_macros[later->tok].flags & MDOC_EXPLICIT) |
if (later == NULL || |
continue; |
! (mdoc_macros[later->tok].flags & MDOC_EXPLICIT)) |
if (n->tok != MDOC_It) |
|
later = n; |
later = n; |
} |
} |
|
rew_sub(MDOC_BODY, mdoc, tok, line, ppos); |
|
|
if ( ! (mdoc_macros[tok].flags & MDOC_PARSED)) { |
if ( ! (mdoc_macros[tok].flags & MDOC_PARSED)) { |
if (buf[*pos] != '\0') |
if (buf[*pos] != '\0') |
Line 762 blk_exp_close(MACRO_PROT_ARGS) |
|
Line 826 blk_exp_close(MACRO_PROT_ARGS) |
|
mdoc->parse, line, ppos, |
mdoc->parse, line, ppos, |
"%s %s", mdoc_macronames[tok], |
"%s %s", mdoc_macronames[tok], |
buf + *pos); |
buf + *pos); |
rew_sub(MDOC_BODY, mdoc, tok, line, ppos); |
|
rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos); |
rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos); |
return(1); |
return; |
} |
} |
rew_sub(MDOC_BODY, mdoc, tok, line, ppos); |
|
|
|
if (maxargs && endbody == NULL) { |
if (maxargs && endbody == NULL) { |
if (n == NULL) { |
if (n == NULL) { |
Line 796 blk_exp_close(MACRO_PROT_ARGS) |
|
Line 858 blk_exp_close(MACRO_PROT_ARGS) |
|
if (ac == ARGS_PUNCT || ac == ARGS_EOLN) |
if (ac == ARGS_PUNCT || ac == ARGS_EOLN) |
break; |
break; |
|
|
ntok = ac == ARGS_QWORD ? MDOC_MAX : lookup(tok, p); |
ntok = ac == ARGS_QWORD ? MDOC_MAX : |
|
lookup(mdoc, tok, line, lastarg, p); |
|
|
if (ntok == MDOC_MAX) { |
if (ntok == MDOC_MAX) { |
dword(mdoc, line, lastarg, p, DELIM_MAX, |
dword(mdoc, line, lastarg, p, DELIM_MAX, |
Line 811 blk_exp_close(MACRO_PROT_ARGS) |
|
Line 874 blk_exp_close(MACRO_PROT_ARGS) |
|
rew_last(mdoc, endbody); |
rew_last(mdoc, endbody); |
flushed = 1; |
flushed = 1; |
} |
} |
|
|
mdoc->flags &= ~MDOC_NEWLINE; |
mdoc->flags &= ~MDOC_NEWLINE; |
|
mdoc_macro(mdoc, ntok, line, lastarg, pos, buf); |
if ( ! mdoc_macro(mdoc, ntok, line, lastarg, pos, buf)) |
|
return(0); |
|
break; |
break; |
} |
} |
|
|
Line 827 blk_exp_close(MACRO_PROT_ARGS) |
|
Line 887 blk_exp_close(MACRO_PROT_ARGS) |
|
} |
} |
if (nl) |
if (nl) |
append_delims(mdoc, line, pos, buf); |
append_delims(mdoc, line, pos, buf); |
return(1); |
|
} |
} |
|
|
static int |
static void |
in_line(MACRO_PROT_ARGS) |
in_line(MACRO_PROT_ARGS) |
{ |
{ |
int la, scope, cnt, firstarg, mayopen, nc, nl; |
int la, scope, cnt, firstarg, mayopen, nc, nl; |
enum margverr av; |
|
enum mdoct ntok; |
enum mdoct ntok; |
enum margserr ac; |
enum margserr ac; |
enum mdelim d; |
enum mdelim d; |
Line 867 in_line(MACRO_PROT_ARGS) |
|
Line 925 in_line(MACRO_PROT_ARGS) |
|
break; |
break; |
} |
} |
|
|
for (arg = NULL;; ) { |
mdoc_argv(mdoc, line, tok, &arg, pos, buf); |
la = *pos; |
|
av = mdoc_argv(mdoc, line, tok, &arg, pos, buf); |
|
|
|
if (ARGV_WORD == av) { |
|
*pos = la; |
|
break; |
|
} |
|
if (ARGV_EOLN == av) |
|
break; |
|
if (ARGV_ARG == av) |
|
continue; |
|
|
|
mdoc_argv_free(arg); |
|
return(0); |
|
} |
|
|
|
d = DELIM_NONE; |
d = DELIM_NONE; |
firstarg = 1; |
firstarg = 1; |
mayopen = 1; |
mayopen = 1; |
Line 917 in_line(MACRO_PROT_ARGS) |
|
Line 960 in_line(MACRO_PROT_ARGS) |
|
} |
} |
|
|
ntok = (ac == ARGS_QWORD || (tok == MDOC_Fn && !cnt)) ? |
ntok = (ac == ARGS_QWORD || (tok == MDOC_Fn && !cnt)) ? |
MDOC_MAX : lookup(tok, p); |
MDOC_MAX : lookup(mdoc, tok, line, la, p); |
|
|
/* |
/* |
* In this case, we've located a submacro and must |
* In this case, we've located a submacro and must |
Line 938 in_line(MACRO_PROT_ARGS) |
|
Line 981 in_line(MACRO_PROT_ARGS) |
|
mdoc->parse, line, ppos, |
mdoc->parse, line, ppos, |
mdoc_macronames[tok]); |
mdoc_macronames[tok]); |
} |
} |
|
mdoc_macro(mdoc, ntok, line, la, pos, buf); |
if ( ! mdoc_macro(mdoc, ntok, line, la, pos, buf)) |
|
return(0); |
|
if (nl) |
if (nl) |
append_delims(mdoc, line, pos, buf); |
append_delims(mdoc, line, pos, buf); |
return(1); |
return; |
} |
} |
|
|
/* |
/* |
Line 1029 in_line(MACRO_PROT_ARGS) |
|
Line 1070 in_line(MACRO_PROT_ARGS) |
|
} |
} |
if (nl) |
if (nl) |
append_delims(mdoc, line, pos, buf); |
append_delims(mdoc, line, pos, buf); |
return(1); |
|
} |
} |
|
|
static int |
static void |
blk_full(MACRO_PROT_ARGS) |
blk_full(MACRO_PROT_ARGS) |
{ |
{ |
int la, nl, nparsed; |
int la, nl, parsed; |
struct mdoc_arg *arg; |
struct mdoc_arg *arg; |
struct mdoc_node *head; /* save of head macro */ |
struct mdoc_node *blk; /* Our own block. */ |
struct mdoc_node *body; /* save of body macro */ |
struct mdoc_node *head; /* Our own head. */ |
|
struct mdoc_node *body; /* Our own body. */ |
struct mdoc_node *n; |
struct mdoc_node *n; |
enum mdoct ntok; |
|
enum margserr ac, lac; |
enum margserr ac, lac; |
enum margverr av; |
|
char *p; |
char *p; |
|
|
nl = MDOC_NEWLINE & mdoc->flags; |
nl = MDOC_NEWLINE & mdoc->flags; |
Line 1051 blk_full(MACRO_PROT_ARGS) |
|
Line 1090 blk_full(MACRO_PROT_ARGS) |
|
|
|
if (tok == MDOC_It) { |
if (tok == MDOC_It) { |
for (n = mdoc->last; n; n = n->parent) |
for (n = mdoc->last; n; n = n->parent) |
if (n->tok == MDOC_Bl && |
if (n->tok == MDOC_Bl && n->type == MDOC_BLOCK && |
! (n->flags & MDOC_VALID)) |
! (n->flags & (MDOC_VALID | MDOC_BREAK))) |
break; |
break; |
if (n == NULL) { |
if (n == NULL) { |
mandoc_vmsg(MANDOCERR_IT_STRAY, mdoc->parse, |
mandoc_vmsg(MANDOCERR_IT_STRAY, mdoc->parse, |
line, ppos, "It %s", buf + *pos); |
line, ppos, "It %s", buf + *pos); |
mdoc_elem_alloc(mdoc, line, ppos, MDOC_br, NULL); |
mdoc_elem_alloc(mdoc, line, ppos, MDOC_br, NULL); |
rew_elem(mdoc, MDOC_br); |
rew_elem(mdoc, MDOC_br); |
return(1); |
return; |
} |
} |
} |
} |
|
|
Line 1079 blk_full(MACRO_PROT_ARGS) |
|
Line 1118 blk_full(MACRO_PROT_ARGS) |
|
* regular child nodes. |
* regular child nodes. |
*/ |
*/ |
|
|
for (arg = NULL;; ) { |
mdoc_argv(mdoc, line, tok, &arg, pos, buf); |
la = *pos; |
blk = mdoc_block_alloc(mdoc, line, ppos, tok, arg); |
av = mdoc_argv(mdoc, line, tok, &arg, pos, buf); |
|
|
|
if (ARGV_WORD == av) { |
|
*pos = la; |
|
break; |
|
} |
|
|
|
if (ARGV_EOLN == av) |
|
break; |
|
if (ARGV_ARG == av) |
|
continue; |
|
|
|
mdoc_argv_free(arg); |
|
return(0); |
|
} |
|
|
|
mdoc_block_alloc(mdoc, line, ppos, tok, arg); |
|
head = body = NULL; |
head = body = NULL; |
|
|
/* |
/* |
* Exception: Heads of `It' macros in `-diag' lists are not |
* Exception: Heads of `It' macros in `-diag' lists are not |
* parsed, even though `It' macros in general are parsed. |
* parsed, even though `It' macros in general are parsed. |
*/ |
*/ |
nparsed = tok == MDOC_It && |
|
mdoc->last->parent->tok == MDOC_Bl && |
|
mdoc->last->parent->norm->Bl.type == LIST_diag; |
|
|
|
|
parsed = tok != MDOC_It || |
|
mdoc->last->parent->tok != MDOC_Bl || |
|
mdoc->last->parent->norm->Bl.type != LIST_diag; |
|
|
/* |
/* |
* The `Nd' macro has all arguments in its body: it's a hybrid |
* The `Nd' macro has all arguments in its body: it's a hybrid |
* of block partial-explicit and full-implicit. Stupid. |
* of block partial-explicit and full-implicit. Stupid. |
Line 1115 blk_full(MACRO_PROT_ARGS) |
|
Line 1138 blk_full(MACRO_PROT_ARGS) |
|
|
|
if (tok == MDOC_Nd) { |
if (tok == MDOC_Nd) { |
head = mdoc_head_alloc(mdoc, line, ppos, tok); |
head = mdoc_head_alloc(mdoc, line, ppos, tok); |
rew_sub(MDOC_HEAD, mdoc, tok, line, ppos); |
rew_last(mdoc, head); |
body = mdoc_body_alloc(mdoc, line, ppos, tok); |
body = mdoc_body_alloc(mdoc, line, ppos, tok); |
} |
} |
|
|
Line 1167 blk_full(MACRO_PROT_ARGS) |
|
Line 1190 blk_full(MACRO_PROT_ARGS) |
|
if (ac == ARGS_PHRASE || |
if (ac == ARGS_PHRASE || |
ac == ARGS_PEND || |
ac == ARGS_PEND || |
ac == ARGS_PPHRASE) { |
ac == ARGS_PPHRASE) { |
|
|
/* |
/* |
* If we haven't opened a body yet, rewind the |
* If we haven't opened a body yet, rewind the |
* head; if we have, rewind that instead. |
* head; if we have, rewind that instead. |
Line 1174 blk_full(MACRO_PROT_ARGS) |
|
Line 1198 blk_full(MACRO_PROT_ARGS) |
|
|
|
rew_sub(body ? MDOC_BODY : MDOC_HEAD, |
rew_sub(body ? MDOC_BODY : MDOC_HEAD, |
mdoc, tok, line, ppos); |
mdoc, tok, line, ppos); |
|
|
/* Then allocate our body context. */ |
|
|
|
body = mdoc_body_alloc(mdoc, line, ppos, tok); |
body = mdoc_body_alloc(mdoc, line, ppos, tok); |
|
|
/* |
/* |
Line 1189 blk_full(MACRO_PROT_ARGS) |
|
Line 1210 blk_full(MACRO_PROT_ARGS) |
|
mdoc->flags |= MDOC_PPHRASE; |
mdoc->flags |= MDOC_PPHRASE; |
if (ac == ARGS_PEND && lac == ARGS_PPHRASE) |
if (ac == ARGS_PEND && lac == ARGS_PPHRASE) |
mdoc->flags |= MDOC_PPHRASE; |
mdoc->flags |= MDOC_PPHRASE; |
|
parse_rest(mdoc, MDOC_MAX, line, &la, buf); |
if ( ! phrase(mdoc, line, la, buf)) |
|
return(0); |
|
|
|
mdoc->flags &= ~MDOC_PPHRASE; |
mdoc->flags &= ~MDOC_PPHRASE; |
continue; |
continue; |
} |
} |
|
|
ntok = nparsed || ac == ARGS_QWORD ? |
if (macro_or_word(mdoc, tok, line, la, pos, buf, parsed)) |
MDOC_MAX : lookup(tok, p); |
break; |
|
|
if (ntok == MDOC_MAX) { |
|
dword(mdoc, line, la, p, DELIM_MAX, |
|
MDOC_JOIN & mdoc_macros[tok].flags); |
|
continue; |
|
} |
|
|
|
if ( ! mdoc_macro(mdoc, ntok, line, la, pos, buf)) |
|
return(0); |
|
break; |
|
} |
} |
|
|
|
if (blk->flags & MDOC_VALID) |
|
return; |
if (head == NULL) |
if (head == NULL) |
head = mdoc_head_alloc(mdoc, line, ppos, tok); |
head = mdoc_head_alloc(mdoc, line, ppos, tok); |
if (nl) |
if (nl) |
append_delims(mdoc, line, pos, buf); |
append_delims(mdoc, line, pos, buf); |
|
if (body != NULL) |
/* If we've already opened our body, exit now. */ |
|
|
|
if (NULL != body) |
|
goto out; |
goto out; |
|
|
/* |
/* |
Line 1228 blk_full(MACRO_PROT_ARGS) |
|
Line 1235 blk_full(MACRO_PROT_ARGS) |
|
* sub-block. |
* sub-block. |
*/ |
*/ |
for (n = mdoc->last; n && n != head; n = n->parent) { |
for (n = mdoc->last; n && n != head; n = n->parent) { |
if (MDOC_BLOCK == n->type && |
if (n->type == MDOC_BLOCK && |
MDOC_EXPLICIT & mdoc_macros[n->tok].flags && |
mdoc_macros[n->tok].flags & MDOC_EXPLICIT && |
! (MDOC_VALID & n->flags)) { |
! (n->flags & MDOC_VALID)) { |
n->pending = head; |
n->pending = head; |
return(1); |
return; |
} |
} |
} |
} |
|
|
Line 1240 blk_full(MACRO_PROT_ARGS) |
|
Line 1247 blk_full(MACRO_PROT_ARGS) |
|
|
|
rew_sub(MDOC_HEAD, mdoc, tok, line, ppos); |
rew_sub(MDOC_HEAD, mdoc, tok, line, ppos); |
mdoc_body_alloc(mdoc, line, ppos, tok); |
mdoc_body_alloc(mdoc, line, ppos, tok); |
|
|
out: |
out: |
if (mdoc->flags & MDOC_FREECOL) { |
if (mdoc->flags & MDOC_FREECOL) { |
rew_sub(MDOC_BODY, mdoc, tok, line, ppos); |
rew_sub(MDOC_BODY, mdoc, tok, line, ppos); |
rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos); |
rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos); |
mdoc->flags &= ~MDOC_FREECOL; |
mdoc->flags &= ~MDOC_FREECOL; |
} |
} |
return(1); |
|
} |
} |
|
|
static int |
static void |
blk_part_imp(MACRO_PROT_ARGS) |
blk_part_imp(MACRO_PROT_ARGS) |
{ |
{ |
int la, nl; |
int la, nl; |
enum mdoct ntok; |
|
enum margserr ac; |
enum margserr ac; |
char *p; |
char *p; |
struct mdoc_node *blk; /* saved block context */ |
struct mdoc_node *blk; /* saved block context */ |
Line 1273 blk_part_imp(MACRO_PROT_ARGS) |
|
Line 1277 blk_part_imp(MACRO_PROT_ARGS) |
|
*/ |
*/ |
|
|
blk = mdoc_block_alloc(mdoc, line, ppos, tok, NULL); |
blk = mdoc_block_alloc(mdoc, line, ppos, tok, NULL); |
mdoc_head_alloc(mdoc, line, ppos, tok); |
rew_last(mdoc, mdoc_head_alloc(mdoc, line, ppos, tok)); |
rew_sub(MDOC_HEAD, mdoc, tok, line, ppos); |
|
|
|
/* |
/* |
* Open the body scope "on-demand", that is, after we've |
* Open the body scope "on-demand", that is, after we've |
Line 1297 blk_part_imp(MACRO_PROT_ARGS) |
|
Line 1300 blk_part_imp(MACRO_PROT_ARGS) |
|
if (body == NULL) |
if (body == NULL) |
body = mdoc_body_alloc(mdoc, line, ppos, tok); |
body = mdoc_body_alloc(mdoc, line, ppos, tok); |
|
|
ntok = ac == ARGS_QWORD ? MDOC_MAX : lookup(tok, p); |
if (macro_or_word(mdoc, tok, line, la, pos, buf, 1)) |
|
break; |
if (ntok == MDOC_MAX) { |
|
dword(mdoc, line, la, p, DELIM_MAX, |
|
MDOC_JOIN & mdoc_macros[tok].flags); |
|
continue; |
|
} |
|
|
|
if ( ! mdoc_macro(mdoc, ntok, line, la, pos, buf)) |
|
return(0); |
|
break; |
|
} |
} |
|
|
/* Clean-ups to leave in a consistent state. */ |
|
|
|
if (body == NULL) |
if (body == NULL) |
body = mdoc_body_alloc(mdoc, line, ppos, tok); |
body = mdoc_body_alloc(mdoc, line, ppos, tok); |
|
|
Line 1320 blk_part_imp(MACRO_PROT_ARGS) |
|
Line 1311 blk_part_imp(MACRO_PROT_ARGS) |
|
* postpone closing out the current block |
* postpone closing out the current block |
* until the rew_sub() call closing out the sub-block. |
* until the rew_sub() call closing out the sub-block. |
*/ |
*/ |
|
|
for (n = mdoc->last; n && n != body && n != blk->parent; |
for (n = mdoc->last; n && n != body && n != blk->parent; |
n = n->parent) { |
n = n->parent) { |
if (n->type == MDOC_BLOCK && |
if (n->type == MDOC_BLOCK && |
Line 1328 blk_part_imp(MACRO_PROT_ARGS) |
|
Line 1320 blk_part_imp(MACRO_PROT_ARGS) |
|
make_pending(n, tok, mdoc, line, ppos); |
make_pending(n, tok, mdoc, line, ppos); |
mdoc_endbody_alloc(mdoc, line, ppos, |
mdoc_endbody_alloc(mdoc, line, ppos, |
tok, body, ENDBODY_NOSPACE); |
tok, body, ENDBODY_NOSPACE); |
return(1); |
return; |
} |
} |
} |
} |
assert(n == body); |
assert(n == body); |
rew_sub(MDOC_BODY, mdoc, tok, line, ppos); |
rew_last(mdoc, body); |
|
|
/* Standard appending of delimiters. */ |
|
|
|
if (nl) |
if (nl) |
append_delims(mdoc, line, pos, buf); |
append_delims(mdoc, line, pos, buf); |
|
rew_last(mdoc, blk); |
|
|
/* Rewind scope, if applicable. */ |
/* |
|
* The current block extends an enclosing block. |
|
* Now that the current block ends, close the enclosing block, too. |
|
*/ |
|
|
rew_sub(MDOC_BLOCK, mdoc, tok, line, ppos); |
while ((blk = blk->pending) != NULL) { |
|
rew_last(mdoc, blk); |
|
if (blk->type == MDOC_HEAD) |
|
mdoc_body_alloc(mdoc, blk->line, blk->pos, blk->tok); |
|
} |
|
|
/* Move trailing .Ns out of scope. */ |
/* Move trailing .Ns out of scope. */ |
|
|
Line 1349 blk_part_imp(MACRO_PROT_ARGS) |
|
Line 1346 blk_part_imp(MACRO_PROT_ARGS) |
|
/* Do nothing. */ ; |
/* Do nothing. */ ; |
if (n && n->tok == MDOC_Ns) |
if (n && n->tok == MDOC_Ns) |
mdoc_node_relink(mdoc, n); |
mdoc_node_relink(mdoc, n); |
|
|
return(1); |
|
} |
} |
|
|
static int |
static void |
blk_part_exp(MACRO_PROT_ARGS) |
blk_part_exp(MACRO_PROT_ARGS) |
{ |
{ |
int la, nl; |
int la, nl; |
enum margserr ac; |
enum margserr ac; |
struct mdoc_node *head; /* keep track of head */ |
struct mdoc_node *head; /* keep track of head */ |
struct mdoc_node *body; /* keep track of body */ |
|
char *p; |
char *p; |
enum mdoct ntok; |
|
|
|
nl = MDOC_NEWLINE & mdoc->flags; |
nl = MDOC_NEWLINE & mdoc->flags; |
|
|
Line 1372 blk_part_exp(MACRO_PROT_ARGS) |
|
Line 1365 blk_part_exp(MACRO_PROT_ARGS) |
|
*/ |
*/ |
|
|
mdoc_block_alloc(mdoc, line, ppos, tok, NULL); |
mdoc_block_alloc(mdoc, line, ppos, tok, NULL); |
for (head = body = NULL; ; ) { |
head = NULL; |
|
for (;;) { |
la = *pos; |
la = *pos; |
ac = mdoc_args(mdoc, line, pos, buf, tok, &p); |
ac = mdoc_args(mdoc, line, pos, buf, tok, &p); |
if (ac == ARGS_PUNCT || ac == ARGS_EOLN) |
if (ac == ARGS_PUNCT || ac == ARGS_EOLN) |
Line 1382 blk_part_exp(MACRO_PROT_ARGS) |
|
Line 1376 blk_part_exp(MACRO_PROT_ARGS) |
|
|
|
if (head == NULL && ac != ARGS_QWORD && |
if (head == NULL && ac != ARGS_QWORD && |
mdoc_isdelim(p) == DELIM_OPEN) { |
mdoc_isdelim(p) == DELIM_OPEN) { |
assert(NULL == body); |
|
dword(mdoc, line, la, p, DELIM_OPEN, 0); |
dword(mdoc, line, la, p, DELIM_OPEN, 0); |
continue; |
continue; |
} |
} |
|
|
if (head == NULL) { |
if (head == NULL) { |
assert(body == NULL); |
|
head = mdoc_head_alloc(mdoc, line, ppos, tok); |
head = mdoc_head_alloc(mdoc, line, ppos, tok); |
} |
if (tok == MDOC_Eo) /* Not parsed. */ |
|
|
/* |
|
* `Eo' gobbles any data into the head, but most other |
|
* macros just immediately close out and begin the body. |
|
*/ |
|
|
|
if (body == NULL) { |
|
assert(head); |
|
/* No check whether it's a macro! */ |
|
if (tok == MDOC_Eo) |
|
dword(mdoc, line, la, p, DELIM_MAX, 0); |
dword(mdoc, line, la, p, DELIM_MAX, 0); |
rew_sub(MDOC_HEAD, mdoc, tok, line, ppos); |
rew_last(mdoc, head); |
body = mdoc_body_alloc(mdoc, line, ppos, tok); |
mdoc_body_alloc(mdoc, line, ppos, tok); |
if (tok == MDOC_Eo) |
if (tok == MDOC_Eo) |
continue; |
continue; |
} |
} |
assert(head != NULL && body != NULL); |
|
|
|
ntok = ac == ARGS_QWORD ? MDOC_MAX : lookup(tok, p); |
if (macro_or_word(mdoc, tok, line, la, pos, buf, 1)) |
if (ntok == MDOC_MAX) { |
break; |
dword(mdoc, line, la, p, DELIM_MAX, |
|
MDOC_JOIN & mdoc_macros[tok].flags); |
|
continue; |
|
} |
|
if ( ! mdoc_macro(mdoc, ntok, line, la, pos, buf)) |
|
return(0); |
|
break; |
|
} |
} |
|
|
/* Clean-up to leave in a consistent state. */ |
/* Clean-up to leave in a consistent state. */ |
|
|
if (head == NULL) |
if (head == NULL) { |
mdoc_head_alloc(mdoc, line, ppos, tok); |
rew_last(mdoc, mdoc_head_alloc(mdoc, line, ppos, tok)); |
|
|
if (body == NULL) { |
|
rew_sub(MDOC_HEAD, mdoc, tok, line, ppos); |
|
mdoc_body_alloc(mdoc, line, ppos, tok); |
mdoc_body_alloc(mdoc, line, ppos, tok); |
} |
} |
|
|
/* Standard appending of delimiters. */ |
|
|
|
if (nl) |
if (nl) |
append_delims(mdoc, line, pos, buf); |
append_delims(mdoc, line, pos, buf); |
return(1); |
|
} |
} |
|
|
static int |
static void |
in_line_argn(MACRO_PROT_ARGS) |
in_line_argn(MACRO_PROT_ARGS) |
{ |
{ |
int la, flushed, j, maxargs, nl; |
int la, flushed, j, maxargs, nl; |
enum margserr ac; |
enum margserr ac; |
enum margverr av; |
|
struct mdoc_arg *arg; |
struct mdoc_arg *arg; |
char *p; |
char *p; |
enum mdoct ntok; |
enum mdoct ntok; |
|
|
nl = MDOC_NEWLINE & mdoc->flags; |
nl = mdoc->flags & MDOC_NEWLINE; |
|
|
/* |
/* |
* A line macro that has a fixed number of arguments (maxargs). |
* A line macro that has a fixed number of arguments (maxargs). |
Line 1477 in_line_argn(MACRO_PROT_ARGS) |
|
Line 1443 in_line_argn(MACRO_PROT_ARGS) |
|
break; |
break; |
} |
} |
|
|
for (arg = NULL; ; ) { |
mdoc_argv(mdoc, line, tok, &arg, pos, buf); |
la = *pos; |
|
av = mdoc_argv(mdoc, line, tok, &arg, pos, buf); |
|
|
|
if (ARGV_WORD == av) { |
p = NULL; |
*pos = la; |
flushed = j = 0; |
break; |
for (;;) { |
} |
|
|
|
if (ARGV_EOLN == av) |
|
break; |
|
if (ARGV_ARG == av) |
|
continue; |
|
|
|
mdoc_argv_free(arg); |
|
return(0); |
|
} |
|
|
|
for (flushed = j = 0; ; ) { |
|
la = *pos; |
la = *pos; |
ac = mdoc_args(mdoc, line, pos, buf, tok, &p); |
ac = mdoc_args(mdoc, line, pos, buf, tok, &p); |
if (ac == ARGS_PUNCT || ac == ARGS_EOLN) |
if (ac == ARGS_PUNCT || ac == ARGS_EOLN) { |
|
if (j < 2 && tok == MDOC_Pf) |
|
mandoc_vmsg(MANDOCERR_PF_SKIP, |
|
mdoc->parse, line, ppos, "Pf %s", |
|
p == NULL ? "at eol" : p); |
break; |
break; |
|
} |
|
|
if ( ! (mdoc_macros[tok].flags & MDOC_IGNDELIM) && |
if ( ! (mdoc_macros[tok].flags & MDOC_IGNDELIM) && |
ac != ARGS_QWORD && j == 0 && |
ac != ARGS_QWORD && j == 0 && |
Line 1514 in_line_argn(MACRO_PROT_ARGS) |
|
Line 1471 in_line_argn(MACRO_PROT_ARGS) |
|
flushed = 1; |
flushed = 1; |
} |
} |
|
|
ntok = ac == ARGS_QWORD ? MDOC_MAX : lookup(tok, p); |
ntok = (ac == ARGS_QWORD || (tok == MDOC_Pf && j == 0)) ? |
|
MDOC_MAX : lookup(mdoc, tok, line, la, p); |
|
|
if (ntok != MDOC_MAX) { |
if (ntok != MDOC_MAX) { |
if ( ! flushed) |
if ( ! flushed) |
rew_elem(mdoc, tok); |
rew_elem(mdoc, tok); |
flushed = 1; |
flushed = 1; |
if ( ! mdoc_macro(mdoc, ntok, line, la, pos, buf)) |
mdoc_macro(mdoc, ntok, line, la, pos, buf); |
return(0); |
|
j++; |
j++; |
break; |
break; |
} |
} |
Line 1538 in_line_argn(MACRO_PROT_ARGS) |
|
Line 1495 in_line_argn(MACRO_PROT_ARGS) |
|
j++; |
j++; |
} |
} |
|
|
if (j == 0) |
if (j == 0) { |
mdoc_elem_alloc(mdoc, line, ppos, tok, arg); |
mdoc_elem_alloc(mdoc, line, ppos, tok, arg); |
|
if (ac == ARGS_PUNCT && tok == MDOC_Pf) |
/* Close out in a consistent state. */ |
append_delims(mdoc, line, pos, buf); |
|
} |
if ( ! flushed) |
if ( ! flushed) |
rew_elem(mdoc, tok); |
rew_elem(mdoc, tok); |
if (nl) |
if (nl) |
append_delims(mdoc, line, pos, buf); |
append_delims(mdoc, line, pos, buf); |
return(1); |
|
} |
} |
|
|
static int |
static void |
in_line_eoln(MACRO_PROT_ARGS) |
in_line_eoln(MACRO_PROT_ARGS) |
{ |
{ |
int la; |
|
enum margserr ac; |
|
enum margverr av; |
|
struct mdoc_arg *arg; |
struct mdoc_arg *arg; |
char *p; |
|
enum mdoct ntok; |
|
|
|
assert( ! (MDOC_PARSED & mdoc_macros[tok].flags)); |
|
|
|
if (tok == MDOC_Pp) |
if (tok == MDOC_Pp) |
rew_sub(MDOC_BLOCK, mdoc, MDOC_Nm, line, ppos); |
rew_sub(MDOC_BLOCK, mdoc, MDOC_Nm, line, ppos); |
|
|
/* Parse macro arguments. */ |
mdoc_argv(mdoc, line, tok, &arg, pos, buf); |
|
|
for (arg = NULL; ; ) { |
|
la = *pos; |
|
av = mdoc_argv(mdoc, line, tok, &arg, pos, buf); |
|
|
|
if (ARGV_WORD == av) { |
|
*pos = la; |
|
break; |
|
} |
|
if (ARGV_EOLN == av) |
|
break; |
|
if (ARGV_ARG == av) |
|
continue; |
|
|
|
mdoc_argv_free(arg); |
|
return(0); |
|
} |
|
|
|
/* Open element scope. */ |
|
|
|
mdoc_elem_alloc(mdoc, line, ppos, tok, arg); |
mdoc_elem_alloc(mdoc, line, ppos, tok, arg); |
|
if (parse_rest(mdoc, tok, line, pos, buf)) |
|
return; |
|
rew_elem(mdoc, tok); |
|
} |
|
|
/* Parse argument terms. */ |
/* |
|
* The simplest argument parser available: Parse the remaining |
|
* words until the end of the phrase or line and return 0 |
|
* or until the next macro, call that macro, and return 1. |
|
*/ |
|
static int |
|
parse_rest(struct mdoc *mdoc, enum mdoct tok, int line, int *pos, char *buf) |
|
{ |
|
int la; |
|
|
for (;;) { |
for (;;) { |
la = *pos; |
la = *pos; |
ac = mdoc_args(mdoc, line, pos, buf, tok, &p); |
if (mdoc_args(mdoc, line, pos, buf, tok, NULL) == ARGS_EOLN) |
if (ac == ARGS_EOLN) |
return(0); |
break; |
if (macro_or_word(mdoc, tok, line, la, pos, buf, 1)) |
|
return(1); |
ntok = ac == ARGS_QWORD ? MDOC_MAX : lookup(tok, p); |
|
|
|
if (ntok == MDOC_MAX) { |
|
dword(mdoc, line, la, p, DELIM_MAX, |
|
MDOC_JOIN & mdoc_macros[tok].flags); |
|
continue; |
|
} |
|
rew_elem(mdoc, tok); |
|
return(mdoc_macro(mdoc, ntok, line, la, pos, buf)); |
|
} |
} |
|
|
/* Close out (no delimiters). */ |
|
|
|
rew_elem(mdoc, tok); |
|
return(1); |
|
} |
} |
|
|
static int |
static void |
ctx_synopsis(MACRO_PROT_ARGS) |
ctx_synopsis(MACRO_PROT_ARGS) |
{ |
{ |
int nl; |
|
|
|
nl = MDOC_NEWLINE & mdoc->flags; |
if (~mdoc->flags & (MDOC_SYNOPSIS | MDOC_NEWLINE)) |
|
in_line(mdoc, tok, line, ppos, pos, buf); |
/* If we're not in the SYNOPSIS, go straight to in-line. */ |
else if (tok == MDOC_Nm) |
if ( ! (MDOC_SYNOPSIS & mdoc->flags)) |
blk_full(mdoc, tok, line, ppos, pos, buf); |
return(in_line(mdoc, tok, line, ppos, pos, buf)); |
else { |
|
assert(tok == MDOC_Vt); |
/* If we're a nested call, same place. */ |
blk_part_imp(mdoc, tok, line, ppos, pos, buf); |
if ( ! nl) |
} |
return(in_line(mdoc, tok, line, ppos, pos, buf)); |
|
|
|
/* |
|
* XXX: this will open a block scope; however, if later we end |
|
* up formatting the block scope, then child nodes will inherit |
|
* the formatting. Be careful. |
|
*/ |
|
if (MDOC_Nm == tok) |
|
return(blk_full(mdoc, tok, line, ppos, pos, buf)); |
|
assert(MDOC_Vt == tok); |
|
return(blk_part_imp(mdoc, tok, line, ppos, pos, buf)); |
|
} |
} |
|
|
/* |
/* |
Line 1644 ctx_synopsis(MACRO_PROT_ARGS) |
|
Line 1559 ctx_synopsis(MACRO_PROT_ARGS) |
|
* They're unusual because they're basically free-form text until a |
* They're unusual because they're basically free-form text until a |
* macro is encountered. |
* macro is encountered. |
*/ |
*/ |
static int |
static void |
phrase(struct mdoc *mdoc, int line, int ppos, char *buf) |
|
{ |
|
int la, pos; |
|
enum margserr ac; |
|
enum mdoct ntok; |
|
char *p; |
|
|
|
for (pos = ppos; ; ) { |
|
la = pos; |
|
|
|
ac = mdoc_zargs(mdoc, line, &pos, buf, &p); |
|
if (ac == ARGS_EOLN) |
|
break; |
|
|
|
ntok = ac == ARGS_QWORD ? MDOC_MAX : lookup_raw(p); |
|
|
|
if (ntok == MDOC_MAX) { |
|
dword(mdoc, line, la, p, DELIM_MAX, 1); |
|
continue; |
|
} |
|
|
|
if ( ! mdoc_macro(mdoc, ntok, line, la, &pos, buf)) |
|
return(0); |
|
append_delims(mdoc, line, &pos, buf); |
|
return(1); |
|
} |
|
|
|
return(1); |
|
} |
|
|
|
static int |
|
phrase_ta(MACRO_PROT_ARGS) |
phrase_ta(MACRO_PROT_ARGS) |
{ |
{ |
struct mdoc_node *n; |
struct mdoc_node *n; |
int la; |
|
enum mdoct ntok; |
|
enum margserr ac; |
|
char *p; |
|
|
|
/* Make sure we are in a column list or ignore this macro. */ |
/* Make sure we are in a column list or ignore this macro. */ |
|
|
n = mdoc->last; |
n = mdoc->last; |
while (NULL != n && MDOC_Bl != n->tok) |
while (n != NULL && |
|
(n->tok != MDOC_Bl || n->flags & (MDOC_VALID | MDOC_BREAK))) |
n = n->parent; |
n = n->parent; |
if (NULL == n || LIST_column != n->norm->Bl.type) { |
if (n == NULL || n->norm->Bl.type != LIST_column) { |
mandoc_msg(MANDOCERR_TA_STRAY, mdoc->parse, |
mandoc_msg(MANDOCERR_TA_STRAY, mdoc->parse, |
line, ppos, "Ta"); |
line, ppos, "Ta"); |
return(1); |
return; |
} |
} |
|
|
/* Advance to the next column. */ |
/* Advance to the next column. */ |
|
|
rew_sub(MDOC_BODY, mdoc, MDOC_It, line, ppos); |
rew_sub(MDOC_BODY, mdoc, MDOC_It, line, ppos); |
mdoc_body_alloc(mdoc, line, ppos, MDOC_It); |
mdoc_body_alloc(mdoc, line, ppos, MDOC_It); |
|
parse_rest(mdoc, MDOC_MAX, line, pos, buf); |
for (;;) { |
|
la = *pos; |
|
ac = mdoc_zargs(mdoc, line, pos, buf, &p); |
|
if (ac == ARGS_EOLN) |
|
break; |
|
|
|
ntok = ac == ARGS_QWORD ? MDOC_MAX : lookup_raw(p); |
|
|
|
if (ntok == MDOC_MAX) { |
|
dword(mdoc, line, la, p, DELIM_MAX, |
|
MDOC_JOIN & mdoc_macros[tok].flags); |
|
continue; |
|
} |
|
|
|
if ( ! mdoc_macro(mdoc, ntok, line, la, pos, buf)) |
|
return(0); |
|
append_delims(mdoc, line, pos, buf); |
|
return(1); |
|
} |
|
|
|
return(1); |
|
} |
} |