date and time created 83/08/11 20:49:31 by sam
[unix-history] / usr / src / old / catman / catman.c
index b31cb3e..65452a0 100644 (file)
@@ -1,37 +1,36 @@
-static char *sccsid = "@(#)catman.c    4.2 (Berkeley) %G%";
-# include      <stdio.h>
-# include      <sys/param.h>
-# include      <stat.h>
-# include      <dir.h>
-# include      <ctype.h>
+#ifndef lint
+static char *sccsid = "@(#)catman.c    4.5 (Berkeley) %G%";
+#endif
 
 
-# define       reg     register
-# define       bool    char
+/*
+ * catman: update cat'able versions of manual pages
+ *  (whatis database also)
+ */
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/dir.h>
+#include <ctype.h>
 
 
-# define       SYSTEM(str)     (pflag ? printf("%s\n", str) : system(str))
+#define        SYSTEM(str)     (pflag ? printf("%s\n", str) : system(str))
 
 
-char           buf[BUFSIZ],
-               pflag = 0,
-               nflag = 0,
-               wflag = 0;
-
-char           *rindex();
+char   buf[BUFSIZ];
+char   pflag;
+char   nflag;
+char   wflag;
+char   man[MAXNAMLEN+6] = "manx/";
+char   cat[MAXNAMLEN+6] = "catx/";
+char   *rindex();
 
 main(ac, av)
 
 main(ac, av)
-int    ac;
-char   *av[]; {
-
-       reg char        *tsp, *msp, *csp, *sp;
-       reg FILE        *inf;
-       reg DIR         *mdir;
-       reg long        time;
-       reg char        *sections;
-       reg int         exstat = 0;
-       reg bool        changed = 0;
-       static char     man[MAXNAMLEN+6] = "manx/";
-       static char     cat[MAXNAMLEN+6] = "catx/";
-       reg struct direct *dir;
-       struct stat     sbuf;
+       int ac;
+       char *av[];
+{
+       register char *msp, *csp, *sp;
+       register char *sections;
+       register int exstat = 0;
+       register char changed = 0;
 
        while (ac > 1) {
                av++;
 
        while (ac > 1) {
                av++;
@@ -63,6 +62,10 @@ usage:
        csp = &cat[5];
        umask(0);
        for (sp = sections; *sp; sp++) {
        csp = &cat[5];
        umask(0);
        for (sp = sections; *sp; sp++) {
+               register DIR *mdir;
+               register struct direct *dir;
+               struct stat sbuf;
+
                man[3] = cat[3] = *sp;
                *msp = *csp = '\0';
                if ((mdir = opendir(man)) == NULL) {
                man[3] = cat[3] = *sp;
                *msp = *csp = '\0';
                if ((mdir = opendir(man)) == NULL) {
@@ -72,25 +75,43 @@ usage:
                        continue;
                }
                if (stat(cat, &sbuf) < 0) {
                        continue;
                }
                if (stat(cat, &sbuf) < 0) {
-                       sprintf(buf, "mkdir %s", cat);
-                       SYSTEM(buf);
+                       char buf[MAXNAMLEN + 6], *cp, *rindex();
+
+                       strcpy(buf, cat);
+                       cp = rindex(buf, '/');
+                       if (cp && cp[1] == '\0')
+                               *cp = '\0';
+                       if (pflag)
+                               printf("mkdir %s\n", buf);
+                       else if (mkdir(buf, 0777) < 0) {
+                               sprintf(buf, "catman: mkdir: %s", cat);
+                               perror(buf);
+                               continue;
+                       }
                        stat(cat, &sbuf);
                }
                if ((sbuf.st_mode & 0777) != 0777)
                        chmod(cat, 0777);
                while ((dir = readdir(mdir)) != NULL) {
                        stat(cat, &sbuf);
                }
                if ((sbuf.st_mode & 0777) != 0777)
                        chmod(cat, 0777);
                while ((dir = readdir(mdir)) != NULL) {
+                       time_t time;
+                       char *tsp;
+                       FILE *inf;
+
                        if (dir->d_ino == 0 || dir->d_name[0] == '.')
                                continue;
                        /*
                        if (dir->d_ino == 0 || dir->d_name[0] == '.')
                                continue;
                        /*
-                        * make sure this is a man file, i.e., that it
+                        * Make sure this is a man file, i.e., that it
                         * ends in .[0-9] or .[0-9][a-z]
                         */
                        tsp = rindex(dir->d_name, '.');
                        if (tsp == NULL)
                                continue;
                         * ends in .[0-9] or .[0-9][a-z]
                         */
                        tsp = rindex(dir->d_name, '.');
                        if (tsp == NULL)
                                continue;
-                       if (!isdigit(*++tsp) || ((*++tsp && !isalpha(*tsp)) || *++tsp))
+                       if (!isdigit(*++tsp))
+                               continue;
+                       if (*++tsp && !isalpha(*tsp))
+                               continue;
+                       if (*tsp && *++tsp)
                                continue;
                                continue;
-
                        strcpy(msp, dir->d_name);
                        if ((inf = fopen(man, "r")) == NULL) {
                                perror(man);
                        strcpy(msp, dir->d_name);
                        if ((inf = fopen(man, "r")) == NULL) {
                                perror(man);