summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-03-17 09:16:38 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-03-17 09:16:38 +0000
commite3df96e26436bd256a2aa5a33e49f9166ff6d4b6 (patch)
tree45cda180303addde16f0252611e2e4f7c28a619d
parentb115f948b8e55e6c3cef4bfa81f62c190af37a59 (diff)
downloadmandoc-e3df96e26436bd256a2aa5a33e49f9166ff6d4b6.tar.gz
Move mdoc_isdelim() into mandoc.h as mandoc_isdelim(). This allows the
removal of manual delimiter checks in html.c and term.c. Finally, add the escaped period as a closing delimiter, removing a TODO to this effect.
-rw-r--r--TODO9
-rw-r--r--html.c42
-rw-r--r--libmdoc.h9
-rw-r--r--mandoc.c56
-rw-r--r--mandoc.h18
-rw-r--r--mdoc_argv.c4
-rw-r--r--mdoc_macro.c14
-rw-r--r--mdoc_strings.c44
-rw-r--r--term.c42
9 files changed, 88 insertions, 150 deletions
diff --git a/TODO b/TODO
index a916a1ee..b2abfc0e 100644
--- a/TODO
+++ b/TODO
@@ -10,15 +10,6 @@
- .TP before .SH is still FATAL in man(7)
reported by brad@ Sat, 15 Jan 2011 15:54:54 -0500
-- The mdoc(7) parser should handle `\.' as punctuation:
- .Ql .if ${VAR} op something \.
- should produce
- `.if ${VAR} op something'.
- not
- `.if ${VAR} op something .'
- as seen in make(1).
- To escape the dot, one would use `\&.'.
-
- the roff parser doesn't tolerate additional characters between
a macro and the \} terminating a conditional block, e.g.
.if n \{
diff --git a/html.c b/html.c
index 5c042581..381a60ed 100644
--- a/html.c
+++ b/html.c
@@ -514,29 +514,9 @@ void
print_text(struct html *h, const char *word)
{
- if (word[0] && '\0' == word[1])
- switch (word[0]) {
- case('.'):
- /* FALLTHROUGH */
- case(','):
- /* FALLTHROUGH */
- case(';'):
- /* FALLTHROUGH */
- case(':'):
- /* FALLTHROUGH */
- case('?'):
- /* FALLTHROUGH */
- case('!'):
- /* FALLTHROUGH */
- case(')'):
- /* FALLTHROUGH */
- case(']'):
- if ( ! (HTML_IGNDELIM & h->flags))
- h->flags |= HTML_NOSPACE;
- break;
- default:
- break;
- }
+ if (DELIM_CLOSE == mandoc_isdelim(word))
+ if ( ! (HTML_IGNDELIM & h->flags))
+ h->flags |= HTML_NOSPACE;
if ( ! (HTML_NOSPACE & h->flags)) {
/* Manage keeps! */
@@ -566,20 +546,8 @@ print_text(struct html *h, const char *word)
h->flags &= ~HTML_IGNDELIM;
- /*
- * Note that we don't process the pipe: the parser sees it as
- * punctuation, but we don't in terms of typography.
- */
- if (word[0] && '\0' == word[1])
- switch (word[0]) {
- case('('):
- /* FALLTHROUGH */
- case('['):
- h->flags |= HTML_NOSPACE;
- break;
- default:
- break;
- }
+ if (DELIM_OPEN == mandoc_isdelim(word))
+ h->flags |= HTML_NOSPACE;
}
diff --git a/libmdoc.h b/libmdoc.h
index 947254fb..372f5063 100644
--- a/libmdoc.h
+++ b/libmdoc.h
@@ -81,13 +81,6 @@ 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
@@ -114,8 +107,6 @@ int mdoc_endbody_alloc(struct mdoc *m, int line, int pos,
void mdoc_node_delete(struct mdoc *, struct mdoc_node *);
void mdoc_hash_init(void);
enum mdoct mdoc_hash_find(const char *);
-#define DELIMSZ 6 /* maximum size of a delimiter string */
-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/mandoc.c b/mandoc.c
index e4c5ca6f..aa934217 100644
--- a/mandoc.c
+++ b/mandoc.c
@@ -363,7 +363,6 @@ mandoc_getarg(char **cpp, mandocmsg msg, void *data, int ln, int *pos)
return(start);
}
-
static int
a2time(time_t *t, const char *fmt, const char *p)
{
@@ -381,7 +380,6 @@ a2time(time_t *t, const char *fmt, const char *p)
return(0);
}
-
static char *
time2a(time_t t)
{
@@ -417,7 +415,6 @@ fail:
return(NULL);
}
-
char *
mandoc_normdate(char *in, mandocmsg msg, void *data, int ln, int pos)
{
@@ -439,7 +436,6 @@ mandoc_normdate(char *in, mandocmsg msg, void *data, int ln, int pos)
return(out ? out : mandoc_strdup(in));
}
-
int
mandoc_eos(const char *p, size_t sz, int enclosed)
{
@@ -483,7 +479,6 @@ mandoc_eos(const char *p, size_t sz, int enclosed)
return(found && !enclosed);
}
-
int
mandoc_hyph(const char *start, const char *c)
{
@@ -510,3 +505,54 @@ mandoc_hyph(const char *start, const char *c)
return(1);
}
+
+/*
+ * Check if a string is a punctuation delimiter. This only applies to
+ * mdoc(7) documents, but as it's used in both front-ends and back-ends,
+ * it needs to go here (instead of, say, in libmdoc.h).
+ */
+enum mdelim
+mandoc_isdelim(const char *p)
+{
+
+ if ('\0' == p[0])
+ return(DELIM_NONE);
+
+ if ('\0' == p[1])
+ switch (p[0]) {
+ case('('):
+ /* FALLTHROUGH */
+ case('['):
+ return(DELIM_OPEN);
+ case('|'):
+ return(DELIM_MIDDLE);
+ case('.'):
+ /* FALLTHROUGH */
+ case(','):
+ /* FALLTHROUGH */
+ case(';'):
+ /* FALLTHROUGH */
+ case(':'):
+ /* FALLTHROUGH */
+ case('?'):
+ /* FALLTHROUGH */
+ case('!'):
+ /* FALLTHROUGH */
+ case(')'):
+ /* FALLTHROUGH */
+ case(']'):
+ return(DELIM_CLOSE);
+ default:
+ return(DELIM_NONE);
+ }
+
+ if ('\\' != p[0])
+ return(DELIM_NONE);
+
+ if (0 == strcmp(p, "\\."))
+ return(DELIM_CLOSE);
+ if (0 == strcmp(p, "\\*(Ba"))
+ return(DELIM_MIDDLE);
+
+ return(DELIM_NONE);
+}
diff --git a/mandoc.h b/mandoc.h
index 71cca22c..dfe0c546 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -312,6 +312,22 @@ struct regset {
struct reg regs[REG__MAX];
};
+/*
+ * A punctuation delimiter, used only in mdoc(7) documents, is opening,
+ * closing, or "middle mark" punctuation. These govern spacing.
+ * Opening punctuation (e.g., the opening parenthesis) suppresses the
+ * following space; closing punctuation (e.g., the closing parenthesis)
+ * suppresses the leading space; middle punctuation (e.g., the vertical
+ * bar) can do either. The middle punctuation delimiter bends the rules
+ * depending on usage.
+ */
+enum mdelim {
+ DELIM_NONE = 0,
+ DELIM_OPEN,
+ DELIM_MIDDLE,
+ DELIM_CLOSE
+};
+
typedef int (*mandocmsg)(enum mandocerr, void *,
int, int, const char *);
@@ -320,6 +336,8 @@ __BEGIN_DECLS
void *mandoc_calloc(size_t, size_t);
void *mandoc_malloc(size_t);
void *mandoc_realloc(void *, size_t);
+#define DELIMSZ 6 /* hint: max possible size of a delimiter */
+enum mdelim mandoc_isdelim(const char *);
__END_DECLS
diff --git a/mdoc_argv.c b/mdoc_argv.c
index 12c15966..89f30fd7 100644
--- a/mdoc_argv.c
+++ b/mdoc_argv.c
@@ -587,7 +587,7 @@ args_checkpunct(const char *p)
return(0);
buf[j] = '\0';
- if (DELIM_CLOSE != mdoc_isdelim(buf))
+ if (DELIM_CLOSE != mandoc_isdelim(buf))
return(0);
while (' ' == p[i])
@@ -604,7 +604,7 @@ args_checkpunct(const char *p)
return(0);
buf[j] = '\0';
- d = mdoc_isdelim(buf);
+ d = mandoc_isdelim(buf);
if (DELIM_NONE == d || DELIM_OPEN == d)
return(0);
diff --git a/mdoc_macro.c b/mdoc_macro.c
index ac5b2c24..74e80d19 100644
--- a/mdoc_macro.c
+++ b/mdoc_macro.c
@@ -599,7 +599,7 @@ append_delims(struct mdoc *m, int line, int *pos, char *buf)
else if (ARGS_EOLN == ac)
break;
- assert(DELIM_NONE != mdoc_isdelim(p));
+ assert(DELIM_NONE != mandoc_isdelim(p));
if ( ! mdoc_word_alloc(m, line, la, p))
return(0);
@@ -870,7 +870,7 @@ in_line(MACRO_PROT_ARGS)
* the word.
*/
- d = ARGS_QWORD == ac ? DELIM_NONE : mdoc_isdelim(p);
+ d = ARGS_QWORD == ac ? DELIM_NONE : mandoc_isdelim(p);
if (DELIM_NONE != d) {
/*
@@ -1061,7 +1061,7 @@ blk_full(MACRO_PROT_ARGS)
ARGS_PHRASE != ac &&
ARGS_PPHRASE != ac &&
ARGS_QWORD != ac &&
- DELIM_OPEN == mdoc_isdelim(p)) {
+ DELIM_OPEN == mandoc_isdelim(p)) {
if ( ! mdoc_word_alloc(m, line, la, p))
return(0);
continue;
@@ -1224,7 +1224,7 @@ blk_part_imp(MACRO_PROT_ARGS)
break;
if (NULL == body && ARGS_QWORD != ac &&
- DELIM_OPEN == mdoc_isdelim(p)) {
+ DELIM_OPEN == mandoc_isdelim(p)) {
if ( ! mdoc_word_alloc(m, line, la, p))
return(0);
continue;
@@ -1355,7 +1355,7 @@ blk_part_exp(MACRO_PROT_ARGS)
/* Flush out leading punctuation. */
if (NULL == head && ARGS_QWORD != ac &&
- DELIM_OPEN == mdoc_isdelim(p)) {
+ DELIM_OPEN == mandoc_isdelim(p)) {
assert(NULL == body);
if ( ! mdoc_word_alloc(m, line, la, p))
return(0);
@@ -1502,7 +1502,7 @@ in_line_argn(MACRO_PROT_ARGS)
if ( ! (MDOC_IGNDELIM & mdoc_macros[tok].flags) &&
ARGS_QWORD != ac &&
- 0 == j && DELIM_OPEN == mdoc_isdelim(p)) {
+ 0 == j && DELIM_OPEN == mandoc_isdelim(p)) {
if ( ! mdoc_word_alloc(m, line, la, p))
return(0);
continue;
@@ -1531,7 +1531,7 @@ in_line_argn(MACRO_PROT_ARGS)
if ( ! (MDOC_IGNDELIM & mdoc_macros[tok].flags) &&
ARGS_QWORD != ac &&
! flushed &&
- DELIM_NONE != mdoc_isdelim(p)) {
+ DELIM_NONE != mandoc_isdelim(p)) {
if ( ! rew_elem(m, tok))
return(0);
flushed = 1;
diff --git a/mdoc_strings.c b/mdoc_strings.c
index cd4654b4..8f2dddbc 100644
--- a/mdoc_strings.c
+++ b/mdoc_strings.c
@@ -54,50 +54,6 @@ static const char * const secnames[SEC__MAX] = {
NULL
};
-enum mdelim
-mdoc_isdelim(const char *p)
-{
-
- if ('\0' == p[0])
- return(DELIM_NONE);
-
- if ('\0' == p[1])
- switch (p[0]) {
- case('('):
- /* FALLTHROUGH */
- case('['):
- return(DELIM_OPEN);
- case('|'):
- return(DELIM_MIDDLE);
- case('.'):
- /* FALLTHROUGH */
- case(','):
- /* FALLTHROUGH */
- case(';'):
- /* FALLTHROUGH */
- case(':'):
- /* FALLTHROUGH */
- case('?'):
- /* FALLTHROUGH */
- case('!'):
- /* FALLTHROUGH */
- case(')'):
- /* FALLTHROUGH */
- case(']'):
- return(DELIM_CLOSE);
- default:
- return(DELIM_NONE);
- }
-
- /*
- * XXX; account for groff bubu where the \*(Ba reserved string
- * is treated in exactly the same way as the vertical bar. This
- * is the only function that checks for this.
- */
- return(strcmp(p, "\\*(Ba") ? DELIM_NONE : DELIM_MIDDLE);
-}
-
-
enum mdoc_sec
mdoc_str2sec(const char *p)
{
diff --git a/term.c b/term.c
index a106224b..2e24eb3d 100644
--- a/term.c
+++ b/term.c
@@ -463,29 +463,9 @@ term_word(struct termp *p, const char *word)
sv = word;
- if (word[0] && '\0' == word[1])
- switch (word[0]) {
- case('.'):
- /* FALLTHROUGH */
- case(','):
- /* FALLTHROUGH */
- case(';'):
- /* FALLTHROUGH */
- case(':'):
- /* FALLTHROUGH */
- case('?'):
- /* FALLTHROUGH */
- case('!'):
- /* FALLTHROUGH */
- case(')'):
- /* FALLTHROUGH */
- case(']'):
- if ( ! (TERMP_IGNDELIM & p->flags))
- p->flags |= TERMP_NOSPACE;
- break;
- default:
- break;
- }
+ if (DELIM_CLOSE == mandoc_isdelim(word))
+ if ( ! (TERMP_IGNDELIM & p->flags))
+ p->flags |= TERMP_NOSPACE;
if ( ! (TERMP_NOSPACE & p->flags)) {
if ( ! (TERMP_KEEP & p->flags)) {
@@ -548,20 +528,8 @@ term_word(struct termp *p, const char *word)
p->flags |= TERMP_NOSPACE;
}
- /*
- * Note that we don't process the pipe: the parser sees it as
- * punctuation, but we don't in terms of typography.
- */
- if (sv[0] && '\0' == sv[1])
- switch (sv[0]) {
- case('('):
- /* FALLTHROUGH */
- case('['):
- p->flags |= TERMP_NOSPACE;
- break;
- default:
- break;
- }
+ if (DELIM_OPEN == mandoc_isdelim(sv))
+ p->flags |= TERMP_NOSPACE;
}