Spawn new process with ADDR_NO_RANDOMIZE personality if not already set
[sxemacs] / lisp / device.el
1 ;;; device.el --- miscellaneous device functions not written in C
2
3 ;; Copyright (C) 1994-5, 1997 Free Software Foundation, Inc.
4 ;; Copyright (C) 1995, 1996 Ben Wing
5
6 ;; Maintainer: SXEmacs Development Team
7 ;; Keywords: internal, dumped
8
9 ;; This file is part of SXEmacs.
10
11 ;; SXEmacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
15
16 ;; SXEmacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
24 ;;; Synched up with: Not in FSF.
25
26 ;;; Commentary:
27
28 ;; This file is dumped with SXEmacs.
29
30 ;;; Code:
31
32 ;;; Initialization
33
34 ; Specifier tag 'printer which matches printers
35 (define-specifier-tag 'printer (function device-printer-p))
36
37 ; Specifier tag 'display which matches displays
38 (define-specifier-tag 'display (function
39                                 (lambda (device)
40                                   (not (device-printer-p device)))))
41
42 ;;; Functions
43
44 (defun device-list ()
45   "Return a list of all devices."
46   (apply 'nconc (mapcar 'console-device-list (console-list))))
47
48 (defun device-type (&optional device)
49   "Return the type of the specified device (e.g. `x' or `tty').
50 This is equivalent to the type of the device's console.
51 Value is `tty' for a tty device (a character-only terminal),
52 `x' for a device that is a screen on an X display,
53 `ns' for a device that is a NeXTstep connection (not yet implemented),
54 `stream' for a stream device (which acts like a stdio stream), and
55 `dead' for a deleted device."
56   (or device (setq device (selected-device)))
57   (if (not (device-live-p device)) 'dead
58     (console-type (device-console device))))
59
60 (defun make-tty-device (&optional tty terminal-type controlling-process)
61   "Create a new device on TTY.
62   TTY should be the name of a tty device file (e.g. \"/dev/ttyp3\" under
63 SunOS et al.), as returned by the `tty' command.  A value of nil means
64 use the stdin and stdout as passed to XEmacs from the shell.
65   If TERMINAL-TYPE is non-nil, it should be a string specifying the
66 type of the terminal attached to the specified tty.  If it is nil,
67 the terminal type will be inferred from the TERM environment variable.
68   If CONTROLLING-PROCESS is non-nil, it should be an integer
69 specifying the process id of the process in control of the specified tty.  If
70 it is nil, it is assumes to be the value returned by emacs-pid."
71   (make-device 'tty tty (list 'terminal-type terminal-type
72                               'controlling-process controlling-process)))
73
74 (defun device-pixel-width (&optional device)
75   "Return the width in pixels of DEVICE, or nil if unknown."
76   (let ((ds (device-system-metric device 'size-device)))
77     (and ds (car ds))))
78
79 (defun device-pixel-height (&optional device)
80   "Return the height in pixels of DEVICE, or nil if unknown."
81   (let ((ds (device-system-metric device 'size-device)))
82     (and ds (cdr ds))))
83
84 (defun device-mm-width (&optional device)
85   "Return the width in millimeters of DEVICE, or nil if unknown."
86   (let ((ds (device-system-metric device 'size-device-mm)))
87     (and ds (car ds))))
88
89 (defun device-mm-height (&optional device)
90   "Return the height in millimeters of DEVICE, or nil if unknown."
91   (let ((ds (device-system-metric device 'size-device-mm)))
92     (and ds (cdr ds))))
93
94 (defun device-bitplanes (&optional device)
95   "Return the number of bitplanes of DEVICE, or nil if unknown."
96   (device-system-metric device 'num-bit-planes))
97
98 (defun device-color-cells (&optional device)
99   "Return the number of color cells of DEVICE, or nil if unknown."
100   (device-system-metric device 'num-color-cells))
101
102 (defun make-x-device (&optional display)
103   "Create a new device connected to DISPLAY."
104   (make-device 'x display))
105
106 (defun device-on-window-system-p (&optional device)
107   "Return non-nil if DEVICE is on a window system.
108 This generally means that there is support for the mouse, the menubar,
109 the toolbar, glyphs, etc."
110   (or device (setq device (selected-device)))
111   (console-on-window-system-p (device-console device)))
112
113 (defun call-device-method (name device &rest args)
114   "Call a DEVICE-specific function with the generic name NAME.
115 If DEVICE is not provided then the selected device is used."
116   (or device (setq device (selected-device)))
117   (or (symbolp name) (error "function name must be a symbol"))
118   (let ((devmeth (intern (concat (symbol-name
119                                   (device-type device)) "-" (symbol-name name)))))
120     (if (functionp devmeth)
121         (if args
122             (apply devmeth args)
123           (funcall devmeth))
124       nil)))
125
126 (defmacro define-device-method (name &optional docstring)
127   "Define NAME to be a device method."
128   `(defun ,name (&rest arglist) ,docstring
129      (apply 'call-device-method (quote ,name) nil arglist)))
130
131 (defmacro define-device-method* (name &optional docstring)
132   "Define NAME to be a device method."
133   `(defun* ,name (&rest arglist) ,docstring
134      (apply 'call-device-method (quote ,name) nil arglist)))
135
136 (defalias 'valid-device-type-p 'valid-console-type-p)
137 (defalias 'device-type-list 'console-type-list)
138 (defalias 'device-pixel-depth 'device-bitplanes)
139
140 ;;; device.el ends here