update.
[elisp/flim.git] / mel-u.el
index 46e9efa..ead3efb 100644 (file)
--- a/mel-u.el
+++ b/mel-u.el
@@ -1,12 +1,12 @@
-;;; mel-u.el: uuencode encoder/decoder for GNU Emacs
+;;; mel-u.el --- uuencode encoder/decoder.
 
 
-;; Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
+;; Copyright (C) 1995,1996,1997,1998,1999 Free Software Foundation, Inc.
 
 
-;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
+;; Author: MORIOKA Tomohiko <tomo@m17n.org>
 ;; Created: 1995/10/25
 ;; Keywords: uuencode
 
 ;; Created: 1995/10/25
 ;; Keywords: uuencode
 
-;; This file is part of MEL (MIME Encoding Library).
+;; This file is part of FLIM (Faithful Library about Internet Message).
 
 ;; This program is free software; you can redistribute it and/or
 ;; modify it under the terms of the GNU General Public License as
 
 ;; This program is free software; you can redistribute it and/or
 ;; modify it under the terms of the GNU General Public License as
 ;; General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
 ;; General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; along with this program; see the file COPYING.  If not, write to the
 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 ;; Boston, MA 02111-1307, USA.
 
 ;;; Code:
 
 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 ;; Boston, MA 02111-1307, USA.
 
 ;;; Code:
 
-(require 'emu)
 (require 'mime-def)
 (require 'mime-def)
+(require 'path-util)
+
+
+(mel-define-backend "x-uue")
 
 
 ;;; @ variables
 
 
 ;;; @ variables
@@ -35,8 +38,7 @@
 (defvar uuencode-external-encoder '("uuencode" "-")
   "*list of uuencode encoder program name and its arguments.")
 
 (defvar uuencode-external-encoder '("uuencode" "-")
   "*list of uuencode encoder program name and its arguments.")
 
-(defvar uuencode-external-decoder
-  (list "sh" "-c" (format "(cd %s; uudecode)" mime-temp-directory))
+(defvar uuencode-external-decoder '("sh" "-c" "uudecode")
   "*list of uuencode decoder program name and its arguments.")
 
 
   "*list of uuencode decoder program name and its arguments.")
 
 
@@ -49,17 +51,17 @@ This function uses external uuencode encoder which is specified by
 variable `uuencode-external-encoder'."
   (interactive "*r")
   (save-excursion
 variable `uuencode-external-encoder'."
   (interactive "*r")
   (save-excursion
-    (as-binary-process (apply (function call-process-region)
-                             start end (car uuencode-external-encoder)
-                             t t nil (cdr uuencode-external-encoder))
-                      )
+    (let ((coding-system-for-read  'binary)
+         (coding-system-for-write 'binary))
+      (apply (function call-process-region)
+            start end (car uuencode-external-encoder)
+            t t nil
+            (cdr uuencode-external-encoder)))
     ;; for OS/2
     ;;   regularize line break code
     (goto-char (point-min))
     (while (re-search-forward "\r$" nil t)
     ;; for OS/2
     ;;   regularize line break code
     (goto-char (point-min))
     (while (re-search-forward "\r$" nil t)
-      (replace-match "")
-      )
-    ))
+      (replace-match ""))))
 
 (defun uuencode-external-decode-region (start end)
   "Decode current region by unofficial uuencode format.
 
 (defun uuencode-external-decode-region (start end)
   "Decode current region by unofficial uuencode format.
@@ -74,48 +76,63 @@ variable `uuencode-external-decoder'."
                        (if (re-search-forward "^begin [0-9]+ " nil t)
                            (if (looking-at ".+$")
                                (buffer-substring (match-beginning 0)
                        (if (re-search-forward "^begin [0-9]+ " nil t)
                            (if (looking-at ".+$")
                                (buffer-substring (match-beginning 0)
-                                                 (match-end 0))
-                             )))))
-         (default-directory (or (getenv "TMP")(getenv "TEMP") "/tmp")))
+                                                 (match-end 0)))))))
+         (default-directory temporary-file-directory))
       (if filename
       (if filename
-         (as-binary-process
-          (apply (function call-process-region)
-                 start end (car uuencode-external-decoder)
-                 t nil nil (cdr uuencode-external-decoder))
-          (as-binary-input-file (insert-file-contents filename))
-          ;; The previous line causes the buffer to be made read-only, I
-          ;; do not pretend to understand the control flow leading to this
-          ;; but suspect it has something to do with image-mode. -slb
-          ;;   Use `inhibit-read-only' to avoid to force
-          ;;   buffer-read-only nil. - tomo.
-          (let ((inhibit-read-only t))
-            (delete-file filename)
-            )
-          ))
-      )))
-
-(defalias 'uuencode-encode-region 'uuencode-external-encode-region)
-(defalias 'uuencode-decode-region 'uuencode-external-decode-region)
+         (let ((coding-system-for-read  'binary)
+               (coding-system-for-write 'binary))
+           (apply (function call-process-region)
+                  start end (car uuencode-external-decoder)
+                  t nil nil
+                  (cdr uuencode-external-decoder))
+           (insert-file-contents filename)
+           ;; The previous line causes the buffer to be made read-only, I
+           ;; do not pretend to understand the control flow leading to this
+           ;; but suspect it has something to do with image-mode. -slb
+           ;;  Use `inhibit-read-only' to avoid to force
+           ;;  buffer-read-only nil. - tomo.
+           (let ((inhibit-read-only t))
+             (delete-file filename)))))))
+
+(mel-define-method-function (mime-encode-region start end (nil "x-uue"))
+                           'uuencode-external-encode-region)
+(mel-define-method-function (mime-decode-region start end (nil "x-uue"))
+                           'uuencode-external-decode-region)
+
+
+;;; @ encoder/decoder for string
+;;;
+
+(mel-define-method mime-encode-string (string (nil "x-uue"))
+  (with-temp-buffer
+    (insert string)
+    (uuencode-external-encode-region (point-min)(point-max))
+    (buffer-string)))
+
+(mel-define-method mime-decode-string (string (nil "x-uue"))
+  (with-temp-buffer
+    (insert string)
+    (uuencode-external-decode-region (point-min)(point-max))
+    (buffer-string)))
 
 
 ;;; @ uuencode encoder/decoder for file
 ;;;
 
 
 
 ;;; @ uuencode encoder/decoder for file
 ;;;
 
-(defun uuencode-insert-encoded-file (filename)
+(mel-define-method mime-insert-encoded-file (filename (nil "x-uue"))
   "Insert file encoded by unofficial uuencode format.
 This function uses external uuencode encoder which is specified by
 variable `uuencode-external-encoder'."
   "Insert file encoded by unofficial uuencode format.
 This function uses external uuencode encoder which is specified by
 variable `uuencode-external-encoder'."
-  (interactive (list (read-file-name "Insert encoded file: ")))
-  (call-process (car uuencode-external-encoder) filename t nil
-               (file-name-nondirectory filename))
-  )
+  (interactive "*fInsert encoded file: ")
+  (call-process (car uuencode-external-encoder)
+               filename t nil
+               (file-name-nondirectory filename)))
 
 
-(defun uuencode-write-decoded-region (start end filename)
+(mel-define-method mime-write-decoded-region (start end filename
+                                                   (nil "x-uue"))
   "Decode and write current region encoded by uuencode into FILENAME.
 START and END are buffer positions."
   "Decode and write current region encoded by uuencode into FILENAME.
 START and END are buffer positions."
-  (interactive
-   (list (region-beginning) (region-end)
-        (read-file-name "Write decoded region to file: ")))
+  (interactive "*r\nFWrite decoded region to file: ")
   (save-excursion
     (let ((file (save-excursion
                  (save-restriction
   (save-excursion
     (let ((file (save-excursion
                  (save-restriction
@@ -124,16 +141,16 @@ START and END are buffer positions."
                    (if (re-search-forward "^begin [0-9]+ " nil t)
                        (if (looking-at ".+$")
                            (buffer-substring (match-beginning 0)
                    (if (re-search-forward "^begin [0-9]+ " nil t)
                        (if (looking-at ".+$")
                            (buffer-substring (match-beginning 0)
-                                             (match-end 0))
-                         )))))
-         (default-directory (or (getenv "TMP")(getenv "TEMP") "/tmp")))
+                                             (match-end 0)))))))
+         (default-directory temporary-file-directory))
       (if file
       (if file
-         (as-binary-process
-          (apply (function call-process-region)
-                 start end (car uuencode-external-decoder)
-                 nil nil nil (cdr uuencode-external-decoder))
-          (rename-file file filename 'overwrites)
-          )))))
+         (let ((coding-system-for-read  'binary)
+               (coding-system-for-write 'binary))
+           (apply (function call-process-region)
+                  start end (car uuencode-external-decoder)
+                  nil nil nil
+                  (cdr uuencode-external-decoder))
+           (rename-file file filename 'overwrites))))))
 
 
 ;;; @ end
 
 
 ;;; @ end
@@ -141,4 +158,6 @@ START and END are buffer positions."
 
 (provide 'mel-u)
 
 
 (provide 'mel-u)
 
-;;; mel-u.el ends here
+(mel-define-backend "x-uuencode" ("x-uue"))
+
+;;; mel-u.el ends here.