-# Copyright 1999-2005 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-src/rc-scripts/sbin/functions.sh,v 1.81.2.6 2005/05/15 20:00:31 vapier Exp $
+# e*() output functions {{{
+# heavily based on gentoo's functions.sh; stripped down and modified
+# to match our needs.
+#
+# defined functions:
+# ebegin()
+# eend()
+# eerror()
+# eindent()
+# einfo()
+# einfon()
+# eoutdent()
+# esetdent()
+# esyslog()
+# ewarn()
+# ewend()
+#
+# copyright 1999-2005 gentoo foundation
+# distributed under the terms of the gnu general public license v2
+# $header: /var/cvsroot/gentoo-src/rc-scripts/sbin/functions.sh,v 1.81.2.6 2005/05/15 20:00:31 vapier exp $
fi
[ -n "$NOCOLORS" ] && RC_NOCOLOR='yes'
RC_NOCOLOR="${RC_NOCOLOR:-no}"
# Can the terminal handle endcols?
fi
[ -n "$NOCOLORS" ] && RC_NOCOLOR='yes'
RC_NOCOLOR="${RC_NOCOLOR:-no}"
# Can the terminal handle endcols?
# Setup COLS and ENDCOL so eend can line up the [ ok ]
# width of [ ok ] == 7
COLS="$(stty size 2>/dev/null | cut -d' ' -f2)"
if [ -z "${COLS}" ] || [ "${COLS}" -le 0 ] ; then
# Setup COLS and ENDCOL so eend can line up the [ ok ]
# width of [ ok ] == 7
COLS="$(stty size 2>/dev/null | cut -d' ' -f2)"
if [ -z "${COLS}" ] || [ "${COLS}" -le 0 ] ; then
# void esyslog(char* priority, char* tag, char* message)
#
# use the system logger to log a message
#
esyslog() {
# void esyslog(char* priority, char* tag, char* message)
#
# use the system logger to log a message
#
esyslog() {
- [ "${RC_QUIET_STDOUT}" = "yes" ] && return 0
- [ "${RC_ENDCOL}" != "yes" ] && [ "${LAST_E_CMD}" = "ebegin" ] && echo
- printf " ${GOOD}*${NORMAL} ${RC_INDENTATION}$*"
- LAST_E_CMD=einfon
- return 0
+ [ "${RC_QUIET_STDOUT}" = "yes" ] && return 0
+ [ "${RC_ENDCOL}" != "yes" ] && [ "${LAST_E_CMD}" = "ebegin" ] && echo
+ printf " ${GOOD}*${NORMAL} ${RC_INDENTATION}$*"
+ LAST_E_CMD=einfon
+ return 0
- if [ "${RC_QUIET_STDOUT}" = "yes" ]; then
- printf " $*\n"
- else
- [ "${RC_ENDCOL}" != "yes" ] && [ "${LAST_E_CMD}" = "ebegin" ] && echo
- printf " ${WARN}*${NORMAL} ${RC_INDENTATION}$*\n"
- fi
+ if [ "${RC_QUIET_STDOUT}" = "yes" ]; then
+ printf " $*\n"
+ else
+ [ "${RC_ENDCOL}" != "yes" ] && [ "${LAST_E_CMD}" = "ebegin" ] && echo
+ printf " ${WARN}*${NORMAL} ${RC_INDENTATION}$*\n"
+ fi
- if [ "${RC_QUIET_STDOUT}" = "yes" ]; then
- printf " $*\n" >/dev/stderr
- else
- [ "${RC_ENDCOL}" != "yes" ] && [ "${LAST_E_CMD}" = "ebegin" ] && echo
- printf " ${BAD}*${NORMAL} ${RC_INDENTATION}$*\n"
- fi
+ if [ "${RC_QUIET_STDOUT}" = "yes" ]; then
+ printf " $*\n" >&2
+ else
+ [ "${RC_ENDCOL}" != "yes" ] && [ "${LAST_E_CMD}" = "ebegin" ] && echo
+ printf " ${BAD}*${NORMAL} ${RC_INDENTATION}$*\n"
+ fi
- local msg="$@" dots spaces
- spaces="$(printf '%'"${#RC_DOT_PATTERN}"'s' '')"
- [ "${RC_QUIET_STDOUT}" = "yes" ] && return 0
-
- if [ -n "${RC_DOT_PATTERN}" ]; then
- dots="$(printf "%$(( $COLS - 3 - ${#RC_INDENTATION} - ${#msg} - 7 ))s" '')"
- while [ "${dots#${spaces}}" != "${dots}" ] ; do
- dots="${dots#${spaces}}${RC_DOT_PATTERN}"
- done
- msg="${msg}${dots}"
- else
- msg="${msg} ..."
- fi
- einfon "${msg}"
- [ "${RC_ENDCOL}" = "yes" ] && echo
-
- LAST_E_LEN=$(( 3 + ${#RC_INDENTATION} + ${#msg} ))
- LAST_E_CMD=ebegin
- return 0
+ local msg="$@" dots spaces
+ spaces="$(printf '%'"${#RC_DOT_PATTERN}"'s' '')"
+ [ "${RC_QUIET_STDOUT}" = "yes" ] && return 0
+
+ if [ -n "${RC_DOT_PATTERN}" ]; then
+ dots="$(printf "%$(( $COLS - 3 - ${#RC_INDENTATION} - ${#msg} - 7 ))s" '')"
+ while [ "${dots#${spaces}}" != "${dots}" ] ; do
+ dots="${dots#${spaces}}${RC_DOT_PATTERN}"
+ done
+ msg="${msg}${dots}"
+ else
+ msg="${msg} ..."
+ fi
+ einfon "${msg}"
+ [ "${RC_ENDCOL}" = "yes" ] && echo
+
+ LAST_E_LEN=$(( 3 + ${#RC_INDENTATION} + ${#msg} ))
+ LAST_E_CMD=ebegin
+ return 0
- if [ "${retval}" -eq 0 ]; then
- [ "${RC_QUIET_STDOUT}" = "yes" ] && return 0
- msg="${BRACKET}[ ${GOOD}ok${BRACKET} ]${NORMAL}"
- else
- if [ "$#" -gt 0 ] ; then
- "${efunc}" "$@"
- fi
- msg="${BRACKET}[ ${BAD}!!${BRACKET} ]${NORMAL}"
+ if [ "${retval}" -eq 0 ]; then
+ [ "${RC_QUIET_STDOUT}" = "yes" ] && return 0
+ msg="${BRACKET}[ ${GOOD}ok${BRACKET} ]${NORMAL}"
+ else
+ if [ "$#" -gt 0 ] ; then
+ "${efunc}" "$@"
- if [ "${RC_ENDCOL}" = "yes" ]; then
- printf "${ENDCOL} ${msg}\n"
- else
- [ "${LAST_E_CMD}" = "ebegin" ] || LAST_E_LEN=0
- printf "%$(( ${COLS} - ${LAST_E_LEN} - 6 ))s%b\n" '' "${msg}"
- fi
+ if [ "${RC_ENDCOL}" = "yes" ]; then
+ printf "${ENDCOL} ${msg}\n"
+ else
+ [ "${LAST_E_CMD}" = "ebegin" ] || LAST_E_LEN=0
+ printf "%$(( ${COLS} - ${LAST_E_LEN} - 6 ))s%b\n" '' "${msg}"
+ fi