diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2010-06-27 21:54:43 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2010-06-27 21:54:43 +0000 |
commit | dae22b2a7b046070a5972b52c5be5ab23c603ce7 (patch) | |
tree | 04d8a2c11e8943c412d5e1de74ee8881754a9d61 | |
parent | d41b978186af813a0930f71b4972e6e4750be2c5 (diff) |
Full .nr nS support, unbreaking the kernel manuals.
Kristaps coded this from scratch after reading my .nr patch;
it is simpler and more powerful.
Registers live in struct regset in regs.h, struct man and struct mdoc
contain pointers to it. The nS register is cleared when parsing .Sh.
Frontends respect the MDOC_SYNPRETTY flag set in mdoc node_alloc.
-rw-r--r-- | usr.bin/mandoc/libman.h | 24 | ||||
-rw-r--r-- | usr.bin/mandoc/libmdoc.h | 26 | ||||
-rw-r--r-- | usr.bin/mandoc/main.c | 14 | ||||
-rw-r--r-- | usr.bin/mandoc/man.3 | 22 | ||||
-rw-r--r-- | usr.bin/mandoc/man.c | 9 | ||||
-rw-r--r-- | usr.bin/mandoc/man.h | 6 | ||||
-rw-r--r-- | usr.bin/mandoc/man_html.c | 5 | ||||
-rw-r--r-- | usr.bin/mandoc/man_term.c | 5 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc.3 | 22 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc.c | 36 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc.h | 7 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_html.c | 13 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_term.c | 15 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_validate.c | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/roff.3 | 11 | ||||
-rw-r--r-- | usr.bin/mandoc/roff.7 | 41 | ||||
-rw-r--r-- | usr.bin/mandoc/roff.c | 88 | ||||
-rw-r--r-- | usr.bin/mandoc/roff.h | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/term.c | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/tree.c | 5 |
20 files changed, 271 insertions, 90 deletions
diff --git a/usr.bin/mandoc/libman.h b/usr.bin/mandoc/libman.h index d187aba5c5e..e26ab2a660d 100644 --- a/usr.bin/mandoc/libman.h +++ b/usr.bin/mandoc/libman.h @@ -1,4 +1,4 @@ -/* $Id: libman.h,v 1.22 2010/06/26 17:56:43 schwarze Exp $ */ +/* $Id: libman.h,v 1.23 2010/06/27 21:54:41 schwarze Exp $ */ /* * Copyright (c) 2009 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -17,6 +17,7 @@ #ifndef LIBMAN_H #define LIBMAN_H +#include "regs.h" #include "man.h" enum man_next { @@ -25,8 +26,8 @@ enum man_next { }; struct man { - void *data; - mandocmsg msg; + void *data; /* private application data */ + mandocmsg msg; /* output message handler */ int pflags; /* parse flags (see man.h) */ int flags; /* parse flags */ #define MAN_HALT (1 << 0) /* badness happened: die */ @@ -35,14 +36,19 @@ struct man { #define MAN_ILINE (1 << 3) /* Ignored in next-line scope. */ #define MAN_LITERAL (1 << 4) /* Literal input. */ #define MAN_BPLINE (1 << 5) - enum man_next next; - struct man_node *last; - struct man_node *first; - struct man_meta meta; + enum man_next next; /* where to put the next node */ + struct man_node *last; /* the last parsed node */ + struct man_node *first; /* the first parsed node */ + struct man_meta meta; /* document meta-data */ + struct regset *regs; /* registers */ }; -#define MACRO_PROT_ARGS struct man *m, enum mant tok, int line, \ - int ppos, int *pos, char *buf +#define MACRO_PROT_ARGS struct man *m, \ + enum mant tok, \ + int line, \ + int ppos, \ + int *pos, \ + char *buf struct man_macro { int (*fp)(MACRO_PROT_ARGS); diff --git a/usr.bin/mandoc/libmdoc.h b/usr.bin/mandoc/libmdoc.h index ceeedfd3f0d..b37489b9f2d 100644 --- a/usr.bin/mandoc/libmdoc.h +++ b/usr.bin/mandoc/libmdoc.h @@ -1,6 +1,6 @@ -/* $Id: libmdoc.h,v 1.37 2010/06/06 20:30:08 schwarze Exp $ */ +/* $Id: libmdoc.h,v 1.38 2010/06/27 21:54:41 schwarze Exp $ */ /* - * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> + * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -17,6 +17,7 @@ #ifndef LIBMDOC_H #define LIBMDOC_H +#include "regs.h" #include "mdoc.h" enum mdoc_next { @@ -25,8 +26,8 @@ enum mdoc_next { }; struct mdoc { - void *data; - mandocmsg msg; + void *data; /* private application data */ + mandocmsg msg; /* message callback */ int flags; #define MDOC_HALT (1 << 0) /* error in parse: halt */ #define MDOC_LITERAL (1 << 1) /* in a literal scope */ @@ -36,16 +37,21 @@ struct mdoc { #define MDOC_PPHRASE (1 << 5) /* within a partial phrase */ #define MDOC_FREECOL (1 << 6) /* `It' invocation should close */ int pflags; - enum mdoc_next next; - struct mdoc_node *last; - struct mdoc_node *first; - struct mdoc_meta meta; + enum mdoc_next next; /* where to put the next node */ + struct mdoc_node *last; /* the last node parsed */ + struct mdoc_node *first; /* the first node parsed */ + struct mdoc_meta meta; /* document meta-data */ enum mdoc_sec lastnamed; enum mdoc_sec lastsec; + struct regset *regs; /* registers */ }; -#define MACRO_PROT_ARGS struct mdoc *m, enum mdoct tok, \ - int line, int ppos, int *pos, char *buf +#define MACRO_PROT_ARGS struct mdoc *m, \ + enum mdoct tok, \ + int line, \ + int ppos, \ + int *pos, \ + char *buf struct mdoc_macro { int (*fp)(MACRO_PROT_ARGS); diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c index 129ebac3aec..7de99beeb8f 100644 --- a/usr.bin/mandoc/main.c +++ b/usr.bin/mandoc/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.37 2010/06/26 17:56:43 schwarze Exp $ */ +/* $Id: main.c,v 1.38 2010/06/27 21:54:41 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -27,10 +27,11 @@ #include <unistd.h> #include "mandoc.h" +#include "regs.h" +#include "main.h" #include "mdoc.h" #include "man.h" #include "roff.h" -#include "main.h" #define UNCONST(a) ((void *)(uintptr_t)(const void *)(a)) @@ -76,6 +77,7 @@ struct curparse { struct man *man; /* man parser */ struct mdoc *mdoc; /* mdoc parser */ struct roff *roff; /* roff parser (!NULL) */ + struct regset regs; /* roff registers */ enum outt outtype; /* which output to use */ out_mdoc outmdoc; /* mdoc output ptr */ out_man outman; /* man output ptr */ @@ -286,7 +288,7 @@ man_init(struct curparse *curp) if (curp->fflags & FL_NIGN_ESCAPE) pflags &= ~MAN_IGN_ESCAPE; - return(man_alloc(curp, pflags, mmsg)); + return(man_alloc(&curp->regs, curp, pflags, mmsg)); } @@ -294,7 +296,7 @@ static struct roff * roff_init(struct curparse *curp) { - return(roff_alloc(mmsg, curp)); + return(roff_alloc(&curp->regs, mmsg, curp)); } @@ -314,7 +316,7 @@ mdoc_init(struct curparse *curp) if (curp->fflags & FL_NIGN_MACRO) pflags &= ~MDOC_IGN_MACRO; - return(mdoc_alloc(curp, pflags, mmsg)); + return(mdoc_alloc(&curp->regs, curp, pflags, mmsg)); } @@ -443,6 +445,7 @@ fdesc(struct curparse *curp) man = NULL; mdoc = NULL; roff = NULL; + memset(&ln, 0, sizeof(struct buf)); /* @@ -623,6 +626,7 @@ fdesc(struct curparse *curp) (*curp->outmdoc)(curp->outdata, mdoc); cleanup: + memset(&curp->regs, 0, sizeof(struct regset)); if (mdoc) mdoc_reset(mdoc); if (man) diff --git a/usr.bin/mandoc/man.3 b/usr.bin/mandoc/man.3 index bfce2bb727d..2edd6a0a88a 100644 --- a/usr.bin/mandoc/man.3 +++ b/usr.bin/mandoc/man.3 @@ -1,4 +1,4 @@ -.\" $Id: man.3,v 1.11 2010/05/26 02:55:16 schwarze Exp $ +.\" $Id: man.3,v 1.12 2010/06/27 21:54:42 schwarze Exp $ .\" .\" Copyright (c) 2009-2010 Kristaps Dzonsons <kristaps@bsd.lv> .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: May 26 2010 $ +.Dd $Mdocdate: June 27 2010 $ .Dt MAN 3 .Os .Sh NAME @@ -29,10 +29,16 @@ .Nd man macro compiler library .Sh SYNOPSIS .In mandoc.h +.In regs.h .In man.h .Vt extern const char * const * man_macronames; .Ft "struct man *" -.Fn man_alloc "void *data" "int pflags" "mandocmsg msgs" +.Fo man_alloc +.Fa "struct regset *regs" +.Fa "void *data" +.Fa "int pflags" +.Fa "mandocmsg msgs" +.Fc .Ft int .Fn man_endparse "struct man *man" .Ft void @@ -42,7 +48,11 @@ .Ft "const struct man_node *" .Fn man_node "const struct man *man" .Ft int -.Fn man_parseln "struct man *man" "int line" "char *buf" +.Fo man_parseln +.Fa "struct man *man" +.Fa "int line" +.Fa "char *buf" +.Fc .Ft void .Fn man_reset "struct man *man" .Sh DESCRIPTION @@ -281,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(®s, sizeof(struct regset)); line = 1; -man = man_alloc(NULL, 0, NULL); +man = man_alloc(®s, NULL, 0, NULL); buf = NULL; alloc_len = 0; diff --git a/usr.bin/mandoc/man.c b/usr.bin/mandoc/man.c index 312fa3f5831..71acf9fd042 100644 --- a/usr.bin/mandoc/man.c +++ b/usr.bin/mandoc/man.c @@ -1,6 +1,6 @@ -/* $Id: man.c,v 1.34 2010/06/06 18:08:41 schwarze Exp $ */ +/* $Id: man.c,v 1.35 2010/06/27 21:54:42 schwarze Exp $ */ /* - * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> + * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -24,6 +24,7 @@ #include <string.h> #include "mandoc.h" +#include "regs.h" #include "libman.h" #include "libmandoc.h" @@ -90,7 +91,8 @@ man_free(struct man *man) struct man * -man_alloc(void *data, int pflags, mandocmsg msg) +man_alloc(struct regset *regs, void *data, + int pflags, mandocmsg msg) { struct man *p; @@ -100,6 +102,7 @@ man_alloc(void *data, int pflags, mandocmsg msg) p->data = data; p->pflags = pflags; p->msg = msg; + p->regs = regs; man_alloc1(p); return(p); diff --git a/usr.bin/mandoc/man.h b/usr.bin/mandoc/man.h index 1c191e39ceb..b56a2863e68 100644 --- a/usr.bin/mandoc/man.h +++ b/usr.bin/mandoc/man.h @@ -1,6 +1,6 @@ -/* $Id: man.h,v 1.23 2010/06/06 18:08:41 schwarze Exp $ */ +/* $Id: man.h,v 1.24 2010/06/27 21:54:42 schwarze Exp $ */ /* - * Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se> + * Copyright (c) 2009 Kristaps Dzonsons <kristaps@bsd.lv> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -106,7 +106,7 @@ __BEGIN_DECLS struct man; void man_free(struct man *); -struct man *man_alloc(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/usr.bin/mandoc/man_html.c b/usr.bin/mandoc/man_html.c index 93553434905..bbe7a7aedef 100644 --- a/usr.bin/mandoc/man_html.c +++ b/usr.bin/mandoc/man_html.c @@ -1,6 +1,6 @@ -/* $Id: man_html.c,v 1.15 2010/06/06 18:08:41 schwarze Exp $ */ +/* $Id: man_html.c,v 1.16 2010/06/27 21:54:42 schwarze Exp $ */ /* - * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> + * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -25,6 +25,7 @@ #include "mandoc.h" #include "out.h" #include "html.h" +#include "regs.h" #include "man.h" #include "main.h" diff --git a/usr.bin/mandoc/man_term.c b/usr.bin/mandoc/man_term.c index dd6533b6228..868f93a6058 100644 --- a/usr.bin/mandoc/man_term.c +++ b/usr.bin/mandoc/man_term.c @@ -1,6 +1,6 @@ -/* $Id: man_term.c,v 1.42 2010/06/26 19:08:00 schwarze Exp $ */ +/* $Id: man_term.c,v 1.43 2010/06/27 21:54:42 schwarze Exp $ */ /* - * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> + * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -24,6 +24,7 @@ #include "mandoc.h" #include "out.h" +#include "regs.h" #include "man.h" #include "term.h" #include "chars.h" diff --git a/usr.bin/mandoc/mdoc.3 b/usr.bin/mandoc/mdoc.3 index 5eb59e962d1..5818184b661 100644 --- a/usr.bin/mandoc/mdoc.3 +++ b/usr.bin/mandoc/mdoc.3 @@ -1,4 +1,4 @@ -.\" $Id: mdoc.3,v 1.8 2010/06/06 20:30:08 schwarze Exp $ +.\" $Id: mdoc.3,v 1.9 2010/06/27 21:54:42 schwarze Exp $ .\" .\" Copyright (c) 2009-2010 Kristaps Dzonsons <kristaps@bsd.lv> .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: June 6 2010 $ +.Dd $Mdocdate: June 27 2010 $ .Dt MDOC 3 .Os .Sh NAME @@ -29,11 +29,17 @@ .Nd mdoc macro compiler library .Sh SYNOPSIS .In mandoc.h +.In regs.h .In mdoc.h .Vt extern const char * const * mdoc_macronames; .Vt extern const char * const * mdoc_argnames; .Ft "struct mdoc *" -.Fn mdoc_alloc "void *data" "int pflags" "mandocmsg msgs" +.Fo mdoc_alloc +.Fa "struct regset *regs" +.Fa "void *data" +.Fa "int pflags" +.Fa "mandocmsg msgs" +.Fc .Ft int .Fn mdoc_endparse "struct mdoc *mdoc" .Ft void @@ -43,7 +49,11 @@ .Ft "const struct mdoc_node *" .Fn mdoc_node "const struct mdoc *mdoc" .Ft int -.Fn mdoc_parseln "struct mdoc *mdoc" "int line" "char *buf" +.Fo mdoc_parseln +.Fa "struct mdoc *mdoc" +.Fa "int line" +.Fa "char *buf" +.Fc .Ft int .Fn mdoc_reset "struct mdoc *mdoc" .Sh DESCRIPTION @@ -249,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(®s, sizeof(struct regset)); line = 1; -mdoc = mdoc_alloc(NULL, 0, NULL); +mdoc = mdoc_alloc(®s, NULL, 0, NULL); buf = NULL; alloc_len = 0; diff --git a/usr.bin/mandoc/mdoc.c b/usr.bin/mandoc/mdoc.c index d0e60ef0980..5498f995586 100644 --- a/usr.bin/mandoc/mdoc.c +++ b/usr.bin/mandoc/mdoc.c @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.57 2010/06/26 17:56:43 schwarze Exp $ */ +/* $Id: mdoc.c,v 1.58 2010/06/27 21:54:42 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -25,6 +25,7 @@ #include <time.h> #include "mandoc.h" +#include "regs.h" #include "libmdoc.h" #include "libmandoc.h" @@ -187,7 +188,8 @@ mdoc_free(struct mdoc *mdoc) * Allocate volatile and non-volatile parse resources. */ struct mdoc * -mdoc_alloc(void *data, int pflags, mandocmsg msg) +mdoc_alloc(struct regset *regs, void *data, + int pflags, mandocmsg msg) { struct mdoc *p; @@ -196,6 +198,7 @@ mdoc_alloc(void *data, int pflags, mandocmsg msg) p->msg = msg; p->data = data; p->pflags = pflags; + p->regs = regs; mdoc_hash_init(); mdoc_alloc1(p); @@ -254,8 +257,7 @@ mdoc_vmsg(struct mdoc *mdoc, enum mandocerr t, int -mdoc_macro(struct mdoc *m, enum mdoct tok, - int ln, int pp, int *pos, char *buf) +mdoc_macro(MACRO_PROT_ARGS) { assert(tok < MDOC_MAX); @@ -263,13 +265,13 @@ mdoc_macro(struct mdoc *m, enum mdoct tok, if (MDOC_PROLOGUE & mdoc_macros[tok].flags && MDOC_PBODY & m->flags) - return(mdoc_pmsg(m, ln, pp, MANDOCERR_BADBODY)); + return(mdoc_pmsg(m, line, ppos, MANDOCERR_BADBODY)); /* If we're in the prologue, deny "body" macros. */ if ( ! (MDOC_PROLOGUE & mdoc_macros[tok].flags) && ! (MDOC_PBODY & m->flags)) { - if ( ! mdoc_pmsg(m, ln, pp, MANDOCERR_BADPROLOG)) + if ( ! mdoc_pmsg(m, line, ppos, MANDOCERR_BADPROLOG)) return(0); if (NULL == m->meta.title) m->meta.title = mandoc_strdup("UNKNOWN"); @@ -282,7 +284,7 @@ mdoc_macro(struct mdoc *m, enum mdoct tok, m->flags |= MDOC_PBODY; } - return((*mdoc_macros[tok].fp)(m, tok, ln, pp, pos, buf)); + return((*mdoc_macros[tok].fp)(m, tok, line, ppos, pos, buf)); } @@ -362,9 +364,27 @@ 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; + + /* Register analysis. */ + + if (m->regs->regs[(int)REG_nS].set) { + if (m->regs->regs[(int)REG_nS].v.u) + p->flags |= MDOC_SYNPRETTY; + else + p->flags &= ~MDOC_SYNPRETTY; + } + return(p); } @@ -781,7 +801,7 @@ mdoc_pmacro(struct mdoc *m, int ln, char *buf, int offs) if (MDOC_Bl == n->tok && MDOC_BODY == n->type && LIST_column == n->data.Bl.type) { m->flags |= MDOC_FREECOL; - if ( ! mdoc_macro(m, MDOC_It, ln, sv, &sv, buf)) + if ( ! mdoc_macro(m, MDOC_It, ln, sv, &sv, buf)) goto err; return(1); } diff --git a/usr.bin/mandoc/mdoc.h b/usr.bin/mandoc/mdoc.h index dc51b4e92a6..66754f450c3 100644 --- a/usr.bin/mandoc/mdoc.h +++ b/usr.bin/mandoc/mdoc.h @@ -1,4 +1,4 @@ -/* $Id: mdoc.h,v 1.28 2010/06/26 17:56:43 schwarze Exp $ */ +/* $Id: mdoc.h,v 1.29 2010/06/27 21:54:42 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -155,6 +155,7 @@ enum mdoct { /* What follows is a list of ALL possible macro arguments. */ +/* FIXME: make this into an enum. */ #define MDOC_Split 0 #define MDOC_Nosplit 1 #define MDOC_Ragged 2 @@ -300,8 +301,10 @@ 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. */ struct mdoc_arg *args; /* BLOCK/ELEM */ struct mdoc_node *pending; /* BLOCK */ struct mdoc_node *head; /* BLOCK */ @@ -331,7 +334,7 @@ struct mdoc; /* See mdoc.3 for documentation. */ void mdoc_free(struct mdoc *); -struct mdoc *mdoc_alloc(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/usr.bin/mandoc/mdoc_html.c b/usr.bin/mandoc/mdoc_html.c index 4fac42a6faa..54a7d203a5a 100644 --- a/usr.bin/mandoc/mdoc_html.c +++ b/usr.bin/mandoc/mdoc_html.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_html.c,v 1.22 2010/06/26 17:56:43 schwarze Exp $ */ +/* $Id: mdoc_html.c,v 1.23 2010/06/27 21:54:42 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -26,6 +26,7 @@ #include "mandoc.h" #include "out.h" #include "html.h" +#include "regs.h" #include "mdoc.h" #include "main.h" @@ -299,7 +300,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); @@ -1609,7 +1610,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); @@ -1639,7 +1640,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); @@ -1649,7 +1650,7 @@ mdoc_fn_pre(MDOC_ARGS) } print_text(h, ")"); - if (SEC_SYNOPSIS == n->sec) + if (MDOC_SYNPRETTY & n->flags) print_text(h, ";"); return(0); @@ -1819,7 +1820,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/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c index fae7bfc7cea..58b3294a230 100644 --- a/usr.bin/mandoc/mdoc_term.c +++ b/usr.bin/mandoc/mdoc_term.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_term.c,v 1.91 2010/06/27 17:49:58 schwarze Exp $ */ +/* $Id: mdoc_term.c,v 1.92 2010/06/27 21:54:42 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -26,6 +26,7 @@ #include "mandoc.h" #include "out.h" #include "term.h" +#include "regs.h" #include "mdoc.h" #include "chars.h" #include "main.h" @@ -1273,7 +1274,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; /* @@ -1538,7 +1539,7 @@ termp_fn_pre(DECL_ARGS) term_word(p, ")"); - if (SEC_SYNOPSIS == n->sec) + if (MDOC_SYNPRETTY & n->flags) term_word(p, ";"); return(0); @@ -1815,7 +1816,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, "<"); @@ -1834,13 +1835,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); } @@ -1982,7 +1983,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, ";"); } diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c index a445b03c59c..3fb8d30cb56 100644 --- a/usr.bin/mandoc/mdoc_validate.c +++ b/usr.bin/mandoc/mdoc_validate.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_validate.c,v 1.62 2010/06/27 17:49:58 schwarze Exp $ */ +/* $Id: mdoc_validate.c,v 1.63 2010/06/27 21:54:42 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -802,6 +802,8 @@ pre_sh(PRE_ARGS) if (MDOC_BLOCK != n->type) return(1); + + mdoc->regs->regs[(int)REG_nS].set = 0; return(check_parent(mdoc, n, MDOC_MAX, MDOC_ROOT)); } diff --git a/usr.bin/mandoc/roff.3 b/usr.bin/mandoc/roff.3 index 3edfccd09e3..0c5a092668b 100644 --- a/usr.bin/mandoc/roff.3 +++ b/usr.bin/mandoc/roff.3 @@ -1,4 +1,4 @@ -.\" $Id: roff.3,v 1.1 2010/05/26 02:55:16 schwarze Exp $ +.\" $Id: roff.3,v 1.2 2010/06/27 21:54:42 schwarze Exp $ .\" .\" Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv> .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: May 26 2010 $ +.Dd $Mdocdate: June 27 2010 $ .Dt ROFF 3 .Os .Sh NAME @@ -27,9 +27,14 @@ .Nd roff macro compiler library .Sh SYNOPSIS .In mandoc.h +.In regs.h .In roff.h .Ft "struct roff *" -.Fn roff_alloc "mandocmsg msgs" "void *data" +.Fo roff_alloc +.Fa "struct regset *regs" +.Fa "mandocmsg msgs" +.Fa "void *data" +.Fc .Ft int .Fn roff_endparse "struct roff *roff" .Ft void diff --git a/usr.bin/mandoc/roff.7 b/usr.bin/mandoc/roff.7 index a2303dbad7d..3ac36e13e3e 100644 --- a/usr.bin/mandoc/roff.7 +++ b/usr.bin/mandoc/roff.7 @@ -1,4 +1,4 @@ -.\" $Id: roff.7,v 1.5 2010/06/26 17:56:43 schwarze Exp $ +.\" $Id: roff.7,v 1.6 2010/06/27 21:54:42 schwarze Exp $ .\" .\" Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv> .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: June 26 2010 $ +.Dd $Mdocdate: June 27 2010 $ .Dt ROFF 7 .Os .Sh NAME @@ -268,6 +268,37 @@ This macro is intended to have one argument, the name of the request, macro or string to be undefined. Currently, it is ignored including its arguments, and the number of arguments is not checked. +.Ss \&nr +Define a register. +A register is an arbitrary string value that defines some sort of state, +which influences parsing and/or formatting. +Its syntax is as follows: +.Pp +.D1 Pf \. Sx \&nr Cm name value +.Pp +The +.Cm value +may, at the moment, only be an integer. +The +.Cm name +is defined up to the next whitespace. +The following register +.Cm name +requests are recognised: +.Bl -tag -width Ds +.It Cm nS +If set to a positive integer value, certain +.Xr mdoc 7 +macros will behave as if they were defined in the +.Em SYNOPSIS +section. +Otherwise, this behaviour is unset (even if called within the +.Em SYNOPSIS +section itself). +Note that invoking a new +.Xr mdoc 7 +section will unset this value. +.El .Ss \&tr Output character translation. This macro is intended to have one argument, @@ -287,6 +318,12 @@ file re-write .Pp .Bl -dash -compact .It +The +.Cm nS +request to +.Sx \&nr +is only compatible with OpenBSD's groff. +.It Historic groff did not accept white-space buffering the custom END tag for the .Sx \&ig diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c index b20c3a98d9d..8bd10dd7050 100644 --- a/usr.bin/mandoc/roff.c +++ b/usr.bin/mandoc/roff.c @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.5 2010/06/26 17:56:43 schwarze Exp $ */ +/* $Id: roff.c,v 1.6 2010/06/27 21:54:42 schwarze Exp $ */ /* * Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -19,12 +19,15 @@ #endif #include <assert.h> +#include <errno.h> #include <ctype.h> +#include <limits.h> #include <stdlib.h> #include <string.h> #include <stdio.h> #include "mandoc.h" +#include "regs.h" #include "roff.h" #define RSTACK_MAX 128 @@ -48,6 +51,7 @@ enum rofft { ROFF_tr, ROFF_cblock, ROFF_ccond, + ROFF_nr, ROFF_MAX }; @@ -62,6 +66,7 @@ struct roff { void *data; /* privdata for messages */ enum roffrule rstack[RSTACK_MAX]; /* stack of !`ie' rules */ int rstackpos; /* position in rstack */ + struct regset *regs; /* read/writable registers */ }; struct roffnode { @@ -103,8 +108,9 @@ static enum rofferr roff_ccond(ROFF_ARGS); static enum rofferr roff_cond(ROFF_ARGS); static enum rofferr roff_cond_text(ROFF_ARGS); static enum rofferr roff_cond_sub(ROFF_ARGS); -static enum roffrule roff_evalcond(const char *, int *); static enum rofferr roff_line(ROFF_ARGS); +static enum rofferr roff_nr(ROFF_ARGS); +static enum roffrule roff_evalcond(const char *, int *); /* See roff_hash_find() */ @@ -130,6 +136,7 @@ static struct roffmac roffs[ROFF_MAX] = { { "tr", roff_line, NULL, NULL, 0, NULL }, { ".", roff_cblock, NULL, NULL, 0, NULL }, { "\\}", roff_ccond, NULL, NULL, 0, NULL }, + { "nr", roff_nr, NULL, NULL, 0, NULL }, }; static void roff_free1(struct roff *); @@ -140,6 +147,7 @@ static int roffnode_push(struct roff *, enum rofft, int, int); static void roffnode_pop(struct roff *); static enum rofft roff_parse(const char *, int *); +static int roff_parse_nat(const char *, unsigned int *); /* See roff_hash_find() */ #define ROFF_HASH(p) (p[0] - ASCII_LO) @@ -273,7 +281,7 @@ roff_free(struct roff *r) struct roff * -roff_alloc(const mandocmsg msg, void *data) +roff_alloc(struct regset *regs, const mandocmsg msg, void *data) { struct roff *r; @@ -282,6 +290,7 @@ roff_alloc(const mandocmsg msg, void *data) return(0); } + r->regs = regs; r->msg = msg; r->data = data; r->rstackpos = -1; @@ -292,8 +301,8 @@ roff_alloc(const mandocmsg msg, void *data) enum rofferr -roff_parseln(struct roff *r, int ln, - char **bufp, size_t *szp, int pos, int *offs) +roff_parseln(struct roff *r, int ln, char **bufp, + size_t *szp, int pos, int *offs) { enum rofft t; int ppos; @@ -392,6 +401,26 @@ roff_parse(const char *buf, int *pos) } +static int +roff_parse_nat(const char *buf, unsigned int *res) +{ + char *ep; + long lval; + + errno = 0; + lval = strtol(buf, &ep, 10); + if (buf[0] == '\0' || *ep != '\0') + return(0); + if ((errno == ERANGE && + (lval == LONG_MAX || lval == LONG_MIN)) || + (lval > INT_MAX || lval < 0)) + return(0); + + *res = (unsigned int)lval; + return(1); +} + + /* ARGSUSED */ static enum rofferr roff_cblock(ROFF_ARGS) @@ -602,8 +631,8 @@ roff_block_sub(ROFF_ARGS) return(ROFF_IGN); assert(roffs[t].proc); - return((*roffs[t].proc)(r, t, bufp, - szp, ln, ppos, pos, offs)); + return((*roffs[t].proc)(r, t, bufp, szp, + ln, ppos, pos, offs)); } @@ -652,8 +681,8 @@ roff_cond_sub(ROFF_ARGS) return(ROFF_IGN); assert(roffs[t].proc); - return((*roffs[t].proc) - (r, t, bufp, szp, ln, ppos, pos, offs)); + return((*roffs[t].proc)(r, t, bufp, szp, + ln, ppos, pos, offs)); } @@ -712,6 +741,15 @@ roff_evalcond(const char *v, int *pos) /* ARGSUSED */ static enum rofferr +roff_line(ROFF_ARGS) +{ + + return(ROFF_IGN); +} + + +/* ARGSUSED */ +static enum rofferr roff_cond(ROFF_ARGS) { int sv; @@ -808,8 +846,38 @@ roff_cond(ROFF_ARGS) /* ARGSUSED */ static enum rofferr -roff_line(ROFF_ARGS) +roff_nr(ROFF_ARGS) { + const char *key, *val; + struct reg *rg; + + key = &(*bufp)[pos]; + rg = r->regs->regs; + + /* Parse register request. */ + while ((*bufp)[pos] && ' ' != (*bufp)[pos]) + pos++; + + /* + * Set our nil terminator. Because this line is going to be + * ignored anyway, we can munge it as we please. + */ + if ((*bufp)[pos]) + (*bufp)[pos++] = '\0'; + + /* Skip whitespace to register token. */ + while ((*bufp)[pos] && ' ' == (*bufp)[pos]) + pos++; + + val = &(*bufp)[pos]; + + /* Process register token. */ + + if (0 == strcmp(key, "nS")) { + rg[(int)REG_nS].set = 1; + if ( ! roff_parse_nat(val, &rg[(int)REG_nS].v.u)) + rg[(int)REG_nS].v.u = 0; + } return(ROFF_IGN); } diff --git a/usr.bin/mandoc/roff.h b/usr.bin/mandoc/roff.h index a89c5c85722..3ec6ec904c6 100644 --- a/usr.bin/mandoc/roff.h +++ b/usr.bin/mandoc/roff.h @@ -1,4 +1,4 @@ -/* $Id: roff.h,v 1.2 2010/05/20 00:58:02 schwarze Exp $ */ +/* $Id: roff.h,v 1.3 2010/06/27 21:54:42 schwarze Exp $ */ /* * Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -29,7 +29,7 @@ __BEGIN_DECLS struct roff; void roff_free(struct roff *); -struct roff *roff_alloc(mandocmsg, void *); +struct roff *roff_alloc(struct regset *, mandocmsg, void *); void roff_reset(struct roff *); enum rofferr roff_parseln(struct roff *, int, char **, size_t *, int, int *); diff --git a/usr.bin/mandoc/term.c b/usr.bin/mandoc/term.c index 90094bf658a..408d9916505 100644 --- a/usr.bin/mandoc/term.c +++ b/usr.bin/mandoc/term.c @@ -1,4 +1,4 @@ -/* $Id: term.c,v 1.40 2010/06/27 01:24:02 schwarze Exp $ */ +/* $Id: term.c,v 1.41 2010/06/27 21:54:42 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -27,8 +27,6 @@ #include "chars.h" #include "out.h" #include "term.h" -#include "man.h" -#include "mdoc.h" #include "main.h" static void spec(struct termp *, const char *, size_t); diff --git a/usr.bin/mandoc/tree.c b/usr.bin/mandoc/tree.c index 9f4df836a0c..fb1297c5fd3 100644 --- a/usr.bin/mandoc/tree.c +++ b/usr.bin/mandoc/tree.c @@ -1,6 +1,6 @@ -/* $Id: tree.c,v 1.7 2010/05/23 22:45:01 schwarze Exp $ */ +/* $Id: tree.c,v 1.8 2010/06/27 21:54:42 schwarze Exp $ */ /* - * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> + * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -20,6 +20,7 @@ #include <time.h> #include "mandoc.h" +#include "regs.h" #include "mdoc.h" #include "man.h" #include "main.h" |