-/* $Id: mdoc_macro.c,v 1.102 2011/03/17 09:16:38 kristaps Exp $ */
+/* $Id: mdoc_macro.c,v 1.106 2011/03/22 14:33:05 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
#include <string.h>
#include <time.h>
+#include "mdoc.h"
#include "mandoc.h"
#include "libmdoc.h"
#include "libmandoc.h"
static int obsolete(MACRO_PROT_ARGS);
static int phrase_ta(MACRO_PROT_ARGS);
+static int dword(struct mdoc *, int, int,
+ const char *, enum mdelim);
static int append_delims(struct mdoc *,
int, int *, char *);
static enum mdoct lookup(enum mdoct, const char *);
taker->pending = broken->pending;
}
broken->pending = breaker;
- mdoc_vmsg(m, MANDOCERR_SCOPENEST, line, ppos,
- "%s breaks %s", mdoc_macronames[tok],
- mdoc_macronames[broken->tok]);
+ mandoc_vmsg(MANDOCERR_SCOPENEST, m->parse, line, ppos,
+ "%s breaks %s", mdoc_macronames[tok],
+ mdoc_macronames[broken->tok]);
return(1);
}
case (REWIND_THIS):
break;
case (REWIND_FORCE):
- mdoc_vmsg(m, MANDOCERR_SCOPEBROKEN, line, ppos,
- "%s breaks %s", mdoc_macronames[tok],
- mdoc_macronames[n->tok]);
+ mandoc_vmsg(MANDOCERR_SCOPEBROKEN, m->parse,
+ line, ppos, "%s breaks %s",
+ mdoc_macronames[tok],
+ mdoc_macronames[n->tok]);
/* FALLTHROUGH */
case (REWIND_MORE):
n = n->parent;
return(1);
}
+/*
+ * Allocate a word and check whether it's punctuation or not.
+ * Punctuation consists of those tokens found in mdoc_isdelim().
+ */
+static int
+dword(struct mdoc *m, int line,
+ int col, const char *p, enum mdelim d)
+{
+
+ if (DELIM_MAX == d)
+ d = mdoc_isdelim(p);
+
+ if ( ! mdoc_word_alloc(m, line, col, p))
+ return(0);
+
+ if (DELIM_OPEN == d)
+ m->last->flags |= MDOC_DELIMO;
+ else if (DELIM_CLOSE == d)
+ m->last->flags |= MDOC_DELIMC;
+
+ return(1);
+}
static int
append_delims(struct mdoc *m, int line, int *pos, char *buf)
else if (ARGS_EOLN == ac)
break;
- assert(DELIM_NONE != mandoc_isdelim(p));
- if ( ! mdoc_word_alloc(m, line, la, p))
- return(0);
+ dword(m, line, la, p, DELIM_MAX);
/*
* If we encounter end-of-sentence symbols, then trigger
if ( ! (MDOC_CALLABLE & mdoc_macros[tok].flags)) {
/* FIXME: do this in validate */
if (buf[*pos])
- if ( ! mdoc_pmsg(m, line, ppos, MANDOCERR_ARGSLOST))
- return(0);
+ mdoc_pmsg(m, line, ppos, MANDOCERR_ARGSLOST);
if ( ! rew_sub(MDOC_BODY, m, tok, line, ppos))
return(0);
ntok = ARGS_QWORD == ac ? MDOC_MAX : lookup(tok, p);
if (MDOC_MAX == ntok) {
- if ( ! mdoc_word_alloc(m, line, lastarg, p))
+ if ( ! dword(m, line, lastarg, p, DELIM_MAX))
return(0);
continue;
}
return(0);
} else if ( ! nc && 0 == cnt) {
mdoc_argv_free(arg);
- if ( ! mdoc_pmsg(m, line, ppos, MANDOCERR_MACROEMPTY))
- return(0);
+ mdoc_pmsg(m, line, ppos, MANDOCERR_MACROEMPTY);
}
+
if ( ! mdoc_macro(m, ntok, line, la, pos, buf))
return(0);
if ( ! nl)
* the word.
*/
- d = ARGS_QWORD == ac ? DELIM_NONE : mandoc_isdelim(p);
+ d = ARGS_QWORD == ac ? DELIM_NONE : mdoc_isdelim(p);
if (DELIM_NONE != d) {
/*
if (DELIM_NONE == d)
cnt++;
- if ( ! mdoc_word_alloc(m, line, la, p))
+
+ if ( ! dword(m, line, la, p, d))
return(0);
/*
return(0);
} else if ( ! nc && 0 == cnt) {
mdoc_argv_free(arg);
- if ( ! mdoc_pmsg(m, line, ppos, MANDOCERR_MACROEMPTY))
- return(0);
+ mdoc_pmsg(m, line, ppos, MANDOCERR_MACROEMPTY);
}
if ( ! nl)
ARGS_PHRASE != ac &&
ARGS_PPHRASE != ac &&
ARGS_QWORD != ac &&
- DELIM_OPEN == mandoc_isdelim(p)) {
- if ( ! mdoc_word_alloc(m, line, la, p))
+ DELIM_OPEN == mdoc_isdelim(p)) {
+ if ( ! dword(m, line, la, p, DELIM_OPEN))
return(0);
continue;
}
ntok = ARGS_QWORD == ac ? MDOC_MAX : lookup(tok, p);
if (MDOC_MAX == ntok) {
- if ( ! mdoc_word_alloc(m, line, la, p))
+ if ( ! dword(m, line, la, p, DELIM_MAX))
return(0);
continue;
}
break;
if (NULL == body && ARGS_QWORD != ac &&
- DELIM_OPEN == mandoc_isdelim(p)) {
- if ( ! mdoc_word_alloc(m, line, la, p))
+ DELIM_OPEN == mdoc_isdelim(p)) {
+ if ( ! dword(m, line, la, p, DELIM_OPEN))
return(0);
continue;
}
ntok = ARGS_QWORD == ac ? MDOC_MAX : lookup(tok, p);
if (MDOC_MAX == ntok) {
- if ( ! mdoc_word_alloc(m, line, la, p))
+ if ( ! dword(m, line, la, p, DELIM_MAX))
return(0);
continue;
}
* is ugly behaviour nodding its head to OpenBSD's overwhelming
* crufty use of `Op' breakage.
*/
- if (n != body && ! mdoc_vmsg(m, MANDOCERR_SCOPENEST,
- line, ppos, "%s broken", mdoc_macronames[tok]))
- return(0);
+ if (n != body)
+ mandoc_vmsg(MANDOCERR_SCOPENEST, m->parse, line, ppos,
+ "%s broken", mdoc_macronames[tok]);
if (n && ! rew_sub(MDOC_BODY, m, tok, line, ppos))
return(0);
/* Flush out leading punctuation. */
if (NULL == head && ARGS_QWORD != ac &&
- DELIM_OPEN == mandoc_isdelim(p)) {
+ DELIM_OPEN == mdoc_isdelim(p)) {
assert(NULL == body);
- if ( ! mdoc_word_alloc(m, line, la, p))
+ if ( ! dword(m, line, la, p, DELIM_OPEN))
return(0);
continue;
}
assert(head);
/* No check whether it's a macro! */
if (MDOC_Eo == tok)
- if ( ! mdoc_word_alloc(m, line, la, p))
+ if ( ! dword(m, line, la, p, DELIM_MAX))
return(0);
if ( ! rew_sub(MDOC_HEAD, m, tok, line, ppos))
ntok = ARGS_QWORD == ac ? MDOC_MAX : lookup(tok, p);
if (MDOC_MAX == ntok) {
- if ( ! mdoc_word_alloc(m, line, la, p))
+ if ( ! dword(m, line, la, p, DELIM_MAX))
return(0);
continue;
}
break;
if ( ! (MDOC_IGNDELIM & mdoc_macros[tok].flags) &&
- ARGS_QWORD != ac &&
- 0 == j && DELIM_OPEN == mandoc_isdelim(p)) {
- if ( ! mdoc_word_alloc(m, line, la, p))
+ ARGS_QWORD != ac && 0 == j &&
+ DELIM_OPEN == mdoc_isdelim(p)) {
+ if ( ! dword(m, line, la, p, DELIM_OPEN))
return(0);
continue;
} else if (0 == j)
if ( ! (MDOC_IGNDELIM & mdoc_macros[tok].flags) &&
ARGS_QWORD != ac &&
! flushed &&
- DELIM_NONE != mandoc_isdelim(p)) {
+ DELIM_NONE != mdoc_isdelim(p)) {
if ( ! rew_elem(m, tok))
return(0);
flushed = 1;
}
#endif
- if ( ! mdoc_word_alloc(m, line, la, p))
+ if ( ! dword(m, line, la, p, DELIM_MAX))
return(0);
j++;
}
ntok = ARGS_QWORD == ac ? MDOC_MAX : lookup(tok, p);
if (MDOC_MAX == ntok) {
- if ( ! mdoc_word_alloc(m, line, la, p))
+ if ( ! dword(m, line, la, p, DELIM_MAX))
return(0);
continue;
}
obsolete(MACRO_PROT_ARGS)
{
- return(mdoc_pmsg(m, line, ppos, MANDOCERR_MACROOBS));
+ mdoc_pmsg(m, line, ppos, MANDOCERR_MACROOBS);
+ return(1);
}
ntok = ARGS_QWORD == ac ? MDOC_MAX : lookup_raw(p);
if (MDOC_MAX == ntok) {
- if ( ! mdoc_word_alloc(m, line, la, p))
+ if ( ! dword(m, line, la, p, DELIM_MAX))
return(0);
continue;
}
ntok = ARGS_QWORD == ac ? MDOC_MAX : lookup_raw(p);
if (MDOC_MAX == ntok) {
- if ( ! mdoc_word_alloc(m, line, la, p))
+ if ( ! dword(m, line, la, p, DELIM_MAX))
return(0);
continue;
}