From bff6b3ca2fc4f13592a52e3979161c8faa5b7bc0 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Thu, 18 May 2017 10:37:25 +0200 Subject: Move generic functions (almost) to the top. --- bin/stream | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) (limited to 'bin/stream') diff --git a/bin/stream b/bin/stream index c10901f..db1c100 100755 --- a/bin/stream +++ b/bin/stream @@ -7,10 +7,35 @@ set -eu # TODO: Externalize to site-specific configfile [ $# -gt 0 ] || set -- morla 5002 -- dvcam ../../content/icon_small.png +## +## generic functions +## exit1() { echo >&2 "ERROR: $1" exit 1 } +# shellcheck disable=SC2048,SC2059 +echo_n() { + printf -- "$*" +} +# shellcheck disable=SC2048,SC2059 +printf_each() { + skel=$1; shift + for string in $*; do + printf -- "$skel" "$string" + done +} +uniqwords() { + echo_n "$@" | tr ' ' '\012' | sort -u +} +valuedargcount() { + nonempty= + while [ $# -gt 0 ]; do + [ -z "$1" ] || nonempty=$((nonempty+1)) + shift + done + echo_n "$nonempty" +} while [ $# -gt 0 ]; do case $1 in @@ -130,29 +155,6 @@ fi [ -n "$HEIGHTS_MPEG" ] || SPEED_VP8="$SPEED_VP8_ALONE" [ -n "$HEIGHTS_WEBM" ] || SPEED_X264="$SPEED_X264_ALONE" -# shellcheck disable=SC2048,SC2059 -echo_n() { - printf -- "$*" -} -# shellcheck disable=SC2048,SC2059 -printf_each() { - skel=$1; shift - for string in $*; do - printf -- "$skel" "$string" - done -} -uniqwords() { - echo_n "$@" | tr ' ' '\012' | sort -u -} -valuedargcount() { - nonempty= - while [ $# -gt 0 ]; do - [ -z "$1" ] || nonempty=$((nonempty+1)) - shift - done - echo_n "$nonempty" -} - HEIGHTS=$(uniqwords "$HEIGHTS_WEBM $HEIGHTS_MPEG") [ -z "${SAVEDIR:-}" ] || SAVESTEM="${SAVEDIR:-}/$(date +%Y%m%d-%H%M%S)" -- cgit v1.2.3