Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-5]: src/libexec/makewhatis Pull up revisions 1.18-1.19 (via pat...



details:   https://anonhg.NetBSD.org/src/rev/f6c564179944
branches:  netbsd-1-5
changeset: 492600:f6c564179944
user:      he <he%NetBSD.org@localhost>
date:      Wed Jan 23 19:01:34 2002 +0000

description:
Pull up revisions 1.18-1.19 (via patch, requested by tron):
  Cleanup and enhance error handling.  Handle ``.Xr'' commands with
  text after the section number properly.  Fixes PR#15253.
This synchronizes with version 1.19.

diffstat:

 libexec/makewhatis/makewhatis.c |  318 ++++++++++++++++++++-------------------
 1 files changed, 162 insertions(+), 156 deletions(-)

diffs (truncated from 700 to 300 lines):

diff -r 30012944e6fb -r f6c564179944 libexec/makewhatis/makewhatis.c
--- a/libexec/makewhatis/makewhatis.c   Wed Jan 23 17:21:53 2002 +0000
+++ b/libexec/makewhatis/makewhatis.c   Wed Jan 23 19:01:34 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: makewhatis.c,v 1.7.4.3 2001/04/22 18:07:14 he Exp $    */
+/*     $NetBSD: makewhatis.c,v 1.7.4.4 2002/01/23 19:01:34 he Exp $    */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -26,7 +26,7 @@
  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@@ -43,7 +43,7 @@
 #endif /* not lint */
 
 #ifndef lint
-__RCSID("$NetBSD: makewhatis.c,v 1.7.4.3 2001/04/22 18:07:14 he Exp $");
+__RCSID("$NetBSD: makewhatis.c,v 1.7.4.4 2002/01/23 19:01:34 he Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -69,7 +69,7 @@
 struct manpagestruct {
        manpage *mp_left,*mp_right;
        ino_t    mp_inode;
-       char     mp_name[1];
+       char     mp_name[1];
 };
 
 typedef struct whatisstruct whatis;
@@ -78,23 +78,25 @@
        char    *wi_data;
 };
 
-int              main (int, char **);
-char           *findwhitespace (char *);
-char           *strmove (char *,char *);
-char           *GetS (gzFile, char *, int);
-int             manpagesection (char *);
-char           *createsectionstring(char *);
-int             addmanpage (manpage **, ino_t, char *);
-int             addwhatis (whatis **, char *);
-char           *replacestring (char *, char *, char *);
-void            catpreprocess (char *);
-char           *parsecatpage (gzFile *);
-int             manpreprocess (char *);
-char           *nroff (gzFile *);
-char           *parsemanpage (gzFile *, int);
-char           *getwhatisdata (char *);
-void            processmanpages (manpage **,whatis **);
-int             dumpwhatis (FILE *, whatis *);
+int     main(int, char **);
+char   *findwhitespace(char *);
+char   *strmove(char *,char *);
+char   *GetS(gzFile, char *, size_t);
+int     manpagesection(char *);
+char   *createsectionstring(char *);
+void    addmanpage(manpage **, ino_t, char *);
+void    addwhatis(whatis **, char *);
+char   *replacestring(char *, char *, char *);
+void    catpreprocess(char *);
+char   *parsecatpage(gzFile *);
+int     manpreprocess(char *);
+char   *nroff(gzFile *);
+char   *parsemanpage(gzFile *, int);
+char   *getwhatisdata(char *);
+void    processmanpages(manpage **,whatis **);
+void    dumpwhatis(FILE *, whatis *);
+void   *emalloc(size_t);
+char   *estrdup(const char *);
 
 char *default_manpath[] = {
        "/usr/share/man",
@@ -102,17 +104,15 @@
 };
 
 char sectionext[] = "0123456789ln";
-char whatisdb[]   = "whatis.db";
-
-extern char *__progname;
+char whatisdb[]          = "whatis.db";
 
 int
-main(int argc,char **argv)
+main(int argc, char **argv)
 {
        char    **manpath;
        FTS     *fts;
        FTSENT  *fe;
-       manpage *source;
+       manpage *source;
        whatis  *dest;
        FILE    *out;
 
@@ -120,20 +120,17 @@
 
        manpath = (argc < 2) ? default_manpath : &argv[1];
 
-       if ((fts = fts_open(manpath, FTS_LOGICAL, NULL)) == NULL) {
-               perror(__progname);
-               return EXIT_FAILURE;
-       }
+       if ((fts = fts_open(manpath, FTS_LOGICAL, NULL)) == NULL)
+               err(EXIT_FAILURE, "Cannot open `%s'", *manpath);
 
        source = NULL;
        while ((fe = fts_read(fts)) != NULL) {
                switch (fe->fts_info) {
                case FTS_F:
                        if (manpagesection(fe->fts_path) >= 0)
-                               if (!addmanpage(&source,
-                                       fe->fts_statp->st_ino,
-                                       fe->fts_path))
-                                       err(EXIT_FAILURE, NULL);
+                               addmanpage(&source, fe->fts_statp->st_ino,
+                                   fe->fts_path);
+                       /*FALLTHROUGH*/
                case FTS_D:
                case FTS_DC:
                case FTS_DEFAULT:
@@ -141,9 +138,8 @@
                case FTS_SLNONE:
                        break;
                default:
-                       errx(EXIT_FAILURE, "%s: %s", fe->fts_path,
-                           strerror(fe->fts_errno));
-
+                       errno = fe->fts_errno;
+                       err(EXIT_FAILURE, "Error reading `%s'", fe->fts_path);
                }
        }
 
@@ -152,25 +148,26 @@
        dest = NULL;
        processmanpages(&source, &dest);
 
-       if (chdir(manpath[0]) < 0)
-               errx(EXIT_FAILURE, "%s: %s", manpath[0], strerror(errno));
+       if (chdir(manpath[0]) == -1)
+               err(EXIT_FAILURE, "Cannot change dir to `%s'", manpath[0]);
 
+       (void)unlink(whatisdb);
        if ((out = fopen(whatisdb, "w")) == NULL)
-               errx(EXIT_FAILURE, "%s: %s", whatisdb, strerror(errno));
+               err(EXIT_FAILURE, "Cannot open `%s'", whatisdb);
 
-       if (!(dumpwhatis(out, dest) ||
-           (fclose(out) < 0)) ||
-           (chmod(whatisdb, S_IRUSR|S_IRGRP|S_IROTH) < 0))
-               errx(EXIT_FAILURE, "%s: %s", whatisdb, strerror(errno));
+       dumpwhatis(out, dest);
+       if (fchmod(fileno(out), S_IRUSR|S_IRGRP|S_IROTH) == -1)
+               err(EXIT_FAILURE, "Cannot chmod `%s'", whatisdb);
+       if (fclose(out) != 0)
+               err(EXIT_FAILURE, "Cannot close `%s'", whatisdb);
 
        return EXIT_SUCCESS;
 }
 
-char
-*findwhitespace(char *str)
-
+char *
+findwhitespace(char *str)
 {
-       while (!isspace(*str))
+       while (!isspace((unsigned char)*str))
                if (*str++ == '\0') {
                        str = NULL;
                        break;
@@ -181,18 +178,16 @@
 
 char
 *strmove(char *dest,char *src)
-
 {
        return memmove(dest, src, strlen(src) + 1);
 }
 
-char
-*GetS(gzFile in, char *buffer, int length)
-
+char *
+GetS(gzFile in, char *buffer, size_t length)
 {
        char    *ptr;
 
-       if (((ptr = gzgets(in, buffer, length)) != NULL) && (*ptr == '\0'))
+       if (((ptr = gzgets(in, buffer, (int)length)) != NULL) && (*ptr == '\0'))
                ptr = NULL;
 
        return ptr;
@@ -223,75 +218,65 @@
        return -1;
 }
 
-char
-*createsectionstring(char *section_id)
+char *
+createsectionstring(char *section_id)
 {
-       char *section;
-
-       if ((section = malloc(strlen(section_id) + 7)) != NULL) {
-               section[0] = ' ';
-               section[1] = '(';
-               (void) strcat(strcpy(&section[2], section_id), ") - ");
-       }
+       char *section = emalloc(strlen(section_id) + 7);
+       section[0] = ' ';
+       section[1] = '(';
+       (void)strcat(strcpy(&section[2], section_id), ") - ");
        return section;
 }
 
-int
+void
 addmanpage(manpage **tree,ino_t inode,char *name)
 {
-       manpage *mp;
+       manpage *mp;
 
        while ((mp = *tree) != NULL) {
                if (mp->mp_inode == inode)
-                       return 1;
-               tree = &((inode < mp->mp_inode) ? mp->mp_left : mp->mp_right);
+                       return;
+               tree = inode < mp->mp_inode ? &mp->mp_left : &mp->mp_right;
        }
 
-       if ((mp = malloc(sizeof(manpage) + strlen(name))) == NULL)
-               return 0;
-
+       mp = emalloc(sizeof(manpage) + strlen(name));
        mp->mp_left = NULL;
        mp->mp_right = NULL;
        mp->mp_inode = inode;
-       (void) strcpy(mp->mp_name, name);
+       (void)strcpy(mp->mp_name, name);
        *tree = mp;
-
-       return 1;
 }
 
-int
+void
 addwhatis(whatis **tree, char *data)
 {
        whatis *wi;
        int result;
 
-       while (isspace(*data))
+       while (isspace((unsigned char)*data))
                data++;
 
        if (*data == '/') {
                char *ptr;
 
                ptr = ++data;
-               while ((*ptr != '\0') && !isspace(*ptr))
+               while ((*ptr != '\0') && !isspace((unsigned char)*ptr))
                        if (*ptr++ == '/')
                                data = ptr;
        }
 
        while ((wi = *tree) != NULL) {
-               result=strcmp(data, wi->wi_data);
-               if (result == 0) return 1;
-               tree = &((result < 0) ? wi->wi_left : wi->wi_right);
+               result = strcmp(data, wi->wi_data);
+               if (result == 0) return;
+               tree = result < 0 ? &wi->wi_left : &wi->wi_right;
        }
 
-       if ((wi = malloc(sizeof(whatis) + strlen(data))) == NULL)
-               return 0;
+       wi = emalloc(sizeof(whatis) + strlen(data));
 
        wi->wi_left = NULL;
        wi->wi_right = NULL;
        wi->wi_data = data;
        *tree = wi;
-
-       return 1;
 }
 
 void
@@ -300,11 +285,11 @@
        char    *to;
 
        to = from;
-       while (isspace(*from)) from++;
+       while (isspace((unsigned char)*from)) from++;
 



Home | Main Index | Thread Index | Old Index