Mercurial > emacs
comparison lisp/gnus/binhex.el @ 88155:d7ddb3e565de
sync with trunk
author | Henrik Enberg <henrik.enberg@telia.com> |
---|---|
date | Mon, 16 Jan 2006 00:03:54 +0000 |
parents | eb94fa4ed0c0 |
children |
comparison
equal
deleted
inserted
replaced
88154:8ce476d3ba36 | 88155:d7ddb3e565de |
---|---|
1 ;;; binhex.el --- elisp native binhex decode | 1 ;;; binhex.el --- elisp native binhex decode |
2 ;; Copyright (c) 1998 Free Software Foundation, Inc. | 2 |
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, | |
4 ;; 2005 Free Software Foundation, Inc. | |
3 | 5 |
4 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu> | 6 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu> |
5 ;; Create Date: Oct 1, 1998 | |
6 ;; Keywords: binhex news | 7 ;; Keywords: binhex news |
7 | 8 |
8 ;; This file is part of GNU Emacs. | 9 ;; This file is part of GNU Emacs. |
9 | 10 |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | 11 ;; GNU Emacs is free software; you can redistribute it and/or modify |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 ;; GNU General Public License for more details. | 19 ;; GNU General Public License for more details. |
19 | 20 |
20 ;; You should have received a copy of the GNU General Public License | 21 ;; You should have received a copy of the GNU General Public License |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 ;; Boston, MA 02111-1307, USA. | 24 ;; Boston, MA 02110-1301, USA. |
24 | 25 |
25 ;;; Commentary: | 26 ;;; Commentary: |
26 | 27 |
27 ;;; Code: | 28 ;;; Code: |
28 | 29 |
30 (autoload 'executable-find "executable") | |
31 | |
29 (eval-when-compile (require 'cl)) | 32 (eval-when-compile (require 'cl)) |
30 | 33 |
31 (defalias 'binhex-char-int | 34 (eval-and-compile |
32 (if (fboundp 'char-int) | 35 (defalias 'binhex-char-int |
33 'char-int | 36 (if (fboundp 'char-int) |
34 'identity)) | 37 'char-int |
35 | 38 'identity))) |
36 (defvar binhex-decoder-program "hexbin" | 39 |
37 "*Non-nil value should be a string that names a uu decoder. | 40 (defcustom binhex-decoder-program "hexbin" |
41 "*Non-nil value should be a string that names a binhex decoder. | |
38 The program should expect to read binhex data on its standard | 42 The program should expect to read binhex data on its standard |
39 input and write the converted data to its standard output.") | 43 input and write the converted data to its standard output." |
40 | 44 :type 'string |
41 (defvar binhex-decoder-switches '("-d") | 45 :group 'gnus-extract) |
42 "*List of command line flags passed to the command `binhex-decoder-program'.") | 46 |
47 (defcustom binhex-decoder-switches '("-d") | |
48 "*List of command line flags passed to the command `binhex-decoder-program'." | |
49 :group 'gnus-extract | |
50 :type '(repeat string)) | |
51 | |
52 (defcustom binhex-use-external | |
53 (executable-find binhex-decoder-program) | |
54 "*Use external binhex program." | |
55 :version "22.1" | |
56 :group 'gnus-extract | |
57 :type 'boolean) | |
43 | 58 |
44 (defconst binhex-alphabet-decoding-alist | 59 (defconst binhex-alphabet-decoding-alist |
45 '(( ?\! . 0) ( ?\" . 1) ( ?\# . 2) ( ?\$ . 3) ( ?\% . 4) ( ?\& . 5) | 60 '(( ?\! . 0) ( ?\" . 1) ( ?\# . 2) ( ?\$ . 3) ( ?\% . 4) ( ?\& . 5) |
46 ( ?\' . 6) ( ?\( . 7) ( ?\) . 8) ( ?\* . 9) ( ?\+ . 10) ( ?\, . 11) | 61 ( ?\' . 6) ( ?\( . 7) ( ?\) . 8) ( ?\* . 9) ( ?\+ . 10) ( ?\, . 11) |
47 ( ?\- . 12) ( ?0 . 13) ( ?1 . 14) ( ?2 . 15) ( ?3 . 16) ( ?4 . 17) | 62 ( ?\- . 12) ( ?0 . 13) ( ?1 . 14) ( ?2 . 15) ( ?3 . 16) ( ?4 . 17) |
67 (defvar binhex-temporary-file-directory | 82 (defvar binhex-temporary-file-directory |
68 (cond ((fboundp 'temp-directory) (temp-directory)) | 83 (cond ((fboundp 'temp-directory) (temp-directory)) |
69 ((boundp 'temporary-file-directory) temporary-file-directory) | 84 ((boundp 'temporary-file-directory) temporary-file-directory) |
70 ("/tmp/"))) | 85 ("/tmp/"))) |
71 | 86 |
72 (if (featurep 'xemacs) | 87 (eval-and-compile |
73 (defalias 'binhex-insert-char 'insert-char) | 88 (defalias 'binhex-insert-char |
74 (defun binhex-insert-char (char &optional count ignored buffer) | 89 (if (featurep 'xemacs) |
75 (if (or (null buffer) (eq buffer (current-buffer))) | 90 'insert-char |
76 (insert-char char count) | 91 (lambda (char &optional count ignored buffer) |
77 (with-current-buffer buffer | 92 "Insert COUNT copies of CHARACTER into BUFFER." |
78 (insert-char char count))))) | 93 (if (or (null buffer) (eq buffer (current-buffer))) |
94 (insert-char char count) | |
95 (with-current-buffer buffer | |
96 (insert-char char count))))))) | |
79 | 97 |
80 (defvar binhex-crc-table | 98 (defvar binhex-crc-table |
81 [0 4129 8258 12387 16516 20645 24774 28903 | 99 [0 4129 8258 12387 16516 20645 24774 28903 |
82 33032 37161 41290 45419 49548 53677 57806 61935 | 100 33032 37161 41290 45419 49548 53677 57806 61935 |
83 4657 528 12915 8786 21173 17044 29431 25302 | 101 4657 528 12915 8786 21173 17044 29431 25302 |
182 ((= char 144) | 200 ((= char 144) |
183 (setq binhex-repeat t)) | 201 (setq binhex-repeat t)) |
184 (t | 202 (t |
185 (binhex-insert-char (setq binhex-last-char char) 1 ignored buffer)))) | 203 (binhex-insert-char (setq binhex-last-char char) 1 ignored buffer)))) |
186 | 204 |
187 (defun binhex-decode-region (start end &optional header-only) | 205 ;;;###autoload |
188 "Binhex decode region between START and END. | 206 (defun binhex-decode-region-internal (start end &optional header-only) |
207 "Binhex decode region between START and END without using an external program. | |
189 If HEADER-ONLY is non-nil only decode header and return filename." | 208 If HEADER-ONLY is non-nil only decode header and return filename." |
190 (interactive "r") | 209 (interactive "r") |
191 (let ((work-buffer nil) | 210 (let ((work-buffer nil) |
192 (counter 0) | 211 (counter 0) |
193 (bits 0) (tmp t) | 212 (bits 0) (tmp t) |
256 (aref header 6))) | 275 (aref header 6))) |
257 (delete-region (point) end))) | 276 (delete-region (point) end))) |
258 (and work-buffer (kill-buffer work-buffer))) | 277 (and work-buffer (kill-buffer work-buffer))) |
259 (if header (aref header 1)))) | 278 (if header (aref header 1)))) |
260 | 279 |
280 ;;;###autoload | |
261 (defun binhex-decode-region-external (start end) | 281 (defun binhex-decode-region-external (start end) |
262 "Binhex decode region between START and END using external decoder." | 282 "Binhex decode region between START and END using external decoder." |
263 (interactive "r") | 283 (interactive "r") |
264 (let ((cbuf (current-buffer)) firstline work-buffer status | 284 (let ((cbuf (current-buffer)) firstline work-buffer status |
265 (file-name (expand-file-name | 285 (file-name (expand-file-name |
266 (concat (binhex-decode-region start end t) ".data") | 286 (concat (binhex-decode-region-internal start end t) |
287 ".data") | |
267 binhex-temporary-file-directory))) | 288 binhex-temporary-file-directory))) |
268 (save-excursion | 289 (save-excursion |
269 (goto-char start) | 290 (goto-char start) |
270 (when (re-search-forward binhex-begin-line nil t) | 291 (when (re-search-forward binhex-begin-line nil t) |
271 (let ((cdir default-directory) default-process-coding-system) | 292 (let ((cdir default-directory) default-process-coding-system) |
294 (error "Can not binhex"))) | 315 (error "Can not binhex"))) |
295 (and work-buffer (kill-buffer work-buffer)) | 316 (and work-buffer (kill-buffer work-buffer)) |
296 (ignore-errors | 317 (ignore-errors |
297 (if file-name (delete-file file-name)))))) | 318 (if file-name (delete-file file-name)))))) |
298 | 319 |
320 ;;;###autoload | |
321 (defun binhex-decode-region (start end) | |
322 "Binhex decode region between START and END." | |
323 (interactive "r") | |
324 (if binhex-use-external | |
325 (binhex-decode-region-external start end) | |
326 (binhex-decode-region-internal start end))) | |
327 | |
299 (provide 'binhex) | 328 (provide 'binhex) |
300 | 329 |
330 ;;; arch-tag: 8476badd-1e76-4f1d-a640-f9a38c72eed8 | |
301 ;;; binhex.el ends here | 331 ;;; binhex.el ends here |