summaryrefslogtreecommitdiffstatshomepage
path: root/macro.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-01-09 14:45:44 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-01-09 14:45:44 +0000
commitd4119897e8e1f98438694ef49e678e47661a3ae5 (patch)
tree446ad2426ee9788d516b5967a7c89a76a52c6368 /macro.c
parent1b6424e34de2a96aaa28ac28d0b0d83c0b46bdf4 (diff)
downloadmandoc-d4119897e8e1f98438694ef49e678e47661a3ae5.tar.gz
mandoc-d4119897e8e1f98438694ef49e678e47661a3ae5.tar.zst
mandoc-d4119897e8e1f98438694ef49e678e47661a3ae5.zip
*** empty log message ***
Diffstat (limited to 'macro.c')
-rw-r--r--macro.c58
1 files changed, 41 insertions, 17 deletions
diff --git a/macro.c b/macro.c
index 9c5fc9bc..352af8be 100644
--- a/macro.c
+++ b/macro.c
@@ -1,4 +1,4 @@
-/* $Id: macro.c,v 1.29 2009/01/08 15:59:58 kristaps Exp $ */
+/* $Id: macro.c,v 1.30 2009/01/09 14:45:44 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -37,16 +37,23 @@ static int rewind_body(struct mdoc *, int);
static int rewind_last(struct mdoc *, struct mdoc_node *);
static int append_delims(struct mdoc *,
int, int, int *, char *);
-static int lookup(struct mdoc *, int, const char *);
+static int lookup(struct mdoc *, int, int, int, const char *);
static int
-lookup(struct mdoc *mdoc, int from, const char *p)
+lookup(struct mdoc *mdoc, int line, int pos, int from, const char *p)
{
+ int res;
- if ( ! (MDOC_PARSED & mdoc_macros[from].flags))
- return(MDOC_MAX);
- return(mdoc_find(mdoc, p));
+ res = mdoc_find(mdoc, p);
+ if (MDOC_PARSED & mdoc_macros[from].flags)
+ return(res);
+ if (MDOC_MAX == res)
+ return(res);
+
+ if ( ! mdoc_pwarn(mdoc, line, pos, WARN_SYNTAX_MACLIKE))
+ return(-1);
+ return(MDOC_MAX);
}
@@ -55,8 +62,14 @@ rewind_last(struct mdoc *mdoc, struct mdoc_node *to)
{
assert(to);
- if (mdoc->last == to)
+ mdoc->next = MDOC_NEXT_SIBLING;
+ if (mdoc->last == to) {
+ if ( ! mdoc_valid_post(mdoc))
+ return(0);
+ if ( ! mdoc_action_post(mdoc))
+ return(0);
return(1);
+ }
do {
mdoc->last = mdoc->last->parent;
@@ -67,7 +80,6 @@ rewind_last(struct mdoc *mdoc, struct mdoc_node *to)
return(0);
} while (mdoc->last != to);
- mdoc->next = MDOC_NEXT_SIBLING;
return(1);
}
@@ -315,7 +327,9 @@ macro_close_explicit(MACRO_PROT_ARGS)
if (ARGS_EOLN == c)
break;
- if (MDOC_MAX != (c = lookup(mdoc, tok, p))) {
+ if (-1 == (c = lookup(mdoc, line, lastarg, tok, p)))
+ return(0);
+ else if (MDOC_MAX != c) {
if ( ! flushed) {
if ( ! rewind_expblock(mdoc, tt))
return(0);
@@ -324,7 +338,7 @@ macro_close_explicit(MACRO_PROT_ARGS)
if ( ! mdoc_macro(mdoc, c, line, lastarg, pos, buf))
return(0);
break;
- }
+ }
if ( ! mdoc_word_alloc(mdoc, line, lastarg, p))
return(0);
@@ -417,7 +431,9 @@ macro_text(MACRO_PROT_ARGS)
if (ARGS_PUNCT == c)
break;
- if (MDOC_MAX != (c = lookup(mdoc, tok, p))) {
+ if (-1 == (c = lookup(mdoc, line, la, tok, p)))
+ return(0);
+ else if (MDOC_MAX != c) {
if ( ! rewind_elem(mdoc, tok)) {
mdoc_argv_free(argc, argv);
return(0);
@@ -524,12 +540,14 @@ macro_scoped(MACRO_PROT_ARGS)
if (ARGS_EOLN == c)
break;
- if (MDOC_MAX == (c = lookup(mdoc, tok, p))) {
+ if (-1 == (c = lookup(mdoc, line, lastarg, tok, p)))
+ return(0);
+ else if (MDOC_MAX == c) {
if ( ! mdoc_word_alloc(mdoc, line, lastarg, p))
return(0);
mdoc->next = MDOC_NEXT_SIBLING;
continue;
- }
+ }
if ( ! mdoc_macro(mdoc, c, line, lastarg, pos, buf))
return(0);
@@ -584,12 +602,14 @@ macro_scoped_line(MACRO_PROT_ARGS)
if (ARGS_EOLN == c)
break;
- if (MDOC_MAX == (c = lookup(mdoc, tok, p))) {
+ if (-1 == (c = lookup(mdoc, line, lastarg, tok, p)))
+ return(0);
+ else if (MDOC_MAX == c) {
if ( ! mdoc_word_alloc(mdoc, line, lastarg, p))
return(0);
mdoc->next = MDOC_NEXT_SIBLING;
continue;
- }
+ }
if ( ! mdoc_macro(mdoc, c, line, lastarg, pos, buf))
return(0);
@@ -668,7 +688,9 @@ macro_constant_scoped(MACRO_PROT_ARGS)
if (ARGS_EOLN == c)
break;
- if (MDOC_MAX != (c = lookup(mdoc, tok, p))) {
+ if (-1 == (c = lookup(mdoc, line, lastarg, tok, p)))
+ return(0);
+ else if (MDOC_MAX != c) {
if ( ! flushed) {
if ( ! rewind_head(mdoc, tok))
return(0);
@@ -780,7 +802,9 @@ macro_constant_delimited(MACRO_PROT_ARGS)
if (ARGS_EOLN == c)
break;
- if (MDOC_MAX != (c = lookup(mdoc, tok, p))) {
+ if (-1 == (c = lookup(mdoc, line, lastarg, tok, p)))
+ return(0);
+ else if (MDOC_MAX != c) {
if ( ! flushed && ! rewind_elem(mdoc, tok))
return(0);
flushed = 1;