micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 1 | # $Id: manlinks.sed,v 1.21 2024/04/20 22:25:36 tom Exp $ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 2 | ############################################################################## |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 3 | # Copyright 2020-2023,2024 Thomas E. Dickey # |
| 4 | # Copyright 2000-2003,2008 Free Software Foundation, Inc. # |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 5 | # # |
| 6 | # Permission is hereby granted, free of charge, to any person obtaining a # |
| 7 | # copy of this software and associated documentation files (the "Software"), # |
| 8 | # to deal in the Software without restriction, including without limitation # |
| 9 | # the rights to use, copy, modify, merge, publish, distribute, distribute # |
| 10 | # with modifications, sublicense, and/or sell copies of the Software, and to # |
| 11 | # permit persons to whom the Software is furnished to do so, subject to the # |
| 12 | # following conditions: # |
| 13 | # # |
| 14 | # The above copyright notice and this permission notice shall be included in # |
| 15 | # all copies or substantial portions of the Software. # |
| 16 | # # |
| 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # |
| 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # |
| 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # |
| 20 | # THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # |
| 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # |
| 22 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # |
| 23 | # DEALINGS IN THE SOFTWARE. # |
| 24 | # # |
| 25 | # Except as contained in this notice, the name(s) of the above copyright # |
| 26 | # holders shall not be used in advertising or otherwise to promote the sale, # |
| 27 | # use or other dealings in this Software without prior written # |
| 28 | # authorization. # |
| 29 | ############################################################################## |
| 30 | # Given a manpage (nroff) as input, writes a list of the names that are |
| 31 | # listed in the "NAME" section, i.e., the names that we would like to use |
| 32 | # as aliases for the manpage -T.Dickey |
| 33 | # |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 34 | # workaround for manpages without a SYNOPSIS |
| 35 | s/^\.\\"SH/.SH/ |
| 36 | # |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 37 | # eliminate formatting controls that get in the way |
| 38 | /^'\\"/d |
| 39 | /\.\\"/d |
| 40 | /^\.br/d |
| 41 | /^\.sp/d |
| 42 | /typedef/d |
| 43 | s/^\.IX// |
| 44 | s/\\f.//g |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 45 | s/\\%//g |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 46 | s/[:,]/ /g |
| 47 | # |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 48 | # ignore C-style comments |
| 49 | s%/\*.*\*/%% |
| 50 | # |
| 51 | # Eliminate unnecessary whitespace, convert multiple blanks to single space. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 52 | s/^[ ][ ]*// |
| 53 | s/[ ][ ]*$// |
| 54 | s/[ ][ ]*/ /g |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 55 | /^$/d |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 56 | # |
| 57 | # convert ".SH" into a more manageable form |
| 58 | s/\.SH[ ][ ]*/.SH_(/ |
| 59 | # |
| 60 | # in ".SH NAME" |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 61 | # Convert a list of names separated from their description by " \-" to a list |
| 62 | # of names on separate lines. Normally the list is also comma-separated, but |
| 63 | # we ignore that detail here. The description is on a separate line to make |
| 64 | # the nroff source more pleasing to some eyes. |
| 65 | /^\.SH_(NAME/,/ \\-$/{ |
| 66 | s/\\-/-/g |
| 67 | s/ / /g |
| 68 | / -$/{ |
| 69 | s/ -$// |
| 70 | n |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 71 | d |
| 72 | } |
| 73 | s/ /\ |
| 74 | /g |
| 75 | } |
| 76 | # |
| 77 | # in ".SH SYNOPSIS" |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 78 | # For readability, the NAME section may not contain all function names, but we |
| 79 | # still want to make aliases for those. Do this by extracting names from the |
| 80 | # list of function prototypes in the synopsis. |
| 81 | # |
| 82 | # Remove any line that does not contain a '(', since we only want functions. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 83 | # then strip off return-type of each function. |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 84 | # |
| 85 | # Finally, remove the parameter list, which begins with a '('. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 86 | /^\.SH_(SYNOPSIS/,/^\.SH_(DESCRIPTION/{ |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 87 | /^\.ti/d |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 88 | /^[^(]*$/d |
| 89 | # reduce |
| 90 | # .B "int add_wch( const cchar_t *\fIwch\fB );" |
| 91 | # to |
| 92 | # add_wch( const cchar_t *\fIwch\fB );" |
| 93 | s/^\([^ (]* [^ (]* [*]*\)//g |
| 94 | s/^\([^ (]* [*]*\)//g |
| 95 | # trim blanks in case we have |
| 96 | # void (*) (FORM *) field_init(const FORM *form); |
| 97 | s/) (/)(/g |
| 98 | # reduce stuff like |
| 99 | # void (*)(FORM *) field_init(const FORM *form); |
| 100 | # to |
| 101 | # field_init(const FORM *form); |
| 102 | s/^\(([^)]*)\)\(([^)]*)\)*[ ]*//g |
| 103 | # rename marker temporarily |
| 104 | s/\.SH_(/.SH_/ |
| 105 | # kill lines with ");", and trim off beginning of argument list. |
| 106 | s/[()].*// |
| 107 | # rename marker back |
| 108 | s/\.SH_/.SH_(/ |
| 109 | } |
| 110 | # |
| 111 | # delete ".SH DESCRIPTION" and following lines |
| 112 | /^\.SH_(DESCRIPTION/,${ |
| 113 | d |
| 114 | } |
| 115 | # |
| 116 | # delete any remaining directives |
| 117 | /^\./d |