
(provide (quote zwrite))

(require (quote zsigs))

(zsigs-init)

(defvar zwrite-last-instance nil)

(defvar zwrite-last-recipient nil)

(defvar zwrite-last-class nil)

(defvar zwrite-min-height 15)

(defvar zwrite-hook nil "\
Hooks run when zwrite is entered.")

(defvar zwrite-send-hook nil "\
Hooks run when a zgram is sent.")

(defvar zwrite-path "/usr/athena/bin/" "\
Path to zephyr programs")

(defvar zwrite-last-zgram nil "\
List of class, instance, recipient, body of last *sent* zephyrgram")

(defvar zwrite-recipient-list (list (list (user-login-name))))

(defvar zwrite-instance-list (list (list)))

(defvar zwrite-class-list (list (list)))

(define-abbrev-table (quote zwrite-abbrev-table) (quote nil))

(defun zwrite-triple (class instance recipient &optional generic-buffer-name save-pair) "\
Start a zwrite process to the given triple.  Allow the
user to enter a message.  Run zwrite-hook." (byte-code "\"
 !
 ׂ $!	! W-  Z! cɉ߉
!!!!E# !\"!	P\"  &
\"\"!)" [instance b generic-buffer-name class recipient zwrite-min-height local-abbrev-table zwrite-abbrev-table abbrev-mode t major-mode mode-name zwrite-target zwrite-save-pair save-pair zwrite-sig zwrite-process zwrite-path string-equal "" error "Ken you're being lame." generate-new-buffer "*Zwrite*" format "*Zwrite to <%s,%s,%s>*" switch-to-buffer window-height enlarge-window indented-text-mode "*** Zwrite process status: checking for subscribers

" zwrite-mode "Zwrite" make-local-variable zsigs use-local-map make-sparse-keymap local-set-key "" zwrite-send message "Press C-c C-c to send message" start-process "zwrite" equal "*" "-n" "-s" "-c" "-i" set-process-sentinel zwrite-sentinel set-process-filter zwrite-filter run-hooks zwrite-hook] 30))

(defun zwrite-filter (proc str) (byte-code "!qeb!` 	`\")!
\"& cW !
\"4 cW !
\"U cJ A@\"8#W 
c)" [proc start str zwrite-save-pair zwrite-target zwrite-sig t process-buffer search-forward ": " end-of-line delete-region string-match regexp-quote "Type your message now" "Ready for message." "Not logged in" "*** NO SUBSCRIBERS ***" "Message sent" "zwrite successful" zwrite-add-to-list message "%s: %s" 2] 15))

(defun zwrite-send nil (interactive) (byte-code "ň!\"!dbn? ceb!l' !`d\"
	\"	C\")
\")!K \"p! \"" [zwrite-target text zwrite-process zwrite-last-zgram t nil run-hooks zwrite-send-hook message format "Sending message to %s" "
" forward-line 1 buffer-substring process-send-string append "" fboundp zlog-add apply bury-buffer switch-to-buffer other-buffer] 16))

(defun zwrite-resend nil (interactive) (byte-code " 888#8c !" [zwrite-last-zgram nil zwrite-triple 0 1 2 3 error "No last zephyrgram"] 5))

(defun zwrite-string-to-triple (msg class inst recip) (byte-code "
PE\"  C%#\"\"\")!9 $" [p nil zwrite-path recip class inst msg apply start-process append "Zwrite" "zwrite" equal "*" list "-n" "-c" "-i" process-send-string "
" fboundp zlog-add] 12))

(defun zwrite-sentinel (proc str) (byte-code "!!" [proc kill-buffer process-buffer] 3))

(defun zwrite-get-option (prompt specified last list) (byte-code "  
#\"	\" = 	)  " [specified input prompt last list completing-read format "%s [%s]: " equal "" 1 0] 5))

(defun zwrite-personal (&optional recip) (interactive) (byte-code "È	
$
B%" [zwrite-last-recipient recip zwrite-recipient-list nil zwrite-get-option "Send personal message to" zwrite-triple "message" "personal"] 8))

(defun zwrite-instance (&optional inst) (interactive) (byte-code "È	
$
B%" [zwrite-last-instance inst zwrite-instance-list nil zwrite-get-option "Write to instance" zwrite-triple "message" "*"] 8))

(defun zwrite-class (&optional class) (interactive) (byte-code "È	
$\"!!O!!O
B%" [zwrite-last-class class zwrite-class-list nil zwrite-get-option "Write to class(instance)" string-match "\\(.*\\)(\\(.*\\))" zwrite-triple match-beginning 1 match-end 2 "*"] 13))

(defun zwrite-i-help nil (interactive) (byte-code "!" [nil zwrite-instance "help"] 2))

(defun zwrite-i-sipb nil (interactive) (byte-code "!" [nil zwrite-instance "sipb"] 2))

(defun zwrite-punt-instance (instance) (interactive "sInstance to punt: ") (byte-code "P
P&" [instance nil zwrite-path start-process "punt-instance-" "zctl" "unsub" "message" "*"] 8))

(defun zwrite-punt-all nil (interactive) (byte-code "P%P&" [zwrite-path nil call-process "zctl" "cancel" start-process "resubscribe-personal" "sub" "message" "personal" "*"] 9))

(defun zwrite-help-rtfm nil (interactive) (byte-code "$" [nil zwrite-string-to-triple "rtfm..." "message" "help" "*"] 5))

(defun zwrite-help-tryit nil (interactive) (byte-code "$" [nil zwrite-string-to-triple "try it..." "message" "help" "*"] 5))

(defun zwrite-reply-to-sender nil (interactive) (byte-code "!qeb#!  8 8\")* !)" [sender nil t get-buffer "*zwgc*" re-search-forward "From \\(.*\\) on" buffer-substring 2 match-data 3 zwrite-personal] 8))

(defun zwrite-reply-to-instance nil (interactive) (byte-code "!qeb!  8 8\")( !)" [instance nil get-buffer "*zwgc*" re-search-forward " *\\([^ 
]*\\)" buffer-substring 2 match-data 3 zwrite-instance] 8))

(defun zwrite-reply-to-instance-unless-personal nil (interactive) (byte-code "!qeb!  8 8\")G !\"3  G !\"D #G !)" [instance t nil get-buffer "*zwgc*" re-search-forward " *\\([^ 
]*\\)" buffer-substring 2 match-data 3 string-equal downcase "personal" zwrite-reply-to-sender "looney" zwrite-triple "reply" "*" zwrite-instance] 14))

(defun zwrite-add-to-list (list name) "\
Make a new entry at the beginning of LIST which contains NAME as
it's car.  Creates a list suitable for use as an alist." (byte-code "	\"? B	@	AB	
\"	\"	*" [name list new-entry nil new-cell assoc setcar setcdr] 5))
