version 1.21, 2015/03/22 18:14:30 |
version 1.22, 2015/03/26 22:42:32 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2011, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2011, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv> |
|
|
* purpose with or without fee is hereby granted, provided that the above |
* purpose with or without fee is hereby granted, provided that the above |
* copyright notice and this permission notice appear in all copies. |
* 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 |
* 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 |
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
|
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/stat.h> |
#include <sys/stat.h> |
|
|
#include <assert.h> |
|
#include <ctype.h> |
#include <ctype.h> |
#include <limits.h> |
#include <limits.h> |
#include <stdio.h> |
#include <stdio.h> |
|
|
#include "manpath.h" |
#include "manpath.h" |
|
|
#define MAN_CONF_FILE "/etc/man.conf" |
#define MAN_CONF_FILE "/etc/man.conf" |
#define MAN_CONF_KEY "_whatdb" |
|
|
|
static void manpath_add(struct manpaths *, const char *, int); |
static void manpath_add(struct manpaths *, const char *, int); |
static void manpath_parseline(struct manpaths *, char *, int); |
static void manpath_parseline(struct manpaths *, char *, int); |
Line 207 manpath_free(struct manpaths *p) |
|
Line 205 manpath_free(struct manpaths *p) |
|
void |
void |
manpath_manconf(struct manpaths *dirs, const char *file) |
manpath_manconf(struct manpaths *dirs, const char *file) |
{ |
{ |
|
const char *const toks[] = { "manpath", "_whatdb" }; |
|
|
FILE *stream; |
FILE *stream; |
char *p, *q; |
char *cp, *ep; |
size_t len, keysz; |
size_t len, tok; |
|
|
keysz = strlen(MAN_CONF_KEY); |
if ((stream = fopen(file, "r")) == NULL) |
assert(keysz > 0); |
|
|
|
if (NULL == (stream = fopen(file, "r"))) |
|
return; |
return; |
|
|
while (NULL != (p = fgetln(stream, &len))) { |
while ((cp = fgetln(stream, &len)) != NULL) { |
if (0 == len || '\n' != p[--len]) |
ep = cp + len; |
|
if (ep[-1] != '\n') |
break; |
break; |
p[len] = '\0'; |
*--ep = '\0'; |
while (isspace((unsigned char)*p)) |
while (isspace((unsigned char)*cp)) |
p++; |
cp++; |
if (strncmp(MAN_CONF_KEY, p, keysz)) |
if (*cp == '#') |
continue; |
continue; |
p += keysz; |
|
while (isspace((unsigned char)*p)) |
for (tok = 0; tok < sizeof(toks)/sizeof(toks[0]); tok++) { |
p++; |
len = strlen(toks[tok]); |
if ('\0' == *p) |
if (cp + len < ep && |
continue; |
isspace((unsigned char)cp[len]) && |
if (NULL == (q = strrchr(p, '/'))) |
!strncmp(cp, toks[tok], len)) { |
continue; |
cp += len; |
*q = '\0'; |
while (isspace((unsigned char)*cp)) |
manpath_add(dirs, p, 0); |
cp++; |
|
break; |
|
} |
|
} |
|
|
|
switch (tok) { |
|
case 1: /* _whatdb */ |
|
while (ep > cp && ep[-1] != '/') |
|
ep--; |
|
if (ep == cp) |
|
continue; |
|
*ep = '\0'; |
|
/* FALLTHROUGH */ |
|
case 0: /* manpath */ |
|
manpath_add(dirs, cp, 0); |
|
break; |
|
default: |
|
break; |
|
} |
} |
} |
|
|
fclose(stream); |
fclose(stream); |