summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libman.h2
-rw-r--r--libmandoc.h2
-rw-r--r--man_validate.c6
-rw-r--r--mandoc.c82
-rw-r--r--mdoc_validate.c17
5 files changed, 65 insertions, 44 deletions
diff --git a/libman.h b/libman.h
index 19738a1b..4f4da709 100644
--- a/libman.h
+++ b/libman.h
@@ -79,7 +79,7 @@ int man_args(struct man *, int, int *, char *, char **);
int man_vmsg(struct man *, enum mandocerr,
int, int, const char *, ...);
int man_valid_post(struct man *);
-int man_valid_pre(struct man *, const struct man_node *);
+int man_valid_pre(struct man *, struct man_node *);
int man_action_post(struct man *);
int man_action_pre(struct man *, struct man_node *);
int man_unscope(struct man *,
diff --git a/libmandoc.h b/libmandoc.h
index eb18dff4..a7c2ffa1 100644
--- a/libmandoc.h
+++ b/libmandoc.h
@@ -19,7 +19,7 @@
__BEGIN_DECLS
-int mandoc_special(const char *);
+int mandoc_special(char *);
void *mandoc_calloc(size_t, size_t);
char *mandoc_strdup(const char *);
void *mandoc_malloc(size_t);
diff --git a/man_validate.c b/man_validate.c
index 362b0da9..38a36258 100644
--- a/man_validate.c
+++ b/man_validate.c
@@ -31,7 +31,7 @@
#include "libman.h"
#include "libmandoc.h"
-#define CHKARGS struct man *m, const struct man_node *n
+#define CHKARGS struct man *m, struct man_node *n
typedef int (*v_check)(CHKARGS);
@@ -101,7 +101,7 @@ static const struct man_valid man_valids[MAN_MAX] = {
int
-man_valid_pre(struct man *m, const struct man_node *n)
+man_valid_pre(struct man *m, struct man_node *n)
{
v_check *cp;
@@ -204,7 +204,7 @@ check_title(CHKARGS)
static int
check_text(CHKARGS)
{
- const char *p;
+ char *p;
int pos, c;
assert(n->string);
diff --git a/mandoc.c b/mandoc.c
index 87e6028b..632324a6 100644
--- a/mandoc.c
+++ b/mandoc.c
@@ -27,20 +27,42 @@
#include <string.h>
#include <time.h>
+#include "mandoc.h"
#include "libmandoc.h"
-static int a2time(time_t *, const char *, const char *);
+static int a2time(time_t *, const char *, const char *);
+static int spec_norm(char *, int);
+
+
+/*
+ * "Normalise" a special string by converting its ASCII_HYPH entries
+ * into actual hyphens.
+ */
+static int
+spec_norm(char *p, int sz)
+{
+ int i;
+
+ for (i = 0; i < sz; i++)
+ if (ASCII_HYPH == p[i])
+ p[i] = '-';
+
+ return(sz);
+}
int
-mandoc_special(const char *p)
+mandoc_special(char *p)
{
int terminator; /* Terminator for \s. */
int lim; /* Limit for N in \s. */
int c, i;
+ char *sv;
+ sv = p;
+
if ('\\' != *p++)
- return(0);
+ return(spec_norm(sv, 0));
switch (*p) {
case ('\''):
@@ -49,6 +71,8 @@ mandoc_special(const char *p)
/* FALLTHROUGH */
case ('q'):
/* FALLTHROUGH */
+ case (ASCII_HYPH):
+ /* FALLTHROUGH */
case ('-'):
/* FALLTHROUGH */
case ('~'):
@@ -72,12 +96,12 @@ mandoc_special(const char *p)
case (':'):
/* FALLTHROUGH */
case ('c'):
- return(2);
+ /* FALLTHROUGH */
case ('e'):
- return(2);
+ return(spec_norm(sv, 2));
case ('s'):
if ('\0' == *++p)
- return(2);
+ return(spec_norm(sv, 2));
c = 2;
terminator = 0;
@@ -107,21 +131,21 @@ mandoc_special(const char *p)
if (*p == '\'') {
if (terminator)
- return(0);
+ return(spec_norm(sv, 0));
lim = 0;
terminator = 1;
++p;
++c;
} else if (*p == '[') {
if (terminator)
- return(0);
+ return(spec_norm(sv, 0));
lim = 0;
terminator = 2;
++p;
++c;
} else if (*p == '(') {
if (terminator)
- return(0);
+ return(spec_norm(sv, 0));
lim = 2;
terminator = 3;
++p;
@@ -131,7 +155,7 @@ mandoc_special(const char *p)
/* TODO: needs to handle floating point. */
if ( ! isdigit((u_char)*p))
- return(0);
+ return(spec_norm(sv, 0));
for (i = 0; isdigit((u_char)*p); i++) {
if (lim && i >= lim)
@@ -142,52 +166,52 @@ mandoc_special(const char *p)
if (terminator && terminator < 3) {
if (1 == terminator && *p != '\'')
- return(0);
+ return(spec_norm(sv, 0));
if (2 == terminator && *p != ']')
- return(0);
+ return(spec_norm(sv, 0));
++p;
++c;
}
- return(c);
+ return(spec_norm(sv, c));
case ('f'):
/* FALLTHROUGH */
case ('F'):
/* FALLTHROUGH */
case ('*'):
- if (0 == *++p || ! isgraph((u_char)*p))
- return(0);
+ if ('\0' == *++p || isspace((u_char)*p))
+ return(spec_norm(sv, 0));
switch (*p) {
case ('('):
- if (0 == *++p || ! isgraph((u_char)*p))
- return(0);
- return(4);
+ if ('\0' == *++p || isspace((u_char)*p))
+ return(spec_norm(sv, 0));
+ return(spec_norm(sv, 4));
case ('['):
for (c = 3, p++; *p && ']' != *p; p++, c++)
- if ( ! isgraph((u_char)*p))
+ if (isspace((u_char)*p))
break;
- return(*p == ']' ? c : 0);
+ return(spec_norm(sv, *p == ']' ? c : 0));
default:
break;
}
- return(3);
+ return(spec_norm(sv, 3));
case ('('):
- if (0 == *++p || ! isgraph((u_char)*p))
- return(0);
- if (0 == *++p || ! isgraph((u_char)*p))
- return(0);
- return(4);
+ if ('\0' == *++p || isspace((u_char)*p))
+ return(spec_norm(sv, 0));
+ if ('\0' == *++p || isspace((u_char)*p))
+ return(spec_norm(sv, 0));
+ return(spec_norm(sv, 4));
case ('['):
break;
default:
- return(0);
+ return(spec_norm(sv, 0));
}
for (c = 3, p++; *p && ']' != *p; p++, c++)
- if ( ! isgraph((u_char)*p))
+ if (isspace((u_char)*p))
break;
- return(*p == ']' ? c : 0);
+ return(spec_norm(sv, *p == ']' ? c : 0));
}
diff --git a/mdoc_validate.c b/mdoc_validate.c
index 9f905b69..388cb6a7 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -47,12 +47,10 @@ struct valids {
static int check_parent(PRE_ARGS, enum mdoct, enum mdoc_type);
static int check_stdarg(PRE_ARGS);
-static int check_text(struct mdoc *, int, int, const char *);
+static int check_text(struct mdoc *, int, int, char *);
static int check_argv(struct mdoc *,
- const struct mdoc_node *,
- const struct mdoc_argv *);
-static int check_args(struct mdoc *,
- const struct mdoc_node *);
+ struct mdoc_node *, struct mdoc_argv *);
+static int check_args(struct mdoc *, struct mdoc_node *);
static int err_child_lt(struct mdoc *, const char *, int);
static int warn_child_lt(struct mdoc *, const char *, int);
static int err_child_gt(struct mdoc *, const char *, int);
@@ -277,7 +275,7 @@ mdoc_valid_pre(struct mdoc *mdoc, struct mdoc_node *n)
{
v_pre *p;
int line, pos;
- const char *tp;
+ char *tp;
if (MDOC_TEXT == n->type) {
tp = n->string;
@@ -419,7 +417,7 @@ check_stdarg(PRE_ARGS)
static int
-check_args(struct mdoc *m, const struct mdoc_node *n)
+check_args(struct mdoc *m, struct mdoc_node *n)
{
int i;
@@ -436,8 +434,7 @@ check_args(struct mdoc *m, const struct mdoc_node *n)
static int
-check_argv(struct mdoc *m, const struct mdoc_node *n,
- const struct mdoc_argv *v)
+check_argv(struct mdoc *m, struct mdoc_node *n, struct mdoc_argv *v)
{
int i;
@@ -457,7 +454,7 @@ check_argv(struct mdoc *m, const struct mdoc_node *n,
static int
-check_text(struct mdoc *mdoc, int line, int pos, const char *p)
+check_text(struct mdoc *mdoc, int line, int pos, char *p)
{
int c;