Commit | Line | Data |
---|---|---|
1b94449f RS |
1 | /* MS-DOS specific Lisp utilities. Coded by Manabu Higashida, 1991. |
2 | Major changes May-July 1993 Morten Welinder (only 10% original code left) | |
0b5538bd | 3 | Copyright (C) 1991, 1993, 1996, 1997, 1998, 2001, 2002, 2003, 2004, |
114f9c96 | 4 | 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
1b94449f RS |
5 | |
6 | This file is part of GNU Emacs. | |
7 | ||
9ec0b715 | 8 | GNU Emacs is free software: you can redistribute it and/or modify |
1b94449f | 9 | it under the terms of the GNU General Public License as published by |
9ec0b715 GM |
10 | the Free Software Foundation, either version 3 of the License, or |
11 | (at your option) any later version. | |
1b94449f RS |
12 | |
13 | GNU Emacs is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
9ec0b715 | 19 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
1b94449f | 20 | |
48984716 | 21 | #include <config.h> |
1b94449f RS |
22 | |
23 | #ifdef MSDOS | |
24 | /* The entire file is within this conditional */ | |
25 | ||
26 | #include <stdio.h> | |
e4441df0 | 27 | #include <string.h> |
1b94449f | 28 | #include <dos.h> |
d7306fe6 | 29 | #include <setjmp.h> |
1b94449f RS |
30 | #include "lisp.h" |
31 | #include "buffer.h" | |
32 | #include "termchar.h" | |
1b94449f | 33 | #include "frame.h" |
c06981c0 | 34 | #include "termhooks.h" |
838a94b8 EZ |
35 | #include "blockinput.h" |
36 | #include "window.h" | |
1b94449f RS |
37 | #include "dosfns.h" |
38 | #include "msdos.h" | |
e4441df0 | 39 | #include "dispextern.h" |
83be827a | 40 | #include "character.h" |
76a76a57 | 41 | #include "coding.h" |
e5c9f94c | 42 | #include "process.h" |
838a94b8 | 43 | #include <dpmi.h> |
5f08dc78 | 44 | #include <go32.h> |
50666766 | 45 | #include <dirent.h> |
76a76a57 | 46 | #include <sys/vfs.h> |
e5c9f94c EZ |
47 | #include <unistd.h> |
48 | #include <grp.h> | |
49 | #include <crt0.h> | |
1b94449f | 50 | |
1b94449f | 51 | DEFUN ("int86", Fint86, Sint86, 2, 2, 0, |
8fc29035 | 52 | doc: /* Call specific MS-DOS interrupt number INTERRUPT with REGISTERS. |
7363986a PJ |
53 | Return the updated REGISTER vector. |
54 | ||
55 | INTERRUPT should be an integer in the range 0 to 255. | |
56 | REGISTERS should be a vector produced by `make-register' and | |
57 | `set-register-value'. */) | |
58 | (interrupt, registers) | |
59 | Lisp_Object interrupt, registers; | |
1b94449f RS |
60 | { |
61 | register int i; | |
62 | int no; | |
63 | union REGS inregs, outregs; | |
64 | Lisp_Object val; | |
65 | ||
b7826503 | 66 | CHECK_NUMBER (interrupt); |
e20104ba | 67 | no = (unsigned long) XINT (interrupt); |
b7826503 | 68 | CHECK_VECTOR (registers); |
b058cb36 | 69 | if (no < 0 || no > 0xff || XVECTOR (registers)-> size != 8) |
1b94449f RS |
70 | return Qnil; |
71 | for (i = 0; i < 8; i++) | |
b7826503 | 72 | CHECK_NUMBER (XVECTOR (registers)->contents[i]); |
1b94449f | 73 | |
e20104ba EN |
74 | inregs.x.ax = (unsigned long) XFASTINT (XVECTOR (registers)->contents[0]); |
75 | inregs.x.bx = (unsigned long) XFASTINT (XVECTOR (registers)->contents[1]); | |
76 | inregs.x.cx = (unsigned long) XFASTINT (XVECTOR (registers)->contents[2]); | |
77 | inregs.x.dx = (unsigned long) XFASTINT (XVECTOR (registers)->contents[3]); | |
78 | inregs.x.si = (unsigned long) XFASTINT (XVECTOR (registers)->contents[4]); | |
79 | inregs.x.di = (unsigned long) XFASTINT (XVECTOR (registers)->contents[5]); | |
80 | inregs.x.cflag = (unsigned long) XFASTINT (XVECTOR (registers)->contents[6]); | |
81 | inregs.x.flags = (unsigned long) XFASTINT (XVECTOR (registers)->contents[7]); | |
1b94449f RS |
82 | |
83 | int86 (no, &inregs, &outregs); | |
84 | ||
e20104ba EN |
85 | XVECTOR (registers)->contents[0] = make_number (outregs.x.ax); |
86 | XVECTOR (registers)->contents[1] = make_number (outregs.x.bx); | |
87 | XVECTOR (registers)->contents[2] = make_number (outregs.x.cx); | |
88 | XVECTOR (registers)->contents[3] = make_number (outregs.x.dx); | |
89 | XVECTOR (registers)->contents[4] = make_number (outregs.x.si); | |
90 | XVECTOR (registers)->contents[5] = make_number (outregs.x.di); | |
91 | XVECTOR (registers)->contents[6] = make_number (outregs.x.cflag); | |
92 | XVECTOR (registers)->contents[7] = make_number (outregs.x.flags); | |
1b94449f | 93 | |
e20104ba | 94 | return registers; |
1b94449f RS |
95 | } |
96 | ||
5f08dc78 | 97 | DEFUN ("msdos-memget", Fdos_memget, Sdos_memget, 2, 2, 0, |
7363986a PJ |
98 | doc: /* Read DOS memory at offset ADDRESS into VECTOR. |
99 | Return the updated VECTOR. */) | |
100 | (address, vector) | |
101 | Lisp_Object address, vector; | |
5f08dc78 KS |
102 | { |
103 | register int i; | |
104 | int offs, len; | |
105 | char *buf; | |
106 | Lisp_Object val; | |
107 | ||
b7826503 | 108 | CHECK_NUMBER (address); |
e20104ba | 109 | offs = (unsigned long) XINT (address); |
b7826503 | 110 | CHECK_VECTOR (vector); |
e20104ba | 111 | len = XVECTOR (vector)-> size; |
238a44a8 | 112 | if (len < 1 || len > 2048 || offs < 0 || offs > 0xfffff - len) |
5f08dc78 KS |
113 | return Qnil; |
114 | buf = alloca (len); | |
115 | dosmemget (offs, len, buf); | |
b058cb36 | 116 | |
5f08dc78 | 117 | for (i = 0; i < len; i++) |
e20104ba | 118 | XVECTOR (vector)->contents[i] = make_number (buf[i]); |
5f08dc78 | 119 | |
e20104ba | 120 | return vector; |
5f08dc78 KS |
121 | } |
122 | ||
123 | DEFUN ("msdos-memput", Fdos_memput, Sdos_memput, 2, 2, 0, | |
7363986a PJ |
124 | doc: /* Write DOS memory at offset ADDRESS from VECTOR. */) |
125 | (address, vector) | |
126 | Lisp_Object address, vector; | |
5f08dc78 KS |
127 | { |
128 | register int i; | |
129 | int offs, len; | |
130 | char *buf; | |
131 | Lisp_Object val; | |
132 | ||
b7826503 | 133 | CHECK_NUMBER (address); |
e20104ba | 134 | offs = (unsigned long) XINT (address); |
b7826503 | 135 | CHECK_VECTOR (vector); |
e20104ba | 136 | len = XVECTOR (vector)-> size; |
238a44a8 | 137 | if (len < 1 || len > 2048 || offs < 0 || offs > 0xfffff - len) |
5f08dc78 KS |
138 | return Qnil; |
139 | buf = alloca (len); | |
140 | ||
141 | for (i = 0; i < len; i++) | |
142 | { | |
b7826503 | 143 | CHECK_NUMBER (XVECTOR (vector)->contents[i]); |
e20104ba | 144 | buf[i] = (unsigned char) XFASTINT (XVECTOR (vector)->contents[i]) & 0xFF; |
5f08dc78 KS |
145 | } |
146 | ||
147 | dosmemput (buf, len, offs); | |
148 | return Qt; | |
149 | } | |
150 | ||
151 | DEFUN ("msdos-set-keyboard", Fmsdos_set_keyboard, Smsdos_set_keyboard, 1, 2, 0, | |
7363986a PJ |
152 | doc: /* Set keyboard layout according to COUNTRY-CODE. |
153 | If the optional argument ALLKEYS is non-nil, the keyboard is mapped for | |
154 | all keys; otherwise it is only used when the ALT key is pressed. | |
155 | The current keyboard layout is available in dos-keyboard-code. */) | |
156 | (country_code, allkeys) | |
238a44a8 | 157 | Lisp_Object country_code, allkeys; |
5f08dc78 | 158 | { |
b7826503 | 159 | CHECK_NUMBER (country_code); |
5f08dc78 KS |
160 | if (!dos_set_keyboard (XINT (country_code), !NILP (allkeys))) |
161 | return Qnil; | |
162 | return Qt; | |
163 | } | |
164 | ||
87485d6f MW |
165 | #ifndef HAVE_X_WINDOWS |
166 | /* Later we might want to control the mouse interface with this function, | |
167 | e.g., with respect to non-80 column screen modes. */ | |
168 | ||
7363986a PJ |
169 | DEFUN ("msdos-mouse-p", Fmsdos_mouse_p, Smsdos_mouse_p, 0, 0, 0, |
170 | doc: /* Report whether a mouse is present. */) | |
87485d6f MW |
171 | () |
172 | { | |
173 | if (have_mouse) | |
174 | return Qt; | |
175 | else | |
176 | return Qnil; | |
177 | } | |
87485d6f MW |
178 | #endif |
179 | ||
ac3b0279 | 180 | DEFUN ("msdos-mouse-init", Fmsdos_mouse_init, Smsdos_mouse_init, 0, 0, "", |
7363986a PJ |
181 | doc: /* Initialize and enable mouse if available. */) |
182 | () | |
ac3b0279 | 183 | { |
5f08dc78 KS |
184 | if (have_mouse) |
185 | { | |
186 | have_mouse = 1; | |
187 | mouse_init (); | |
188 | return Qt; | |
189 | } | |
ac3b0279 RS |
190 | return Qnil; |
191 | } | |
192 | ||
193 | DEFUN ("msdos-mouse-enable", Fmsdos_mouse_enable, Smsdos_mouse_enable, 0, 0, "", | |
7363986a PJ |
194 | doc: /* Enable mouse if available. */) |
195 | () | |
ac3b0279 RS |
196 | { |
197 | if (have_mouse) | |
198 | { | |
5f08dc78 KS |
199 | have_mouse = 1; |
200 | mouse_on (); | |
ac3b0279 RS |
201 | } |
202 | return have_mouse ? Qt : Qnil; | |
203 | } | |
204 | ||
205 | DEFUN ("msdos-mouse-disable", Fmsdos_mouse_disable, Smsdos_mouse_disable, 0, 0, "", | |
7363986a PJ |
206 | doc: /* Disable mouse if available. */) |
207 | () | |
ac3b0279 RS |
208 | { |
209 | mouse_off (); | |
210 | if (have_mouse) have_mouse = -1; | |
211 | return Qnil; | |
212 | } | |
213 | ||
7363986a | 214 | DEFUN ("insert-startup-screen", Finsert_startup_screen, Sinsert_startup_screen, 0, 0, "", |
cd53fb50 | 215 | doc: /* Insert copy of screen contents prior to starting Emacs. |
7363986a PJ |
216 | Return nil if startup screen is not available. */) |
217 | () | |
5f08dc78 KS |
218 | { |
219 | char *s; | |
b058cb36 EZ |
220 | int rows, cols, i, j; |
221 | ||
5f08dc78 KS |
222 | if (!dos_get_saved_screen (&s, &rows, &cols)) |
223 | return Qnil; | |
b058cb36 | 224 | |
5f08dc78 KS |
225 | for (i = 0; i < rows; i++) |
226 | { | |
227 | for (j = 0; j < cols; j++) | |
228 | { | |
65788bc2 | 229 | insert_char (*s); |
5f08dc78 KS |
230 | s += 2; |
231 | } | |
65788bc2 | 232 | insert_char ('\n'); |
5f08dc78 KS |
233 | } |
234 | ||
235 | return Qt; | |
236 | } | |
87485d6f | 237 | \f |
5f08dc78 | 238 | /* country info */ |
31ade731 SM |
239 | EMACS_INT dos_country_code; |
240 | EMACS_INT dos_codepage; | |
241 | EMACS_INT dos_timezone_offset; | |
242 | EMACS_INT dos_decimal_point; | |
243 | EMACS_INT dos_keyboard_layout; | |
5f08dc78 | 244 | unsigned char dos_country_info[DOS_COUNTRY_INFO]; |
e089dc62 RS |
245 | static unsigned char usa_country_info[DOS_COUNTRY_INFO] = { |
246 | 0, 0, /* date format */ | |
247 | '$', 0, 0, 0, 0, /* currency string */ | |
248 | ',', 0, /* thousands separator */ | |
249 | '.', 0, /* decimal separator */ | |
250 | '/', 0, /* date separator */ | |
251 | ':', 0, /* time separator */ | |
252 | 0, /* currency format */ | |
253 | 2, /* digits after decimal in currency */ | |
254 | 0, /* time format */ | |
255 | 0, 0, 0, 0, /* address of case map routine, GPF if used */ | |
256 | ' ', 0, /* data-list separator (?) */ | |
257 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* reserved */ | |
258 | }; | |
5f08dc78 | 259 | |
31ade731 SM |
260 | EMACS_INT dos_hyper_key; |
261 | EMACS_INT dos_super_key; | |
262 | EMACS_INT dos_keypad_mode; | |
1b94449f | 263 | |
5f08dc78 KS |
264 | Lisp_Object Vdos_version; |
265 | Lisp_Object Vdos_display_scancodes; | |
838a94b8 EZ |
266 | |
267 | #ifndef HAVE_X_WINDOWS | |
268 | static unsigned dos_windows_version; | |
269 | Lisp_Object Vdos_windows_version; | |
270 | ||
271 | char parent_vm_title[50]; /* Ralf Brown says 30 is enough */ | |
272 | int w95_set_virtual_machine_title (const char *); | |
273 | ||
274 | void | |
275 | restore_parent_vm_title (void) | |
276 | { | |
277 | if (NILP (Vdos_windows_version)) | |
278 | return; | |
279 | if ((dos_windows_version & 0xff) >= 4 && parent_vm_title[0]) | |
280 | w95_set_virtual_machine_title (parent_vm_title); | |
281 | delay (50); | |
282 | } | |
283 | #endif /* !HAVE_X_WINDOWS */ | |
b058cb36 | 284 | |
1b94449f RS |
285 | void |
286 | init_dosfns () | |
287 | { | |
288 | union REGS regs; | |
1b94449f | 289 | _go32_dpmi_registers dpmiregs; |
e089dc62 | 290 | unsigned long xbuf = _go32_info_block.linear_address_of_transfer_buffer; |
1b94449f | 291 | |
87485d6f | 292 | #ifndef SYSTEM_MALLOC |
1b94449f | 293 | get_lim_data (); /* why the hell isn't this called elsewhere? */ |
87485d6f | 294 | #endif |
1b94449f RS |
295 | |
296 | regs.x.ax = 0x3000; | |
297 | intdos (®s, ®s); | |
298 | Vdos_version = Fcons (make_number (regs.h.al), make_number (regs.h.ah)); | |
299 | ||
e089dc62 RS |
300 | /* Obtain the country code via DPMI, use DJGPP transfer buffer. */ |
301 | dpmiregs.x.ax = 0x3800; | |
7a2fd369 | 302 | dpmiregs.x.ds = xbuf >> 4; |
e089dc62 RS |
303 | dpmiregs.x.dx = 0; |
304 | dpmiregs.x.ss = dpmiregs.x.sp = dpmiregs.x.flags = 0; | |
305 | _go32_dpmi_simulate_int (0x21, &dpmiregs); | |
306 | if (dpmiregs.x.flags & 1) | |
307 | { | |
308 | dos_country_code = 1; /* assume USA if 213800 failed */ | |
309 | memcpy (dos_country_info, usa_country_info, DOS_COUNTRY_INFO); | |
310 | } | |
1b94449f RS |
311 | else |
312 | { | |
1b94449f | 313 | dos_country_code = dpmiregs.x.bx; |
e089dc62 | 314 | dosmemget (xbuf, DOS_COUNTRY_INFO, dos_country_info); |
1b94449f | 315 | } |
e089dc62 | 316 | |
5f08dc78 | 317 | dos_set_keyboard (dos_country_code, 0); |
1b94449f RS |
318 | |
319 | regs.x.ax = 0x6601; | |
320 | intdos (®s, ®s); | |
321 | if (regs.x.cflag) | |
322 | /* Estimate code page from country code */ | |
b058cb36 | 323 | switch (dos_country_code) |
1b94449f RS |
324 | { |
325 | case 45: /* Denmark */ | |
326 | case 47: /* Norway */ | |
327 | dos_codepage = 865; | |
328 | break; | |
329 | default: | |
330 | /* US */ | |
331 | dos_codepage = 437; | |
332 | } | |
333 | else | |
334 | dos_codepage = regs.x.bx & 0xffff; | |
50666766 | 335 | |
838a94b8 EZ |
336 | #ifndef HAVE_X_WINDOWS |
337 | parent_vm_title[0] = '\0'; | |
338 | ||
339 | /* If we are running from DOS box on MS-Windows, get Windows version. */ | |
340 | dpmiregs.x.ax = 0x1600; /* enhanced mode installation check */ | |
341 | dpmiregs.x.ss = dpmiregs.x.sp = dpmiregs.x.flags = 0; | |
342 | _go32_dpmi_simulate_int (0x2f, &dpmiregs); | |
343 | /* We only support Windows-specific features when we run on Windows 9X | |
344 | or on Windows 3.X/enhanced mode. | |
345 | ||
346 | Int 2Fh/AX=1600h returns: | |
347 | ||
348 | AL = 00: no Windows at all; | |
349 | AL = 01: Windows/386 2.x; | |
350 | AL = 80h: Windows 3.x in mode other than enhanced; | |
351 | AL = FFh: Windows/386 2.x | |
352 | ||
353 | We also check AH > 0 (Windows 3.1 or later), in case AL tricks us. */ | |
354 | if (dpmiregs.h.al > 2 && dpmiregs.h.al != 0x80 && dpmiregs.h.al != 0xff | |
355 | && (dpmiregs.h.al > 3 || dpmiregs.h.ah > 0)) | |
356 | { | |
357 | dos_windows_version = dpmiregs.x.ax; | |
358 | Vdos_windows_version = | |
359 | Fcons (make_number (dpmiregs.h.al), make_number (dpmiregs.h.ah)); | |
360 | ||
361 | /* Save the current title of this virtual machine, so we can restore | |
362 | it before exiting. Otherwise, Windows 95 will continue to use | |
363 | the title we set even after we are history, stupido... */ | |
364 | if (dpmiregs.h.al >= 4) | |
365 | { | |
366 | dpmiregs.x.ax = 0x168e; | |
367 | dpmiregs.x.dx = 3; /* get VM title */ | |
368 | dpmiregs.x.cx = sizeof(parent_vm_title) - 1; | |
369 | dpmiregs.x.es = __tb >> 4; | |
370 | dpmiregs.x.di = __tb & 15; | |
371 | dpmiregs.x.sp = dpmiregs.x.ss = dpmiregs.x.flags = 0; | |
372 | _go32_dpmi_simulate_int (0x2f, &dpmiregs); | |
373 | if (dpmiregs.x.ax == 1) | |
374 | dosmemget (__tb, sizeof(parent_vm_title), parent_vm_title); | |
375 | } | |
376 | } | |
377 | else | |
378 | { | |
379 | dos_windows_version = 0; | |
380 | Vdos_windows_version = Qnil; | |
381 | } | |
382 | #endif /* !HAVE_X_WINDOWS */ | |
383 | ||
459f4042 RS |
384 | /* Without this, we never see hidden files. |
385 | Don't OR it with the previous value, so the value recorded at dump | |
386 | time, possibly with `preserve-case' flags set, won't get through. */ | |
387 | __opendir_flags = __OPENDIR_FIND_HIDDEN; | |
388 | ||
389 | #if __DJGPP_MINOR__ == 0 | |
390 | /* Under LFN, preserve the case of files as recorded in the directory | |
391 | (in DJGPP 2.01 and later this is automagically done by the library). */ | |
50666766 RS |
392 | if (!NILP (Fmsdos_long_file_names ())) |
393 | __opendir_flags |= __OPENDIR_PRESERVE_CASE; | |
459f4042 | 394 | #endif /* __DJGPP_MINOR__ == 0 */ |
1b94449f RS |
395 | } |
396 | \f | |
838a94b8 | 397 | #ifndef HAVE_X_WINDOWS |
e4441df0 EZ |
398 | |
399 | /* Emulation of some X window features from xfns.c and xfaces.c. */ | |
400 | ||
401 | /* Standard VGA colors, in the order of their standard numbering | |
402 | in the default VGA palette. */ | |
403 | static char *vga_colors[16] = { | |
404 | "black", "blue", "green", "cyan", "red", "magenta", "brown", | |
405 | "lightgray", "darkgray", "lightblue", "lightgreen", "lightcyan", | |
406 | "lightred", "lightmagenta", "yellow", "white" | |
407 | }; | |
408 | ||
409 | /* Given a color name, return its index, or -1 if not found. Note | |
410 | that this only performs case-insensitive comparison against the | |
411 | standard names. For anything more sophisticated, like matching | |
412 | "gray" with "grey" or translating X color names into their MSDOS | |
2d764c78 EZ |
413 | equivalents, call the Lisp function Qtty_color_desc (defined |
414 | on lisp/term/tty-colors.el). */ | |
e4441df0 EZ |
415 | int |
416 | msdos_stdcolor_idx (const char *name) | |
417 | { | |
418 | int i; | |
419 | ||
420 | for (i = 0; i < sizeof (vga_colors) / sizeof (vga_colors[0]); i++) | |
05131107 | 421 | if (xstrcasecmp (name, vga_colors[i]) == 0) |
e4441df0 EZ |
422 | return i; |
423 | ||
f9d2fdc4 | 424 | return |
24480d5b EZ |
425 | strcmp (name, unspecified_fg) == 0 ? FACE_TTY_DEFAULT_FG_COLOR |
426 | : strcmp (name, unspecified_bg) == 0 ? FACE_TTY_DEFAULT_BG_COLOR | |
f9d2fdc4 | 427 | : FACE_TTY_DEFAULT_COLOR; |
e4441df0 EZ |
428 | } |
429 | ||
430 | /* Given a color index, return its standard name. */ | |
2d764c78 | 431 | Lisp_Object |
e4441df0 EZ |
432 | msdos_stdcolor_name (int idx) |
433 | { | |
24480d5b EZ |
434 | extern Lisp_Object Qunspecified; |
435 | ||
436 | if (idx == FACE_TTY_DEFAULT_FG_COLOR) | |
437 | return build_string (unspecified_fg); | |
438 | else if (idx == FACE_TTY_DEFAULT_BG_COLOR) | |
439 | return build_string (unspecified_bg); | |
440 | else if (idx >= 0 && idx < sizeof (vga_colors) / sizeof (vga_colors[0])) | |
441 | return build_string (vga_colors[idx]); | |
442 | else | |
443 | return Qunspecified; /* meaning the default */ | |
e4441df0 EZ |
444 | } |
445 | ||
838a94b8 EZ |
446 | /* Support for features that are available when we run in a DOS box |
447 | on MS-Windows. */ | |
448 | int | |
449 | ms_windows_version (void) | |
450 | { | |
451 | return dos_windows_version; | |
452 | } | |
453 | ||
454 | /* Set the title of the current virtual machine, to appear on | |
455 | the caption bar of that machine's window. */ | |
456 | ||
457 | int | |
458 | w95_set_virtual_machine_title (const char *title_string) | |
459 | { | |
460 | /* Only Windows 9X (version 4 and higher) support this function. */ | |
461 | if (!NILP (Vdos_windows_version) | |
462 | && (dos_windows_version & 0xff) >= 4) | |
463 | { | |
464 | _go32_dpmi_registers regs; | |
465 | dosmemput (title_string, strlen (title_string) + 1, __tb); | |
466 | regs.x.ax = 0x168e; | |
467 | regs.x.dx = 1; | |
468 | regs.x.es = __tb >> 4; | |
469 | regs.x.di = __tb & 15; | |
470 | regs.x.sp = regs.x.ss = regs.x.flags = 0; | |
471 | _go32_dpmi_simulate_int (0x2f, ®s); | |
472 | return regs.x.ax == 1; | |
473 | } | |
474 | return 0; | |
475 | } | |
476 | ||
477 | /* Change the title of frame F to NAME. | |
478 | If NAME is nil, use the frame name as the title. | |
479 | ||
480 | If Emacs is not run from a DOS box on Windows 9X, this only | |
481 | sets the name in the frame struct, but has no other effects. */ | |
482 | ||
483 | void | |
484 | x_set_title (f, name) | |
485 | struct frame *f; | |
486 | Lisp_Object name; | |
487 | { | |
488 | /* Don't change the title if it's already NAME. */ | |
489 | if (EQ (name, f->title)) | |
490 | return; | |
491 | ||
492 | update_mode_lines = 1; | |
493 | ||
494 | f->title = name; | |
495 | ||
496 | if (NILP (name)) | |
497 | name = f->name; | |
498 | ||
499 | if (FRAME_MSDOS_P (f)) | |
500 | { | |
501 | BLOCK_INPUT; | |
d5db4077 | 502 | w95_set_virtual_machine_title (SDATA (name)); |
838a94b8 EZ |
503 | UNBLOCK_INPUT; |
504 | } | |
505 | } | |
506 | #endif /* !HAVE_X_WINDOWS */ | |
507 | \f | |
76a76a57 | 508 | DEFUN ("file-system-info", Ffile_system_info, Sfile_system_info, 1, 1, 0, |
7363986a PJ |
509 | doc: /* Return storage information about the file system FILENAME is on. |
510 | Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total | |
511 | storage of the file system, FREE is the free storage, and AVAIL is the | |
512 | storage available to a non-superuser. All 3 numbers are in bytes. | |
513 | If the underlying system call fails, value is nil. */) | |
514 | (filename) | |
515 | Lisp_Object filename; | |
76a76a57 EZ |
516 | { |
517 | struct statfs stfs; | |
518 | Lisp_Object encoded, value; | |
519 | ||
b7826503 | 520 | CHECK_STRING (filename); |
76a76a57 EZ |
521 | filename = Fexpand_file_name (filename, Qnil); |
522 | encoded = ENCODE_FILE (filename); | |
523 | ||
d5db4077 | 524 | if (statfs (SDATA (encoded), &stfs)) |
76a76a57 EZ |
525 | value = Qnil; |
526 | else | |
527 | value = list3 (make_float ((double) stfs.f_bsize * stfs.f_blocks), | |
528 | make_float ((double) stfs.f_bsize * stfs.f_bfree), | |
529 | make_float ((double) stfs.f_bsize * stfs.f_bavail)); | |
530 | ||
531 | return value; | |
532 | } | |
533 | \f | |
e5c9f94c EZ |
534 | /* System depended enumeration of and access to system processes a-la |
535 | ps(1). Here, we only return info about the running Emacs process. | |
536 | (There are no other processes on DOS, right?) */ | |
537 | ||
538 | Lisp_Object | |
539 | list_system_processes () | |
540 | { | |
541 | Lisp_Object proclist = Qnil; | |
542 | ||
543 | proclist = Fcons (make_fixnum_or_float (getpid ()), proclist); | |
544 | ||
545 | return proclist; | |
546 | } | |
547 | ||
548 | Lisp_Object | |
549 | system_process_attributes (Lisp_Object pid) | |
550 | { | |
551 | int proc_id; | |
552 | Lisp_Object attrs = Qnil; | |
553 | ||
554 | CHECK_NUMBER_OR_FLOAT (pid); | |
555 | proc_id = FLOATP (pid) ? XFLOAT_DATA (pid) : XINT (pid); | |
556 | ||
557 | if (proc_id == getpid ()) | |
558 | { | |
559 | EMACS_INT uid, gid; | |
560 | char *usr; | |
561 | struct group *gr; | |
562 | char cmd[FILENAME_MAX]; | |
563 | char *cmdline = NULL, *p, *q; | |
564 | size_t cmdline_size = 0; | |
565 | int i; | |
566 | Lisp_Object cmd_str, decoded_cmd, tem; | |
567 | double pmem; | |
693a2698 | 568 | #ifndef SYSTEM_MALLOC |
e5c9f94c | 569 | extern unsigned long ret_lim_data (); |
693a2698 | 570 | #endif |
e5c9f94c EZ |
571 | |
572 | uid = getuid (); | |
573 | attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (uid)), attrs); | |
574 | usr = getlogin (); | |
575 | if (usr) | |
576 | attrs = Fcons (Fcons (Quser, build_string (usr)), attrs); | |
577 | gid = getgid (); | |
578 | attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (gid)), attrs); | |
579 | gr = getgrgid (gid); | |
580 | if (gr) | |
581 | attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs); | |
582 | strcpy (cmd, basename (__crt0_argv[0])); | |
583 | /* Command name is encoded in locale-coding-system; decode it. */ | |
584 | cmd_str = make_unibyte_string (cmd, strlen (cmd)); | |
585 | decoded_cmd = code_convert_string_norecord (cmd_str, | |
586 | Vlocale_coding_system, 0); | |
587 | attrs = Fcons (Fcons (Qcomm, decoded_cmd), attrs); | |
588 | /* Pretend we have 0 as PPID. */ | |
589 | attrs = Fcons (Fcons (Qppid, make_number (0)), attrs); | |
590 | attrs = Fcons (Fcons (Qpgrp, pid), attrs); | |
591 | attrs = Fcons (Fcons (Qttname, build_string ("/dev/tty")), attrs); | |
592 | /* We are never idle! */ | |
593 | tem = Fget_internal_run_time (); | |
594 | attrs = Fcons (Fcons (Qtime, tem), attrs); | |
595 | attrs = Fcons (Fcons (Qthcount, make_number (1)), attrs); | |
596 | attrs = Fcons (Fcons (Qstart, | |
597 | Fsymbol_value (intern ("before-init-time"))), | |
598 | attrs); | |
599 | attrs = Fcons (Fcons (Qvsize, | |
600 | make_fixnum_or_float ((unsigned long)sbrk(0)/1024)), | |
601 | attrs); | |
602 | attrs = Fcons (Fcons (Qetime, tem), attrs); | |
693a2698 EZ |
603 | #ifndef SYSTEM_MALLOC |
604 | /* ret_lim_data is on vm-limit.c, which is not compiled in under | |
605 | SYSTEM_MALLOC. */ | |
e5c9f94c EZ |
606 | pmem = (double)((unsigned long) sbrk (0)) / ret_lim_data () * 100.0; |
607 | if (pmem > 100) | |
693a2698 | 608 | #endif |
e5c9f94c EZ |
609 | pmem = 100; |
610 | attrs = Fcons (Fcons (Qpmem, make_float (pmem)), attrs); | |
611 | /* Pass 1: Count how much storage we need. */ | |
612 | for (i = 0; i < __crt0_argc; i++) | |
613 | { | |
614 | cmdline_size += strlen (__crt0_argv[i]) + 1; /* +1 for blank delim */ | |
615 | if (strpbrk (__crt0_argv[i], " \t\n\r\v\f")) | |
616 | { | |
617 | cmdline_size += 2; | |
618 | for (p = __crt0_argv[i]; *p; p++) | |
619 | { | |
620 | if (*p == '"') | |
621 | cmdline_size++; | |
622 | } | |
623 | } | |
624 | } | |
625 | /* Pass 2: Allocate storage and concatenate argv[]. */ | |
626 | cmdline = xmalloc (cmdline_size + 1); | |
627 | for (i = 0, q = cmdline; i < __crt0_argc; i++) | |
628 | { | |
629 | if (strpbrk (__crt0_argv[i], " \t\n\r\v\f")) | |
630 | { | |
631 | *q++ = '"'; | |
632 | for (p = __crt0_argv[i]; *p; p++) | |
633 | { | |
634 | if (*p == '\"') | |
635 | *q++ = '\\'; | |
636 | *q++ = *p; | |
637 | } | |
638 | *q++ = '"'; | |
639 | } | |
640 | else | |
641 | { | |
642 | strcpy (q, __crt0_argv[i]); | |
643 | q += strlen (__crt0_argv[i]); | |
644 | } | |
645 | *q++ = ' '; | |
646 | } | |
647 | /* Remove the trailing blank. */ | |
648 | if (q > cmdline) | |
649 | q[-1] = '\0'; | |
650 | ||
651 | /* Command line is encoded in locale-coding-system; decode it. */ | |
652 | cmd_str = make_unibyte_string (cmdline, strlen (cmdline)); | |
653 | decoded_cmd = code_convert_string_norecord (cmd_str, | |
654 | Vlocale_coding_system, 0); | |
655 | xfree (cmdline); | |
656 | attrs = Fcons (Fcons (Qargs, decoded_cmd), attrs); | |
657 | } | |
658 | ||
659 | return attrs; | |
660 | } | |
661 | \f | |
838a94b8 EZ |
662 | void |
663 | dos_cleanup (void) | |
664 | { | |
c06981c0 EZ |
665 | struct tty_display_info *tty; |
666 | ||
838a94b8 EZ |
667 | #ifndef HAVE_X_WINDOWS |
668 | restore_parent_vm_title (); | |
669 | #endif | |
6f855d64 EZ |
670 | /* Make sure the termscript file is committed, in case we are |
671 | crashing and some vital info was written there. */ | |
c06981c0 | 672 | if (FRAMEP (selected_frame)) |
6f855d64 | 673 | { |
c06981c0 EZ |
674 | struct frame *sf = XFRAME (selected_frame); |
675 | ||
676 | if (FRAME_LIVE_P (sf) | |
677 | && (FRAME_MSDOS_P (sf) || FRAME_TERMCAP_P (sf))) | |
678 | { | |
679 | tty = CURTTY (); | |
680 | if (tty->termscript) | |
681 | { | |
682 | fflush (tty->termscript); | |
683 | fsync (fileno (tty->termscript)); | |
684 | } | |
685 | } | |
6f855d64 | 686 | } |
838a94b8 EZ |
687 | } |
688 | ||
1b94449f RS |
689 | /* |
690 | * Define everything | |
691 | */ | |
692 | syms_of_dosfns () | |
693 | { | |
1b94449f | 694 | defsubr (&Sint86); |
5f08dc78 KS |
695 | defsubr (&Sdos_memget); |
696 | defsubr (&Sdos_memput); | |
ac3b0279 RS |
697 | defsubr (&Smsdos_mouse_init); |
698 | defsubr (&Smsdos_mouse_enable); | |
5f08dc78 KS |
699 | defsubr (&Smsdos_set_keyboard); |
700 | defsubr (&Sinsert_startup_screen); | |
ac3b0279 | 701 | defsubr (&Smsdos_mouse_disable); |
76a76a57 | 702 | defsubr (&Sfile_system_info); |
87485d6f MW |
703 | #ifndef HAVE_X_WINDOWS |
704 | defsubr (&Smsdos_mouse_p); | |
87485d6f | 705 | #endif |
1b94449f RS |
706 | |
707 | DEFVAR_INT ("dos-country-code", &dos_country_code, | |
7363986a PJ |
708 | doc: /* The country code returned by Dos when Emacs was started. |
709 | Usually this is the international telephone prefix. */); | |
1b94449f RS |
710 | |
711 | DEFVAR_INT ("dos-codepage", &dos_codepage, | |
7363986a PJ |
712 | doc: /* The codepage active when Emacs was started. |
713 | The following are known: | |
714 | 437 United States | |
715 | 850 Multilingual (Latin I) | |
716 | 852 Slavic (Latin II) | |
717 | 857 Turkish | |
718 | 860 Portugal | |
719 | 861 Iceland | |
720 | 863 Canada (French) | |
721 | 865 Norway/Denmark */); | |
1b94449f | 722 | |
5f08dc78 | 723 | DEFVAR_INT ("dos-timezone-offset", &dos_timezone_offset, |
7363986a PJ |
724 | doc: /* The current timezone offset to UTC in minutes. |
725 | Implicitly modified when the TZ variable is changed. */); | |
b058cb36 | 726 | |
1b94449f | 727 | DEFVAR_LISP ("dos-version", &Vdos_version, |
7363986a | 728 | doc: /* The (MAJOR . MINOR) Dos version (subject to modification with setver). */); |
5f08dc78 | 729 | |
838a94b8 EZ |
730 | #ifndef HAVE_X_WINDOWS |
731 | DEFVAR_LISP ("dos-windows-version", &Vdos_windows_version, | |
7363986a | 732 | doc: /* The (MAJOR . MINOR) Windows version for DOS session on MS-Windows. */); |
838a94b8 EZ |
733 | #endif |
734 | ||
5f08dc78 | 735 | DEFVAR_LISP ("dos-display-scancodes", &Vdos_display_scancodes, |
7363986a PJ |
736 | doc: /* *Controls whether DOS raw keyboard events are displayed as you type. |
737 | When non-nil, the keyboard scan-codes are displayed at the bottom right | |
738 | corner of the display (typically at the end of the mode line). | |
739 | The output format is: scan code:char code*modifiers. */); | |
740 | ||
5f08dc78 | 741 | Vdos_display_scancodes = Qnil; |
b058cb36 | 742 | |
5f08dc78 | 743 | DEFVAR_INT ("dos-hyper-key", &dos_hyper_key, |
7363986a PJ |
744 | doc: /* *If set to 1, use right ALT key as hyper key. |
745 | If set to 2, use right CTRL key as hyper key. */); | |
5f08dc78 | 746 | dos_hyper_key = 0; |
b058cb36 | 747 | |
5f08dc78 | 748 | DEFVAR_INT ("dos-super-key", &dos_super_key, |
7363986a PJ |
749 | doc: /* *If set to 1, use right ALT key as super key. |
750 | If set to 2, use right CTRL key as super key. */); | |
5f08dc78 | 751 | dos_super_key = 0; |
b058cb36 | 752 | |
5f08dc78 | 753 | DEFVAR_INT ("dos-keypad-mode", &dos_keypad_mode, |
7363986a PJ |
754 | doc: /* *Controls what key code is returned by a key in the numeric keypad. |
755 | The `numlock ON' action is only taken if no modifier keys are pressed. | |
756 | The value is an integer constructed by adding the following bits together: | |
757 | ||
758 | 0x00 Digit key returns digit (if numlock ON) | |
759 | 0x01 Digit key returns kp-digit (if numlock ON) | |
760 | 0x02 Digit key returns M-digit (if numlock ON) | |
761 | 0x03 Digit key returns edit key (if numlock ON) | |
762 | ||
763 | 0x00 Grey key returns char (if numlock ON) | |
764 | 0x04 Grey key returns kp-key (if numlock ON) | |
765 | ||
766 | 0x00 Digit key returns digit (if numlock OFF) | |
767 | 0x10 Digit key returns kp-digit (if numlock OFF) | |
768 | 0x20 Digit key returns M-digit (if numlock OFF) | |
769 | 0x30 Digit key returns edit key (if numlock OFF) | |
770 | ||
771 | 0x00 Grey key returns char (if numlock OFF) | |
772 | 0x40 Grey key returns kp-key (if numlock OFF) | |
773 | ||
774 | 0x200 ALT-0..ALT-9 in top-row produces shifted codes. */); | |
b3d5621c | 775 | dos_keypad_mode = 0x75; |
b058cb36 | 776 | |
5f08dc78 | 777 | DEFVAR_INT ("dos-keyboard-layout", &dos_keyboard_layout, |
7363986a PJ |
778 | doc: /* Contains the country code for the current keyboard layout. |
779 | Use msdos-set-keyboard to select another keyboard layout. */); | |
5f08dc78 | 780 | dos_keyboard_layout = 1; /* US */ |
b058cb36 | 781 | |
5f08dc78 | 782 | DEFVAR_INT ("dos-decimal-point", &dos_decimal_point, |
7363986a PJ |
783 | doc: /* The character to produce when kp-decimal key is pressed. |
784 | If non-zero, this variable contains the character to be returned when the | |
785 | decimal point key in the numeric keypad is pressed when Num Lock is on. | |
786 | If zero, the decimal point key returns the country code specific value. */); | |
5f08dc78 | 787 | dos_decimal_point = 0; |
1b94449f RS |
788 | } |
789 | #endif /* MSDOS */ | |
6b61353c KH |
790 | |
791 | /* arch-tag: f5ea8847-a014-42c9-83f5-7738ad640b17 | |
792 | (do not change this comment) */ |