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 }