[less/f15/master] - Add support for reading UTF-16 and UTF-32 files

Vojtěch Vítek vvitek at fedoraproject.org
Tue Feb 15 13:45:33 UTC 2011


commit ea3e205b136bbb7b1824fea6ffe35aac5df114e7
Author: Vojtech Vitek (V-Teq) <vvitek at redhat.com>
Date:   Mon Feb 14 17:01:44 2011 +0100

    - Add support for reading UTF-16 and UTF-32 files

 less.spec   |    2 ++
 lesspipe.sh |   14 +++++++++++++-
 2 files changed, 15 insertions(+), 1 deletions(-)
---
diff --git a/less.spec b/less.spec
index 4c88a94..6b9b8b0 100644
--- a/less.spec
+++ b/less.spec
@@ -72,6 +72,8 @@ ls -la $RPM_BUILD_ROOT/etc/profile.d
 rm -rf $RPM_BUILD_ROOT
 
 %changelog
+- Add support for reading UTF-16 and UTF-32 files
+  Resolves: #638312
 - Don't require correct exit status from LESSOPEN scripts until
   it gets accepted by upstream (preserve backward compatibility)
   Resolves: #666084, #676057
diff --git a/lesspipe.sh b/lesspipe.sh
index 71b2044..441207a 100755
--- a/lesspipe.sh
+++ b/lesspipe.sh
@@ -50,8 +50,20 @@ lesspipe() {
 	else
 		echo "No identify available"
 		echo "Install ImageMagick or GraphicsMagick to browse images"
+		exit 1
 	fi ;;
   *)
+	if [ -x /usr/bin/file -a -x /usr/bin/iconv -a -x /usr/bin/cut ]; then
+		case `file "$1"` in
+		*UTF-16*) conv='UTF-16' ;;
+		*UTF-32*) conv='UTF-32' ;;
+		esac
+		env=`echo $LANG | cut -d. -f2`
+		if [ -n  "$conv" -a -n "$env" -a "$conv" != "$env" ]; then
+			iconv -f $conv -t $env "$1"
+			exit $?
+		fi
+	fi
 	exit 1
   esac
   exit $?
@@ -62,7 +74,7 @@ if [ ! -e "$1" ] ; then
 fi
 
 if [ -d "$1" ] ; then
-	/bin/ls -alF -- "$1"
+	ls -alF -- "$1"
 	exit $?
 else
 	lesspipe "$1" 2> /dev/null


More information about the scm-commits mailing list