annotate lisp/efs/efs-coke.el @ 199:169c0442b401 r20-3b26

Import from CVS: tag r20-3b26
author cvs
date Mon, 13 Aug 2007 10:00:33 +0200
parents 8b8b7f3559a2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1 ;; -*-Emacs-Lisp-*-
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4 ;; File: efs-coke.el
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5 ;; Release: $efs release: 1.15 $
42
8b8b7f3559a2 Import from CVS: tag r19-15b104
cvs
parents: 22
diff changeset
6 ;; Version: #Revision: 1.1 $
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
7 ;; RCS:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
8 ;; Description: Coke Machine support for efs
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
9 ;; Author: Sandy Rutherford <sandy@imb550.sissa.it>
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
10 ;; Created: Fri Oct 14 23:55:04 1994 by sandy on ibm550
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
11 ;; Modified: Sun Nov 27 12:16:47 1994 by sandy on gandalf
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
12 ;; Language: Emacs-Lisp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
13 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
14 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
15
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
16 ;;; This file is part of efs. See efs.el for copyright
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
17 ;;; (it's copylefted) and warrranty (there isn't one) information.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
18
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
19 (provide 'efs-coke)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
20 (require 'efs)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
21
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
22 (defconst efs-coke-version
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
23 (concat (substring "$efs release: 1.15 $" 14 -2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
24 "/"
42
8b8b7f3559a2 Import from CVS: tag r19-15b104
cvs
parents: 22
diff changeset
25 (substring "#Revision: 1.1 $" 11 -2)))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
26
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
27 ;;;; ------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
28 ;;;; Coke Machine support
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
29 ;;;; ------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
30 ;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
31 ;;; Works for the MIT vending machine FTP server.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
32 ;;; Hopefully, a vending machine RFC is on its way, so we won't
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
33 ;;; need to support a wide variation of vending machine protocols.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
34
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
35 (efs-defun efs-send-pwd coke (host user &optional xpwd)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
36 ;; Directories on vending machines?
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
37 "/")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
38
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
39 (efs-defun efs-fix-path coke (path &optional reverse)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
40 (if (= ?/ (aref path 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
41 (if reverse path (substring path 1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
42 (if reverse (concat "/" path) path)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
43
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
44 (efs-defun efs-fix-dir-path coke (dir-path)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
45 ;; Make a beverage path for a dir listing.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
46 (if (or (string-equal dir-path "/") (string-equal dir-path "/."))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
47 "*"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
48 dir-path))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
49
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
50 (efs-defun efs-parse-listing coke
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
51 (host user dir path &optional switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
52 ;; Parse the current buffer which is assumed to be in coke machine
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
53 ;; ftp dir format.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
54 ;; HOST = remote host name
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
55 ;; USER = remote user name
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
56 ;; DIR = remote directory as a remote full path
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
57 ;; PATH = directory as an efs full path
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
58 ;; SWITCHES are never used here, but they
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
59 ;; must be specified in the argument list for compatibility
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
60 ;; with the unix version of this function.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
61 (let ((tbl (efs-make-hashtable)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
62 (goto-char (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
63 (efs-save-match-data
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
64 (while (re-search-forward "^\\(SOLD OUT \\)?\\[[0-9]+\\] +\\([^:\n]+\\)"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
65 nil t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
66 (efs-put-hash-entry (buffer-substring (match-beginning 2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
67 (match-end 2))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
68 (list nil) tbl)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
69 (forward-line 1)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
70 ;; Don't need to bother with ..
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
71 (efs-put-hash-entry "." '(t) tbl)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
72 tbl))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
73
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
74 (efs-defun efs-allow-child-lookup coke (host user dir file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
75 ;; Returns t if FILE in directory DIR could possibly be a subdir
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
76 ;; according to its file-name syntax, and therefore a child listing should
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
77 ;; be attempted.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
78
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
79 ;; Coke machine file system is flat. Hopefully not the coke.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
80 (and (string-equal "/" dir) (string-equal "." file)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
81
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
82 (defun efs-coke-insert-beverage-contents (buffer file line)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
83 ;; Inserts the contents of a beverage (determined by the FTP server
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
84 ;; response LINE) into BUFFER, and then drinks it.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
85 ;; FILE is the name of the file.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
86 (efs-save-buffer-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
87 (set-buffer buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
88 (if (zerop (buffer-size))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
89 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
90 (insert "\n\n\n\n " (substring line 4) "\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
91 (set-buffer-modified-p nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
92 (set-process-sentinel
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
93 (start-process "efs-coke-gulp-buffer" (current-buffer) "sleep" "3")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
94 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
95 (lambda (proc str)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
96 (efs-save-buffer-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
97 (let ((buff (process-buffer proc)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
98 (and buff (get-buffer buff)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
99 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
100 (set-buffer buff)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
101 (erase-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
102 (insert "\n\n\n\n GULP!!!\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
103 (sit-for 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
104 (set-buffer-modified-p nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
105 (kill-buffer (current-buffer)))))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
106 (if (featurep 'dired)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
107 (dired-fun-in-all-buffers
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
108 (file-name-directory file) 'dired-revert)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
109 (message "You haven't finished your last drink in buffer %s!"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
110 (current-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
111 (ding)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
112 (sit-for 1))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
113
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
114 ;;; Dired support
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
115
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
116 (efs-defun efs-dired-manual-move-to-filename coke
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
117 (&optional raise-error bol eol)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
118 ;; In dired, move to first char of filename on this line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
119 ;; Returns position (point) or nil if no filename on this line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
120 ;; This is the COKE version.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
121 (or eol (setq eol (save-excursion (skip-chars-forward "^\n\r") (point))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
122 (if bol
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
123 (goto-char bol)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
124 (skip-chars-backward "^\n\r")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
125 (setq bol (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
126 (if (looking-at "\\(. \\)?\\(SOLD OUT \\)?\\[[0-9]+\\] +\\([^:\n]+\\): ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
127 (goto-char (match-beginning 3))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
128 (and raise-error (error "No file on this line"))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
129
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
130 (efs-defun efs-dired-manual-move-to-end-of-filename coke
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
131 (&optional no-error bol eol)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
132 ;; Assumes point is at beginning of filename.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
133 ;; So, it should be called only after (dired-move-to-filename t).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
134 ;; On failure, signals an error or returns nil.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
135 ;; This is the COKE version.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
136 (let ((opoint (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
137 (and selective-display
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
138 (null no-error)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
139 (eq (char-after
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
140 (1- (or bol (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
141 (skip-chars-backward "^\r\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
142 (point)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
143 ?\r)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
144 ;; File is hidden or omitted.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
145 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
146 ((dired-subdir-hidden-p (dired-current-directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
147 (error
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
148 (substitute-command-keys
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
149 "File line is hidden. Type \\[dired-hide-subdir] to unhide.")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
150 ((error
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
151 (substitute-command-keys
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
152 "File line is omitted. Type \\[dired-omit-toggle] to un-omit."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
153 )))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
154 (if (search-forward ": " eol t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
155 (goto-char (- (match-end 0) 2))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
156 (if no-error
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
157 nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
158 (error "No file on this line"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
159 (point))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
160
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
161 (efs-defun efs-dired-insert-headerline coke (dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
162 (let* ((parsed (efs-ftp-path dir))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
163 (host (car parsed))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
164 (user (nth 1 parsed))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
165 (accounting
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
166 (efs-send-cmd
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
167 host user '(quote pwd)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
168 (format "Getting accounting data for %s@%s user host" user host))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
169 (insert " " user "@" host "\n "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
170 (if (car accounting)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
171 "Account status unavailable"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
172 (substring (nth 1 accounting) 4)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
173 (delete-region (point) (progn (skip-chars-backward ":.,;") (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
174 (insert ":\n \n")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
175
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
176 ;;; end of efs-coke.el