Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src - getlist(): add "int create" arg, which creates list if it'...
details: https://anonhg.NetBSD.org/src/rev/3c9d30025c0c
branches: trunk
changeset: 532614:3c9d30025c0c
user: lukem <lukem%NetBSD.org@localhost>
date: Tue Jun 11 04:39:52 2002 +0000
description:
- getlist(): add "int create" arg, which creates list if it's not present
(using guts of now defunct addlist())
- use TAILQ_*() macros appropriately when manipulating tailqs
diffstat:
usr.bin/man/config.c | 52 ++++++++++---------------
usr.bin/man/config.h | 5 +-
usr.bin/man/man.c | 81 ++++++++++++++++++----------------------
usr.sbin/catman/catman.c | 94 ++++++++++++++++++++---------------------------
4 files changed, 99 insertions(+), 133 deletions(-)
diffs (truncated from 511 to 300 lines):
diff -r 43d4885d79dc -r 3c9d30025c0c usr.bin/man/config.c
--- a/usr.bin/man/config.c Tue Jun 11 03:15:41 2002 +0000
+++ b/usr.bin/man/config.c Tue Jun 11 04:39:52 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: config.c,v 1.15 2002/03/22 18:20:58 bouyer Exp $ */
+/* $NetBSD: config.c,v 1.16 2002/06/11 04:39:52 lukem Exp $ */
/*
* Copyright (c) 1989, 1993, 1995
@@ -39,7 +39,7 @@
static char sccsid[] = "@(#)config.c 8.8 (Berkeley) 1/31/95";
#else
#if defined(__RCSID)
-__RCSID("$NetBSD: config.c,v 1.15 2002/03/22 18:20:58 bouyer Exp $");
+__RCSID("$NetBSD: config.c,v 1.16 2002/06/11 04:39:52 lukem Exp $");
#endif
#endif
#endif /* not lint */
@@ -104,9 +104,7 @@
continue;
*t = '\0';
- tp = getlist(p);
- if (tp == NULL) /* Create a new tag. */
- tp = addlist(p);
+ tp = getlist(p, 1);
/*
* Attach new records. Check to see if it is a
@@ -164,38 +162,30 @@
}
/*
- * addlist --
- * Add a tag to the list. caller should check for duplicate
- * before calling (we don't).
+ * getlist --
+ * Return the linked list of entries for a tag if it exists.
+ * If it doesn't exist and create is non zero, create new tag
+ * and return that, otherwise return NULL.
*/
TAG *
-addlist(name)
+getlist(name, create)
const char *name;
+ int create;
{
TAG *tp;
- if ((tp = malloc(sizeof(TAG))) == NULL ||
- (tp->s = strdup(name)) == NULL)
- err(1, "malloc");
- TAILQ_INIT(&tp->list);
- TAILQ_INSERT_TAIL(&head, tp, q);
- return (tp);
-}
-
-/*
- * getlist --
- * Return the linked list of entries for a tag if it exists.
- */
-TAG *
-getlist(name)
- const char *name;
-{
- TAG *tp;
-
- for (tp = head.tqh_first; tp != NULL; tp = tp->q.tqe_next)
+ TAILQ_FOREACH(tp, &head, q)
if (!strcmp(name, tp->s))
return (tp);
- return (NULL);
+ if (create) {
+ if ((tp = malloc(sizeof(TAG))) == NULL ||
+ (tp->s = strdup(name)) == NULL)
+ err(1, "malloc");
+ TAILQ_INIT(&tp->list);
+ TAILQ_INSERT_TAIL(&head, tp, q);
+ return (tp);
+ } else
+ return (NULL);
}
/*
@@ -228,9 +218,9 @@
ENTRY *ep;
(void)printf("%s ===============\n", l);
- for (tp = head.tqh_first; tp != NULL; tp = tp->q.tqe_next) {
+ TAILQ_FOREACH(tp, &head, q) {
printf("%s\n", tp->s);
- for (ep = tp->list.tqh_first; ep != NULL; ep = ep->q.tqe_next)
+ TAILQ_FOREACH(ep, &tp->list, q)
printf("\t%s\n", ep->s);
}
}
diff -r 43d4885d79dc -r 3c9d30025c0c usr.bin/man/config.h
--- a/usr.bin/man/config.h Tue Jun 11 03:15:41 2002 +0000
+++ b/usr.bin/man/config.h Tue Jun 11 04:39:52 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: config.h,v 1.5 2000/05/28 16:23:55 he Exp $ */
+/* $NetBSD: config.h,v 1.6 2002/06/11 04:39:52 lukem Exp $ */
/*-
* Copyright (c) 1993
@@ -53,12 +53,11 @@
TAILQ_HEAD(_head, _tag);
extern struct _head head;
-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 *));
+TAG *getlist __P((const char *, int));
void removelist __P((const char *));
TAG *renamelist __P((const char *, const char *));
diff -r 43d4885d79dc -r 3c9d30025c0c usr.bin/man/man.c
--- a/usr.bin/man/man.c Tue Jun 11 03:15:41 2002 +0000
+++ b/usr.bin/man/man.c Tue Jun 11 04:39:52 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: man.c,v 1.27 2002/03/14 05:24:14 groo Exp $ */
+/* $NetBSD: man.c,v 1.28 2002/06/11 04:39:52 lukem 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.27 2002/03/14 05:24:14 groo Exp $");
+__RCSID("$NetBSD: man.c,v 1.28 2002/06/11 04:39:52 lukem Exp $");
#endif
#endif /* not lint */
@@ -180,8 +180,7 @@
}
/* create an empty _default list if the config file didn't have one */
- if ((defp = getlist("_default")) == NULL)
- defp = addlist("_default");
+ defp = getlist("_default", 1);
/* if -M wasn't specified, check for MANPATH */
if (p_path == NULL)
@@ -193,12 +192,12 @@
* relative) paths in the man.conf file.
*/
if ((argc > 1 || sectionname != NULL) &&
- (section = getlist(sectionname ? sectionname : *argv)) != NULL) {
+ (section = getlist(sectionname ? sectionname : *argv, 0)) != NULL) {
if (sectionname == NULL) {
argv++;
argc--;
}
- abs_section = (TAILQ_FIRST(§ion->list) != NULL &&
+ abs_section = (! TAILQ_EMPTY(§ion->list) &&
*(TAILQ_FIRST(§ion->list)->s) == '/');
} else {
section = NULL;
@@ -206,9 +205,7 @@
}
/* get subdir list */
- subp = getlist("_subdir");
- if (!subp)
- subp = addlist("_subdir");
+ subp = getlist("_subdir", 1);
/*
* now that we have all the inputs we must generate a search path.
@@ -243,13 +240,11 @@
* for backward compat, we do not append subp if abs_section
* and the path does not end in "/".
*/
- newpathp = addlist("_new_path");
+ newpathp = getlist("_new_path", 1);
if (p_path) {
/* use p_path */
for (; (p = strtok(p_path, ":")) != NULL; p_path = NULL) {
- for ( e_subp = TAILQ_FIRST(&subp->list) ;
- e_subp != NULL ;
- e_subp = TAILQ_NEXT(e_subp, q)) {
+ TAILQ_FOREACH(e_subp, &subp->list, q) {
snprintf(buf, sizeof(buf), "%s/%s{/%s,}",
p, e_subp->s, machine);
addentry(newpathp, buf, 0);
@@ -257,9 +252,7 @@
}
} else {
/* use defp rather than p_path */
- for (e_defp = TAILQ_FIRST(&defp->list) ;
- e_defp != NULL ;
- e_defp = TAILQ_NEXT(e_defp, q)) {
+ TAILQ_FOREACH(e_defp, &defp->list, q) {
/* handle trailing "/" magic here ... */
if (abs_section &&
@@ -271,9 +264,7 @@
continue;
}
- for ( e_subp = TAILQ_FIRST(&subp->list) ;
- e_subp != NULL ;
- e_subp = TAILQ_NEXT(e_subp, q)) {
+ TAILQ_FOREACH(e_subp, &subp->list, q) {
snprintf(buf, sizeof(buf), "%s%s%s{/%s,}",
e_defp->s, (abs_section) ? "" : "/",
e_subp->s, machine);
@@ -292,9 +283,7 @@
if (p_add) {
for (p = strtok(p_add, ":") ; p ; p = strtok(NULL, ":")) {
- for ( e_subp = TAILQ_FIRST(&subp->list) ;
- e_subp != NULL ;
- e_subp = TAILQ_NEXT(e_subp, q)) {
+ TAILQ_FOREACH(e_subp, &subp->list, q) {
snprintf(buf, sizeof(buf), "%s/%s{/%s,}",
p, e_subp->s, machine);
addentry(newpathp, buf, 1);
@@ -427,8 +416,7 @@
*eptr = '\0';
/* For each element in the list... */
- e_tag = tag == NULL ? NULL : tag->list.tqh_first;
- for (; e_tag != NULL; e_tag = e_tag->q.tqe_next) {
+ TAILQ_FOREACH(e_tag, &tag->list, q) {
(void)snprintf(buf, sizeof(buf), "%s/%s.*", e_tag->s, escpage);
if ((error = glob(buf,
GLOB_APPEND | GLOB_BRACE | GLOB_NOSORT, NULL, pg)) != 0) {
@@ -468,10 +456,9 @@
if (!fnmatch(buf, pg->gl_pathv[cnt], 0))
goto next;
- e_sufp = (sufp = getlist("_suffix")) == NULL ?
- NULL : sufp->list.tqh_first;
- for (found = 0;
- e_sufp != NULL; e_sufp = e_sufp->q.tqe_next) {
+ sufp = getlist("_suffix", 1);
+ found = 0;
+ TAILQ_FOREACH(e_sufp, &sufp->list, q) {
(void)snprintf(buf,
sizeof(buf), "*/%s%s", escpage,
e_sufp->s);
@@ -484,12 +471,13 @@
goto next;
/* Try the _build key words next. */
- e_sufp = (sufp = getlist("_build")) == NULL ?
- NULL : sufp->list.tqh_first;
- for (found = 0;
- e_sufp != NULL; e_sufp = e_sufp->q.tqe_next) {
+ sufp = getlist("_build", 1);
+ found = 0;
+ TAILQ_FOREACH(e_sufp, &sufp->list, q) {
for (p = e_sufp->s;
- *p != '\0' && !isspace((unsigned char)*p); ++p);
+ *p != '\0' && !isspace((unsigned char)*p);
+ ++p)
+ continue;
if (*p == '\0')
continue;
*p = '\0';
@@ -527,8 +515,7 @@
/* If not found, enter onto the missing list. */
if (!anyfound) {
- if ((missp = getlist("_missing")) == NULL)
- missp = addlist("_missing");
+ missp = getlist("_missing", 1);
if ((ep = malloc(sizeof(ENTRY))) == NULL ||
(ep->s = strdup(page)) == NULL) {
warn("malloc");
@@ -590,8 +577,7 @@
/* Add a remove-when-done list. */
- if ((intmpp = getlist("_intmp")) == NULL)
- intmpp = addlist("_intmp");
+ intmpp = getlist("_intmp", 1);
/* Move to the printf(3) format string. */
for (; *fmt && isspace((unsigned char)*fmt); ++fmt)
@@ -792,18 +778,23 @@
int rval;
rval = 0;
- ep = (missp = getlist("_missing")) == NULL ?
- NULL : missp->list.tqh_first;
- if (ep != NULL)
- for (; ep != NULL; ep = ep->q.tqe_next) {
+ /*
+ * get missing list, but don't create missing _missing,
+ * as we don't want to try & allocate memory in getlist()
+ */
+ if ((missp = getlist("_missing", 0)) != NULL)
+ TAILQ_FOREACH(ep, &missp->list, q) {
warnx("no entry for %s in the manual.", ep->s);
Home |
Main Index |
Thread Index |
Old Index