aboutsummaryrefslogtreecommitdiffstatshomepage
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
commitdc95dcaff23f7235529d0b5d9866a252ca3f8c06 (patch)
tree33263f6d49184bc0c76b80cf9d91e5409c3d3e16
parentdc649a73f967c1a61e60d2495f16d56db82eac57 (diff)
downloadmandoc-dc95dcaff23f7235529d0b5d9866a252ca3f8c06.tar.gz
mandoc-dc95dcaff23f7235529d0b5d9866a252ca3f8c06.tar.zst
mandoc-dc95dcaff23f7235529d0b5d9866a252ca3f8c06.zip
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.h4
-rw-r--r--libmdoc.h4
-rw-r--r--man.38
-rw-r--r--man.c6
-rw-r--r--man.h4
-rw-r--r--man_html.c3
-rw-r--r--mdoc.38
-rw-r--r--mdoc.c15
-rw-r--r--mdoc.h5
-rw-r--r--mdoc_html.c12
-rw-r--r--mdoc_term.c14
11 files changed, 49 insertions, 34 deletions
diff --git a/libman.h b/libman.h
index 4cc0befc..7a4fd6fe 100644
--- a/libman.h
+++ b/libman.h
@@ -1,4 +1,4 @@
-/* $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>
*
@@ -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 16d577ce..d0a8a979 100644
--- a/libmdoc.h
+++ b/libmdoc.h
@@ -1,4 +1,4 @@
-/* $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>
*
@@ -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 4f461290..a3be19da 100644
--- a/man.3
+++ b/man.3
@@ -1,4 +1,4 @@
-.\" $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>
.\"
@@ -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 0bdff790..1d320706 100644
--- a/man.c
+++ b/man.c
@@ -1,4 +1,4 @@
-/* $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>
*
@@ -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 f8c8d786..dfe6c5a7 100644
--- a/man.h
+++ b/man.h
@@ -1,4 +1,4 @@
-/* $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>
*
@@ -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 1534e12c..162f3045 100644
--- a/man_html.c
+++ b/man_html.c
@@ -1,4 +1,4 @@
-/* $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>
*
@@ -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 17d41fef..8b15b998 100644
--- a/mdoc.3
+++ b/mdoc.3
@@ -1,4 +1,4 @@
-.\" $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>
.\"
@@ -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 4848b045..6d2334a6 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -1,4 +1,4 @@
-/* $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>
*
@@ -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 19e52e23..485cfc61 100644
--- a/mdoc.h
+++ b/mdoc.h
@@ -1,4 +1,4 @@
-/* $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>
*
@@ -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 f13fe42f..38538cdb 100644
--- a/mdoc_html.c
+++ b/mdoc_html.c
@@ -1,4 +1,4 @@
-/* $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>
*
@@ -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 e4d50a70..cad6403e 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -1,4 +1,4 @@
-/* $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>
*
@@ -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, ";");
}