/[tramp]/tramp/lisp/tramp-smb.el
ViewVC logotype

Diff of /tramp/lisp/tramp-smb.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2.7 by albinus, Tue Nov 19 16:57:39 2002 UTC revision 2.8 by albinus, Wed Nov 20 22:53:03 2002 UTC
# Line 38  Line 38 
38    (or (>= emacs-major-version 20)    (or (>= emacs-major-version 20)
39        (load "cl-seq")))        (load "cl-seq")))
40    
 (autoload 'date-to-time "time-date")  
   
41  (defvar tramp-use-smb nil  (defvar tramp-use-smb nil
42    "*Temporary variable to pretend SMB application as long as under development.    "*Temporary variable to pretend SMB application as long as under development.
43  Change it only if you know what you do.")  Change it only if you know what you do.")
# Line 273  rather than as numbers." Line 271  rather than as numbers."
271                  -1              ;1 link count                  -1              ;1 link count
272                  -1              ;2 uid                  -1              ;2 uid
273                  -1              ;3 gid                  -1              ;3 gid
274                  (nth 7 entry)   ;4 atime                  (nth 3 entry)   ;4 atime
275                  (nth 7 entry)   ;5 mtime                  (nth 3 entry)   ;5 mtime
276                  (nth 7 entry)   ;6 ctime                  (nth 3 entry)   ;6 ctime
277                  (nth 2 entry)   ;7 size                  (nth 2 entry)   ;7 size
278                  (nth 1 entry)   ;8 mode                  (nth 1 entry)   ;8 mode
279                  nil             ;9 gid weird                  nil             ;9 gid weird
# Line 410  SWITCHES, WILDCARD and FULL-DIRECTORY-P Line 408  SWITCHES, WILDCARD and FULL-DIRECTORY-P
408              '(lambda (x y)              '(lambda (x y)
409                 (if (string-match dired-sort-by-date-regexp dired-actual-switches)                 (if (string-match dired-sort-by-date-regexp dired-actual-switches)
410                     ; sort by date                     ; sort by date
411                     (time-less-p (nth 7 y) (nth 7 x))                     (tramp-smb-time-less-p (nth 3 y) (nth 3 x))
412                   ; sort by name                   ; sort by name
413                   (string-lessp (nth 0 x) (nth 0 y))))))                   (string-lessp (nth 0 x) (nth 0 y))))))
414    
# Line 419  SWITCHES, WILDCARD and FULL-DIRECTORY-P Line 417  SWITCHES, WILDCARD and FULL-DIRECTORY-P
417             '(lambda (x)             '(lambda (x)
418                (insert                (insert
419                 (format                 (format
420                  "%10s %3d %-8s %-8s %8s %3s %2s %5s %s\n"                  "%10s %3d %-8s %-8s %8s %s %s\n"
421                  (nth 1 x) ; mode                  (nth 1 x) ; mode
422                  1 "nouser" "nogroup"                  1 "nobody" "nogroup"
423                  (nth 2 x) ; size                  (nth 2 x) ; size
424                  (nth 3 x) ; month                  (format-time-string
425                  (nth 4 x) ; day                   (if (tramp-smb-time-less-p
426                  (if (equal (format-time-string "%Y") (nth 6 x))                        (tramp-smb-time-subtract (current-time) (nth 3 x))
427                      (nth 5 x) ; time                        tramp-smb-half-a-year)
428                    (nth 6 x)) ; year                       "%b %e %R"
429                       "%b %e  %Y")
430                     (nth 3 x)) ; date
431                  (nth 0 x))) ; file name                  (nth 0 x))) ; file name
432                (forward-line)                (forward-line)
433                (beginning-of-line))                (beginning-of-line))
# Line 611  Result is a list of (PATH MODE SIZE MONT Line 611  Result is a list of (PATH MODE SIZE MONT
611    
612    
613          ;; Add directory itself          ;; Add directory itself
614          (add-to-list 'res '("" "dr-xr-xr-x" 0 "Jan" "1" "00:00" "1970" (0 0)))          (add-to-list 'res '("" "dr-xr-xr-x" 0 (0 0)))
615    
616          ;; Check for matching entries          ;; Check for matching entries
617          (delq nil (mapcar          (delq nil (mapcar
# Line 658  Result is a list of (PATH MODE SIZE MONT Line 658  Result is a list of (PATH MODE SIZE MONT
658  (defun tramp-smb-read-file-entry (share)  (defun tramp-smb-read-file-entry (share)
659    "Parse entry in SMB output buffer.    "Parse entry in SMB output buffer.
660  If SHARE is result, entries are of type dir. Otherwise, shares are listed.  If SHARE is result, entries are of type dir. Otherwise, shares are listed.
661  Result is the list (PATH MODE SIZE MONTH DAY TIME YEAR MTIME)."  Result is the list (PATH MODE SIZE MTIME)."
662    (let ((line (buffer-substring (point) (tramp-point-at-eol)))    (let ((line (buffer-substring (point) (tramp-point-at-eol)))
663          path mode size month day time year mtime)          path mode size month day hour min sec year mtime)
664    
665      (if (not share)      (if (not share)
666    
# Line 670  Result is the list (PATH MODE SIZE MONTH Line 670  Result is the list (PATH MODE SIZE MONTH
670                  mode "dr-xr-xr-x"                  mode "dr-xr-xr-x"
671                  size 0                  size 0
672                  month "Jan"                  month "Jan"
673                  day "1"                  day 1
674                  time "00:00"                  hour 0
675                  year "1970"                  min 0
676                  mtime "00:00:00"))                  sec 0
677                    year 1970))
678    
679        ; real listing        ; real listing
680        (block nil        (block nil
681    
682          ;; year          ;; year
683          (if (string-match "\\([0-9]+\\)$" line)          (if (string-match "\\([0-9]+\\)$" line)
684              (setq year (match-string 1 line)              (setq year (string-to-number (match-string 1 line))
685                    line (substring line 0 -5))                    line (substring line 0 -5))
686            (return))            (return))
687    
688          ;; time          ;; time
689          (if (string-match "\\(\\([0-9]+:[0-9]+\\):[0-9]+\\)$" line)          (if (string-match "\\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\)$" line)
690              (setq time (match-string 2 line)              (setq hour (string-to-number (match-string 1 line))
691                    mtime (match-string 1 line)                    min  (string-to-number (match-string 2 line))
692                      sec  (string-to-number (match-string 3 line))
693                    line (substring line 0 -9))                    line (substring line 0 -9))
694            (return))            (return))
695    
696          ;; day          ;; day
697          (if (string-match "\\([0-9]+\\)$" line)          (if (string-match "\\([0-9]+\\)$" line)
698              (setq day (match-string 1 line)              (setq day  (string-to-number (match-string 1 line))
699                    line (substring line 0 -3))                    line (substring line 0 -3))
700            (return))            (return))
701    
702          ;; month          ;; month
703          (if (string-match "\\(\\w+\\)$" line)          (if (string-match "\\(\\w+\\)$" line)
704              (setq month (match-string 1 line)              (setq month (match-string 1 line)
705                    line (substring line 0 -4))                    line  (substring line 0 -4))
706            (return))            (return))
707    
708          ;; weekday          ;; weekday
# Line 732  Result is the list (PATH MODE SIZE MONTH Line 734  Result is the list (PATH MODE SIZE MONTH
734              (setq path (match-string 1 line))              (setq path (match-string 1 line))
735            (return))))            (return))))
736    
737      (when (and path mode size month day time year mtime)      (when (and path mode size sec min hour day month year)
738        (setq mtime        (setq mtime
739              (date-to-time              (encode-time
740               (mapconcat 'identity (list month day mtime year) " ")))               sec min hour day
741        (list path mode size month day time year mtime))))               (cdr (assoc (downcase month) tramp-smb-parse-time-months))
742                 year))
743          (list path mode size mtime))))
744    
745    
746  ;; Connection functions  ;; Connection functions
# Line 792  Domain names in USER and port numbers in Line 796  Domain names in USER and port numbers in
796             domain port args)             domain port args)
797    
798        ; Check for domain ("user%domain") and port ("host#port")        ; Check for domain ("user%domain") and port ("host#port")
799        (when (string-match "\\(.+\\)%\\(.+\\)" user)        (when (and user (string-match "\\(.+\\)%\\(.+\\)" user))
800          (setq real-user (or (match-string 1 user) user)          (setq real-user (or (match-string 1 user) user)
801                domain (match-string 2 user)))                domain (match-string 2 user)))
802    
803        (when (string-match "\\(.+\\)#\\(.+\\)" host)        (when (and host (string-match "\\(.+\\)#\\(.+\\)" host))
804          (setq real-host (or (match-string 1 host) host)          (setq real-host (or (match-string 1 host) host)
805                port (match-string 2 host)))                port (match-string 2 host)))
806    
# Line 890  is not found." Line 894  is not found."
894        ;; Return value is whether tramp-smb-prompt sentinel was found.        ;; Return value is whether tramp-smb-prompt sentinel was found.
895        found)))        found)))
896    
897    
898    ;; Snarfed code from time-date.el and parse-time.el
899    
900    (defconst tramp-smb-half-a-year '(241 17024)
901    "Evaluated by \"(days-to-time 183)\".")
902    
903    (defconst tramp-smb-parse-time-months '(("jan" . 1) ("feb" . 2) ("mar" . 3)
904                                ("apr" . 4) ("may" . 5) ("jun" . 6)
905                                ("jul" . 7) ("aug" . 8) ("sep" . 9)
906                                ("oct" . 10) ("nov" . 11) ("dec" . 12))
907    "Alist mapping month names to integers.")
908    
909    (defun tramp-smb-time-less-p (t1 t2)
910      "Say whether time value T1 is less than time value T2."
911      (or (< (car t1) (car t2))
912          (and (= (car t1) (car t2))
913               (< (nth 1 t1) (nth 1 t2)))))
914    
915    (defun tramp-smb-time-subtract (t1 t2)
916      "Subtract two time values.
917    Return the difference in the format of a time value."
918      (let ((borrow (< (cadr t1) (cadr t2))))
919        (list (- (car t1) (car t2) (if borrow 1 0))
920              (- (+ (if borrow 65536 0) (cadr t1)) (cadr t2)))))
921    
922  (provide 'tramp-smb)  (provide 'tramp-smb)
923    
924  ;;; TODO:  ;;; TODO:
925    
926    ;; * Support M$ Windows on local side.  Apply "net use" but "smbclient".
927  ;; * Provide a local smb.conf. The default one might not be readable.  ;; * Provide a local smb.conf. The default one might not be readable.
928  ;; * Error handling in most of the functions. Brrrr.  ;; * Error handling in most of the functions. Brrrr.
929  ;; * Read password from "~/.netrc".  ;; * Read password from "~/.netrc".
930  ;; * Update documentation.  ;; * Update documentation.
 ;; * In `tramp-smb-handle-insert-directory', compute 183 days differences  
 ;;   for decision whether to print time or year string.  
931  ;; * Return more comprehensive file permission string.  ;; * Return more comprehensive file permission string.
 ;; * Replace `date-to-time' by `encode-time', because existence of  
 ;;   `time-date.el' cannot be assumed. `time-less-p' is a problem as well.  
 ;;   Remember the autoload.  
932  ;; * Use of `dired-sort-by-date-regexp' and `dired-actual-switches' seem  ;; * Use of `dired-sort-by-date-regexp' and `dired-actual-switches' seem
933  ;;   to work in GNU Emacs 21.x only.  ;;   to work in GNU Emacs 21.x only.
934  ;; * Handle '$' respectively '$$' correctly. Currently, it is done in  ;; * Handle '$' respectively '$$' correctly. Currently, it is done in
935  ;;   `tramp-smb-handle-substitute-in-file-name' and `tramp-smb-get-path'.  ;;   `tramp-smb-handle-substitute-in-file-name' and `tramp-smb-get-path'.
936  ;;   But that's not the full game; "C-x f" in dired converts "$" to "$$"  ;;   But that's not the full game; "C-x f" in dired converts "$" to "$$"
937  ;;   overzealous.  ;;   overzealous.
938    ;; * Maybe local tmp files should have the same extension like the original
939    ;;   files.  Strange behaviour with jka-compr otherwise?
940  ;; * Provide variables for debug.  ;; * Provide variables for debug.
941  ;; * (RMS) Use unwind-protect to clean up the state so as to make the state  ;; * (RMS) Use unwind-protect to clean up the state so as to make the state
942  ;;   regular again.  ;;   regular again.

Legend:
Removed from v.2.7  
changed lines
  Added in v.2.8

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26