From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from localhost (fantadrom.bsd.lv [local]); by fantadrom.bsd.lv (OpenSMTPD) with ESMTPA id 52ada078; for ; Fri, 27 Mar 2015 12:37:56 -0500 (EST) Date: Fri, 27 Mar 2015 12:37:56 -0500 (EST) Message-Id: <13717811938939411435.enqueue@fantadrom.bsd.lv> X-Mailinglist: mdocml-source Reply-To: source@mdocml.bsd.lv MIME-Version: 1.0 From: schwarze@mdocml.bsd.lv To: source@mdocml.bsd.lv Subject: mdocml: Parse the new man.conf(5) "output" directive. X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- Parse the new man.conf(5) "output" directive. The next step will be to actually use the parsed data. Modified Files: -------------- mdocml: Makefile Makefile.depend cgi.c main.c mandoc_headers.3 mandocdb.c manpage.c manpath.c mansearch.3 mansearch.c Added Files: ----------- mdocml: manconf.h Removed Files: ------------- mdocml: manpath.h Revision Data ------------- Index: mansearch.c =================================================================== RCS file: /home/cvs/mdocml/mdocml/mansearch.c,v retrieving revision 1.55 retrieving revision 1.56 diff -Lmansearch.c -Lmansearch.c -u -p -r1.55 -r1.56 --- mansearch.c +++ mansearch.c @@ -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; Index: cgi.c =================================================================== RCS file: /home/cvs/mdocml/mdocml/cgi.c,v retrieving revision 1.104 retrieving revision 1.105 diff -Lcgi.c -Lcgi.c -u -p -r1.104 -r1.105 --- cgi.c +++ cgi.c @@ -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" --- /dev/null +++ manconf.h @@ -0,0 +1,51 @@ +/* $OpenBSD$ */ +/* + * Copyright (c) 2011, 2015 Ingo Schwarze + * Copyright (c) 2011 Kristaps Dzonsons + * + * 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 Index: mandocdb.c =================================================================== RCS file: /home/cvs/mdocml/mdocml/mandocdb.c,v retrieving revision 1.186 retrieving revision 1.187 diff -Lmandocdb.c -Lmandocdb.c -u -p -r1.186 -r1.187 --- mandocdb.c +++ mandocdb.c @@ -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[M 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(); Index: mandoc_headers.3 =================================================================== RCS file: /home/cvs/mdocml/mdocml/mandoc_headers.3,v retrieving revision 1.2 retrieving revision 1.3 diff -Lmandoc_headers.3 -Lmandoc_headers.3 -u -p -r1.2 -r1.3 --- mandoc_headers.3 +++ 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 Index: manpage.c =================================================================== RCS file: /home/cvs/mdocml/mdocml/manpage.c,v retrieving revision 1.10 retrieving revision 1.11 diff -Lmanpage.c -Lmanpage.c -u -p -r1.10 -r1.11 --- manpage.c +++ manpage.c @@ -28,7 +28,7 @@ #include #include -#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; Index: mansearch.3 =================================================================== RCS file: /home/cvs/mdocml/mdocml/mansearch.3,v retrieving revision 1.3 retrieving revision 1.4 diff -Lmansearch.3 -Lmansearch.3 -u -p -r1.3 -r1.4 --- mansearch.3 +++ mansearch.3 @@ -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 Index: Makefile.depend =================================================================== RCS file: /home/cvs/mdocml/mdocml/Makefile.depend,v retrieving revision 1.9 retrieving revision 1.10 diff -LMakefile.depend -LMakefile.depend -u -p -r1.9 -r1.10 --- Makefile.depend +++ 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 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 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 Index: Makefile =================================================================== RCS file: /home/cvs/mdocml/mdocml/Makefile,v retrieving revision 1.459 retrieving revision 1.460 diff -LMakefile -LMakefile -u -p -r1.459 -r1.460 --- Makefile +++ Makefile @@ -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 Index: main.c =================================================================== RCS file: /home/cvs/mdocml/mdocml/main.c,v retrieving revision 1.228 retrieving revision 1.229 diff -Lmain.c -Lmain.c -u -p -r1.228 -r1.229 --- main.c +++ main.c @@ -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); --- 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 - * Copyright (c) 2011 Kristaps Dzonsons - * - * 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 Index: manpath.c =================================================================== RCS file: /home/cvs/mdocml/mdocml/manpath.c,v retrieving revision 1.22 retrieving revision 1.23 diff -Lmanpath.c -Lmanpath.c -u -p -r1.22 -r1.23 --- manpath.c +++ manpath.c @@ -27,15 +27,15 @@ #include #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, con 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, con /* 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, con 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 } 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, c } 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, c *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; @@ -253,4 +260,66 @@ manpath_manconf(struct manpaths *dirs, c } 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; + } } -- To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv