passed in to libmdoc and libman.
Fix mdoc.3 and man.3 EXAMPLE sections to include regset.
Add MDOC_SYNPRETTY flag cueing front-end to nicely format certain values
as if SEC_SYNOPSIS were the current section.
-/* $Id: libman.h,v 1.39 2010/06/27 15:52:41 kristaps Exp $ */
+/* $Id: libman.h,v 1.40 2010/06/27 16:18:13 kristaps Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@bsd.lv>
*
struct man_node *last; /* the last parsed node */
struct man_node *first; /* the first parsed node */
struct man_meta meta; /* document meta-data */
- const struct regset *regs; /* readonly registers */
+ struct regset *regs; /* registers */
};
#define MACRO_PROT_ARGS struct man *m, \
-/* $Id: libmdoc.h,v 1.56 2010/06/27 15:52:41 kristaps Exp $ */
+/* $Id: libmdoc.h,v 1.57 2010/06/27 16:18:13 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
*
struct mdoc_meta meta; /* document meta-data */
enum mdoc_sec lastnamed;
enum mdoc_sec lastsec;
- const struct regset *regs; /* readonly registers */
+ struct regset *regs; /* registers */
};
#define MACRO_PROT_ARGS struct mdoc *m, \
-.\" $Id: man.3,v 1.20 2010/06/27 15:52:41 kristaps Exp $
+.\" $Id: man.3,v 1.21 2010/06/27 16:18:13 kristaps Exp $
.\"
.\" Copyright (c) 2009-2010 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.Vt extern const char * const * man_macronames;
.Ft "struct man *"
.Fo man_alloc
-.Fa "const struct regset *regs"
+.Fa "struct regset *regs"
.Fa "void *data"
.Fa "int pflags"
.Fa "mandocmsg msgs"
.Fn parsed .
This example does not error-check nor free memory upon failure.
.Bd -literal -offset indent
+struct regset regs;
struct man *man;
struct man_node *node;
char *buf;
size_t len;
int line;
+bzero(®s, sizeof(struct regset));
line = 1;
-man = man_alloc(NULL, 0, NULL);
+man = man_alloc(®s, NULL, 0, NULL);
buf = NULL;
alloc_len = 0;
-/* $Id: man.c,v 1.79 2010/06/27 15:52:41 kristaps Exp $ */
+/* $Id: man.c,v 1.80 2010/06/27 16:18:13 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
*
struct man *
-man_alloc(const struct regset *regs,
- void *data, int pflags, mandocmsg msg)
+man_alloc(struct regset *regs, void *data,
+ int pflags, mandocmsg msg)
{
struct man *p;
-/* $Id: man.h,v 1.39 2010/06/27 15:52:41 kristaps Exp $ */
+/* $Id: man.h,v 1.40 2010/06/27 16:18:13 kristaps Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@bsd.lv>
*
struct man;
void man_free(struct man *);
-struct man *man_alloc(const struct regset *, void *, int, mandocmsg);
+struct man *man_alloc(struct regset *, void *, int, mandocmsg);
void man_reset(struct man *);
int man_parseln(struct man *, int, char *, int);
int man_endparse(struct man *);
-/* $Id: man_html.c,v 1.39 2010/06/27 15:52:41 kristaps Exp $ */
+/* $Id: man_html.c,v 1.40 2010/06/27 16:18:13 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
*
}
+/* ARGSUSED */
static int
man_root_pre(MAN_ARGS)
{
-.\" $Id: mdoc.3,v 1.43 2010/06/27 15:52:41 kristaps Exp $
+.\" $Id: mdoc.3,v 1.44 2010/06/27 16:18:13 kristaps Exp $
.\"
.\" Copyright (c) 2009-2010 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.Vt extern const char * const * mdoc_argnames;
.Ft "struct mdoc *"
.Fo mdoc_alloc
-.Fa "const struct regset *regs"
+.Fa "struct regset *regs"
.Fa "void *data"
.Fa "int pflags"
.Fa "mandocmsg msgs"
.Fn parsed .
This example does not error-check nor free memory upon failure.
.Bd -literal -offset indent
+struct regset regs;
struct mdoc *mdoc;
const struct mdoc_node *node;
char *buf;
size_t len;
int line;
+bzero(®s, sizeof(struct regset));
line = 1;
-mdoc = mdoc_alloc(NULL, 0, NULL);
+mdoc = mdoc_alloc(®s, NULL, 0, NULL);
buf = NULL;
alloc_len = 0;
-/* $Id: mdoc.c,v 1.149 2010/06/27 15:52:41 kristaps Exp $ */
+/* $Id: mdoc.c,v 1.150 2010/06/27 16:18:13 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
*
* Allocate volatile and non-volatile parse resources.
*/
struct mdoc *
-mdoc_alloc(const struct regset *regs,
- void *data, int pflags, mandocmsg msg)
+mdoc_alloc(struct regset *regs, void *data,
+ int pflags, mandocmsg msg)
{
struct mdoc *p;
p->pos = pos;
p->tok = tok;
p->type = type;
+
+ /* Flag analysis. */
+
if (MDOC_NEWLINE & m->flags)
p->flags |= MDOC_LINE;
m->flags &= ~MDOC_NEWLINE;
+
+ /* Section analysis. */
+
+ if (SEC_SYNOPSIS == p->sec)
+ p->flags |= MDOC_SYNPRETTY;
+
return(p);
}
-/* $Id: mdoc.h,v 1.93 2010/06/27 15:52:41 kristaps Exp $ */
+/* $Id: mdoc.h,v 1.94 2010/06/27 16:18:13 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
*
#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 */
+#define MDOC_SYNPRETTY (1 << 4) /* SYNOPSIS-style formatting */
enum mdoc_type type; /* AST node type */
enum mdoc_sec sec; /* current named section */
/* FIXME: these can be union'd to shave a few bytes. */
/* See mdoc.3 for documentation. */
void mdoc_free(struct mdoc *);
-struct mdoc *mdoc_alloc(const struct regset *, void *, int, mandocmsg);
+struct mdoc *mdoc_alloc(struct regset *, void *, int, mandocmsg);
void mdoc_reset(struct mdoc *);
int mdoc_parseln(struct mdoc *, int, char *, int);
const struct mdoc_node *mdoc_node(const struct mdoc *);
-/* $Id: mdoc_html.c,v 1.86 2010/06/26 15:36:37 kristaps Exp $ */
+/* $Id: mdoc_html.c,v 1.87 2010/06/27 16:18:13 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
*
struct roffsu su;
struct htmlpair tag;
- if (NULL == n->prev || SEC_SYNOPSIS != n->sec)
+ if (NULL == n->prev || ! (MDOC_SYNPRETTY & n->flags))
return;
SCALE_VS_INIT(&su, 1);
*/
#if 0
- if (SEC_SYNOPSIS == n->sec) {
+ if (MDOC_SYNPRETTY & n->flags) {
nbuf[0] = '\0';
html_idcat(nbuf, sp, BUFSIZ);
PAIR_ID_INIT(&tag[1], nbuf);
for (nn = n->child->next; nn; nn = nn->next) {
i = 1;
- if (SEC_SYNOPSIS == n->sec)
+ if (MDOC_SYNPRETTY & n->flags)
i = 2;
t = print_otag(h, TAG_SPAN, i, tag);
print_text(h, nn->string);
}
print_text(h, ")");
- if (SEC_SYNOPSIS == n->sec)
+ if (MDOC_SYNPRETTY & n->flags)
print_text(h, ";");
return(0);
PAIR_CLASS_INIT(&tag[0], "includes");
print_otag(h, TAG_SPAN, 1, tag);
- if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags)
+ if (MDOC_SYNPRETTY & n->flags && MDOC_LINE & n->flags)
print_text(h, "#include");
print_text(h, "<");
-/* $Id: mdoc_term.c,v 1.159 2010/06/27 01:26:20 schwarze Exp $ */
+/* $Id: mdoc_term.c,v 1.160 2010/06/27 16:18:13 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
*
* Obviously, if we're not in a SYNOPSIS or no prior macros
* exist, do nothing.
*/
- if (NULL == n->prev || SEC_SYNOPSIS != n->sec)
+ if (NULL == n->prev || ! (MDOC_SYNPRETTY & n->flags))
return;
/*
term_word(p, ")");
- if (SEC_SYNOPSIS == n->sec)
+ if (MDOC_SYNPRETTY & n->flags)
term_word(p, ";");
return(0);
synopsis_pre(p, n);
- if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags) {
+ if (MDOC_SYNPRETTY & n->flags && MDOC_LINE & n->flags) {
term_fontpush(p, TERMFONT_BOLD);
term_word(p, "#include");
term_word(p, "<");
termp_in_post(DECL_ARGS)
{
- if (SEC_SYNOPSIS == n->sec)
+ if (MDOC_SYNPRETTY & n->flags)
term_fontpush(p, TERMFONT_BOLD);
p->flags |= TERMP_NOSPACE;
term_word(p, ">");
- if (SEC_SYNOPSIS == n->sec)
+ if (MDOC_SYNPRETTY & n->flags)
term_fontpop(p);
}
p->flags |= TERMP_NOSPACE;
term_word(p, ")");
- if (SEC_SYNOPSIS == n->sec) {
+ if (MDOC_SYNPRETTY & n->flags) {
p->flags |= TERMP_NOSPACE;
term_word(p, ";");
}