#!/bin/sh [ -n "$BASH" ] || exec bash -p $0 $@ # Script to process man pages output by doxygen. # We need to use bash for its associative array facility. # (`bash -p` prevents import of functions from the environment). # Args: none or 2 being man7 page name & relative path of source with \mainpage declare -A renamed_page done_synopsis=false main(){ set -e # make_man7 has no dependencies or dependants so kick it off now [ $# -ne 2 ] || make_man7 $@ & pushd man/man3 >/dev/null; rm -f _* count_real_pages rename_real_pages # Nothing depends on make_symlinks so background it make_symlinks & post_process $@ wait } count_real_pages(){ page_count=0 # # Count "real" man pages (i.e. not generated by MAN_LINKS) # MAN_LINKS pages are 1-liners starting .so # Method: list files in descending order of size, # looking for the first 1-liner # for i in $(ls -S) do head -n1 $i | grep -E -q '^\.so' && break page_count=$(($page_count + 1)) done first_link=$(($page_count + 1)) } rename_real_pages(){ for i in $(ls -S | head -n$page_count) do j=$(ed -s $i <doxytmp cat >>doxytmp </dev/null # Remove SYNOPSIS line if there is one target=man/man7/$1.7 mygrep "SH SYNOPSIS" $target [ $linnum -eq 0 ] || delete_lines $linnum $((linnum+1)) # doxygen 1.8.9.1 and possibly newer run the first para into NAME # (i.e. in this unusual group). There won't be a SYNOPSIS when this happens if grep -Eq "overview$1" $target; then echo "Re-running doxygen $(doxygen --version)" ed -s temp.c << //// 2a * \\manonly .PP .SH "Detailed Description" .PP \\endmanonly . wq //// doxygen doxytmp >/dev/null fi rm temp.c doxytmp } # Insert top-level "See also" of man7 page in man3 page insert_see_also(){ mygrep "Detailed Description" $target [ $linnum -ne 0 ] || mygrep "Function Documentation" $target [ $linnum -ne 0 ] || { echo "NO HEADER IN $target" >&2; return; } ed -s $target <../$target.tmp while : do foundline=$(grep -En "^\\.RI" ../$target.tmp 2>/dev/null | head -n1) [ "$foundline" ] || break linnum=$(echo $foundline | cut -f1 -d:) # Discard this entry (and all previous lines) ed -s ../$target.tmp </dev/null | head -n1 | cut -f1 -d:) [ $linnum ] || linnum=0 } main $@