5443
|
1 ;;; dos-fns.el --- MS-Dos specific functions.
|
|
2
|
14734
|
3 ;; Copyright (C) 1991, 1993, 1995, 1996 Free Software Foundation, Inc.
|
5443
|
4
|
17977
|
5 ;; Maintainer: Morten Welinder <terra@diku.dk>
|
5443
|
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
|
14169
|
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.
|
5443
|
24
|
|
25 ;;; Commentary:
|
|
26
|
|
27 ;; Part of this code is taken from (or derived from) demacs.
|
|
28
|
|
29 ;;; Code:
|
|
30
|
21088
|
31 (defgroup dos-fns nil
|
|
32 "MS-Dos specific functions."
|
|
33 :group 'environment)
|
|
34
|
13913
|
35 ;; This overrides a trivial definition in files.el.
|
|
36 (defun convert-standard-filename (filename)
|
|
37 "Convert a standard file's name to something suitable for the current OS.
|
|
38 This function's standard definition is trivial; it just returns the argument.
|
|
39 However, on some systems, the function is redefined
|
|
40 with a definition that really does change some file names."
|
15187
|
41 (if (or (msdos-long-file-names)
|
|
42 (not (stringp filename))
|
|
43 (member (file-name-nondirectory filename) '("" "." "..")))
|
|
44 filename
|
|
45 (let* ((dir (file-name-directory filename))
|
|
46 (string (copy-sequence (file-name-nondirectory filename)))
|
|
47 (lastchar (aref string (1- (length string))))
|
|
48 i firstdot)
|
|
49 ;; Change a leading period to a leading underscore.
|
|
50 (if (= (aref string 0) ?.)
|
|
51 (aset string 0 ?_))
|
|
52 ;; Get rid of invalid characters.
|
|
53 (while (setq i (string-match
|
|
54 "[^-a-zA-Z0-9_.%~^$!#&{}@`'()\200-\376]"
|
|
55 string))
|
|
56 (aset string i ?_))
|
|
57 ;; If we don't have a period,
|
|
58 ;; and we have a dash or underscore that isn't the first char,
|
|
59 ;; change that to a period.
|
|
60 (if (and (not (string-match "\\." string))
|
|
61 (setq i (string-match "[-_]" string 1)))
|
|
62 (aset string i ?\.))
|
|
63 ;; If we don't have a period in the first 8 chars, insert one.
|
|
64 (if (> (or (string-match "\\." string)
|
|
65 (length string))
|
|
66 8)
|
|
67 (setq string
|
|
68 (concat (substring string 0 8)
|
|
69 "."
|
|
70 (substring string 8))))
|
|
71 (setq firstdot (or (string-match "\\." string) (1- (length string))))
|
|
72 ;; Truncate to 3 chars after the first period.
|
|
73 (if (> (length string) (+ firstdot 4))
|
|
74 (setq string (substring string 0 (+ firstdot 4))))
|
|
75 ;; Change all periods except the first one into underscores.
|
|
76 (while (string-match "\\." string (1+ firstdot))
|
|
77 (setq i (string-match "\\." string (1+ firstdot)))
|
|
78 (aset string i ?_))
|
|
79 ;; If the last character of the original filename was `~',
|
|
80 ;; make sure the munged name ends with it also.
|
|
81 (if (equal lastchar ?~)
|
|
82 (aset string (1- (length string)) lastchar))
|
|
83 (concat dir string))))
|
13913
|
84
|
21088
|
85 (defcustom msdos-shells '("command.com" "4dos.com" "ndos.com")
|
|
86 "*List of shells that use `/c' instead of `-c' and a backslashed command."
|
|
87 :type '(repeat string)
|
|
88 :group 'dos-fns)
|
5443
|
89
|
16690
|
90 (defvar register-name-alist
|
5443
|
91 '((ax . 0) (bx . 1) (cx . 2) (dx . 3) (si . 4) (di . 5)
|
7256
|
92 (cflag . 6) (flags . 7)
|
|
93 (al . (0 . 0)) (bl . (1 . 0)) (cl . (2 . 0)) (dl . (3 . 0))
|
|
94 (ah . (0 . 1)) (bh . (1 . 1)) (ch . (2 . 1)) (dh . (3 . 1))))
|
5443
|
95
|
|
96 (defun make-register ()
|
|
97 (make-vector 8 0))
|
|
98
|
|
99 (defun register-value (regs name)
|
7256
|
100 (let ((where (cdr (assoc name register-name-alist))))
|
5443
|
101 (cond ((consp where)
|
|
102 (let ((tem (aref regs (car where))))
|
|
103 (if (zerop (cdr where))
|
|
104 (% tem 256)
|
|
105 (/ tem 256))))
|
|
106 ((numberp where)
|
|
107 (aref regs where))
|
|
108 (t nil))))
|
|
109
|
|
110 (defun set-register-value (regs name value)
|
|
111 (and (numberp value)
|
7256
|
112 (>= value 0)
|
|
113 (let ((where (cdr (assoc name register-name-alist))))
|
5443
|
114 (cond ((consp where)
|
7256
|
115 (let ((tem (aref regs (car where)))
|
|
116 (value (logand value 255)))
|
|
117 (aset regs
|
|
118 (car where)
|
|
119 (if (zerop (cdr where))
|
|
120 (logior (logand tem 65280) value)
|
|
121 (logior (logand tem 255) (lsh value 8))))))
|
5443
|
122 ((numberp where)
|
7256
|
123 (aset regs where (logand value 65535))))))
|
5443
|
124 regs)
|
|
125
|
|
126 (defsubst intdos (regs)
|
|
127 (int86 33 regs))
|
|
128
|
14189
|
129 ;; Support for printing under MS-DOS, see lpr.el and ps-print.el.
|
21088
|
130 (defcustom dos-printer "PRN"
|
14189
|
131 "*The name of a local MS-DOS device to which data is sent for printing.
|
|
132 \(Note that PostScript files are sent to `dos-ps-printer', which see.\)
|
|
133
|
|
134 Typical non-default settings would be \"LPT1\" to \"LPT3\" for
|
|
135 parallel printers, or \"COM1\" to \"COM4\" or \"AUX\" for serial
|
|
136 printers. You can also set it to a name of a file, in which
|
|
137 case the output gets appended to that file.
|
21088
|
138 If you want to discard the printed output, set this to \"NUL\"."
|
|
139 :type 'file ; could use string but then we lose completion for files.
|
|
140 :group 'dos-fns)
|
14189
|
141
|
|
142 (defun dos-print-region-function (start end
|
|
143 &optional lpr-prog
|
|
144 delete-text buf display rest)
|
|
145 "MS-DOS-specific function to print the region on a printer.
|
|
146 Writes the region to the device or file which is a value of
|
|
147 `dos-printer' \(which see\). Ignores any arguments beyond
|
|
148 START and END."
|
|
149
|
19314
860783b225b9
(dos-print-region-function): Force EOL conversion to DOS CR-LF pairs.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
150 ;; DOS printers need the lines to end with CR-LF pairs, so make
|
21568
|
151 ;; sure it always happens that way, unless the buffer is binary.
|
|
152 (let* ((coding coding-system-for-write)
|
|
153 (coding-base
|
|
154 (if (null coding) 'undecided (coding-system-base coding)))
|
|
155 (eol-type (coding-system-eol-type coding-base)))
|
|
156 (or (eq coding-system-for-write 'no-conversion)
|
|
157 (setq coding-system-for-write
|
|
158 (aref eol-type 1))) ; force conversion to DOS EOLs
|
19314
860783b225b9
(dos-print-region-function): Force EOL conversion to DOS CR-LF pairs.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
159 (write-region start end dos-printer t 0)
|
860783b225b9
(dos-print-region-function): Force EOL conversion to DOS CR-LF pairs.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
160 ;; Make each print-out start on a new page, but don't waste
|
860783b225b9
(dos-print-region-function): Force EOL conversion to DOS CR-LF pairs.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
161 ;; paper if there was a form-feed at the end of this file.
|
860783b225b9
(dos-print-region-function): Force EOL conversion to DOS CR-LF pairs.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
162 (if (not (char-equal (char-after (1- end)) ?\C-l))
|
860783b225b9
(dos-print-region-function): Force EOL conversion to DOS CR-LF pairs.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
163 (write-region "\f" nil dos-printer t 0))))
|
14189
|
164
|
|
165 ;; Set this to nil if you have a port of the `lpr' program and
|
|
166 ;; you want to use it for printing. If the default setting is
|
|
167 ;; in effect, `lpr-command' and its switches are ignored when
|
|
168 ;; printing with `lpr-xxx' and `print-xxx'.
|
|
169 (setq print-region-function 'dos-print-region-function)
|
|
170
|
|
171 ;; Set this to nil if you have a port of the `pr' program
|
|
172 ;; (e.g., from GNU Textutils), or if you have an `lpr'
|
|
173 ;; program (see above) that can print page headers.
|
|
174 ;; If `lpr-headers-switches' is non-nil (the default) and
|
|
175 ;; `print-region-function' is set to `dos-print-region-function',
|
|
176 ;; then requests to print page headers will be silently
|
|
177 ;; ignored, and `print-buffer' and `print-region' produce
|
|
178 ;; the same output as `lpr-buffer' and `lpr-region', accordingly.
|
|
179 (setq lpr-headers-switches "(page headers are not supported)")
|
|
180
|
21088
|
181 (defcustom dos-ps-printer "PRN"
|
14189
|
182 "*Method for printing PostScript files under MS-DOS.
|
|
183
|
|
184 If the value is a string, then it is taken as the name of the
|
|
185 device to which PostScript files are written. By default it
|
|
186 is the default printer device; typical non-default settings
|
|
187 would be \"LPT1\" to \"LPT3\" for parallel printers, or \"COM1\"
|
|
188 to \"COM4\" or \"AUX\" for serial printers. You can also set it
|
|
189 to a name of a file, in which case the output gets appended
|
|
190 to that file. \(Note that `ps-print' package already has
|
|
191 facilities for printing to a file, so you might as well use
|
|
192 them instead of changing the setting of this variable.\) If
|
|
193 you want to silently discard the printed output, set this to \"NUL\".
|
|
194
|
|
195 If the value is anything but a string, PostScript files will be
|
|
196 piped to the program given by `ps-lpr-command', with switches
|
21088
|
197 given by `ps-lpr-switches', which see."
|
|
198 :type '(choice file (const :tag "Pipe to ps-lpr-command" pipe))
|
|
199 :group 'dos-fns)
|
14189
|
200
|
|
201 (setq ps-lpr-command "gs")
|
|
202
|
|
203 (setq ps-lpr-switches '("-q" "-dNOPAUSE" "-sDEVICE=epson" "-r240x60"
|
|
204 "-sOutputFile=LPT1" "-"))
|
|
205
|
14380
874cd82cd2b4
(mode25): Moved from `src/dosfns.c' for backward compatibility.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
206 ;; Backward compatibility for obsolescent functions which
|
874cd82cd2b4
(mode25): Moved from `src/dosfns.c' for backward compatibility.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
207 ;; set screen size.
|
874cd82cd2b4
(mode25): Moved from `src/dosfns.c' for backward compatibility.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
208
|
874cd82cd2b4
(mode25): Moved from `src/dosfns.c' for backward compatibility.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
209 (defun mode25 ()
|
874cd82cd2b4
(mode25): Moved from `src/dosfns.c' for backward compatibility.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
210 "Changes the number of screen rows to 25."
|
874cd82cd2b4
(mode25): Moved from `src/dosfns.c' for backward compatibility.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
211 (interactive)
|
874cd82cd2b4
(mode25): Moved from `src/dosfns.c' for backward compatibility.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
212 (set-frame-size (selected-frame) 80 25))
|
874cd82cd2b4
(mode25): Moved from `src/dosfns.c' for backward compatibility.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
213
|
874cd82cd2b4
(mode25): Moved from `src/dosfns.c' for backward compatibility.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
214 (defun mode4350 ()
|
874cd82cd2b4
(mode25): Moved from `src/dosfns.c' for backward compatibility.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
215 "Changes the number of rows to 43 or 50.
|
874cd82cd2b4
(mode25): Moved from `src/dosfns.c' for backward compatibility.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
216 Emacs always tries to set the screen height to 50 rows first.
|
874cd82cd2b4
(mode25): Moved from `src/dosfns.c' for backward compatibility.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
217 If this fails, it will try to set it to 43 rows, on the assumption
|
874cd82cd2b4
(mode25): Moved from `src/dosfns.c' for backward compatibility.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
218 that your video hardware might not support 50-line mode."
|
874cd82cd2b4
(mode25): Moved from `src/dosfns.c' for backward compatibility.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
219 (interactive)
|
874cd82cd2b4
(mode25): Moved from `src/dosfns.c' for backward compatibility.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
220 (set-frame-size (selected-frame) 80 50)
|
874cd82cd2b4
(mode25): Moved from `src/dosfns.c' for backward compatibility.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
221 (if (eq (frame-height (selected-frame)) 50)
|
874cd82cd2b4
(mode25): Moved from `src/dosfns.c' for backward compatibility.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
222 nil ; the original built-in function returned nil
|
874cd82cd2b4
(mode25): Moved from `src/dosfns.c' for backward compatibility.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
223 (set-frame-size (selected-frame) 80 43)))
|
874cd82cd2b4
(mode25): Moved from `src/dosfns.c' for backward compatibility.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
224
|
14189
|
225 (provide 'dos-fns)
|
|
226
|
|
227 ; dos-fns.el ends here
|