summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2010-05-13 06:22:11 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2010-05-13 06:22:11 +0000
commitbbca9de4c44fc5e7d5aa68015495daccc2f69081 (patch)
treea958d78176c6f69c955bca59a0eed757293c2ef1
parentfa29183f6542c3a65f105c7296ce435beb629a12 (diff)
downloadmandoc-bbca9de4c44fc5e7d5aa68015495daccc2f69081.tar.gz
mandoc-bbca9de4c44fc5e7d5aa68015495daccc2f69081.tar.zst
mandoc-bbca9de4c44fc5e7d5aa68015495daccc2f69081.zip
Fixed bug in -Thtml -mdoc where `Lb' would line-break in LIBRARY section.
Fixed assumption that parse-point == 1 equates to beginning of line (false if whitespace separates macro and control character). Fixed line-break for non-first-macro in several SYNOPSIS macros.
-rw-r--r--libmdoc.h9
-rw-r--r--mdoc.c16
-rw-r--r--mdoc.h30
-rw-r--r--mdoc_html.c15
-rw-r--r--mdoc_macro.c35
-rw-r--r--mdoc_term.c16
6 files changed, 69 insertions, 52 deletions
diff --git a/libmdoc.h b/libmdoc.h
index 8b76c95f..0d3bad59 100644
--- a/libmdoc.h
+++ b/libmdoc.h
@@ -1,4 +1,4 @@
-/* $Id: libmdoc.h,v 1.41 2010/05/12 08:41:17 kristaps Exp $ */
+/* $Id: libmdoc.h,v 1.42 2010/05/13 06:22:11 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -28,9 +28,10 @@ struct mdoc {
void *data;
struct mdoc_cb cb;
int flags;
-#define MDOC_HALT (1 << 0) /* Error in parse. Halt. */
-#define MDOC_LITERAL (1 << 1) /* In a literal scope. */
-#define MDOC_PBODY (1 << 2) /* In the document body. */
+#define MDOC_HALT (1 << 0) /* error in parse: halt */
+#define MDOC_LITERAL (1 << 1) /* in a literal scope */
+#define MDOC_PBODY (1 << 2) /* in the document body */
+#define MDOC_NEWLINE (1 << 3) /* first macro/text in a line */
int pflags;
enum mdoc_next next;
struct mdoc_node *last;
diff --git a/mdoc.c b/mdoc.c
index 8cb8c4ed..38f97ed1 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc.c,v 1.129 2010/05/12 17:08:03 kristaps Exp $ */
+/* $Id: mdoc.c,v 1.130 2010/05/13 06:22:11 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -289,7 +289,9 @@ mdoc_parseln(struct mdoc *m, int ln, char *buf)
if (MDOC_HALT & m->flags)
return(0);
- return('.' == *buf ? mdoc_pmacro(m, ln, buf) :
+ m->flags |= MDOC_NEWLINE;
+ return('.' == *buf ?
+ mdoc_pmacro(m, ln, buf) :
mdoc_ptext(m, ln, buf));
}
@@ -453,7 +455,9 @@ node_alloc(struct mdoc *m, int line, int pos,
p->pos = pos;
p->tok = tok;
p->type = type;
-
+ if (MDOC_NEWLINE & m->flags)
+ p->flags |= MDOC_LINE;
+ m->flags &= ~MDOC_NEWLINE;
return(p);
}
@@ -726,7 +730,7 @@ int
mdoc_pmacro(struct mdoc *m, int ln, char *buf)
{
enum mdoct tok;
- int i, j;
+ int i, j, sv;
char mac[5];
/* Empty lines are ignored. */
@@ -746,6 +750,8 @@ mdoc_pmacro(struct mdoc *m, int ln, char *buf)
return(1);
}
+ sv = i;
+
/* Copy the first word into a nil-terminated buffer. */
for (j = 0; j < 4; j++, i++) {
@@ -793,7 +799,7 @@ mdoc_pmacro(struct mdoc *m, int ln, char *buf)
* Begin recursive parse sequence. Since we're at the start of
* the line, we don't need to do callable/parseable checks.
*/
- if ( ! mdoc_macro(m, tok, ln, 1, &i, buf))
+ if ( ! mdoc_macro(m, tok, ln, sv, &i, buf))
goto err;
return(1);
diff --git a/mdoc.h b/mdoc.h
index 2d2267a2..00cc5f6a 100644
--- a/mdoc.h
+++ b/mdoc.h
@@ -1,4 +1,4 @@
-/* $Id: mdoc.h,v 1.77 2010/05/12 16:01:01 kristaps Exp $ */
+/* $Id: mdoc.h,v 1.78 2010/05/13 06:22:11 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -249,21 +249,21 @@ struct mdoc_arg {
/* Node in AST. */
struct mdoc_node {
- struct mdoc_node *parent;
- struct mdoc_node *child;
- struct mdoc_node *next;
- struct mdoc_node *prev;
- int nchild;
- int line;
- int pos;
- enum mdoct tok;
+ struct mdoc_node *parent; /* parent AST node */
+ struct mdoc_node *child; /* first child AST node */
+ struct mdoc_node *next; /* sibling AST node */
+ struct mdoc_node *prev; /* prior sibling AST node */
+ int nchild; /* number children */
+ int line; /* parse line */
+ int pos; /* parse column */
+ enum mdoct tok; /* tok or MDOC__MAX if none */
int flags;
-#define MDOC_VALID (1 << 0)
-#define MDOC_ACTED (1 << 1)
-#define MDOC_EOS (1 << 2)
- enum mdoc_type type;
- enum mdoc_sec sec;
-
+#define MDOC_VALID (1 << 0) /* has been validated */
+#define MDOC_ACTED (1 << 1) /* has been acted upon */
+#define MDOC_EOS (1 << 2) /* at sentence boundary */
+#define MDOC_LINE (1 << 3) /* first macro/text on line */
+ enum mdoc_type type; /* AST node type */
+ enum mdoc_sec sec; /* current named section */
struct mdoc_arg *args; /* BLOCK/ELEM */
#ifdef UGLY
struct mdoc_node *pending; /* BLOCK */
diff --git a/mdoc_html.c b/mdoc_html.c
index 0ba4bea3..3f5d4ab6 100644
--- a/mdoc_html.c
+++ b/mdoc_html.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_html.c,v 1.61 2010/04/08 08:17:55 kristaps Exp $ */
+/* $Id: mdoc_html.c,v 1.62 2010/05/13 06:22:11 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -729,7 +729,8 @@ mdoc_nm_pre(MDOC_ARGS)
{
struct htmlpair tag;
- if (SEC_SYNOPSIS == n->sec && n->prev) {
+ if (SEC_SYNOPSIS == n->sec &&
+ n->prev && MDOC_LINE & n->flags) {
bufcat_style(h, "clear", "both");
PAIR_STYLE_INIT(&tag, h);
print_otag(h, TAG_BR, 1, &tag);
@@ -1557,7 +1558,7 @@ mdoc_fd_pre(MDOC_ARGS)
struct htmlpair tag;
struct roffsu su;
- if (SEC_SYNOPSIS == n->sec) {
+ if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags) {
if (n->next && MDOC_Fd != n->next->tok) {
SCALE_VS_INIT(&su, 1);
bufcat_su(h, "margin-bottom", &su);
@@ -1605,7 +1606,7 @@ mdoc_ft_pre(MDOC_ARGS)
{
struct htmlpair tag;
- if (SEC_SYNOPSIS == n->sec)
+ if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags)
print_otag(h, TAG_DIV, 0, NULL);
PAIR_CLASS_INIT(&tag, "ftype");
@@ -1626,7 +1627,7 @@ mdoc_fn_pre(MDOC_ARGS)
int sz, i;
struct roffsu su;
- if (SEC_SYNOPSIS == n->sec) {
+ if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags) {
SCALE_HS_INIT(&su, INDENT);
bufcat_su(h, "margin-left", &su);
su.scale = -su.scale;
@@ -1867,7 +1868,7 @@ mdoc_in_pre(MDOC_ARGS)
int i;
struct roffsu su;
- if (SEC_SYNOPSIS == n->sec) {
+ if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags) {
if (n->next && MDOC_In != n->next->tok) {
SCALE_VS_INIT(&su, 1);
bufcat_su(h, "margin-bottom", &su);
@@ -2172,7 +2173,7 @@ mdoc_lb_pre(MDOC_ARGS)
{
struct htmlpair tag;
- if (SEC_SYNOPSIS == n->sec)
+ if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags)
print_otag(h, TAG_DIV, 0, NULL);
PAIR_CLASS_INIT(&tag, "lib");
print_otag(h, TAG_SPAN, 1, &tag);
diff --git a/mdoc_macro.c b/mdoc_macro.c
index 77b5860a..9c11fc01 100644
--- a/mdoc_macro.c
+++ b/mdoc_macro.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_macro.c,v 1.59 2010/05/09 10:17:02 kristaps Exp $ */
+/* $Id: mdoc_macro.c,v 1.60 2010/05/13 06:22:11 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -653,11 +653,13 @@ append_delims(struct mdoc *mdoc, int line, int *pos, char *buf)
static int
blk_exp_close(MACRO_PROT_ARGS)
{
- int j, lastarg, maxargs, flushed;
+ int j, lastarg, maxargs, flushed, nl;
enum margserr ac;
enum mdoct ntok;
char *p;
+ nl = MDOC_NEWLINE & m->flags;
+
switch (tok) {
case (MDOC_Ec):
maxargs = 1;
@@ -723,7 +725,7 @@ blk_exp_close(MACRO_PROT_ARGS)
if ( ! flushed && ! rew_sub(MDOC_BLOCK, m, tok, line, ppos))
return(0);
- if (ppos > 1)
+ if ( ! nl)
return(1);
return(append_delims(m, line, pos, buf));
}
@@ -732,13 +734,15 @@ blk_exp_close(MACRO_PROT_ARGS)
static int
in_line(MACRO_PROT_ARGS)
{
- int la, lastpunct, cnt, d, nc;
+ int la, lastpunct, cnt, d, nc, nl;
enum margverr av;
enum mdoct ntok;
enum margserr ac;
struct mdoc_arg *arg;
char *p;
+ nl = MDOC_NEWLINE & m->flags;
+
/*
* Whether we allow ignored elements (those without content,
* usually because of reserved words) to squeak by.
@@ -815,7 +819,7 @@ in_line(MACRO_PROT_ARGS)
}
if ( ! mdoc_macro(m, ntok, line, la, pos, buf))
return(0);
- if (ppos > 1)
+ if ( ! nl)
return(1);
return(append_delims(m, line, pos, buf));
}
@@ -875,7 +879,7 @@ in_line(MACRO_PROT_ARGS)
return(0);
}
- if (ppos > 1)
+ if ( ! nl)
return(1);
return(append_delims(m, line, pos, buf));
}
@@ -1180,13 +1184,15 @@ blk_part_imp(MACRO_PROT_ARGS)
static int
blk_part_exp(MACRO_PROT_ARGS)
{
- int la;
+ int la, nl;
enum margserr ac;
struct mdoc_node *head; /* keep track of head */
struct mdoc_node *body; /* keep track of body */
char *p;
enum mdoct ntok;
+ nl = MDOC_NEWLINE & m->flags;
+
/*
* The opening of an explicit macro having zero or more leading
* punctuation nodes; a head with optional single element (the
@@ -1279,9 +1285,8 @@ blk_part_exp(MACRO_PROT_ARGS)
/* Standard appending of delimiters. */
- if (ppos > 1)
+ if ( ! nl)
return(1);
-
return(append_delims(m, line, pos, buf));
}
@@ -1289,13 +1294,15 @@ blk_part_exp(MACRO_PROT_ARGS)
static int
in_line_argn(MACRO_PROT_ARGS)
{
- int la, flushed, j, maxargs;
+ int la, flushed, j, maxargs, nl;
enum margserr ac;
enum margverr av;
struct mdoc_arg *arg;
char *p;
enum mdoct ntok;
+ nl = MDOC_NEWLINE & m->flags;
+
/*
* A line macro that has a fixed number of arguments (maxargs).
* Only open the scope once the first non-leading-punctuation is
@@ -1415,8 +1422,7 @@ in_line_argn(MACRO_PROT_ARGS)
if ( ! flushed && ! rew_elem(m, tok))
return(0);
-
- if (ppos > 1)
+ if ( ! nl)
return(1);
return(append_delims(m, line, pos, buf));
}
@@ -1492,13 +1498,16 @@ in_line_eoln(MACRO_PROT_ARGS)
static int
ctx_synopsis(MACRO_PROT_ARGS)
{
+ int nl;
+
+ nl = MDOC_NEWLINE & m->flags;
/* If we're not in the SYNOPSIS, go straight to in-line. */
if (SEC_SYNOPSIS != m->lastsec)
return(in_line(m, tok, line, ppos, pos, buf));
/* If we're a nested call, same place. */
- if (ppos > 1)
+ if ( ! nl)
return(in_line(m, tok, line, ppos, pos, buf));
/*
diff --git a/mdoc_term.c b/mdoc_term.c
index 490c3e47..728bdc28 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_term.c,v 1.121 2010/05/12 16:01:01 kristaps Exp $ */
+/* $Id: mdoc_term.c,v 1.122 2010/05/13 06:22:11 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -1085,7 +1085,7 @@ static int
termp_nm_pre(DECL_ARGS)
{
- if (SEC_SYNOPSIS == n->sec)
+ if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags)
term_newln(p);
term_fontpush(p, TERMFONT_BOLD);
@@ -1384,7 +1384,7 @@ static void
termp_fd_post(DECL_ARGS)
{
- if (n->sec != SEC_SYNOPSIS)
+ if (n->sec != SEC_SYNOPSIS || ! (MDOC_LINE & n->flags))
return;
term_newln(p);
@@ -1471,7 +1471,7 @@ static void
termp_lb_post(DECL_ARGS)
{
- if (SEC_LIBRARY == n->sec)
+ if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags)
term_newln(p);
}
@@ -1540,7 +1540,7 @@ static int
termp_ft_pre(DECL_ARGS)
{
- if (SEC_SYNOPSIS == n->sec)
+ if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags)
if (n->prev && MDOC_Fo == n->prev->tok)
term_vspace(p);
@@ -1554,7 +1554,7 @@ static void
termp_ft_post(DECL_ARGS)
{
- if (SEC_SYNOPSIS == n->sec)
+ if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags)
term_newln(p);
}
@@ -1595,7 +1595,7 @@ static void
termp_fn_post(DECL_ARGS)
{
- if (n->sec == SEC_SYNOPSIS && n->next)
+ if (n->sec == SEC_SYNOPSIS && n->next && MDOC_LINE & n->flags)
term_vspace(p);
}
@@ -1894,7 +1894,7 @@ termp_in_post(DECL_ARGS)
term_word(p, ">");
term_fontpop(p);
- if (SEC_SYNOPSIS != n->sec)
+ if (SEC_SYNOPSIS != n->sec && ! (MDOC_LINE & n->flags))
return;
term_newln(p);