aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2015-03-27 21:33:20 +0000
committerIngo Schwarze <schwarze@openbsd.org>2015-03-27 21:33:20 +0000
commit3a566c6001cb69c071c16b210bbb84009ab1b662 (patch)
tree1623a89f3236c216a580acbede0a3b507c822c9d
parent0376f290310249f2701221cdaaf7138fae3c6989 (diff)
downloadmandoc-3a566c6001cb69c071c16b210bbb84009ab1b662.tar.gz
mandoc-3a566c6001cb69c071c16b210bbb84009ab1b662.tar.zst
mandoc-3a566c6001cb69c071c16b210bbb84009ab1b662.zip
Actually use the new man.conf(5) "output" directive.
Additional functionality, yet minus 45 lines of code.
-rw-r--r--cgi.c15
-rw-r--r--html.c39
-rw-r--r--main.c19
-rw-r--r--main.h27
-rw-r--r--man.conf.522
-rw-r--r--term_ascii.c71
-rw-r--r--term_ps.c33
7 files changed, 98 insertions, 128 deletions
diff --git a/cgi.c b/cgi.c
index a482ffac..402be8f9 100644
--- a/cgi.c
+++ b/cgi.c
@@ -1,7 +1,7 @@
-/* $Id: cgi.c,v 1.105 2015/03/27 17:37:25 schwarze Exp $ */
+/* $Id: cgi.c,v 1.106 2015/03/27 21:33:20 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2014 Ingo Schwarze <schwarze@usta.de>
+ * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@usta.de>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -816,12 +816,12 @@ catman(const struct req *req, const char *file)
static void
format(const struct req *req, const char *file)
{
+ struct manoutput conf;
struct mparse *mp;
struct mchars *mchars;
struct mdoc *mdoc;
struct man *man;
void *vp;
- char *opts;
int fd;
int usepath;
@@ -836,9 +836,10 @@ format(const struct req *req, const char *file)
mparse_readfd(mp, fd, file);
close(fd);
+ memset(&conf, 0, sizeof(conf));
+ conf.fragment = 1;
usepath = strcmp(req->q.manpath, req->p[0]);
- mandoc_asprintf(&opts,
- "fragment,man=%s?query=%%N&sec=%%S%s%s%s%s",
+ mandoc_asprintf(&conf.man, "%s?query=%%N&sec=%%S%s%s%s%s",
scriptname,
req->q.arch ? "&arch=" : "",
req->q.arch ? req->q.arch : "",
@@ -855,7 +856,7 @@ format(const struct req *req, const char *file)
return;
}
- vp = html_alloc(mchars, opts);
+ vp = html_alloc(mchars, &conf);
if (NULL != mdoc)
html_mdoc(vp, mdoc);
@@ -865,7 +866,7 @@ format(const struct req *req, const char *file)
html_free(vp);
mparse_free(mp);
mchars_free(mchars);
- free(opts);
+ free(conf.man);
}
static void
diff --git a/html.c b/html.c
index 487dacda..8adf00d1 100644
--- a/html.c
+++ b/html.c
@@ -1,4 +1,4 @@
-/* $Id: html.c,v 1.185 2015/01/21 20:33:25 schwarze Exp $ */
+/* $Id: html.c,v 1.186 2015/03/27 21:33:20 schwarze Exp $ */
/*
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011-2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -7,9 +7,9 @@
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
@@ -32,6 +32,7 @@
#include "mandoc_aux.h"
#include "out.h"
#include "html.h"
+#include "manconf.h"
#include "main.h"
struct htmldata {
@@ -129,40 +130,20 @@ static void print_attr(struct html *, const char *, const char *);
void *
-html_alloc(const struct mchars *mchars, char *outopts)
+html_alloc(const struct mchars *mchars, const struct manoutput *outopts)
{
struct html *h;
- const char *toks[5];
- char *v;
-
- toks[0] = "style";
- toks[1] = "man";
- toks[2] = "includes";
- toks[3] = "fragment";
- toks[4] = NULL;
h = mandoc_calloc(1, sizeof(struct html));
h->tags.head = NULL;
h->symtab = mchars;
- while (outopts && *outopts)
- switch (getsubopt(&outopts, UNCONST(toks), &v)) {
- case 0:
- h->style = v;
- break;
- case 1:
- h->base_man = v;
- break;
- case 2:
- h->base_includes = v;
- break;
- case 3:
- h->oflags |= HTML_FRAGMENT;
- break;
- default:
- break;
- }
+ h->style = outopts->style;
+ h->base_man = outopts->man;
+ h->base_includes = outopts->includes;
+ if (outopts->fragment)
+ h->oflags |= HTML_FRAGMENT;
return(h);
}
diff --git a/main.c b/main.c
index d5d61e81..2c365f71 100644
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.229 2015/03/27 17:37:25 schwarze Exp $ */
+/* $Id: main.c,v 1.230 2015/03/27 21:33:20 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2012, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -83,7 +83,7 @@ struct curparse {
out_man outman; /* man output ptr */
out_free outfree; /* free output ptr */
void *outdata; /* data for output */
- char outopts[BUFSIZ]; /* buf of output opts */
+ struct manoutput *outopts; /* output options */
};
static int fs_lookup(const struct manpaths *,
@@ -127,7 +127,7 @@ main(int argc, char *argv[])
struct manpage *res, *resp;
char *conf_file, *defpaths;
size_t isec, i, sz;
- int prio, best_prio, synopsis_only;
+ int prio, best_prio;
char sec;
enum mandoclevel rctmp;
enum outmode outmode;
@@ -174,12 +174,12 @@ main(int argc, char *argv[])
memset(&curp, 0, sizeof(struct curparse));
curp.outtype = OUTT_LOCALE;
curp.wlevel = MANDOCLEVEL_BADARG;
+ curp.outopts = &conf.output;
options = MPARSE_SO | MPARSE_UTF8 | MPARSE_LATIN1;
defos = NULL;
pager_pid = 1;
show_usage = 0;
- synopsis_only = 0;
outmode = OUTMODE_DEF;
while (-1 != (c = getopt(argc, argv,
@@ -198,8 +198,7 @@ main(int argc, char *argv[])
search.argmode = ARG_WORD;
break;
case 'h':
- (void)strlcat(curp.outopts, "synopsis,", BUFSIZ);
- synopsis_only = 1;
+ conf.output.synopsisonly = 1;
pager_pid = 0;
outmode = OUTMODE_ALL;
break;
@@ -240,8 +239,9 @@ main(int argc, char *argv[])
break;
case 'O':
search.outkey = optarg;
- (void)strlcat(curp.outopts, optarg, BUFSIZ);
- (void)strlcat(curp.outopts, ",", BUFSIZ);
+ while (optarg != NULL)
+ manconf_output(&conf.output,
+ strsep(&optarg, ","));
break;
case 'S':
search.arch = optarg;
@@ -444,7 +444,8 @@ main(int argc, char *argv[])
chdir(conf.manpath.paths[resp->ipath]);
parse(&curp, fd, resp->file);
} else
- passthrough(resp->file, fd, synopsis_only);
+ passthrough(resp->file, fd,
+ conf.output.synopsisonly);
rctmp = mparse_wait(curp.mp);
if (rc < rctmp)
diff --git a/main.h b/main.h
index 9b04a781..60065e5f 100644
--- a/main.h
+++ b/main.h
@@ -1,15 +1,15 @@
-/* $Id: main.h,v 1.20 2014/12/31 16:52:40 schwarze Exp $ */
+/* $Id: main.h,v 1.21 2015/03/27 21:33:20 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2014, 2015 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
* copyright notice and this permission notice appear in all copies.
*
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
@@ -23,6 +23,7 @@ __BEGIN_DECLS
struct mchars;
struct mdoc;
struct man;
+struct manoutput;
/*
* Definitions for main.c-visible output device functions, e.g., -Thtml
@@ -31,7 +32,8 @@ struct man;
* terminal output routines with different character settings.
*/
-void *html_alloc(const struct mchars *, char *);
+void *html_alloc(const struct mchars *,
+ const struct manoutput *);
void html_mdoc(void *, const struct mdoc *);
void html_man(void *, const struct man *);
void html_free(void *);
@@ -42,14 +44,19 @@ void tree_man(void *, const struct man *);
void man_mdoc(void *, const struct mdoc *);
void man_man(void *, const struct man *);
-void *locale_alloc(const struct mchars *, char *);
-void *utf8_alloc(const struct mchars *, char *);
-void *ascii_alloc(const struct mchars *, char *);
+void *locale_alloc(const struct mchars *,
+ const struct manoutput *);
+void *utf8_alloc(const struct mchars *,
+ const struct manoutput *);
+void *ascii_alloc(const struct mchars *,
+ const struct manoutput *);
void ascii_free(void *);
void ascii_sepline(void *);
-void *pdf_alloc(const struct mchars *, char *);
-void *ps_alloc(const struct mchars *, char *);
+void *pdf_alloc(const struct mchars *,
+ const struct manoutput *);
+void *ps_alloc(const struct mchars *,
+ const struct manoutput *);
void pspdf_free(void *);
void terminal_mdoc(void *, const struct mdoc *);
diff --git a/man.conf.5 b/man.conf.5
index 88fc9ebd..9cfeca76 100644
--- a/man.conf.5
+++ b/man.conf.5
@@ -1,4 +1,4 @@
-.\" $Id: man.conf.5,v 1.2 2015/03/27 16:28:55 schwarze Exp $
+.\" $Id: man.conf.5,v 1.3 2015/03/27 21:33:20 schwarze Exp $
.\"
.\" Copyright (c) 2015 Ingo Schwarze <schwarze@openbsd.org>
.\"
@@ -76,6 +76,26 @@ is recommended and necessary for
.Xr apropos 1
to work, but not strictly required for
.Xr man 1 .
+.It Ic output Ar option Op Ar value
+Configure the default value of an output option.
+These directives are overridden by the
+.Fl O
+command line options of the same names.
+For details, see the
+.Xr mandoc 1
+manual.
+.Pp
+.Bl -column fragment integer "ascii, utf8" -compact
+.It Ar option Ta Ar value Ta used by Fl T Ta purpose
+.It Ta Ta Ta
+.It Ic fragment Ta none Ta Cm html Ta print only body
+.It Ic includes Ta string Ta Cm html Ta path to header files
+.It Ic indent Ta integer Ta Cm ascii , utf8 Ta left margin
+.It Ic man Ta string Ta Cm html Ta path for Xr links
+.It Ic paper Ta string Ta Cm ps , pdf Ta paper size
+.It Ic style Ta string Ta Cm html Ta CSS file
+.It Ic width Ta integer Ta Cm ascii , utf8 Ta right margin
+.El
.It Ic _whatdb Ar path Ns Cm /whatis.db
This directive provides the same functionality as
.Ic manpath ,
diff --git a/term_ascii.c b/term_ascii.c
index 4ce4b686..f217b9a4 100644
--- a/term_ascii.c
+++ b/term_ascii.c
@@ -1,15 +1,15 @@
-/* $Id: term_ascii.c,v 1.43 2015/02/16 14:11:41 schwarze Exp $ */
+/* $Id: term_ascii.c,v 1.44 2015/03/27 21:33:20 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2014, 2015 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
* copyright notice and this permission notice appear in all copies.
*
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
@@ -35,10 +35,11 @@
#include "mandoc_aux.h"
#include "out.h"
#include "term.h"
+#include "manconf.h"
#include "main.h"
-static struct termp *ascii_init(enum termenc,
- const struct mchars *, char *);
+static struct termp *ascii_init(enum termenc, const struct mchars *,
+ const struct manoutput *);
static double ascii_hspan(const struct termp *,
const struct roffsu *);
static size_t ascii_width(const struct termp *, int);
@@ -58,13 +59,11 @@ static size_t locale_width(const struct termp *, int);
static struct termp *
-ascii_init(enum termenc enc, const struct mchars *mchars, char *outopts)
+ascii_init(enum termenc enc, const struct mchars *mchars,
+ const struct manoutput *outopts)
{
- const char *toks[5];
char *v;
struct termp *p;
- const char *errstr;
- int num;
p = mandoc_calloc(1, sizeof(struct termp));
@@ -102,62 +101,36 @@ ascii_init(enum termenc enc, const struct mchars *mchars, char *outopts)
}
#endif
- toks[0] = "indent";
- toks[1] = "width";
- toks[2] = "mdoc";
- toks[3] = "synopsis";
- toks[4] = NULL;
-
- while (outopts && *outopts)
- switch (getsubopt(&outopts, UNCONST(toks), &v)) {
- case 0:
- num = strtonum(v, 0, 1000, &errstr);
- if (!errstr)
- p->defindent = num;
- break;
- case 1:
- num = strtonum(v, 0, 1000, &errstr);
- if (!errstr)
- p->defrmargin = num;
- break;
- case 2:
- /*
- * Temporary, undocumented mode
- * to imitate mdoc(7) output style.
- */
- p->mdocstyle = 1;
- p->defindent = 5;
- break;
- case 3:
- p->synopsisonly = 1;
- break;
- default:
- break;
- }
-
- /* Enforce a lower boundary. */
- if (p->defrmargin < 58)
- p->defrmargin = 58;
+ if (outopts->mdoc) {
+ p->mdocstyle = 1;
+ p->defindent = 5;
+ }
+ if (outopts->indent)
+ p->defindent = outopts->indent;
+ if (outopts->width)
+ p->defrmargin = outopts->width;
+ if (outopts->synopsisonly)
+ p->synopsisonly = 1;
return(p);
}
void *
-ascii_alloc(const struct mchars *mchars, char *outopts)
+ascii_alloc(const struct mchars *mchars, const struct manoutput *outopts)
{
return(ascii_init(TERMENC_ASCII, mchars, outopts));
}
void *
-utf8_alloc(const struct mchars *mchars, char *outopts)
+utf8_alloc(const struct mchars *mchars, const struct manoutput *outopts)
{
return(ascii_init(TERMENC_UTF8, mchars, outopts));
}
void *
-locale_alloc(const struct mchars *mchars, char *outopts)
+locale_alloc(const struct mchars *mchars, const struct manoutput *outopts)
{
return(ascii_init(TERMENC_LOCALE, mchars, outopts));
diff --git a/term_ps.c b/term_ps.c
index 12ca7d67..961de1b0 100644
--- a/term_ps.c
+++ b/term_ps.c
@@ -1,4 +1,4 @@
-/* $Id: term_ps.c,v 1.72 2015/01/21 19:40:54 schwarze Exp $ */
+/* $Id: term_ps.c,v 1.73 2015/03/27 21:33:20 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -7,9 +7,9 @@
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
@@ -30,6 +30,7 @@
#include "mandoc_aux.h"
#include "out.h"
#include "term.h"
+#include "manconf.h"
#include "main.h"
/* These work the buffer used by the header and footer. */
@@ -106,7 +107,8 @@ static void ps_printf(struct termp *, const char *, ...);
static void ps_putchar(struct termp *, char);
static void ps_setfont(struct termp *, enum termfont);
static void ps_setwidth(struct termp *, int, size_t);
-static struct termp *pspdf_alloc(const struct mchars *, char *);
+static struct termp *pspdf_alloc(const struct mchars *,
+ const struct manoutput *);
static void pdf_obj(struct termp *, size_t);
/*
@@ -507,7 +509,7 @@ static const struct font fonts[TERMFONT__MAX] = {
};
void *
-pdf_alloc(const struct mchars *mchars, char *outopts)
+pdf_alloc(const struct mchars *mchars, const struct manoutput *outopts)
{
struct termp *p;
@@ -518,7 +520,7 @@ pdf_alloc(const struct mchars *mchars, char *outopts)
}
void *
-ps_alloc(const struct mchars *mchars, char *outopts)
+ps_alloc(const struct mchars *mchars, const struct manoutput *outopts)
{
struct termp *p;
@@ -529,14 +531,12 @@ ps_alloc(const struct mchars *mchars, char *outopts)
}
static struct termp *
-pspdf_alloc(const struct mchars *mchars, char *outopts)
+pspdf_alloc(const struct mchars *mchars, const struct manoutput *outopts)
{
struct termp *p;
unsigned int pagex, pagey;
size_t marginx, marginy, lineheight;
- const char *toks[2];
const char *pp;
- char *v;
p = mandoc_calloc(1, sizeof(struct termp));
p->symtab = mchars;
@@ -555,20 +555,6 @@ pspdf_alloc(const struct mchars *mchars, char *outopts)
p->setwidth = ps_setwidth;
p->width = ps_width;
- toks[0] = "paper";
- toks[1] = NULL;
-
- pp = NULL;
-
- while (outopts && *outopts)
- switch (getsubopt(&outopts, UNCONST(toks), &v)) {
- case 0:
- pp = v;
- break;
- default:
- break;
- }
-
/* Default to US letter (millimetres). */
pagex = 216;
@@ -581,6 +567,7 @@ pspdf_alloc(const struct mchars *mchars, char *outopts)
* only happens once, I'm not terribly concerned.
*/
+ pp = outopts->paper;
if (pp && strcasecmp(pp, "letter")) {
if (0 == strcasecmp(pp, "a3")) {
pagex = 297;