From 43bdecc08b4d9a3ee01a55858e2f85bbb8b673fc Mon Sep 17 00:00:00 2001 From: Jephte CLAIN Date: Sun, 12 Oct 2014 22:15:33 +0400 Subject: [PATCH] =?UTF-8?q?detect=5Fenc()=20retourne=20faux=20si=20l'encod?= =?UTF-8?q?ing=20n'a=20pas=20pu=20=C3=AAtre=20d=C3=A9tect=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fconv | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/fconv b/fconv index f1ee1b2..e4cbdf0 100755 --- a/fconv +++ b/fconv @@ -41,18 +41,19 @@ COMMANDES } function detect_enc() { + local enc if [ -f "$1" ]; then - "$scriptdir/lib/pywrapper" uencdetect.py -f "$1" - return $? + setx enc="$scriptdir/lib/pywrapper" uencdetect.py -f "$1" elif [ -d "$1" ]; then local -a files setx -a files=evalp find "$1" -type f // head -n1 if [ ${#files[*]} -gt 0 ]; then - "$scriptdir/lib/pywrapper" uencdetect.py -f "${files[0]}" - return $? + setx enc="$scriptdir/lib/pywrapper" uencdetect.py -f "${files[0]}" fi fi - echo Unknown + [ -n "$enc" ] || enc=Unknown + echo "$enc" + [ "$enc" != Unknown ] } function before_parse_cmd() { @@ -64,8 +65,7 @@ function before_parse_cmd() { local from="${3:-detect}" if [ "$from" == "detect" ]; then - setx from=detect_enc "$FILE" - if [ "$from" == "Unknown" ]; then + if ! setx from=detect_enc "$FILE"; then echo "$FILE: Impossible de détecter l'encoding" return 1 fi @@ -83,11 +83,7 @@ function before_parse_cmd() { function iconv_detect() { local to="$1"; shift local from - setx from=detect_enc "$FILE" - if [ "$from" == "Unknown" ]; then - cat - return 1 - else + if setx from=detect_enc "$FILE"; then if [ -n "$REVERSE_CONV" ]; then local tmp="$to" to="$from" @@ -95,6 +91,9 @@ function iconv_detect() { fi iconv -f "$from" -t "$to" "$@" return 0 + else + cat + return 1 fi }