(FILE_SYSTEM_CASE): Call Fmsdos_downcase_filename instead of Fdowncase.
[bpt/emacs.git] / lisp / dos-fns.el
1 ;;; dos-fns.el --- MS-Dos specific functions.
2
3 ;; Copyright (C) 1991, 1993, 1995, 1996 Free Software Foundation, Inc.
4
5 ;; Maintainer: Morten Welinder (terra@diku.dk)
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
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.
24
25 ;;; Commentary:
26
27 ;; Part of this code is taken from (or derived from) demacs.
28
29 ;;; Code:
30
31 ;;; Add %t: into the mode line format just after the open-paren.
32 (let ((tail (member " %[(" mode-line-format)))
33 (setcdr tail (cons (purecopy "%t:")
34 (cdr tail))))
35
36 ;; Use ";" instead of ":" as a path separator (from files.el).
37 (setq path-separator ";")
38
39 ;; Set the null device (for compile.el).
40 (setq grep-null-device "NUL")
41
42 ;; Set the grep regexp to match entries with drive letters.
43 (setq grep-regexp-alist
44 '(("^\\(\\([a-zA-Z]:\\)?[^:( \t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]" 1 3)))
45
46 ;; This overrides a trivial definition in files.el.
47 (defun convert-standard-filename (filename)
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.
50 However, on some systems, the function is redefined
51 with a definition that really does change some file names."
52 (if (or (msdos-long-file-names)
53 (not (stringp filename))
54 (member (file-name-nondirectory filename) '("" "." "..")))
55 filename
56 (let* ((dir (file-name-directory filename))
57 (string (copy-sequence (file-name-nondirectory filename)))
58 (lastchar (aref string (1- (length string))))
59 i firstdot)
60 ;; Change a leading period to a leading underscore.
61 (if (= (aref string 0) ?.)
62 (aset string 0 ?_))
63 ;; Get rid of invalid characters.
64 (while (setq i (string-match
65 "[^-a-zA-Z0-9_.%~^$!#&{}@`'()\200-\376]"
66 string))
67 (aset string i ?_))
68 ;; If we don't have a period,
69 ;; and we have a dash or underscore that isn't the first char,
70 ;; change that to a period.
71 (if (and (not (string-match "\\." string))
72 (setq i (string-match "[-_]" string 1)))
73 (aset string i ?\.))
74 ;; If we don't have a period in the first 8 chars, insert one.
75 (if (> (or (string-match "\\." string)
76 (length string))
77 8)
78 (setq string
79 (concat (substring string 0 8)
80 "."
81 (substring string 8))))
82 (setq firstdot (or (string-match "\\." string) (1- (length string))))
83 ;; Truncate to 3 chars after the first period.
84 (if (> (length string) (+ firstdot 4))
85 (setq string (substring string 0 (+ firstdot 4))))
86 ;; Change all periods except the first one into underscores.
87 (while (string-match "\\." string (1+ firstdot))
88 (setq i (string-match "\\." string (1+ firstdot)))
89 (aset string i ?_))
90 ;; If the last character of the original filename was `~',
91 ;; make sure the munged name ends with it also.
92 (if (equal lastchar ?~)
93 (aset string (1- (length string)) lastchar))
94 (concat dir string))))
95
96 (defvar file-name-buffer-file-type-alist
97 '(
98 ("[:/].*config.sys$" . nil) ; config.sys text
99 ("\\.elc$" . t) ; emacs stuff
100 ("\\.\\(obj\\|exe\\|com\\|lib\\|sys\\|chk\\|out\\|bin\\|ico\\|pif\\)$" . t)
101 ; MS-Dos stuff
102 ("\\.\\(arc\\|zip\\|pak\\|lzh\\|zoo\\)$" . t)
103 ; Packers
104 ("\\.\\(a\\|o\\|tar\\|z\\|gz\\|taz\\)$" . t)
105 ; Unix stuff
106 ("\\.tp[ulpw]$" . t)
107 ; Borland Pascal stuff
108 ("[:/]tags$" . t)
109 ; Emacs TAGS file
110 )
111 "*Alist for distinguishing text files from binary files.
112 Each element has the form (REGEXP . TYPE), where REGEXP is matched
113 against the file name, and TYPE is nil for text, t for binary.")
114
115 (defun find-buffer-file-type (filename)
116 (let ((alist file-name-buffer-file-type-alist)
117 (found nil)
118 (code nil))
119 (let ((case-fold-search t))
120 (setq filename (file-name-sans-versions filename))
121 (while (and (not found) alist)
122 (if (string-match (car (car alist)) filename)
123 (setq code (cdr (car alist))
124 found t))
125 (setq alist (cdr alist))))
126 (if found
127 (cond((memq code '(nil t)) code)
128 ((and (symbolp code) (fboundp code))
129 (funcall code filename)))
130 default-buffer-file-type)))
131
132 (defun find-file-binary (filename)
133 "Visit file FILENAME and treat it as binary."
134 (interactive "FFind file binary: ")
135 (let ((file-name-buffer-file-type-alist '(("" . t))))
136 (find-file filename)))
137
138 (defun find-file-text (filename)
139 "Visit file FILENAME and treat it as a text file."
140 (interactive "FFind file text: ")
141 (let ((file-name-buffer-file-type-alist '(("" . nil))))
142 (find-file filename)))
143
144 (defun find-file-not-found-set-buffer-file-type ()
145 (save-excursion
146 (set-buffer (current-buffer))
147 (setq buffer-file-type (find-buffer-file-type (buffer-file-name))))
148 nil)
149
150 ;;; To set the default file type on new files.
151 (add-hook 'find-file-not-found-hooks 'find-file-not-found-set-buffer-file-type)
152
153 (defvar msdos-shells '("command.com" "4dos.com" "ndos.com")
154 "*List of shells that use `/c' instead of `-c' and a backslashed command.")
155
156 (defconst register-name-alist
157 '((ax . 0) (bx . 1) (cx . 2) (dx . 3) (si . 4) (di . 5)
158 (cflag . 6) (flags . 7)
159 (al . (0 . 0)) (bl . (1 . 0)) (cl . (2 . 0)) (dl . (3 . 0))
160 (ah . (0 . 1)) (bh . (1 . 1)) (ch . (2 . 1)) (dh . (3 . 1))))
161
162 (defun make-register ()
163 (make-vector 8 0))
164
165 (defun register-value (regs name)
166 (let ((where (cdr (assoc name register-name-alist))))
167 (cond ((consp where)
168 (let ((tem (aref regs (car where))))
169 (if (zerop (cdr where))
170 (% tem 256)
171 (/ tem 256))))
172 ((numberp where)
173 (aref regs where))
174 (t nil))))
175
176 (defun set-register-value (regs name value)
177 (and (numberp value)
178 (>= value 0)
179 (let ((where (cdr (assoc name register-name-alist))))
180 (cond ((consp where)
181 (let ((tem (aref regs (car where)))
182 (value (logand value 255)))
183 (aset regs
184 (car where)
185 (if (zerop (cdr where))
186 (logior (logand tem 65280) value)
187 (logior (logand tem 255) (lsh value 8))))))
188 ((numberp where)
189 (aset regs where (logand value 65535))))))
190 regs)
191
192 (defsubst intdos (regs)
193 (int86 33 regs))
194
195 ;; Extra stub to functions in src/frame.c
196 ;; Emacs aborts during dump if the following don't have a doc string.
197 (defun window-frame (window)
198 "Return the frame that WINDOW resides on."
199 (selected-frame))
200 (defun raise-frame (frame)
201 "Raise FRAME to the top of the desktop."
202 nil)
203 (defun select-frame (frame &optional no-enter)
204 "Select FRAME for input events."
205 (selected-frame))
206
207 ;; Support for printing under MS-DOS, see lpr.el and ps-print.el.
208 (defvar dos-printer "PRN"
209 "*The name of a local MS-DOS device to which data is sent for printing.
210 \(Note that PostScript files are sent to `dos-ps-printer', which see.\)
211
212 Typical non-default settings would be \"LPT1\" to \"LPT3\" for
213 parallel printers, or \"COM1\" to \"COM4\" or \"AUX\" for serial
214 printers. You can also set it to a name of a file, in which
215 case the output gets appended to that file.
216 If you want to discard the printed output, set this to \"NUL\".")
217
218 (defun dos-print-region-function (start end
219 &optional lpr-prog
220 delete-text buf display rest)
221 "MS-DOS-specific function to print the region on a printer.
222 Writes the region to the device or file which is a value of
223 `dos-printer' \(which see\). Ignores any arguments beyond
224 START and END."
225
226 (write-region start end dos-printer t 0)
227 ;; Make each print-out start on a new page, but don't waste
228 ;; paper if there was a form-feed at the end of this file.
229 (if (not (char-equal (char-after (1- end)) ?\C-l))
230 (write-region "\f" nil dos-printer t 0)))
231
232 ;; Set this to nil if you have a port of the `lpr' program and
233 ;; you want to use it for printing. If the default setting is
234 ;; in effect, `lpr-command' and its switches are ignored when
235 ;; printing with `lpr-xxx' and `print-xxx'.
236 (setq print-region-function 'dos-print-region-function)
237
238 ;; Set this to nil if you have a port of the `pr' program
239 ;; (e.g., from GNU Textutils), or if you have an `lpr'
240 ;; program (see above) that can print page headers.
241 ;; If `lpr-headers-switches' is non-nil (the default) and
242 ;; `print-region-function' is set to `dos-print-region-function',
243 ;; then requests to print page headers will be silently
244 ;; ignored, and `print-buffer' and `print-region' produce
245 ;; the same output as `lpr-buffer' and `lpr-region', accordingly.
246 (setq lpr-headers-switches "(page headers are not supported)")
247
248 (defvar dos-ps-printer "PRN"
249 "*Method for printing PostScript files under MS-DOS.
250
251 If the value is a string, then it is taken as the name of the
252 device to which PostScript files are written. By default it
253 is the default printer device; typical non-default settings
254 would be \"LPT1\" to \"LPT3\" for parallel printers, or \"COM1\"
255 to \"COM4\" or \"AUX\" for serial printers. You can also set it
256 to a name of a file, in which case the output gets appended
257 to that file. \(Note that `ps-print' package already has
258 facilities for printing to a file, so you might as well use
259 them instead of changing the setting of this variable.\) If
260 you want to silently discard the printed output, set this to \"NUL\".
261
262 If the value is anything but a string, PostScript files will be
263 piped to the program given by `ps-lpr-command', with switches
264 given by `ps-lpr-switches', which see.")
265
266 (setq ps-lpr-command "gs")
267
268 (setq ps-lpr-switches '("-q" "-dNOPAUSE" "-sDEVICE=epson" "-r240x60"
269 "-sOutputFile=LPT1" "-"))
270
271 ;; Backward compatibility for obsolescent functions which
272 ;; set screen size.
273
274 (defun mode25 ()
275 "Changes the number of screen rows to 25."
276 (interactive)
277 (set-frame-size (selected-frame) 80 25))
278
279 (defun mode4350 ()
280 "Changes the number of rows to 43 or 50.
281 Emacs always tries to set the screen height to 50 rows first.
282 If this fails, it will try to set it to 43 rows, on the assumption
283 that your video hardware might not support 50-line mode."
284 (interactive)
285 (set-frame-size (selected-frame) 80 50)
286 (if (eq (frame-height (selected-frame)) 50)
287 nil ; the original built-in function returned nil
288 (set-frame-size (selected-frame) 80 43)))
289
290 (provide 'dos-fns)
291
292 ; dos-fns.el ends here