summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2018-04-11 17:10:36 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2018-04-11 17:10:36 +0000
commit1b95341c3f6bb721edfdd84de159b61651136659 (patch)
treee6588e7ff9381a9e4f1ed1977679618a6ef4a548 /usr.bin
parent0fd0c4122540b8650b6a674c1deb83dea65d2d53 (diff)
preserve comments before .Dd when converting mdoc(7) to man(7)
with mandoc -Tman; suggested by Thomas Klausner <wiz at NetBSD>
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mandoc/man_html.c4
-rw-r--r--usr.bin/mandoc/man_term.c13
-rw-r--r--usr.bin/mandoc/man_validate.c8
-rw-r--r--usr.bin/mandoc/mdoc_html.c4
-rw-r--r--usr.bin/mandoc/mdoc_man.c14
-rw-r--r--usr.bin/mandoc/mdoc_markdown.c4
-rw-r--r--usr.bin/mandoc/mdoc_term.c17
-rw-r--r--usr.bin/mandoc/mdoc_validate.c9
-rw-r--r--usr.bin/mandoc/roff.c37
-rw-r--r--usr.bin/mandoc/roff.h3
-rw-r--r--usr.bin/mandoc/tree.c12
11 files changed, 89 insertions, 36 deletions
diff --git a/usr.bin/mandoc/man_html.c b/usr.bin/mandoc/man_html.c
index 86f30b9901c..0897b0889c2 100644
--- a/usr.bin/mandoc/man_html.c
+++ b/usr.bin/mandoc/man_html.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: man_html.c,v 1.98 2017/06/25 07:23:53 bentley Exp $ */
+/* $OpenBSD: man_html.c,v 1.99 2018/04/11 17:10:35 schwarze Exp $ */
/*
* Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -260,6 +260,8 @@ print_man_node(MAN_ARGS)
break;
print_paragraph(h);
return;
+ case ROFFT_COMMENT:
+ return;
default:
break;
}
diff --git a/usr.bin/mandoc/man_term.c b/usr.bin/mandoc/man_term.c
index 6fd2368e13c..839230e10d5 100644
--- a/usr.bin/mandoc/man_term.c
+++ b/usr.bin/mandoc/man_term.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: man_term.c,v 1.162 2017/07/31 15:18:59 schwarze Exp $ */
+/* $OpenBSD: man_term.c,v 1.163 2018/04/11 17:10:35 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010-2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010-2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -673,7 +673,8 @@ pre_SS(DECL_ARGS)
n = n->prev;
} while (n != NULL && n->tok >= MAN_TH &&
termacts[n->tok].flags & MAN_NOTEXT);
- if (n == NULL || (n->tok == MAN_SS && n->body->child == NULL))
+ if (n == NULL || n->type == ROFFT_COMMENT ||
+ (n->tok == MAN_SS && n->body->child == NULL))
break;
for (i = 0; i < mt->pardist; i++)
@@ -735,7 +736,8 @@ pre_SH(DECL_ARGS)
n = n->prev;
} while (n != NULL && n->tok >= MAN_TH &&
termacts[n->tok].flags & MAN_NOTEXT);
- if (n == NULL || (n->tok == MAN_SH && n->body->child == NULL))
+ if (n == NULL || n->type == ROFFT_COMMENT ||
+ (n->tok == MAN_SH && n->body->child == NULL))
break;
for (i = 0; i < mt->pardist; i++)
@@ -883,7 +885,8 @@ print_man_node(DECL_ARGS)
term_word(p, n->string);
goto out;
-
+ case ROFFT_COMMENT:
+ return;
case ROFFT_EQN:
if ( ! (n->flags & NODE_LINE))
p->flags |= TERMP_NOSPACE;
diff --git a/usr.bin/mandoc/man_validate.c b/usr.bin/mandoc/man_validate.c
index f73e1c837c2..4c303d8bbf9 100644
--- a/usr.bin/mandoc/man_validate.c
+++ b/usr.bin/mandoc/man_validate.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: man_validate.c,v 1.104 2017/07/26 10:33:02 schwarze Exp $ */
+/* $OpenBSD: man_validate.c,v 1.105 2018/04/11 17:10:35 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010, 2012-2017 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010, 2012-2018 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -118,6 +118,7 @@ man_node_validate(struct roff_man *man)
case ROFFT_ROOT:
check_root(man, n);
break;
+ case ROFFT_COMMENT:
case ROFFT_EQN:
case ROFFT_TBL:
break;
@@ -147,10 +148,9 @@ man_node_validate(struct roff_man *man)
static void
check_root(CHKARGS)
{
-
assert((man->flags & (MAN_BLINE | MAN_ELINE)) == 0);
- if (NULL == man->first->child)
+ if (n->last == NULL || n->last->type == ROFFT_COMMENT)
mandoc_msg(MANDOCERR_DOC_EMPTY, man->parse,
n->line, n->pos, NULL);
else
diff --git a/usr.bin/mandoc/mdoc_html.c b/usr.bin/mandoc/mdoc_html.c
index 337b918bebc..cf71eb198f8 100644
--- a/usr.bin/mandoc/mdoc_html.c
+++ b/usr.bin/mandoc/mdoc_html.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdoc_html.c,v 1.169 2017/07/15 17:57:46 schwarze Exp $ */
+/* $OpenBSD: mdoc_html.c,v 1.170 2018/04/11 17:10:35 schwarze Exp $ */
/*
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2015, 2016, 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -342,7 +342,7 @@ print_mdoc_node(MDOC_ARGS)
int child;
struct tag *t;
- if (n->flags & NODE_NOPRT)
+ if (n->type == ROFFT_COMMENT || n->flags & NODE_NOPRT)
return;
child = 1;
diff --git a/usr.bin/mandoc/mdoc_man.c b/usr.bin/mandoc/mdoc_man.c
index 4a9b2357cc3..5573dd531d8 100644
--- a/usr.bin/mandoc/mdoc_man.c
+++ b/usr.bin/mandoc/mdoc_man.c
@@ -1,6 +1,6 @@
-/* $OpenBSD: mdoc_man.c,v 1.123 2018/04/05 22:04:37 schwarze Exp $ */
+/* $OpenBSD: mdoc_man.c,v 1.124 2018/04/11 17:10:35 schwarze Exp $ */
/*
- * Copyright (c) 2011-2017 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2011-2018 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -608,6 +608,14 @@ man_mdoc(void *arg, const struct roff_man *mdoc)
{
struct roff_node *n;
+ printf(".\\\" Automatically generated from an mdoc input file."
+ " Do not edit.\n");
+ for (n = mdoc->first->child; n != NULL; n = n->next) {
+ if (n->type != ROFFT_COMMENT)
+ break;
+ printf(".\\\"%s\n", n->string);
+ }
+
printf(".TH \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"\n",
mdoc->meta.title,
(mdoc->meta.msec == NULL ? "" : mdoc->meta.msec),
@@ -622,7 +630,7 @@ man_mdoc(void *arg, const struct roff_man *mdoc)
fontqueue.head = fontqueue.tail = mandoc_malloc(8);
*fontqueue.tail = 'R';
}
- for (n = mdoc->first->child; n != NULL; n = n->next)
+ for (; n != NULL; n = n->next)
print_node(&mdoc->meta, n);
putchar('\n');
}
diff --git a/usr.bin/mandoc/mdoc_markdown.c b/usr.bin/mandoc/mdoc_markdown.c
index 1a8a70ada5d..104bb025a96 100644
--- a/usr.bin/mandoc/mdoc_markdown.c
+++ b/usr.bin/mandoc/mdoc_markdown.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdoc_markdown.c,v 1.23 2017/06/14 01:31:19 schwarze Exp $ */
+/* $OpenBSD: mdoc_markdown.c,v 1.24 2018/04/11 17:10:35 schwarze Exp $ */
/*
* Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
*
@@ -294,7 +294,7 @@ md_node(struct roff_node *n)
const struct md_act *act;
int cond, process_children;
- if (n->flags & NODE_NOPRT)
+ if (n->type == ROFFT_COMMENT || n->flags & NODE_NOPRT)
return;
if (outflags & MD_nonl)
diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c
index 846b5fdf7c2..c226f4b5eb2 100644
--- a/usr.bin/mandoc/mdoc_term.c
+++ b/usr.bin/mandoc/mdoc_term.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: mdoc_term.c,v 1.265 2018/04/05 09:16:45 schwarze Exp $ */
+/* $OpenBSD: mdoc_term.c,v 1.266 2018/04/11 17:10:35 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010, 2012-2017 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010, 2012-2018 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2013 Franco Fichtner <franco@lastsummer.de>
*
* Permission to use, copy, modify, and distribute this software for any
@@ -281,7 +281,9 @@ terminal_mdoc(void *arg, const struct roff_man *mdoc)
p->defindent = 5;
term_begin(p, print_mdoc_head, print_mdoc_foot,
&mdoc->meta);
- while (n != NULL && n->flags & NODE_NOPRT)
+ while (n != NULL &&
+ (n->type == ROFFT_COMMENT ||
+ n->flags & NODE_NOPRT))
n = n->next;
if (n != NULL) {
if (n->tok != MDOC_Sh)
@@ -310,7 +312,7 @@ print_mdoc_node(DECL_ARGS)
struct termpair npair;
size_t offset, rmargin;
- if (n->flags & NODE_NOPRT)
+ if (n->type == ROFFT_COMMENT || n->flags & NODE_NOPRT)
return;
chld = 1;
@@ -565,7 +567,9 @@ print_bvspace(struct termp *p,
/* Do not vspace directly after Ss/Sh. */
nn = n;
- while (nn->prev != NULL && nn->prev->flags & NODE_NOPRT)
+ while (nn->prev != NULL &&
+ (nn->prev->type == ROFFT_COMMENT ||
+ nn->prev->flags & NODE_NOPRT))
nn = nn->prev;
while (nn->prev == NULL) {
do {
@@ -1548,7 +1552,8 @@ termp_ss_pre(DECL_ARGS)
case ROFFT_BLOCK:
term_newln(p);
for (nn = n->prev; nn != NULL; nn = nn->prev)
- if ((nn->flags & NODE_NOPRT) == 0)
+ if (nn->type != ROFFT_COMMENT &&
+ (nn->flags & NODE_NOPRT) == 0)
break;
if (nn != NULL)
term_vspace(p);
diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c
index 77730dd345c..4225aa7ebe5 100644
--- a/usr.bin/mandoc/mdoc_validate.c
+++ b/usr.bin/mandoc/mdoc_validate.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdoc_validate.c,v 1.272 2018/04/05 09:16:45 schwarze Exp $ */
+/* $OpenBSD: mdoc_validate.c,v 1.273 2018/04/11 17:10:35 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -318,6 +318,7 @@ mdoc_node_validate(struct roff_man *mdoc)
(np->tok == MDOC_Sh || np->tok == MDOC_Ss)))
check_toptext(mdoc, n->line, n->pos, n->string);
break;
+ case ROFFT_COMMENT:
case ROFFT_EQN:
case ROFFT_TBL:
break;
@@ -1973,8 +1974,10 @@ post_root(POST_ARGS)
/* Check that we begin with a proper `Sh'. */
n = mdoc->first->child;
- while (n != NULL && n->tok >= MDOC_Dd &&
- mdoc_macros[n->tok].flags & MDOC_PROLOGUE)
+ while (n != NULL &&
+ (n->type == ROFFT_COMMENT ||
+ (n->tok >= MDOC_Dd &&
+ mdoc_macros[n->tok].flags & MDOC_PROLOGUE)))
n = n->next;
if (n == NULL)
diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c
index 47507154239..e0b5ed67f46 100644
--- a/usr.bin/mandoc/roff.c
+++ b/usr.bin/mandoc/roff.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: roff.c,v 1.199 2018/04/10 00:52:21 schwarze Exp $ */
+/* $OpenBSD: roff.c,v 1.200 2018/04/11 17:10:35 schwarze Exp $ */
/*
* Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -760,7 +760,7 @@ roff_alloc(struct mparse *parse, int options)
r = mandoc_calloc(1, sizeof(struct roff));
r->parse = parse;
- r->reqtab = roffhash_alloc(0, ROFF_USERDEF);
+ r->reqtab = roffhash_alloc(0, ROFF_RENAMED);
r->options = options;
r->format = options & (MPARSE_MDOC | MPARSE_MAN);
r->rstackpos = -1;
@@ -1120,8 +1120,10 @@ static enum rofferr
roff_res(struct roff *r, struct buf *buf, int ln, int pos)
{
char ubuf[24]; /* buffer to print the number */
+ struct roff_node *n; /* used for header comments */
const char *start; /* start of the string to process */
char *stesc; /* start of an escape sequence ('\\') */
+ char *ep; /* end of comment string */
const char *stnam; /* start of the name, after "[(*" */
const char *cp; /* end of the name, e.g. before ']' */
const char *res; /* the string to be substituted */
@@ -1171,14 +1173,35 @@ roff_res(struct roff *r, struct buf *buf, int ln, int pos)
/* Handle trailing whitespace. */
- cp = strchr(stesc--, '\0') - 1;
- if (*cp == '\n') {
+ ep = strchr(stesc--, '\0') - 1;
+ if (*ep == '\n') {
done = 1;
- cp--;
+ ep--;
}
- if (*cp == ' ' || *cp == '\t')
+ if (*ep == ' ' || *ep == '\t')
mandoc_msg(MANDOCERR_SPACE_EOL, r->parse,
- ln, cp - buf->buf, NULL);
+ ln, ep - buf->buf, NULL);
+
+ /*
+ * Save comments preceding the title macro
+ * in the syntax tree.
+ */
+
+ if (r->format == 0) {
+ while (*ep == ' ' || *ep == '\t')
+ ep--;
+ ep[1] = '\0';
+ n = roff_node_alloc(r->man,
+ ln, stesc + 1 - buf->buf,
+ ROFFT_COMMENT, TOKEN_NONE);
+ n->string = mandoc_strdup(stesc + 2);
+ roff_node_append(r->man, n);
+ n->flags |= NODE_VALID | NODE_ENDED;
+ r->man->next = ROFF_NEXT_SIBLING;
+ }
+
+ /* Discard comments. */
+
while (stesc > start && stesc[-1] == ' ')
stesc--;
*stesc = '\0';
diff --git a/usr.bin/mandoc/roff.h b/usr.bin/mandoc/roff.h
index 2be8356de08..a13d9662bf1 100644
--- a/usr.bin/mandoc/roff.h
+++ b/usr.bin/mandoc/roff.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: roff.h,v 1.40 2017/07/08 14:51:01 schwarze Exp $ */
+/* $OpenBSD: roff.h,v 1.41 2018/04/11 17:10:35 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -61,6 +61,7 @@ enum roff_type {
ROFFT_TAIL,
ROFFT_ELEM,
ROFFT_TEXT,
+ ROFFT_COMMENT,
ROFFT_TBL,
ROFFT_EQN
};
diff --git a/usr.bin/mandoc/tree.c b/usr.bin/mandoc/tree.c
index e7c163b2817..65c23c8ff75 100644
--- a/usr.bin/mandoc/tree.c
+++ b/usr.bin/mandoc/tree.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: tree.c,v 1.44 2017/07/08 14:51:01 schwarze Exp $ */
+/* $OpenBSD: tree.c,v 1.45 2018/04/11 17:10:35 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -113,6 +113,9 @@ print_mdoc(const struct roff_node *n, int indent)
case ROFFT_TEXT:
t = "text";
break;
+ case ROFFT_COMMENT:
+ t = "comment";
+ break;
case ROFFT_TBL:
break;
case ROFFT_EQN:
@@ -124,6 +127,7 @@ print_mdoc(const struct roff_node *n, int indent)
switch (n->type) {
case ROFFT_TEXT:
+ case ROFFT_COMMENT:
p = n->string;
break;
case ROFFT_BODY:
@@ -229,6 +233,9 @@ print_man(const struct roff_node *n, int indent)
case ROFFT_TEXT:
t = "text";
break;
+ case ROFFT_COMMENT:
+ t = "comment";
+ break;
case ROFFT_BLOCK:
t = "block";
break;
@@ -249,6 +256,7 @@ print_man(const struct roff_node *n, int indent)
switch (n->type) {
case ROFFT_TEXT:
+ case ROFFT_COMMENT:
p = n->string;
break;
case ROFFT_ELEM: