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