Commit | Line | Data |
---|---|---|
007c61fa RS |
1 | ;;; dos-fns.el --- MS-Dos specific functions. |
2 | ||
3aaa90ef | 3 | ;; Copyright (C) 1991, 1993 Free Software Foundation, Inc. |
007c61fa RS |
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 | |
22 | ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | ||
24 | ;;; Commentary: | |
25 | ||
26 | ;; Part of this code is taken from (or derived from) demacs. | |
27 | ||
28 | ;;; Code: | |
29 | ||
64852bcd | 30 | ;;; Add %t: into the mode line format just after the open-paren. |
dde25849 | 31 | (let ((tail (member " %[(" mode-line-format))) |
64852bcd RS |
32 | (setcdr tail (cons (purecopy "%t:") |
33 | (cdr tail)))) | |
007c61fa | 34 | |
35d6dd87 RS |
35 | ;; Use ";" instead of ":" as a path separator (from files.el). |
36 | (setq path-separator ";") | |
37 | ||
38 | ;; Set the null device (for compile.el). | |
39 | (setq grep-null-device "NUL") | |
40 | ||
41 | ;; Set the grep regexp to match entries with drive letters. | |
42 | (setq grep-regexp-alist | |
43 | '(("^\\(\\([a-zA-Z]:\\)?[^:( \t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]" 1 3))) | |
44 | ||
44998f5b RS |
45 | ;; This overrides a trivial definition in files.el. |
46 | (defun convert-standard-filename (filename) | |
47 | "Convert a standard file's name to something suitable for the current OS. | |
48 | This function's standard definition is trivial; it just returns the argument. | |
49 | However, on some systems, the function is redefined | |
50 | with a definition that really does change some file names." | |
51 | (let ((dir (file-name-directory filename)) | |
52 | (string (copy-sequence (file-name-nondirectory filename))) | |
53 | i firstdot) | |
54 | ;; Change a leading period to a leading underscore. | |
55 | (if (= (aref string 0) ?.) | |
56 | (aset string 0 ?_)) | |
57 | ;; Get rid of invalid characters. | |
58 | (while (setq i (string-match "[^a-zA-Z0-9_.%~]" string)) | |
59 | (aset string i ?_)) | |
60 | ;; If we don't have a period, | |
61 | ;; and we have a dash or underscore that isn't the first char, | |
62 | ;; change that to a period. | |
63 | (if (and (not (string-match "\\." string)) | |
64 | (setq i (string-match "[-_]" string 1))) | |
65 | (aset string i ?\.)) | |
66 | ;; If we don't have a period in the first 8 chars, insert one. | |
67 | (if (> (or (string-match "\\." string) | |
68 | (length string)) | |
69 | 8) | |
70 | (setq string | |
71 | (concat (substring string 0 8) | |
72 | "." | |
73 | (substring string 8)))) | |
74 | (setq firstdot (string-match "\\." string)) | |
75 | ;; Truncate to 3 chars after the first period. | |
76 | (if (> (length string) (+ firstdot 4)) | |
77 | (setq string (substring string 0 (+ firstdot 4)))) | |
78 | ;; Change all periods except the first one into underscores. | |
79 | (while (string-match "\\." string (1+ firstdot)) | |
80 | (setq i (string-match "\\." string (1+ firstdot))) | |
81 | (aset string i ?_)) | |
82 | (concat dir string))) | |
83 | ||
007c61fa RS |
84 | (defvar file-name-buffer-file-type-alist |
85 | '( | |
594cabd7 RS |
86 | ("[:/].*config.sys$" . nil) ; config.sys text |
87 | ("\\.elc$" . t) ; emacs stuff | |
88 | ("\\.\\(obj\\|exe\\|com\\|lib\\|sys\\|chk\\|out\\|bin\\|ico\\|pif\\)$" . t) | |
007c61fa | 89 | ; MS-Dos stuff |
594cabd7 | 90 | ("\\.\\(arc\\|zip\\|pak\\|lzh\\|zoo\\)$" . t) |
007c61fa | 91 | ; Packers |
594cabd7 | 92 | ("\\.\\(a\\|o\\|tar\\|z\\|gz\\|taz\\)$" . t) |
007c61fa | 93 | ; Unix stuff |
594cabd7 | 94 | ("\\.tp[ulpw]$" . t) |
007c61fa | 95 | ; Borland Pascal stuff |
21f2acd3 | 96 | ("[:/]tags$" . t) |
007c61fa | 97 | ; Emacs TAGS file |
594cabd7 RS |
98 | ) |
99 | "*Alist for distinguishing text files from binary files. | |
100 | Each element has the form (REGEXP . TYPE), where REGEXP is matched | |
101 | against the file name, and TYPE is nil for text, t for binary.") | |
007c61fa RS |
102 | |
103 | (defun find-buffer-file-type (filename) | |
104 | (let ((alist file-name-buffer-file-type-alist) | |
105 | (found nil) | |
106 | (code nil)) | |
107 | (let ((case-fold-search t)) | |
108 | (setq filename (file-name-sans-versions filename)) | |
109 | (while (and (not found) alist) | |
110 | (if (string-match (car (car alist)) filename) | |
111 | (setq code (cdr (car alist)) | |
112 | found t)) | |
113 | (setq alist (cdr alist)))) | |
594cabd7 RS |
114 | (if found |
115 | (cond((memq code '(nil t)) code) | |
007c61fa RS |
116 | ((and (symbolp code) (fboundp code)) |
117 | (funcall code filename))) | |
118 | default-buffer-file-type))) | |
119 | ||
120 | (defun find-file-binary (filename) | |
594cabd7 | 121 | "Visit file FILENAME and treat it as binary." |
007c61fa | 122 | (interactive "FFind file binary: ") |
594cabd7 | 123 | (let ((file-name-buffer-file-type-alist '(("" . t)))) |
007c61fa RS |
124 | (find-file filename))) |
125 | ||
126 | (defun find-file-text (filename) | |
594cabd7 | 127 | "Visit file FILENAME and treat it as a text file." |
007c61fa | 128 | (interactive "FFind file text: ") |
594cabd7 | 129 | (let ((file-name-buffer-file-type-alist '(("" . nil)))) |
007c61fa RS |
130 | (find-file filename))) |
131 | ||
132 | (defun find-file-not-found-set-buffer-file-type () | |
133 | (save-excursion | |
134 | (set-buffer (current-buffer)) | |
135 | (setq buffer-file-type (find-buffer-file-type (buffer-file-name)))) | |
136 | nil) | |
137 | ||
138 | ;;; To set the default file type on new files. | |
139 | (add-hook 'find-file-not-found-hooks 'find-file-not-found-set-buffer-file-type) | |
140 | ||
007c61fa RS |
141 | (defvar msdos-shells '("command.com" "4dos.com" "ndos.com") |
142 | "*List of shells that use `/c' instead of `-c' and a backslashed command.") | |
143 | ||
21f2acd3 | 144 | (defconst register-name-alist |
007c61fa | 145 | '((ax . 0) (bx . 1) (cx . 2) (dx . 3) (si . 4) (di . 5) |
21f2acd3 RS |
146 | (cflag . 6) (flags . 7) |
147 | (al . (0 . 0)) (bl . (1 . 0)) (cl . (2 . 0)) (dl . (3 . 0)) | |
148 | (ah . (0 . 1)) (bh . (1 . 1)) (ch . (2 . 1)) (dh . (3 . 1)))) | |
007c61fa RS |
149 | |
150 | (defun make-register () | |
151 | (make-vector 8 0)) | |
152 | ||
153 | (defun register-value (regs name) | |
21f2acd3 | 154 | (let ((where (cdr (assoc name register-name-alist)))) |
007c61fa RS |
155 | (cond ((consp where) |
156 | (let ((tem (aref regs (car where)))) | |
157 | (if (zerop (cdr where)) | |
158 | (% tem 256) | |
159 | (/ tem 256)))) | |
160 | ((numberp where) | |
161 | (aref regs where)) | |
162 | (t nil)))) | |
163 | ||
164 | (defun set-register-value (regs name value) | |
165 | (and (numberp value) | |
21f2acd3 RS |
166 | (>= value 0) |
167 | (let ((where (cdr (assoc name register-name-alist)))) | |
007c61fa | 168 | (cond ((consp where) |
21f2acd3 RS |
169 | (let ((tem (aref regs (car where))) |
170 | (value (logand value 255))) | |
171 | (aset regs | |
172 | (car where) | |
173 | (if (zerop (cdr where)) | |
174 | (logior (logand tem 65280) value) | |
175 | (logior (logand tem 255) (lsh value 8)))))) | |
007c61fa | 176 | ((numberp where) |
21f2acd3 | 177 | (aset regs where (logand value 65535)))))) |
007c61fa RS |
178 | regs) |
179 | ||
180 | (defsubst intdos (regs) | |
181 | (int86 33 regs)) | |
182 | ||
87485d6f MW |
183 | ;; Extra stub to functions in src/frame.c |
184 | ;; Emacs aborts during dump if the following don't have a doc string. | |
185 | (defun window-frame (window) | |
186 | "Return the frame that WINDOW resides on." | |
187 | (selected-frame)) | |
188 | (defun raise-frame (frame) | |
189 | "Raise FRAME to the top of the desktop." | |
190 | nil) | |
191 | (defun select-frame (frame &optional no-enter) | |
192 | "Select FRAME for input events." | |
193 | (selected-frame)) |