comparison src/console.c @ 412:697ef44129c6 r21-2-14

Import from CVS: tag r21-2-14
author cvs
date Mon, 13 Aug 2007 11:20:41 +0200
parents 2f8bb876ab1d
children 41dbb7a9d5f2
comparison
equal deleted inserted replaced
411:12e008d41344 412:697ef44129c6
51 in this structure as an individual console's value occupies in 51 in this structure as an individual console's value occupies in
52 that console. Setting the default value also goes through the 52 that console. Setting the default value also goes through the
53 list of consoles and stores into each console that does not say 53 list of consoles and stores into each console that does not say
54 it has a local value. */ 54 it has a local value. */
55 Lisp_Object Vconsole_defaults; 55 Lisp_Object Vconsole_defaults;
56 static void *console_defaults_saved_slots;
57 56
58 /* This structure marks which slots in a console have corresponding 57 /* This structure marks which slots in a console have corresponding
59 default values in console_defaults. 58 default values in console_defaults.
60 Each such slot has a nonzero value in this structure. 59 Each such slot has a nonzero value in this structure.
61 The value has only one nonzero bit. 60 The value has only one nonzero bit.
68 for the slot, but there is no default value for it; the corresponding 67 for the slot, but there is no default value for it; the corresponding
69 slot in console_defaults is not used except to initialize newly-created 68 slot in console_defaults is not used except to initialize newly-created
70 consoles. 69 consoles.
71 70
72 If a slot is -1, then there is a DEFVAR_CONSOLE_LOCAL for it 71 If a slot is -1, then there is a DEFVAR_CONSOLE_LOCAL for it
73 as well as a default value which is used to initialize newly-created 72 as well as a default value which is used to initialize newly-created
74 consoles and as a reset-value when local-vars are killed. 73 consoles and as a reset-value when local-vars are killed.
75 74
76 If a slot is -2, there is no DEFVAR_CONSOLE_LOCAL for it. 75 If a slot is -2, there is no DEFVAR_CONSOLE_LOCAL for it.
77 (The slot is always local, but there's no lisp variable for it.) 76 (The slot is always local, but there's no lisp variable for it.)
78 The default value is only used to initialize newly-creation consoles. 77 The default value is only used to initialize newly-creation consoles.
86 struct console console_local_flags; 85 struct console console_local_flags;
87 86
88 /* This structure holds the names of symbols whose values may be 87 /* This structure holds the names of symbols whose values may be
89 console-local. It is indexed and accessed in the same way as the above. */ 88 console-local. It is indexed and accessed in the same way as the above. */
90 static Lisp_Object Vconsole_local_symbols; 89 static Lisp_Object Vconsole_local_symbols;
91 static void *console_local_symbols_saved_slots;
92 90
93 DEFINE_CONSOLE_TYPE (dead); 91 DEFINE_CONSOLE_TYPE (dead);
94 92
95 Lisp_Object Vconsole_type_list; 93 Lisp_Object Vconsole_type_list;
96 94
97 console_type_entry_dynarr *the_console_type_entry_dynarr; 95 console_type_entry_dynarr *the_console_type_entry_dynarr;
98 96
99 97
100 static Lisp_Object 98 static Lisp_Object
101 mark_console (Lisp_Object obj) 99 mark_console (Lisp_Object obj, void (*markobj) (Lisp_Object))
102 { 100 {
103 struct console *con = XCONSOLE (obj); 101 struct console *con = XCONSOLE (obj);
104 102
105 #define MARKED_SLOT(x) mark_object (con->x) 103 #define MARKED_SLOT(x) ((void) (markobj (con->x)));
106 #include "conslots.h" 104 #include "conslots.h"
107 #undef MARKED_SLOT 105 #undef MARKED_SLOT
108 106
109 /* Can be zero for Vconsole_defaults, Vconsole_local_symbols */ 107 /* Can be zero for Vconsole_defaults, Vconsole_local_symbols */
110 if (con->conmeths) 108 if (con->conmeths)
111 { 109 {
112 mark_object (con->conmeths->symbol); 110 markobj (con->conmeths->symbol);
113 MAYBE_CONMETH (con, mark_console, (con)); 111 MAYBE_CONMETH (con, mark_console, (con, markobj));
114 } 112 }
115 113
116 return Qnil; 114 return Qnil;
117 } 115 }
118 116
127 XSTRING_DATA (con->name), con->header.uid); 125 XSTRING_DATA (con->name), con->header.uid);
128 126
129 sprintf (buf, "#<%s-console", !CONSOLE_LIVE_P (con) ? "dead" : 127 sprintf (buf, "#<%s-console", !CONSOLE_LIVE_P (con) ? "dead" :
130 CONSOLE_TYPE_NAME (con)); 128 CONSOLE_TYPE_NAME (con));
131 write_c_string (buf, printcharfun); 129 write_c_string (buf, printcharfun);
132 if (CONSOLE_LIVE_P (con) && !NILP (CONSOLE_CONNECTION (con))) 130 if (CONSOLE_LIVE_P (con))
133 { 131 {
134 write_c_string (" on ", printcharfun); 132 write_c_string (" on ", printcharfun);
135 print_internal (CONSOLE_CONNECTION (con), printcharfun, 1); 133 print_internal (CONSOLE_CONNECTION (con), printcharfun, 1);
136 } 134 }
137 sprintf (buf, " 0x%x>", con->header.uid); 135 sprintf (buf, " 0x%x>", con->header.uid);
138 write_c_string (buf, printcharfun); 136 write_c_string (buf, printcharfun);
139 } 137 }
140 138
141 DEFINE_LRECORD_IMPLEMENTATION ("console", console, 139 DEFINE_LRECORD_IMPLEMENTATION ("console", console,
142 mark_console, print_console, 0, 0, 0, 0, 140 mark_console, print_console, 0, 0, 0,
143 struct console); 141 struct console);
144 142
145 static struct console * 143 static struct console *
146 allocate_console (void) 144 allocate_console (void)
147 { 145 {
353 351
354 static Lisp_Object 352 static Lisp_Object
355 semi_canonicalize_console_connection (struct console_methods *meths, 353 semi_canonicalize_console_connection (struct console_methods *meths,
356 Lisp_Object name, Error_behavior errb) 354 Lisp_Object name, Error_behavior errb)
357 { 355 {
358 if (HAS_CONTYPE_METH_P (meths, semi_canonicalize_console_connection)) 356 return CONTYPE_METH_OR_GIVEN (meths, semi_canonicalize_console_connection,
359 return CONTYPE_METH (meths, semi_canonicalize_console_connection, 357 (name, errb), name);
360 (name, errb));
361 else
362 return CONTYPE_METH_OR_GIVEN (meths, canonicalize_console_connection,
363 (name, errb), name);
364 } 358 }
365 359
366 static Lisp_Object 360 static Lisp_Object
367 canonicalize_console_connection (struct console_methods *meths, 361 canonicalize_console_connection (struct console_methods *meths,
368 Lisp_Object name, Error_behavior errb) 362 Lisp_Object name, Error_behavior errb)
369 { 363 {
370 if (HAS_CONTYPE_METH_P (meths, canonicalize_console_connection)) 364 return CONTYPE_METH_OR_GIVEN (meths, canonicalize_console_connection,
371 return CONTYPE_METH (meths, canonicalize_console_connection, 365 (name, errb), name);
372 (name, errb));
373 else
374 return CONTYPE_METH_OR_GIVEN (meths, semi_canonicalize_console_connection,
375 (name, errb), name);
376 } 366 }
377 367
378 static Lisp_Object 368 static Lisp_Object
379 find_console_of_type (struct console_methods *meths, Lisp_Object canon) 369 find_console_of_type (struct console_methods *meths, Lisp_Object canon)
380 { 370 {
494 MAYBE_CONMETH (con, init_console, (con, props)); 484 MAYBE_CONMETH (con, init_console, (con, props));
495 485
496 /* Do it this way so that the console list is in order of creation */ 486 /* Do it this way so that the console list is in order of creation */
497 Vconsole_list = nconc2 (Vconsole_list, Fcons (console, Qnil)); 487 Vconsole_list = nconc2 (Vconsole_list, Fcons (console, Qnil));
498 488
499 if (CONMETH_OR_GIVEN (con, initially_selected_for_input, (con), 0)) 489 if (CONMETH (con, initially_selected_for_input, (con)))
500 event_stream_select_console (con); 490 event_stream_select_console (con);
501 491
502 UNGCPRO; 492 UNGCPRO;
503 return console; 493 return console;
504 } 494 }
884 if (STRINGP (stuffstring)) 874 if (STRINGP (stuffstring))
885 { 875 {
886 Extcount count; 876 Extcount count;
887 Extbyte *p; 877 Extbyte *p;
888 878
889 TO_EXTERNAL_FORMAT (LISP_STRING, stuffstring, 879 GET_STRING_EXT_DATA_ALLOCA (stuffstring, FORMAT_KEYBOARD, p, count);
890 ALLOCA, (p, count),
891 Qkeyboard);
892 while (count-- > 0) 880 while (count-- > 0)
893 stuff_char (XCONSOLE (Vcontrolling_terminal), *p++); 881 stuff_char (XCONSOLE (Vcontrolling_terminal), *p++);
894 stuff_char (XCONSOLE (Vcontrolling_terminal), '\n'); 882 stuff_char (XCONSOLE (Vcontrolling_terminal), '\n');
895 } 883 }
896 /* Anything we have read ahead, put back for the shell to read. */ 884 /* Anything we have read ahead, put back for the shell to read. */
1071 /************************************************************************/ 1059 /************************************************************************/
1072 1060
1073 void 1061 void
1074 syms_of_console (void) 1062 syms_of_console (void)
1075 { 1063 {
1076 INIT_LRECORD_IMPLEMENTATION (console);
1077
1078 DEFSUBR (Fvalid_console_type_p); 1064 DEFSUBR (Fvalid_console_type_p);
1079 DEFSUBR (Fconsole_type_list); 1065 DEFSUBR (Fconsole_type_list);
1080 DEFSUBR (Fcdfw_console); 1066 DEFSUBR (Fcdfw_console);
1081 DEFSUBR (Fselected_console); 1067 DEFSUBR (Fselected_console);
1082 DEFSUBR (Fselect_console); 1068 DEFSUBR (Fselect_console);
1108 1094
1109 defsymbol (&Qsuspend_hook, "suspend-hook"); 1095 defsymbol (&Qsuspend_hook, "suspend-hook");
1110 defsymbol (&Qsuspend_resume_hook, "suspend-resume-hook"); 1096 defsymbol (&Qsuspend_resume_hook, "suspend-resume-hook");
1111 } 1097 }
1112 1098
1113 static const struct lrecord_description cte_description_1[] = {
1114 { XD_LISP_OBJECT, offsetof (console_type_entry, symbol) },
1115 { XD_STRUCT_PTR, offsetof (console_type_entry, meths), 1, &console_methods_description },
1116 { XD_END }
1117 };
1118
1119 static const struct struct_description cte_description = {
1120 sizeof (console_type_entry),
1121 cte_description_1
1122 };
1123
1124 static const struct lrecord_description cted_description_1[] = {
1125 XD_DYNARR_DESC (console_type_entry_dynarr, &cte_description),
1126 { XD_END }
1127 };
1128
1129 const struct struct_description cted_description = {
1130 sizeof (console_type_entry_dynarr),
1131 cted_description_1
1132 };
1133
1134 static const struct lrecord_description console_methods_description_1[] = {
1135 { XD_LISP_OBJECT, offsetof (struct console_methods, symbol) },
1136 { XD_LISP_OBJECT, offsetof (struct console_methods, predicate_symbol) },
1137 { XD_LISP_OBJECT, offsetof (struct console_methods, image_conversion_list) },
1138 { XD_END }
1139 };
1140
1141 const struct struct_description console_methods_description = {
1142 sizeof (struct console_methods),
1143 console_methods_description_1
1144 };
1145
1146
1147 void 1099 void
1148 console_type_create (void) 1100 console_type_create (void)
1149 { 1101 {
1150 the_console_type_entry_dynarr = Dynarr_new (console_type_entry); 1102 the_console_type_entry_dynarr = Dynarr_new (console_type_entry);
1151 dumpstruct(&the_console_type_entry_dynarr, &cted_description);
1152 1103
1153 Vconsole_type_list = Qnil; 1104 Vconsole_type_list = Qnil;
1154 staticpro (&Vconsole_type_list); 1105 staticpro (&Vconsole_type_list);
1155 1106
1156 /* Initialize the dead console type */ 1107 /* Initialize the dead console type */
1161 Dynarr_reset (the_console_type_entry_dynarr); 1112 Dynarr_reset (the_console_type_entry_dynarr);
1162 Vconsole_type_list = Qnil; 1113 Vconsole_type_list = Qnil;
1163 } 1114 }
1164 1115
1165 void 1116 void
1166 reinit_vars_of_console (void)
1167 {
1168 staticpro_nodump (&Vconsole_list);
1169 Vconsole_list = Qnil;
1170 staticpro_nodump (&Vselected_console);
1171 Vselected_console = Qnil;
1172 }
1173
1174 void
1175 vars_of_console (void) 1117 vars_of_console (void)
1176 { 1118 {
1177 reinit_vars_of_console ();
1178
1179 DEFVAR_LISP ("create-console-hook", &Vcreate_console_hook /* 1119 DEFVAR_LISP ("create-console-hook", &Vcreate_console_hook /*
1180 Function or functions to call when a console is created. 1120 Function or functions to call when a console is created.
1181 One argument, the newly-created console. 1121 One argument, the newly-created console.
1182 This is called after the first frame has been created, but before 1122 This is called after the first frame has been created, but before
1183 calling the `create-device-hook' or `create-frame-hook'. 1123 calling the `create-device-hook' or `create-frame-hook'.
1189 Function or functions to call when a console is deleted. 1129 Function or functions to call when a console is deleted.
1190 One argument, the to-be-deleted console. 1130 One argument, the to-be-deleted console.
1191 */ ); 1131 */ );
1192 Vdelete_console_hook = Qnil; 1132 Vdelete_console_hook = Qnil;
1193 1133
1134 staticpro (&Vconsole_list);
1135 Vconsole_list = Qnil;
1136 staticpro (&Vselected_console);
1137 Vselected_console = Qnil;
1138
1194 #ifdef HAVE_WINDOW_SYSTEM 1139 #ifdef HAVE_WINDOW_SYSTEM
1195 Fprovide (intern ("window-system")); 1140 Fprovide (intern ("window-system"));
1196 #endif 1141 #endif
1197 } 1142 }
1198 1143
1199 /* The docstrings for DEFVAR_* are recorded externally by make-docfile. */ 1144 /* The docstrings for DEFVAR_* are recorded externally by make-docfile. */
1145
1146 /* Declaring this stuff as const produces 'Cannot reinitialize' messages
1147 from SunPro C's fix-and-continue feature (a way neato feature that
1148 makes debugging unbelievably more bearable) */
1200 #define DEFVAR_CONSOLE_LOCAL_1(lname, field_name, forward_type, magicfun) do { \ 1149 #define DEFVAR_CONSOLE_LOCAL_1(lname, field_name, forward_type, magicfun) do { \
1201 static const struct symbol_value_forward I_hate_C = \ 1150 static CONST_IF_NOT_DEBUG struct symbol_value_forward I_hate_C \
1202 { /* struct symbol_value_forward */ \ 1151 = { { { symbol_value_forward_lheader_initializer, \
1203 { /* struct symbol_value_magic */ \ 1152 (struct lcrecord_header *) &(console_local_flags.field_name), 69 }, \
1204 { /* struct lcrecord_header */ \ 1153 forward_type }, magicfun }; \
1205 { /* struct lrecord_header */ \
1206 lrecord_type_symbol_value_forward, /* lrecord_type_index */ \
1207 1, /* mark bit */ \
1208 1, /* c_readonly bit */ \
1209 1 /* lisp_readonly bit */ \
1210 }, \
1211 0, /* next */ \
1212 0, /* uid */ \
1213 0 /* free */ \
1214 }, \
1215 &(console_local_flags.field_name), \
1216 forward_type \
1217 }, \
1218 magicfun \
1219 }; \
1220 \
1221 { \ 1154 { \
1222 int offset = ((char *)symbol_value_forward_forward (&I_hate_C) \ 1155 int offset = ((char *)symbol_value_forward_forward (&I_hate_C) \
1223 - (char *)&console_local_flags); \ 1156 - (char *)&console_local_flags); \
1224 \ 1157 \
1225 defvar_magic (lname, &I_hate_C); \ 1158 defvar_magic (lname, &I_hate_C); \
1249 static void 1182 static void
1250 nuke_all_console_slots (struct console *con, Lisp_Object zap) 1183 nuke_all_console_slots (struct console *con, Lisp_Object zap)
1251 { 1184 {
1252 zero_lcrecord (con); 1185 zero_lcrecord (con);
1253 1186
1254 #define MARKED_SLOT(x) con->x = zap 1187 #define MARKED_SLOT(x) con->x = (zap);
1255 #include "conslots.h" 1188 #include "conslots.h"
1256 #undef MARKED_SLOT 1189 #undef MARKED_SLOT
1257 } 1190 }
1258 1191
1259 static void 1192 void
1260 common_init_complex_vars_of_console (void) 1193 complex_vars_of_console (void)
1261 { 1194 {
1262 /* Make sure all markable slots in console_defaults 1195 /* Make sure all markable slots in console_defaults
1263 are initialized reasonably, so mark_console won't choke. 1196 are initialized reasonably, so mark_console won't choke.
1264 */ 1197 */
1265 struct console *defs = alloc_lcrecord_type (struct console, &lrecord_console); 1198 struct console *defs = alloc_lcrecord_type (struct console, &lrecord_console);
1266 struct console *syms = alloc_lcrecord_type (struct console, &lrecord_console); 1199 struct console *syms = alloc_lcrecord_type (struct console, &lrecord_console);
1267 1200
1268 staticpro_nodump (&Vconsole_defaults); 1201 staticpro (&Vconsole_defaults);
1269 staticpro_nodump (&Vconsole_local_symbols); 1202 staticpro (&Vconsole_local_symbols);
1270 XSETCONSOLE (Vconsole_defaults, defs); 1203 XSETCONSOLE (Vconsole_defaults, defs);
1271 XSETCONSOLE (Vconsole_local_symbols, syms); 1204 XSETCONSOLE (Vconsole_local_symbols, syms);
1272 1205
1273 nuke_all_console_slots (syms, Qnil); 1206 nuke_all_console_slots (syms, Qnil);
1274 nuke_all_console_slots (defs, Qnil); 1207 nuke_all_console_slots (defs, Qnil);
1319 1252
1320 /* #### Warning, 0x4000000 (that's six zeroes) is the largest number 1253 /* #### Warning, 0x4000000 (that's six zeroes) is the largest number
1321 currently allowable due to the XINT() handling of this value. 1254 currently allowable due to the XINT() handling of this value.
1322 With some rearrangement you can get 4 more bits. */ 1255 With some rearrangement you can get 4 more bits. */
1323 } 1256 }
1324 }
1325
1326
1327 #define CONSOLE_SLOTS_SIZE (offsetof (struct console, CONSOLE_SLOTS_LAST_NAME) - offsetof (struct console, CONSOLE_SLOTS_FIRST_NAME) + sizeof (Lisp_Object))
1328 #define CONSOLE_SLOTS_COUNT (CONSOLE_SLOTS_SIZE / sizeof (Lisp_Object))
1329
1330 void
1331 reinit_complex_vars_of_console (void)
1332 {
1333 struct console *defs, *syms;
1334
1335 common_init_complex_vars_of_console ();
1336
1337 defs = XCONSOLE (Vconsole_defaults);
1338 syms = XCONSOLE (Vconsole_local_symbols);
1339 memcpy (&defs->CONSOLE_SLOTS_FIRST_NAME,
1340 console_defaults_saved_slots,
1341 CONSOLE_SLOTS_SIZE);
1342 memcpy (&syms->CONSOLE_SLOTS_FIRST_NAME,
1343 console_local_symbols_saved_slots,
1344 CONSOLE_SLOTS_SIZE);
1345 }
1346
1347
1348 static const struct lrecord_description console_slots_description_1[] = {
1349 { XD_LISP_OBJECT_ARRAY, 0, CONSOLE_SLOTS_COUNT },
1350 { XD_END }
1351 };
1352
1353 static const struct struct_description console_slots_description = {
1354 CONSOLE_SLOTS_SIZE,
1355 console_slots_description_1
1356 };
1357
1358 void
1359 complex_vars_of_console (void)
1360 {
1361 struct console *defs, *syms;
1362
1363 common_init_complex_vars_of_console ();
1364
1365 defs = XCONSOLE (Vconsole_defaults);
1366 syms = XCONSOLE (Vconsole_local_symbols);
1367 console_defaults_saved_slots = &defs->CONSOLE_SLOTS_FIRST_NAME;
1368 console_local_symbols_saved_slots = &syms->CONSOLE_SLOTS_FIRST_NAME;
1369 dumpstruct (&console_defaults_saved_slots, &console_slots_description);
1370 dumpstruct (&console_local_symbols_saved_slots, &console_slots_description);
1371 1257
1372 DEFVAR_CONSOLE_DEFAULTS ("default-function-key-map", function_key_map /* 1258 DEFVAR_CONSOLE_DEFAULTS ("default-function-key-map", function_key_map /*
1373 Default value of `function-key-map' for consoles that don't override it. 1259 Default value of `function-key-map' for consoles that don't override it.
1374 This is the same as (default-value 'function-key-map). 1260 This is the same as (default-value 'function-key-map).
1375 */ ); 1261 */ );
1396 were a prefix key, typing `ESC O P x' would return 1282 were a prefix key, typing `ESC O P x' would return
1397 \[#<keypress-event f1> #<keypress-event x>]. 1283 \[#<keypress-event f1> #<keypress-event x>].
1398 */ ); 1284 */ );
1399 1285
1400 #ifdef HAVE_TTY 1286 #ifdef HAVE_TTY
1401 /* #### Should this somehow go to TTY data? How do we make it 1287 /* ### Should this somehow go to TTY data? How do we make it
1402 accessible from Lisp, then? */ 1288 accessible from Lisp, then? */
1403 DEFVAR_CONSOLE_LOCAL ("tty-erase-char", tty_erase_char /* 1289 DEFVAR_CONSOLE_LOCAL ("tty-erase-char", tty_erase_char /*
1404 The ERASE character as set by the user with stty. 1290 The ERASE character as set by the user with stty.
1405 When this value cannot be determined or would be meaningless (on non-TTY 1291 When this value cannot be determined or would be meaningless (on non-TTY
1406 consoles, for example), it is set to nil. 1292 consoles, for example), it is set to nil.
1407 */ ); 1293 */ );
1408 #endif 1294 #endif
1409 1295
1410 /* While this should be const it can't be because some things 1296 /* While this should be CONST it can't be because some things
1411 (i.e. edebug) do manipulate it. */ 1297 (i.e. edebug) do manipulate it. */
1412 DEFVAR_CONSOLE_LOCAL ("defining-kbd-macro", defining_kbd_macro /* 1298 DEFVAR_CONSOLE_LOCAL ("defining-kbd-macro", defining_kbd_macro /*
1413 Non-nil while a keyboard macro is being defined. Don't set this! 1299 Non-nil while a console macro is being defined. Don't set this!
1414 */ ); 1300 */ );
1415 1301
1416 DEFVAR_CONSOLE_LOCAL ("last-kbd-macro", last_kbd_macro /* 1302 DEFVAR_CONSOLE_LOCAL ("last-kbd-macro", last_kbd_macro /*
1417 Last keyboard macro defined, as a vector of events; nil if none defined. 1303 Last kbd macro defined, as a vector of events; nil if none defined.
1418 */ ); 1304 */ );
1419 1305
1420 DEFVAR_CONSOLE_LOCAL ("prefix-arg", prefix_arg /* 1306 DEFVAR_CONSOLE_LOCAL ("prefix-arg", prefix_arg /*
1421 The value of the prefix argument for the next editing command. 1307 The value of the prefix argument for the next editing command.
1422 It may be a number, or the symbol `-' for just a minus sign as arg, 1308 It may be a number, or the symbol `-' for just a minus sign as arg,