I would like to search for POSIX functions matching the restrict
keyword and my idea (open to other ideas) is to search the SYNOPSIS sections of the POSIX Programmer's Manual for \<restrict\>
and to output matching lines. I know I can match sections with -S
and search man pages with -K
. How would I restrict searches to the POSIX Programmer's Manual? Is there a way to filter by "manual", i.e. by the centered text at the top of a man page?
1 Answer
The POSIX Programmer's Manual has its own dedicated sections in man
, namely 0p
(header files), 1p
(commands) and 3p
(functions). You can restrict your search to those sections:
[haxiel@testvm1 ~]$ man -k -s 0p,1p,3p mmap
mmap (3p) - map pages of memory
If you want to search the full text, replace the -k
option (apropos) with the -K
option (global apropos). By default, this will give you an interactive collection of all the man pages containing the search term (note that the first result opens up automatically, and is not in the list shown below).
[haxiel@testvm1 ~]$ man -K -s 0p,1p,3p 'restrict'
--Man-- next: cpio.h(0p) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]
--Man-- next: dirent.h(0p) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]
--Man-- next: dlfcn.h(0p) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]
--Man-- next: glob.h(0p) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]
--Man-- next: iconv.h(0p) [ view (return) | skip (Ctrl-D) | quit (Ctrl-C) ]
If you want only a list of matching pages, use the -w
(where) option instead.
[haxiel@testvm1 ~]$ man -K -w -s 0p,1p,3p 'restrict'
/usr/share/man/man0p/aio.h.0p.gz
/usr/share/man/man0p/cpio.h.0p.gz
/usr/share/man/man0p/dirent.h.0p.gz
/usr/share/man/man0p/dlfcn.h.0p.gz
/usr/share/man/man0p/glob.h.0p.gz
/usr/share/man/man0p/iconv.h.0p.gz
/usr/share/man/man0p/in.h.0p.gz
If you then decide to examine the iconv.h.0p.gz
man page from the results, you can do that by running man 0p iconv.h
.
The restrict
keyword appears in the POSIX Programmer's Manual in three different forms: const char *restrict
, char **restrict
, and char *const [restrict]
. We can update the man
command to search for these patterns using a regex:
man -K -w -s 0p,1p,3p --regex '(\*+|\[)restrict'
This will search for and return the man pages containing any of the above three forms.
-
There's a few false positives, for example cpio.h in your output, but still good enough for what I need :) Jan 6, 2019 at 19:08
-
1@rubystallion I've attempted to tighten up the search using a regex. Can you take a look at my edit and see if it works better now?– HaxielJan 7, 2019 at 12:23
-
-S
switch lets you limit your search to a list of sections of the manual. Part of the POSIX standard is distributed as a section of the manual and Haxiel's answer explains how to target it. On the other hand,SYNOPSIS
is usually a section of a man page (and I'm aware of no switches to limit your search to its content).