Skip to content

Instantly share code, notes, and snippets.

@yiding
Last active October 29, 2022 18:20
Show Gist options
  • Save yiding/11270916 to your computer and use it in GitHub Desktop.
Save yiding/11270916 to your computer and use it in GitHub Desktop.
Man pages on OSX + Xcode Developer tools

OSX's man utility has custom patches to allow finding man pages from installed Xcode SDKs.

#ifdef __APPLE__
	xcselect_manpaths *xcp;
	const char *path;
	unsigned i, count;

	// TODO: pass something for sdkname
	xcp = xcselect_get_manpaths(NULL);
	if (xcp != NULL) {
		count = xcselect_manpaths_get_num_paths(xcp);
		for (i = 0; i < count; i++) {
			path = xcselect_manpaths_get_path(xcp, i);
			if (path != NULL) {
				add_to_mandirlist((char *)path, perrs);
			}
		}
		xcselect_manpaths_free(xcp);
	}
#endif /* __APPLE__ */

Source: http://www.opensource.apple.com/source/man/man-16/patches/PR11291804-xcode.diff


Curiously, this and other "magical" search paths only activate if your MANPATH contains the empty path.

MANPATH=/foo/bar/baz   # nope
MANPATH=/foo/bar/baz:  # yep!

Source: http://www.opensource.apple.com/source/man/man-16/man/src/manpath.c

static void
to_mandirlist(char *s, int perrs) {
     char *path;

     if (*s) {
	  add_to_mandirlist (s, perrs);
     } else {
	  /* empty substring: insert default path */
	  if((path = getenv ("PATH")) != NULL)
	       split (path, get_manpath_from_pathdir, perrs);
	  add_default_manpath (perrs);
     }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment