diff options
author | 2012-05-27 17:48:57 +0000 | |
---|---|---|
committer | 2012-05-27 17:48:57 +0000 | |
commit | 5924b5736a3bec0c2ef93ddbd1da733745942d59 (patch) | |
tree | 1df37aca7cb87b5dba851f42f6052cdfcb19f89b | |
parent | 75264eae65dc293d4a49cd965f67b124bc6fb138 (diff) | |
download | mandoc-5924b5736a3bec0c2ef93ddbd1da733745942d59.tar.gz mandoc-5924b5736a3bec0c2ef93ddbd1da733745942d59.tar.zst mandoc-5924b5736a3bec0c2ef93ddbd1da733745942d59.zip |
Support -Ios='OpenBSD 5.1' to override uname(3) as the source of the
default value for the mdoc(7) .Os macro.
Needed for man.cgi on the OpenBSD website.
Problem with man.cgi first noticed by deraadt@;
beck@ and deraadt@ agree with the way to solve the issue.
"Please check them in and I'll look into them later!" kristaps@
-rw-r--r-- | cgi.c | 4 | ||||
-rw-r--r-- | libmandoc.h | 4 | ||||
-rw-r--r-- | libmdoc.h | 3 | ||||
-rw-r--r-- | main.c | 24 | ||||
-rw-r--r-- | mandoc.1 | 17 | ||||
-rw-r--r-- | mandoc.h | 6 | ||||
-rw-r--r-- | mandocdb.c | 4 | ||||
-rw-r--r-- | mdoc.c | 5 | ||||
-rw-r--r-- | mdoc_validate.c | 25 | ||||
-rw-r--r-- | read.c | 13 |
10 files changed, 71 insertions, 34 deletions
@@ -1,4 +1,4 @@ -/* $Id: cgi.c,v 1.43 2012/03/25 00:46:39 kristaps Exp $ */ +/* $Id: cgi.c,v 1.44 2012/05/27 17:48:57 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -733,7 +733,7 @@ format(const struct req *req, const char *file) return; } - mp = mparse_alloc(MPARSE_AUTO, MANDOCLEVEL_FATAL, NULL, NULL); + mp = mparse_alloc(MPARSE_AUTO, MANDOCLEVEL_FATAL, NULL, NULL, NULL); rc = mparse_readfd(mp, fd, file); close(fd); diff --git a/libmandoc.h b/libmandoc.h index de422884..f75416db 100644 --- a/libmandoc.h +++ b/libmandoc.h @@ -1,4 +1,4 @@ -/* $Id: libmandoc.h,v 1.29 2011/12/02 01:37:14 schwarze Exp $ */ +/* $Id: libmandoc.h,v 1.30 2012/05/27 17:48:57 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -52,7 +52,7 @@ int mandoc_strntoi(const char *, size_t, int); const char *mandoc_a2msec(const char*); void mdoc_free(struct mdoc *); -struct mdoc *mdoc_alloc(struct roff *, struct mparse *); +struct mdoc *mdoc_alloc(struct roff *, struct mparse *, char *); void mdoc_reset(struct mdoc *); int mdoc_parseln(struct mdoc *, int, char *, int); int mdoc_endparse(struct mdoc *); @@ -1,4 +1,4 @@ -/* $Id: libmdoc.h,v 1.78 2011/12/02 01:37:14 schwarze Exp $ */ +/* $Id: libmdoc.h,v 1.79 2012/05/27 17:48:57 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -24,6 +24,7 @@ enum mdoc_next { struct mdoc { struct mparse *parse; /* parse pointer */ + char *defos; /* default argument for .Os */ int flags; /* parse flags */ #define MDOC_HALT (1 << 0) /* error in parse: halt */ #define MDOC_LITERAL (1 << 1) /* in a literal scope */ @@ -1,7 +1,7 @@ -/* $Id: main.c,v 1.165 2011/10/06 22:29:12 kristaps Exp $ */ +/* $Id: main.c,v 1.166 2012/05/27 17:48:57 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> - * Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2010, 2011, 2012 Ingo Schwarze <schwarze@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -85,6 +85,7 @@ main(int argc, char *argv[]) struct curparse curp; enum mparset type; enum mandoclevel rc; + char *defos; progname = strrchr(argv[0], '/'); if (progname == NULL) @@ -97,10 +98,24 @@ main(int argc, char *argv[]) type = MPARSE_AUTO; curp.outtype = OUTT_ASCII; curp.wlevel = MANDOCLEVEL_FATAL; + defos = NULL; /* LINTED */ - while (-1 != (c = getopt(argc, argv, "m:O:T:VW:"))) + while (-1 != (c = getopt(argc, argv, "I:m:O:T:VW:"))) switch (c) { + case ('I'): + if (strncmp(optarg, "os=", 3)) { + fprintf(stderr, "-I%s: Bad argument\n", + optarg); + return((int)MANDOCLEVEL_BADARG); + } + if (defos) { + fprintf(stderr, "-I%s: Duplicate argument\n", + optarg); + return((int)MANDOCLEVEL_BADARG); + } + defos = mandoc_strdup(optarg + 3); + break; case ('m'): if ( ! moptions(&type, optarg)) return((int)MANDOCLEVEL_BADARG); @@ -125,7 +140,7 @@ main(int argc, char *argv[]) /* NOTREACHED */ } - curp.mp = mparse_alloc(type, curp.wlevel, mmsg, &curp); + curp.mp = mparse_alloc(type, curp.wlevel, mmsg, &curp, defos); /* * Conditionally start up the lookaside buffer before parsing. @@ -152,6 +167,7 @@ main(int argc, char *argv[]) (*curp.outfree)(curp.outdata); if (curp.mp) mparse_free(curp.mp); + free(defos); return((int)rc); } @@ -1,6 +1,7 @@ -.\" $Id: mandoc.1,v 1.100 2011/12/25 19:35:44 kristaps Exp $ +.\" $Id: mandoc.1,v 1.101 2012/05/27 17:48:57 schwarze Exp $ .\" .\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> +.\" Copyright (c) 2012 Ingo Schwarze <schwarze@openbsd.org> .\" .\" Permission to use, copy, modify, and distribute this software for any .\" purpose with or without fee is hereby granted, provided that the above @@ -14,7 +15,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: December 25 2011 $ +.Dd $Mdocdate: May 27 2012 $ .Dt MANDOC 1 .Os .Sh NAME @@ -23,6 +24,9 @@ .Sh SYNOPSIS .Nm mandoc .Op Fl V +.Sm off +.Op Fl I Cm os Li = Ar name +.Sm on .Op Fl m Ns Ar format .Op Fl O Ns Ar option .Op Fl T Ns Ar output @@ -49,6 +53,15 @@ output. .Pp The arguments are as follows: .Bl -tag -width Ds +.Sm off +.It Fl I Cm os Li = Ar name +.Sm on +Override the default operating system +.Ar name +for the +.Xr mdoc 7 +.Sq \&Os +macro. .It Fl m Ns Ar format Input format. See @@ -1,4 +1,4 @@ -/* $Id: mandoc.h,v 1.99 2012/02/16 20:51:31 joerg Exp $ */ +/* $Id: mandoc.h,v 1.100 2012/05/27 17:48:57 schwarze Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -413,8 +413,8 @@ int mchars_spec2cp(const struct mchars *, const char *, size_t); const char *mchars_spec2str(const struct mchars *, const char *, size_t, size_t *); -struct mparse *mparse_alloc(enum mparset, - enum mandoclevel, mandocmsg, void *); +struct mparse *mparse_alloc(enum mparset, enum mandoclevel, + mandocmsg, void *, char *); void mparse_free(struct mparse *); void mparse_keep(struct mparse *); enum mandoclevel mparse_readfd(struct mparse *, int, const char *); @@ -1,4 +1,4 @@ -/* $Id: mandocdb.c,v 1.48 2012/05/27 17:39:28 schwarze Exp $ */ +/* $Id: mandocdb.c,v 1.49 2012/05/27 17:48:57 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011, 2012 Ingo Schwarze <schwarze@openbsd.org> @@ -396,7 +396,7 @@ main(int argc, char *argv[]) info.lorder = 4321; info.flags = R_DUP; - mp = mparse_alloc(MPARSE_AUTO, MANDOCLEVEL_FATAL, NULL, NULL); + mp = mparse_alloc(MPARSE_AUTO, MANDOCLEVEL_FATAL, NULL, NULL, NULL); memset(&buf, 0, sizeof(struct buf)); memset(&dbuf, 0, sizeof(struct buf)); @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.196 2011/09/30 00:13:28 schwarze Exp $ */ +/* $Id: mdoc.c,v 1.197 2012/05/27 17:48:57 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org> @@ -197,13 +197,14 @@ mdoc_free(struct mdoc *mdoc) * Allocate volatile and non-volatile parse resources. */ struct mdoc * -mdoc_alloc(struct roff *roff, struct mparse *parse) +mdoc_alloc(struct roff *roff, struct mparse *parse, char *defos) { struct mdoc *p; p = mandoc_calloc(1, sizeof(struct mdoc)); p->parse = parse; + p->defos = defos; p->roff = roff; mdoc_hash_init(); diff --git a/mdoc_validate.c b/mdoc_validate.c index 07fd6873..d4a0b8d3 100644 --- a/mdoc_validate.c +++ b/mdoc_validate.c @@ -1,7 +1,7 @@ -/* $Id: mdoc_validate.c,v 1.183 2012/05/27 17:39:28 schwarze Exp $ */ +/* $Id: mdoc_validate.c,v 1.184 2012/05/27 17:48:57 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> - * Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2010, 2011, 2012 Ingo Schwarze <schwarze@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -2192,14 +2192,15 @@ post_os(POST_ARGS) n = mdoc->last; /* - * Set the operating system by way of the `Os' macro. Note that - * if an argument isn't provided and -DOSNAME="\"foo\"" is - * provided during compilation, this value will be used instead - * of filling in "sysname release" from uname(). + * Set the operating system by way of the `Os' macro. + * The order of precedence is: + * 1. the argument of the `Os' macro, unless empty + * 2. the -Ios=foo command line argument, if provided + * 3. -DOSNAME="\"foo\"", if provided during compilation + * 4. "sysname release" from uname(3) */ - if (mdoc->meta.os) - free(mdoc->meta.os); + free(mdoc->meta.os); buf[0] = '\0'; if (-1 == (c = concat(buf, n->child, BUFSIZ))) { @@ -2209,11 +2210,11 @@ post_os(POST_ARGS) assert(c); - /* XXX: yes, these can all be dynamically-adjusted buffers, but - * it's really not worth the extra hackery. - */ - if ('\0' == buf[0]) { + if (mdoc->defos) { + mdoc->meta.os = mandoc_strdup(mdoc->defos); + return(1); + } #ifdef OSNAME if (strlcat(buf, OSNAME, BUFSIZ) >= BUFSIZ) { mdoc_nmsg(mdoc, n, MANDOCERR_MEM); @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.28 2012/02/16 20:51:31 joerg Exp $ */ +/* $Id: read.c,v 1.29 2012/05/27 17:48:57 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org> @@ -66,6 +66,7 @@ struct mparse { void *arg; /* argument to mmsg */ const char *file; struct buf *secondary; + char *defos; /* default operating system */ }; static void resize_buf(struct buf *, size_t); @@ -247,7 +248,8 @@ pset(const char *buf, int pos, struct mparse *curp) switch (curp->inttype) { case (MPARSE_MDOC): if (NULL == curp->pmdoc) - curp->pmdoc = mdoc_alloc(curp->roff, curp); + curp->pmdoc = mdoc_alloc(curp->roff, curp, + curp->defos); assert(curp->pmdoc); curp->mdoc = curp->pmdoc; return; @@ -263,7 +265,8 @@ pset(const char *buf, int pos, struct mparse *curp) if (pos >= 3 && 0 == memcmp(buf, ".Dd", 3)) { if (NULL == curp->pmdoc) - curp->pmdoc = mdoc_alloc(curp->roff, curp); + curp->pmdoc = mdoc_alloc(curp->roff, curp, + curp->defos); assert(curp->pmdoc); curp->mdoc = curp->pmdoc; return; @@ -720,7 +723,8 @@ mparse_readfd(struct mparse *curp, int fd, const char *file) } struct mparse * -mparse_alloc(enum mparset inttype, enum mandoclevel wlevel, mandocmsg mmsg, void *arg) +mparse_alloc(enum mparset inttype, enum mandoclevel wlevel, + mandocmsg mmsg, void *arg, char *defos) { struct mparse *curp; @@ -732,6 +736,7 @@ mparse_alloc(enum mparset inttype, enum mandoclevel wlevel, mandocmsg mmsg, void curp->mmsg = mmsg; curp->arg = arg; curp->inttype = inttype; + curp->defos = defos; curp->roff = roff_alloc(curp); return(curp); |