1#!/bin/sh 2rcsid='$MirOS: src/bin/mksh/FAQ2HTML.sh,v 1.2 2020/10/31 04:17:36 tg Exp $' 3#- 4# Copyright © 2020 5# mirabilos <m@mirbsd.org> 6# 7# Provided that these terms and disclaimer and all copyright notices 8# are retained or reproduced in an accompanying document, permission 9# is granted to deal in this work without restriction, including un‐ 10# limited rights to use, publicly perform, distribute, sell, modify, 11# merge, give away, or sublicence. 12# 13# This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to 14# the utmost extent permitted by applicable law, neither express nor 15# implied; without malicious intent or gross negligence. In no event 16# may a licensor, author or contributor be held liable for indirect, 17# direct, other damage, loss, or other issues arising in any way out 18# of dealing in the work, even if advised of the possibility of such 19# damage or existence of a defect, except proven that it results out 20# of said person’s immediate fault when using the work as intended. 21#- 22 23set -e 24LC_ALL=C; LANGUAGE=C 25export LC_ALL; unset LANGUAGE 26nl=' 27' 28srcdir=$(dirname "$0") 29 30p=--posix 31sed $p -e q </dev/null >/dev/null 2>&1 || p= 32 33v=$1 34if test -z "$v"; then 35 v=$(sed $p -n '/^#define MKSH_VERSION "\(.*\)"$/s//\1/p' "$srcdir"/sh.h) 36fi 37src_id=$(sed $p -n '/^RCSID: /s///p' "$srcdir"/mksh.faq) 38# sanity check 39case $src_id in 40*"$nl"*) 41 echo >&2 "E: more than one RCSID in mksh.faq?" 42 exit 1 ;; 43esac 44 45sed $p \ 46 -e '/^RCSID: \$/s/^.*$/----/' \ 47 -e 's!@@RELPATH@@!http://www.mirbsd.org/!g' \ 48 -e 's^ <span style="display:none;"> </span>' \ 49 "$srcdir"/mksh.faq | tr '\n' '' | sed $p \ 50 -e 'sg' \ 51 -e 's----g' \ 52 -e 's\([^]*\)\1g' \ 53 -e 's\([^]*\)\1g' \ 54 -e 's\([^]*\)*ToC: \([^]*\)Title: \([^]*\)\([^]*\)\{0,1\}</div><h2 id="\2"><a href="#\2">\3</a></h2><div>g' \ 55 -e 's[^]*</div><div>g' \ 56 -e 's^</div>*' \ 57 -e 's$</div>' \ 58 -e 's<><error><>g' \ 59 -e 'sg' | tr '' '\n' >FAQ.tmp 60 61exec >FAQ.htm~ 62cat <<EOF 63<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 64 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 65<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head> 66 <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 67 <title>mksh $v FAQ (local copy)</title> 68 <meta name="source" content="$src_id" /> 69 <meta name="generator" content="$rcsid" /> 70 <style type="text/css"><!--/*--><![CDATA[/*><!--*/ 71 .boxhead { 72 margin-bottom:0px; 73 } 74 75 .boxtext { 76 border:4px ridge green; 77 margin:0px 24px 0px 18px; 78 padding:2px 3px 2px 3px; 79 } 80 81 .boxfoot { 82 margin-top:0px; 83 } 84 85 h2:before { 86 content:" "; 87 } 88 89 a[href^="ftp://"]:after, 90 a[href^="http://"]:after, 91 a[href^="https://"]:after, 92 a[href^="irc://"]:after, 93 a[href^="mailto:"]:after, 94 a[href^="news:"]:after, 95 a[href^="nntp://"]:after { 96 content:"⏍"; 97 color:#FF0000; 98 vertical-align:super; 99 margin:0 0 0 1px; 100 } 101 102 pre { 103 /* ↑ → ↓ ← */ 104 margin:0px 9px 0px 15px; 105 } 106 107 tt { 108 white-space:nowrap; 109 } 110 /*]]>*/--></style> 111</head><body> 112<p>Note: Links marked like <a href="irc://chat.freenode.net/!/bin/mksh">this 113 one to the mksh IRC channel</a> connect to external resources.</p> 114<p>⚠ <b>Notice:</b> the website will have <a 115 href="http://www.mirbsd.org/mksh-faq.htm">the latest version of the 116 mksh FAQ</a> online.</p> 117<h1>Table of Contents</h1> 118<ul> 119EOF 120sed $p -n \ 121 '/^<h2 id="\([^"]*"\)><a[^>]*\(>.*<\/a><\/\)h2>$/s//<li><a href="#\1\2li>/p' \ 122 <FAQ.tmp 123cat <<EOF 124</ul> 125 126<h1>Frequently Asked Questions</h1> 127EOF 128cat FAQ.tmp - <<EOF 129<h1>Imprint</h1> 130<p>This offline HTML page for mksh $v was automatically generated 131 from the sources.</p> 132</body></html> 133EOF 134exec >/dev/null 135rm FAQ.tmp 136mv FAQ.htm~ FAQ.htm 137