aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2015-03-27 17:37:25 +0000
committerIngo Schwarze <schwarze@openbsd.org>2015-03-27 17:37:25 +0000
commit0376f290310249f2701221cdaaf7138fae3c6989 (patch)
treeaf23aca22eb3b9d3fa8f3fe749fb6ea4ce2e9a72
parent0094b52bf5ae4780a23fccaab7adc5bf71c2c161 (diff)
downloadmandoc-0376f290310249f2701221cdaaf7138fae3c6989.tar.gz
mandoc-0376f290310249f2701221cdaaf7138fae3c6989.tar.zst
mandoc-0376f290310249f2701221cdaaf7138fae3c6989.zip
Parse the new man.conf(5) "output" directive.
The next step will be to actually use the parsed data.
-rw-r--r--Makefile6
-rw-r--r--Makefile.depend12
-rw-r--r--cgi.c8
-rw-r--r--main.c24
-rw-r--r--manconf.h51
-rw-r--r--mandoc_headers.328
-rw-r--r--mandocdb.c46
-rw-r--r--manpage.c14
-rw-r--r--manpath.c123
-rw-r--r--manpath.h34
-rw-r--r--mansearch.38
-rw-r--r--mansearch.c8
12 files changed, 221 insertions, 141 deletions
diff --git a/Makefile b/Makefile
index 8497ae1a..d2a59135 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.459 2015/03/27 00:18:14 schwarze Exp $
+# $Id: Makefile,v 1.460 2015/03/27 17:37:25 schwarze Exp $
#
# Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
# Copyright (c) 2011, 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -133,6 +133,7 @@ DISTFILES = INSTALL \
man.cgi.8 \
man.conf.5 \
man.h \
+ manconf.h \
mandoc.1 \
mandoc.3 \
mandoc.db.5 \
@@ -143,7 +144,6 @@ DISTFILES = INSTALL \
mandoc_headers.3 \
mandoc_html.3 \
mandoc_malloc.3 \
- manpath.h \
mansearch.3 \
mansearch.h \
mchars_alloc.3 \
@@ -269,9 +269,9 @@ WWW_MANS = apropos.1.html \
makewhatis.8.html \
man.cgi.8.html \
man.h.html \
+ manconf.h.html \
mandoc.h.html \
mandoc_aux.h.html \
- manpath.h.html \
mansearch.h.html \
mdoc.h.html
diff --git a/Makefile.depend b/Makefile.depend
index 54b85bb8..b0de8570 100644
--- a/Makefile.depend
+++ b/Makefile.depend
@@ -1,5 +1,5 @@
att.o: att.c config.h mdoc.h libmdoc.h
-cgi.o: cgi.c config.h mandoc.h mandoc_aux.h main.h manpath.h mansearch.h cgi.h
+cgi.o: cgi.c config.h mandoc.h mandoc_aux.h main.h manconf.h mansearch.h cgi.h
chars.o: chars.c config.h mandoc.h mandoc_aux.h libmandoc.h chars.in
compat_fgetln.o: compat_fgetln.c config.h
compat_fts.o: compat_fts.c config.h compat_fts.h
@@ -21,7 +21,7 @@ eqn_html.o: eqn_html.c config.h mandoc.h out.h html.h
eqn_term.o: eqn_term.c config.h mandoc.h out.h term.h
html.o: html.c config.h mandoc.h mandoc_aux.h out.h html.h main.h
lib.o: lib.c config.h mdoc.h libmdoc.h lib.in
-main.o: main.c config.h mandoc.h mandoc_aux.h main.h mdoc.h man.h manpath.h mansearch.h
+main.o: main.c config.h mandoc.h mandoc_aux.h main.h mdoc.h man.h manconf.h mansearch.h
man.o: man.c config.h man.h mandoc.h mandoc_aux.h libman.h libmandoc.h
man_hash.o: man_hash.c config.h man.h libman.h
man_html.o: man_html.c config.h mandoc_aux.h man.h out.h html.h main.h
@@ -30,10 +30,10 @@ man_term.o: man_term.c config.h mandoc.h mandoc_aux.h out.h man.h term.h main.h
man_validate.o: man_validate.c config.h man.h mandoc.h mandoc_aux.h libman.h libmandoc.h
mandoc.o: mandoc.c config.h mandoc.h mandoc_aux.h libmandoc.h
mandoc_aux.o: mandoc_aux.c config.h mandoc.h mandoc_aux.h
-mandocdb.o: mandocdb.c config.h compat_fts.h compat_ohash.h mdoc.h man.h mandoc.h mandoc_aux.h manpath.h mansearch.h
-manpage.o: manpage.c config.h manpath.h mansearch.h
-manpath.o: manpath.c config.h mandoc_aux.h manpath.h
-mansearch.o: mansearch.c config.h compat_ohash.h mandoc.h mandoc_aux.h manpath.h mansearch.h
+mandocdb.o: mandocdb.c config.h compat_fts.h compat_ohash.h mdoc.h man.h mandoc.h mandoc_aux.h manconf.h mansearch.h
+manpage.o: manpage.c config.h manconf.h mansearch.h
+manpath.o: manpath.c config.h mandoc_aux.h manconf.h
+mansearch.o: mansearch.c config.h compat_ohash.h mandoc.h mandoc_aux.h manconf.h mansearch.h
mansearch_const.o: mansearch_const.c config.h mansearch.h
mdoc.o: mdoc.c config.h mdoc.h mandoc.h mandoc_aux.h libmdoc.h libmandoc.h
mdoc_argv.o: mdoc_argv.c config.h mdoc.h mandoc.h mandoc_aux.h libmdoc.h libmandoc.h
diff --git a/cgi.c b/cgi.c
index 05d1b8a0..a482ffac 100644
--- a/cgi.c
+++ b/cgi.c
@@ -1,4 +1,4 @@
-/* $Id: cgi.c,v 1.104 2015/02/10 08:05:30 schwarze Exp $ */
+/* $Id: cgi.c,v 1.105 2015/03/27 17:37:25 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014 Ingo Schwarze <schwarze@usta.de>
@@ -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
@@ -33,7 +33,7 @@
#include "mandoc.h"
#include "mandoc_aux.h"
#include "main.h"
-#include "manpath.h"
+#include "manconf.h"
#include "mansearch.h"
#include "cgi.h"
diff --git a/main.c b/main.c
index 96d34887..d5d61e81 100644
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.228 2015/03/27 16:36:31 schwarze Exp $ */
+/* $Id: main.c,v 1.229 2015/03/27 17:37:25 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2012, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -8,9 +8,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
@@ -39,7 +39,7 @@
#include "main.h"
#include "mdoc.h"
#include "man.h"
-#include "manpath.h"
+#include "manconf.h"
#include "mansearch.h"
#if !defined(__GNUC__) || (__GNUC__ < 2)
@@ -118,9 +118,9 @@ static enum mandoclevel rc;
int
main(int argc, char *argv[])
{
+ struct manconf conf;
struct curparse curp;
struct mansearch search;
- struct manpaths paths;
char *auxpaths;
char *defos;
unsigned char *uc;
@@ -151,7 +151,7 @@ main(int argc, char *argv[])
/* Search options. */
- memset(&paths, 0, sizeof(struct manpaths));
+ memset(&conf, 0, sizeof(conf));
conf_file = defpaths = NULL;
auxpaths = NULL;
@@ -336,10 +336,11 @@ main(int argc, char *argv[])
/* Access the mandoc database. */
- manpath_parse(&paths, conf_file, defpaths, auxpaths);
+ manconf_parse(&conf, conf_file, defpaths, auxpaths);
#if HAVE_SQLITE3
mansearch_setup(1);
- if( ! mansearch(&search, &paths, argc, argv, &res, &sz))
+ if ( ! mansearch(&search, &conf.manpath,
+ argc, argv, &res, &sz))
usage(search.argmode);
#else
if (search.argmode != ARG_NAME) {
@@ -351,7 +352,8 @@ main(int argc, char *argv[])
#endif
if (sz == 0 && search.argmode == ARG_NAME)
- fs_search(&search, &paths, argc, argv, &res, &sz);
+ fs_search(&search, &conf.manpath,
+ argc, argv, &res, &sz);
if (sz == 0) {
rc = MANDOCLEVEL_BADARG;
@@ -439,7 +441,7 @@ main(int argc, char *argv[])
parse(&curp, fd, *argv);
else if (resp->form & FORM_SRC) {
/* For .so only; ignore failure. */
- chdir(paths.paths[resp->ipath]);
+ chdir(conf.manpath.paths[resp->ipath]);
parse(&curp, fd, resp->file);
} else
passthrough(resp->file, fd, synopsis_only);
@@ -470,7 +472,7 @@ main(int argc, char *argv[])
out:
if (search.argmode != ARG_FILE) {
- manpath_free(&paths);
+ manconf_free(&conf);
#if HAVE_SQLITE3
mansearch_free(res, sz);
mansearch_setup(0);
diff --git a/manconf.h b/manconf.h
new file mode 100644
index 00000000..0784b8d6
--- /dev/null
+++ b/manconf.h
@@ -0,0 +1,51 @@
+/* $OpenBSD$ */
+/*
+ * Copyright (c) 2011, 2015 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2011 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
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * 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 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
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* List of unique, absolute paths to manual trees. */
+
+struct manpaths {
+ char **paths;
+ size_t sz;
+};
+
+/* Data from -O options and man.conf(5) output directives. */
+
+struct manoutput {
+ char *includes;
+ char *man;
+ char *paper;
+ char *style;
+ size_t indent;
+ size_t width;
+ int fragment;
+ int mdoc;
+ int synopsisonly;
+};
+
+struct manconf {
+ struct manoutput output;
+ struct manpaths manpath;
+};
+
+__BEGIN_DECLS
+
+void manconf_parse(struct manconf *, const char *, char *, char *);
+void manconf_output(struct manoutput *, const char *);
+void manconf_free(struct manconf *);
+
+__END_DECLS
diff --git a/mandoc_headers.3 b/mandoc_headers.3
index 79d90fff..12879ea6 100644
--- a/mandoc_headers.3
+++ b/mandoc_headers.3
@@ -366,8 +366,6 @@ from
as an opaque type for function prototypes.
.Pp
When this header is included, the same file should not include
-.Pa manpath.h
-or
.Pa mansearch.h .
.It Qq Pa term.h
Requires
@@ -406,8 +404,7 @@ from
as opaque types for function prototypes.
.Pp
When this header is included, the same file should not include
-.Pa html.h ,
-.Pa manpath.h
+.Pa html.h
or
.Pa mansearch.h .
.It Qq Pa html.h
@@ -441,8 +438,7 @@ from
.Pa chars.c .
.Pp
When this header is included, the same file should not include
-.Pa term.h ,
-.Pa manpath.h
+.Pa term.h
or
.Pa mansearch.h .
.It Qq Pa main.h
@@ -461,25 +457,21 @@ and
from
.Pa libman.h
as opaque types for function prototypes.
-.It Qq Pa manpath.h
+.It Qq Pa manconf.h
Requires
.In sys/types.h
for
.Vt size_t .
.Pp
Provides
-.Vt struct manpaths
+.Vt struct manconf ,
+.Vt struct manpaths ,
+.Vt struct manoutput ,
and the functions
-.Fn manpath_manconf ,
-.Fn manpath_parse ,
+.Fn manconf_parse ,
+.Fn manconf_output ,
and
-.Fn manpath_free .
-.Pp
-When this header is included, the same file should not include
-.Pa out.h ,
-.Pa term.h ,
-or
-.Pa html.h .
+.Fn manconf_free .
.It Qq Pa mansearch.h
Requires
.In sys/types.h
@@ -503,7 +495,7 @@ and
Uses
.Vt struct manpaths
from
-.Pa manpath.h
+.Pa manconf.h
as an opaque type for function prototypes.
.Pp
When this header is included, the same file should not include
diff --git a/mandocdb.c b/mandocdb.c
index fed11e9f..a0b87750 100644
--- a/mandocdb.c
+++ b/mandocdb.c
@@ -1,4 +1,4 @@
-/* $Id: mandocdb.c,v 1.186 2015/03/13 00:19:41 schwarze Exp $ */
+/* $Id: mandocdb.c,v 1.187 2015/03/27 17:37:25 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 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
@@ -50,7 +50,7 @@
#include "man.h"
#include "mandoc.h"
#include "mandoc_aux.h"
-#include "manpath.h"
+#include "manconf.h"
#include "mansearch.h"
extern int mansearch_keymax;
@@ -338,15 +338,15 @@ static const struct mdoc_handler mdocs[MDOC_MAX] = {
int
mandocdb(int argc, char *argv[])
{
- int ch, i;
- size_t j, sz;
- const char *path_arg;
- struct manpaths dirs;
- struct mparse *mp;
+ struct manconf conf;
struct ohash_info mpages_info, mlinks_info;
+ struct mparse *mp;
+ const char *path_arg;
+ size_t j, sz;
+ int ch, i;
+ memset(&conf, 0, sizeof(conf));
memset(stmts, 0, STMT__MAX * sizeof(sqlite3_stmt *));
- memset(&dirs, 0, sizeof(struct manpaths));
mpages_info.alloc = mlinks_info.alloc = hash_alloc;
mpages_info.calloc = mlinks_info.calloc = hash_calloc;
@@ -485,18 +485,18 @@ mandocdb(int argc, char *argv[])
/*
* If we have arguments, use them as our manpaths.
* If we don't, grok from manpath(1) or however else
- * manpath_parse() wants to do it.
+ * manconf_parse() wants to do it.
*/
if (argc > 0) {
- dirs.paths = mandoc_reallocarray(NULL,
+ conf.manpath.paths = mandoc_reallocarray(NULL,
argc, sizeof(char *));
- dirs.sz = (size_t)argc;
+ conf.manpath.sz = (size_t)argc;
for (i = 0; i < argc; i++)
- dirs.paths[i] = mandoc_strdup(argv[i]);
+ conf.manpath.paths[i] = mandoc_strdup(argv[i]);
} else
- manpath_parse(&dirs, path_arg, NULL, NULL);
+ manconf_parse(&conf, path_arg, NULL, NULL);
- if (0 == dirs.sz) {
+ if (conf.manpath.sz == 0) {
exitcode = (int)MANDOCLEVEL_BADARG;
say("", "Empty manpath");
}
@@ -507,10 +507,10 @@ mandocdb(int argc, char *argv[])
* Ignore zero-length directories and strip trailing
* slashes.
*/
- for (j = 0; j < dirs.sz; j++) {
- sz = strlen(dirs.paths[j]);
- if (sz && '/' == dirs.paths[j][sz - 1])
- dirs.paths[j][--sz] = '\0';
+ for (j = 0; j < conf.manpath.sz; j++) {
+ sz = strlen(conf.manpath.paths[j]);
+ if (sz && conf.manpath.paths[j][sz - 1] == '/')
+ conf.manpath.paths[j][--sz] = '\0';
if (0 == sz)
continue;
@@ -519,7 +519,7 @@ mandocdb(int argc, char *argv[])
ohash_init(&mlinks, 6, &mlinks_info);
}
- if (0 == set_basedir(dirs.paths[j], argc > 0))
+ if ( ! set_basedir(conf.manpath.paths[j], argc > 0))
continue;
if (0 == treescan())
continue;
@@ -532,7 +532,7 @@ mandocdb(int argc, char *argv[])
names_check();
dbclose(0);
- if (j + 1 < dirs.sz) {
+ if (j + 1 < conf.manpath.sz) {
mpages_free();
ohash_delete(&mpages);
ohash_delete(&mlinks);
@@ -540,7 +540,7 @@ mandocdb(int argc, char *argv[])
}
}
out:
- manpath_free(&dirs);
+ manconf_free(&conf);
mparse_free(mp);
mchars_free(mchars);
mpages_free();
diff --git a/manpage.c b/manpage.c
index 999f3d32..dda6089c 100644
--- a/manpage.c
+++ b/manpage.c
@@ -1,4 +1,4 @@
-/* $Id: manpage.c,v 1.10 2015/02/10 08:05:30 schwarze Exp $ */
+/* $Id: manpage.c,v 1.11 2015/03/27 17:37:25 schwarze Exp $ */
/*
* Copyright (c) 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013 Ingo Schwarze <schwarze@openbsd.org>
@@ -28,7 +28,7 @@
#include <string.h>
#include <unistd.h>
-#include "manpath.h"
+#include "manconf.h"
#include "mansearch.h"
static void show(const char *, const char *);
@@ -43,7 +43,7 @@ main(int argc, char *argv[])
char *conf_file, *defpaths, *auxpaths, *cp;
char buf[PATH_MAX];
const char *cmd;
- struct manpaths paths;
+ struct manconf conf;
char *progname;
extern char *optarg;
extern int optind;
@@ -57,7 +57,7 @@ main(int argc, char *argv[])
++progname;
auxpaths = defpaths = conf_file = NULL;
- memset(&paths, 0, sizeof(struct manpaths));
+ memset(&conf, 0, sizeof(conf));
memset(&search, 0, sizeof(struct mansearch));
while (-1 != (ch = getopt(argc, argv, "C:M:m:S:s:")))
@@ -90,9 +90,9 @@ main(int argc, char *argv[])
search.outkey = "Nd";
search.argmode = ARG_EXPR;
- manpath_parse(&paths, conf_file, defpaths, auxpaths);
- ch = mansearch(&search, &paths, argc, argv, &res, &sz);
- manpath_free(&paths);
+ manconf_parse(&conf, conf_file, defpaths, auxpaths);
+ ch = mansearch(&search, &conf.manpath, argc, argv, &res, &sz);
+ manconf_free(&conf);
if (0 == ch)
goto usage;
diff --git a/manpath.c b/manpath.c
index 5ff2d319..e7451597 100644
--- a/manpath.c
+++ b/manpath.c
@@ -1,4 +1,4 @@
-/* $Id: manpath.c,v 1.22 2015/03/26 22:42:32 schwarze Exp $ */
+/* $Id: manpath.c,v 1.23 2015/03/27 17:37:25 schwarze Exp $ */
/*
* Copyright (c) 2011, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -27,15 +27,15 @@
#include <string.h>
#include "mandoc_aux.h"
-#include "manpath.h"
-
-#define MAN_CONF_FILE "/etc/man.conf"
+#include "manconf.h"
+static void manconf_file(struct manconf *, const char *);
static void manpath_add(struct manpaths *, const char *, int);
static void manpath_parseline(struct manpaths *, char *, int);
+
void
-manpath_parse(struct manpaths *dirs, const char *file,
+manconf_parse(struct manconf *conf, const char *file,
char *defp, char *auxp)
{
#if HAVE_MANPATH
@@ -88,11 +88,11 @@ manpath_parse(struct manpaths *dirs, const char *file,
char *insert;
/* Always prepend -m. */
- manpath_parseline(dirs, auxp, 1);
+ manpath_parseline(&conf->manpath, auxp, 1);
/* If -M is given, it overrides everything else. */
if (NULL != defp) {
- manpath_parseline(dirs, defp, 1);
+ manpath_parseline(&conf->manpath, defp, 1);
return;
}
@@ -103,23 +103,23 @@ manpath_parse(struct manpaths *dirs, const char *file,
/* No MANPATH; use man.conf(5) only. */
if (NULL == defp || '\0' == defp[0]) {
- manpath_manconf(dirs, file);
- if (dirs->sz == 0)
- manpath_parseline(dirs, manpath_default, 0);
+ manconf_file(conf, file);
+ if (conf->manpath.sz == 0)
+ manpath_parseline(&conf->manpath, manpath_default, 0);
return;
}
/* Prepend man.conf(5) to MANPATH. */
if (':' == defp[0]) {
- manpath_manconf(dirs, file);
- manpath_parseline(dirs, defp, 0);
+ manconf_file(conf, file);
+ manpath_parseline(&conf->manpath, defp, 0);
return;
}
/* Append man.conf(5) to MANPATH. */
if (':' == defp[strlen(defp) - 1]) {
- manpath_parseline(dirs, defp, 0);
- manpath_manconf(dirs, file);
+ manpath_parseline(&conf->manpath, defp, 0);
+ manconf_file(conf, file);
return;
}
@@ -127,14 +127,14 @@ manpath_parse(struct manpaths *dirs, const char *file,
insert = strstr(defp, "::");
if (NULL != insert) {
*insert++ = '\0';
- manpath_parseline(dirs, defp, 0);
- manpath_manconf(dirs, file);
- manpath_parseline(dirs, insert + 1, 0);
+ manpath_parseline(&conf->manpath, defp, 0);
+ manconf_file(conf, file);
+ manpath_parseline(&conf->manpath, insert + 1, 0);
return;
}
/* MANPATH overrides man.conf(5) completely. */
- manpath_parseline(dirs, defp, 0);
+ manpath_parseline(&conf->manpath, defp, 0);
#endif
}
@@ -192,20 +192,24 @@ manpath_add(struct manpaths *dirs, const char *dir, int complain)
}
void
-manpath_free(struct manpaths *p)
+manconf_free(struct manconf *conf)
{
size_t i;
- for (i = 0; i < p->sz; i++)
- free(p->paths[i]);
+ for (i = 0; i < conf->manpath.sz; i++)
+ free(conf->manpath.paths[i]);
- free(p->paths);
+ free(conf->manpath.paths);
+ free(conf->output.includes);
+ free(conf->output.man);
+ free(conf->output.paper);
+ free(conf->output.style);
}
-void
-manpath_manconf(struct manpaths *dirs, const char *file)
+static void
+manconf_file(struct manconf *conf, const char *file)
{
- const char *const toks[] = { "manpath", "_whatdb" };
+ const char *const toks[] = { "manpath", "output", "_whatdb" };
FILE *stream;
char *cp, *ep;
@@ -237,7 +241,7 @@ manpath_manconf(struct manpaths *dirs, const char *file)
}
switch (tok) {
- case 1: /* _whatdb */
+ case 2: /* _whatdb */
while (ep > cp && ep[-1] != '/')
ep--;
if (ep == cp)
@@ -245,7 +249,10 @@ manpath_manconf(struct manpaths *dirs, const char *file)
*ep = '\0';
/* FALLTHROUGH */
case 0: /* manpath */
- manpath_add(dirs, cp, 0);
+ manpath_add(&conf->manpath, cp, 0);
+ break;
+ case 1: /* output */
+ manconf_output(&conf->output, cp);
break;
default:
break;
@@ -254,3 +261,65 @@ manpath_manconf(struct manpaths *dirs, const char *file)
fclose(stream);
}
+
+void
+manconf_output(struct manoutput *conf, const char *cp)
+{
+ const char *const toks[] = {
+ "includes", "man", "paper", "style",
+ "indent", "width", "fragment", "mdoc"
+ };
+
+ size_t len, tok;
+
+ for (tok = 0; tok < sizeof(toks)/sizeof(toks[0]); tok++) {
+ len = strlen(toks[tok]);
+ if ( ! strncmp(cp, toks[tok], len) &&
+ strchr(" = ", cp[len]) != NULL) {
+ cp += len;
+ if (*cp == '=')
+ cp++;
+ while (isspace((unsigned char)*cp))
+ cp++;
+ break;
+ }
+ }
+
+ if (tok < 6 && *cp == '\0')
+ return;
+
+ switch (tok) {
+ case 0:
+ if (conf->includes == NULL)
+ conf->includes = mandoc_strdup(cp);
+ break;
+ case 1:
+ if (conf->man == NULL)
+ conf->man = mandoc_strdup(cp);
+ break;
+ case 2:
+ if (conf->paper == NULL)
+ conf->paper = mandoc_strdup(cp);
+ break;
+ case 3:
+ if (conf->style == NULL)
+ conf->style = mandoc_strdup(cp);
+ break;
+ case 4:
+ if (conf->indent == 0)
+ conf->indent = strtonum(cp, 0, 1000, NULL);
+ break;
+ case 5:
+ if (conf->width == 0)
+ conf->width = strtonum(cp, 58, 1000, NULL);
+ break;
+ case 6:
+ conf->fragment = 1;
+ break;
+ case 7:
+ conf->mdoc = 1;
+ break;
+ default:
+ break;
+ }
+}
diff --git a/manpath.h b/manpath.h
deleted file mode 100644
index 728373b2..00000000
--- a/manpath.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/* $Id: manpath.h,v 1.7 2014/12/01 04:05:32 schwarze Exp $ */
-/*
- * Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
- * Copyright (c) 2011 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
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-/*
- * Unsorted list of unique, absolute paths to be searched for manual
- * databases.
- */
-struct manpaths {
- size_t sz;
- char **paths;
-};
-
-__BEGIN_DECLS
-
-void manpath_manconf(struct manpaths *, const char *);
-void manpath_parse(struct manpaths *, const char *, char *, char *);
-void manpath_free(struct manpaths *);
-
-__END_DECLS
diff --git a/mansearch.3 b/mansearch.3
index f41e3617..051f9aa2 100644
--- a/mansearch.3
+++ b/mansearch.3
@@ -1,4 +1,4 @@
-.\" $Id: mansearch.3,v 1.3 2014/12/12 21:44:33 schwarze Exp $
+.\" $Id: mansearch.3,v 1.4 2015/03/27 17:37:25 schwarze Exp $
.\"
.\" Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
.\"
@@ -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: December 12 2014 $
+.Dd $Mdocdate: March 27 2015 $
.Dt MANSEARCH 3
.Os
.Sh NAME
@@ -23,7 +23,7 @@
.Nd search manual page databases
.Sh SYNOPSIS
.In stdint.h
-.In manpath.h
+.In manconf.h
.In mansearch.h
.Ft int
.Fo mansearch_setup
@@ -53,7 +53,7 @@ Search options, defined in
.In mansearch.h .
.It Fa "const struct manpaths *paths"
Directories to be searched, defined in
-.In manpath.h .
+.In manconf.h .
.It Fa "int argc" , "char *argv[]"
Search criteria, usually taken from the command line.
.El
diff --git a/mansearch.c b/mansearch.c
index 05e2a0a2..af103963 100644
--- a/mansearch.c
+++ b/mansearch.c
@@ -1,4 +1,4 @@
-/* $Id: mansearch.c,v 1.55 2015/03/11 13:11:22 schwarze Exp $ */
+/* $Id: mansearch.c,v 1.56 2015/03/27 17:37:25 schwarze Exp $ */
/*
* Copyright (c) 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013, 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
@@ -46,7 +46,7 @@
#include "mandoc.h"
#include "mandoc_aux.h"
-#include "manpath.h"
+#include "manconf.h"
#include "mansearch.h"
extern int mansearch_keymax;