comparison src/keyboard.c @ 5513:d7770758acfd

(interrupt_signal) [MSDOS]: write explicit CRs since stdout has been made binary. Start at the top of the screen since the internal terminal otherwise will write "below the screen." [MSDOS]: #include <dos.h> and <time.h>, but not <sys/ioctl.h>. (read_avail_input) [MSDOS]: Work around `ioctl'. Also read through dos_keyread for better keyboard support. (interrupt_signal) [MSDOS]: Don't claim we can core dump. (kbd_buffer_store_event): Cast a pointer to avoid a compiler warning. (read_avail_input): Args to `kill' were backwards. (kbd_buffer_get_event): If deleting last frame, call Fkill_emacs. (modify_event_symbol): New arg NAME_ALIST. Allow SYMBOL_TABLE to be an alist. (Vvendor_key_alist): New variable. (syms_of_keyboard): Initialize it. (make_lispy_event): Handle vendor-specific keysyms. (lispy_function_keys): Delete `remove' and th HP keysyms. (read_avail_input): Turn O_NDELAY off on DGUX as on USG.
author Richard M. Stallman <rms@gnu.org>
date Sat, 08 Jan 1994 13:28:03 +0000
parents ca6521958577
children 8b688d642fc1
comparison
equal deleted inserted replaced
5512:9d548eeedc06 5513:d7770758acfd
38 #include "intervals.h" 38 #include "intervals.h"
39 #include "blockinput.h" 39 #include "blockinput.h"
40 #include <setjmp.h> 40 #include <setjmp.h>
41 #include <errno.h> 41 #include <errno.h>
42 42
43 #ifdef MSDOS
44 #include "msdos.h"
45 #include <time.h>
46 #else /* not MSDOS */
43 #ifndef VMS 47 #ifndef VMS
44 #include <sys/ioctl.h> 48 #include <sys/ioctl.h>
45 #endif 49 #endif
50 #endif /* not MSDOS */
46 51
47 #include "syssignal.h" 52 #include "syssignal.h"
48 #include "systty.h" 53 #include "systty.h"
49 #include "systime.h" 54 #include "systime.h"
50 55
116 int waiting_for_input; 121 int waiting_for_input;
117 122
118 /* True while displaying for echoing. Delays C-g throwing. */ 123 /* True while displaying for echoing. Delays C-g throwing. */
119 static int echoing; 124 static int echoing;
120 125
121 /* Nonzero means C-G should cause immediate error-signal. */ 126 /* Nonzero means C-g should cause immediate error-signal. */
122 int immediate_quit; 127 int immediate_quit;
123 128
124 /* Character to recognize as the help char. */ 129 /* Character to recognize as the help char. */
125 Lisp_Object Vhelp_char; 130 Lisp_Object Vhelp_char;
126 131
1963 if (FRAME_VISIBLE_P (f) || FRAME_ICONIFIED_P (f)) 1968 if (FRAME_VISIBLE_P (f) || FRAME_ICONIFIED_P (f))
1964 break; 1969 break;
1965 } 1970 }
1966 1971
1967 if (! CONSP (tail)) 1972 if (! CONSP (tail))
1968 kill (getpid (), SIGHUP); 1973 Fkill_emacs (Qnil);
1969 1974
1970 Fdelete_frame (event->frame_or_window, Qt); 1975 Fdelete_frame (event->frame_or_window, Qt);
1971 kbd_fetch_ptr = event + 1; 1976 kbd_fetch_ptr = event + 1;
1972 } 1977 }
1973 #endif 1978 #endif
2112 get_input_pending (&input_pending); 2117 get_input_pending (&input_pending);
2113 } 2118 }
2114 2119
2115 /* Caches for modify_event_symbol. */ 2120 /* Caches for modify_event_symbol. */
2116 static Lisp_Object accent_key_syms; 2121 static Lisp_Object accent_key_syms;
2122 static Lisp_Object vendor_key_syms;
2117 static Lisp_Object func_key_syms; 2123 static Lisp_Object func_key_syms;
2118 static Lisp_Object mouse_syms; 2124 static Lisp_Object mouse_syms;
2125
2126 Lisp_Object Vvendor_key_alist;
2119 2127
2120 /* This is a list of keysym codes for special "accent" characters. 2128 /* This is a list of keysym codes for special "accent" characters.
2121 It parallels lispy_accent_keys. */ 2129 It parallels lispy_accent_keys. */
2122 2130
2123 static int lispy_accent_codes[] = 2131 static int lispy_accent_codes[] =
2213 indexed by X Windows keysym values. */ 2221 indexed by X Windows keysym values. */
2214 static char *lispy_function_keys[] = 2222 static char *lispy_function_keys[] =
2215 { 2223 {
2216 /* X Keysym value */ 2224 /* X Keysym value */
2217 2225
2218 "remove", 0, 0, 0, 0, 0, 0, 0, /* 0xff00 */ 2226 0, 0, 0, 0, 0, 0, 0, 0, /* 0xff00 */
2219 "backspace", 2227 "backspace",
2220 "tab", 2228 "tab",
2221 "linefeed", 2229 "linefeed",
2222 "clear", 2230 "clear",
2223 0, 2231 0,
2254 "find", 2262 "find",
2255 "cancel", 2263 "cancel",
2256 "help", 2264 "help",
2257 "break", /* 0xff6b */ 2265 "break", /* 0xff6b */
2258 2266
2259 /* Here are some keys found mostly on HP keyboards. The X event 2267 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2260 handling code will strip bit 29, which flags vendor-specific
2261 keysyms. */
2262 "reset", /* 0x1000ff6c */
2263 "system",
2264 "user",
2265 "clearline",
2266 "insertline",
2267 "deleteline",
2268 "insertchar",
2269 "deletechar",
2270 "backtab",
2271 "kp-backtab", /* 0x1000ff75 */
2272 0, /* 0xff76 */ 2268 0, /* 0xff76 */
2273 0, 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff7f */ 2269 0, 0, 0, 0, 0, 0, 0, 0, "kp-numlock", /* 0xff7f */
2274 "kp-space", /* 0xff80 */ /* IsKeypadKey */ 2270 "kp-space", /* 0xff80 */ /* IsKeypadKey */
2275 0, 0, 0, 0, 0, 0, 0, 0, 2271 0, 0, 0, 0, 0, 0, 0, 0,
2276 "kp-tab", /* 0xff89 */ 2272 "kp-tab", /* 0xff89 */
2396 2392
2397 for (i = 0; i < sizeof (lispy_accent_codes) / sizeof (int); i++) 2393 for (i = 0; i < sizeof (lispy_accent_codes) / sizeof (int); i++)
2398 if (event->code == lispy_accent_codes[i]) 2394 if (event->code == lispy_accent_codes[i])
2399 return modify_event_symbol (i, 2395 return modify_event_symbol (i,
2400 event->modifiers, 2396 event->modifiers,
2401 Qfunction_key, 2397 Qfunction_key, Qnil,
2402 lispy_accent_keys, &accent_key_syms, 2398 lispy_accent_keys, &accent_key_syms,
2403 (sizeof (lispy_accent_keys) 2399 (sizeof (lispy_accent_keys)
2404 / sizeof (lispy_accent_keys[0]))); 2400 / sizeof (lispy_accent_keys[0])));
2405 2401
2402 /* Handle vendor-specific keysyms. */
2403 if (event->code & (1 << 28))
2404 {
2405 /* We need to use an alist rather than a vector as the cache
2406 since we can't make a vector long enuf. */
2407 if (NILP (vendor_key_syms))
2408 vendor_key_syms = Fcons (Qnil, Qnil);
2409 return modify_event_symbol (event->code & 0xffffff,
2410 event->modifiers,
2411 Qfunction_key, Vvendor_key_alist,
2412 0, &vendor_key_syms, 0xffffff);
2413 }
2414
2406 return modify_event_symbol (event->code - 0xff00, 2415 return modify_event_symbol (event->code - 0xff00,
2407 event->modifiers, 2416 event->modifiers,
2408 Qfunction_key, 2417 Qfunction_key, Qnil,
2409 lispy_function_keys, &func_key_syms, 2418 lispy_function_keys, &func_key_syms,
2410 (sizeof (lispy_function_keys) 2419 (sizeof (lispy_function_keys)
2411 / sizeof (lispy_function_keys[0]))); 2420 / sizeof (lispy_function_keys[0])));
2412 break; 2421 break;
2413 2422
2588 { 2597 {
2589 /* Get the symbol we should use for the mouse click. */ 2598 /* Get the symbol we should use for the mouse click. */
2590 Lisp_Object head 2599 Lisp_Object head
2591 = modify_event_symbol (button, 2600 = modify_event_symbol (button,
2592 event->modifiers, 2601 event->modifiers,
2593 Qmouse_click, 2602 Qmouse_click, Qnil,
2594 lispy_mouse_names, &mouse_syms, 2603 lispy_mouse_names, &mouse_syms,
2595 (sizeof (lispy_mouse_names) 2604 (sizeof (lispy_mouse_names)
2596 / sizeof (lispy_mouse_names[0]))); 2605 / sizeof (lispy_mouse_names[0])));
2597 2606
2598 if (event->modifiers & drag_modifier) 2607 if (event->modifiers & drag_modifier)
3026 3035
3027 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i] 3036 NAME_TABLE should point to an array of strings, such that NAME_TABLE[i]
3028 is the name of the i'th symbol. TABLE_SIZE is the number of elements 3037 is the name of the i'th symbol. TABLE_SIZE is the number of elements
3029 in the table. 3038 in the table.
3030 3039
3040 Alternatively, NAME_ALIST is an alist mapping codes into symbol names.
3041 NAME_ALIST is used if it is non-nil; otherwise NAME_TABLE is used.
3042
3031 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will 3043 SYMBOL_TABLE should be a pointer to a Lisp_Object whose value will
3032 persist between calls to modify_event_symbol that it can use to 3044 persist between calls to modify_event_symbol that it can use to
3033 store a cache of the symbols it's generated for this NAME_TABLE 3045 store a cache of the symbols it's generated for this NAME_TABLE
3034 before. 3046 before. The object stored there may be a vector or an alist.
3035 3047
3036 SYMBOL_NUM is the number of the base name we want from NAME_TABLE. 3048 SYMBOL_NUM is the number of the base name we want from NAME_TABLE.
3037 3049
3038 MODIFIERS is a set of modifier bits (as given in struct input_events) 3050 MODIFIERS is a set of modifier bits (as given in struct input_events)
3039 whose prefixes should be applied to the symbol name. 3051 whose prefixes should be applied to the symbol name.
3044 The symbols we create are supposed to have an 3056 The symbols we create are supposed to have an
3045 `event-symbol-elements' property, which lists the modifiers present 3057 `event-symbol-elements' property, which lists the modifiers present
3046 in the symbol's name. */ 3058 in the symbol's name. */
3047 3059
3048 static Lisp_Object 3060 static Lisp_Object
3049 modify_event_symbol (symbol_num, modifiers, symbol_kind, name_table, 3061 modify_event_symbol (symbol_num, modifiers, symbol_kind, name_alist,
3050 symbol_table, table_size) 3062 name_table, symbol_table, table_size)
3051 int symbol_num; 3063 int symbol_num;
3052 unsigned modifiers; 3064 unsigned modifiers;
3053 Lisp_Object symbol_kind; 3065 Lisp_Object symbol_kind;
3066 Lisp_Object name_alist;
3054 char **name_table; 3067 char **name_table;
3055 Lisp_Object *symbol_table; 3068 Lisp_Object *symbol_table;
3056 int table_size; 3069 int table_size;
3057 { 3070 {
3058 Lisp_Object *slot; 3071 Lisp_Object value;
3072 Lisp_Object symbol_int;
3073
3074 XSET (symbol_int, Lisp_Int, symbol_num);
3059 3075
3060 /* Is this a request for a valid symbol? */ 3076 /* Is this a request for a valid symbol? */
3061 if (symbol_num < 0 || symbol_num >= table_size) 3077 if (symbol_num < 0 || symbol_num >= table_size)
3062 abort (); 3078 abort ();
3079
3080 if (CONSP (*symbol_table))
3081 value = Fcdr (assq_no_quit (symbol_int, *symbol_table));
3063 3082
3064 /* If *symbol_table doesn't seem to be initialized properly, fix that. 3083 /* If *symbol_table doesn't seem to be initialized properly, fix that.
3065 *symbol_table should be a lisp vector TABLE_SIZE elements long, 3084 *symbol_table should be a lisp vector TABLE_SIZE elements long,
3066 where the Nth element is the symbol for NAME_TABLE[N], or nil if 3085 where the Nth element is the symbol for NAME_TABLE[N], or nil if
3067 we've never used that symbol before. */ 3086 we've never used that symbol before. */
3068 if (XTYPE (*symbol_table) != Lisp_Vector 3087 else
3069 || XVECTOR (*symbol_table)->size != table_size) 3088 {
3070 { 3089 if (! VECTORP (*symbol_table)
3071 Lisp_Object size; 3090 || XVECTOR (*symbol_table)->size != table_size)
3072 3091 {
3073 XFASTINT (size) = table_size; 3092 Lisp_Object size;
3074 *symbol_table = Fmake_vector (size, Qnil); 3093
3075 } 3094 XFASTINT (size) = table_size;
3076 3095 *symbol_table = Fmake_vector (size, Qnil);
3077 slot = & XVECTOR (*symbol_table)->contents[symbol_num]; 3096 }
3097
3098 value = XVECTOR (*symbol_table)->contents[symbol_num];
3099 }
3078 3100
3079 /* Have we already used this symbol before? */ 3101 /* Have we already used this symbol before? */
3080 if (NILP (*slot)) 3102 if (NILP (value))
3081 { 3103 {
3082 /* No; let's create it. */ 3104 /* No; let's create it. */
3083 if (name_table[symbol_num]) 3105 if (!NILP (name_alist))
3084 *slot = intern (name_table[symbol_num]); 3106 value = Fassq (symbol_int, name_alist);
3107 else if (name_table[symbol_num])
3108 value = intern (name_table[symbol_num]);
3085 else 3109 else
3086 { 3110 {
3087 char buf[20]; 3111 char buf[20];
3088 sprintf (buf, "key-%d", symbol_num); 3112 sprintf (buf, "key-%d", symbol_num);
3089 *slot = intern (buf); 3113 value = intern (buf);
3090 } 3114 }
3115
3116 if (CONSP (*symbol_table))
3117 *symbol_table = Fcons (value, *symbol_table);
3118 else
3119 XVECTOR (*symbol_table)->contents[symbol_num] = value;
3091 3120
3092 /* Fill in the cache entries for this symbol; this also 3121 /* Fill in the cache entries for this symbol; this also
3093 builds the Qevent_symbol_elements property, which the user 3122 builds the Qevent_symbol_elements property, which the user
3094 cares about. */ 3123 cares about. */
3095 apply_modifiers (modifiers & click_modifier, *slot); 3124 apply_modifiers (modifiers & click_modifier, value);
3096 Fput (*slot, Qevent_kind, symbol_kind); 3125 Fput (value, Qevent_kind, symbol_kind);
3097 } 3126 }
3098 3127
3099 /* Apply modifiers to that symbol. */ 3128 /* Apply modifiers to that symbol. */
3100 return apply_modifiers (modifiers, *slot); 3129 return apply_modifiers (modifiers, value);
3101 } 3130 }
3102 3131
3103 3132
3104 /* Store into *addr a value nonzero if terminal input chars are available. 3133 /* Store into *addr a value nonzero if terminal input chars are available.
3105 Serves the purpose of ioctl (0, FIONREAD, addr) 3134 Serves the purpose of ioctl (0, FIONREAD, addr)
3173 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than 3202 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
3174 the kbd_buffer can really hold. That may prevent loss 3203 the kbd_buffer can really hold. That may prevent loss
3175 of characters on some systems when input is stuffed at us. */ 3204 of characters on some systems when input is stuffed at us. */
3176 unsigned char cbuf[KBD_BUFFER_SIZE - 1]; 3205 unsigned char cbuf[KBD_BUFFER_SIZE - 1];
3177 3206
3207 #ifdef MSDOS
3208 nread = dos_keysns ();
3209 if (nread == 0) return 0;
3210 #else */ not MSDOS */
3178 #ifdef FIONREAD 3211 #ifdef FIONREAD
3179 /* Find out how much input is available. */ 3212 /* Find out how much input is available. */
3180 if (ioctl (0, FIONREAD, &nread) < 0) 3213 if (ioctl (0, FIONREAD, &nread) < 0)
3181 /* Formerly simply reported no input, but that sometimes led to 3214 /* Formerly simply reported no input, but that sometimes led to
3182 a failure of Emacs to terminate. 3215 a failure of Emacs to terminate.
3196 fcntl (fileno (stdin), F_SETFL, O_NDELAY); 3229 fcntl (fileno (stdin), F_SETFL, O_NDELAY);
3197 #else 3230 #else
3198 you lose; 3231 you lose;
3199 #endif 3232 #endif
3200 #endif 3233 #endif
3234 #endif /* not MSDOS */
3201 3235
3202 /* Now read; for one reason or another, this will not block. */ 3236 /* Now read; for one reason or another, this will not block. */
3203 while (1) 3237 while (1)
3204 { 3238 {
3239 #ifdef MSDOS
3240 cbuf[0] = dos_keyread();
3241 nread = 1;
3242 #else
3205 nread = read (fileno (stdin), cbuf, nread); 3243 nread = read (fileno (stdin), cbuf, nread);
3244 #endif
3206 #ifdef AIX 3245 #ifdef AIX
3207 /* The kernel sometimes fails to deliver SIGHUP for ptys. 3246 /* The kernel sometimes fails to deliver SIGHUP for ptys.
3208 This looks incorrect, but it isn't, because _BSD causes 3247 This looks incorrect, but it isn't, because _BSD causes
3209 O_NDELAY to be defined in fcntl.h as O_NONBLOCK, 3248 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
3210 and that causes a value other than 0 when there is no input. */ 3249 and that causes a value other than 0 when there is no input. */
3211 if (nread == 0) 3250 if (nread == 0)
3212 kill (SIGHUP, 0); 3251 kill (0, SIGHUP);
3213 #endif 3252 #endif
3214 /* This code is wrong, but at least it gets the right results. 3253 /* This code is wrong, but at least it gets the right results.
3215 Fix it for 19.23. */ 3254 Fix it for 19.23. */
3216 /* Retry the read if it is interrupted. */ 3255 /* Retry the read if it is interrupted. */
3217 if (nread >= 0 3256 if (nread >= 0
3257 #ifdef EFAULT
3218 || ! (errno == EAGAIN || errno == EFAULT 3258 || ! (errno == EAGAIN || errno == EFAULT
3259 #else
3260 || ! (errno == EAGAIN
3261 #endif
3219 #ifdef EBADSLT 3262 #ifdef EBADSLT
3220 || errno == EBADSLT 3263 || errno == EBADSLT
3221 #endif 3264 #endif
3222 )) 3265 ))
3223 break; 3266 break;
5105 to the original shell, ever. */ 5148 to the original shell, ever. */
5106 printf ("No support for stopping a process on this operating system;\n"); 5149 printf ("No support for stopping a process on this operating system;\n");
5107 printf ("you can continue or abort.\n"); 5150 printf ("you can continue or abort.\n");
5108 #endif /* not VMS */ 5151 #endif /* not VMS */
5109 #endif /* not SIGTSTP */ 5152 #endif /* not SIGTSTP */
5153 #ifdef MSDOS
5154 /* We must remain inside the screen area when the internal terminal
5155 is used. Note that [Enter] is not echoed by dos. */
5156 cursor_to (0, 0);
5157 #endif
5110 printf ("Auto-save? (y or n) "); 5158 printf ("Auto-save? (y or n) ");
5111 fflush (stdout); 5159 fflush (stdout);
5112 if (((c = getchar ()) & ~040) == 'Y') 5160 if (((c = getchar ()) & ~040) == 'Y')
5113 { 5161 {
5114 Fdo_auto_save (Qt, Qnil); 5162 Fdo_auto_save (Qt, Qnil);
5163 #ifdef MSDOS
5164 printf ("\r\nAuto-save done");
5165 #else /* not MSDOS */
5115 printf ("Auto-save done\n"); 5166 printf ("Auto-save done\n");
5167 #endif /* not MSDOS */
5116 } 5168 }
5117 while (c != '\n') c = getchar (); 5169 while (c != '\n') c = getchar ();
5170 #ifdef MSDOS
5171 printf ("\r\nAbort? (y or n) ");
5172 #else /* not MSDOS */
5118 #ifdef VMS 5173 #ifdef VMS
5119 printf ("Abort (and enter debugger)? (y or n) "); 5174 printf ("Abort (and enter debugger)? (y or n) ");
5120 #else /* not VMS */ 5175 #else /* not VMS */
5121 printf ("Abort (and dump core)? (y or n) "); 5176 printf ("Abort (and dump core)? (y or n) ");
5122 #endif /* not VMS */ 5177 #endif /* not VMS */
5178 #endif /* not MSDOS */
5123 fflush (stdout); 5179 fflush (stdout);
5124 if (((c = getchar ()) & ~040) == 'Y') 5180 if (((c = getchar ()) & ~040) == 'Y')
5125 abort (); 5181 abort ();
5126 while (c != '\n') c = getchar (); 5182 while (c != '\n') c = getchar ();
5183 #ifdef MSDOS
5184 printf ("\r\nContinuing...\r\n");
5185 #else /* not MSDOS */
5127 printf ("Continuing...\n"); 5186 printf ("Continuing...\n");
5187 #endif /* not MSDOS */
5128 fflush (stdout); 5188 fflush (stdout);
5129 init_sys_modes (); 5189 init_sys_modes ();
5130 } 5190 }
5131 else 5191 else
5132 { 5192 {
5650 The elements of the list are event types that may have menu bar bindings."); 5710 The elements of the list are event types that may have menu bar bindings.");
5651 Vmenu_bar_final_items = Qnil; 5711 Vmenu_bar_final_items = Qnil;
5652 5712
5653 DEFVAR_BOOL ("track-mouse", &do_mouse_tracking, 5713 DEFVAR_BOOL ("track-mouse", &do_mouse_tracking,
5654 "*Non-nil means generate motion events for mouse motion."); 5714 "*Non-nil means generate motion events for mouse motion.");
5715
5716 DEFVAR_LISP ("vendor-key-alist", &Vvendor_key_alist,
5717 "Alist of vendor-specific X windows key symbols.\n\
5718 Each element should have the form (N . SYMBOL) where N is the\n\
5719 numeric keysym code (sans the \"vendor-specific\" bit 1<<28)\n\
5720 and SYMBOL is its name.");
5721 Vmenu_bar_final_items = Qnil;
5655 } 5722 }
5656 5723
5657 keys_of_keyboard () 5724 keys_of_keyboard ()
5658 { 5725 {
5659 initial_define_key (global_map, Ctl ('Z'), "suspend-emacs"); 5726 initial_define_key (global_map, Ctl ('Z'), "suspend-emacs");