#!/bin/sh

set -xe

rm -Rf xlib-tutorial
test -e xlib-tutorial.tar.gz || \
   wget https://tronche.com/gui/x/xlib-tutorial/xlib-tutorial.tar.gz
tar xzvf xlib-tutorial.tar.gz

(
   cd xlib-tutorial

   # Probably requires GNU sed
   sed -i -E 's_(HREF=")/gui/x/xlib/([^"]+")_\1../xlib-manual/\2_g' *.html
   sed -i -E 's_(Unlike what appears in the )<A HREF="./">(dialog)</A>_\1\2_' 2nd-program-anatomy.html
   sed -i -E 's_(<A HREF=")(/web-directory)_\1https://tronche.com\2_' 2nd-program-anatomy.html

   # Most clients use the wrong menu type here, though ...
   sed -i -E 's_<A HREF="/gui/x/">_<A HREF="..">_' index.html

   for i in screen-and-root-window.html window-manager.html
   do
       echo 'This file never existed.' >"$i"
   done
)