aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mdoc_macro.c
diff options
context:
space:
mode:
Diffstat (limited to 'mdoc_macro.c')
-rw-r--r--mdoc_macro.c73
1 files changed, 48 insertions, 25 deletions
diff --git a/mdoc_macro.c b/mdoc_macro.c
index f15082bf..dfd14907 100644
--- a/mdoc_macro.c
+++ b/mdoc_macro.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_macro.c,v 1.104 2011/03/20 16:02:05 kristaps Exp $ */
+/* $Id: mdoc_macro.c,v 1.105 2011/03/22 14:05:45 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -50,6 +50,8 @@ static int in_line(MACRO_PROT_ARGS);
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 *);
@@ -580,6 +582,28 @@ rew_sub(enum mdoc_type t, struct mdoc *m,
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)
@@ -600,9 +624,7 @@ 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
@@ -746,7 +768,7 @@ blk_exp_close(MACRO_PROT_ARGS)
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;
}
@@ -870,7 +892,7 @@ in_line(MACRO_PROT_ARGS)
* the word.
*/
- d = ARGS_QWORD == ac ? DELIM_NONE : mandoc_isdelim(p);
+ d = ARGS_QWORD == ac ? DELIM_NONE : mdoc_isdelim(p);
if (DELIM_NONE != d) {
/*
@@ -905,7 +927,8 @@ in_line(MACRO_PROT_ARGS)
if (DELIM_NONE == d)
cnt++;
- if ( ! mdoc_word_alloc(m, line, la, p))
+
+ if ( ! dword(m, line, la, p, d))
return(0);
/*
@@ -1060,8 +1083,8 @@ blk_full(MACRO_PROT_ARGS)
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;
}
@@ -1113,7 +1136,7 @@ blk_full(MACRO_PROT_ARGS)
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;
}
@@ -1223,8 +1246,8 @@ blk_part_imp(MACRO_PROT_ARGS)
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;
}
@@ -1238,7 +1261,7 @@ blk_part_imp(MACRO_PROT_ARGS)
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;
}
@@ -1354,9 +1377,9 @@ blk_part_exp(MACRO_PROT_ARGS)
/* 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;
}
@@ -1377,7 +1400,7 @@ blk_part_exp(MACRO_PROT_ARGS)
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))
@@ -1395,7 +1418,7 @@ blk_part_exp(MACRO_PROT_ARGS)
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;
}
@@ -1500,9 +1523,9 @@ in_line_argn(MACRO_PROT_ARGS)
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)
@@ -1530,7 +1553,7 @@ in_line_argn(MACRO_PROT_ARGS)
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;
@@ -1552,7 +1575,7 @@ in_line_argn(MACRO_PROT_ARGS)
}
#endif
- if ( ! mdoc_word_alloc(m, line, la, p))
+ if ( ! dword(m, line, la, p, DELIM_MAX))
return(0);
j++;
}
@@ -1623,7 +1646,7 @@ in_line_eoln(MACRO_PROT_ARGS)
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;
}
@@ -1703,7 +1726,7 @@ phrase(struct mdoc *m, int line, int ppos, char *buf)
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;
}
@@ -1748,7 +1771,7 @@ phrase_ta(MACRO_PROT_ARGS)
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;
}