From: Robert Luberda <robert@debian.org>
Date: Wed, 28 Jul 2004 08:33:32 +0200
Subject: 015 hman urlencode

Properly encode URLs given to browsers, so `hman index++' should work now (closes: #258027)
---
 man2html/hman.sh | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/man2html/hman.sh b/man2html/hman.sh
index b5e2dc6..091aa09 100755
--- a/man2html/hman.sh
+++ b/man2html/hman.sh
@@ -59,6 +59,11 @@ nsfunc () {
 	fi
 }
 
+urlencode() {
+	echo "$@" | perl -pe 'chomp(); s/([^A-Za-z0-9\ \_\-\.\/])/"%" . unpack("H*", $1)/eg; tr/ /+/;'
+}
+
+
 case "$HMAN_BROWSER" in
      lynxcgi)
 	HMAN_BROWSER=lynx
@@ -77,22 +82,22 @@ esac
      0)   $HMAN_BROWSER "$CG/man2html" ;;
      1)   case "$1" in
 	    1|2|3|4|5|6|7|8|l|n)
-		$HMAN_BROWSER "$CG/mansec?$CG+$1" ;;
+		$HMAN_BROWSER "$CG/mansec?query=$1" ;;
 	    /*)
-		$HMAN_BROWSER "$CG/man2html?$1" ;;
+		$HMAN_BROWSER "$CG/man2html?query=`urlencode "$1"`" ;;
 	    */*)
-		$HMAN_BROWSER "$CG/man2html?$PWD/$1" ;;
+		$HMAN_BROWSER "$CG/man2html?query=`urlencode "$PWD/$1"`" ;;
 	    *)
-		$HMAN_BROWSER "$CG/man2html?$1" ;;
+		$HMAN_BROWSER "$CG/man2html?query=`urlencode "$1"`" ;;
           esac ;;
      2)   case "$1" in
             -k)
-                $HMAN_BROWSER "$CG/mansearch?$2" ;;
+                $HMAN_BROWSER "$CG/mansearch?query=`urlencode "$2"`" ;;
             *)
 		if [ "$2" = index ]; then
-		    $HMAN_BROWSER "$CG/manwhatis?$CG+$1"
+		    $HMAN_BROWSER "$CG/manwhatis?query=`urlencode "$1"`"
                 else
-		    $HMAN_BROWSER "$CG/man2html?$1+$2"
+		    $HMAN_BROWSER "$CG/man2html?query=`urlencode "$1 $2"`"
                 fi ;;
           esac ;;
      *)   echo "bad number of args" ;;
