Mercurial > emacs
comparison lisp/dos-fns.el @ 15187:d46c1e8bdb0d
(convert-standard-filename): Test msdos-long-file-names.
Return "." or ".." unchanged.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 08 May 1996 17:40:51 +0000 |
parents | 20f4c4a078b2 |
children | 160e99f12c6d |
comparison
equal
deleted
inserted
replaced
15186:242bddc25e5a | 15187:d46c1e8bdb0d |
---|---|
47 (defun convert-standard-filename (filename) | 47 (defun convert-standard-filename (filename) |
48 "Convert a standard file's name to something suitable for the current OS. | 48 "Convert a standard file's name to something suitable for the current OS. |
49 This function's standard definition is trivial; it just returns the argument. | 49 This function's standard definition is trivial; it just returns the argument. |
50 However, on some systems, the function is redefined | 50 However, on some systems, the function is redefined |
51 with a definition that really does change some file names." | 51 with a definition that really does change some file names." |
52 (let* ((dir (file-name-directory filename)) | 52 (if (or (msdos-long-file-names) |
53 (string (copy-sequence (file-name-nondirectory filename))) | 53 (not (stringp filename)) |
54 (lastchar (aref string (1- (length string)))) | 54 (member (file-name-nondirectory filename) '("" "." ".."))) |
55 i firstdot) | 55 filename |
56 ;; If the argument is empty, just return it. | 56 (let* ((dir (file-name-directory filename)) |
57 (if (or (not (stringp filename)) | 57 (string (copy-sequence (file-name-nondirectory filename))) |
58 (string= filename "") | 58 (lastchar (aref string (1- (length string)))) |
59 (string= string "")) | 59 i firstdot) |
60 filename | 60 ;; If the argument is empty, just return it. |
61 (progn | 61 ;; Change a leading period to a leading underscore. |
62 ;; Change a leading period to a leading underscore. | 62 (if (= (aref string 0) ?.) |
63 (if (= (aref string 0) ?.) | 63 (aset string 0 ?_)) |
64 (aset string 0 ?_)) | 64 ;; Get rid of invalid characters. |
65 ;; Get rid of invalid characters. | 65 (while (setq i (string-match |
66 (while (setq i (string-match | 66 "[^-a-zA-Z0-9_.%~^$!#&{}@`'()\200-\376]" |
67 "[^-a-zA-Z0-9_.%~^$!#&{}@`'()\200-\376]" | 67 string)) |
68 string)) | 68 (aset string i ?_)) |
69 (aset string i ?_)) | 69 ;; If we don't have a period, |
70 ;; If we don't have a period, | 70 ;; and we have a dash or underscore that isn't the first char, |
71 ;; and we have a dash or underscore that isn't the first char, | 71 ;; change that to a period. |
72 ;; change that to a period. | 72 (if (and (not (string-match "\\." string)) |
73 (if (and (not (string-match "\\." string)) | 73 (setq i (string-match "[-_]" string 1))) |
74 (setq i (string-match "[-_]" string 1))) | 74 (aset string i ?\.)) |
75 (aset string i ?\.)) | 75 ;; If we don't have a period in the first 8 chars, insert one. |
76 ;; If we don't have a period in the first 8 chars, insert one. | 76 (if (> (or (string-match "\\." string) |
77 (if (> (or (string-match "\\." string) | 77 (length string)) |
78 (length string)) | 78 8) |
79 8) | 79 (setq string |
80 (setq string | 80 (concat (substring string 0 8) |
81 (concat (substring string 0 8) | 81 "." |
82 "." | 82 (substring string 8)))) |
83 (substring string 8)))) | 83 (setq firstdot (or (string-match "\\." string) (1- (length string)))) |
84 (setq firstdot (or (string-match "\\." string) (1- (length string)))) | 84 ;; Truncate to 3 chars after the first period. |
85 ;; Truncate to 3 chars after the first period. | 85 (if (> (length string) (+ firstdot 4)) |
86 (if (> (length string) (+ firstdot 4)) | 86 (setq string (substring string 0 (+ firstdot 4)))) |
87 (setq string (substring string 0 (+ firstdot 4)))) | 87 ;; Change all periods except the first one into underscores. |
88 ;; Change all periods except the first one into underscores. | 88 (while (string-match "\\." string (1+ firstdot)) |
89 (while (string-match "\\." string (1+ firstdot)) | 89 (setq i (string-match "\\." string (1+ firstdot))) |
90 (setq i (string-match "\\." string (1+ firstdot))) | 90 (aset string i ?_)) |
91 (aset string i ?_)) | 91 ;; If the last character of the original filename was `~', |
92 ;; If the last character of the original filename was `~', | 92 ;; make sure the munged name ends with it also. |
93 ;; make sure the munged name ends with it also. | 93 (if (equal lastchar ?~) |
94 (if (equal lastchar ?~) | 94 (aset string (1- (length string)) lastchar)) |
95 (aset string (1- (length string)) lastchar)) | 95 (concat dir string)))) |
96 (concat dir string))))) | |
97 | 96 |
98 (defvar file-name-buffer-file-type-alist | 97 (defvar file-name-buffer-file-type-alist |
99 '( | 98 '( |
100 ("[:/].*config.sys$" . nil) ; config.sys text | 99 ("[:/].*config.sys$" . nil) ; config.sys text |
101 ("\\.elc$" . t) ; emacs stuff | 100 ("\\.elc$" . t) ; emacs stuff |