#!/bin/sh

set -u -e

tmp=..

if which tmexpand >/dev/null; then
    mkdir $tmp/hlp-new

    dpatch apply fix-documentation

    sed -n '/^%!%+/,/^%!%-/ {  /^%!%+/d; /^%!%-/ { s/.*/\\done/; }; s/^%//g; p; }' \
      lib/*.sl | tmexpand -Mslhlp - $tmp/hlp-new/libfuns.hlp
    cat doc/tm/rtl/*.tm | tmexpand -Mslhlp - $tmp/hlp-new/jedfuns.hlp

    dpkg-deb --fsys-tarfile ../jed-common* | \
      tar -C $tmp -x ./usr/share/doc/jed-common/hlp

    diff -ur $tmp/usr/share/doc/jed-common/hlp $tmp/hlp-new || true

    dpatch deapply fix-documentation
    rm -r ../hlp-new ../usr
else
    echo "tmexpand not found. Skipped uptodate hlp check"
fi
