aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2000-06-22 14:57:45 +0000
committerEli Zaretskii2000-06-22 14:57:45 +0000
commit09def38b4d617ef48e989cc6c2fa424a2895676f (patch)
tree9953168d0e71af2192c758578a1d148bb6b63ccc
parent543ce495ab064ce3fc344176e4bfa0446d4032e6 (diff)
downloademacs-09def38b4d617ef48e989cc6c2fa424a2895676f.tar.gz
emacs-09def38b4d617ef48e989cc6c2fa424a2895676f.zip
(convert-standard-filename): Convert leading
directories as well. When long file names are supported, convert characters that are invalid in Windows file names.
-rw-r--r--lisp/dos-fns.el109
1 files changed, 67 insertions, 42 deletions
diff --git a/lisp/dos-fns.el b/lisp/dos-fns.el
index 64ed19b0010..d4fb12c1927 100644
--- a/lisp/dos-fns.el
+++ b/lisp/dos-fns.el
@@ -34,49 +34,74 @@
34This function's standard definition is trivial; it just returns the argument. 34This function's standard definition is trivial; it just returns the argument.
35However, on some systems, the function is redefined 35However, on some systems, the function is redefined
36with a definition that really does change some file names." 36with a definition that really does change some file names."
37 (if (or (msdos-long-file-names) 37 (if (or (not (stringp filename))
38 (not (stringp filename)) 38 ;; Note: the empty file-name-nondirectory catches the case
39 (member (file-name-nondirectory filename) '("" "." ".."))) 39 ;; where FILENAME is "x:" or "x:/", thus preventing infinite
40 ;; recursion.
41 (string-match "\\`[a-zA-Z]:[/\\]?\\'" filename))
40 filename 42 filename
41 (let* ((dir (file-name-directory filename)) 43 ;; If FILENAME has a trailing slash, remove it and recurse.
42 (string (copy-sequence (file-name-nondirectory filename))) 44 (if (memq (aref filename (1- (length filename))) '(?/ ?\\))
43 (lastchar (aref string (1- (length string)))) 45 (concat (convert-standard-filename
44 i firstdot) 46 (substring filename 0 (1- (length filename))))
45 ;; Change a leading period to a leading underscore. 47 "/")
46 (if (= (aref string 0) ?.) 48 (let* ((dir
47 (aset string 0 ?_)) 49 ;; If FILENAME is "x:foo", file-name-directory returns
48 ;; Get rid of invalid characters. 50 ;; "x:/bar/baz", substituting the current working
49 (while (setq i (string-match 51 ;; directory on drive x:. We want to be left with "x:"
50 "[^-a-zA-Z0-9_.%~^$!#&{}@`'()\200-\376]" 52 ;; instead.
51 string)) 53 (if (and (eq (aref filename 1) ?:)
52 (aset string i ?_)) 54 (null (string-match "[/\\]" filename)))
53 ;; If we don't have a period, 55 (substring filename 0 2)
54 ;; and we have a dash or underscore that isn't the first char, 56 (file-name-directory filename)))
55 ;; change that to a period. 57 (string (copy-sequence (file-name-nondirectory filename)))
56 (if (and (not (string-match "\\." string)) 58 (lastchar (aref string (1- (length string))))
57 (setq i (string-match "[-_]" string 1))) 59 i firstdot)
58 (aset string i ?\.)) 60 (if (msdos-long-file-names)
59 ;; If we don't have a period in the first 8 chars, insert one. 61 ;; Replace characters that are invalid even on Windows.
60 (if (> (or (string-match "\\." string) 62 (while (setq i (string-match "[?*:<>|\"\000-\037]" string))
61 (length string)) 63 (aset string i ?!))
62 8) 64 ;; Change a leading period to a leading underscore.
63 (setq string 65 (if (= (aref string 0) ?.)
64 (concat (substring string 0 8) 66 (aset string 0 ?_))
65 "." 67 ;; Get rid of invalid characters.
66 (substring string 8)))) 68 (while (setq i (string-match
67 (setq firstdot (or (string-match "\\." string) (1- (length string)))) 69 "[^-a-zA-Z0-9_.%~^$!#&{}@`'()\200-\376]"
68 ;; Truncate to 3 chars after the first period. 70 string))
69 (if (> (length string) (+ firstdot 4)) 71 (aset string i ?_))
70 (setq string (substring string 0 (+ firstdot 4)))) 72 ;; If we don't have a period,
71 ;; Change all periods except the first one into underscores. 73 ;; and we have a dash or underscore that isn't the first char,
72 (while (string-match "\\." string (1+ firstdot)) 74 ;; change that to a period.
73 (setq i (string-match "\\." string (1+ firstdot))) 75 (if (and (not (string-match "\\." string))
74 (aset string i ?_)) 76 (setq i (string-match "[-_]" string 1)))
75 ;; If the last character of the original filename was `~', 77 (aset string i ?\.))
76 ;; make sure the munged name ends with it also. 78 ;; If we don't have a period in the first 8 chars, insert one.
77 (if (equal lastchar ?~) 79 (if (> (or (string-match "\\." string)
78 (aset string (1- (length string)) lastchar)) 80 (length string))
79 (concat dir string)))) 81 8)
82 (setq string
83 (concat (substring string 0 8)
84 "."
85 (substring string 8))))
86 (setq firstdot (or (string-match "\\." string) (1- (length string))))
87 ;; Truncate to 3 chars after the first period.
88 (if (> (length string) (+ firstdot 4))
89 (setq string (substring string 0 (+ firstdot 4))))
90 ;; Change all periods except the first one into underscores.
91 (while (string-match "\\." string (1+ firstdot))
92 (setq i (string-match "\\." string (1+ firstdot)))
93 (aset string i ?_))
94 ;; If the last character of the original filename was `~',
95 ;; make sure the munged name ends with it also.
96 (if (equal lastchar ?~)
97 (aset string (1- (length string)) lastchar)))
98 (concat (if (and (stringp dir)
99 (memq (aref dir (1- (length dir))) '(?/ ?\\)))
100 (concat (convert-standard-filename
101 (substring dir 0 (1- (length dir))))
102 "/")
103 (convert-standard-filename dir))
104 string)))))
80 105
81;; See dos-vars.el for defcustom. 106;; See dos-vars.el for defcustom.
82(defvar msdos-shells) 107(defvar msdos-shells)