aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--TODO11
-rw-r--r--html.c44
-rw-r--r--libmdoc.h11
-rw-r--r--mandoc.c58
-rw-r--r--mandoc.h20
-rw-r--r--mdoc_argv.c6
-rw-r--r--mdoc_macro.c16
-rw-r--r--mdoc_strings.c46
-rw-r--r--term.c44
9 files changed, 97 insertions, 159 deletions
diff --git a/TODO b/TODO
index 0bc7d535..47e2bdf4 100644
--- a/TODO
+++ b/TODO
@@ -1,6 +1,6 @@
************************************************************************
* Official mandoc TODO.
-* $Id: TODO,v 1.91 2011/02/27 14:17:28 schwarze Exp $
+* $Id: TODO,v 1.92 2011/03/17 09:16:38 kristaps Exp $
************************************************************************
************************************************************************
@@ -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 c75b5b15..8e333ecb 100644
--- a/html.c
+++ b/html.c
@@ -1,4 +1,4 @@
-/* $Id: html.c,v 1.128 2011/03/17 08:49:34 kristaps Exp $ */
+/* $Id: html.c,v 1.129 2011/03/17 09:16:38 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -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 f1089c82..192aff69 100644
--- a/libmdoc.h
+++ b/libmdoc.h
@@ -1,4 +1,4 @@
-/* $Id: libmdoc.h,v 1.64 2011/03/17 01:23:28 kristaps Exp $ */
+/* $Id: libmdoc.h,v 1.65 2011/03/17 09:16:38 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -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 6f4f656e..67dc1da8 100644
--- a/mandoc.c
+++ b/mandoc.c
@@ -1,4 +1,4 @@
-/* $Id: mandoc.c,v 1.39 2011/03/15 16:23:51 kristaps Exp $ */
+/* $Id: mandoc.c,v 1.40 2011/03/17 09:16:38 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -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 ad0345db..447dbd55 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -1,4 +1,4 @@
-/* $Id: mandoc.h,v 1.59 2011/03/17 08:49:34 kristaps Exp $ */
+/* $Id: mandoc.h,v 1.60 2011/03/17 09:16:38 kristaps Exp $ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -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 dc28916c..42266dbb 100644
--- a/mdoc_argv.c
+++ b/mdoc_argv.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_argv.c,v 1.65 2011/03/17 01:23:28 kristaps Exp $ */
+/* $Id: mdoc_argv.c,v 1.66 2011/03/17 09:16:38 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -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 925f4a19..740c1596 100644
--- a/mdoc_macro.c
+++ b/mdoc_macro.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_macro.c,v 1.101 2011/01/25 15:17:18 kristaps Exp $ */
+/* $Id: mdoc_macro.c,v 1.102 2011/03/17 09:16:38 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -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 83e58a98..dae31f2e 100644
--- a/mdoc_strings.c
+++ b/mdoc_strings.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_strings.c,v 1.25 2011/03/17 01:23:29 kristaps Exp $ */
+/* $Id: mdoc_strings.c,v 1.26 2011/03/17 09:16:38 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -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 bdf73bf2..3d1f4edd 100644
--- a/term.c
+++ b/term.c
@@ -1,4 +1,4 @@
-/* $Id: term.c,v 1.179 2011/03/17 08:49:34 kristaps Exp $ */
+/* $Id: term.c,v 1.180 2011/03/17 09:16:38 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -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;
}