summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2010-06-27 16:18:13 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2010-06-27 16:18:13 +0000
commit971f7ac206ac7af70e97998c7ef5b4536efda79e (patch)
tree27e88af287b96db192d82640ab03b190da3b84a2
parent093fd946278d03ba2f1e7e6e6194129e51485c58 (diff)
downloadmandoc-971f7ac206ac7af70e97998c7ef5b4536efda79e.tar.gz
Following clue-stick applied by schwarze@, back out const-ness of regset
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.
-rw-r--r--libman.h2
-rw-r--r--libmdoc.h2
-rw-r--r--man.36
-rw-r--r--man.c4
-rw-r--r--man.h2
-rw-r--r--man_html.c1
-rw-r--r--mdoc.36
-rw-r--r--mdoc.c13
-rw-r--r--mdoc.h3
-rw-r--r--mdoc_html.c10
-rw-r--r--mdoc_term.c12
11 files changed, 38 insertions, 23 deletions
diff --git a/libman.h b/libman.h
index d1e48588..a0f31fa1 100644
--- a/libman.h
+++ b/libman.h
@@ -40,7 +40,7 @@ struct man {
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, \
diff --git a/libmdoc.h b/libmdoc.h
index 87f66c2d..df34021c 100644
--- a/libmdoc.h
+++ b/libmdoc.h
@@ -43,7 +43,7 @@ struct mdoc {
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, \
diff --git a/man.3 b/man.3
index b1551914..d607a7d2 100644
--- a/man.3
+++ b/man.3
@@ -34,7 +34,7 @@
.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"
@@ -291,14 +291,16 @@ on the finished parse tree with
.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(&regs, sizeof(struct regset));
line = 1;
-man = man_alloc(NULL, 0, NULL);
+man = man_alloc(&regs, NULL, 0, NULL);
buf = NULL;
alloc_len = 0;
diff --git a/man.c b/man.c
index 55f9f9cc..da3eb3a3 100644
--- a/man.c
+++ b/man.c
@@ -95,8 +95,8 @@ man_free(struct man *man)
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;
diff --git a/man.h b/man.h
index 545aa66a..d3c80b3a 100644
--- a/man.h
+++ b/man.h
@@ -106,7 +106,7 @@ __BEGIN_DECLS
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 *);
diff --git a/man_html.c b/man_html.c
index 0b20fe5a..47b66063 100644
--- a/man_html.c
+++ b/man_html.c
@@ -252,6 +252,7 @@ a2width(const struct man_node *n, struct roffsu *su)
}
+/* ARGSUSED */
static int
man_root_pre(MAN_ARGS)
{
diff --git a/mdoc.3 b/mdoc.3
index d27df25a..b21c34dc 100644
--- a/mdoc.3
+++ b/mdoc.3
@@ -35,7 +35,7 @@
.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"
@@ -259,14 +259,16 @@ on the finished parse tree with
.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(&regs, sizeof(struct regset));
line = 1;
-mdoc = mdoc_alloc(NULL, 0, NULL);
+mdoc = mdoc_alloc(&regs, NULL, 0, NULL);
buf = NULL;
alloc_len = 0;
diff --git a/mdoc.c b/mdoc.c
index 3d82b8d4..f2f5f1cf 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -192,8 +192,8 @@ mdoc_free(struct mdoc *mdoc)
* 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;
@@ -368,9 +368,18 @@ node_alloc(struct mdoc *m, int line, int pos,
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);
}
diff --git a/mdoc.h b/mdoc.h
index e552cdd5..e09256f1 100644
--- a/mdoc.h
+++ b/mdoc.h
@@ -301,6 +301,7 @@ struct mdoc_node {
#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. */
@@ -333,7 +334,7 @@ struct mdoc;
/* 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 *);
diff --git a/mdoc_html.c b/mdoc_html.c
index f3bc78e2..cafc664c 100644
--- a/mdoc_html.c
+++ b/mdoc_html.c
@@ -304,7 +304,7 @@ synopsis_pre(struct html *h, const struct mdoc_node *n)
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);
@@ -1614,7 +1614,7 @@ mdoc_fn_pre(MDOC_ARGS)
*/
#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);
@@ -1644,7 +1644,7 @@ mdoc_fn_pre(MDOC_ARGS)
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);
@@ -1654,7 +1654,7 @@ mdoc_fn_pre(MDOC_ARGS)
}
print_text(h, ")");
- if (SEC_SYNOPSIS == n->sec)
+ if (MDOC_SYNPRETTY & n->flags)
print_text(h, ";");
return(0);
@@ -1824,7 +1824,7 @@ mdoc_in_pre(MDOC_ARGS)
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, "<");
diff --git a/mdoc_term.c b/mdoc_term.c
index 7cc7388c..3352bf77 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -1278,7 +1278,7 @@ synopsis_pre(struct termp *p, const struct mdoc_node *n)
* 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;
/*
@@ -1543,7 +1543,7 @@ termp_fn_pre(DECL_ARGS)
term_word(p, ")");
- if (SEC_SYNOPSIS == n->sec)
+ if (MDOC_SYNPRETTY & n->flags)
term_word(p, ";");
return(0);
@@ -1820,7 +1820,7 @@ termp_in_pre(DECL_ARGS)
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, "<");
@@ -1839,13 +1839,13 @@ static void
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);
}
@@ -1987,7 +1987,7 @@ termp_fo_post(DECL_ARGS)
p->flags |= TERMP_NOSPACE;
term_word(p, ")");
- if (SEC_SYNOPSIS == n->sec) {
+ if (MDOC_SYNPRETTY & n->flags) {
p->flags |= TERMP_NOSPACE;
term_word(p, ";");
}