#!/usr/bin/ksh93

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

[ -z $NSCDE_ROOT ] && exit 2
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_ROOT/share/palettes/${NSCDE_PALETTE}.dp" ]; then
            palfile="$NSCDE_ROOT/share/palettes/${NSCDE_PALETTE}.dp"
         fi
      fi

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

      if [ "x$palfile" != "x" ]; then
         $NSCDE_ROOT/libexec/nscde_palette_colorgen.py \
          -n ${NSCDE_PALETTE_NCOLORS} \
          -p /opt/NsCDE/share/palettes/${NSCDE_PALETTE}.dp -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
}

find_colors

if [ -x $NSCDE_ROOT/bin/fpclock-${NSCDE_OS}_${MARCH} ]; then
   exec $NSCDE_ROOT/bin/fpclock-${NSCDE_OS}_${MARCH} -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

