From 1f5db8721297ddaecddcb9a94f9225aa45fff51d Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Mon, 4 Aug 2014 23:30:02 -0400 Subject: Break out a util.inc.sh --- Makefile | 3 ++- asp.in | 30 +----------------------------- util.inc.sh | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 30 deletions(-) create mode 100644 util.inc.sh diff --git a/Makefile b/Makefile index 542377b..2512cc7 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,8 @@ MANPAGES = \ INCLUDES = \ package.inc.sh \ - remote.inc.sh + remote.inc.sh \ + util.inc.sh all: $(BINPROGS) $(MANPAGES) diff --git a/asp.in b/asp.in index 3ac8021..b33d5fb 100644 --- a/asp.in +++ b/asp.in @@ -6,38 +6,10 @@ OPT_ARCH=$(uname -m) OPT_FORCE=0 : ${ASPROOT:=$HOME/asp} +m4_include(util.inc.sh) m4_include(remote.inc.sh) m4_include(package.inc.sh) -log_meta() { - printf "$1 $2\n" "${@:3}" -} - -log_error() { - log_meta 'error:' "$@" >&2 -} - -log_fatal() { - log_error "$@" - exit 1 -} - -log_warning() { - log_meta 'warning:' "$@" >&2 -} - -log_info() { - log_meta '==>' "$@" -} - -map() { - local map_r=0 - for _ in "${@:2}"; do - "$1" "$_" || (( $# > 255 ? map_r=1 : ++r )) - done - return $map_r -} - usage() { cat<&2 +} + +log_fatal() { + log_error "$@" + exit 1 +} + +log_warning() { + log_meta 'warning:' "$@" >&2 +} + +log_info() { + log_meta '==>' "$@" +} + +map() { + local map_r=0 + for _ in "${@:2}"; do + "$1" "$_" || (( $# > 255 ? map_r=1 : ++r )) + done + return $map_r +} + +in_array() { + local item needle=$1 + + for item in "${@:2}"; do + [[ $item = "$needle" ]] && return 0 + done + + return 1 +} -- cgit v1.2.3-70-g09d2