From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Add a new directive "manpath path" to replace the legacy
Date: Thu, 26 Mar 2015 17:43:02 -0500 (EST) [thread overview]
Message-ID: <17246669967251717062.enqueue@fantadrom.bsd.lv> (raw)
Log Message:
-----------
Add a new directive "manpath path"
to replace the legacy "_whatdb path/whatis.db".
Keep _whatdb support for backward compat, for now.
Discussed with many, jmc@ and ajacoutot@ agree with the general direction.
Modified Files:
--------------
mdocml:
manpath.c
Revision Data
-------------
Index: manpath.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/manpath.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -Lmanpath.c -Lmanpath.c -u -p -r1.21 -r1.22
--- manpath.c
+++ manpath.c
@@ -1,4 +1,4 @@
-/* $Id$ */
+/* $Id$ */
/*
* Copyright (c) 2011, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -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
@@ -20,7 +20,6 @@
#include <sys/types.h>
#include <sys/stat.h>
-#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
@@ -31,7 +30,6 @@
#include "manpath.h"
#define MAN_CONF_FILE "/etc/man.conf"
-#define MAN_CONF_KEY "_whatdb"
static void manpath_add(struct manpaths *, const char *, int);
static void manpath_parseline(struct manpaths *, char *, int);
@@ -207,33 +205,51 @@ manpath_free(struct manpaths *p)
void
manpath_manconf(struct manpaths *dirs, const char *file)
{
- FILE *stream;
- char *p, *q;
- size_t len, keysz;
+ const char *const toks[] = { "manpath", "_whatdb" };
- keysz = strlen(MAN_CONF_KEY);
- assert(keysz > 0);
+ FILE *stream;
+ char *cp, *ep;
+ size_t len, tok;
- if (NULL == (stream = fopen(file, "r")))
+ if ((stream = fopen(file, "r")) == NULL)
return;
- while (NULL != (p = fgetln(stream, &len))) {
- if (0 == len || '\n' != p[--len])
+ while ((cp = fgetln(stream, &len)) != NULL) {
+ ep = cp + len;
+ if (ep[-1] != '\n')
break;
- p[len] = '\0';
- while (isspace((unsigned char)*p))
- p++;
- if (strncmp(MAN_CONF_KEY, p, keysz))
- continue;
- p += keysz;
- while (isspace((unsigned char)*p))
- p++;
- if ('\0' == *p)
+ *--ep = '\0';
+ while (isspace((unsigned char)*cp))
+ cp++;
+ if (*cp == '#')
continue;
- if (NULL == (q = strrchr(p, '/')))
- continue;
- *q = '\0';
- manpath_add(dirs, p, 0);
+
+ for (tok = 0; tok < sizeof(toks)/sizeof(toks[0]); tok++) {
+ len = strlen(toks[tok]);
+ if (cp + len < ep &&
+ isspace((unsigned char)cp[len]) &&
+ !strncmp(cp, toks[tok], len)) {
+ cp += len;
+ while (isspace((unsigned char)*cp))
+ 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);
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
reply other threads:[~2015-03-26 22:43 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=17246669967251717062.enqueue@fantadrom.bsd.lv \
--to=schwarze@mdocml.bsd.lv \
--cc=source@mdocml.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).