comparison lisp/gnus/binhex.el @ 33118:a9e6d31e455f

Use (featurep 'xemacs). (binhex-char-int): New alias, replacing char-int. Change callers. (binhex-decode-region): Simplify work buffer code. (binhex-decode-region-external): Use expand-file-name, not concat.
author Dave Love <fx@gnu.org>
date Wed, 01 Nov 2000 14:46:55 +0000
parents 6b20b7e85e3c
children a26d9b55abb6
comparison
equal deleted inserted replaced
33117:334f9d0ca32d 33118:a9e6d31e455f
26 26
27 ;;; Code: 27 ;;; Code:
28 28
29 (eval-when-compile (require 'cl)) 29 (eval-when-compile (require 'cl))
30 30
31 (if (not (fboundp 'char-int)) 31 (defalias 'binhex-char-int
32 (fset 'char-int 'identity)) 32 (if (fboundp 'char-int)
33 'char-int
34 'identity))
33 35
34 (defvar binhex-decoder-program "hexbin" 36 (defvar binhex-decoder-program "hexbin"
35 "*Non-nil value should be a string that names a uu decoder. 37 "*Non-nil value should be a string that names a uu decoder.
36 The program should expect to read binhex data on its standard 38 The program should expect to read binhex data on its standard
37 input and write the converted data to its standard output.") 39 input and write the converted data to its standard output.")
65 (defvar binhex-temporary-file-directory 67 (defvar binhex-temporary-file-directory
66 (cond ((fboundp 'temp-directory) (temp-directory)) 68 (cond ((fboundp 'temp-directory) (temp-directory))
67 ((boundp 'temporary-file-directory) temporary-file-directory) 69 ((boundp 'temporary-file-directory) temporary-file-directory)
68 ("/tmp/"))) 70 ("/tmp/")))
69 71
70 (if (string-match "XEmacs" emacs-version) 72 (if (featurep 'xemacs)
71 (defalias 'binhex-insert-char 'insert-char) 73 (defalias 'binhex-insert-char 'insert-char)
72 (defun binhex-insert-char (char &optional count ignored buffer) 74 (defun binhex-insert-char (char &optional count ignored buffer)
73 (if (or (null buffer) (eq buffer (current-buffer))) 75 (if (or (null buffer) (eq buffer (current-buffer)))
74 (insert-char char count) 76 (insert-char char count)
75 (with-current-buffer buffer 77 (with-current-buffer buffer
130 (error "CRC error"))))) 132 (error "CRC error")))))
131 133
132 (defun binhex-string-big-endian (string) 134 (defun binhex-string-big-endian (string)
133 (let ((ret 0) (i 0) (len (length string))) 135 (let ((ret 0) (i 0) (len (length string)))
134 (while (< i len) 136 (while (< i len)
135 (setq ret (+ (lsh ret 8) (char-int (aref string i))) 137 (setq ret (+ (lsh ret 8) (binhex-char-int (aref string i)))
136 i (1+ i))) 138 i (1+ i)))
137 ret)) 139 ret))
138 140
139 (defun binhex-string-little-endian (string) 141 (defun binhex-string-little-endian (string)
140 (let ((ret 0) (i 0) (shift 0) (len (length string))) 142 (let ((ret 0) (i 0) (shift 0) (len (length string)))
141 (while (< i len) 143 (while (< i len)
142 (setq ret (+ ret (lsh (char-int (aref string i)) shift)) 144 (setq ret (+ ret (lsh (binhex-char-int (aref string i)) shift))
143 i (1+ i) 145 i (1+ i)
144 shift (+ shift 8))) 146 shift (+ shift 8)))
145 ret)) 147 ret))
146 148
147 (defun binhex-header (buffer) 149 (defun binhex-header (buffer)
148 (with-current-buffer buffer 150 (with-current-buffer buffer
149 (let ((pos (point-min)) len) 151 (let ((pos (point-min)) len)
150 (vector 152 (vector
151 (prog1 153 (prog1
152 (setq len (char-int (char-after pos))) 154 (setq len (binhex-char-int (char-after pos)))
153 (setq pos (1+ pos))) 155 (setq pos (1+ pos)))
154 (buffer-substring pos (setq pos (+ pos len))) 156 (buffer-substring pos (setq pos (+ pos len)))
155 (prog1 157 (prog1
156 (setq len (char-int (char-after pos))) 158 (setq len (binhex-char-int (char-after pos)))
157 (setq pos (1+ pos))) 159 (setq pos (1+ pos)))
158 (buffer-substring pos (setq pos (+ pos 4))) 160 (buffer-substring pos (setq pos (+ pos 4)))
159 (buffer-substring pos (setq pos (+ pos 4))) 161 (buffer-substring pos (setq pos (+ pos 4)))
160 (binhex-string-big-endian 162 (binhex-string-big-endian
161 (buffer-substring pos (setq pos (+ pos 2)))) 163 (buffer-substring pos (setq pos (+ pos 2))))
196 binhex-last-char binhex-repeat) 198 binhex-last-char binhex-repeat)
197 (unwind-protect 199 (unwind-protect
198 (save-excursion 200 (save-excursion
199 (goto-char start) 201 (goto-char start)
200 (when (re-search-forward binhex-begin-line end t) 202 (when (re-search-forward binhex-begin-line end t)
201 (if (and (not (string-match "XEmacs\\|Lucid" emacs-version)) 203 (let (default-enable-multibyte-characters)
202 (boundp 'enable-multibyte-characters))
203 (let ((multibyte
204 (default-value 'enable-multibyte-characters)))
205 (setq-default enable-multibyte-characters nil)
206 (setq work-buffer (generate-new-buffer " *binhex-work*"))
207 (setq-default enable-multibyte-characters multibyte))
208 (setq work-buffer (generate-new-buffer " *binhex-work*"))) 204 (setq work-buffer (generate-new-buffer " *binhex-work*")))
209 (buffer-disable-undo work-buffer)
210 (beginning-of-line) 205 (beginning-of-line)
211 (setq bits 0 counter 0) 206 (setq bits 0 counter 0)
212 (while tmp 207 (while tmp
213 (skip-chars-forward non-data-chars end) 208 (skip-chars-forward non-data-chars end)
214 (setq inputpos (point)) 209 (setq inputpos (point))
265 260
266 (defun binhex-decode-region-external (start end) 261 (defun binhex-decode-region-external (start end)
267 "Binhex decode region between START and END using external decoder." 262 "Binhex decode region between START and END using external decoder."
268 (interactive "r") 263 (interactive "r")
269 (let ((cbuf (current-buffer)) firstline work-buffer status 264 (let ((cbuf (current-buffer)) firstline work-buffer status
270 (file-name (concat binhex-temporary-file-directory 265 (file-name (expand-file-name
271 (binhex-decode-region start end t) 266 (concat (binhex-decode-region start end t) ".data")
272 ".data"))) 267 binhex-temporary-file-directory)))
273 (save-excursion 268 (save-excursion
274 (goto-char start) 269 (goto-char start)
275 (when (re-search-forward binhex-begin-line nil t) 270 (when (re-search-forward binhex-begin-line nil t)
276 (let ((cdir default-directory) default-process-coding-system) 271 (let ((cdir default-directory) default-process-coding-system)
277 (unwind-protect 272 (unwind-protect