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.
-/* $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>
*
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;
-/* $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>
*
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));
}
p->pos = pos;
p->tok = tok;
p->type = type;
-
+ if (MDOC_NEWLINE & m->flags)
+ p->flags |= MDOC_LINE;
+ m->flags &= ~MDOC_NEWLINE;
return(p);
}
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. */
return(1);
}
+ sv = i;
+
/* Copy the first word into a nil-terminated buffer. */
for (j = 0; j < 4; j++, i++) {
* 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);
-/* $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>
*
/* 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 */
-/* $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>
*
{
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);
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);
{
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");
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;
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);
{
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);
-/* $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>
*
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;
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));
}
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.
}
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));
}
return(0);
}
- if (ppos > 1)
+ if ( ! nl)
return(1);
return(append_delims(m, line, pos, buf));
}
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
/* Standard appending of delimiters. */
- if (ppos > 1)
+ if ( ! nl)
return(1);
-
return(append_delims(m, line, pos, buf));
}
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
if ( ! flushed && ! rew_elem(m, tok))
return(0);
-
- if (ppos > 1)
+ if ( ! nl)
return(1);
return(append_delims(m, line, pos, buf));
}
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));
/*
-/* $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>
*
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);
termp_fd_post(DECL_ARGS)
{
- if (n->sec != SEC_SYNOPSIS)
+ if (n->sec != SEC_SYNOPSIS || ! (MDOC_LINE & n->flags))
return;
term_newln(p);
termp_lb_post(DECL_ARGS)
{
- if (SEC_LIBRARY == n->sec)
+ if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags)
term_newln(p);
}
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);
termp_ft_post(DECL_ARGS)
{
- if (SEC_SYNOPSIS == n->sec)
+ if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags)
term_newln(p);
}
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);
}
term_word(p, ">");
term_fontpop(p);
- if (SEC_SYNOPSIS != n->sec)
+ if (SEC_SYNOPSIS != n->sec && ! (MDOC_LINE & n->flags))
return;
term_newln(p);