Mercurial > emacs
comparison lisp/dos-fns.el @ 39305:22c925655e32
(convert-standard-filename): Replace invalid
characters only after converting dash/underscore to a period.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Sun, 16 Sep 2001 17:58:09 +0000 |
parents | 5be08a776a76 |
children | 321baeaafdc2 |
comparison
equal
deleted
inserted
replaced
39304:7be776e0f517 | 39305:22c925655e32 |
---|---|
72 (aset string i ?!))) | 72 (aset string i ?!))) |
73 ((not (member string '("" "." ".."))) | 73 ((not (member string '("" "." ".."))) |
74 ;; Change a leading period to a leading underscore. | 74 ;; Change a leading period to a leading underscore. |
75 (if (= (aref string 0) ?.) | 75 (if (= (aref string 0) ?.) |
76 (aset string 0 ?_)) | 76 (aset string 0 ?_)) |
77 ;; If the name is longer than 8 chars, and doesn't have a | |
78 ;; period, and we have a dash or underscore that isn't too | |
79 ;; close to the beginning, change that to a period. This | |
80 ;; is so we could salvage more characters of the original | |
81 ;; name by pushing them into the extension. | |
82 (if (and (not (string-match "\\." string)) | |
83 (> (length string) 8) | |
84 ;; We don't gain anything if we put the period closer | |
85 ;; than 5 chars from the beginning (5 + 3 = 8). | |
86 (setq i (string-match "[-_]" string 5))) | |
87 (aset string i ?\.)) | |
77 ;; Get rid of invalid characters. | 88 ;; Get rid of invalid characters. |
78 (while (setq i (string-match | 89 (while (setq i (string-match |
79 "[^-a-zA-Z0-9_.%~^$!#&{}@`'()\200-\376]" | 90 "[^-a-zA-Z0-9_.%~^$!#&{}@`'()\200-\376]" |
80 string)) | 91 string)) |
81 (aset string i ?_)) | 92 (aset string i ?_)) |
82 ;; If we don't have a period, | |
83 ;; and we have a dash or underscore that isn't the first char, | |
84 ;; change that to a period. | |
85 (if (and (not (string-match "\\." string)) | |
86 (setq i (string-match "[-_]" string 1))) | |
87 (aset string i ?\.)) | |
88 ;; If we don't have a period in the first 8 chars, insert one. | 93 ;; If we don't have a period in the first 8 chars, insert one. |
94 ;; This enables to have 3 more characters from the original | |
95 ;; name in the extension. | |
89 (if (> (or (string-match "\\." string) (length string)) | 96 (if (> (or (string-match "\\." string) (length string)) |
90 8) | 97 8) |
91 (setq string | 98 (setq string |
92 (concat (substring string 0 8) | 99 (concat (substring string 0 8) |
93 "." | 100 "." |
96 (1- (length string)))) | 103 (1- (length string)))) |
97 ;; Truncate to 3 chars after the first period. | 104 ;; Truncate to 3 chars after the first period. |
98 (if (> (length string) (+ firstdot 4)) | 105 (if (> (length string) (+ firstdot 4)) |
99 (setq string (substring string 0 (+ firstdot 4)))) | 106 (setq string (substring string 0 (+ firstdot 4)))) |
100 ;; Change all periods except the first one into underscores. | 107 ;; Change all periods except the first one into underscores. |
108 ;; (DOS doesn't allow more than one period.) | |
101 (while (string-match "\\." string (1+ firstdot)) | 109 (while (string-match "\\." string (1+ firstdot)) |
102 (setq i (string-match "\\." string (1+ firstdot))) | 110 (setq i (string-match "\\." string (1+ firstdot))) |
103 (aset string i ?_)) | 111 (aset string i ?_)) |
104 ;; If the last character of the original filename was `~', | 112 ;; If the last character of the original filename was `~' or `#', |
105 ;; make sure the munged name ends with it also. This is so | 113 ;; make sure the munged name ends with it also. This is so that |
106 ;; a backup file retains its final `~'. | 114 ;; backup and auto-save files retain their telltale form. |
107 (if (equal lastchar ?~) | 115 (if (memq lastchar '(?~ ?#)) |
108 (aset string (1- (length string)) lastchar)))) | 116 (aset string (1- (length string)) lastchar)))) |
109 (concat (if (and (stringp dir) | 117 (concat (if (and (stringp dir) |
110 (memq (aref dir dlen-m-1) '(?/ ?\\))) | 118 (memq (aref dir dlen-m-1) '(?/ ?\\))) |
111 (concat (convert-standard-filename | 119 (concat (convert-standard-filename |
112 (substring dir 0 dlen-m-1)) | 120 (substring dir 0 dlen-m-1)) |