Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/man allow to specify relative paths for sections in ...
details: https://anonhg.NetBSD.org/src/rev/ccf85fe366e2
branches: trunk
changeset: 486720:ccf85fe366e2
user: jdolecek <jdolecek%NetBSD.org@localhost>
date: Sat May 27 21:33:26 2000 +0000
description:
allow to specify relative paths for sections in man.conf - they are used
similarily to _subdir, but only when appropriate
fix -m handling, so that e.g. "man -m . 3 printf" works as it should
add new -S flag, to specify a string the result path has to contain
g/c some unused stuff
Written by Chuck Cranor, with only cosmetic changes & const poisoning by me.
diffstat:
usr.bin/man/config.c | 131 ++++++++++++---------
usr.bin/man/config.h | 15 +-
usr.bin/man/man.1 | 8 +-
usr.bin/man/man.c | 287 +++++++++++++++++++++++++-----------------------
usr.bin/man/man.conf.5 | 15 +-
5 files changed, 248 insertions(+), 208 deletions(-)
diffs (truncated from 712 to 300 lines):
diff -r 6e7ec2933f99 -r ccf85fe366e2 usr.bin/man/config.c
--- a/usr.bin/man/config.c Sat May 27 21:17:06 2000 +0000
+++ b/usr.bin/man/config.c Sat May 27 21:33:26 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: config.c,v 1.10 1999/04/04 16:57:36 dante Exp $ */
+/* $NetBSD: config.c,v 1.11 2000/05/27 21:33:26 jdolecek Exp $ */
/*
* Copyright (c) 1989, 1993, 1995
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)config.c 8.8 (Berkeley) 1/31/95";
#else
-__RCSID("$NetBSD: config.c,v 1.10 1999/04/04 16:57:36 dante Exp $");
+__RCSID("$NetBSD: config.c,v 1.11 2000/05/27 21:33:26 jdolecek Exp $");
#endif
#endif /* not lint */
@@ -69,14 +69,13 @@
*/
void
config(fname)
- char *fname;
+ const char *fname;
{
TAG *tp;
- ENTRY *ep;
FILE *cfp;
size_t len;
int lcnt;
- char *p, *t;
+ char *p, *t, type;
if (fname == NULL)
fname = _PATH_MANCONF;
@@ -103,31 +102,59 @@
continue;
*t = '\0';
- for (tp = head.tqh_first; /* Find any matching tag. */
- tp != NULL && strcmp(p, tp->s); tp = tp->q.tqe_next);
-
+ tp = getlist(p);
if (tp == NULL) /* Create a new tag. */
tp = addlist(p);
/*
- * Attach new records. The keywords _build and _crunch takes
- * the rest of the line as a single entity, everything else is
- * whitespace separated.
- * The reason we're not just using strtok(3) for all of the
- * parsing is so we don't get caught if a line has only a
- * single token on it.
+ * Attach new records. Check to see if it is a
+ * section record or not.
*/
- if (!strcmp(p, "_build") || !strcmp(p, "_crunch")) {
- while (*++t && isspace((unsigned char)*t));
- if ((ep = malloc(sizeof(ENTRY))) == NULL ||
- (ep->s = strdup(t)) == NULL)
- err(1, "malloc");
- TAILQ_INSERT_TAIL(&tp->list, ep, q);
- } else for (++t; (p = strtok(t, " \t\n")) != NULL; t = NULL) {
- if ((ep = malloc(sizeof(ENTRY))) == NULL ||
- (ep->s = strdup(p)) == NULL)
- err(1, "malloc");
- TAILQ_INSERT_TAIL(&tp->list, ep, q);
+
+ if (*p == '_') { /* not a section record */
+ /*
+ * Special cases: _build and _crunch take the
+ * rest of the line as a single entry.
+ */
+ if (!strcmp(p, "_build") || !strcmp(p, "_crunch")) {
+ /*
+ * The reason we're not just using
+ * strtok(3) for all of the parsing is
+ * so we don't get caught if a line
+ * has only a single token on it.
+ */
+ while (*++t && isspace((unsigned char)*t));
+ addentry(tp, t, 0);
+ } else {
+ for(++t; (p = strtok(t, " \t\n")) != NULL;
+ t = NULL)
+ addentry(tp, p, 0);
+ }
+
+ } else { /* section record */
+
+ /*
+ * section entries can either be all absolute
+ * paths or all relative paths, but not both.
+ */
+ type = (TAILQ_FIRST(&tp->list) != NULL) ?
+ *(TAILQ_FIRST(&tp->list)->s) : 0;
+
+ for (++t; (p = strtok(t, " \t\n")) != NULL; t = NULL) {
+
+ /* ensure an assigned type */
+ if (type == 0)
+ type = *p;
+
+ /* check for illegal mix */
+ if (*p != type) {
+ warnx("section %s: %s: invalid entry, does not match previous types",
+ tp->s, p);
+ warnx("man.conf cannot mix absolute and relative paths in an entry");
+ continue;
+ }
+ addentry(tp, p, 0);
+ }
}
}
@@ -136,15 +163,16 @@
/*
* addlist --
- * Add a tag to the list.
+ * Add a tag to the list. caller should check for duplicate
+ * before calling (we don't).
*/
TAG *
addlist(name)
- char *name;
+ const char *name;
{
TAG *tp;
- if ((tp = calloc(1, sizeof(TAG))) == NULL ||
+ if ((tp = malloc(sizeof(TAG))) == NULL ||
(tp->s = strdup(name)) == NULL)
err(1, "malloc");
TAILQ_INIT(&tp->list);
@@ -158,7 +186,7 @@
*/
TAG *
getlist(name)
- char *name;
+ const char *name;
{
TAG *tp;
@@ -168,41 +196,31 @@
return (NULL);
}
+/*
+ * addentry --
+ * add an entry to a list.
+ */
void
-removelist(name)
- char *name;
+addentry(tp, newent, head)
+ TAG *tp;
+ const char *newent;
+ int head;
{
- TAG *tp;
ENTRY *ep;
- tp = getlist(name);
- while ((ep = tp->list.tqh_first) != NULL) {
- free(ep->s);
- TAILQ_REMOVE(&tp->list, ep, q);
- }
- free(tp->s);
- TAILQ_REMOVE(&head, tp, q);
-
+ if ((ep = malloc(sizeof(*ep))) == NULL ||
+ (ep->s = strdup(newent)) == NULL)
+ err(1, "malloc");
+ if (head)
+ TAILQ_INSERT_HEAD(&tp->list, ep, q);
+ else
+ TAILQ_INSERT_TAIL(&tp->list, ep, q);
}
-TAG *
-renamelist(oldname, newname)
- char *oldname;
- char *newname;
-{
- TAG *tp;
-
- if(!(tp = getlist(oldname)))
- return (NULL);
- free(tp->s);
- if(!(tp->s = strdup(newname)))
- err(1, "malloc");
- return (tp);
-}
-
+#ifdef MANDEBUG
void
debug(l)
- char *l;
+ const char *l;
{
TAG *tp;
ENTRY *ep;
@@ -214,3 +232,4 @@
printf("\t%s\n", ep->s);
}
}
+#endif
diff -r 6e7ec2933f99 -r ccf85fe366e2 usr.bin/man/config.h
--- a/usr.bin/man/config.h Sat May 27 21:17:06 2000 +0000
+++ b/usr.bin/man/config.h Sat May 27 21:33:26 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: config.h,v 1.3 1999/04/04 16:57:36 dante Exp $ */
+/* $NetBSD: config.h,v 1.4 2000/05/27 21:33:26 jdolecek Exp $ */
/*-
* Copyright (c) 1993
@@ -53,9 +53,10 @@
TAILQ_HEAD(_head, _tag);
extern struct _head head;
-TAG *addlist __P((char *));
-void config __P((char *));
-void debug __P((char *));
-TAG *getlist __P((char *));
-void removelist __P((char *));
-TAG *renamelist __P((char *, char *));
+TAG *addlist __P((const char *));
+void addentry __P((TAG *, const char *, int));
+void config __P((const char *));
+#ifdef MANDEBUG
+void debug __P((const char *));
+#endif
+TAG *getlist __P((const char *));
diff -r 6e7ec2933f99 -r ccf85fe366e2 usr.bin/man/man.1
--- a/usr.bin/man/man.1 Sat May 27 21:17:06 2000 +0000
+++ b/usr.bin/man/man.1 Sat May 27 21:33:26 2000 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: man.1,v 1.9 1999/09/08 20:32:03 fredb Exp $
+.\" $NetBSD: man.1,v 1.10 2000/05/27 21:33:26 jdolecek Exp $
.\"
.\" Copyright (c) 1989, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -46,6 +46,7 @@
.Op Fl C Ar file
.Op Fl M Ar path
.Op Fl m Ar path
+.Op Fl S Ar srch
.Op Ar section
.Ar name Ar ...
.Nm ""
@@ -126,6 +127,11 @@
is specified by the ``_subdir'' line in the
.Nm
configuration file.
+.It Fl S
+Display only man pages that have the specified string in their
+filenames. This allows the man page search process criteria to be
+narrowed without having to change the MANPATH or ``_default''
+variables.
.It Fl w
List the pathnames of the man pages which
.Nm
diff -r 6e7ec2933f99 -r ccf85fe366e2 usr.bin/man/man.c
--- a/usr.bin/man/man.c Sat May 27 21:17:06 2000 +0000
+++ b/usr.bin/man/man.c Sat May 27 21:33:26 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: man.c,v 1.22 2000/01/09 04:54:54 tsutsui Exp $ */
+/* $NetBSD: man.c,v 1.23 2000/05/27 21:33:26 jdolecek Exp $ */
/*
* Copyright (c) 1987, 1993, 1994, 1995
@@ -44,7 +44,7 @@
#if 0
static char sccsid[] = "@(#)man.c 8.17 (Berkeley) 1/31/95";
#else
-__RCSID("$NetBSD: man.c,v 1.22 2000/01/09 04:54:54 tsutsui Exp $");
+__RCSID("$NetBSD: man.c,v 1.23 2000/05/27 21:33:26 jdolecek Exp $");
#endif
#endif /* not lint */
@@ -72,11 +72,11 @@
int main __P((int, char **));
static void build_page __P((char *, char **));
static void cat __P((char *));
-static char *check_pager __P((char *));
+static const char *check_pager __P((const char *));
static int cleanup __P((void));
static void how __P((char *));
static void jump __P((char **, char *, char *));
-static int manual __P((char *, TAG *, glob_t *));
+static int manual __P((char *, TAG *, glob_t *, const char *));
static void onsig __P((int));
static void usage __P((void));
@@ -85,13 +85,14 @@
int argc;
char *argv[];
{
- TAG *defp, *defnewp, *section, *sectnewp, *subp;
Home |
Main Index |
Thread Index |
Old Index