Commit | Line | Data |
---|---|---|
e8af40ee | 1 | ;;; dos-fns.el --- MS-Dos specific functions |
007c61fa | 2 | |
9596811a | 3 | ;; Copyright (C) 1991, 1993, 1995, 1996 Free Software Foundation, Inc. |
007c61fa | 4 | |
0acdb863 | 5 | ;; Maintainer: Morten Welinder <terra@diku.dk> |
007c61fa RS |
6 | ;; Keywords: internal |
7 | ||
8 | ;; This file is part of GNU Emacs. | |
9 | ||
10 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 | ;; it under the terms of the GNU General Public License as published by | |
12 | ;; the Free Software Foundation; either version 2, or (at your option) | |
13 | ;; any later version. | |
14 | ||
15 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | ;; GNU General Public License for more details. | |
19 | ||
20 | ;; You should have received a copy of the GNU General Public License | |
b578f267 EN |
21 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
22 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 | ;; Boston, MA 02111-1307, USA. | |
007c61fa RS |
24 | |
25 | ;;; Commentary: | |
26 | ||
27 | ;; Part of this code is taken from (or derived from) demacs. | |
28 | ||
29 | ;;; Code: | |
30 | ||
44998f5b RS |
31 | ;; This overrides a trivial definition in files.el. |
32 | (defun convert-standard-filename (filename) | |
33 | "Convert a standard file's name to something suitable for the current OS. | |
915b0bf0 JB |
34 | This means to guarantee valid names and perhaps to canonicalize |
35 | certain patterns. | |
36 | ||
37 | On Windows and DOS, replace invalid characters. On DOS, make | |
38 | sure to obey the 8.3 limitations. On Windows, turn Cygwin names | |
39 | into native names, and also turn slashes into backslashes if the | |
40 | shell requires it (see `w32-shell-dos-semantics')." | |
09def38b | 41 | (if (or (not (stringp filename)) |
9d47450f EZ |
42 | ;; This catches the case where FILENAME is "x:" or "x:/" or |
43 | ;; "/", thus preventing infinite recursion. | |
44 | (string-match "\\`\\([a-zA-Z]:\\)?[/\\]?\\'" filename)) | |
9c777199 | 45 | filename |
9d47450f EZ |
46 | (let ((flen (length filename))) |
47 | ;; If FILENAME has a trailing slash, remove it and recurse. | |
48 | (if (memq (aref filename (1- flen)) '(?/ ?\\)) | |
71296446 | 49 | (concat (convert-standard-filename |
9d47450f EZ |
50 | (substring filename 0 (1- flen))) |
51 | "/") | |
52 | (let* (;; ange-ftp gets in the way for names like "/foo:bar". | |
53 | ;; We need to inhibit all magic file names, because | |
54 | ;; remote file names should never be passed through | |
55 | ;; this function, as they are not meant for the local | |
56 | ;; filesystem! | |
57 | (file-name-handler-alist nil) | |
58 | (dir | |
59 | ;; If FILENAME is "x:foo", file-name-directory returns | |
60 | ;; "x:/bar/baz", substituting the current working | |
61 | ;; directory on drive x:. We want to be left with "x:" | |
62 | ;; instead. | |
63 | (if (and (< 1 flen) | |
64 | (eq (aref filename 1) ?:) | |
65 | (null (string-match "[/\\]" filename))) | |
66 | (substring filename 0 2) | |
67 | (file-name-directory filename))) | |
68 | (dlen-m-1 (1- (length dir))) | |
69 | (string (copy-sequence (file-name-nondirectory filename))) | |
70 | (lastchar (aref string (1- (length string)))) | |
71 | i firstdot) | |
72 | (cond | |
73 | ((msdos-long-file-names) | |
09def38b EZ |
74 | ;; Replace characters that are invalid even on Windows. |
75 | (while (setq i (string-match "[?*:<>|\"\000-\037]" string)) | |
9d47450f EZ |
76 | (aset string i ?!))) |
77 | ((not (member string '("" "." ".."))) | |
78 | ;; Change a leading period to a leading underscore. | |
79 | (if (= (aref string 0) ?.) | |
80 | (aset string 0 ?_)) | |
a007e4e3 EZ |
81 | ;; If the name is longer than 8 chars, and doesn't have a |
82 | ;; period, and we have a dash or underscore that isn't too | |
83 | ;; close to the beginning, change that to a period. This | |
84 | ;; is so we could salvage more characters of the original | |
85 | ;; name by pushing them into the extension. | |
86 | (if (and (not (string-match "\\." string)) | |
87 | (> (length string) 8) | |
88 | ;; We don't gain anything if we put the period closer | |
89 | ;; than 5 chars from the beginning (5 + 3 = 8). | |
90 | (setq i (string-match "[-_]" string 5))) | |
91 | (aset string i ?\.)) | |
9d47450f EZ |
92 | ;; Get rid of invalid characters. |
93 | (while (setq i (string-match | |
94 | "[^-a-zA-Z0-9_.%~^$!#&{}@`'()\200-\376]" | |
95 | string)) | |
96 | (aset string i ?_)) | |
9d47450f | 97 | ;; If we don't have a period in the first 8 chars, insert one. |
a007e4e3 EZ |
98 | ;; This enables to have 3 more characters from the original |
99 | ;; name in the extension. | |
9d47450f EZ |
100 | (if (> (or (string-match "\\." string) (length string)) |
101 | 8) | |
102 | (setq string | |
103 | (concat (substring string 0 8) | |
104 | "." | |
105 | (substring string 8)))) | |
106 | (setq firstdot (or (string-match "\\." string) | |
107 | (1- (length string)))) | |
108 | ;; Truncate to 3 chars after the first period. | |
109 | (if (> (length string) (+ firstdot 4)) | |
110 | (setq string (substring string 0 (+ firstdot 4)))) | |
111 | ;; Change all periods except the first one into underscores. | |
a007e4e3 | 112 | ;; (DOS doesn't allow more than one period.) |
9d47450f EZ |
113 | (while (string-match "\\." string (1+ firstdot)) |
114 | (setq i (string-match "\\." string (1+ firstdot))) | |
115 | (aset string i ?_)) | |
a007e4e3 EZ |
116 | ;; If the last character of the original filename was `~' or `#', |
117 | ;; make sure the munged name ends with it also. This is so that | |
118 | ;; backup and auto-save files retain their telltale form. | |
119 | (if (memq lastchar '(?~ ?#)) | |
9d47450f EZ |
120 | (aset string (1- (length string)) lastchar)))) |
121 | (concat (if (and (stringp dir) | |
122 | (memq (aref dir dlen-m-1) '(?/ ?\\))) | |
123 | (concat (convert-standard-filename | |
124 | (substring dir 0 dlen-m-1)) | |
125 | "/") | |
126 | (convert-standard-filename dir)) | |
127 | string)))))) | |
44998f5b | 128 | |
51f32106 | 129 | (defun dos-8+3-filename (filename) |
a9d36252 EZ |
130 | "Truncate FILENAME to DOS 8+3 limits." |
131 | (if (or (not (stringp filename)) | |
132 | (< (length filename) 5)) ; too short to give any trouble | |
133 | filename | |
134 | (let ((flen (length filename))) | |
135 | ;; If FILENAME has a trailing slash, remove it and recurse. | |
136 | (if (memq (aref filename (1- flen)) '(?/ ?\\)) | |
51f32106 | 137 | (concat (dos-8+3-filename (substring filename 0 (1- flen))) |
a9d36252 EZ |
138 | "/") |
139 | (let* (;; ange-ftp gets in the way for names like "/foo:bar". | |
140 | ;; We need to inhibit all magic file names, because | |
141 | ;; remote file names should never be passed through | |
142 | ;; this function, as they are not meant for the local | |
143 | ;; filesystem! | |
144 | (file-name-handler-alist nil) | |
145 | (dir | |
146 | ;; If FILENAME is "x:foo", file-name-directory returns | |
147 | ;; "x:/bar/baz", substituting the current working | |
148 | ;; directory on drive x:. We want to be left with "x:" | |
149 | ;; instead. | |
150 | (if (and (< 1 flen) | |
151 | (eq (aref filename 1) ?:) | |
152 | (null (string-match "[/\\]" filename))) | |
153 | (substring filename 0 2) | |
154 | (file-name-directory filename))) | |
155 | (dlen-m-1 (1- (length dir))) | |
156 | (string (copy-sequence (file-name-nondirectory filename))) | |
157 | (strlen (length string)) | |
158 | (lastchar (aref string (1- strlen))) | |
159 | i firstdot) | |
160 | (setq firstdot (string-match "\\." string)) | |
161 | (cond | |
162 | (firstdot | |
163 | ;; Truncate the extension to 3 characters. | |
164 | (if (> strlen (+ firstdot 4)) | |
165 | (setq string (substring string 0 (+ firstdot 4)))) | |
166 | ;; Truncate the basename to 8 characters. | |
167 | (if (> firstdot 8) | |
168 | (setq string (concat (substring string 0 8) | |
169 | "." | |
170 | (substring string (1+ firstdot)))))) | |
171 | ((> strlen 8) | |
172 | ;; No dot; truncate file name to 8 characters. | |
173 | (setq string (substring string 0 8)))) | |
174 | ;; If the last character of the original filename was `~', | |
175 | ;; make sure the munged name ends with it also. This is so | |
176 | ;; a backup file retains its final `~'. | |
177 | (if (equal lastchar ?~) | |
178 | (aset string (1- (length string)) lastchar)) | |
179 | (concat (if (and (stringp dir) | |
180 | (memq (aref dir dlen-m-1) '(?/ ?\\))) | |
51f32106 | 181 | (concat (dos-8+3-filename (substring dir 0 dlen-m-1)) |
a9d36252 EZ |
182 | "/") |
183 | ;; Recurse to truncate the leading directories. | |
51f32106 | 184 | (dos-8+3-filename dir)) |
a9d36252 EZ |
185 | string)))))) |
186 | ||
feb65403 RS |
187 | ;; See dos-vars.el for defcustom. |
188 | (defvar msdos-shells) | |
007c61fa | 189 | |
224116b8 AI |
190 | ;;; Override setting chosen at startup. |
191 | (defun set-default-process-coding-system () | |
192 | (setq default-process-coding-system | |
193 | (if default-enable-multibyte-characters | |
194 | '(undecided-dos . undecided-dos) | |
195 | '(raw-text-dos . raw-text-dos)))) | |
196 | ||
197 | (add-hook 'before-init-hook 'set-default-process-coding-system) | |
198 | ||
cafef6ab | 199 | (defvar register-name-alist |
007c61fa | 200 | '((ax . 0) (bx . 1) (cx . 2) (dx . 3) (si . 4) (di . 5) |
21f2acd3 RS |
201 | (cflag . 6) (flags . 7) |
202 | (al . (0 . 0)) (bl . (1 . 0)) (cl . (2 . 0)) (dl . (3 . 0)) | |
203 | (ah . (0 . 1)) (bh . (1 . 1)) (ch . (2 . 1)) (dh . (3 . 1)))) | |
007c61fa RS |
204 | |
205 | (defun make-register () | |
206 | (make-vector 8 0)) | |
207 | ||
208 | (defun register-value (regs name) | |
21f2acd3 | 209 | (let ((where (cdr (assoc name register-name-alist)))) |
007c61fa RS |
210 | (cond ((consp where) |
211 | (let ((tem (aref regs (car where)))) | |
212 | (if (zerop (cdr where)) | |
213 | (% tem 256) | |
214 | (/ tem 256)))) | |
215 | ((numberp where) | |
216 | (aref regs where)) | |
217 | (t nil)))) | |
218 | ||
219 | (defun set-register-value (regs name value) | |
220 | (and (numberp value) | |
21f2acd3 RS |
221 | (>= value 0) |
222 | (let ((where (cdr (assoc name register-name-alist)))) | |
007c61fa | 223 | (cond ((consp where) |
21f2acd3 RS |
224 | (let ((tem (aref regs (car where))) |
225 | (value (logand value 255))) | |
226 | (aset regs | |
227 | (car where) | |
228 | (if (zerop (cdr where)) | |
229 | (logior (logand tem 65280) value) | |
230 | (logior (logand tem 255) (lsh value 8)))))) | |
007c61fa | 231 | ((numberp where) |
21f2acd3 | 232 | (aset regs where (logand value 65535)))))) |
007c61fa RS |
233 | regs) |
234 | ||
235 | (defsubst intdos (regs) | |
236 | (int86 33 regs)) | |
237 | ||
70662974 RS |
238 | ;; Backward compatibility for obsolescent functions which |
239 | ;; set screen size. | |
240 | ||
241 | (defun mode25 () | |
242 | "Changes the number of screen rows to 25." | |
243 | (interactive) | |
244 | (set-frame-size (selected-frame) 80 25)) | |
245 | ||
246 | (defun mode4350 () | |
247 | "Changes the number of rows to 43 or 50. | |
248 | Emacs always tries to set the screen height to 50 rows first. | |
249 | If this fails, it will try to set it to 43 rows, on the assumption | |
250 | that your video hardware might not support 50-line mode." | |
251 | (interactive) | |
252 | (set-frame-size (selected-frame) 80 50) | |
253 | (if (eq (frame-height (selected-frame)) 50) | |
254 | nil ; the original built-in function returned nil | |
255 | (set-frame-size (selected-frame) 80 43))) | |
256 | ||
868c7abd RS |
257 | (provide 'dos-fns) |
258 | ||
ab5796a9 | 259 | ;;; arch-tag: 00b03579-8ebb-4a02-8762-5c5a929774ad |
e8af40ee | 260 | ;;; dos-fns.el ends here |