#!/bin/sh
# /TR 2020-06-08

# lib version
ZSTDMT="v0.7"

function generate() {
 PROGNAME="$1"
 ALGORITHM="$2"
 LMIN="$3"
 LMAX="$4"
 LDEF="$5"
 VERSION="$6"
 SUFFIX="$7"
 HOMEPAGE="$8"

 if [ $LMAX == 0 ]; then
   LEVELNUMBERS=""
 else
   LEVELNUMBERS="1234567890"
 fi

 if [ $ALGORITHM == "lizard" ]; then
   LEVELNOTES=`printf "%q" "
.TP
.BI -10..-19
fastLZ4: designed to give better decompression speed than LZ4 i.e. over 2000 MB/s
.TP
.BI -20..-29
LIZv1: designed to give better ratio than LZ4 keeping 75% decompression speed
.TP
.BI -30..-39
fastLZ4 + Huffman: Huffman coding to fastLZ4
.TP
.BI -40..-49
LIZv1 + Huffman: give the best ratio at decompression speed of 1000 MB/s
.br
The default is -3"`
   LEVELNOTES=${LEVELNOTES:2:-1}
 elif [ $ALGORITHM == "snappy" ]; then
   LEVELNOTES=""
 else
   LEVELNOTES=`printf "%q" "
.TP
.BI -$LMIN..$LMAX
Use the compression method with a level -$LMIN to -$LMAX.
.br
Compression level -$LMIN is the fastest, but provides a poorer level
of compression.
.br
Compression level -$LMAX provides the best level of compression, but is
also the slowest.
.br
The default is -$LDEF"`
   LEVELNOTES=${LEVELNOTES:2:-1}
 fi

 cat generic.man | sed \
 -e "s|%PROGNAME%|$PROGNAME|g" \
 -e "s|%ALGORITHM%|$ALGORITHM|g" \
 -e "s|%VERSION%|$VERSION|g" \
 -e "s|%SUFFIX%|$SUFFIX|g" \
 -e "s|%HOMEPAGE%|$HOMEPAGE|g" \
 -e "s|%ZSTDMT%|$ZSTDMT|g" \
 -e "s|%LEVELNUMBERS%|$LEVELNUMBERS|g" \
 -e "s|%LEVELNOTES%|$LEVELNOTES|g" \
 > "$PROGNAME.1"
}

#         progname    algo     min max def version   suffix homepage
generate "brotli-mt" "brotli"  0   11  3   "v1.0.7"  "brot" "https://github.com/google/brotli"
generate "lizard-mt" "lizard"  10  49  3   "v2.0"    "liz"  "https://github.com/inikep/lizard"
generate "lz4-mt"    "lz4"     1   12  3   "v1.8.3"  "lz4"  "https://github.com/lz4/lz4"
generate "lz5-mt"    "lz5"     1   15  3   "v1.5"    "lz5"  "https://github.com/inikep/lz5"
generate "zstd-mt"   "zstd"    1   22  3   "v1.3.7"  "zst"  "https://github.com/facebook/zstd"
generate "snappy-mt" "snappy"  0    0  0   "v0.0.0"  "snp"  "https://github.com/andikleen/snappy-c"
