comparison lisp/net-utils.el @ 26430:9b2b851efc39

(net-utils-run-program): Changed backquotes to new style (run-network-program): Changed backquotes to new style Added smbclient functions and variables
author Peter Breton <pbreton@attbi.com>
date Sat, 13 Nov 1999 15:22:27 +0000
parents 01eac276e455
children
comparison
equal deleted inserted replaced
26429:e20b16957cdd 26430:9b2b851efc39
1 ;;; net-utils.el --- Network functions 1 ;;; net-utils.el --- Network functions
2 2
3 ;; Author: Peter Breton <pbreton@cs.umb.edu> 3 ;; Author: Peter Breton <pbreton@cs.umb.edu>
4 ;; Created: Sun Mar 16 1997 4 ;; Created: Sun Mar 16 1997
5 ;; Keywords: network communications 5 ;; Keywords: network communications
6 ;; Time-stamp: <1999-10-15 23:14:59 pbreton> 6 ;; Time-stamp: <1999-11-13 10:19:01 pbreton>
7 7
8 ;; This file is part of GNU Emacs. 8 ;; This file is part of GNU Emacs.
9 9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify 10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by 11 ;; it under the terms of the GNU General Public License as published by
194 :type '(repeat string) 194 :type '(repeat string)
195 ) 195 )
196 196
197 (defcustom ftp-prompt-regexp "^ftp>" 197 (defcustom ftp-prompt-regexp "^ftp>"
198 "Regexp which matches the FTP program's prompt." 198 "Regexp which matches the FTP program's prompt."
199 :group 'net-utils
200 :type 'regexp
201 )
202
203 (defcustom smbclient-program "smbclient"
204 "Smbclient program."
205 :group 'net-utils
206 :type 'string
207 )
208
209 (defcustom smbclient-program-options nil
210 "List of options to pass to the smbclient program."
211 :group 'net-utils
212 :type '(repeat string)
213 )
214
215 (defcustom smbclient-prompt-regexp "^smb: \>"
216 "Regexp which matches the smbclient program's prompt."
199 :group 'net-utils 217 :group 'net-utils
200 :type 'regexp 218 :type 'regexp
201 ) 219 )
202 220
203 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 221 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
242 (require 'font-lock) 260 (require 'font-lock)
243 (list 261 (list
244 (list ftp-prompt-regexp 0 font-lock-reference-face))))) 262 (list ftp-prompt-regexp 0 font-lock-reference-face)))))
245 263
246 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 264 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
265 ;; smbclient goodies
266 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
267
268 (defconst smbclient-font-lock-keywords
269 (and window-system
270 (progn
271 (require 'font-lock)
272 (list
273 (list smbclient-prompt-regexp 0 font-lock-reference-face)))))
274
275 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
247 ;; Utility functions 276 ;; Utility functions
248 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 277 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
249 278
250 ;; Simplified versions of some at-point functions from ffap.el. 279 ;; Simplified versions of some at-point functions from ffap.el.
251 ;; It's not worth loading all of ffap just for these. 280 ;; It's not worth loading all of ffap just for these.
294 (if moving (goto-char (process-mark process)))) 323 (if moving (goto-char (process-mark process))))
295 (set-buffer old-buffer)))) 324 (set-buffer old-buffer))))
296 325
297 (defmacro net-utils-run-program (name header program &rest args) 326 (defmacro net-utils-run-program (name header program &rest args)
298 "Run a network information program." 327 "Run a network information program."
299 (` 328 ` (let ((buf (get-buffer-create (concat "*" ,name "*"))))
300 (let ((buf (get-buffer-create (concat "*" (, name) "*")))) 329 (set-buffer buf)
301 (set-buffer buf) 330 (erase-buffer)
302 (erase-buffer) 331 (insert ,header "\n")
303 (insert (, header) "\n") 332 (set-process-filter
304 (set-process-filter 333 (apply 'start-process ,name buf ,program ,@args)
305 (apply 'start-process (, name) buf (, program) (,@ args)) 334 'net-utils-remove-ctrl-m-filter)
306 'net-utils-remove-ctrl-m-filter) 335 (display-buffer buf)))
307 (display-buffer buf))))
308 336
309 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 337 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
310 ;; Wrappers for external network programs 338 ;; Wrappers for external network programs
311 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 339 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
312 340
526 (define-abbrev ftp-mode-abbrev-table "p" "prompt") 554 (define-abbrev ftp-mode-abbrev-table "p" "prompt")
527 (define-abbrev ftp-mode-abbrev-table "anon" "anonymous") 555 (define-abbrev ftp-mode-abbrev-table "anon" "anonymous")
528 556
529 ;; Occasionally useful 557 ;; Occasionally useful
530 (define-key ftp-mode-map "\t" 'comint-dynamic-complete) 558 (define-key ftp-mode-map "\t" 'comint-dynamic-complete)
559
560 (defun smbclient (host service)
561 "Connect to SERVICE on HOST via SMB."
562 (interactive
563 (list
564 (read-from-minibuffer
565 "Connect to Host: " (net-utils-machine-at-point))
566 (read-from-minibuffer "SMB Service: ")))
567 (require 'comint)
568 (let* ((name (format "smbclient [%s\\%s]" host service))
569 (buf (get-buffer-create (concat "*" name "*")))
570 (service-name (concat "\\\\" host "\\" service)))
571 (set-buffer buf)
572 (comint-mode)
573 (comint-exec buf name smbclient-program nil
574 (if smbclient-program-options
575 (append (list service-name) smbclient-program-options)
576 (list service-name)))
577 (smbclient-mode)
578 (switch-to-buffer-other-window buf)
579 ))
580
581 (defun smbclient-list-shares (host)
582 "List services on HOST."
583 (interactive
584 (list
585 (read-from-minibuffer
586 "Connect to Host: " (net-utils-machine-at-point))
587 ))
588 (let ((buf (get-buffer-create (format "*SMB Shares on %s*" host))))
589 (set-buffer buf)
590 (comint-mode)
591 (comint-exec
592 buf
593 "smbclient-list-shares"
594 smbclient-program
595 nil
596 (list "-L" host)
597 )
598 (smbclient-mode)
599 (switch-to-buffer-other-window buf)))
600
601 (define-derived-mode
602 smbclient-mode comint-mode "smbclient"
603 "Major mode for interacting with the smbclient program."
604
605 (set
606 (make-local-variable 'font-lock-defaults)
607 '((smbclient-font-lock-keywords)))
608
609 (make-local-variable 'comint-prompt-regexp)
610 (setq comint-prompt-regexp smbclient-prompt-regexp)
611
612 (make-local-variable 'comint-input-autoexpand)
613 (setq comint-input-autoexpand t)
614
615 ;; Already buffer local!
616 (setq comint-output-filter-functions
617 (list 'comint-watch-for-password-prompt))
618
619 (setq local-abbrev-table smbclient-mode-abbrev-table)
620 (abbrev-mode t)
621 )
622
623 (define-abbrev smbclient-mode-abbrev-table "q" "quit")
624
531 625
532 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 626 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
533 ;; Network Connections 627 ;; Network Connections
534 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 628 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
535 629
564 This list in not complete.") 658 This list in not complete.")
565 659
566 ;; Workhorse macro 660 ;; Workhorse macro
567 (defmacro run-network-program (process-name host port 661 (defmacro run-network-program (process-name host port
568 &optional initial-string) 662 &optional initial-string)
569 (` 663 `
570 (let ((tcp-connection) 664 (let ((tcp-connection)
571 (buf) 665 (buf)
572 ) 666 )
573 (setq buf (get-buffer-create (concat "*" (, process-name) "*"))) 667 (setq buf (get-buffer-create (concat "*" ,process-name "*")))
574 (set-buffer buf) 668 (set-buffer buf)
575 (or 669 (or
576 (setq tcp-connection 670 (setq tcp-connection
577 (open-network-stream 671 (open-network-stream
578 (, process-name) 672 ,process-name
579 buf 673 buf
580 (, host) 674 ,host
581 (, port) 675 ,port
582 )) 676 ))
583 (error "Could not open connection to %s" (, host))) 677 (error "Could not open connection to %s" ,host))
584 (erase-buffer) 678 (erase-buffer)
585 (set-marker (process-mark tcp-connection) (point-min)) 679 (set-marker (process-mark tcp-connection) (point-min))
586 (set-process-filter tcp-connection 'net-utils-remove-ctrl-m-filter) 680 (set-process-filter tcp-connection 'net-utils-remove-ctrl-m-filter)
587 (and (, initial-string) 681 (and ,initial-string
588 (process-send-string tcp-connection 682 (process-send-string tcp-connection
589 (concat (, initial-string) "\r\n"))) 683 (concat ,initial-string "\r\n")))
590 (display-buffer buf)))) 684 (display-buffer buf)))
591 685
592 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 686 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
593 ;; Simple protocols 687 ;; Simple protocols
594 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 688 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
595 689