-/* $Id: mandocdb.c,v 1.162 2014/09/03 23:21:47 schwarze Exp $ */
+/* $Id: mandocdb.c,v 1.166 2014/10/12 20:32:39 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
const struct mdoc_node *, uint64_t);
static void render_key(struct mchars *, struct str *);
static void say(const char *, const char *, ...);
-static int set_basedir(const char *);
+static int set_basedir(const char *, int);
static int treescan(void);
static size_t utf8(unsigned int, char [7]);
{ NULL, 0 }, /* sp */
{ NULL, 0 }, /* %U */
{ NULL, 0 }, /* Ta */
+ { NULL, 0 }, /* ll */
};
* Most of these deal with a specific directory.
* Jump into that directory first.
*/
- if (OP_TEST != op && 0 == set_basedir(path_arg))
+ if (OP_TEST != op && 0 == set_basedir(path_arg, 1))
goto out;
if (dbopen(1)) {
ohash_init(&mlinks, 6, &mlinks_info);
}
- if (0 == set_basedir(dirs.paths[j]))
- goto out;
+ if (0 == set_basedir(dirs.paths[j], argc > 0))
+ continue;
if (0 == treescan())
- goto out;
+ continue;
if (0 == dbopen(0))
- goto out;
+ continue;
mpages_merge(mc, mp);
if (warnings && !nodb &&
if (mpage->mlinks->gzip)
mpage->form |= FORM_GZ;
putkey(mpage, mpage->sec, TYPE_sec);
- putkey(mpage, '\0' == *mpage->arch ?
- any : mpage->arch, TYPE_arch);
+ if (*mpage->arch != '\0')
+ putkey(mpage, mpage->arch, TYPE_arch);
for (mlink = mpage->mlinks; mlink; mlink = mlink->next) {
if ('\0' != *mlink->dsec)
htab = &strings;
if (debug > 1)
for (i = 0; i < mansearch_keymax; i++)
- if (1 << i & v)
+ if ((uint64_t)1 << i & v)
say(mpage->mlinks->file,
"Adding key %s=%*s",
mansearch_keynames[i], sz, cp);
}
static int
-set_basedir(const char *targetdir)
+set_basedir(const char *targetdir, int report_baddir)
{
static char startdir[PATH_MAX];
static int getcwd_status; /* 1 = ok, 2 = failure */
* we can reliably check whether files are inside.
*/
if (NULL == realpath(targetdir, basedir)) {
- exitcode = (int)MANDOCLEVEL_BADARG;
- say("", "&%s: realpath", targetdir);
+ if (report_baddir || errno != ENOENT) {
+ exitcode = (int)MANDOCLEVEL_BADARG;
+ say("", "&%s: realpath", targetdir);
+ }
return(0);
} else if (-1 == chdir(basedir)) {
- exitcode = (int)MANDOCLEVEL_BADARG;
- say("", "&chdir");
+ if (report_baddir || errno != ENOENT) {
+ exitcode = (int)MANDOCLEVEL_BADARG;
+ say("", "&chdir");
+ }
return(0);
}
chdir_status = 1;