gnulib-tool: Omit the logs of skipped tests from test-suite.log.
[gnulib.git] / doc / glibc-functions / add-links.sh
blob5f081efd0e76cab4298ac05026eea0e170a99637
1 #!/bin/sh
2 # Adds the reference to the Glibc documentation and to the Linux manual page
3 # to the file foo.texi.
4 # Usage: add-links.sh foo.texi
6 case "$1" in
7 *.texi)
8 f="$1"
9 g="${f%.texi}"
10 glibc_inforef=
11 glibc_link=
12 if test -f _index.html \
13 || { wget -O _index1.html https://www.gnu.org/software/libc/manual/html_node/Function-Index.html \
14 && wget -O _index2.html https://www.gnu.org/software/libc/manual/html_node/Variable-Index.html \
15 && cat _index1.html _index2.html > _index.html; \
16 }; then
17 glibc_page=`sed -n -e "s|^.*<a href=\"\([^\"]*\)\"><code>$g</code></a>.*|\1|p" < _index.html | sed -s 's/#.*//'`
18 if test -n "$glibc_page"; then
19 glibc_page_title=`wget -O - "https://www.gnu.org/software/libc/manual/html_node/$glibc_page" 2>/dev/null | sed -n -e 's/^.*<h[1-4][^>]*>[0-9. ]*\(.*\)<\/h.*/\1/p' | sed -e 's|<[^>]*>||g' -e 's|,||g' | head -n 1`
20 if test -n "$glibc_page_title"; then
21 glibc_node=`echo "$glibc_page" | sed -e 's/\.html$//' -e 's/_/\\\\u/g' -e 's/\\u00\([0-7]\)/\\x\1/g' -e 's/-/ /g'`
22 # Avoid the broken built-in 'printf' in the dash shell.
23 glibc_node=`/usr/bin/printf "$glibc_node" 2>/dev/null || printf "$glibc_node"`
24 glibc_inforef="@ref{$glibc_node,,$glibc_page_title,libc}"
25 glibc_link="@url{https://www.gnu.org/software/libc/manual/html_node/$glibc_page}"
26 else
27 echo "failed to determine page title of https://www.gnu.org/software/libc/manual/html_node/$glibc_page"
29 else
30 echo $f not documented in glibc manual
32 else
33 echo "failed to fetch glibc index"
35 manpages_link=
36 if wget https://www.kernel.org/doc/man-pages/online/pages/man3/${g}.3.html >/dev/null 2>&1; then
37 manpages_link="@uref{https://www.kernel.org/doc/man-pages/online/pages/man3/${g}.3.html,,man ${g}}"
38 else
39 if wget https://www.kernel.org/doc/man-pages/online/pages/man2/${g}.2.html >/dev/null 2>&1; then
40 manpages_link="@uref{https://www.kernel.org/doc/man-pages/online/pages/man2/${g}.2.html,,man ${g}}"
41 else
42 echo $f not documented among the man pages
45 if test -n "$glibc_link"; then
46 if test -n "$manpages_link"; then
47 documentation="Documentation:\n\
48 @itemize\n\
49 @item\n\
50 @ifinfo\n\
51 $glibc_inforef,\n\
52 @end ifinfo\n\
53 @ifnotinfo\n\
54 $glibc_link,\n\
55 @end ifnotinfo\n\
56 @item\n\
57 $manpages_link.\n\
58 @end itemize"
59 else
60 documentation="Documentation:@*\n\
61 @ifinfo\n\
62 $glibc_inforef.\n\
63 @end ifinfo\n\
64 @ifnotinfo\n\
65 $glibc_link.\n\
66 @end ifnotinfo"
68 else
69 if test -n "$manpages_link"; then
70 documentation="Documentation:@* $manpages_link"
71 else
72 documentation=
75 if test -n "$documentation"; then
76 mv ${f} ${f}~
77 if cat ${f}~ | sed -e '/^Documentation:/,/^$/d' | sed -e "s|^Gnulib module|$documentation\n\
78 \n\
79 Gnulib module|" > ${f}; then
80 echo $f updated
81 else
82 echo $f update failed
83 mv ${f}~ ${f}
87 *) echo "invalid argument: $1" 1>&2 ;;
88 esac