#!/bin/ksh
#
# This script only works with packages built for Slackware 8.1 or higher
# since it relies on the new naming scheme (NAME-VERSION-ARCH-BUILD)
#

# This is the rewritten version (II) of listpkg 
# 
# 0.0.1   04.02.2005  Initial version
#
# 0.0.2   10.02.2005
#       - added version information (II_0.0.2)
#       - archivepkg (-z) and checkpkg (-c) added but not functional
#       - package list given on the command line is not handled correctly
#
# 0.0.3   11.02.2005
#       - format of /tmp/pkginfo changed from PKGNAME VERSION ARCH BUILD
#         to COMPLETE_NAME:PKGNAME:VERSION:ARCH:BUILD
#       - correct handling of the package list given on the commandline,
#         no asterisk
#
# 0.0.4   17.02.2005
#       - 666 auf /tmp/pkginfo
#
# 0.0.5   23.02.2005
#       - basic asterisk handling (buggy!)
#       - option -p implemented
#
# 0.0.10  09.11.2008
#       - now handling ':' in package description correctly
# 
# 0.0.20  04.08.2011
#       - can report installation date of a package
#       - -z, -a call external programm if existent
#
# 0.0.21  27.08.2011
#       - fixed a problem in handling '+' in package names
#
# 0.0.30  09.02.2013
#       - changed to ksh ('cos bash still can't read from a pipe)
#       - repository information included in output
#
# 0.0.40  02.11.2013
#       - partly rewritten to make a more modular usage possible
#
# 0.0.41  02.11.2013
#       - bugfix in getopts
#       - additions to repository db

# Author: Armin Meyer-Larsen

MYNAME=$(basename $0)
PKGROOT=${PKGROOT:-/}
PKGVER=45 # our version
CR_DATE="2013-11-22.12:42 CET"  # date '+%Y-%m-%d.%H:%M %Z'

# Data
# ====
PRINTHEADER="yes"
header_vers="VERSION              "
header_build="BUILD  "
header_arch="ARCH   "
header_repo="REPOSITORY                "
header_size="  SIZE (kB)  "
header_zsize=" zSIZE (kB)  "
header_date="INSTALLATION DATE    "
header_desc="DESCRIPTION"
ul_vers="====================="
ul_build="========"
ul_arch="======="
ul_repo="============================="
ul_size="============"
ul_zsize="==========="
ul_date="====================="
ul_desc="======================================================="


# FEXIT
# =====
fexit()
{
 RC=${RC:-$ERR_NSET}
 cd $RCWD
 exit $RC
}

trap fexit 1 2 3 14 15 19

# Read config
# ===========
CONFIGPATH=$CONFIGPATH:/etc:/usr/local/etc:/etc/slack-pkg
for i in $(echo $CONFIGPATH | sed -e 's/:/ /g')
do
  [ -r $i/slack-pkgrc ] && . $i/slack-pkgrc
done


# Where to find Slackware's package information
# =============================================
SLACKDB=${SLACKDB:-/var/log/packages}
SLACKSCRIPTDIR=${SLACKSCRIPTDIR:-/var/log/scripts}

SLACK_PKG=/usr/local/sbin/slack-pkg
TMP=${TMP:-/tmp}


# Return-Codes
# ============
OK=${OK:-0}
ERR_UNKN=${ERR_UNKN:-255}
ERR_DIST=${ERR_UNKN:-127}
ERR_NSET=${ERR_NSET:-254}
ERR_OPT=${ERR_OPT:-1}
ERR_ARG=${ERR_ARG:-2}
ERR_PKG=${ERR_PKG:-3}


# Asterisk
# ========
 if [ ! -d ${TMP}/.slackpkg/.leerdir ]
 then
   rm -rf ${TMP}/.slackpkg/.leerdir
   mkdir -p ${TMP}/.slackpkg/.leerdir
 fi
 RCWD=$PWD
 cd ${TMP}/.slackpkg/.leerdir


# Slackware-Version
# =================
if [ -f /etc/slackware-version ]
then
  SLACKVERSION=$(cat ${PKGROOT}/etc/slackware-version | cut -d" " -f2)
else
  printf "\n $MYNAME: Cannot determine your Slackware version\n Exiting...\n\n" 1>&2
  cd $RCWD ; exit $ERR_DIST
fi


### I. Functions

# CLEAR_ALL_FLAGS
clear_all_flags()
{
 H_VERS=""  ; VU="" ; F_VERS=""
 H_BUILD="" ; HU="" ; F_BUILD=""
 H_ARCH=""  ; AU="" ; F_ARCH=""
 H_REPO=""  ; RU="" ; F_REPO=""
 H_SIZE=""  ; SU="" ; F_SIZE=""
 H_DATE=""  ; DU="" ; F_DATE=""
 H_DESC=""  ; PU="" ; F_DESC=""
}

# PKGINFO()
pkginfo()
{
 echo -n Reading Package Information...

 CWD=$PWD

 cd $PKGROOT/$SLACKDB
 # We silently suppress entries that do not follow the new naming scheme ...
 for i in $(find . -name '*-*-*-*' )
 do 
   printf "%s:%s:%s:%s:%s\n" $(echo $i | sed -e 's#^\./##g') $(echo $i | sed -e 's#./\(.*\)-\(.*\)-\(.*\)-\(.*\)#\1 \2 \3 \4#')
 done | sed -e 's#\(:[0-9]*\)\([^:]*\)$#\1:\2#' | sort > ${TMP}/pkginfo
 _RC=$?

 chmod 666 ${TMP}/pkginfo 2>/dev/null
 echo done

 cd $CWD
 return $_RC
}


# FHELP()
# =======
fhelp()
{
 echo
 echo " Usage:"
 echo " ------"
 echo " $MYNAME [ -C ] [ -H ] [ -a ] [ -b ] [ -d ] [ -p ] [ -r ] [ -s | -S ] [ -v ] [ -x | -X ] [ PKG1 [ PKG2 [...] ] ]"
 echo " $MYNAME [ -A | -i | -l | -P ]  PKG"
 echo " $MYNAME { -w | -f } FILE"
 echo " $MYNAME -h | -u | -V"
 echo
 echo " Options:"
 echo " --------"
 echo " -A | --all                  display all known information of PKG"
 echo " -a | --arch                 include architecture information in the output"
 echo " -b | --build                include build number information in the output"
 echo " -C | --clear                clear all defaults"
 echo " -d | --date                 include installation date information in the output"
 echo " -f | --find-file            find package containing file(s)"
 echo " -H | --noheader             don't print the header line"
 echo " -h | --help                 print this usage information"
 echo " -i | --install-script       display install script of PKG"
 echo " -l | --list                 list files in PKG"
 echo " -P | --package-description  display description of PKG"
 echo " -p | --short-description    include a short package description in the output"
 echo " -r | --repository           include package source information in the output"
 echo " -s | --size                 include installation size in the output"
 echo " -S | --compressed-size      include download size in the output"
 echo " -u | --force-update         force update of package information cache"
 echo " -V | --version              print version information of $MYNAME"
 echo " -v | --pversion             include version information in the output"
 echo " -w | --whereis              same as -f"
 echo " -x | --extended             same as -a -b -d -p -r -s -v"
 echo
}


# F_ARGERROR
# ==========
# required variables: OPT
fargerror()
{
 printf "\n $MYNAME: Option $OPT requires an argument\n\n" 
 return $ERR_ARG
}


# F_PKGERR
# ========
# required variables: WHATPKG
fpkgerr()
{
 printf "\n $MYNAME: Package ${WHATPKG} not installed.\n\n" 1>&2
 return $ERR_PKG
}


# PRINTHEADER()
# =============
printheader()
{
 [ "$PRINTHEADER" = "yes" ] || return 0
 echo
 echo "Path: $SLACKDB"
 printf "\n  PACKAGE                         $H_VERS$H_ARCH$H_BUILD$H_SIZE$H_DATE$H_REPO$H_DESC\n"
 echo "==================================$VU$AU$BU$SU$DU$RU$PU"
}


# FINDPKG()
# =========
# returns the complete filename to package WHATPKG
findpkg()
{
 if [ -f "${SLACKDB}/${WHATPKG}" ]
 then
   FOUNDPKG=${SLACKDB}/${WHATPKG}
 else 
   FOUNDPKG=$(ls ${SLACKDB}/${WHATPKG}-[0-9IVX]*-*-* 2>/dev/null) 
 fi

 if [ -f "$FOUNDPKG" ]
 then
   echo $FOUNDPKG
 else
   WHATPKG="$FOUNDPKG" fpkgerr   # WHATPKG required for fpkgerr!
   RC=$? fexit
 fi
}


# GET_PKGSOURCE()
# ===============
# returns installation sources from build suffix
get_pkgsource()
{
 VERSION=$(echo $SLACKVERSION|cut -d. -f1,2)
 case $P_REST in

   # Multilib
   compat32) P_SOURCE="Slackware/32 $VERSION" ;;
   [_]*slack[1-9\._]*compat32) P_SOURCE="Patches/32 $(echo $P_REST|sed -e 's/[_]*slack[_]*//' -e 's/compat32//')" ;;
   _SeB|SeB) P_SOURCE="Sebastien Ballet" ;;
   SBocompat32|_SBocompat32) P_SOURCE=Slackbuilds.org/32 ;;

   # official
   "") P_SOURCE="Slackware $VERSION" ;;
   slack*|_slack*) P_SOURCE="Patches $(echo $P_REST|sed -e 's/[_]*slack[_]*//')" ;;

   # Slackbuild.org
   _SBo|SBo) P_SOURCE=Slackbuilds.org ;;
   _cng|cng) P_SOURCE="Chess Griffin" ;;

   # Slacky.eu
   sl|as|ms|bj) P_SOURCE="Slacky.eu" ;;

   # Alien BOB
   alien) P_SOURCE=Alienbase.nl ;;

   # Wine
   sg) P_SOURCE="Simone Giustetti" ;;
   mgc[0-9]*) P_SOURCE="Magic Linux Plus" ;;

   # Mate Slackbuilds
   msb|_msb) P_SOURCE="MATE SlackBuilds" ;;

   # Unixwerk
   ux) P_SOURCE=Unixwerk ;;

   # Converted packages
   rpm2t?z) P_SOURCE="Converted RPM Package" ;;

   # OpenOffice
   deb2t?z) P_SOURCE="Converted Debian Package" ;;

   # LinuxPackages.net
   gh|pin|ces|kjz) P_SOURCE="LinuxPackages.net" ;;

   fc[0-9]*) P_SOURCE="Fedora $(echo $P_REST|sed -e 's/fc//')" ;;

   *) P_SOURCE="$(echo $P_REST|sed -e 's/^_//')" ;;

 esac
}


# PKGLIST()
# =========
# returns list of packagenames from cmdline
# required variables: _okg
pkglist()
{
 for i in $_okg
 do
   echo "$i" | grep '\*' >/dev/null 2>&1
   if [ "$?" = "0" ]
   then
   # asterisk
     egrep ^$(echo "$i" | sed -e 's/*/.*/g' -e 's/+/./g'): ${TMP}/pkginfo | cut -d: -f1
   else
   # regular argument
     I="$(echo $i | sed -e 's/+/./g')"
     egrep "(^$I:|:$I:)" ${TMP}/pkginfo | cut -d: -f1
   fi
 done

 return
}


# GET_PKGDESC()
# =============
# returns first line of the package description
get_pkgdesc()
{
 _PKG="$(echo $_pkg | sed -e 's/+/./g')"
 FILE=${SLACKDB}/$(egrep "(:${_PKG}:|^${_PKG}:)" ${TMP}/pkginfo | awk -F: '{print $1}')
 P_DESC=$(grep -A1 'PACKAGE DESCRIPTION:' $FILE | tail -1 | awk -F\: '{print $NF}' | sed -e 's/^ //' -e 's/).*/)/' -e 's|-compat32 (| (32bit |')
}


# GET_PKGSIZE()
# =============
# returns size of $_pkg, needs F_SIZE to be set to c(=COMPRESSED) or y(=UNCOMPRESSED)
get_pkgsize()
{
 # compressed or uncompressed size?
 if [ "$F_SIZE" = "c" ]
 then
   z=z ; SZ=COMPRESSED
 elif [ "$F_SIZE" = "y" ]
 then
   z="" ; SZ=UNCOMPRESSED
 else
   RC=$ERR_UNKN fexit
 fi

 _PKG="$(echo $_pkg | sed -e 's/+/./g')"
 FILE=${SLACKDB}/$(egrep "(:${_PKG}:|^${_PKG}:)" ${TMP}/pkginfo | awk -F: '{print $1}')
 SIZE=$(grep "^$SZ PACKAGE SIZE:" $FILE | awk '{print $4;}')

 return $OK
}


# GET_INSTDATE()
# ==============
# returns installation date of $_pkg
get_instdate()
{
 _PKG="$(echo $_pkg | sed -e 's/+/./g')"
 FILE=${SLACKDB}/$(egrep "(:${_PKG}:|^${_PKG}:)" ${TMP}/pkginfo | awk -F: '{print $1}')
 IDATE=$(LC_ALL=C stat -c "%y" $FILE | awk -F. '{print $1;}')
 return $OK
}


### II How are we called?

case "$MYNAME" in

  archivepkg )
    exec $MYNAME -z $*
    ;;

  checkpkg )
    exec $MYNAME -c $*
    ;;

  listpkg )
    true
    ;;

  * )
    true
    ;;

esac


### III. Updating List of Installed Packages

if [ ! -e ${TMP}/pkginfo ]
then
  touch ${TMP}/pkginfo && sleep 2 && touch $PKGROOT/$SLACKDB
fi

if [ $PKGROOT/$SLACKDB -nt ${TMP}/pkginfo ]
then
  pkginfo
fi

# At this point we are sure that we have a recent pkginfo.
# and we can start working


### IV. Command line options

# SETENV()
# ========
H_VERS="$header_vers"   ; VU="$ul_vers"  ; F_VERS="y"  # set
H_BUILD="$header_build" ; HU="$ul_build" ; F_BUILD="y" # set
H_ARCH="$header_arch"   ; AU="$ul_arch"  ; F_ARCH="y"  # set
H_REPO="$header_repo"   ; RU="$ul_repo"  ; F_REPO="y"  # set
H_SIZE="" ; SU="" ; F_SIZE=""    # unset
H_DATE="" ; DU="" ; F_DATE=""    # unset
H_DESC="" ; PU="" ; F_DESC=""    # unset


# GETOPTS()
# =========
while [ "$#" -gt "0" ]
do
  case "$1" in
    # LIST PACKAGE CONTENTS
    "-A" | "--all" )
      [ -z "$2" ] && OPT="$1" fargerror
      WHATPKG=$2 PKG=$(findpkg) || RC=$? fexit
      cat $PKG
      shift
      shift
      ;;

    # BUILD VERSIOM
    "-a" | "--arch" )
      F_ARCH="y" ; H_ARCH="$header_arch" ; AU="$ul_arch" ; 
      shift
      ;;

    # BUILD VERSIOM
    "-b" | "--build" )
      F_BUILD="y" ; H_BUILD="$header_build" ; BU="$ul_build" ; 
      shift
      ;;

    # CHECK
    "-c" | "--check" )
      shift
      [ -x "/usr/sbin/checkpkg" ] && /usr/sbin/checkpkg "$@"
      exit $?
      ;;

    # CLEAR ALL FLAGS
    "-C" | "--clear" )
      clear_all_flags
      shift
      ;;

    # INSTALLATION DATE
    "-d" | "--date" )
      F_DATE="y" ; H_DATE="$header_date" ; DU="$ul_date"
      shift
      ;;

    # SUPPRESS HEADER
    "-H" | "--noheader" )
      PRINTHEADER="no"
      shift
      ;;

    # HELP
    "-h" | "--hilfe" | "--help" )
      fhelp
      RC=$OK fexit
      ;;

    # INSTALL SCRIPT
    "-i" | "--install" | "--install-script" )
      [ -z "$2" ] && OPT="$1" fargerror
      WHATPKG=$2 _PKG=$(findpkg) || RC=$? fexit
      PKG=$(basename $_PKG)

      if [ -e $SLACKSCRIPTDIR/$PKG ]
      then
        echo
        echo "Path: $SLACKSCRIPTDIR"
        echo
        echo "Installation script of package $PKG:"
        echo "========================================================="
        cat $SLACKSCRIPTDIR/$PKG
        echo
      else
        echo
        echo " Package $PKG"
        echo " doesn't contain an installation script."
        echo
      fi
      shift
      shift
      RC=0 fexit
      ;;

    # FILE LIST
    "-l" | "--list" | "--file-list" )
      [ -z "$2" ] && { OPT="$1" fargerror ; RC=$? fexit ; }
      WHATPKG=$2 PKG=$(findpkg) || RC=$? fexit
      echo
      echo "Path: $SLACKDB"
      echo
      echo "Contents of package $(basename $PKG):"
      echo "========================================================="
      tail +$(($(grep -n "FILE LIST:" ${PKG} | cut -d: -f1)+1)) ${PKG}
      echo
      shift
      shift
      RC=0 exit
      ;;

    # PACKAGE DESCRIPTION
    "-P" | "--package-description" )
      [ -z "$2" ] && { OPT="$1" fargerror ; RC=$? fexit ; }
      WHATPKG=$2 PKG=$(findpkg)
      [ -z "$PKG" ] && RC=$ERR_PKG fexit
      BGN_LN=$(($(grep -n 'PACKAGE DESCRIPTION:' $PKG | cut -d: -f1)+1))
      END_LN=$(($(grep -n 'FILE LIST:' $PKG | cut -d: -f1) ))

      printf "\nPath   : $SLACKDB\nPackage: $(basename $PKG)\n\n"

      tail +$BGN_LN $PKG | head -$((END_LN-BGN_LN)) | cut -d: -f2,3,4
      echo
      shift
      shift
      RC=0 fexit
      ;;

    # SHORT PACKAGE DESCRIPTION
    "-p" | "--short-description" )
      OPT=$1    # parameter value for fargerror; required!
      shift
      F_DESC=y ; H_DESC="$header_desc" ; PU="$ul_desc"
      ;;
      
    # INSTALLATION SOURCE (REPOSITORY)
    "-r" | "--repository" )
      shift
      F_REPO=y ; H_REPO="$header_repo" ; RU="$ul_repo"
      ;;
      
    # UNCOMPRESSED PACKAGE SIZE
    "-s" | "--size" )
      shift
      F_SIZE=y ; H_SIZE="$header_size" ; SU="$ul_size"
      ;;

    # COMPRESSED PACKAGE SIZE
    "-S" | "--compressed-size" )
      shift
      F_SIZE=c ; H_SIZE="$header_zsize" ; SU="$ul_size"
      ;;

    # RESERVED - TESTING SWITCH!
    "-T" | "--test" )
      shift
      [ ! -z "$*" ] && PACKAGES="$*" pkglist
      RC=$? fexit
      ;;


    # FORCE UPDATE PKGINFO
    "-u" | "--force-update" )
      echo
      pkginfo
      RC=$?
      echo
      fexit
      ;;

    # PACKAGE VERSION
    "-v" | "--pversion" )
      F_VERS="y" ; H_VERS="$header_vers" ; VU="$ul_vers"
      shift
      ;;

    # VERSION
    "-V" | "--version" )
      VERSION=$(echo ${SLACKVERSION}_$PKGVER)
      printf "\n $MYNAME $VERSION ($CR_DATE)\n\n"
      RC=$OK fexit
      ;;

    # SEARCH FILE IN ALL PACKAGES
    "-w" | "--whereis" | "-f" | "--file" | "--find-file" )
      [ -z "$2" ] && OPT="$1" fargerror
      printf "\nPath: /var/adm/packages\n\n"  
      ( cd ${SLACKDB} && grep "$2" * | egrep -v '.*:.*:' )
      echo
      shift
      shift
      RC=0 fexit
      ;;

    # EXTENDED DISPLAY: enable all options
    "-"+([CHx]) | "--extended" )
      echo " $1" | fgrep -q 'H' && PRINTHEADER="no"
      F_ARCH="y" ; H_ARCH="$header_arch" ; AU="$ul_arch"
      F_BUILD="y" ; H_BUILD="$header_build" ; BU="$ul_build"
      F_DATE=y ; H_DATE="$header_date" ; DU="$ul_date"
      F_DESC=y ; H_DESC="$header_desc" ; PU="$ul_desc"
      F_REPO=y ; H_REPO="$header_repo" ; RU="$ul_repo"
      F_SIZE=y ; H_SIZE="$header_size" ; SU="$ul_size"
      F_VERS="y" ; H_VERS="$header_vers" ; VU="$ul_vers"
      shift
      ;;

    "-"+([CHX]) )
      echo " $1" | fgrep -q 'H' && PRINTHEADER="no"
      F_ARCH="y" ; H_ARCH="$header_arch" ; AU="$ul_arch"
      F_BUILD="y" ; H_BUILD="$header_build" ; BU="$ul_build" 
      F_DATE=y ; H_DATE="$header_date" ; DU="$ul_date"
      F_DESC=y ; H_DESC="$header_desc" ; PU="$ul_desc"
      F_REPO=y ; H_REPO="$header_repo" ; RU="$ul_repo"
      F_SIZE=c ; H_SIZE="$header_zsize" ; SU="$ul_size"
      F_VERS="y" ; H_VERS="$header_vers" ; VU="$ul_vers"
      shift
      ;;

    # ARCHIVEPKG
    "-z" | "--archive" )
      shift
      [ -x "/usr/sbin/archivepkg" ] && /usr/sbin/archivepkg "$@"
      exit $?
      ;;

    # ANY COMBINATION OF -C -H -a -b -d -p -r -s -v
    "-"+([CHabdprsSv]) )
      echo " $1" | fgrep -q 'C' && clear_all_flags
      echo " $1" | fgrep -q 'H' && PRINTHEADER="no"
      echo " $1" | fgrep -q 'a' && { F_ARCH=y ; H_ARCH="$header_arch" ; AU="$ul_arch" ; }
      echo " $1" | fgrep -q 'b' && { F_BUILD=y ; H_BUILD="$header_build" ; BU="$ul_build" ; }
      echo " $1" | fgrep -q 'd' && { F_DATE=y ; H_DATE="$header_date" ; DU="$ul_date" ; }
      echo " $1" | fgrep -q 'p' && { F_DESC=y ; H_DESC="$header_desc" ; PU="$ul_desc" ; }
      echo " $1" | fgrep -q 'r' && { F_REPO=y ; H_REPO="$header_repo" ; RU="$ul_repo" ; }
      echo " $1" | fgrep -q 's' && { F_SIZE=y ; H_SIZE="$header_size" ; SU="$ul_size" ; }
      echo " $1" | fgrep -q 'S' && { F_SIZE=c ; H_SIZE="$header_zsize" ; SU="$ul_size" ; }
      echo " $1" | fgrep -q 'v' && { F_VERS=y ; H_VERS="$header_vers" ; VU="$ul_vers" ; }
      shift 
      ;;

    # UNKNOWN OPTION
    "-"* )
      printf "\n$MYNAME: invalid option $1\n" 1>&2
      fhelp 1>&2
      RC=$ERR_OPT fexit
      ;;

    # PACKAGE LIST
    * )
      [ ! -z "$1" ] && PKGLIST="$PKGLIST $1"
      shift
      ;;
  esac
done


# MAIN()
# ======
printheader 

if [ -z "$PKGLIST" ]
then
  PKGLIST="$(awk -F: '{print $1}' ${TMP}/pkginfo)"
fi

for _okg in $PKGLIST
do
  case $_okg in
    *"*"*) PACKAGES="$PACKAGES $(pkglist)" ;;
    *) PACKAGES="$PACKAGES $_okg" ;;
  esac
done

for _pkg in ${PACKAGES}
do

  _PKG="$(echo $_pkg | sed -e 's/+/./g')"

  P_REST=""
  egrep "(:${_PKG}:|^${_PKG}:)" ${TMP}/pkginfo 2>/dev/null | awk -F: '{print $2, $3, $4, $5, $6;}' | read P_NAME P_VER P_ARCH P_BUILD P_REST

  # Package not installed? => continue with next element in the list
  # ================================================================
  if [ -z "$P_NAME" ]
  then
    WHATPKG=$_pkg fpkgerr
    continue
  fi

  [ "$F_REPO" = "y" ] && get_pkgsource                              # gets $P_SOURCE
  [ \( "$F_SIZE" = "y" \) -o \( "$F_SIZE" = "c" \) ] && get_pkgsize # gets $SIZE  
  [ "$F_DATE" = "y" ] && get_instdate    # gets $IDATE
  [ "$F_DESC" = "y" ] && get_pkgdesc     # gets $P_DESC
  
  # print results
  # =============
  printf "  %-32s" "$P_NAME"
  [ "$F_VERS" = "y" ] &&  printf "%-20s " "$P_VER"
  [ "$F_ARCH" = "y" ] &&  printf "%-6s " "$P_ARCH"
  [ "$F_BUILD" = "y" ] &&  printf "%5s  " "$P_BUILD"
  [ \( "$F_SIZE" = "y" \) -o \( "$F_SIZE" = "c" \) ] && printf "%11s  " "$SIZE"
  [ "$F_DATE" = "y" ] &&  printf "%19s  " "$IDATE"
  [ "$F_REPO" = "y" ] &&  printf "%-24s  " "$P_SOURCE"  
  [ "$F_DESC" = "y" ] && printf "%s" "$P_DESC"
  printf "\n"


done | uniq

echo
RC=${RC:-0}
fexit
