-(defun woman-parse-colon-path (cd-path)
- "Explode a search path CD-PATH into a list of directory names.
-If the platform is MS-DOS/MS-Windows and any path begins with `//',
-assume a Cygwin-style colon-separated search path and convert any
-leading drive specifier `//X/' to `X:', otherwise assume paths
-separated by `path-separator'."
- ;; Based on a suggestion by Jari Aalto.
- (if (and (memq system-type '(ms-dos windows-nt))
- (or (string-match "://" cd-path)
- (and (not (string-match ":" cd-path))
- (string-match "\\`//" cd-path))))
- (let ((path-separator ":"))
- (mapcar
- (function
- (lambda (path) ; //a/b -> a:/b
- (cond ((string-match "\\`//" path)
- (setq path (substring path 1)) ; //a/b -> /a/b
- (aset path 0 (aref path 1)) ; /a/b -> aa/b
- (aset path 1 ?:) ; aa/b -> a:/b
- ))
- path))
- (parse-colon-path cd-path)))
- (parse-colon-path cd-path)))
+(defun woman-mapcan (fn x)
+ "Return concatenated list of FN applied to successive `car' elements of X.
+FN must return a list, cons or nil. Useful for splicing into a list."
+ ;; Based on the Standard Lisp function MAPCAN but with args swapped!
+ ;; More concise implementation than the recursive one. -- dak
+ (apply #'nconc (mapcar fn x)))
+
+(defun woman-parse-colon-path (paths)
+ "Explode search path string PATHS into a list of directory names.
+Allow Cygwin colon-separated search paths on Microsoft platforms.
+Replace null components by calling `woman-parse-man.conf'.
+As a special case, if PATHS is nil then replace it by calling
+`woman-parse-man.conf'."
+ ;; Based on suggestions by Jari Aalto and Eli Zaretskii.
+ ;; parse-colon-path returns nil for a null path component and
+ ;; an empty substring of MANPATH denotes the default list.
+ (if (memq system-type '(windows-nt ms-dos))
+ (cond ((null paths)
+ (mapcar 'woman-Cyg-to-Win (woman-parse-man.conf)))
+ ((string-match ";" paths)
+ ;; Assume DOS-style path-list...
+ (woman-mapcan ; splice list into list
+ (lambda (x)
+ (if x
+ (list x)
+ (mapcar 'woman-Cyg-to-Win (woman-parse-man.conf))))
+ (parse-colon-path paths)))
+ ((string-match "\\`[a-zA-Z]:" paths)
+ ;; Assume single DOS-style path...
+ paths)
+ (t
+ ;; Assume UNIX/Cygwin-style path-list...
+ (woman-mapcan ; splice list into list
+ (lambda (x)
+ (mapcar 'woman-Cyg-to-Win
+ (if x (list x) (woman-parse-man.conf))))
+ (let ((path-separator ":"))
+ (parse-colon-path paths)))))
+ ;; Assume host-default-style path-list...
+ (woman-mapcan ; splice list into list
+ (lambda (x) (if x (list x) (woman-parse-man.conf)))
+ (parse-colon-path (or paths "")))))
+
+(defun woman-Cyg-to-Win (file)
+ "Convert an absolute filename FILE from Cygwin to Windows form."
+ ;; Code taken from w32-symlinks.el
+ (if (eq (aref file 0) ?/)
+ ;; Try to use Cygwin mount table via `cygpath.exe'.
+ (condition-case nil
+ (with-temp-buffer
+ ;; cygpath -m file
+ (call-process "cygpath" nil t nil "-m" file)
+ (buffer-substring 1 (buffer-size)))
+ (error
+ ;; Assume no `cygpath' program available.
+ ;; Hack /cygdrive/x/ or /x/ or (obsolete) //x/ to x:/
+ (when (string-match "\\`\\(/cygdrive\\|/\\)?/./" file)
+ (if (match-string 1) ; /cygdrive/x/ or //x/ -> /x/
+ (setq file (substring file (match-end 1))))
+ (aset file 0 (aref file 1)) ; /x/ -> xx/
+ (aset file 1 ?:)) ; xx/ -> x:/
+ file))
+ file))