Created attachment 217939 [details]
Honor MANSECT and -S section-list when matching section names
man(1) relies on the default list of manual sections when determining whether an argument is a section name, completely ignoring the MANSECT environment variable and the sections listed in the argument to the -S option.
I encountered this behavior when trying to determine why
man -S '1:3p' '3p' printf
would open printf(1) instead of printf(3p) after installing man-pages-posix, yet
man -S '3p' printf
Attached is a patch that ensures the section list provided by either the -S option (which sets the MANSECT shell variable) or the MANSECT environment variable is searched if they don't expand to an empty string, else the default section list is searched. It intentionally avoids setting the MANSECT shell variable since that's taken care of later by the man_setup() function.