summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libmdoc.h11
-rw-r--r--mdoc_argv.c5
-rw-r--r--mdoc_macro.c22
-rw-r--r--mdoc_strings.c16
4 files changed, 32 insertions, 22 deletions
diff --git a/libmdoc.h b/libmdoc.h
index cff9a62b..a8e8a6fc 100644
--- a/libmdoc.h
+++ b/libmdoc.h
@@ -131,6 +131,13 @@ enum margverr {
ARGV_WORD
};
+enum mdelim {
+ DELIM_NONE = 0,
+ DELIM_OPEN,
+ DELIM_MIDDLE,
+ DELIM_CLOSE
+};
+
extern const struct mdoc_macro *const mdoc_macros;
__BEGIN_DECLS
@@ -161,8 +168,8 @@ int mdoc_body_alloc(struct mdoc *, int, int, enum mdoct);
void mdoc_node_delete(struct mdoc *, struct mdoc_node *);
void mdoc_hash_init(void);
enum mdoct mdoc_hash_find(const char *);
-int mdoc_iscdelim(char);
-int mdoc_isdelim(const char *);
+enum mdelim mdoc_iscdelim(char);
+enum mdelim mdoc_isdelim(const char *);
size_t mdoc_isescape(const char *);
enum mdoc_sec mdoc_str2sec(const char *);
time_t mdoc_atotime(const char *);
diff --git a/mdoc_argv.c b/mdoc_argv.c
index 95c92e3e..33d03062 100644
--- a/mdoc_argv.c
+++ b/mdoc_argv.c
@@ -421,9 +421,10 @@ args(struct mdoc *m, int line, int *pos,
* we ONLY care about closing delimiters.
*/
- if ((fl & ARGS_DELIM) && mdoc_iscdelim(buf[*pos]) > 1) {
+ if ((fl & ARGS_DELIM) && DELIM_CLOSE == mdoc_iscdelim(buf[*pos])) {
for (i = *pos; buf[i]; ) {
- if (mdoc_iscdelim(buf[i]) < 2)
+ enum mdelim d = mdoc_iscdelim(buf[i]);
+ if (DELIM_NONE == d || DELIM_OPEN == d)
break;
i++;
if ('\0' == buf[i] || ' ' != buf[i])
diff --git a/mdoc_macro.c b/mdoc_macro.c
index 6d5ccb7e..87f87f18 100644
--- a/mdoc_macro.c
+++ b/mdoc_macro.c
@@ -640,7 +640,7 @@ append_delims(struct mdoc *m, int line, int *pos, char *buf)
else if (ARGS_EOLN == ac)
break;
- assert(mdoc_isdelim(p));
+ assert(DELIM_NONE != mdoc_isdelim(p));
if ( ! mdoc_word_alloc(m, line, la, p))
return(0);
@@ -750,10 +750,11 @@ blk_exp_close(MACRO_PROT_ARGS)
static int
in_line(MACRO_PROT_ARGS)
{
- int la, lastpunct, cnt, d, nc, nl;
+ int la, lastpunct, cnt, nc, nl;
enum margverr av;
enum mdoct ntok;
enum margserr ac;
+ enum mdelim d;
struct mdoc_arg *arg;
char *p;
@@ -846,9 +847,9 @@ in_line(MACRO_PROT_ARGS)
* the word.
*/
- d = ARGS_QWORD == ac ? 0 : mdoc_isdelim(p);
+ d = ARGS_QWORD == ac ? DELIM_NONE : mdoc_isdelim(p);
- if (ARGS_QWORD != ac && d) {
+ if (ARGS_QWORD != ac && DELIM_NONE != d) {
if (0 == lastpunct && ! rew_elem(m, tok))
return(0);
lastpunct = 1;
@@ -858,7 +859,7 @@ in_line(MACRO_PROT_ARGS)
lastpunct = 0;
}
- if ( ! d)
+ if (DELIM_NONE == d)
cnt++;
if ( ! mdoc_word_alloc(m, line, la, p))
return(0);
@@ -1000,7 +1001,7 @@ blk_full(MACRO_PROT_ARGS)
ARGS_PHRASE != ac &&
ARGS_PPHRASE != ac &&
ARGS_QWORD != ac &&
- 1 == mdoc_isdelim(p)) {
+ DELIM_OPEN == mdoc_isdelim(p)) {
if ( ! mdoc_word_alloc(m, line, la, p))
return(0);
continue;
@@ -1133,7 +1134,7 @@ blk_part_imp(MACRO_PROT_ARGS)
break;
if (NULL == body && ARGS_QWORD != ac &&
- 1 == mdoc_isdelim(p)) {
+ DELIM_OPEN == mdoc_isdelim(p)) {
if ( ! mdoc_word_alloc(m, line, la, p))
return(0);
continue;
@@ -1252,7 +1253,7 @@ blk_part_exp(MACRO_PROT_ARGS)
/* Flush out leading punctuation. */
if (NULL == head && ARGS_QWORD != ac &&
- 1 == mdoc_isdelim(p)) {
+ DELIM_OPEN == mdoc_isdelim(p)) {
assert(NULL == body);
if ( ! mdoc_word_alloc(m, line, la, p))
return(0);
@@ -1397,7 +1398,7 @@ in_line_argn(MACRO_PROT_ARGS)
if ( ! (MDOC_IGNDELIM & mdoc_macros[tok].flags) &&
ARGS_QWORD != ac &&
- 0 == j && 1 == mdoc_isdelim(p)) {
+ 0 == j && DELIM_OPEN == mdoc_isdelim(p)) {
if ( ! mdoc_word_alloc(m, line, la, p))
return(0);
continue;
@@ -1425,7 +1426,8 @@ in_line_argn(MACRO_PROT_ARGS)
if ( ! (MDOC_IGNDELIM & mdoc_macros[tok].flags) &&
ARGS_QWORD != ac &&
- ! flushed && mdoc_isdelim(p)) {
+ ! flushed &&
+ DELIM_NONE != mdoc_isdelim(p)) {
if ( ! rew_elem(m, tok))
return(0);
flushed = 1;
diff --git a/mdoc_strings.c b/mdoc_strings.c
index a852394b..a5ebdc83 100644
--- a/mdoc_strings.c
+++ b/mdoc_strings.c
@@ -57,17 +57,17 @@ static const char * const secnames[SEC__MAX] = {
* FIXME: this is repeated in print_text() (html.c) and term_word()
* (term.c).
*/
-int
+enum mdelim
mdoc_iscdelim(char p)
{
switch (p) {
- case('|'):
- /* FALLTHROUGH */
case('('):
/* FALLTHROUGH */
case('['):
- return(1);
+ return(DELIM_OPEN);
+ case('|'):
+ return(DELIM_MIDDLE);
case('.'):
/* FALLTHROUGH */
case(','):
@@ -83,16 +83,16 @@ mdoc_iscdelim(char p)
case(')'):
/* FALLTHROUGH */
case(']'):
- return(2);
+ return(DELIM_CLOSE);
default:
break;
}
- return(0);
+ return(DELIM_NONE);
}
-int
+enum mdelim
mdoc_isdelim(const char *p)
{
@@ -106,7 +106,7 @@ mdoc_isdelim(const char *p)
* is treated in exactly the same way as the vertical bar. This
* is the only function that checks for this.
*/
- return(0 == strcmp(p, "\\*(Ba"));
+ return(strcmp(p, "\\*(Ba") ? DELIM_NONE : DELIM_MIDDLE);
}