Mercurial > emacs
annotate src/msdos.c @ 7487:a7ff1a4b4e21
(syms_of_keyboard): Set up Qpolling_period.
(bind_polling_period): New function.
| author | Richard M. Stallman <rms@gnu.org> |
|---|---|
| date | Fri, 13 May 1994 08:32:16 +0000 |
| parents | 24426d7e14eb |
| children | b393834bab2a |
| rev | line source |
|---|---|
| 5503 | 1 /* MS-DOS specific C utilities. Coded by Morten Welinder 1993 |
| 2 Copyright (C) 1993 Free Software Foundation, Inc. | |
| 3 | |
| 4 This file is part of GNU Emacs. | |
| 5 | |
| 6 GNU Emacs is free software; you can redistribute it and/or modify | |
| 7 it under the terms of the GNU General Public License as published by | |
| 8 the Free Software Foundation; either version 1, or (at your option) | |
| 9 any later version. | |
| 10 | |
| 11 GNU Emacs is distributed in the hope that it will be useful, | |
| 12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 GNU General Public License for more details. | |
| 15 | |
| 16 You should have received a copy of the GNU General Public License | |
| 17 along with GNU Emacs; see the file COPYING. If not, write to | |
| 18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
| 19 | |
| 20 /* Note: some of the stuff here was taken from end of sysdep.c in demacs. */ | |
| 21 | |
| 5980 | 22 #include <config.h> |
| 5503 | 23 |
| 24 #ifdef MSDOS | |
| 25 #include "lisp.h" | |
| 26 #include <stdio.h> | |
| 27 #include <stdlib.h> | |
| 28 #include <sys/param.h> | |
| 29 #include <sys/time.h> | |
| 30 #include <dos.h> | |
| 31 #include "dosfns.h" | |
| 32 #include "msdos.h" | |
| 33 #include "systime.h" | |
| 34 #include "termhooks.h" | |
| 35 #include "frame.h" | |
| 36 #include <go32.h> | |
| 37 #include <pc.h> | |
| 38 #include <ctype.h> | |
| 39 /* #include <process.h> */ | |
| 40 /* Damn that local process.h! Instead we can define P_WAIT ourselves. */ | |
| 41 #define P_WAIT 1 | |
| 42 | |
| 43 static int break_stat; /* BREAK check mode status. */ | |
| 44 static int stdin_stat; /* stdin IOCTL status. */ | |
| 45 static int extended_kbd; /* 101 (102) keyboard present. */ | |
| 46 | |
| 47 int have_mouse; /* Mouse present? */ | |
| 48 static int mouse_last_x; | |
| 49 static int mouse_last_y; | |
| 50 | |
| 51 /* Turn off Dos' Ctrl-C checking and inhibit interpretation of control chars | |
| 52 by Dos. Determine the keyboard type. */ | |
| 53 int | |
| 54 dos_ttraw () | |
| 55 { | |
| 56 union REGS inregs, outregs; | |
| 57 | |
| 58 inregs.h.ah = 0xc0; | |
| 59 int86 (0x15, &inregs, &outregs); | |
| 60 extended_kbd = (!outregs.x.cflag) && (outregs.h.ah == 0); | |
| 61 | |
| 62 break_stat = getcbrk (); | |
| 63 setcbrk (0); | |
| 64 install_ctrl_break_check (); | |
|
7273
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
65 have_mouse = mouse_init1 (); |
| 5503 | 66 |
| 67 inregs.x.ax = 0x4400; /* Get IOCTL status. */ | |
| 68 inregs.x.bx = 0x00; /* 0 = stdin. */ | |
| 69 intdos (&inregs, &outregs); | |
| 70 stdin_stat = outregs.h.dl; | |
| 71 | |
| 72 inregs.x.dx = (outregs.x.dx | 0x0020) & 0x0027; /* raw mode */ | |
| 73 inregs.h.al = 0x01; | |
| 74 intdos (&inregs, &outregs); | |
| 75 return !outregs.x.cflag; | |
| 76 } | |
| 77 | |
| 78 /* Restore status of standard input and Ctrl-C checking. */ | |
| 79 int | |
| 80 dos_ttcooked () | |
| 81 { | |
| 82 union REGS inregs, outregs; | |
| 83 | |
| 84 setcbrk (break_stat); | |
|
7273
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
85 if (have_mouse) mouse_off (); |
| 5503 | 86 |
| 87 inregs.x.ax = 0x4401; /* Set IOCTL status. */ | |
| 88 inregs.x.bx = 0x00; /* 0 = stdin. */ | |
| 89 inregs.x.dx = stdin_stat; | |
| 90 intdos (&inregs, &outregs); | |
| 91 return !outregs.x.cflag; | |
| 92 } | |
| 93 | |
| 94 static unsigned short | |
| 95 ibmpc_translate_map[] = | |
| 96 { | |
| 97 /* --------------- 00 to 0f --------------- */ | |
| 98 0, /* Ctrl Break */ | |
| 99 0xff1b, /* Escape */ | |
| 100 0xffb1, /* Keypad 1 */ | |
| 101 0xffb2, /* Keypad 2 */ | |
| 102 0xffb3, /* Keypad 3 */ | |
| 103 0xffb4, /* Keypad 4 */ | |
| 104 0xffb5, /* Keypad 5 */ | |
| 105 0xffb6, /* Keypad 6 */ | |
| 106 0xffb7, /* Keypad 7 */ | |
| 107 0xffb8, /* Keypad 8 */ | |
| 108 0xffb9, /* Keypad 9 */ | |
| 109 0xffb0, /* Keypad 0 */ | |
| 110 '-', '=', | |
| 111 0xff08, /* Backspace */ | |
| 112 0xff74, /* (Shift) Tab [Tab doesn't use this table] */ | |
| 113 | |
| 114 /* --------------- 10 to 1f --------------- */ | |
| 115 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', | |
| 116 0xff8d, /* Keypad Enter */ | |
| 117 0, /* Ctrl */ | |
| 118 'a', 's', | |
| 119 | |
| 120 /* --------------- 20 to 2f --------------- */ | |
| 121 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', | |
| 122 0, /* Left shift */ | |
| 123 '\\', 'z', 'x', 'c', 'v', | |
| 124 | |
| 125 /* --------------- 30 to 3f --------------- */ | |
| 126 'b', 'n', 'm', ',', '.', | |
| 127 0xffaf, /* Grey / */ | |
| 128 0, /* Right shift */ | |
| 129 0xffaa, /* Grey * */ | |
| 130 0, /* Alt */ | |
| 131 ' ', | |
| 132 0, /* Caps Lock */ | |
| 133 0xffbe, /* F1 */ | |
| 134 0xffbf, /* F2 */ | |
| 135 0xffc0, /* F3 */ | |
| 136 0xffc1, /* F4 */ | |
| 137 0xffc2, /* F5 */ | |
| 138 | |
| 139 /* --------------- 40 to 4f --------------- */ | |
| 140 0xffc3, /* F6 */ | |
| 141 0xffc4, /* F7 */ | |
| 142 0xffc5, /* F8 */ | |
| 143 0xffc6, /* F9 */ | |
| 144 0xffc7, /* F10 */ | |
| 145 0, /* Num Lock */ | |
| 146 0, /* Scroll Lock */ | |
| 147 0xff50, /* Home */ | |
| 148 0xff52, /* Up */ | |
| 149 0xff55, /* Page Up */ | |
| 150 0xffad, /* Grey - */ | |
| 151 0xff51, /* Left */ | |
| 152 0xffb5, /* Keypad 5 */ | |
| 153 0xff53, /* Right */ | |
| 154 0xffab, /* Grey + */ | |
| 155 0xff57, /* End */ | |
| 156 | |
| 157 /* --------------- 50 to 5f --------------- */ | |
| 158 0xff54, /* Down */ | |
| 159 0xff56, /* Page Down */ | |
| 160 0xff63, /* Insert */ | |
| 161 0xffff, /* Delete */ | |
| 162 0xffbe, /* (Shift) F1 */ | |
| 163 0xffbf, /* (Shift) F2 */ | |
| 164 0xffc0, /* (Shift) F3 */ | |
| 165 0xffc1, /* (Shift) F4 */ | |
| 166 0xffc2, /* (Shift) F5 */ | |
| 167 0xffc3, /* (Shift) F6 */ | |
| 168 0xffc4, /* (Shift) F7 */ | |
| 169 0xffc5, /* (Shift) F8 */ | |
| 170 0xffc6, /* (Shift) F9 */ | |
| 171 0xffc7, /* (Shift) F10 */ | |
| 172 0xffbe, /* (Ctrl) F1 */ | |
| 173 0xffbf, /* (Ctrl) F2 */ | |
| 174 | |
| 175 /* --------------- 60 to 6f --------------- */ | |
| 176 0xffc0, /* (Ctrl) F3 */ | |
| 177 0xffc1, /* (Ctrl) F4 */ | |
| 178 0xffc2, /* (Ctrl) F5 */ | |
| 179 0xffc3, /* (Ctrl) F6 */ | |
| 180 0xffc4, /* (Ctrl) F7 */ | |
| 181 0xffc5, /* (Ctrl) F8 */ | |
| 182 0xffc6, /* (Ctrl) F9 */ | |
| 183 0xffc7, /* (Ctrl) F10 */ | |
| 184 0xffbe, /* (Alt) F1 */ | |
| 185 0xffbf, /* (Alt) F2 */ | |
| 186 0xffc0, /* (Alt) F3 */ | |
| 187 0xffc1, /* (Alt) F4 */ | |
| 188 0xffc2, /* (Alt) F5 */ | |
| 189 0xffc3, /* (Alt) F6 */ | |
| 190 0xffc4, /* (Alt) F7 */ | |
| 191 0xffc5, /* (Alt) F8 */ | |
| 192 | |
| 193 /* --------------- 70 to 7f --------------- */ | |
| 194 0xffc6, /* (Alt) F9 */ | |
| 195 0xffc7, /* (Alt) F10 */ | |
| 196 0xff6d, /* (Ctrl) Sys Rq */ | |
| 197 0xff51, /* (Ctrl) Left */ | |
| 198 0xff53, /* (Ctrl) Right */ | |
| 199 0xff57, /* (Ctrl) End */ | |
| 200 0xff56, /* (Ctrl) Page Down */ | |
| 201 0xff50, /* (Ctrl) Home */ | |
| 202 '1', '2', '3', '4', '5', '6', '7', '8', /* (Alt) */ | |
| 203 | |
| 204 /* --------------- 80 to 8f --------------- */ | |
| 205 '9', '0', '-', '=', /* (Alt) */ | |
| 206 0xff55, /* (Ctrl) Page Up */ | |
| 207 0xffc8, /* F11 */ | |
| 208 0xffc9, /* F12 */ | |
| 209 0xffc8, /* (Shift) F11 */ | |
| 210 0xffc9, /* (Shift) F12 */ | |
| 211 0xffc8, /* (Ctrl) F11 */ | |
| 212 0xffc9, /* (Ctrl) F12 */ | |
| 213 0xffc8, /* (Alt) F11 */ | |
| 214 0xffc9, /* (Alt) F12 */ | |
| 215 0xff52, /* (Ctrl) Up */ | |
| 216 0xffae, /* (Ctrl) Grey - */ | |
| 217 0xffb5, /* (Ctrl) Keypad 5 */ | |
| 218 | |
| 219 /* --------------- 90 to 9f --------------- */ | |
| 220 0xffab, /* (Ctrl) Grey + */ | |
| 221 0xff54, /* (Ctrl) Down */ | |
| 222 0xff63, /* (Ctrl) Insert */ | |
| 223 0xffff, /* (Ctrl) Delete */ | |
| 224 0xff09, /* (Ctrl) Tab */ | |
| 225 0xffaf, /* (Ctrl) Grey / */ | |
| 226 0xffaa, /* (Ctrl) Grey * */ | |
| 227 0xff50, /* (Alt) Home */ | |
| 228 0xff52, /* (Alt) Up */ | |
| 229 0xff55, /* (Alt) Page Up */ | |
| 230 0, /* NO KEY */ | |
| 231 0xff51, /* (Alt) Left */ | |
| 232 0, /* NO KEY */ | |
| 233 0xff53, /* (Alt) Right */ | |
| 234 0, /* NO KEY */ | |
| 235 0xff57, /* (Alt) End */ | |
| 236 | |
| 237 /* --------------- a0 to af --------------- */ | |
| 238 0xff54, /* (Alt) Down */ | |
| 239 0xff56, /* (Alt) Page Down */ | |
| 240 0xff63, /* (Alt) Insert */ | |
| 241 0xffff, /* (Alt) Delete */ | |
| 242 0xffaf, /* (Alt) Grey / */ | |
| 243 0xff09, /* (Alt) Tab */ | |
| 244 0xff0d /* (Alt) Enter */ | |
| 245 }; | |
| 246 | |
| 247 /* Get a char from keyboard. Function keys are put into the event queue. */ | |
| 248 static int | |
| 249 dos_rawgetc () | |
| 250 { | |
| 251 struct input_event event; | |
| 252 struct timeval tv; | |
| 253 union REGS regs; | |
| 254 int ctrl_p, alt_p, shift_p; | |
| 255 | |
| 256 /* Calculate modifier bits */ | |
| 257 regs.h.ah = extended_kbd ? 0x12 : 0x02; | |
| 258 int86 (0x16, ®s, ®s); | |
| 259 ctrl_p = ((regs.h.al & 4) != 0); | |
| 260 shift_p = ((regs.h.al & 3) != 0); | |
| 261 alt_p = ((extended_kbd ? (regs.h.ah & 2) : (regs.h.al & 8)) != 0); | |
| 262 | |
| 263 while (kbhit ()) | |
| 264 { | |
| 265 union REGS regs; | |
| 266 register unsigned char c; | |
| 267 int sc, code; | |
| 268 | |
| 269 regs.h.ah = extended_kbd ? 0x10 : 0x00; | |
| 270 int86 (0x16, ®s, ®s); | |
| 271 c = regs.h.al; | |
| 272 sc = regs.h.ah; | |
| 273 | |
| 274 /* Determine from the scan code if a keypad key was pressed. */ | |
| 275 if (c >= '0' && c <= '9' && sc > 0xb) | |
| 276 sc = (c == '0') ? 0xb : (c - '0' + 1), c = 0; | |
| 277 else if (sc == 0xe0) | |
| 278 { | |
| 279 switch (c) | |
| 280 { | |
| 281 case 10: /* Ctrl Enter */ | |
| 282 case 13: | |
| 283 sc = 0x1c; | |
| 284 break; | |
| 285 case '.': /* Decimal point or decimal comma */ | |
| 286 case ',': | |
| 287 sc = 0x53; | |
| 288 break; | |
| 289 case '/': | |
| 290 sc = 0x35; | |
| 291 break; | |
| 292 default: | |
| 293 sc = 0; | |
| 294 }; | |
| 295 c = 0; | |
| 296 } | |
| 297 | |
| 298 if (c == 0 | |
| 299 || c == ' ' | |
| 300 || alt_p | |
| 301 || (ctrl_p && shift_p) | |
| 302 || (c == 0xe0 && sc != 0) /* Pseudo-key */ | |
| 303 || sc == 0x37 /* Grey * */ | |
| 304 || sc == 0x4a /* Grey - */ | |
| 305 || sc == 0x4e /* Grey + */ | |
| 306 || sc == 0x0e) /* Back space *key*, not Ctrl-h */ | |
| 307 { | |
| 308 if (sc >= (sizeof (ibmpc_translate_map) / sizeof (short))) | |
| 309 code = 0; | |
| 310 else | |
| 311 code = ibmpc_translate_map[sc]; | |
| 312 if (code != 0) | |
| 313 { | |
| 314 if (code >= 0x100) | |
| 315 { | |
| 316 event.kind = non_ascii_keystroke; | |
|
7273
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
317 event.code = (code & 0xff) + 0xff00; |
| 5503 | 318 } |
| 319 else | |
| 320 { | |
| 321 /* Don't return S- if we don't have to. */ | |
| 322 if (code >= 'a' && code <= 'z') | |
| 323 { | |
| 324 c = shift_p ? toupper (code) : code; | |
| 325 shift_p = 0; | |
| 326 } | |
| 327 else | |
| 328 if (c == 0) c = code; | |
| 329 event.kind = ascii_keystroke; | |
| 330 event.code = c; | |
| 331 } | |
| 332 event.modifiers | |
|
7273
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
333 = (shift_p ? shift_modifier : 0 |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
334 + (ctrl_p ? ctrl_modifier : 0 |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
335 + (alt_p ? meta_modifier : 0))); |
| 5503 | 336 /* EMACS == Enter Meta Alt Control Shift */ |
| 337 event.frame_or_window = selected_frame; | |
| 338 gettimeofday (&tv, NULL); | |
| 339 event.timestamp = tv.tv_usec; | |
| 340 kbd_buffer_store_event (&event); | |
| 341 } | |
| 342 } else | |
| 343 return c; | |
| 344 } | |
| 345 | |
| 346 if (have_mouse) | |
| 347 { | |
| 348 int but, press, x, y, ok; | |
| 349 | |
| 350 /* Check for mouse movement *before* buttons. */ | |
|
7273
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
351 mouse_check_moved (); |
| 5503 | 352 |
| 353 for (but = 0; but < NUM_MOUSE_BUTTONS; but++) | |
| 354 for (press = 0; press < 2; press++) | |
| 355 { | |
| 356 if (press) | |
|
7273
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
357 ok = mouse_pressed (but, &x, &y); |
| 5503 | 358 else |
|
7273
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
359 ok = mouse_released (but, &x, &y); |
| 5503 | 360 if (ok) |
| 361 { | |
| 362 event.kind = mouse_click; | |
| 363 event.code = but; | |
| 364 event.modifiers | |
|
7273
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
365 = (shift_p ? shift_modifier : 0 |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
366 + (ctrl_p ? ctrl_modifier : 0 |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
367 + (alt_p ? meta_modifier : 0 |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
368 + (press ? down_modifier : up_modifier)))); |
| 5503 | 369 event.x = x; |
| 370 event.y = y; | |
| 371 event.frame_or_window = selected_frame; | |
| 372 gettimeofday (&tv, NULL); | |
| 373 event.timestamp = tv.tv_usec; | |
| 374 kbd_buffer_store_event (&event); | |
| 375 } | |
| 376 } | |
| 377 } | |
| 378 | |
| 379 return -1; | |
| 380 } | |
| 381 | |
| 382 static int prev_get_char = -1; | |
| 383 | |
| 384 /* Return 1 if a key is ready to be read without suspending execution. */ | |
| 385 dos_keysns () | |
| 386 { | |
| 387 if (prev_get_char != -1) | |
| 388 return 1; | |
| 389 else | |
| 390 return ((prev_get_char = dos_rawgetc ()) != -1); | |
| 391 } | |
| 392 | |
| 393 /* Read a key. Return -1 if no key is ready. */ | |
| 394 dos_keyread () | |
| 395 { | |
| 396 if (prev_get_char != -1) | |
| 397 { | |
| 398 int c = prev_get_char; | |
| 399 prev_get_char = -1; | |
| 400 return c; | |
| 401 } | |
| 402 else | |
| 403 return dos_rawgetc (); | |
| 404 } | |
| 405 | |
| 406 /* Hostnames for a pc are not really funny, but they are used in change log | |
| 407 so we emulate the best we can. */ | |
| 408 gethostname (p, size) | |
| 409 char *p; | |
| 410 int size; | |
| 411 { | |
| 412 char *q = egetenv ("HOSTNAME"); | |
| 413 | |
| 414 if (!q) q = "pc"; | |
| 415 strcpy (p, q); | |
| 416 return 0; | |
| 417 } | |
| 418 | |
| 419 /* Destructively turn backslashes into slashes. */ | |
| 420 void | |
| 421 dostounix_filename (p) | |
| 422 register char *p; | |
| 423 { | |
| 424 while (*p) | |
| 425 { | |
| 426 if (*p == '\\') | |
| 427 *p = '/'; | |
| 428 p++; | |
| 429 } | |
| 430 } | |
| 431 | |
| 432 /* Destructively turn slashes into backslashes. */ | |
| 433 void | |
| 434 unixtodos_filename (p) | |
| 435 register char *p; | |
| 436 { | |
| 437 while (*p) | |
| 438 { | |
| 439 if (*p == '/') | |
| 440 *p = '\\'; | |
| 441 p++; | |
| 442 } | |
| 443 } | |
| 444 | |
| 445 /* Get the default directory for a given drive. 0=def, 1=A, 2=B, ... */ | |
| 446 int | |
| 447 getdefdir (drive, dst) | |
| 448 int drive; | |
| 449 char *dst; | |
| 450 { | |
| 451 union REGS regs; | |
| 452 | |
| 453 *dst++ = '/'; | |
| 454 regs.h.dl = drive; | |
| 455 regs.x.si = (int) dst; | |
| 456 regs.h.ah = 0x47; | |
| 457 intdos (®s, ®s); | |
| 458 return !regs.x.cflag; | |
| 459 } | |
| 460 | |
| 461 /* Remove all CR's that are followed by a LF. */ | |
| 462 int | |
| 463 crlf_to_lf (n, buf) | |
| 464 register int n; | |
| 465 register unsigned char *buf; | |
| 466 { | |
| 467 unsigned char *np = buf; | |
| 468 unsigned char *startp = buf; | |
| 469 unsigned char *endp = buf + n; | |
| 470 unsigned char c; | |
| 471 | |
| 472 if (n == 0) | |
| 473 return n; | |
| 474 while (buf < endp) | |
| 475 { | |
| 476 if (*buf == 0x0d) | |
| 477 { | |
| 478 if (*(++buf) != 0x0a) | |
| 479 *np++ = 0x0d; | |
| 480 } | |
| 481 else | |
| 482 *np++ = *buf++; | |
| 483 } | |
| 484 return np - startp; | |
| 485 } | |
| 486 | |
| 487 | |
| 488 /* Run command as specified by ARGV in directory DIR. | |
| 489 The command is run with input from TEMPIN and output to file TEMPOUT. */ | |
| 490 int | |
| 491 run_msdos_command (argv, dir, tempin, tempout) | |
| 492 unsigned char **argv; | |
| 493 Lisp_Object dir; | |
| 494 int tempin, tempout; | |
| 495 { | |
| 496 char *saveargv1, *saveargv2, **envv; | |
| 497 char oldwd[MAXPATHLEN + 1]; /* Fixed size is safe on MSDOS. */ | |
| 498 int msshell, result = -1; | |
| 499 int in, out, inbak, outbak, errbak; | |
| 500 Lisp_Object cmd; | |
| 501 | |
| 502 /* Get current directory as MSDOS cwd is not per-process. */ | |
| 503 getwd (oldwd); | |
| 504 | |
| 505 cmd = Ffile_name_nondirectory (build_string (argv[0])); | |
| 506 msshell = !NILP (Fmember (cmd, Fsymbol_value (intern ("msdos-shells")))) | |
| 507 && !strcmp ("-c", argv[1]); | |
| 508 if (msshell) | |
| 509 { | |
| 510 saveargv1 = argv[1]; | |
| 511 argv[1] = "/c"; | |
| 512 if (argv[2]) | |
| 513 { | |
| 514 saveargv2 = argv[2]; | |
| 515 unixtodos_filename (argv[2] = strdup (argv[2])); | |
| 516 } | |
| 517 } | |
| 518 | |
| 519 /* Build the environment array. */ | |
| 520 { | |
| 521 extern Lisp_Object Vprocess_environment; | |
|
6505
ce4fbb055f87
(run_msdos_command): Use assignment instead of initialization.
Karl Heuer <kwzh@gnu.org>
parents:
6056
diff
changeset
|
522 Lisp_Object tmp, lst; |
|
ce4fbb055f87
(run_msdos_command): Use assignment instead of initialization.
Karl Heuer <kwzh@gnu.org>
parents:
6056
diff
changeset
|
523 int i, len; |
|
ce4fbb055f87
(run_msdos_command): Use assignment instead of initialization.
Karl Heuer <kwzh@gnu.org>
parents:
6056
diff
changeset
|
524 |
|
ce4fbb055f87
(run_msdos_command): Use assignment instead of initialization.
Karl Heuer <kwzh@gnu.org>
parents:
6056
diff
changeset
|
525 lst = Vprocess_environment; |
|
ce4fbb055f87
(run_msdos_command): Use assignment instead of initialization.
Karl Heuer <kwzh@gnu.org>
parents:
6056
diff
changeset
|
526 len = XFASTINT (Flength (lst)); |
| 5503 | 527 |
| 528 envv = alloca ((len + 1) * sizeof (char *)); | |
| 529 for (i = 0; i < len; i++) | |
| 530 { | |
| 531 tmp = Fcar (lst); | |
| 532 lst = Fcdr (lst); | |
| 533 CHECK_STRING (tmp, 0); | |
| 534 envv[i] = alloca (XSTRING (tmp)->size + 1); | |
| 535 strcpy (envv[i], XSTRING (tmp)->data); | |
| 536 } | |
| 537 envv[len] = (char *) 0; | |
| 538 } | |
| 539 | |
| 540 if (XTYPE (dir) == Lisp_String) | |
| 541 chdir (XSTRING (dir)->data); | |
| 542 inbak = dup (0); | |
| 543 outbak = dup (1); | |
| 544 errbak = dup (2); | |
| 545 if (inbak < 0 || outbak < 0 || errbak < 0) | |
| 546 goto done; /* Allocation might fail due to lack of descriptors. */ | |
| 547 dup2 (tempin, 0); | |
| 548 dup2 (tempout, 1); | |
| 549 dup2 (tempout, 2); | |
| 550 dos_ttcooked (); | |
| 551 result = spawnve (P_WAIT, argv[0], argv, envv); | |
| 552 dos_ttraw (); | |
| 553 dup2 (inbak, 0); | |
| 554 dup2 (outbak, 1); | |
| 555 dup2 (errbak, 2); | |
| 556 | |
| 557 done: | |
| 558 chdir (oldwd); | |
| 559 if (msshell) | |
| 560 { | |
| 561 argv[1] = saveargv1; | |
| 562 if (argv[2]) | |
| 563 { | |
| 564 free (argv[2]); | |
| 565 argv[2] = saveargv2; | |
| 566 } | |
| 567 } | |
| 568 return result; | |
| 569 } | |
| 570 | |
| 571 | |
| 572 croak (badfunc) | |
| 573 char *badfunc; | |
| 574 { | |
| 575 fprintf (stderr, "%s not yet implemented\r\n", badfunc); | |
| 576 reset_sys_modes (); | |
| 577 exit (1); | |
| 578 } | |
| 579 | |
| 580 /* A list of unimplemented functions that we silently ignore. */ | |
| 581 unsigned alarm (s) unsigned s; {} | |
| 582 fork () { return 0; } | |
| 583 int kill (x, y) int x, y; { return -1; } | |
| 584 nice (p) int p; {} | |
| 585 void volatile pause () {} | |
| 586 request_sigio () {} | |
| 587 setpgrp () {return 0; } | |
| 588 setpriority (x,y,z) int x,y,z; { return 0; } | |
| 589 sigsetmask (x) int x; { return 0; } | |
| 590 unrequest_sigio () {} | |
| 591 | |
| 592 #ifdef chdir | |
| 593 #undef chdir | |
| 594 #endif | |
| 595 | |
| 596 int | |
| 597 sys_chdir (path) | |
| 598 const char* path; | |
| 599 { | |
| 600 int len = strlen (path); | |
| 601 char *tmp = (char *) alloca (len + 1); | |
| 602 /* Gotta do this extern here due to the corresponding #define: */ | |
| 603 extern int chdir (); | |
| 604 | |
| 605 if (*path && path[1] == ':' && (getdisk () != tolower (path[0]) - 'a')) | |
| 606 setdisk (tolower (path[0]) - 'a'); | |
| 607 | |
| 608 strcpy (tmp, path); | |
| 609 if (strcmp (path, "/") && strcmp (path + 1, ":/") && (path[len - 1] == '/')) | |
| 610 tmp[len - 1] = 0; | |
| 611 return chdir (tmp); | |
| 612 } | |
| 613 | |
| 614 /* Sleep SECS. If KBDOK also return immediately if a key is pressed. */ | |
| 615 void | |
| 616 sleep_or_kbd_hit (secs, kbdok) | |
| 617 int secs, kbdok; | |
| 618 { | |
| 619 long clnow, clthen; | |
| 620 struct timeval t; | |
| 621 | |
| 622 gettimeofday (&t, NULL); | |
| 623 clnow = t.tv_sec * 100 + t.tv_usec / 10000; | |
| 624 clthen = clnow + (100 * secs); | |
| 625 | |
| 626 do | |
| 627 { | |
| 628 gettimeofday (&t, NULL); | |
| 629 clnow = t.tv_sec * 100 + t.tv_usec / 10000; | |
| 630 if (kbdok && detect_input_pending ()) | |
| 631 return; | |
| 632 } | |
| 633 while (clnow < clthen); | |
| 634 } | |
| 635 | |
| 636 /* Define a lot of environment variables if not already defined. Don't | |
| 637 remove anything unless you know what you're doing -- lots of code will | |
| 638 break if one or more of these are missing. */ | |
| 639 void | |
| 640 init_environment (argc, argv, skip_args) | |
| 641 int argc; | |
| 642 char **argv; | |
| 643 int skip_args; | |
| 644 { | |
| 645 char *s, *t; | |
| 646 | |
| 647 /* We default HOME to the directory from which Emacs was started, but with | |
| 648 a "/bin" suffix removed. */ | |
| 649 s = argv[0]; | |
| 650 t = alloca (strlen (s) + 1); | |
| 651 strcpy (t, s); | |
| 652 s = t + strlen (t); | |
| 653 while (s != t && *s != '/' && *s != ':') s--; | |
| 654 if (s == t) | |
| 655 t = "c:/emacs"; /* When run under debug32. */ | |
| 656 else | |
| 657 { | |
| 658 if (*s == ':') s++; | |
| 659 *s = 0; | |
| 660 if (s - 4 >= t && strcmp (s - 4, "/bin") == 0) | |
| 661 s[strlen (s) - 4] = 0; | |
| 662 } | |
| 663 setenv ("HOME", t, 0); | |
| 664 | |
| 665 /* We set EMACSPATH to ~/bin (expanded) */ | |
| 666 s = getenv ("HOME"); | |
| 667 t = strcpy (alloca (strlen (s) + 6), s); | |
| 668 if (s[strlen (s) - 1] != '/') strcat (t, "/"); | |
| 669 strcat (t, "bin"); | |
| 670 setenv ("EMACSPATH", t, 0); | |
| 671 | |
| 672 /* I don't expect anybody to ever use other terminals so the internal | |
| 673 terminal is the default. */ | |
| 674 setenv ("TERM", "internal", 0); | |
| 675 | |
| 676 /* SHELL is a bit tricky -- COMSPEC is the closest we come, but we must | |
| 677 downcase it and mirror the backslashes. */ | |
| 678 s = getenv ("COMSPEC"); | |
| 679 if (!s) s = "c:/command.com"; | |
| 680 t = alloca (strlen (s) + 1); | |
| 681 strcpy (t, s); | |
| 682 strlwr (t); | |
| 683 dostounix_filename (t); | |
| 684 setenv ("SHELL", t, 0); | |
| 685 | |
| 686 /* PATH is also downcased and backslashes mirrored. */ | |
| 687 s = getenv ("PATH"); | |
| 688 if (!s) s = ""; | |
| 689 t = alloca (strlen (s) + 3); | |
| 690 /* Current directory is always considered part of MsDos's path but it is | |
| 691 not normally mentioned. Now it is. */ | |
| 692 strcat (strcpy (t, ".;"), s); | |
| 693 strlwr (t); | |
| 694 dostounix_filename (t); /* Not a single file name, but this should work. */ | |
| 695 setenv ("PATH", t, 1); | |
| 696 | |
| 697 /* In some sense all dos users have root privileges, so... */ | |
| 698 setenv ("USER", "root", 0); | |
| 699 setenv ("NAME", getenv ("USER"), 0); | |
| 700 | |
| 701 /* Time zone determined from country code. To make this possible, the | |
| 702 country code may not span more than one time zone. In other words, | |
| 703 in the USA, you lose. */ | |
| 704 switch (dos_country_code) | |
| 705 { | |
| 706 case 31: /* Belgium */ | |
| 707 case 32: /* The Netherlands */ | |
| 708 case 33: /* France */ | |
| 709 case 34: /* Spain */ | |
| 710 case 36: /* Hungary */ | |
| 711 case 38: /* Yugoslavia (or what's left of it?) */ | |
| 712 case 39: /* Italy */ | |
| 713 case 41: /* Switzerland */ | |
| 714 case 42: /* Tjekia */ | |
| 715 case 45: /* Denmark */ | |
| 716 case 46: /* Sweden */ | |
| 717 case 47: /* Norway */ | |
| 718 case 48: /* Poland */ | |
| 719 case 49: /* Germany */ | |
| 720 /* Daylight saving from last Sunday in March to last Sunday in | |
| 721 September, both at 2AM. */ | |
| 722 setenv ("TZ", "MET-01METDST-02,M3.5.0/02:00,M9.5.0/02:00", 0); | |
| 723 break; | |
| 724 case 44: /* United Kingdom */ | |
| 725 case 351: /* Portugal */ | |
| 726 case 354: /* Iceland */ | |
| 727 setenv ("TZ", "GMT+00", 0); | |
| 728 break; | |
| 729 case 81: /* Japan */ | |
| 730 case 82: /* Korea */ | |
| 731 setenv ("TZ", "???-09", 0); | |
| 732 break; | |
| 733 case 90: /* Turkey */ | |
| 734 case 358: /* Finland */ | |
| 735 case 972: /* Israel */ | |
| 736 setenv ("TZ", "EET-02", 0); | |
| 737 break; | |
| 738 } | |
| 739 tzset (); | |
| 740 } | |
| 741 | |
| 742 /* Flash the screen as a substitute for BEEPs. */ | |
| 743 | |
| 744 static unsigned char _xorattr; | |
| 745 | |
|
7273
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
746 static void |
| 5503 | 747 visible_bell (xorattr) |
| 748 unsigned char xorattr; | |
| 749 { | |
| 750 _xorattr = xorattr; | |
|
7273
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
751 asm volatile |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
752 (" pushl %eax |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
753 pushl %ebx |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
754 pushl %ecx |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
755 pushl %edx |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
756 movl $1,%edx |
| 5503 | 757 visible_bell_0: |
|
7273
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
758 call _ScreenRows |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
759 pushl %eax |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
760 call _ScreenCols |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
761 pushl %eax |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
762 movl _ScreenPrimary,%eax |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
763 call dosmemsetup |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
764 movl %eax,%ebx |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
765 popl %ecx |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
766 popl %eax |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
767 imull %eax,%ecx |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
768 movb (__xorattr),%al |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
769 incl %ebx |
| 5503 | 770 visible_bell_1: |
|
7273
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
771 xorb %al,%gs:(%ebx) |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
772 addl $2,%ebx |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
773 decl %ecx |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
774 jne visible_bell_1 |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
775 decl %edx |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
776 jne visible_bell_3 |
| 5503 | 777 visible_bell_2: |
|
7273
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
778 movzwl %ax,%eax |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
779 movzwl %ax,%eax |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
780 movzwl %ax,%eax |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
781 movzwl %ax,%eax |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
782 decw %cx |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
783 jne visible_bell_2 |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
784 jmp visible_bell_0 |
| 5503 | 785 visible_bell_3: |
|
7273
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
786 popl %edx |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
787 popl %ecx |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
788 popl %ebx |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
789 popl %eax"); |
| 5503 | 790 } |
| 791 | |
| 792 static int internal_terminal = 0; | |
| 793 #undef fflush | |
| 794 | |
| 795 int | |
| 796 internal_flush (f) | |
| 797 FILE *f; | |
| 798 { | |
| 799 static int x; | |
| 800 static int y; | |
| 801 char c, *cp; | |
| 802 int count, i; | |
| 803 | |
| 804 if (internal_terminal && f == stdout) | |
| 805 { | |
|
7273
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
806 if (have_mouse) mouse_off (); |
| 5503 | 807 cp = stdout->_base; |
| 808 count = stdout->_ptr - stdout->_base; | |
| 809 while (count > 0) | |
| 810 { | |
| 811 switch (c = *cp++) | |
| 812 { | |
| 813 case 27: | |
| 814 switch (*cp++) | |
| 815 { | |
| 816 case '@': | |
| 817 y = *cp++; | |
| 818 x = *cp++; | |
| 819 count -= 4; | |
| 820 break; | |
| 821 case 'A': | |
| 822 ScreenAttrib = *cp++; | |
| 823 count -= 3; | |
| 824 break; | |
| 825 case 'B': | |
| 826 visible_bell (*cp++); | |
| 827 count -= 3; | |
| 828 break; | |
| 829 case 'C': | |
| 830 ScreenClear (); | |
| 831 x = y = 0; | |
| 832 count -= 2; | |
| 833 break; | |
| 834 case 'E': | |
| 835 for (i = ScreenCols () - 1; i >= x; i--) | |
| 836 ScreenPutChar (' ', ScreenAttrib, i, y); | |
| 837 count -= 2; | |
| 838 break; | |
| 839 case 'R': | |
| 840 x++; | |
| 841 count -= 2; | |
| 842 break; | |
| 843 case 'U': | |
| 844 y--; | |
| 845 count -= 2; | |
| 846 break; | |
| 847 case 'X': | |
| 848 ScreenAttrib ^= *cp++; | |
| 849 count -= 3; | |
| 850 break; | |
| 851 default: | |
| 852 count -= 2; | |
| 853 } | |
| 854 break; | |
| 855 case 8: | |
| 856 x--; | |
| 857 count--; | |
| 858 break; | |
| 859 case 13: | |
| 860 x = 0; | |
| 861 count--; | |
| 862 break; | |
| 863 case 10: | |
| 864 y++; | |
| 865 count--; | |
| 866 break; | |
| 867 default: | |
| 868 ScreenPutChar (c, ScreenAttrib, x++, y); | |
| 869 count--; | |
| 870 } | |
| 871 } | |
| 872 fpurge (stdout); | |
| 873 ScreenSetCursor (y, x); | |
|
7273
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
874 if (have_mouse) mouse_on (); |
| 5503 | 875 } |
| 876 else | |
| 877 /* This is a call to the original fflush. */ | |
| 878 fflush (f); | |
| 879 } | |
| 880 | |
| 881 /* Do we need the internal terminal? */ | |
| 882 void | |
| 883 internal_terminal_init () | |
| 884 { | |
| 885 char *term = getenv ("TERM"); | |
| 886 | |
| 887 internal_terminal | |
| 888 = (!noninteractive) && term && !strcmp (term, "internal"); | |
| 889 } | |
| 890 | |
| 891 /* These must be global. */ | |
| 892 static _go32_dpmi_seginfo ctrl_break_vector; | |
| 893 static _go32_dpmi_registers ctrl_break_regs; | |
| 894 static int ctrlbreakinstalled = 0; | |
| 895 | |
| 896 /* Interrupt level detection of Ctrl-Break. Don't do anything fancy here! */ | |
| 897 void | |
| 898 ctrl_break_func (regs) | |
| 899 _go32_dpmi_registers *regs; | |
| 900 { | |
| 901 Vquit_flag = Qt; | |
| 902 } | |
| 903 | |
| 904 void | |
| 905 install_ctrl_break_check () | |
| 906 { | |
| 907 if (!ctrlbreakinstalled) | |
| 908 { | |
| 909 /* Don't press Ctrl-Break if you don't have either DPMI or Emacs | |
| 910 was compiler with Djgpp 1.11 maintenance level 2 or later! */ | |
| 911 ctrlbreakinstalled = 1; | |
| 912 ctrl_break_vector.pm_offset = (int) ctrl_break_func; | |
| 913 _go32_dpmi_allocate_real_mode_callback_iret (&ctrl_break_vector, | |
| 914 &ctrl_break_regs); | |
| 915 _go32_dpmi_set_real_mode_interrupt_vector (0x1b, &ctrl_break_vector); | |
| 916 } | |
| 917 } | |
| 918 | |
| 919 | |
| 920 /* Mouse routines under devellopment follow. Coordinates are in screen | |
| 921 positions and zero based. Mouse buttons are numbered from left to | |
| 922 right and also zero based. */ | |
| 923 | |
| 924 static int mouse_button_translate[NUM_MOUSE_BUTTONS]; | |
| 925 static int mouse_button_count; | |
| 926 | |
| 927 void | |
| 928 mouse_init () | |
| 929 { | |
| 930 union REGS regs; | |
| 931 | |
| 932 regs.x.ax = 0x0007; | |
| 933 regs.x.cx = 0; | |
| 934 regs.x.dx = 8 * (ScreenCols () - 1); | |
| 935 int86 (0x33, ®s, ®s); | |
| 936 | |
| 937 regs.x.ax = 0x0008; | |
| 938 regs.x.cx = 0; | |
| 939 regs.x.dx = 8 * (ScreenRows () - 1); | |
| 940 int86 (0x33, ®s, ®s); | |
| 941 | |
| 942 mouse_moveto (ScreenCols () - 1, ScreenRows () - 1); | |
| 943 mouse_on (); | |
| 944 } | |
| 945 | |
| 946 void | |
| 947 mouse_on () | |
| 948 { | |
| 949 union REGS regs; | |
| 950 | |
| 951 regs.x.ax = 0x0001; | |
| 952 int86 (0x33, ®s, ®s); | |
| 953 } | |
| 954 | |
| 955 void | |
| 956 mouse_off () | |
| 957 { | |
| 958 union REGS regs; | |
| 959 | |
| 960 regs.x.ax = 0x0002; | |
| 961 int86 (0x33, ®s, ®s); | |
| 962 } | |
| 963 | |
| 964 void | |
| 965 mouse_moveto (x, y) | |
| 966 int x, y; | |
| 967 { | |
| 968 union REGS regs; | |
| 969 | |
| 970 regs.x.ax = 0x0004; | |
| 971 mouse_last_x = regs.x.cx = x * 8; | |
| 972 mouse_last_y = regs.x.dx = y * 8; | |
| 973 int86 (0x33, ®s, ®s); | |
| 974 } | |
| 975 | |
| 976 int | |
| 977 mouse_pressed (b, xp, yp) | |
| 978 int b, *xp, *yp; | |
| 979 { | |
| 980 union REGS regs; | |
| 981 | |
| 982 if (b >= mouse_button_count) | |
| 983 return 0; | |
| 984 regs.x.ax = 0x0005; | |
| 985 regs.x.bx = mouse_button_translate[b]; | |
| 986 int86 (0x33, ®s, ®s); | |
| 987 if (regs.x.bx) | |
| 988 *xp = regs.x.cx / 8, *yp = regs.x.dx /8; | |
| 989 return (regs.x.bx != 0); | |
| 990 } | |
| 991 | |
| 992 int | |
| 993 mouse_released (b, xp, yp) | |
| 994 int b, *xp, *yp; | |
| 995 { | |
| 996 union REGS regs; | |
| 997 | |
| 998 if (b >= mouse_button_count) | |
| 999 return 0; | |
| 1000 regs.x.ax = 0x0006; | |
| 1001 regs.x.bx = mouse_button_translate[b]; | |
| 1002 int86 (0x33, ®s, ®s); | |
| 1003 if (regs.x.bx) | |
| 1004 *xp = regs.x.cx / 8, *yp = regs.x.dx / 8; | |
| 1005 return (regs.x.bx != 0); | |
| 1006 } | |
| 1007 | |
| 1008 void | |
| 1009 mouse_get_pos (f, bar_window, part, x, y, time) | |
| 1010 FRAME_PTR *f; | |
| 1011 Lisp_Object *bar_window, *x, *y; | |
| 1012 enum scroll_bar_part *part; | |
| 1013 unsigned long *time; | |
| 1014 { | |
| 1015 union REGS regs; | |
| 1016 struct timeval tv; | |
| 1017 | |
| 1018 regs.x.ax = 0x0003; | |
| 1019 int86 (0x33, ®s, ®s); | |
| 1020 *f = selected_frame; | |
| 1021 *bar_window = Qnil; | |
| 1022 gettimeofday (&tv, NULL); | |
|
6056
afa75a0c15f8
(mouse_get_pos): Don't convert to glyph units.
Richard M. Stallman <rms@gnu.org>
parents:
5980
diff
changeset
|
1023 *x = make_number (regs.x.cx); |
|
afa75a0c15f8
(mouse_get_pos): Don't convert to glyph units.
Richard M. Stallman <rms@gnu.org>
parents:
5980
diff
changeset
|
1024 *y = make_number (regs.x.dx); |
| 5503 | 1025 *time = tv.tv_usec; |
| 1026 mouse_moved = 0; | |
| 1027 } | |
| 1028 | |
| 1029 void | |
| 1030 mouse_check_moved () | |
| 1031 { | |
| 1032 union REGS regs; | |
| 1033 | |
| 1034 regs.x.ax = 0x0003; | |
| 1035 int86 (0x33, ®s, ®s); | |
| 1036 if (regs.x.cx != mouse_last_x || regs.x.dx != mouse_last_y) | |
| 1037 { | |
| 1038 mouse_moved = 1; | |
| 1039 mouse_last_x = regs.x.cx; | |
| 1040 mouse_last_y = regs.x.dx; | |
| 1041 } | |
| 1042 } | |
| 1043 | |
| 1044 int | |
| 1045 mouse_init1 () | |
| 1046 { | |
| 1047 union REGS regs; | |
| 1048 int present; | |
| 1049 | |
| 1050 regs.x.ax = 0x0021; | |
| 1051 int86 (0x33, ®s, ®s); | |
| 1052 present = internal_terminal && (regs.x.ax & 0xffff) == 0xffff; | |
| 1053 if (present) | |
| 1054 { | |
| 1055 if (regs.x.bx == 3) | |
| 1056 { | |
| 1057 mouse_button_count = 3; | |
| 1058 mouse_button_translate[0] = 0; /* Left */ | |
| 1059 mouse_button_translate[1] = 2; /* Middle */ | |
| 1060 mouse_button_translate[2] = 1; /* Right */ | |
| 1061 } | |
| 1062 else | |
| 1063 { | |
| 1064 mouse_button_count = 2; | |
| 1065 mouse_button_translate[0] = 0; | |
| 1066 mouse_button_translate[1] = 1; | |
| 1067 } | |
| 1068 mouse_position_hook = &mouse_get_pos; | |
| 1069 mouse_init (); | |
| 1070 } | |
| 1071 return present; | |
| 1072 } | |
| 1073 | |
|
7273
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
1074 /* See xterm.c for more info. */ |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
1075 void |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
1076 pixel_to_glyph_coords (f, pix_x, pix_y, x, y, bounds, noclip) |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
1077 FRAME_PTR f; |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
1078 register int pix_x, pix_y; |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
1079 register int *x, *y; |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
1080 void /* XRectangle */ *bounds; |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
1081 int noclip; |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
1082 { |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
1083 if (bounds) abort (); |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
1084 |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
1085 /* Ignore clipping. */ |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
1086 |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
1087 *x = pix_x; |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
1088 *y = pix_y; |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
1089 } |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
1090 |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
1091 void |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
1092 glyph_to_pixel_coords (f, x, y, pix_x, pix_y) |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
1093 FRAME_PTR f; |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
1094 register int x, y; |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
1095 register int *pix_x, *pix_y; |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
1096 { |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
1097 *pix_x = x; |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
1098 *pix_y = y; |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
1099 } |
|
24426d7e14eb
Finish downcasing mouse_init1, mouse_off,
Richard M. Stallman <rms@gnu.org>
parents:
6505
diff
changeset
|
1100 |
| 5503 | 1101 #endif /* MSDOS */ |
