(struct x_output): Add member wait_for_wm.
[emacs.git] / lisp / dos-fns.el
blob09267c28c18fcb15f3f61c24dbedabf3bd3186d4
1 ;;; dos-fns.el --- MS-Dos specific functions.
3 ;; Copyright (C) 1991, 1993, 1995, 1996 Free Software Foundation, Inc.
5 ;; Maintainer: Morten Welinder <terra@diku.dk>
6 ;; Keywords: internal
8 ;; This file is part of GNU Emacs.
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.
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.
20 ;; You should have received a copy of the GNU General Public License
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.
25 ;;; Commentary:
27 ;; Part of this code is taken from (or derived from) demacs.
29 ;;; Code:
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.
34 This function's standard definition is trivial; it just returns the argument.
35 However, on some systems, the function is redefined
36 with a definition that really does change some file names."
37 (if (or (not (stringp filename))
38 ;; This catches the case where FILENAME is "x:" or "x:/" or
39 ;; "/", thus preventing infinite recursion.
40 (string-match "\\`\\([a-zA-Z]:\\)?[/\\]?\\'" filename))
41 filename
42 (let ((flen (length filename)))
43 ;; If FILENAME has a trailing slash, remove it and recurse.
44 (if (memq (aref filename (1- flen)) '(?/ ?\\))
45 (concat (convert-standard-filename
46 (substring filename 0 (1- flen)))
47 "/")
48 (let* (;; ange-ftp gets in the way for names like "/foo:bar".
49 ;; We need to inhibit all magic file names, because
50 ;; remote file names should never be passed through
51 ;; this function, as they are not meant for the local
52 ;; filesystem!
53 (file-name-handler-alist nil)
54 (dir
55 ;; If FILENAME is "x:foo", file-name-directory returns
56 ;; "x:/bar/baz", substituting the current working
57 ;; directory on drive x:. We want to be left with "x:"
58 ;; instead.
59 (if (and (< 1 flen)
60 (eq (aref filename 1) ?:)
61 (null (string-match "[/\\]" filename)))
62 (substring filename 0 2)
63 (file-name-directory filename)))
64 (dlen-m-1 (1- (length dir)))
65 (string (copy-sequence (file-name-nondirectory filename)))
66 (lastchar (aref string (1- (length string))))
67 i firstdot)
68 (cond
69 ((msdos-long-file-names)
70 ;; Replace characters that are invalid even on Windows.
71 (while (setq i (string-match "[?*:<>|\"\000-\037]" string))
72 (aset string i ?!)))
73 ((not (member string '("" "." "..")))
74 ;; Change a leading period to a leading underscore.
75 (if (= (aref string 0) ?.)
76 (aset string 0 ?_))
77 ;; Get rid of invalid characters.
78 (while (setq i (string-match
79 "[^-a-zA-Z0-9_.%~^$!#&{}@`'()\200-\376]"
80 string))
81 (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.
89 (if (> (or (string-match "\\." string) (length string))
91 (setq string
92 (concat (substring string 0 8)
93 "."
94 (substring string 8))))
95 (setq firstdot (or (string-match "\\." string)
96 (1- (length string))))
97 ;; Truncate to 3 chars after the first period.
98 (if (> (length string) (+ firstdot 4))
99 (setq string (substring string 0 (+ firstdot 4))))
100 ;; Change all periods except the first one into underscores.
101 (while (string-match "\\." string (1+ firstdot))
102 (setq i (string-match "\\." string (1+ firstdot)))
103 (aset string i ?_))
104 ;; If the last character of the original filename was `~',
105 ;; make sure the munged name ends with it also. This is so
106 ;; a backup file retains its final `~'.
107 (if (equal lastchar ?~)
108 (aset string (1- (length string)) lastchar))))
109 (concat (if (and (stringp dir)
110 (memq (aref dir dlen-m-1) '(?/ ?\\)))
111 (concat (convert-standard-filename
112 (substring dir 0 dlen-m-1))
113 "/")
114 (convert-standard-filename dir))
115 string))))))
117 (defun dos-8+3-filename (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-8+3-filename (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)
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-8+3-filename (substring dir 0 dlen-m-1))
170 "/")
171 ;; Recurse to truncate the leading directories.
172 (dos-8+3-filename dir))
173 string))))))
175 ;; See dos-vars.el for defcustom.
176 (defvar msdos-shells)
178 ;;; Override setting chosen at startup.
179 (defun set-default-process-coding-system ()
180 (setq default-process-coding-system
181 (if default-enable-multibyte-characters
182 '(undecided-dos . undecided-dos)
183 '(raw-text-dos . raw-text-dos))))
185 (add-hook 'before-init-hook 'set-default-process-coding-system)
187 (defvar register-name-alist
188 '((ax . 0) (bx . 1) (cx . 2) (dx . 3) (si . 4) (di . 5)
189 (cflag . 6) (flags . 7)
190 (al . (0 . 0)) (bl . (1 . 0)) (cl . (2 . 0)) (dl . (3 . 0))
191 (ah . (0 . 1)) (bh . (1 . 1)) (ch . (2 . 1)) (dh . (3 . 1))))
193 (defun make-register ()
194 (make-vector 8 0))
196 (defun register-value (regs name)
197 (let ((where (cdr (assoc name register-name-alist))))
198 (cond ((consp where)
199 (let ((tem (aref regs (car where))))
200 (if (zerop (cdr where))
201 (% tem 256)
202 (/ tem 256))))
203 ((numberp where)
204 (aref regs where))
205 (t nil))))
207 (defun set-register-value (regs name value)
208 (and (numberp value)
209 (>= value 0)
210 (let ((where (cdr (assoc name register-name-alist))))
211 (cond ((consp where)
212 (let ((tem (aref regs (car where)))
213 (value (logand value 255)))
214 (aset regs
215 (car where)
216 (if (zerop (cdr where))
217 (logior (logand tem 65280) value)
218 (logior (logand tem 255) (lsh value 8))))))
219 ((numberp where)
220 (aset regs where (logand value 65535))))))
221 regs)
223 (defsubst intdos (regs)
224 (int86 33 regs))
226 ;; Backward compatibility for obsolescent functions which
227 ;; set screen size.
229 (defun mode25 ()
230 "Changes the number of screen rows to 25."
231 (interactive)
232 (set-frame-size (selected-frame) 80 25))
234 (defun mode4350 ()
235 "Changes the number of rows to 43 or 50.
236 Emacs always tries to set the screen height to 50 rows first.
237 If this fails, it will try to set it to 43 rows, on the assumption
238 that your video hardware might not support 50-line mode."
239 (interactive)
240 (set-frame-size (selected-frame) 80 50)
241 (if (eq (frame-height (selected-frame)) 50)
242 nil ; the original built-in function returned nil
243 (set-frame-size (selected-frame) 80 43)))
245 (provide 'dos-fns)
247 ; dos-fns.el ends here