#!/bin/sh

# Copyright © 2015 Jakub Wilk <jwilk@jwilk.net>
#
# This file is part of pdf2djvu.
#
# pdf2djvu is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# pdf2djvu is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

set -e -u

usage()
{
    printf '%s [--lang] <src> <dst>\n' "$0"
}

here=$(dirname "$0")
args=$(getopt -n "$0" -o 'h' --long 'help,lang' -- "$@")
eval set -- "$args"
opt_lang=
while true
do
    case "$1" in
        -h|--help) usage; exit 0;;
        --lang) opt_lang=y; shift;;
        --) shift; break;;
        *) printf '%s: internal error (%s)\n' "$0" "$1" >&2; exit 1;;
    esac
done
[ $# -eq 2 ] || { usage; exit 1; }
src="$1"
dst="$2"
xsl=http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl
xmllint='xmllint --valid --noout --nonet'
xsltproc='xsltproc --nonet --param man.charmap.use.subset 0'
[ -n "$opt_lang" ] && xsltproc="$xsltproc --param man.output.lang.in.name.enabled 1"
PS4='$ '
set -x
$xmllint "$src"
$xsltproc "$xsl" "$src"
$here/fix-manpage "$dst"

# vim:ts=4 sts=4 sw=4 et
