# Takes a local man page and makes a text, pdf and html version of it.
# If no file name given, uses SkantiControl.1
# Formats the output for a 80 columns screen
# Usage: makemanuals [<man page file>]
# Output: Manual-en.txt, Manual.en.pdf and Manual-en.html.
# I1EPJ 2021

#!/bin/bash

if test "$1" = ""; then
    MANNAME="../man/en/SkantiControl.1"
else
    MANNAME=$1
fi

echo Making text, pdf and html versions of $MANNAME man page...

echo Writing Manual-en.txt...
export COLUMNS=80; man -l $MANNAME | col -b -x > ../doc/Manual-en.txt
# Get rid of extra spaces around punctuation
sed -i 's/ \. /\. /g' ../doc/Manual-en.txt
sed -i 's/ \.$/\./g' ../doc/Manual-en.txt
sed -i 's/ , /\, /g' ../doc/Manual-en.txt

echo Writing Manual-en.pdf...
export COLUMNS=80; man -t -l $MANNAME | ps2pdf - ../doc/Manual-en.pdf

echo Writing Manual-en.html...
export COLUMNS=80; man -l -Thtml $MANNAME > ../doc/Manual-en.html

echo Done!
