annotate lisp/mail/binhex.el @ 112321:dc74e58f6b0b

Merge from mainline.
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 11 Jan 2011 21:57:19 -0800
parents 40af77a50adc
children 417b1e4d63cd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
112054
1af8fe6a8d55 * lisp/mail/binhex.el: Improve commentary (Bug#7482).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
1 ;;; binhex.el --- decode BinHex-encoded text
86959
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
2
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
86959
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
5
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
6 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
7 ;; Keywords: binhex news
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
8
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
10
94674
ef65fa4dca3b Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
86959
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
94674
ef65fa4dca3b Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
13 ;; the Free Software Foundation, either version 3 of the License, or
ef65fa4dca3b Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
14 ;; (at your option) any later version.
86959
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
15
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
20
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
94674
ef65fa4dca3b Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
86959
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
23
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
24 ;;; Commentary:
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
25
112054
1af8fe6a8d55 * lisp/mail/binhex.el: Improve commentary (Bug#7482).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
26 ;; BinHex is a binary-to-text encoding scheme similar to uuencode.
1af8fe6a8d55 * lisp/mail/binhex.el: Improve commentary (Bug#7482).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
27 ;; The command `binhex-decode-region' decodes BinHex-encoded text, via
1af8fe6a8d55 * lisp/mail/binhex.el: Improve commentary (Bug#7482).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
28 ;; the external program "hexbin" if that is available, or an Emacs
1af8fe6a8d55 * lisp/mail/binhex.el: Improve commentary (Bug#7482).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
29 ;; Lisp implementation if not.
1af8fe6a8d55 * lisp/mail/binhex.el: Improve commentary (Bug#7482).
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
30
86959
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
31 ;;; Code:
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
32
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
33 (eval-when-compile (require 'cl))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
34
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
35 (eval-and-compile
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
36 (defalias 'binhex-char-int
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
37 (if (fboundp 'char-int)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
38 'char-int
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
39 'identity)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
40
86960
8f2d093e6920 (binhex): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 86959
diff changeset
41 (defgroup binhex nil
8f2d093e6920 (binhex): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 86959
diff changeset
42 "Decoding of BinHex (binary-to-hexadecimal) data."
8f2d093e6920 (binhex): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 86959
diff changeset
43 :group 'mail
8f2d093e6920 (binhex): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 86959
diff changeset
44 :group 'news)
8f2d093e6920 (binhex): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 86959
diff changeset
45
86959
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
46 (defcustom binhex-decoder-program "hexbin"
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
47 "*Non-nil value should be a string that names a binhex decoder.
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
48 The program should expect to read binhex data on its standard
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
49 input and write the converted data to its standard output."
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
50 :type 'string
86960
8f2d093e6920 (binhex): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 86959
diff changeset
51 :group 'binhex)
86959
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
52
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
53 (defcustom binhex-decoder-switches '("-d")
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
54 "*List of command line flags passed to the command `binhex-decoder-program'."
86960
8f2d093e6920 (binhex): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 86959
diff changeset
55 :group 'binhex
86959
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
56 :type '(repeat string))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
57
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
58 (defcustom binhex-use-external
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
59 (executable-find binhex-decoder-program)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
60 "*Use external binhex program."
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
61 :version "22.1"
86960
8f2d093e6920 (binhex): New custom group.
Glenn Morris <rgm@gnu.org>
parents: 86959
diff changeset
62 :group 'binhex
86959
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
63 :type 'boolean)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
64
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
65 (defconst binhex-alphabet-decoding-alist
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
66 '(( ?\! . 0) ( ?\" . 1) ( ?\# . 2) ( ?\$ . 3) ( ?\% . 4) ( ?\& . 5)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
67 ( ?\' . 6) ( ?\( . 7) ( ?\) . 8) ( ?\* . 9) ( ?\+ . 10) ( ?\, . 11)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
68 ( ?\- . 12) ( ?0 . 13) ( ?1 . 14) ( ?2 . 15) ( ?3 . 16) ( ?4 . 17)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
69 ( ?5 . 18) ( ?6 . 19) ( ?8 . 20) ( ?9 . 21) ( ?@ . 22) ( ?A . 23)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
70 ( ?B . 24) ( ?C . 25) ( ?D . 26) ( ?E . 27) ( ?F . 28) ( ?G . 29)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
71 ( ?H . 30) ( ?I . 31) ( ?J . 32) ( ?K . 33) ( ?L . 34) ( ?M . 35)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
72 ( ?N . 36) ( ?P . 37) ( ?Q . 38) ( ?R . 39) ( ?S . 40) ( ?T . 41)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
73 ( ?U . 42) ( ?V . 43) ( ?X . 44) ( ?Y . 45) ( ?Z . 46) ( ?\[ . 47)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
74 ( ?\` . 48) ( ?a . 49) ( ?b . 50) ( ?c . 51) ( ?d . 52) ( ?e . 53)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
75 ( ?f . 54) ( ?h . 55) ( ?i . 56) ( ?j . 57) ( ?k . 58) ( ?l . 59)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
76 ( ?m . 60) ( ?p . 61) ( ?q . 62) ( ?r . 63)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
77
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
78 (defun binhex-char-map (char)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
79 (cdr (assq char binhex-alphabet-decoding-alist)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
80
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
81 ;;;###autoload
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
82 (defconst binhex-begin-line
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
83 "^:...............................................................$")
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
84 (defconst binhex-body-line
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
85 "^[^:]...............................................................$")
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
86 (defconst binhex-end-line ":$")
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
87
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
88 (defvar binhex-temporary-file-directory
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
89 (cond ((fboundp 'temp-directory) (temp-directory))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
90 ((boundp 'temporary-file-directory) temporary-file-directory)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
91 ("/tmp/")))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
92
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
93 (eval-and-compile
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
94 (defalias 'binhex-insert-char
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
95 (if (featurep 'xemacs)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
96 'insert-char
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
97 (lambda (char &optional count ignored buffer)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
98 "Insert COUNT copies of CHARACTER into BUFFER."
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
99 (if (or (null buffer) (eq buffer (current-buffer)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
100 (insert-char char count)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
101 (with-current-buffer buffer
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
102 (insert-char char count)))))))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
103
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
104 (defvar binhex-crc-table
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
105 [0 4129 8258 12387 16516 20645 24774 28903
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
106 33032 37161 41290 45419 49548 53677 57806 61935
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
107 4657 528 12915 8786 21173 17044 29431 25302
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
108 37689 33560 45947 41818 54205 50076 62463 58334
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
109 9314 13379 1056 5121 25830 29895 17572 21637
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
110 42346 46411 34088 38153 58862 62927 50604 54669
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
111 13907 9842 5649 1584 30423 26358 22165 18100
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
112 46939 42874 38681 34616 63455 59390 55197 51132
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
113 18628 22757 26758 30887 2112 6241 10242 14371
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
114 51660 55789 59790 63919 35144 39273 43274 47403
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
115 23285 19156 31415 27286 6769 2640 14899 10770
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
116 56317 52188 64447 60318 39801 35672 47931 43802
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
117 27814 31879 19684 23749 11298 15363 3168 7233
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
118 60846 64911 52716 56781 44330 48395 36200 40265
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
119 32407 28342 24277 20212 15891 11826 7761 3696
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
120 65439 61374 57309 53244 48923 44858 40793 36728
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
121 37256 33193 45514 41451 53516 49453 61774 57711
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
122 4224 161 12482 8419 20484 16421 28742 24679
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
123 33721 37784 41979 46042 49981 54044 58239 62302
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
124 689 4752 8947 13010 16949 21012 25207 29270
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
125 46570 42443 38312 34185 62830 58703 54572 50445
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
126 13538 9411 5280 1153 29798 25671 21540 17413
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
127 42971 47098 34713 38840 59231 63358 50973 55100
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
128 9939 14066 1681 5808 26199 30326 17941 22068
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
129 55628 51565 63758 59695 39368 35305 47498 43435
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
130 22596 18533 30726 26663 6336 2273 14466 10403
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
131 52093 56156 60223 64286 35833 39896 43963 48026
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
132 19061 23124 27191 31254 2801 6864 10931 14994
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
133 64814 60687 56684 52557 48554 44427 40424 36297
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
134 31782 27655 23652 19525 15522 11395 7392 3265
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
135 61215 65342 53085 57212 44955 49082 36825 40952
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
136 28183 32310 20053 24180 11923 16050 3793 7920])
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
137
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
138 (defun binhex-update-crc (crc char &optional count)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
139 (if (null count) (setq count 1))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
140 (while (> count 0)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
141 (setq crc (logxor (logand (lsh crc 8) 65280)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
142 (aref binhex-crc-table
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
143 (logxor (logand (lsh crc -8) 255)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
144 char)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
145 count (1- count)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
146 crc)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
147
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
148 (defun binhex-verify-crc (buffer start end)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
149 (with-current-buffer buffer
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
150 (let ((pos start) (crc 0) (last (- end 2)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
151 (while (< pos last)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
152 (setq crc (binhex-update-crc crc (char-after pos))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
153 pos (1+ pos)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
154 (if (= crc (binhex-string-big-endian (buffer-substring last end)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
155 nil
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
156 (error "CRC error")))))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
157
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
158 (defun binhex-string-big-endian (string)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
159 (let ((ret 0) (i 0) (len (length string)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
160 (while (< i len)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
161 (setq ret (+ (lsh ret 8) (binhex-char-int (aref string i)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
162 i (1+ i)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
163 ret))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
164
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
165 (defun binhex-string-little-endian (string)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
166 (let ((ret 0) (i 0) (shift 0) (len (length string)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
167 (while (< i len)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
168 (setq ret (+ ret (lsh (binhex-char-int (aref string i)) shift))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
169 i (1+ i)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
170 shift (+ shift 8)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
171 ret))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
172
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
173 (defun binhex-header (buffer)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
174 (with-current-buffer buffer
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
175 (let ((pos (point-min)) len)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
176 (vector
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
177 (prog1
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
178 (setq len (binhex-char-int (char-after pos)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
179 (setq pos (1+ pos)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
180 (buffer-substring pos (setq pos (+ pos len)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
181 (prog1
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
182 (setq len (binhex-char-int (char-after pos)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
183 (setq pos (1+ pos)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
184 (buffer-substring pos (setq pos (+ pos 4)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
185 (buffer-substring pos (setq pos (+ pos 4)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
186 (binhex-string-big-endian
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
187 (buffer-substring pos (setq pos (+ pos 2))))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
188 (binhex-string-big-endian
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
189 (buffer-substring pos (setq pos (+ pos 4))))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
190 (binhex-string-big-endian
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
191 (buffer-substring pos (setq pos (+ pos 4))))))))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
192
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
193 (defvar binhex-last-char)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
194 (defvar binhex-repeat)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
195
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
196 (defun binhex-push-char (char &optional count ignored buffer)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
197 (cond
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
198 (binhex-repeat
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
199 (if (eq char 0)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
200 (binhex-insert-char (setq binhex-last-char 144) 1
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
201 ignored buffer)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
202 (binhex-insert-char binhex-last-char (- char 1)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
203 ignored buffer)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
204 (setq binhex-last-char nil))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
205 (setq binhex-repeat nil))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
206 ((= char 144)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
207 (setq binhex-repeat t))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
208 (t
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
209 (binhex-insert-char (setq binhex-last-char char) 1 ignored buffer))))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
210
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
211 ;;;###autoload
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
212 (defun binhex-decode-region-internal (start end &optional header-only)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
213 "Binhex decode region between START and END without using an external program.
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
214 If HEADER-ONLY is non-nil only decode header and return filename."
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
215 (interactive "r")
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
216 (let ((work-buffer nil)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
217 (counter 0)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
218 (bits 0) (tmp t)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
219 (lim 0) inputpos
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
220 (non-data-chars " \t\n\r:")
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
221 file-name-length data-fork-start
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
222 header
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
223 binhex-last-char binhex-repeat)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
224 (unwind-protect
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
225 (save-excursion
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
226 (goto-char start)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
227 (when (re-search-forward binhex-begin-line end t)
92783
b8de2f698e11 (binhex-decode-region-internal): Use set-buffer-multibyte rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
228 (setq work-buffer (generate-new-buffer " *binhex-work*"))
108287
c0d13767677a Synch with Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 106815
diff changeset
229 (unless (featurep 'xemacs)
c0d13767677a Synch with Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 106815
diff changeset
230 (with-current-buffer work-buffer (set-buffer-multibyte nil)))
86959
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
231 (beginning-of-line)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
232 (setq bits 0 counter 0)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
233 (while tmp
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
234 (skip-chars-forward non-data-chars end)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
235 (setq inputpos (point))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
236 (end-of-line)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
237 (setq lim (point))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
238 (while (and (< inputpos lim)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
239 (setq tmp (binhex-char-map (char-after inputpos))))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
240 (setq bits (+ bits tmp)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
241 counter (1+ counter)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
242 inputpos (1+ inputpos))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
243 (cond ((= counter 4)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
244 (binhex-push-char (lsh bits -16) 1 nil work-buffer)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
245 (binhex-push-char (logand (lsh bits -8) 255) 1 nil
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
246 work-buffer)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
247 (binhex-push-char (logand bits 255) 1 nil
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
248 work-buffer)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
249 (setq bits 0 counter 0))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
250 (t (setq bits (lsh bits 6)))))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
251 (if (null file-name-length)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
252 (with-current-buffer work-buffer
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
253 (setq file-name-length (char-after (point-min))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
254 data-fork-start (+ (point-min)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
255 file-name-length 22))))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
256 (when (and (null header)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
257 (with-current-buffer work-buffer
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
258 (>= (buffer-size) data-fork-start)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
259 (binhex-verify-crc work-buffer
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
260 (point-min) data-fork-start)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
261 (setq header (binhex-header work-buffer))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
262 (when header-only (setq tmp nil counter 0)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
263 (setq tmp (and tmp (not (eq inputpos end)))))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
264 (cond
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
265 ((= counter 3)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
266 (binhex-push-char (logand (lsh bits -16) 255) 1 nil
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
267 work-buffer)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
268 (binhex-push-char (logand (lsh bits -8) 255) 1 nil
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
269 work-buffer))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
270 ((= counter 2)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
271 (binhex-push-char (logand (lsh bits -10) 255) 1 nil
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
272 work-buffer))))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
273 (if header-only nil
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
274 (binhex-verify-crc work-buffer
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
275 data-fork-start
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
276 (+ data-fork-start (aref header 6) 2))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
277 (or (markerp end) (setq end (set-marker (make-marker) end)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
278 (goto-char start)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
279 (insert-buffer-substring work-buffer
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
280 data-fork-start (+ data-fork-start
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
281 (aref header 6)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
282 (delete-region (point) end)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
283 (and work-buffer (kill-buffer work-buffer)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
284 (if header (aref header 1))))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
285
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
286 ;;;###autoload
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
287 (defun binhex-decode-region-external (start end)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
288 "Binhex decode region between START and END using external decoder."
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
289 (interactive "r")
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
290 (let ((cbuf (current-buffer)) firstline work-buffer status
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
291 (file-name (expand-file-name
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
292 (concat (binhex-decode-region-internal start end t)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
293 ".data")
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
294 binhex-temporary-file-directory)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
295 (save-excursion
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
296 (goto-char start)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
297 (when (re-search-forward binhex-begin-line nil t)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
298 (let ((cdir default-directory) default-process-coding-system)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
299 (unwind-protect
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
300 (progn
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
301 (set-buffer (setq work-buffer
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
302 (generate-new-buffer " *binhex-work*")))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
303 (buffer-disable-undo work-buffer)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
304 (insert-buffer-substring cbuf firstline end)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
305 (cd binhex-temporary-file-directory)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
306 (apply 'call-process-region
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
307 (point-min)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
308 (point-max)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
309 binhex-decoder-program
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
310 nil
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
311 nil
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
312 nil
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
313 binhex-decoder-switches))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
314 (cd cdir) (set-buffer cbuf)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
315 (if (and file-name (file-exists-p file-name))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
316 (progn
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
317 (goto-char start)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
318 (delete-region start end)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
319 (let (format-alist)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
320 (insert-file-contents-literally file-name)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
321 (error "Can not binhex")))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
322 (and work-buffer (kill-buffer work-buffer))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
323 (ignore-errors
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
324 (if file-name (delete-file file-name))))))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
325
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
326 ;;;###autoload
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
327 (defun binhex-decode-region (start end)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
328 "Binhex decode region between START and END."
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
329 (interactive "r")
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
330 (if binhex-use-external
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
331 (binhex-decode-region-external start end)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
332 (binhex-decode-region-internal start end)))
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
333
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
334 (provide 'binhex)
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
335
2a30481eb39c Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
336 ;;; binhex.el ends here