[Date Prev][Date Next][Thread Prev][][Date Index][Thread Index]

decode w3m-process-realm



青田です。

Basic認証でユーザ名・パスワードを聞かれる時のrealmに日本語などが使って
あるとうまく表示できないようです。
たとえば、
http://www.bookshelf.jp/pukiwiki/pukiwiki.php
などです。

ということで、realmをdecodeするようにしました。w3m-url-decode-stringの
後半がちょうど目的にそうコードだったのでそこを
w3m-decode-coding-string-with-priorityとしてdefunし、それを使っています。

XEmacsではw3m-decode-coding-string-with-priorityは定義済みですが、
find-coding-systemが定義されていない時にstrをそのまま返すように変更して
います。

XEmacs環境がないため、XEmacsではテストできていません。どなたかテストし
てくださったら幸いです。

Index: ChangeLog
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/ChangeLog,v
retrieving revision 1.3035
diff -u -r1.3035 ChangeLog
--- ChangeLog	28 Aug 2007 10:37:15 -0000	1.3035
+++ ChangeLog	29 Aug 2007 10:52:49 -0000
@@ -1,3 +1,15 @@
+2007-08-29  Naohiro Aota  <nao.aota@xxxxxxxxx>
+
+	* w3m-proc.el (w3m-process-filter): Decode realm string.
+
+	* w3m.el (w3m-url-decode-string): Define latter half as a function :
+	w3m-decode-coding-string-with-priority ,and use it.
+
+	* w3m-ems.el (w3m-decode-coding-string-with-priority): New function.
+
+	* w3m-xmas.el (w3m-decode-coding-string-with-priority): Return string
+	itself unless find-coding-system is defined as built-in function.
+
 2007-08-28  Hideyuki SHIRAI  <shirai@xxxxxxxxxxx>
 
 	* w3m.el (w3m-uri-replace-alist): Add key of "alc:".
Index: w3m-ems.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m-ems.el,v
retrieving revision 1.18
diff -u -r1.18 w3m-ems.el
--- w3m-ems.el	17 Jul 2007 22:46:35 -0000	1.18
+++ w3m-ems.el	29 Aug 2007 10:52:53 -0000
@@ -1261,6 +1261,23 @@
 			'help-echo w3m-spinner-map-help-echo))
       image)))
 
+(defun w3m-decode-coding-string-with-priority (str coding)
+  "Decode the string STR which is encoded in CODING.
+If CODING is a list, look for the coding system using it as a priority
+list."
+  (setq str (string-make-unibyte str))
+  (when (listp coding)
+    (setq coding
+	  (with-temp-buffer
+	    (set-buffer-multibyte nil)
+	    (insert str)
+	    (w3m-detect-coding-region (point-min) (point-max) coding))))
+  (decode-coding-string str
+			(or coding
+			    w3m-default-coding-system
+			    w3m-coding-system
+			    'iso-2022-7bit)))
+
 (provide 'w3m-ems)
 
 ;;; w3m-ems.el ends here
Index: w3m-proc.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m-proc.el,v
retrieving revision 1.60
diff -u -r1.60 w3m-proc.el
--- w3m-proc.el	18 Jan 2007 23:21:37 -0000	1.60
+++ w3m-proc.el	29 Aug 2007 10:52:55 -0000
@@ -645,7 +645,7 @@
 	   ((and (looking-at "\\(\n?Wrong username or password\n\\)?\
 Username for \\(.*\\)\n?: ")
 		 (= (match-end 0) (point-max)))
-	    (setq w3m-process-realm (match-string 2))
+	    (setq w3m-process-realm (w3m-decode-coding-string-with-priority (match-string 2) nil))
 	    (when (or (match-beginning 1)
 		      (not (stringp w3m-process-user)))
 	      (setq w3m-process-user
Index: w3m-xmas.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m-xmas.el,v
retrieving revision 1.139
diff -u -r1.139 w3m-xmas.el
--- w3m-xmas.el	3 Jul 2007 05:24:16 -0000	1.139
+++ w3m-xmas.el	29 Aug 2007 10:52:57 -0000
@@ -165,44 +165,47 @@
   "Decode the string STR which is encoded in CODING.
 If CODING is a list, look for the coding system using it as a priority
 list."
-  (if (listp coding)
-      (with-temp-buffer
-	(insert str)
-	(let* ((orig-category-list (coding-priority-list))
-	       (orig-category-systems (mapcar #'coding-category-system
-					      orig-category-list))
-	       codesys category priority-list)
-	  (unwind-protect
-	      (progn
-		(while coding
-		  (setq codesys (car coding)
-			coding (cdr coding)
-			category (or (coding-system-category codesys)
-				     (coding-system-name codesys)))
-		  (unless (or (eq (coding-system-type codesys) 'undecided)
-			      (assq category priority-list))
-		    (set-coding-category-system category codesys)
-		    (push category priority-list)))
-		(set-coding-priority-list (nreverse priority-list))
-		;; `detect-coding-region' always returns `undecided'
-		;; ignoring `priority-list' in XEmacs 21.5-b19, but
-		;; that's okay.
-		(when (consp (setq codesys (detect-coding-region
-					    (point-min) (point-max))))
-		  (setq codesys (car codesys)))
-		(decode-coding-region (point-min) (point-max)
-				      (or codesys
-					  w3m-default-coding-system
-					  w3m-coding-system
-					  'iso-2022-7bit))
-		(buffer-string))
-	    (set-coding-priority-list orig-category-list)
-	    (while orig-category-list
-	      (set-coding-category-system (car orig-category-list)
-					  (car orig-category-systems))
-	      (setq orig-category-list (cdr orig-category-list)
-		    orig-category-systems (cdr orig-category-systems))))))
-    (decode-coding-string str coding)))
+  (w3m-static-if (and (fboundp 'find-coding-system)
+		      (subrp (symbol-function 'find-coding-system)))
+      (if (listp coding)
+	  (with-temp-buffer
+	    (insert str)
+	    (let* ((orig-category-list (coding-priority-list))
+		   (orig-category-systems (mapcar #'coding-category-system
+						  orig-category-list))
+		   codesys category priority-list)
+	      (unwind-protect
+		  (progn
+		    (while coding
+		      (setq codesys (car coding)
+			    coding (cdr coding)
+			    category (or (coding-system-category codesys)
+					 (coding-system-name codesys)))
+		      (unless (or (eq (coding-system-type codesys) 'undecided)
+				  (assq category priority-list))
+			(set-coding-category-system category codesys)
+			(push category priority-list)))
+		    (set-coding-priority-list (nreverse priority-list))
+		    ;; `detect-coding-region' always returns `undecided'
+		    ;; ignoring `priority-list' in XEmacs 21.5-b19, but
+		    ;; that's okay.
+		    (when (consp (setq codesys (detect-coding-region
+						(point-min) (point-max))))
+		      (setq codesys (car codesys)))
+		    (decode-coding-region (point-min) (point-max)
+					  (or codesys
+					      w3m-default-coding-system
+					      w3m-coding-system
+					      'iso-2022-7bit))
+		    (buffer-string))
+		(set-coding-priority-list orig-category-list)
+		(while orig-category-list
+		  (set-coding-category-system (car orig-category-list)
+					      (car orig-category-systems))
+		  (setq orig-category-list (cdr orig-category-list)
+			orig-category-systems (cdr orig-category-systems))))))
+	(decode-coding-string str coding))
+    str))
 
 (when (and (not (fboundp 'w3m-ucs-to-char))
 	   (fboundp 'unicode-to-char)
Index: w3m.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m.el,v
retrieving revision 1.1295
diff -u -r1.1295 w3m.el
--- w3m.el	28 Aug 2007 08:39:33 -0000	1.1295
+++ w3m.el	29 Aug 2007 10:53:24 -0000
@@ -3112,26 +3112,7 @@
 	    buf)
       (setq start (match-end 0)))
     (setq str (apply 'concat (nreverse (cons (substring str start) buf))))
-    (w3m-static-cond
-     ((and (featurep 'xemacs)
-	   (fboundp 'find-coding-system)
-	   (subrp (symbol-function 'find-coding-system)))
-      (w3m-decode-coding-string-with-priority str coding))
-     ((featurep 'xemacs)
-      str)
-     (t
-      (setq str (string-make-unibyte str))
-      (when (listp coding)
-	(setq coding
-	      (with-temp-buffer
-		(set-buffer-multibyte nil)
-		(insert str)
-		(w3m-detect-coding-region (point-min) (point-max) coding))))
-      (decode-coding-string str
-			    (or coding
-				w3m-default-coding-system
-				w3m-coding-system
-				'iso-2022-7bit))))))
+    (w3m-decode-coding-string-with-priority str coding)))
 
 (defun w3m-url-readable-string (url)
   "Return a readable string for a give encoded URL.