blob: 6e2d2b8699703b61b492e66c00a4bdff44ac7b46 [file] [log] [blame]
micky3879b9f5e72025-07-08 18:04:53 -04001# $Id: manlinks.sed,v 1.21 2024/04/20 22:25:36 tom Exp $
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05302##############################################################################
micky3879b9f5e72025-07-08 18:04:53 -04003# Copyright 2020-2023,2024 Thomas E. Dickey #
4# Copyright 2000-2003,2008 Free Software Foundation, Inc. #
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05305# #
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#
micky3879b9f5e72025-07-08 18:04:53 -040034# workaround for manpages without a SYNOPSIS
35s/^\.\\"SH/.SH/
36#
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053037# eliminate formatting controls that get in the way
38/^'\\"/d
39/\.\\"/d
40/^\.br/d
41/^\.sp/d
42/typedef/d
43s/^\.IX//
44s/\\f.//g
micky3879b9f5e72025-07-08 18:04:53 -040045s/\\%//g
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053046s/[:,]/ /g
47#
micky3879b9f5e72025-07-08 18:04:53 -040048# ignore C-style comments
49s%/\*.*\*/%%
50#
51# Eliminate unnecessary whitespace, convert multiple blanks to single space.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053052s/^[ ][ ]*//
53s/[ ][ ]*$//
54s/[ ][ ]*/ /g
micky3879b9f5e72025-07-08 18:04:53 -040055/^$/d
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053056#
57# convert ".SH" into a more manageable form
58s/\.SH[ ][ ]*/.SH_(/
59#
60# in ".SH NAME"
micky3879b9f5e72025-07-08 18:04:53 -040061# 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/,/ \\-$/{
66s/\\-/-/g
67s/ / /g
68/ -$/{
69s/ -$//
70n
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053071d
72}
73s/ /\
74/g
75}
76#
77# in ".SH SYNOPSIS"
micky3879b9f5e72025-07-08 18:04:53 -040078# 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 Kachhape6a01f52011-07-20 11:45:59 +053083# then strip off return-type of each function.
micky3879b9f5e72025-07-08 18:04:53 -040084#
85# Finally, remove the parameter list, which begins with a '('.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053086/^\.SH_(SYNOPSIS/,/^\.SH_(DESCRIPTION/{
micky3879b9f5e72025-07-08 18:04:53 -040087/^\.ti/d
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053088/^[^(]*$/d
89# reduce
90# .B "int add_wch( const cchar_t *\fIwch\fB );"
91# to
92# add_wch( const cchar_t *\fIwch\fB );"
93s/^\([^ (]* [^ (]* [*]*\)//g
94s/^\([^ (]* [*]*\)//g
95# trim blanks in case we have
96# void (*) (FORM *) field_init(const FORM *form);
97s/) (/)(/g
98# reduce stuff like
99# void (*)(FORM *) field_init(const FORM *form);
100# to
101# field_init(const FORM *form);
102s/^\(([^)]*)\)\(([^)]*)\)*[ ]*//g
103# rename marker temporarily
104s/\.SH_(/.SH_/
105# kill lines with ");", and trim off beginning of argument list.
106s/[()].*//
107# rename marker back
108s/\.SH_/.SH_(/
109}
110#
111# delete ".SH DESCRIPTION" and following lines
112/^\.SH_(DESCRIPTION/,${
113d
114}
115#
116# delete any remaining directives
117/^\./d