summaryrefslogtreecommitdiffstats
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
commit04007246b4661dffd30ad53faf1ef776be330dba (patch)
treef6db8cfbc99238f7655884f89a976d73dc43c701
parent94584327ed391203187fa593c8e0ff125dfd3979 (diff)
downloadmandoc-04007246b4661dffd30ad53faf1ef776be330dba.tar.gz
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.h7
-rw-r--r--mdoc.c14
-rw-r--r--mdoc.h28
-rw-r--r--mdoc_html.c13
-rw-r--r--mdoc_macro.c33
-rw-r--r--mdoc_term.c14
6 files changed, 63 insertions, 46 deletions
diff --git a/libmdoc.h b/libmdoc.h
index 2b4ca755..4a76df4d 100644
--- a/libmdoc.h
+++ b/libmdoc.h
@@ -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 88e673e8..9b468d84 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -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 9246b2a3..01e37b4d 100644
--- a/mdoc.h
+++ b/mdoc.h
@@ -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 ed72cbc6..bb109efa 100644
--- a/mdoc_html.c
+++ b/mdoc_html.c
@@ -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 f6df7e40..1ea1316d 100644
--- a/mdoc_macro.c
+++ b/mdoc_macro.c
@@ -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 de9af97e..7413a541 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -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);