#! /bin/sh case "$0" in */get_encodings) sourced=false ;; *) sourced=true ;; esac from_encoding= to_encoding= default_encoding="`python3 -c \"from m_lib.defenc import default_encoding; print(default_encoding)"`" while getopts f:t: opt; do case $opt in f ) from_encoding="$OPTARG" ;; t ) to_encoding="$OPTARG" ;; esac done shift `expr $OPTIND - 1` error() { echo "$@" >&2 echo "Usage: $0 [-f from_encoding] [-t to_encoding] [path [path ...]]" >&2 exit 1 } if [ -n "$from_encoding" ]; then if [ -n "$to_encoding" ]; then : # Everything is defined, no need to guess elif [ "$from_encoding" = utf-8 ]; then if [ "$default_encoding" = utf-8 ]; then error Cannot guess to_encoding else to_encoding="$default_encoding" fi else to_encoding=utf-8 fi elif [ -n "$to_encoding" ]; then if [ "$to_encoding" = "$default_encoding" ]; then if [ "$default_encoding" = utf-8 ]; then error Cannot guess from_encoding else from_encoding=utf-8 fi else from_encoding="$default_encoding" fi else if [ "$default_encoding" = utf-8 ]; then error Cannot guess encodings else from_encoding="$default_encoding" to_encoding=utf-8 fi fi if [ "$sourced" = false ]; then echo "$from_encoding $to_encoding" fi