Function: ange-ftp-ls-parser

ange-ftp-ls-parser is a byte-compiled function defined in ange-ftp.el.gz.

Signature

(ange-ftp-ls-parser SWITCHES)

Source Code

;; Defined in /usr/src/emacs/lisp/net/ange-ftp.el.gz
;; This deals with the F switch. Should also do something about
;; unquoting names obtained with the SysV b switch and the GNU Q
;; switch. See Sebastian's dired-get-filename.

(defun ange-ftp-ls-parser (switches)
  ;; Meant to be called by ange-ftp-parse-dired-listing
  (let ((tbl (make-hash-table :test 'equal))
	(used-F (and (stringp switches)
		     (string-match "F" switches)))
	file-type symlink directory file)
    (while (setq file (ange-ftp-parse-filename))
      (beginning-of-line)
      (skip-chars-forward "\t 0-9")
      (setq file-type (following-char)
	    directory (eq file-type ?d))
      (if (eq file-type ?l)
	  (let ((end (string-match " -> " file)))
	    (if end
		;; Sometimes `ls' appends a @ at the end of the target.
		(setq symlink (substring file (match-end 0)
					 (string-match "@\\'" file))
		      file (substring file 0 end))
	      ;; Shouldn't happen
	      (setq symlink "")))
	(setq symlink nil))
      ;; Only do a costly regexp search if the F switch was used.
      (if (and used-F
	       (not (string-equal file ""))
	       (looking-at
		".[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)"))
	  (let ((socket (eq file-type ?s))
		(executable
		 (and (not symlink) ; x bits don't mean a thing for symlinks
		      (string-match
		       "[xst]"
		       (concat (match-string 1)
			       (match-string 2)
			       (match-string 3))))))
	    ;; Some ls's with the F switch mark symlinks with an @ (ULTRIX)
	    ;; and others don't. (sigh...) Beware, that some Unix's don't
	    ;; seem to believe in the F-switch
	    (if (or (and symlink (string-match "@\\'" file))
		    (and directory (string-match "/\\'" file))
		    (and executable (string-match "\\*\\'" file))
		    (and socket (string-match "=\\'" file)))
		(setq file (substring file 0 -1)))))
      (puthash file (or symlink directory) tbl)
      (forward-line 1))
    (puthash "." t tbl)
    (puthash ".." t tbl)
    tbl))