* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
"@(#) Copyright (c) 1980 Regents of the University of California.\n\
static char sccsid
[] = "@(#)catman.c 5.8 (Berkeley) %G%";
* catman: update cat'able versions of manual pages
char man
[MAXNAMLEN
+6] = "manx/";
char cat
[MAXNAMLEN
+6] = "catx/";
char lncat
[MAXNAMLEN
+9] = "../catx/";
char *manpath
= "/usr/man";
char *sections
= "12345678ln";
char *makewhatis
= "/usr/lib/makewhatis";
char *index(), *rindex();
if ((mp
= getenv("MANPATH")) != NULL
)
while (ac
> 0 && av
[0][0] == '-') {
fprintf(stderr
, "%s: missing path\n",
printf("usage: catman [ -p ] [ -n ] [ -w ] [ -M path ] [ sections ]\n");
for (mp
= manpath
; mp
&& ((nextp
= index(mp
, ':')), 1); mp
= nextp
) {
register char *msp
, *csp
, *sp
;
sprintf(buf
, "catman: %s", mandir
);
printf("cd %s\n", mandir
);
for (sp
= sections
; *sp
; sp
++) {
register struct direct
*dir
;
if ((mdir
= opendir(man
)) == NULL
) {
sprintf(buf
, "catman: opendir: %s", man
);
if (stat(cat
, &sbuf
) < 0) {
printf("mkdir %s\n", buf
);
else if (mkdir(buf
, 0777) < 0) {
sprintf(buf
, "catman: mkdir: %s", cat
);
if (access(cat
, R_OK
|W_OK
|X_OK
) == -1) {
sprintf(buf
, "catman: %s", cat
);
if ((sbuf
.st_mode
& S_IFMT
) != S_IFDIR
) {
fprintf(stderr
, "catman: %s: Not a directory\n", cat
);
while ((dir
= readdir(mdir
)) != NULL
) {
if (dir
->d_ino
== 0 || dir
->d_name
[0] == '.')
* 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 (!isdigit(*++tsp
) && *tsp
!= *sp
)
if (*++tsp
&& !isalpha(*tsp
))
(void) strcpy(msp
, dir
->d_name
);
if ((inf
= fopen(man
, "r")) == NULL
) {
sprintf(buf
, "catman: %s", man
);
if (getc(inf
) == '.' && getc(inf
) == 's'
fgets(lncat
+3, sizeof(lncat
)-3, inf
)==NULL
) {
if (lncat
[strlen(lncat
)-1] == '\n')
lncat
[strlen(lncat
)-1] = '\0';
if (strncmp(lncat
+3, "man", 3) != 0) {
bcopy("../cat", lncat
, sizeof("../cat")-1);
(void) strcpy(csp
, dir
->d_name
);
if (stat(cat
, &sbuf
) >= 0) {
if (time
>= sbuf
.st_mtime
)
* Don't unlink a directory by accident.
if (stat(lncat
+3, &sbuf
) >= 0 &&
(((sbuf
.st_mode
&S_IFMT
)==S_IFREG
) ||
((sbuf
.st_mode
&S_IFMT
)==S_IFLNK
)))
printf("ln -s %s %s\n", lncat
, cat
);
if (symlink(lncat
, cat
) == -1) {
sprintf(buf
, "catman: symlink: %s", cat
);
sprintf(buf
, "nroff -man %s > %s", man
, cat
);
else if ((status
= system(buf
)) != 0) {
fprintf(stderr
, "catman: nroff: %s: exit status %d: Owooooo!\n", cat
, status
);
sprintf(buf
, "%s %s", makewhatis
, mandir
);
else if ((status
= system(buf
)) != 0) {
fprintf(stderr
, "catman: %s: exit status %d\n",