Move config.h before other includes (which may use feature tests).
[emacs.git] / lisp / dos-fns.el
blobd4fb12c1927915e0f58c752d31e3ae6c52f501eb
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 ;; Note: the empty file-name-nondirectory catches the case
39 ;; where FILENAME is "x:" or "x:/", thus preventing infinite
40 ;; recursion.
41 (string-match "\\`[a-zA-Z]:[/\\]?\\'" filename))
42 filename
43 ;; If FILENAME has a trailing slash, remove it and recurse.
44 (if (memq (aref filename (1- (length filename))) '(?/ ?\\))
45 (concat (convert-standard-filename
46 (substring filename 0 (1- (length filename))))
47 "/")
48 (let* ((dir
49 ;; If FILENAME is "x:foo", file-name-directory returns
50 ;; "x:/bar/baz", substituting the current working
51 ;; directory on drive x:. We want to be left with "x:"
52 ;; instead.
53 (if (and (eq (aref filename 1) ?:)
54 (null (string-match "[/\\]" filename)))
55 (substring filename 0 2)
56 (file-name-directory filename)))
57 (string (copy-sequence (file-name-nondirectory filename)))
58 (lastchar (aref string (1- (length string))))
59 i firstdot)
60 (if (msdos-long-file-names)
61 ;; Replace characters that are invalid even on Windows.
62 (while (setq i (string-match "[?*:<>|\"\000-\037]" string))
63 (aset string i ?!))
64 ;; Change a leading period to a leading underscore.
65 (if (= (aref string 0) ?.)
66 (aset string 0 ?_))
67 ;; Get rid of invalid characters.
68 (while (setq i (string-match
69 "[^-a-zA-Z0-9_.%~^$!#&{}@`'()\200-\376]"
70 string))
71 (aset string i ?_))
72 ;; If we don't have a period,
73 ;; and we have a dash or underscore that isn't the first char,
74 ;; change that to a period.
75 (if (and (not (string-match "\\." string))
76 (setq i (string-match "[-_]" string 1)))
77 (aset string i ?\.))
78 ;; If we don't have a period in the first 8 chars, insert one.
79 (if (> (or (string-match "\\." string)
80 (length string))
82 (setq string
83 (concat (substring string 0 8)
84 "."
85 (substring string 8))))
86 (setq firstdot (or (string-match "\\." string) (1- (length string))))
87 ;; Truncate to 3 chars after the first period.
88 (if (> (length string) (+ firstdot 4))
89 (setq string (substring string 0 (+ firstdot 4))))
90 ;; Change all periods except the first one into underscores.
91 (while (string-match "\\." string (1+ firstdot))
92 (setq i (string-match "\\." string (1+ firstdot)))
93 (aset string i ?_))
94 ;; If the last character of the original filename was `~',
95 ;; make sure the munged name ends with it also.
96 (if (equal lastchar ?~)
97 (aset string (1- (length string)) lastchar)))
98 (concat (if (and (stringp dir)
99 (memq (aref dir (1- (length dir))) '(?/ ?\\)))
100 (concat (convert-standard-filename
101 (substring dir 0 (1- (length dir))))
102 "/")
103 (convert-standard-filename dir))
104 string)))))
106 ;; See dos-vars.el for defcustom.
107 (defvar msdos-shells)
109 ;;; Override setting chosen at startup.
110 (defun set-default-process-coding-system ()
111 (setq default-process-coding-system
112 (if default-enable-multibyte-characters
113 '(undecided-dos . undecided-dos)
114 '(raw-text-dos . raw-text-dos))))
116 (add-hook 'before-init-hook 'set-default-process-coding-system)
118 (defvar register-name-alist
119 '((ax . 0) (bx . 1) (cx . 2) (dx . 3) (si . 4) (di . 5)
120 (cflag . 6) (flags . 7)
121 (al . (0 . 0)) (bl . (1 . 0)) (cl . (2 . 0)) (dl . (3 . 0))
122 (ah . (0 . 1)) (bh . (1 . 1)) (ch . (2 . 1)) (dh . (3 . 1))))
124 (defun make-register ()
125 (make-vector 8 0))
127 (defun register-value (regs name)
128 (let ((where (cdr (assoc name register-name-alist))))
129 (cond ((consp where)
130 (let ((tem (aref regs (car where))))
131 (if (zerop (cdr where))
132 (% tem 256)
133 (/ tem 256))))
134 ((numberp where)
135 (aref regs where))
136 (t nil))))
138 (defun set-register-value (regs name value)
139 (and (numberp value)
140 (>= value 0)
141 (let ((where (cdr (assoc name register-name-alist))))
142 (cond ((consp where)
143 (let ((tem (aref regs (car where)))
144 (value (logand value 255)))
145 (aset regs
146 (car where)
147 (if (zerop (cdr where))
148 (logior (logand tem 65280) value)
149 (logior (logand tem 255) (lsh value 8))))))
150 ((numberp where)
151 (aset regs where (logand value 65535))))))
152 regs)
154 (defsubst intdos (regs)
155 (int86 33 regs))
157 ;; Backward compatibility for obsolescent functions which
158 ;; set screen size.
160 (defun mode25 ()
161 "Changes the number of screen rows to 25."
162 (interactive)
163 (set-frame-size (selected-frame) 80 25))
165 (defun mode4350 ()
166 "Changes the number of rows to 43 or 50.
167 Emacs always tries to set the screen height to 50 rows first.
168 If this fails, it will try to set it to 43 rows, on the assumption
169 that your video hardware might not support 50-line mode."
170 (interactive)
171 (set-frame-size (selected-frame) 80 50)
172 (if (eq (frame-height (selected-frame)) 50)
173 nil ; the original built-in function returned nil
174 (set-frame-size (selected-frame) 80 43)))
176 (provide 'dos-fns)
178 ; dos-fns.el ends here