=================================================================== RCS file: /cvs/mandoc/main.c,v retrieving revision 1.227 retrieving revision 1.232 diff -u -p -r1.227 -r1.232 --- mandoc/main.c 2015/03/17 13:35:52 1.227 +++ mandoc/main.c 2015/04/03 08:46:17 1.232 @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.227 2015/03/17 13:35:52 schwarze Exp $ */ +/* $Id: main.c,v 1.232 2015/04/03 08:46:17 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2012, 2014, 2015 Ingo Schwarze @@ -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 @@ -34,12 +34,13 @@ #include #include -#include "mandoc.h" #include "mandoc_aux.h" -#include "main.h" +#include "mandoc.h" +#include "roff.h" #include "mdoc.h" #include "man.h" -#include "manpath.h" +#include "main.h" +#include "manconf.h" #include "mansearch.h" #if !defined(__GNUC__) || (__GNUC__ < 2) @@ -83,7 +84,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 *, @@ -118,16 +119,16 @@ 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; 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; @@ -151,7 +152,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; @@ -174,12 +175,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 +199,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 +240,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; @@ -336,10 +337,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 +353,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,10 +442,11 @@ 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); + passthrough(resp->file, fd, + conf.output.synopsisonly); rctmp = mparse_wait(curp.mp); if (rc < rctmp) @@ -470,7 +474,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); @@ -499,9 +503,9 @@ usage(enum argmode argmode) switch (argmode) { case ARG_FILE: - fputs("usage: mandoc [-acfhkl] [-Ios=name] " - "[-Kencoding] [-mformat] [-Ooption]\n" - "\t [-Toutput] [-Wlevel] [file ...]\n", stderr); + fputs("usage: mandoc [-acfhkl] [-I os=name] " + "[-K encoding] [-mformat] [-O option]\n" + "\t [-T output] [-W level] [file ...]\n", stderr); break; case ARG_NAME: fputs("usage: man [-acfhklw] [-C file] [-I os=name] " @@ -993,7 +997,7 @@ spawn_pager(void) if (pager == NULL || *pager == '\0') pager = getenv("PAGER"); if (pager == NULL || *pager == '\0') - pager = "/usr/bin/more -s"; + pager = "more -s"; cp = mandoc_strdup(pager); /*