aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2001-04-06 19:03:00 +0000
committerEli Zaretskii2001-04-06 19:03:00 +0000
commita9d36252047b2f04c6cf1486a2fa6048443feb0f (patch)
tree24dddbe97a239abb1d7063bdc699248543af2c44
parent63685b9d09862e4e964d2dc7a4e856742fe69420 (diff)
downloademacs-a9d36252047b2f04c6cf1486a2fa6048443feb0f.tar.gz
emacs-a9d36252047b2f04c6cf1486a2fa6048443feb0f.zip
(dos-truncate-to-8+3): New function.
-rw-r--r--lisp/dos-fns.el58
1 files changed, 58 insertions, 0 deletions
diff --git a/lisp/dos-fns.el b/lisp/dos-fns.el
index 8037de4f54c..5280280be2b 100644
--- a/lisp/dos-fns.el
+++ b/lisp/dos-fns.el
@@ -114,6 +114,64 @@ with a definition that really does change some file names."
114 (convert-standard-filename dir)) 114 (convert-standard-filename dir))
115 string)))))) 115 string))))))
116 116
117(defun dos-truncate-to-8+3 (filename)
118 "Truncate FILENAME to DOS 8+3 limits."
119 (if (or (not (stringp filename))
120 (< (length filename) 5)) ; too short to give any trouble
121 filename
122 (let ((flen (length filename)))
123 ;; If FILENAME has a trailing slash, remove it and recurse.
124 (if (memq (aref filename (1- flen)) '(?/ ?\\))
125 (concat (dos-truncate-to-8+3 (substring filename 0 (1- flen)))
126 "/")
127 (let* (;; ange-ftp gets in the way for names like "/foo:bar".
128 ;; We need to inhibit all magic file names, because
129 ;; remote file names should never be passed through
130 ;; this function, as they are not meant for the local
131 ;; filesystem!
132 (file-name-handler-alist nil)
133 (dir
134 ;; If FILENAME is "x:foo", file-name-directory returns
135 ;; "x:/bar/baz", substituting the current working
136 ;; directory on drive x:. We want to be left with "x:"
137 ;; instead.
138 (if (and (< 1 flen)
139 (eq (aref filename 1) ?:)
140 (null (string-match "[/\\]" filename)))
141 (substring filename 0 2)
142 (file-name-directory filename)))
143 (dlen-m-1 (1- (length dir)))
144 (string (copy-sequence (file-name-nondirectory filename)))
145 (strlen (length string))
146 (lastchar (aref string (1- strlen)))
147 i firstdot)
148 (setq firstdot (string-match "\\." string))
149 (cond
150 (firstdot
151 ;; Truncate the extension to 3 characters.
152 (if (> strlen (+ firstdot 4))
153 (setq string (substring string 0 (+ firstdot 4))))
154 ;; Truncate the basename to 8 characters.
155 (if (> firstdot 8)
156 (setq string (concat (substring string 0 8)
157 "."
158 (substring string (1+ firstdot))))))
159 ((> strlen 8)
160 ;; No dot; truncate file name to 8 characters.
161 (setq string (substring string 0 8))))
162 ;; If the last character of the original filename was `~',
163 ;; make sure the munged name ends with it also. This is so
164 ;; a backup file retains its final `~'.
165 (if (equal lastchar ?~)
166 (aset string (1- (length string)) lastchar))
167 (concat (if (and (stringp dir)
168 (memq (aref dir dlen-m-1) '(?/ ?\\)))
169 (concat (dos-truncate-to-8+3 (substring dir 0 dlen-m-1))
170 "/")
171 ;; Recurse to truncate the leading directories.
172 (dos-truncate-to-8+3 dir))
173 string))))))
174
117;; See dos-vars.el for defcustom. 175;; See dos-vars.el for defcustom.
118(defvar msdos-shells) 176(defvar msdos-shells)
119 177