[hackers] [farbfeld] 2ff: Check return values and handle errors || FRIGN

From: <git_AT_suckless.org>
Date: Tue, 5 Jan 2016 16:57:22 +0100 (CET)

commit ba154494ae239b9a79fc0947cad497e983c80653
Author: FRIGN <dev_AT_frign.de>
AuthorDate: Tue Jan 5 16:03:43 2016 +0100
Commit: FRIGN <dev_AT_frign.de>
CommitDate: Tue Jan 5 16:03:43 2016 +0100

    2ff: Check return values and handle errors
    
    Also, in case convert(1) is not in the path, it will just return an
    error-message giving the MIME-type of the problematic input data.
    The return-value is given properly as well (0 on success, 1 on error).

diff --git a/2ff b/2ff
index 2b0cbd9..19946df 100755
--- a/2ff
+++ b/2ff
_AT_@ -10,9 +10,15 @@ cat > $TMP;
 FORMAT=$(file -ib $TMP | cut -d ";" -f 1);
 
 case "$FORMAT" in
- image/png) png2ff < $TMP ;;
- image/jpeg) jpg2ff < $TMP ;;
- *) convert $TMP png:- | png2ff ;;
+ image/png) png2ff < $TMP; ret=$? ;;
+ image/jpeg) jpg2ff < $TMP; ret=$? ;;
+ *) xconvert $TMP png:- 2&>/dev/null | png2ff 2&>/dev/null; ret=$? ;;
 esac
 
 rm $TMP;
+
+if [ $ret -ne 0 ]; then
+ printf "%s: failed to convert %s\n" "$0" "$FORMAT" 1>&2;
+fi
+
+exit $ret;
Received on Tue Jan 05 2016 - 16:57:22 CET

This archive was generated by hypermail 2.3.0 : Tue Jan 05 2016 - 17:00:20 CET