1: # include   <stdio.h>
   2: # include   <sys/types.h>
   3: # include   <dir.h>
   4: # include   <stat.h>
   5: # include   <ctype.h>
   6: 
   7: #define NROFF   "nroff -man"
   8: #define SSP "cat -s"
   9: 
  10: # define    reg register
  11: # define    bool    char
  12: 
  13: # define    SYSTEM(str) (pflag ? printf("%s\n", str) : system(str))
  14: 
  15: char        buf[BUFSIZ],
  16:         pflag = 0,
  17:         nflag = 0,
  18:         wflag = 0;
  19: char    *rindex();
  20: 
  21: main(ac, av)
  22: int ac;
  23: char    *av[]; {
  24: 
  25:     reg char    *tsp, *msp, *csp, *man, *cat, *sp;
  26:     reg FILE    *mdir, *inf;
  27:     reg long    time;
  28:     reg char    *sections;
  29:     reg int     exstat = 0;
  30:     reg bool    changed = 0;
  31:     static struct direct    dir;
  32:     static struct stat  sbuf;
  33: 
  34:     while (ac > 1) {
  35:         av++;
  36:         if (strcmp(*av, "-p") == 0)
  37:             pflag++;
  38:         else if (strcmp(*av, "-n") == 0)
  39:             nflag++;
  40:         else if (strcmp(*av, "-w") == 0)
  41:             wflag++;
  42:         else if (*av[0] == '-')
  43:             goto usage;
  44:         else
  45:             break;
  46:         ac--;
  47:     }
  48:     if (ac == 2)
  49:         sections = *av;
  50:     else if (ac < 2)
  51:         sections = "12345678lnpu";
  52:     else {
  53: usage:
  54:         printf("usage: catman [ -p ] [ -n ] [ -w ] [ sections ]\n");
  55:         exit(-1);
  56:     }
  57:     if (wflag)
  58:         goto whatis;
  59:     chdir("/usr/man");
  60:     man = "manx/xxxxxxxxxxxxxx";
  61:     cat = "catx/xxxxxxxxxxxxxx";
  62:     msp = &man[5];
  63:     csp = &cat[5];
  64:     umask(0);
  65:     for (sp = sections; *sp; sp++) {
  66:         man[3] = cat[3] = *sp;
  67:         *msp = *csp = '\0';
  68:         if ((mdir = fopen(man, "r")) == NULL) {
  69:             fprintf(stderr, "fopen:");
  70:             perror(man);
  71:             exstat = 1;
  72:             continue;
  73:         }
  74:         if (stat(cat, &sbuf) < 0) {
  75:             sprintf(buf, "mkdir %s", cat);
  76:             SYSTEM(buf);
  77:             stat(cat, &sbuf);
  78:         }
  79:         if ((sbuf.st_mode & 0777) != 0777)
  80:             chmod(cat, 0777);
  81:         while (fread((char *) &dir, sizeof dir, 1, mdir) > 0) {
  82:             if (dir.d_ino == 0 || dir.d_name[0] == '.')
  83:                 continue;
  84:             /*
  85: 			 * make sure this is a man file, i.e., that it
  86: 			 * ends in .[0-9] or .[0-9][a-z]
  87: 			 */
  88:             tsp = rindex(dir.d_name, '.');
  89:             if (tsp == NULL)
  90:                 continue;
  91:             switch (*++tsp) {
  92:                 case '1':   case '2':   case '3':
  93:                 case '4':   case '5':   case '6':
  94:                 case '7':   case '8':   case 'l':
  95:                 case 'n':   case 'p':   case 'u':
  96:                     if (isalpha(*++tsp) || *tsp == '\0')
  97:                         break;
  98:                 default:
  99:                     continue;
 100:             }
 101: 
 102:             strncpy(msp, dir.d_name, DIRSIZ);
 103:             if ((inf = fopen(man, "r")) == NULL) {
 104:                 perror(man);
 105:                 exstat = 1;
 106:                 continue;
 107:             }
 108:             if (getc(inf) == '.' && getc(inf) == 's'
 109:                 && getc(inf) == 'o') {
 110:                 fclose(inf);
 111:                 continue;
 112:             }
 113:             fclose(inf);
 114:             strncpy(csp, dir.d_name, DIRSIZ);
 115:             if (stat(cat, &sbuf) >= 0) {
 116:                 time = sbuf.st_mtime;
 117:                 stat(man, &sbuf);
 118:                 if (time >= sbuf.st_mtime)
 119:                     continue;
 120:                 unlink(cat);
 121:             }
 122:             sprintf(buf, "%s %s | %s > %s", NROFF, man, SSP, cat);
 123:             SYSTEM(buf);
 124:             changed = 1;
 125:         }
 126:         fclose(mdir);
 127:     }
 128:     if (changed && !nflag) {
 129: whatis:
 130:         if (pflag)
 131:             printf("/bin/csh /usr/lib/makewhatis\n");
 132:         else {
 133:             execl("/bin/csh", "/bin/csh", "/usr/lib/makewhatis", 0);
 134:             perror("/bin/csh /usr/lib/makewhatis");
 135:             exstat = 1;
 136:         }
 137:     }
 138:     exit(exstat);
 139: }

Defined functions

main defined in line 21; never used

Defined variables

buf defined in line 15; used 4 times
pflag defined in line 16; used 3 times

Defined macros

NROFF defined in line 7; used 1 times
SSP defined in line 8; used 1 times
SYSTEM defined in line 13; used 2 times
bool defined in line 11; used 1 times
  • in line 30
reg defined in line 10; used 6 times
Last modified: 1982-10-30
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 829
Valid CSS Valid XHTML 1.0 Strict