#!/usr/bin/ksh93

#
# This file is a part of the NsCDE - Not so Common Desktop Environment
# Author: Hegel3DReloaded
# Licence: GPLv3
#

[ -z $NSCDE_DATADIR ] && exit 2
[ -z $FVWM_USERDIR ] && exit 3
MARCH=$(uname -m)

function find_colors
{
   if [ "x$NSCDE_PALETTE" != "x" ]; then
      if [ -r "$FVWM_USERDIR/palettes/${NSCDE_PALETTE}.dp" ]; then
         palfile="$FVWM_USERDIR/palettes/${NSCDE_PALETTE}.dp"
      else
         if [ -r "$NSCDE_DATADIR/palettes/${NSCDE_PALETTE}.dp" ]; then
            palfile="$NSCDE_DATADIR/palettes/${NSCDE_PALETTE}.dp"
         fi
      fi

      if [[ "$NSCDE_PALETTE_NCOLORS" != @(4|8) ]]; then
         NSCDE_PALETTE_NCOLORS=4
      fi

      if [ "x$palfile" != "x" ]; then
         $NSCDE_TOOLSDIR/palette_colorgen \
          -n ${NSCDE_PALETTE_NCOLORS} \
          -p ${palfile} -sl | \
          egrep '(ts|bs)_color_3' | while IFS=" " read name value
         do
            eval "${name}"="${value}"
         done
         if [ "x$bs_color_3" == "x" ]; then
            bs_color_3="black"
         fi
         if [ "x$ts_color_3" == "x" ]; then
            ts_color_3="red"
         fi
      else
         bs_color="black"
         ts_color="red"
      fi
   else
      bs_color="black"
      ts_color="red"
   fi

   # Make sure it ends before continuing to
   # avoid defunct/zombie process creation
   return
}

find_colors

if [ -x ${NSCDE_TOOLSDIR}/${NSCDE_OS}_${MARCH}/fpclock ]; then
   exec ${NSCDE_TOOLSDIR}/${NSCDE_OS}_${MARCH}/fpclock -H $bs_color_3 -S $ts_color_3 "$@"
else
   pclock=$(whence -p pclock)
   if [ "x$pclock" != "x" ]; then
      exec $pclock -H black -S red --hour-hand-length=15 --minute-hand-length=20 --second-hand-length=22 "$@"
   fi
fi

