#!/bin/sh
##
##  lesspipe -- input filter for less(1)
##  To use: ``export LESSOPEN="|lesspipe %s"''
##

file="$1"
base="$file"
filter=""
while [ 1 ]; do
    ext=`expr "$base" : '.*\.\([^.]*\)$'`
    base=`expr "$base" : '\(.*\)\.[^.]*$'`
    case $ext in
        gz|z|Z )
            filter="$filter | gzip -d -c"
            ;;
        bz2 )
            filter="$filter | bzip2 -d -c"
            ;;
        [1-9n]|man )
            case `uname -s` in
                FreeBSD) macro='mandoc' ;; # detects man(7) and mdoc(7)
                *      ) macro='man'    ;; # only man(7)
            esac
            filter="$filter | nroff -$macro"
            break
            ;;
        tar ) 
            filter="$filter | tar tvf -"
            break
            ;;
        cpio ) 
            filter="$filter | cpio -it"
            break
            ;;
        rpm )
            filter="$filter | @l_prefix@/bin/openpkg rpm -qpilv --scripts -- -"
            break
            ;;
        * )
            break
            ;;
    esac
done
if [ ".$filter" != . ]; then
    echo "[LESS INPUT FILTER APPLIED: \"$filter\"]"
fi
eval "cat \"$file\" $filter"

