* Copyright (c) 1990, 1991, John W. Eaton.
* You may distribute under the terms of the GNU General Public
* License as specified in the file COPYING that comes with the man
* Department of Chemical Engineering
* The University of Texas at Austin
extern int is_directory ();
* Examine user's PATH and print a reasonable MANPATH.
extern char *mkprogname ();
prognam
= mkprogname (argv
[0]);
while ((c
= getopt (argc
, argv
, "dhq?")) != EOF
)
fprintf (stdout
, "%s\n", mp
);
fprintf (stderr
, "usage: %s [-q]\n", prognam
);
* If the environment variable MANPATH is set, return it.
* If the environment variable PATH is set and has a nonzero length,
* try to determine the corresponding manpath, otherwise, return the
* The manpath.config file is used to map system wide /bin directories
* to top level man page directories.
* For directories which are in the user's path but not in the
* manpath.config file, see if there is a subdirectory `man' or `MAN'.
* If so, add that directory to the path. Example: user has
* $HOME/bin in his path and the directory $HOME/bin/man exists -- the
* directory $HOME/bin/man will be added to the manpath.
register char *manpathlist
;
gripe_reading_mp_config ();
if ((manpathlist
= getenv ("MANPATH")) != NULL
)
fprintf (stderr
, "(Warning: MANPATH environment variable set)\n");
return strdup (manpathlist
);
else if ((path
= getenv ("PATH")) == NULL
)
* Things aren't going to work well, but hey...
fprintf (stderr
, "Warning: path not set\n");
if ((len
= strlen (path
)) == 0)
* Things aren't going to work well here either...
fprintf (stderr
, "Warning: path set but has zero length\n");
return get_manpath (perrs
, path
);
* Get the list of bin directories and the corresponding man
* directories from the manpath.config file.
if ((config
= fopen (config_file
, "r")) == NULL
)
gripe_getting_mp_config (config_file
);
while ((bp
= fgets (buf
, BUFSIZ
, config
)) != NULL
)
while (*bp
&& (*bp
== ' ' || *bp
== '\t'))
if (*bp
== '#' || *bp
== '\n')
if (!strncmp ("MANBIN", bp
, 6))
if (!strncmp ("MANDATORY_MANPATH", bp
, 17))
if ((p
= strchr (bp
, ' ')) == NULL
)
if ((p
= strchr (bp
, '\t')) == NULL
)
while (*bp
&& *bp
!= '\n' && (*bp
== ' ' || *bp
== '\t'))
while (*bp
&& *bp
!= '\n' && *bp
!= ' ' && *bp
!= '\t')
dlp
->mandir
[i
++] = *bp
++;
fprintf (stderr
, "found mandatory man directory %s\n",
else if (!strncmp ("MANPATH_MAP", bp
, 11))
if ((p
= strchr (bp
, ' ')) == NULL
)
if ((p
= strchr (bp
, '\t')) == NULL
)
while (*bp
&& *bp
!= '\n' && (*bp
== ' ' || *bp
== '\t'))
while (*bp
&& *bp
!= '\n' && *bp
!= ' ' && *bp
!= '\t')
while (*bp
&& *bp
!= '\n' && (*bp
== ' ' || *bp
== '\t'))
while (*bp
&& *bp
!= '\n' && *bp
!= ' ' && *bp
!= '\t')
dlp
->mandir
[i
++] = *bp
++;
fprintf (stderr
, "found manpath map %s --> %s\n",
gripe_reading_mp_config ();
* Construct the default manpath. This picks up mandatory manpaths
register char *manpathlist
, *p
;
while (dlp
->mandatory
!= 0)
len
+= strlen (dlp
->mandir
) + 1;
manpathlist
= (char *) malloc (len
);
gripe_alloc (len
, "manpathlist");
while (dlp
->mandatory
!= 0)
char *path
= dlp
->mandir
;
status
= is_directory(path
);
fprintf (stderr
, "Warning: couldn't stat file %s!\n", path
);
else if (status
== 0 && perrs
)
fprintf (stderr
, "Warning: standard directory %s doesn't exist!\n",
* For each directory in the user's path, see if it is one of the
* directories listed in the manpath.config file. If so, and it is
* not already in the manpath, add it. If the directory is not listed
* in the manpath.config file, see if there is a subdirectory `man' or
* `MAN'. If so, and it is not already in the manpath, add it.
* Example: user has $HOME/bin in his path and the directory
* $HOME/bin/man exists -- the directory $HOME/bin/man will be added
get_manpath (perrs
, path
)
register char *manpathlist
;
for (p
= tmppath
; ; p
= end
+1)
if (end
= strchr(p
, ':'))
fprintf (stderr
, "\npath directory %s ", p
);
* The directory we're working on is in the config file.
* If we haven't added it to the list yet, do.
for (dlp
= list
; dlp
->mandir
[0] != '\0'; dlp
++)
if (dlp
->bin
[0] != '\0' && !strcmp (p
, dlp
->bin
))
fprintf (stderr
, "is in the config file\n");
add_dir_to_list (tmplist
, dlp
->mandir
, perrs
);
* The directory we're working on isn't in the config file. See
* if it has man or MAN subdirectories. If so, and it hasn't
* been added to the list, do.
fprintf (stderr
, "is not in the config file\n");
fprintf (stderr
, "but it does have a man or MAN subdirectory\n");
add_dir_to_list (tmplist
, t
, perrs
);
fprintf (stderr
, "and doesn't have man or MAN subdirectories\n");
fprintf (stderr
, "\nadding mandatory man directories\n\n");
while (dlp
->mandatory
!= 0)
add_dir_to_list (tmplist
, dlp
->mandir
, perrs
);
manpathlist
= (char *) malloc (len
);
gripe_alloc (len
, "manpathlist");
* Add a directory to the manpath list if it isn't already there.
add_dir_to_list (lp
, dir
, perrs
)
fprintf (stderr
, "%s is already in the manpath\n", dir
);
status
= is_directory(dir
);
fprintf (stderr
, "Warning: couldn't stat file %s!\n", dir
);
else if (status
== 0 && perrs
)
fprintf (stderr
, "Warning: %s isn't a directory!\n", dir
);
fprintf (stderr
, "adding %s to manpath\n", dir
);
* Check to see if the current directory has man or MAN
t
= (char *) malloc ((unsigned) len
+ 5);
gripe_alloc (len
+5, "p\n");
strcpy (t
+ len
, "/man");
if (is_directory (t
) == 1)
strcpy (t
+ len
, "/MAN");
if (is_directory (t
) == 1)