summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2010-04-25 16:32:19 +0000
committerschwarze <schwarze@openbsd.org>2010-04-25 16:32:19 +0000
commita2047730238eba36892eb3ef092f982e4d17cf3c (patch)
tree23ced65c28f9c790cd09f752c6b486ad6c43dcf9
parentdirhash cna cope with real locks (and has before), enable mutexes here. (diff)
downloadwireguard-openbsd-a2047730238eba36892eb3ef092f982e4d17cf3c.tar.xz
wireguard-openbsd-a2047730238eba36892eb3ef092f982e4d17cf3c.zip
Implement roff conditional instructions .if .ie .el, in man(7) only for now;
fixing OpenBSD::PackageName(3p) and friends for espie@.
-rw-r--r--usr.bin/mandoc/libman.h4
-rw-r--r--usr.bin/mandoc/man.c27
-rw-r--r--usr.bin/mandoc/man.h6
-rw-r--r--usr.bin/mandoc/man_action.c5
-rw-r--r--usr.bin/mandoc/man_hash.c4
-rw-r--r--usr.bin/mandoc/man_html.c5
-rw-r--r--usr.bin/mandoc/man_macro.c94
-rw-r--r--usr.bin/mandoc/man_term.c5
-rw-r--r--usr.bin/mandoc/man_validate.c5
9 files changed, 141 insertions, 14 deletions
diff --git a/usr.bin/mandoc/libman.h b/usr.bin/mandoc/libman.h
index bf5204dd9cb..c8c457f7955 100644
--- a/usr.bin/mandoc/libman.h
+++ b/usr.bin/mandoc/libman.h
@@ -1,4 +1,4 @@
-/* $Id: libman.h,v 1.15 2010/04/02 11:37:07 schwarze Exp $ */
+/* $Id: libman.h,v 1.16 2010/04/25 16:32:19 schwarze Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -36,6 +36,7 @@ struct man {
#define MAN_ILINE (1 << 3) /* Ignored in next-line scope. */
#define MAN_LITERAL (1 << 4) /* Literal input. */
#define MAN_BPLINE (1 << 5)
+#define MAN_EL_USE (1 << 6) /* Following .el will be used. */
enum man_next next;
enum man_next svnext;
struct man_node *last;
@@ -118,6 +119,7 @@ int man_action_post(struct man *);
int man_action_pre(struct man *, struct man_node *);
int man_unscope(struct man *,
const struct man_node *, enum merr);
+int man_brace_close(struct man *, int, int);
__END_DECLS
diff --git a/usr.bin/mandoc/man.c b/usr.bin/mandoc/man.c
index 30426f19cbf..24a4c27cfe8 100644
--- a/usr.bin/mandoc/man.c
+++ b/usr.bin/mandoc/man.c
@@ -1,4 +1,4 @@
-/* $Id: man.c,v 1.24 2010/04/02 11:37:07 schwarze Exp $ */
+/* $Id: man.c,v 1.25 2010/04/25 16:32:19 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -62,7 +62,7 @@ const char *const __man_macronames[MAN_MAX] = {
"RS", "DT", "UC", "PD",
"Sp", "Vb", "Ve", "de",
"dei", "am", "ami", "ig",
- ".",
+ ".", "if", "ie", "el",
};
const char * const *man_macronames = __man_macronames;
@@ -152,10 +152,27 @@ man_endparse(struct man *m)
int
man_parseln(struct man *m, int ln, char *buf)
{
+ char *p;
+ size_t len;
+ int brace_close = 0;
+
+ if ((len = strlen(buf)) > 1) {
+ p = buf + (len - 2);
+ if (p[0] == '\\' && p[1] == '}') {
+ brace_close = 1;
+ *p = '\0';
+ }
+ }
+
+ if ('.' == *buf || '\'' == *buf) {
+ if ( ! man_pmacro(m, ln, buf))
+ return(0);
+ } else {
+ if ( ! man_ptext(m, ln, buf))
+ return(0);
+ }
- return('.' == *buf || '\'' == *buf ?
- man_pmacro(m, ln, buf) :
- man_ptext(m, ln, buf));
+ return(brace_close ? man_brace_close(m, ln, len-2) : 1);
}
diff --git a/usr.bin/mandoc/man.h b/usr.bin/mandoc/man.h
index 5fb1befdbcb..5c4372e03e5 100644
--- a/usr.bin/mandoc/man.h
+++ b/usr.bin/mandoc/man.h
@@ -1,4 +1,4 @@
-/* $Id: man.h,v 1.14 2010/03/26 01:22:05 schwarze Exp $ */
+/* $Id: man.h,v 1.15 2010/04/25 16:32:19 schwarze Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -61,6 +61,9 @@ enum mant {
MAN_ami,
MAN_ig,
MAN_dot,
+ MAN_if,
+ MAN_ie,
+ MAN_el,
MAN_MAX,
};
@@ -93,6 +96,7 @@ struct man_node {
int flags;
#define MAN_VALID (1 << 0)
#define MAN_ACTED (1 << 1)
+#define MAN_USE (1 << 2)
enum man_type type;
char *string;
struct man_node *head;
diff --git a/usr.bin/mandoc/man_action.c b/usr.bin/mandoc/man_action.c
index b9850dcbbf7..234c22f05f7 100644
--- a/usr.bin/mandoc/man_action.c
+++ b/usr.bin/mandoc/man_action.c
@@ -1,4 +1,4 @@
-/* $Id: man_action.c,v 1.14 2010/03/26 01:22:05 schwarze Exp $ */
+/* $Id: man_action.c,v 1.15 2010/04/25 16:32:19 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -73,6 +73,9 @@ const struct actions man_actions[MAN_MAX] = {
{ post_de }, /* ami */
{ post_de }, /* ig */
{ NULL }, /* . */
+ { NULL }, /* if */
+ { NULL }, /* ie */
+ { NULL }, /* el */
};
diff --git a/usr.bin/mandoc/man_hash.c b/usr.bin/mandoc/man_hash.c
index 4d0a6a05d9a..81610efe8c9 100644
--- a/usr.bin/mandoc/man_hash.c
+++ b/usr.bin/mandoc/man_hash.c
@@ -1,4 +1,4 @@
-/* $Id: man_hash.c,v 1.8 2010/03/26 01:22:05 schwarze Exp $ */
+/* $Id: man_hash.c,v 1.9 2010/04/25 16:32:19 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -24,7 +24,7 @@
#include "libman.h"
-#define HASH_DEPTH 6
+#define HASH_DEPTH 8
#define HASH_ROW(x) do { \
if ('.' == (x)) \
diff --git a/usr.bin/mandoc/man_html.c b/usr.bin/mandoc/man_html.c
index 339bbf967e4..b17d6be2833 100644
--- a/usr.bin/mandoc/man_html.c
+++ b/usr.bin/mandoc/man_html.c
@@ -1,4 +1,4 @@
-/* $Id: man_html.c,v 1.8 2010/03/26 01:22:05 schwarze Exp $ */
+/* $Id: man_html.c,v 1.9 2010/04/25 16:32:19 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -108,6 +108,9 @@ static const struct htmlman mans[MAN_MAX] = {
{ man_ign_pre, NULL }, /* ami */
{ man_ign_pre, NULL }, /* ig */
{ NULL, NULL }, /* . */
+ { NULL, NULL }, /* if */
+ { NULL, NULL }, /* ie */
+ { NULL, NULL }, /* el */
};
diff --git a/usr.bin/mandoc/man_macro.c b/usr.bin/mandoc/man_macro.c
index 5b4c8eaa441..8a57bd9899c 100644
--- a/usr.bin/mandoc/man_macro.c
+++ b/usr.bin/mandoc/man_macro.c
@@ -1,4 +1,4 @@
-/* $Id: man_macro.c,v 1.14 2010/04/02 11:37:07 schwarze Exp $ */
+/* $Id: man_macro.c,v 1.15 2010/04/25 16:32:19 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -31,6 +31,7 @@ static int blk_close(MACRO_PROT_ARGS);
static int blk_dotted(MACRO_PROT_ARGS);
static int blk_exp(MACRO_PROT_ARGS);
static int blk_imp(MACRO_PROT_ARGS);
+static int blk_cond(MACRO_PROT_ARGS);
static int in_line_eoln(MACRO_PROT_ARGS);
static int rew_scope(enum man_type,
@@ -84,6 +85,9 @@ const struct man_macro __man_macros[MAN_MAX] = {
{ blk_exp, MAN_EXPLICIT | MAN_NOCLOSE}, /* ami */
{ blk_exp, MAN_EXPLICIT | MAN_NOCLOSE}, /* ig */
{ blk_dotted, 0 }, /* . */
+ { blk_cond, 0 }, /* if */
+ { blk_cond, 0 }, /* ie */
+ { blk_cond, 0 }, /* el */
};
const struct man_macro * const man_macros = __man_macros;
@@ -277,6 +281,50 @@ rew_scope(enum man_type type, struct man *m, enum mant tok)
/*
+ * Closure for brace blocks (if, ie, el).
+ */
+int
+man_brace_close(struct man *m, int line, int ppos)
+{
+ struct man_node *nif;
+
+ nif = m->last->parent;
+ while (nif &&
+ MAN_if != nif->tok &&
+ MAN_ie != nif->tok &&
+ MAN_el != nif->tok)
+ nif = nif->parent;
+
+ if (NULL == nif)
+ return(man_pwarn(m, line, ppos, WNOSCOPE));
+
+ if (MAN_ie != nif->tok || MAN_USE & nif->flags)
+ m->flags &= ~MAN_EL_USE;
+ else
+ m->flags |= MAN_EL_USE;
+
+ if (MAN_USE & nif->flags) {
+ if (nif->prev) {
+ nif->prev->next = nif->child;
+ nif->child->prev = nif->prev;
+ nif->prev = NULL;
+ } else {
+ nif->parent->child = nif->child;
+ }
+ nif->parent->nchild += nif->nchild - 1;
+ while (nif->child) {
+ nif->child->parent = nif->parent;
+ nif->child = nif->child->next;
+ }
+ nif->nchild = 0;
+ nif->parent = NULL;
+ }
+ man_node_delete(m, nif);
+ return(1);
+}
+
+
+/*
* Closure for dotted macros (de, dei, am, ami, ign). This must handle
* any of these as the parent node, so it needs special handling.
* Beyond this, it's the same as blk_close().
@@ -479,6 +527,50 @@ blk_imp(MACRO_PROT_ARGS)
}
+/*
+ * Parse a conditional roff instruction.
+ */
+int
+blk_cond(MACRO_PROT_ARGS)
+{
+ char *p = buf + *pos;
+ int use;
+
+ if (MAN_el == tok)
+ use = m->flags & MAN_EL_USE;
+ else {
+ use = 'n' == *p++;
+ /* XXX skip the rest of the condition for now */
+ while (*p && !isblank(*p))
+ p++;
+ }
+ m->flags &= ~MAN_EL_USE;
+
+ /* advance to the code controlled by the condition */
+ while (*p && isblank(*p))
+ p++;
+ if ('\0' == *p)
+ return(1);
+
+ /* single-line body */
+ if (strncmp("\\{", p, 2)) {
+ if (use && ! man_parseln(m, line, p))
+ return(0);
+ if (MAN_ie == tok && !use)
+ m->flags |= MAN_EL_USE;
+ return(1);
+ }
+
+ /* multi-line body */
+ if ( ! man_block_alloc(m, line, ppos, tok))
+ return(0);
+ if (use)
+ m->last->flags |= MAN_USE;
+ p += 2;
+ return(*p ? man_parseln(m, line, p) : 1);
+}
+
+
int
in_line_eoln(MACRO_PROT_ARGS)
{
diff --git a/usr.bin/mandoc/man_term.c b/usr.bin/mandoc/man_term.c
index 44dc484f2bb..af977b4df70 100644
--- a/usr.bin/mandoc/man_term.c
+++ b/usr.bin/mandoc/man_term.c
@@ -1,4 +1,4 @@
-/* $Id: man_term.c,v 1.27 2010/03/26 01:22:05 schwarze Exp $ */
+/* $Id: man_term.c,v 1.28 2010/04/25 16:32:19 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -144,6 +144,9 @@ static const struct termact termacts[MAN_MAX] = {
{ pre_ign, NULL, MAN_NOTEXT }, /* ami */
{ pre_ign, NULL, MAN_NOTEXT }, /* ig */
{ NULL, NULL, 0 }, /* . */
+ { NULL, NULL, 0 }, /* if */
+ { NULL, NULL, 0 }, /* ie */
+ { NULL, NULL, 0 }, /* el */
};
diff --git a/usr.bin/mandoc/man_validate.c b/usr.bin/mandoc/man_validate.c
index 954849f650c..66b5fc5248f 100644
--- a/usr.bin/mandoc/man_validate.c
+++ b/usr.bin/mandoc/man_validate.c
@@ -1,4 +1,4 @@
-/* $Id: man_validate.c,v 1.18 2010/04/07 23:15:05 schwarze Exp $ */
+/* $Id: man_validate.c,v 1.19 2010/04/25 16:32:19 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -99,6 +99,9 @@ static const struct man_valid man_valids[MAN_MAX] = {
{ pres_roff, NULL }, /* ami */
{ pres_roff, NULL }, /* ig */
{ NULL, NULL }, /* . */
+ { NULL, NULL }, /* if */
+ { NULL, NULL }, /* ie */
+ { NULL, NULL }, /* el */
};