From 67ad50492dc882e3ebefded4ab3fe74d03059a72 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Tue, 1 Sep 2020 20:33:42 +0900 Subject: [PATCH] doc/man: Add script for crosslinking of generated HTML documentation --- doc/man/Makefile | 19 ++++++++++++++----- doc/man/linkify.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 5 deletions(-) create mode 100755 doc/man/linkify.sh diff --git a/doc/man/Makefile b/doc/man/Makefile index 0790b40..0f8a141 100644 --- a/doc/man/Makefile +++ b/doc/man/Makefile @@ -1,12 +1,21 @@ -HTMLFILES = paging.html -PHONY = +HTMLFILES = memory.10.html +PHONY = clean all: $(HTMLFILES) clean: - rm -f $(HTMLFILES) + rm -f $(HTMLFILES) *.png .PHONY: $(PHONY) -%.html: %.9 - groff -mandoc -Thtml $< > $@ +%.0.html: %.0 + groff -mandoc -tbl -Thtml $< > $@ + ./linkify.sh $@ + +%.9.html: %.9 + groff -mandoc -tbl -Thtml $< > $@ + ./linkify.sh $@ + +%.10.html: %.10 + groff -mandoc -tbl -Thtml $< > $@ + ./linkify.sh $@ diff --git a/doc/man/linkify.sh b/doc/man/linkify.sh new file mode 100755 index 0000000..59c15b9 --- /dev/null +++ b/doc/man/linkify.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# collect the name of all pages +pages=() + +while read -r page; do + pages+=("$(basename "$page")") +done < <(find . -name "*.0" -or -name "*.9" -or -name "*.10" -type f) + +# Iterate over all pages, inserting links to those pages that actually exist. I used a simple +# regex for this at first, but this would also insert links for pages that don't exist, which +# is not what we want since there is stuff like "hoge(0)" and references to not-yet-existing +# articles. + +for ((i=1; i<="$#"; i++)); do + manpage="${!i}" + + for page in "${pages[@]}"; do + pn=$(echo "$page" | cut -d '.' -f 1) + ps=$(echo "$page" | cut -d '.' -f 2) + + sed -i -e "s|$pn($ps)|$pn($ps)|g" "$manpage" + done +done + +exit 0 -- 2.47.3