summaryrefslogtreecommitdiffstats
path: root/mandoc.c
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 /mandoc.c
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.
Diffstat (limited to 'mandoc.c')
-rw-r--r--mandoc.c56
1 files changed, 51 insertions, 5 deletions
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);
+}