From xemacs-m  Mon Jan 13 11:01:41 1997
Received: from mgate.uni-hannover.de (mgate.uni-hannover.de [130.75.2.3])
          by xemacs.org (8.8.4/8.8.4) with SMTP
	  id LAA05994 for <xemacs-beta@xemacs.org>; Mon, 13 Jan 1997 11:01:32 -0600 (CST)
Received: from helios (actually helios.tnt.uni-hannover.de) by mgate 
          with SMTP (PP); Mon, 13 Jan 1997 17:58:03 +0100
Received: from daedalus.tnt.uni-hannover.de by helios (SMI-8.6/SMI-SVR4) 
          id RAA18365; Mon, 13 Jan 1997 17:57:23 +0100
Received: by daedalus.tnt.uni-hannover.de (SMI-8.6/SMI-SVR4) id RAA00815;
          Mon, 13 Jan 1997 17:57:17 +0100
Date: Mon, 13 Jan 1997 17:57:17 +0100
Message-Id: <199701131657.RAA00815@daedalus.tnt.uni-hannover.de>
From: Heiko Muenkel <muenkel@tnt.uni-hannover.de>
To: toy@rtp.ericsson.se
Cc: xemacs-beta@xemacs.org
In-Reply-To: <7941.852936278@rtp.ericsson.se>
References: <7941.852936278@rtp.ericsson.se>
X-Face: n}R'l6CHRf>pi&bj7[x0CW3:kmXm@1)7m+l*9[fp;-Ow4Xe~=5E;skf?2> 
        y]f{HzB|Q(\V9+y$PP~.4G[2n4W7{6Ilm[AMY9B:0kj.K_$-d%p4YIF*bX;=ADp6{ 
        HS@NEv9c.VII+9PgXHASx}K(jy^t=q%qzZ72q1e4E;O!$A$`&wgtLk"1%p.nC_G!] 
        4d1!+J4Q#YD_iXeEy`1x)d\r$1Qn\'23n|[8Y_xzuXJJ7W(EGqnzB]`]aq??;+z=) 
        DW~\'Vq&F'g%QU[Mv2:}nS>SdZFTEC2GsgB=Q,:~H<R5S[:ZN%B:s0;|v1x"Jb
Subject: Re: Wishful thinking for TM (2/2)
MIME-version: 1.0
Content-type: message/partial; id="Mon_Jan_13_17:57:15_1997@daedalus.tnt.uni-hannover.de"; number="2"; total="2"

\"      .XXXXXXOOXXXXXXXXXXo      \",
\"      .XXXXXXOOXXXXXXXXXXo      \",
\"      .XXXXXXOO+XXO+XXXXXo      \",
\"      .XXXXOOXOOOOOXXXXXXo      \",
\"      .XXXXOOXXOOOXXXXXXXo      \",
\"      .XXXXXXXXXXXXXXXXXXo      \",
\"      .XXXXXXXXXXXXXXXXXXo      \",
\"      .XXXXXXXXXXXXXXXXXXo      \",
\"      .XXXXXXXXXXXXXXXXXXo      \",
\"      .XXXXXXXXXXXX......o      \",
\"      .XXXXXXXXXXXX.@@@@o       \",
\"      .XXXXXXXXXXXX.@@@o        \",
\"      .XXXXXXXXXXXX.@@o         \",
\"      .XXXXXXXXXXXX.@o          \",
\"      .XXXXXXXXXXXX.o           \",
\"      .ooooooooooooo            \",
\"                                \",
\"                                \",
\"                                \"};"))
       (cons
	'h-file
	(make-pixmap "/* XPM */
static char * h_xpm[] = {
\"32 32 7 1\",
\" 	s None	c None\",
\".	c grey90\",
\"X	c grey75\",
\"o	c grey50\",
\"O	c black\",
\"+	c #888888888888\",
\"@	c grey63\",
\"                                \",
\"                                \",
\"                                \",
\"      ....................      \",
\"      .XXXXXXXXXXXXXXXXXXo      \",
\"      .XXXXXXXXXXXXXXXXXXo      \",
\"      .XXXXXXXXXXXXXXXXXXo      \",
\"      .XXXXXXXXXXXXXXXXXXo      \",
\"      .XXXXXXXOOXXXXXXXXXo      \",
\"      .XXXXXXXOOXXXXXXXXXo      \",
\"      .XXXXXXXOOXXXXXXXXXo      \",
\"      .XXXXXXXOOOOOOXXXXXo      \",
\"      .XXXXXXXOO+X+O+XXXXo      \",
\"      .XXXXXXXOOXXXOOXXXXo      \",
\"      .XXXXXXXOOXXXOOXXXXo      \",
\"      .XXXXXXXOOXXXOOXXXXo      \",
\"      .XXXXOOXOOXXXOOXXXXo      \",
\"      .XXXXOOXOOXXXOOXXXXo      \",
\"      .XXXXXXXXXXXXXXXXXXo      \",
\"      .XXXXXXXXXXXXXXXXXXo      \",
\"      .XXXXXXXXXXXXXXXXXXo      \",
\"      .XXXXXXXXXXXXXXXXXXo      \",
\"      .XXXXXXXXXXXX......o      \",
\"      .XXXXXXXXXXXX.@@@@o       \",
\"      .XXXXXXXXXXXX.@@@o        \",
\"      .XXXXXXXXXXXX.@@o         \",
\"      .XXXXXXXXXXXX.@o          \",
\"      .XXXXXXXXXXXX.o           \",
\"      .ooooooooooooo            \",
\"                                \",
\"                                \",
\"                                \"};"))
       (cons
	'frame-file
	(make-pixmap "/* XPM */
static char * f_xpm[] = {
\"32 32 6 1\",
\" 	s None	c None\",
\".	c grey90\",
\"X	c grey75\",
\"o	c grey50\",
\"O	c black\",
\"+	c grey63\",
\"                                \",
\"                                \",
\"                                \",
\"      ....................      \",
\"      .XXXXXXXXXXXXXXXXXXo      \",
\"      .XXXXXXXOOOOXXXXXXXo      \",
\"      .XXXXXXOXXXXOXXXXXXo      \",
\"      .XXXXXOXXOOXXOXXXXXo      \",
\"      .XXXXOXXOXXOXXOXXXXo      \",
\"      .XXXOXXOXXXXOXXOXXXo      \",
\"      .XXOXXOXXOOXXOXXOXXo      \",
\"      .XXXXOXXOXXOXXOOXXXo      \",
\"      .XXXOXXOXXXXOXOXXXXo      \",
\"      .XXOXXOXXXXXXOXXOXXo      \",
\"      .XXXXOXOXXXXOXXOXXXo      \",
\"      .XXXOOXXOXXOXXOXXXXo      \",
\"      .XXOXXOXXOOXXOXXOXXo      \",
\"      .XXXOXXOXXXXOXXOXXXo      \",
\"      .XXXXOXXOXXOXXOXXXXo      \",
\"      .XXXXXOXXOOXXOXXXXXo      \",
\"      .XXXXXXOXXXXOXXXXXXo      \",
\"      .XXXXXXXOOOOXXXXXXXo      \",
\"      .XXXXXXXXXXXX......o      \",
\"      .XXXXXXXXXXXX.++++o       \",
\"      .XXXXXXXXXXXX.+++o        \",
\"      .XXXXXXXXXXXX.++o         \",
\"      .XXXXXXXXXXXX.+o          \",
\"      .XXXXXXXXXXXX.o           \",
\"      .ooooooooooooo            \",
\"                                \",
\"                                \",
\"                                \"};"))
;       (cons
;	'makefile
;	(make-pixmap "/* XPM */   
;/* Testfile */
;static char *ps_xpm[] = {
;/*   width height ncolors chars_per_pixel x_hot y_hot */
;\"     32     32       6    1   	16      23\",
;/*  colors */	              
;\"  c None	m None\",
;\". c grey90	m white\",
;\"X c green 	m white\",
;\"o c grey50	m white\",
;\"O c black	m black\",
;\"+ c grey63	m white\",
;\"                                \",
;\"                                \",
;\"                                \",
;\"      ....................      \",
;\"      .XXXXXXXXXXXXXXXXXXo      \",
;\"      .XXXXXXXXXXXXXXXXXXo      \",
;\"      .XXXXXXXXXXXXXXXXXXo      \",
;\"      .XXXXXXXXXXXXXXXXXXo      \",
;\"      .XXXOOXXXXXXXXXOOXXo      \",
;\"      .XXXOOOXXXXXXXOOOXXo      \",
;\"      .XXXOOXOXXXXXOXOOXXo      \",
;\"      .XXXOOXXOXXXOXXOOXXo      \",
;\"      .XXXOOXXXOXOXXXOOXXo      \",
;\"      .XXXOOXXXXOXXXXOOXXo      \",
;\"      .XXXOOXXXXXXXXXOOXXo      \",
;\"      .XXXOOXXXXXXXXXOOXXo      \",
;\"      .XXXOOXXXXXXXXXOOXXo      \",
;\"      .XXXXXXXXXXXXXXXXXXo      \",
;\"      .XXXXXXXXXXXXXXXXXXo      \",
;\"      .XXXXXXXXXXXXXXXXXXo      \",
;\"      .XXXXXXXXXXXXXXXXXXo      \",
;\"      .XXXXXXXXXXXXXXXXXXo      \",
;\"      .XXXXXXXXXXXX......o      \",
;\"      .XXXXXXXXXXXX.++++o       \",
;\"      .XXXXXXXXXXXX.+++o        \",
;\"      .XXXXXXXXXXXX.++o         \",
;\"      .XXXXXXXXXXXX.+o          \",
;\"      .XXXXXXXXXXXX.o           \",
;\"      .ooooooooooooo            \",
;\"                                \",
;\"                                \",
;\"                                \"};"))
       ;(cons
;	'audio
;	(make-pixmap "/* XPM */   
;/* Testfile */
;static char *ps_xpm[] = {
;/*   width height ncolors chars_per_pixel x_hot y_hot */
;\"     32     32       6    1   	16      23\",
;/*  colors */	              
;\"  c None	m None\",
;\". c grey90     m white\",
;\"X c gray75     m white\",
;\"o c grey50     m white\",
;\"O c black      m black\",
;\"+ c grey63     m white\",
;\"                                \",
;\"                                \",
;\"                                \",
;\"      ....................      \",
;\"      .XXXXXXXXXXXXXXXXXXo      \",
;\"      .XXXXXXXXXXXXXXXXXXo      \",
;\"      .XXXXXXXXXXOOOXXXXOo      \",
;\"      .XXXXXXXXXOXXOXXXOXo      \",
;\"      .XXXXXXXXOXXXOXXOXXo      \",
;\"      .XXXXXXXOXXXXOXOXXXo      \",
;\"      .XXXXXXOXXXXXOXXXOOo      \",
;\"      .XXOOOOXXXXXXOXOOXXo      \",
;\"      .XXOXXOXXXXXXOXXXXXo      \",
;\"      .XXOXXOXXXXXXOXXXXXo      \",
;\"      .XXOOOOXXXXXXOXOOXXo      \",
;\"      .XXXXXXOXXXXXOXXXOOo      \",
;\"      .XXXXXXXOXXXXOXOXXXo      \",
;\"      .XXXXXXXXOXXXOXXOXXo      \",
;\"      .XXXXXXXXXOXXOXXXOXo      \",
;\"      .XXXXXXXXXXOOOXXXXOo      \",
;\"      .XXXXXXXXXXXXXXXXXXo      \",
;\"      .XXXXXXXXXXXXXXXXXXo      \",
;\"      .XXXXXXXXXXXX......o      \",
;\"      .XXXXXXXXXXXX.++++o       \",
;\"      .XXXXXXXXXXXX.+++o        \",
;\"      .XXXXXXXXXXXX.++o         \",
;\"      .XXXXXXXXXXXX.+o          \",
;\"      .XXXXXXXXXXXX.o           \",
;\"      .ooooooooooooo            \",
;\"                                \",
;\"                                \",
;\"                                \"};"))
       (cons
	'postscript
	(make-pixmap "/* XPM */
static char * ps_xpm[] = {
\"32 32 6 1\",
\" 	s None	c None\",
\".	c grey90\",
\"X	c grey75\",
\"o	c grey50\",
\"O	c black\",
\"+	c grey63\",
\"                                \",
\"                                \",
\"                                \",
\"      ....................      \",
\"      .XXXXXXXXXXXXXXXXXXo      \",
\"      .XXXXXXXXXXXXXXXXXXo      \",
\"      .XXXXXXXXXXXXXXXXXXo      \",
\"      .XXXXXXXXXXXXXXXXXXo      \",
\"      .XXXXXXXXXXXXXXXXXXo      \",
\"      .XXXXXXXXXXXXXXXXXXo      \",
\"      .XXXXOOOOXXXXOOOOXXo      \",
\"      .XXXXOOOOOOXOOXXOOXo      \",
\"      .XXXXOOXXOOXOOXXXXXo      \",
\"      .XXXXOOXXOOXOOOOOXXo      \",
\"      .XXXXOOXXOOXXOOOOOXo      \",
\"      .XXXXOOXXOOXXXXXOOXo      \",
\"      .XOOXOOOOOOXOOXXOOXo      \",
\"      .XOOXOOOOXXXXOOOOXXo      \",
\"      .XXXXOOXXXXXXXXXXXXo      \",
\"      .XXXXOOXXXXXXXXXXXXo      \",
\"      .XXXXOOXXXXXXXXXXXXo      \",
\"      .XXXXXXXXXXXXXXXXXXo      \",
\"      .XXXXXXXXXXXX......o      \",
\"      .XXXXXXXXXXXX.++++o       \",
\"      .XXXXXXXXXXXX.+++o        \",
\"      .XXXXXXXXXXXX.++o         \",
\"      .XXXXXXXXXXXX.+o          \",
\"      .XXXXXXXXXXXX.o           \",
\"      .ooooooooooooo            \",
\"                                \",
\"                                \",
\"                                \"};"))))

;;;; new

(defun mailtool-concat-directory-and-filename (directory filename)
  "Concats the filename at the end of the directory."
  (cond ((eq system-type 'vax-vms) (concat directory filename)) ; untested
	(t (concat (directory-file-name directory) "/" filename))))

(defun mailtool-save-text-region (start 
				  end 
				  data-name
				  &optional directory)
  "Save the text between START and END in the file DATA-NAME.
The user wil be asked for the directory, if DIRECTORY is nil,
otherwise DIRECTORY must be a string with the pathname."
  (if (not directory)
      (setq directory
	    (expand-file-name
	     (read-directory-name "File saving Directory: "
				  nil
				  "/tmp"))))
  (make-directory-path directory)
  (let ((filename (mailtool-concat-directory-and-filename directory data-name))
	)
    (write-region (buffer-substring (marker-position start)
				    (marker-position end)
				    (marker-buffer start))
		  nil
		  filename)
    filename))

(defun mailtool-save-encoded-region (start 
				     end 
				     data-name
				     encoding-info
				     &optional directory)
    "Save the encoded text between START and END in the file DATA-NAME.
The user wil be asked for the directory, if DIRECTORY is nil,
otherwise DIRECTORY must be a string with the pathname.
The ENCODING-INFO is used to determine the decoding program."
  (if (not directory)
      (setq directory
	    (expand-file-name
	     (read-directory-name "File saving Directory: "
				  nil
				  "/tmp"))))
  (make-directory-path directory)
  (let ((decoding-program 
	 (second (assoc encoding-info mailtool-encoding-info-alist))))
    (if decoding-program
	(let* ((file (concat (mailtool-concat-directory-and-filename 
			      directory
			      data-name)))
	       (encoded-file (concat file
				     ".uu"))
	       (default-directory (file-name-directory encoded-file)))
	  (write-region (buffer-substring (marker-position start)
				    (marker-position end)
				    (marker-buffer start))
			nil
			encoded-file)
	  (apply 'call-process (subst encoded-file 'file decoding-program))
	  file))))

(defvar mailtool-actual-icon-data nil
  "Internal variable. Holds the current icon data.")

(defun mailtool-icon-popup-menu (event)
  "Pops an icon menu up."
  (interactive "e")
  (mouse-set-point event)
  (setq mailtool-actual-icon-data
	(extent-property (extent-at (event-point event))
			 'mailtool-icon-data))
  (popup-menu mailtool-icon-popup-menu))

;(defun mailtool-decode (encoding directory file-name start end)
;  "Decode the file in the region from start to end"
;  )

(defun mailtool-print-region (start-mark end-mark)
  "Prints the region between START-MARK and END-MARK."
  (save-excursion
    (switch-to-buffer (marker-buffer start-mark))
    (goto-char (start-mark))
    (set-mark (end-mark))
    (ps-print-region)))

(defun mailtool-exec-internal (encoding arg-list file-name start end)
  "Start an internal viewer.
ARG-LIST is the cdr of a command entry of the `mailtool-data-type-alist'.
The first element of ARG-LIST must be a form, which is evaluated in this
function. This form could contain the following place holders:
-start- : start point of the data region
-end- : end point of the data region
-start-mark- : -start- as a marker
-end-mark- : -end- as a marker
-data-name- : name of the data file (X-Sun_data-Name)
-file-name- : name of the temporary saved file
-buffer- : buffer with the original message data.
-encoding- : the encoding type.

The optional second element of ARG-LIST must be true, if the data shouldn't
be saved in a temporary file before the internal viewer starts."
  (if encoding
      (let* ((-encoding- encoding)
	     (-start-mark- start)
	     (-start- (marker-position start))
	     (-end-mark- end)
	     (-end- (marker-position end))
	     (-buffer- (marker-buffer start))
	     (-data-name- file-name)
	     (-file-name- (if (not (second arg-list))
			      (mailtool-save-encoded-region start 
							    end 
							    file-name
							    encoding
							    mailtool-tmp-dir)
			    nil)))
	(eval (first arg-list)))
    (let* ((-encoding- encoding)
	   (-start-mark- start)
	   (-start- (marker-position start))
	   (-end-mark- end)
	   (-end- (marker-position end))
	   (-buffer- (marker-buffer start))
	   (-data-name- file-name)
	   (-file-name- (if (not (second arg-list))
			    (mailtool-save-text-region start 
						       end 
						       file-name 
						       mailtool-tmp-dir)
			  nil)))
      (eval (first arg-list)))))

(defun mailtool-exec-external (encoding command file-name start end)
  "Start an external viewer.
The command must be a list with one element, a string of the following
format: \"<external-program> %s\". %s will be substitute with the 
file name."
  (if encoding
      (start-process-shell-command 
       "*mailtool*"
       nil
       (format (car command)
	       (mailtool-save-encoded-region start
					     end
					     file-name
					     encoding
					     mailtool-tmp-dir)))
;    (mailtool-decode encoding mailtool-tmp-dir file-name start end))
    (start-process-shell-command
     "*mailtool*"
     nil
     (format (car command)
	     (mailtool-save-text-region start end file-name mailtool-tmp-dir))
		  )))

(defun mailtool-exec-command (encoding command file-name start end)
  "Execute the COMMAND. TEST VERSION !!!!"
;  (message "%s|%s|%s|%s|%s" encoding command file-name start end)
  (funcall (car command) encoding (cdr command) file-name start end)
  )

(defun mailtool-exec-command-with-key (command-key)
  "Execute the command with the COMMAND-KEY from the actual icon data list.
This list is named `mailtool-actual-icon-data'."
  (mailtool-exec-command (fourth mailtool-actual-icon-data)
			 (second (assoc command-key 
					(fifth mailtool-actual-icon-data)))
			 (substring (third mailtool-actual-icon-data)
				    0
				    (string-match 
				     "[ \t]"
				     (third mailtool-actual-icon-data)))
			 (sixth mailtool-actual-icon-data)
			 (seventh mailtool-actual-icon-data)))

(defun mailtool-exist-command-p (command-key)
  "Returns t, if a command exists for the COMMAND-KEY.
The variable `mailtool-actual-icon-data' is used for this."
  (second (assoc command-key (fifth mailtool-actual-icon-data))))

(defvar mailtool-icon-popup-menu nil
  "The icon popup menu.")

(setq mailtool-icon-popup-menu
	'("Icon Popup Menu"
	  ["Open" (mailtool-exec-command-with-key ':open-command) 
	   (mailtool-exist-command-p ':open-command)]
	  ["View" (mailtool-exec-command-with-key ':view-command)
	   (mailtool-exist-command-p ':view-command)]
	  ["Edit" (mailtool-exec-command-with-key ':edit-command)
	   (mailtool-exist-command-p ':edit-command)]
	  ["Run" (mailtool-exec-command-with-key ':run-command)
	   (mailtool-exist-command-p ':run-command)]
	  ["Print" (mailtool-exec-command-with-key ':print-command)
	   (mailtool-exist-command-p ':print-command)]
	  ["Save" (mailtool-exec-command-with-key ':save-command)
	   (mailtool-exist-command-p ':save-command)]
	  )
	)

(provide 'mailtool)

