diff options
Diffstat (limited to 'src/lib/libremessages')
-rwxr-xr-x | src/lib/libremessages | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/src/lib/libremessages b/src/lib/libremessages index c6d08e2..e5b7157 100755 --- a/src/lib/libremessages +++ b/src/lib/libremessages @@ -2,15 +2,15 @@ # This may be included with or without `set -euE` # When run directly, it does `set -euE` -# Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> -# Copyright (c) 2006-2010 Pacman Development Team <pacman-dev@archlinux.org> -# Copyright (c) 2005 by Aurelien Foret <orelien@chez.com> -# Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu> -# Copyright (c) 2006 by Alex Smith <alex@alex-smith.me.uk> -# Copyright (c) 2006 by Andras Voroskoi <voroskoi@frugalware.org> -# Copyright (c) 2006 by Miklos Vajna <vmiklos@frugalware.org> -# Copyright (c) 2011 by Joshua Haase <hahj87@gmail.com> -# Copyright (c) 2012-2013 by Luke Shumaker <lukeshu@sbcglobal.net> +# Copyright (C) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> +# Copyright (C) 2006-2010 Pacman Development Team <pacman-dev@archlinux.org> +# Copyright (C) 2005 by Aurelien Foret <orelien@chez.com> +# Copyright (C) 2005 by Christian Hamar <krics@linuxforum.hu> +# Copyright (C) 2006 by Alex Smith <alex@alex-smith.me.uk> +# Copyright (C) 2006 by Andras Voroskoi <voroskoi@frugalware.org> +# Copyright (C) 2006 by Miklos Vajna <vmiklos@frugalware.org> +# Copyright (C) 2011 by Joshua Haase <hahj87@gmail.com> +# Copyright (C) 2012-2014 by Luke Shumaker <lukeshu@sbcglobal.net> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -36,7 +36,7 @@ ################################################################################ panic() { - echo "$(_ 'panic: malformed call to internal function')" >&2 + echo "$(_l _ 'panic: malformed call to internal function')" >&2 exit 1 } @@ -88,8 +88,6 @@ bullet() { # bullet. flag() { [[ $# == 2 ]] || panic - local n=' -' local flag=$1 local desc="$(_ "$(_html_whitespace_collapse <<<"$2")")" @@ -99,7 +97,7 @@ flag() { done local lines - IFS=$n lines=($(fmt -u -w $((73-indent)) <<<"$desc")) + IFS=$'\n' lines=($(fmt -u -w $((73-indent)) <<<"$desc")) local line for line in "${lines[@]}"; do printf " %-${indent}s %s\n" "$flag" "$line" @@ -119,6 +117,25 @@ term_title() { printf "$fmt" "$*" } +# Usage: setup_traps +# Sets up traps on TERM, HUP, QUIT and INT signals, as well as the ERR event, +# similar to makepkg +setup_traps() { + _libremessages_trap_exit() { + local signal=$1; shift + echo + error "$@" + trap -- "$signal" + kill "-$signal" "$$" + } + set -E + for signal in TERM HUP QUIT; do + trap "_libremessages_trap_exit $signal '%s signal caught. Exiting...' $signal" $signal + done + trap '_libremessages_trap_exit INT "Aborted by user! Exiting..."' INT + trap '_libremessages_trap_exit USR1 "An unknown error has occurred. Exiting..."' ERR +} + ################################################################################ # Run one of the defined functions if invoked directly # ################################################################################ |