summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2010-05-15 12:31:00 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2010-05-15 12:31:00 +0000
commita355e7868a2177fe355b4911c68ec4103093780b (patch)
tree0ecfe75c1bf25d6889187d8e20809583b057c59f /usr.bin
parent4365040b802cae8f70e1ea7ab12e7e0b1bf991ee (diff)
Distinguish OPEN, MIDDLE and CLOSE delimiters (using an enum).
Only OPEN are drawn before the beginning of a macro; this is new, before this, MIDDLE ('|') were drawn in front, too. Only CLOSE are pushed after the end of a macro (as before). ok kristaps@ This allows us to finally enable handling of leading punctuation without regressions.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mandoc/libmdoc.h13
-rw-r--r--usr.bin/mandoc/mdoc_argv.c7
-rw-r--r--usr.bin/mandoc/mdoc_macro.c51
-rw-r--r--usr.bin/mandoc/mdoc_strings.c18
4 files changed, 37 insertions, 52 deletions
diff --git a/usr.bin/mandoc/libmdoc.h b/usr.bin/mandoc/libmdoc.h
index d8175f8267a..3b59e440d82 100644
--- a/usr.bin/mandoc/libmdoc.h
+++ b/usr.bin/mandoc/libmdoc.h
@@ -1,4 +1,4 @@
-/* $Id: libmdoc.h,v 1.30 2010/05/14 14:47:44 schwarze Exp $ */
+/* $Id: libmdoc.h,v 1.31 2010/05/15 12:30:59 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -130,6 +130,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
@@ -160,8 +167,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/usr.bin/mandoc/mdoc_argv.c b/usr.bin/mandoc/mdoc_argv.c
index c97929729ad..6e284601a2f 100644
--- a/usr.bin/mandoc/mdoc_argv.c
+++ b/usr.bin/mandoc/mdoc_argv.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_argv.c,v 1.26 2010/05/14 19:52:43 schwarze Exp $ */
+/* $Id: mdoc_argv.c,v 1.27 2010/05/15 12:30:59 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -404,9 +404,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/usr.bin/mandoc/mdoc_macro.c b/usr.bin/mandoc/mdoc_macro.c
index 3f76b776175..a87b7827372 100644
--- a/usr.bin/mandoc/mdoc_macro.c
+++ b/usr.bin/mandoc/mdoc_macro.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_macro.c,v 1.39 2010/05/15 09:20:01 schwarze Exp $ */
+/* $Id: mdoc_macro.c,v 1.40 2010/05/15 12:30:59 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -632,7 +632,7 @@ append_delims(struct mdoc *mdoc, int line, int *pos, char *buf)
return(0);
else if (ARGS_EOLN == ac)
break;
- assert(mdoc_isdelim(p));
+ assert(DELIM_NONE != mdoc_isdelim(p));
if ( ! mdoc_word_alloc(mdoc, line, lastarg, p))
return(0);
}
@@ -728,10 +728,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;
@@ -824,9 +825,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;
@@ -836,7 +837,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);
@@ -961,11 +962,6 @@ blk_full(MACRO_PROT_ARGS)
if (ARGS_EOLN == ac)
break;
-/*
- * XXX Temporarily disable the handling of leading punctuation.
- * We must investigate the fallout before enabling this.
- */
-#if 0
/* Don't emit leading punct. for phrases. */
if (NULL == head &&
@@ -973,12 +969,11 @@ blk_full(MACRO_PROT_ARGS)
ARGS_PPHRASE != ac &&
ARGS_PEND != ac &&
ARGS_QWORD != ac &&
- 1 == mdoc_isdelim(p)) {
+ DELIM_OPEN == mdoc_isdelim(p)) {
if ( ! mdoc_word_alloc(m, line, la, p))
return(0);
continue;
}
-#endif
/* Always re-open head for phrases. */
@@ -1112,18 +1107,12 @@ blk_part_imp(MACRO_PROT_ARGS)
if (ARGS_PUNCT == ac)
break;
-/*
- * XXX Temporarily disable the handling of leading punctuation.
- * We must investigate the fallout before enabling this.
- */
-#if 0
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;
}
-#endif
if (NULL == body) {
if ( ! mdoc_body_alloc(m, line, ppos, tok))
@@ -1233,21 +1222,15 @@ blk_part_exp(MACRO_PROT_ARGS)
if (ARGS_EOLN == ac)
break;
-/*
- * XXX Temporarily disable the handling of leading punctuation.
- * We must investigate the fallout before enabling this.
- */
-#if 0
/* 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);
continue;
}
-#endif
if (NULL == head) {
assert(NULL == body);
@@ -1385,20 +1368,13 @@ in_line_argn(MACRO_PROT_ARGS)
if (ARGS_EOLN == ac)
break;
-/*
- * XXX Temporarily disable the handling of leading punctuation.
- * We must investigate the fallout before enabling this.
- */
-#if 0
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;
- } else
-#endif
- if (0 == j)
+ } else if (0 == j)
if ( ! mdoc_elem_alloc(m, line, la, tok, arg))
return(0);
@@ -1422,7 +1398,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/usr.bin/mandoc/mdoc_strings.c b/usr.bin/mandoc/mdoc_strings.c
index 193e865bfa4..a491988b547 100644
--- a/usr.bin/mandoc/mdoc_strings.c
+++ b/usr.bin/mandoc/mdoc_strings.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_strings.c,v 1.15 2010/05/14 14:47:44 schwarze Exp $ */
+/* $Id: mdoc_strings.c,v 1.16 2010/05/15 12:30:59 schwarze Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -53,17 +53,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(','):
@@ -79,16 +79,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)
{
@@ -102,7 +102,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);
}