428
|
1 /* TTY-specific Lisp objects.
|
|
2 Copyright (C) 1995 Board of Trustees, University of Illinois.
|
793
|
3 Copyright (C) 1995, 1996, 2001, 2002 Ben Wing.
|
428
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: Not in FSF. */
|
|
23
|
|
24 #include <config.h>
|
|
25 #include "lisp.h"
|
|
26
|
872
|
27 #include "console-tty-impl.h"
|
428
|
28 #include "insdel.h"
|
872
|
29 #include "objects-tty-impl.h"
|
428
|
30 #include "device.h"
|
771
|
31 #include "charset.h"
|
428
|
32
|
|
33 /* An alist mapping from color names to a cons of (FG-STRING, BG-STRING). */
|
|
34 Lisp_Object Vtty_color_alist;
|
|
35 #if 0 /* This stuff doesn't quite work yet */
|
|
36 Lisp_Object Vtty_dynamic_color_fg;
|
|
37 Lisp_Object Vtty_dynamic_color_bg;
|
|
38 #endif
|
|
39
|
1204
|
40 static const struct memory_description tty_color_instance_data_description_1 [] = {
|
|
41 { XD_LISP_OBJECT, offsetof (struct tty_color_instance_data, symbol) },
|
|
42 { XD_END }
|
|
43 };
|
|
44
|
3092
|
45 #ifdef NEW_GC
|
|
46 DEFINE_LRECORD_IMPLEMENTATION ("tty-color-instance-data",
|
|
47 tty_color_instance_data,
|
|
48 0, /*dumpable-flag*/
|
|
49 0, 0, 0, 0, 0,
|
|
50 tty_color_instance_data_description_1,
|
|
51 struct tty_color_instance_data);
|
|
52 #else /* not NEW_GC */
|
1204
|
53 const struct sized_memory_description tty_color_instance_data_description = {
|
|
54 sizeof (struct tty_color_instance_data), tty_color_instance_data_description_1
|
|
55 };
|
3092
|
56 #endif /* not NEW_GC */
|
1204
|
57
|
|
58 static const struct memory_description tty_font_instance_data_description_1 [] = {
|
|
59 { XD_LISP_OBJECT, offsetof (struct tty_font_instance_data, charset) },
|
|
60 { XD_END }
|
|
61 };
|
|
62
|
3092
|
63 #ifdef NEW_GC
|
|
64 DEFINE_LRECORD_IMPLEMENTATION ("tty-font-instance-data",
|
|
65 tty_font_instance_data,
|
|
66 0, /*dumpable-flag*/
|
|
67 0, 0, 0, 0, 0,
|
|
68 tty_font_instance_data_description_1,
|
|
69 struct tty_font_instance_data);
|
|
70 #else /* not NEW_GC */
|
1204
|
71 const struct sized_memory_description tty_font_instance_data_description = {
|
|
72 sizeof (struct tty_font_instance_data), tty_font_instance_data_description_1
|
|
73 };
|
3092
|
74 #endif /* not NEW_GC */
|
1204
|
75
|
428
|
76 DEFUN ("register-tty-color", Fregister_tty_color, 3, 3, 0, /*
|
|
77 Register COLOR as a recognized TTY color.
|
|
78 COLOR should be a string.
|
|
79 Strings FG-STRING and BG-STRING should specify the escape sequences to
|
|
80 set the foreground and background to the given color, respectively.
|
|
81 */
|
|
82 (color, fg_string, bg_string))
|
|
83 {
|
|
84 CHECK_STRING (color);
|
|
85 CHECK_STRING (fg_string);
|
|
86 CHECK_STRING (bg_string);
|
|
87
|
|
88 color = Fintern (color, Qnil);
|
|
89 Vtty_color_alist = Fremassq (color, Vtty_color_alist);
|
|
90 Vtty_color_alist = Fcons (Fcons (color, Fcons (fg_string, bg_string)),
|
|
91 Vtty_color_alist);
|
|
92
|
|
93 return Qnil;
|
|
94 }
|
|
95
|
|
96 DEFUN ("unregister-tty-color", Funregister_tty_color, 1, 1, 0, /*
|
|
97 Unregister COLOR as a recognized TTY color.
|
|
98 */
|
|
99 (color))
|
|
100 {
|
|
101 CHECK_STRING (color);
|
|
102
|
|
103 color = Fintern (color, Qnil);
|
|
104 Vtty_color_alist = Fremassq (color, Vtty_color_alist);
|
|
105 return Qnil;
|
|
106 }
|
|
107
|
|
108 DEFUN ("find-tty-color", Ffind_tty_color, 1, 1, 0, /*
|
|
109 Look up COLOR in the list of registered TTY colors.
|
|
110 If it is found, return a list (FG-STRING BG-STRING) of the escape
|
|
111 sequences used to set the foreground and background to the color, respectively.
|
|
112 If it is not found, return nil.
|
|
113 */
|
|
114 (color))
|
|
115 {
|
|
116 Lisp_Object result;
|
|
117
|
|
118 CHECK_STRING (color);
|
|
119
|
|
120 result = Fassq (Fintern (color, Qnil), Vtty_color_alist);
|
|
121 if (!NILP (result))
|
|
122 return list2 (Fcar (Fcdr (result)), Fcdr (Fcdr (result)));
|
|
123 else
|
|
124 return Qnil;
|
|
125 }
|
|
126
|
2527
|
127 static Lisp_Object
|
|
128 tty_color_list (void)
|
428
|
129 {
|
|
130 Lisp_Object result = Qnil;
|
|
131 Lisp_Object rest;
|
|
132
|
|
133 LIST_LOOP (rest, Vtty_color_alist)
|
|
134 {
|
|
135 result = Fcons (Fsymbol_name (XCAR (XCAR (rest))), result);
|
|
136 }
|
|
137
|
|
138 return Fnreverse (result);
|
|
139 }
|
|
140
|
|
141 #if 0
|
|
142
|
|
143 /* This approach is too simplistic. The problem is that the
|
|
144 dynamic color settings apply to *all* text in the default color,
|
|
145 not just the text output after the escape sequence has been given. */
|
|
146
|
|
147 DEFUN ("set-tty-dynamic-color-specs", Fset_tty_dynamic_color_specs, 2, 2, 0, /*
|
|
148 Set the dynamic color specifications for TTY's.
|
|
149 FG and BG should be either nil or vaguely printf-like strings,
|
|
150 where each occurrence of %s is replaced with the color name and each
|
|
151 occurrence of %% is replaced with a single % character.
|
|
152 */
|
|
153 (fg, bg))
|
|
154 {
|
|
155 if (!NILP (fg))
|
|
156 CHECK_STRING (fg);
|
|
157 if (!NILP (bg))
|
|
158 CHECK_STRING (bg);
|
|
159
|
|
160 Vtty_dynamic_color_fg = fg;
|
|
161 Vtty_dynamic_color_bg = bg;
|
|
162
|
|
163 return Qnil;
|
|
164 }
|
|
165
|
|
166 DEFUN ("tty-dynamic-color-specs", Ftty_dynamic_color_specs, 0, 0, 0, /*
|
|
167 Return the dynamic color specifications for TTY's as a list of (FG BG).
|
|
168 See `set-tty-dynamic-color-specs'.
|
|
169 */
|
|
170 ())
|
|
171 {
|
|
172 return list2 (Vtty_dynamic_color_fg, Vtty_dynamic_color_bg);
|
|
173 }
|
|
174
|
|
175 #endif /* 0 */
|
|
176
|
|
177 static int
|
440
|
178 tty_initialize_color_instance (Lisp_Color_Instance *c, Lisp_Object name,
|
2286
|
179 Lisp_Object UNUSED (device),
|
|
180 Error_Behavior UNUSED (errb))
|
428
|
181 {
|
|
182 Lisp_Object result;
|
|
183
|
|
184 name = Fintern (name, Qnil);
|
|
185 result = assq_no_quit (name, Vtty_color_alist);
|
|
186
|
|
187 if (NILP (result))
|
|
188 {
|
|
189 #if 0
|
|
190 if (!STRINGP (Vtty_dynamic_color_fg)
|
|
191 && !STRINGP (Vtty_dynamic_color_bg))
|
|
192 #endif
|
|
193 return 0;
|
|
194 }
|
|
195
|
|
196 /* Don't allocate the data until we're sure that we will succeed. */
|
3092
|
197 #ifdef NEW_GC
|
|
198 c->data = alloc_lrecord_type (struct tty_color_instance_data,
|
|
199 &lrecord_tty_color_instance_data);
|
|
200 #else /* not NEW_GC */
|
428
|
201 c->data = xnew (struct tty_color_instance_data);
|
3092
|
202 #endif /* not NEW_GC */
|
428
|
203 COLOR_INSTANCE_TTY_SYMBOL (c) = name;
|
|
204
|
|
205 return 1;
|
|
206 }
|
|
207
|
|
208 static void
|
440
|
209 tty_mark_color_instance (Lisp_Color_Instance *c)
|
428
|
210 {
|
|
211 mark_object (COLOR_INSTANCE_TTY_SYMBOL (c));
|
|
212 }
|
|
213
|
|
214 static void
|
2286
|
215 tty_print_color_instance (Lisp_Color_Instance *UNUSED (c),
|
|
216 Lisp_Object UNUSED (printcharfun),
|
|
217 int UNUSED (escapeflag))
|
428
|
218 {
|
|
219 }
|
|
220
|
|
221 static void
|
440
|
222 tty_finalize_color_instance (Lisp_Color_Instance *c)
|
428
|
223 {
|
|
224 if (c->data)
|
3092
|
225 #ifdef NEW_GC
|
|
226 mc_free (c->data);
|
|
227 #else /* not NEW_GC */
|
1726
|
228 xfree (c->data, void *);
|
3092
|
229 #endif /* not NEW_GC */
|
428
|
230 }
|
|
231
|
|
232 static int
|
440
|
233 tty_color_instance_equal (Lisp_Color_Instance *c1,
|
|
234 Lisp_Color_Instance *c2,
|
2286
|
235 int UNUSED (depth))
|
428
|
236 {
|
|
237 return (EQ (COLOR_INSTANCE_TTY_SYMBOL (c1),
|
|
238 COLOR_INSTANCE_TTY_SYMBOL (c2)));
|
|
239 }
|
|
240
|
2515
|
241 static Hashcode
|
2286
|
242 tty_color_instance_hash (Lisp_Color_Instance *c, int UNUSED (depth))
|
428
|
243 {
|
|
244 return LISP_HASH (COLOR_INSTANCE_TTY_SYMBOL (c));
|
|
245 }
|
|
246
|
|
247 static int
|
2286
|
248 tty_valid_color_name_p (struct device *UNUSED (d), Lisp_Object color)
|
428
|
249 {
|
|
250 return (!NILP (assoc_no_quit (Fintern (color, Qnil), Vtty_color_alist)));
|
|
251 #if 0
|
|
252 || STRINGP (Vtty_dynamic_color_fg)
|
|
253 || STRINGP (Vtty_dynamic_color_bg)
|
|
254 #endif
|
|
255 }
|
|
256
|
|
257
|
|
258 static int
|
440
|
259 tty_initialize_font_instance (Lisp_Font_Instance *f, Lisp_Object name,
|
2286
|
260 Lisp_Object UNUSED (device),
|
|
261 Error_Behavior UNUSED (errb))
|
428
|
262 {
|
867
|
263 Ibyte *str = XSTRING_DATA (name);
|
428
|
264 Lisp_Object charset = Qnil;
|
|
265
|
2367
|
266 if (qxestrncmp_ascii (str, "normal", 6))
|
428
|
267 return 0;
|
|
268 str += 6;
|
|
269 if (*str)
|
|
270 {
|
|
271 #ifdef MULE
|
|
272 if (*str != '/')
|
|
273 return 0;
|
|
274 str++;
|
771
|
275 charset = Ffind_charset (intern_int (str));
|
428
|
276 if (NILP (charset))
|
|
277 return 0;
|
|
278 #else
|
|
279 return 0;
|
|
280 #endif
|
|
281 }
|
|
282
|
|
283 /* Don't allocate the data until we're sure that we will succeed. */
|
3092
|
284 #ifdef NEW_GC
|
|
285 f->data = alloc_lrecord_type (struct tty_font_instance_data,
|
|
286 &lrecord_tty_font_instance_data);
|
|
287 #else /* not NEW_GC */
|
428
|
288 f->data = xnew (struct tty_font_instance_data);
|
3092
|
289 #endif /* not NEW_GC */
|
428
|
290 FONT_INSTANCE_TTY_CHARSET (f) = charset;
|
|
291 #ifdef MULE
|
|
292 if (CHARSETP (charset))
|
|
293 f->width = XCHARSET_COLUMNS (charset);
|
|
294 else
|
|
295 #endif
|
|
296 f->width = 1;
|
|
297
|
|
298 f->proportional_p = 0;
|
|
299 f->ascent = f->height = 1;
|
|
300 f->descent = 0;
|
|
301
|
|
302 return 1;
|
|
303 }
|
|
304
|
|
305 static void
|
440
|
306 tty_mark_font_instance (Lisp_Font_Instance *f)
|
428
|
307 {
|
|
308 mark_object (FONT_INSTANCE_TTY_CHARSET (f));
|
|
309 }
|
|
310
|
|
311 static void
|
2286
|
312 tty_print_font_instance (Lisp_Font_Instance *UNUSED (f),
|
|
313 Lisp_Object UNUSED (printcharfun),
|
|
314 int UNUSED (escapeflag))
|
428
|
315 {
|
|
316 }
|
|
317
|
|
318 static void
|
440
|
319 tty_finalize_font_instance (Lisp_Font_Instance *f)
|
428
|
320 {
|
|
321 if (f->data)
|
3092
|
322 #ifdef NEW_GC
|
|
323 mc_free (f->data);
|
|
324 #else /* not NEW_GC */
|
1726
|
325 xfree (f->data, void *);
|
3092
|
326 #endif /* not NEW_GC */
|
428
|
327 }
|
|
328
|
|
329 static Lisp_Object
|
2527
|
330 tty_font_list (Lisp_Object UNUSED (pattern), Lisp_Object UNUSED (device),
|
2286
|
331 Lisp_Object UNUSED (maxnumber))
|
428
|
332 {
|
|
333 return list1 (build_string ("normal"));
|
|
334 }
|
|
335
|
|
336 #ifdef MULE
|
|
337
|
|
338 static int
|
2286
|
339 tty_font_spec_matches_charset (struct device *UNUSED (d), Lisp_Object charset,
|
867
|
340 const Ibyte *nonreloc, Lisp_Object reloc,
|
872
|
341 Bytecount offset, Bytecount length,
|
|
342 int stage)
|
428
|
343 {
|
867
|
344 const Ibyte *the_nonreloc = nonreloc;
|
428
|
345
|
872
|
346 if (stage)
|
|
347 return 0;
|
|
348
|
428
|
349 if (!the_nonreloc)
|
|
350 the_nonreloc = XSTRING_DATA (reloc);
|
|
351 fixup_internal_substring (nonreloc, reloc, offset, &length);
|
|
352 the_nonreloc += offset;
|
|
353
|
|
354 if (UNBOUNDP (charset))
|
|
355 return !memchr (the_nonreloc, '/', length);
|
867
|
356 the_nonreloc = (const Ibyte *) memchr (the_nonreloc, '/', length);
|
428
|
357 if (!the_nonreloc)
|
|
358 return 0;
|
|
359 the_nonreloc++;
|
|
360 {
|
793
|
361 Lisp_Object s = symbol_name (XSYMBOL (XCHARSET_NAME (charset)));
|
|
362 return !qxestrcmp (the_nonreloc, XSTRING_DATA (s));
|
428
|
363 }
|
|
364 }
|
|
365
|
|
366 /* find a font spec that matches font spec FONT and also matches
|
|
367 (the registry of) CHARSET. */
|
|
368 static Lisp_Object
|
|
369 tty_find_charset_font (Lisp_Object device, Lisp_Object font,
|
872
|
370 Lisp_Object charset, int stage)
|
428
|
371 {
|
867
|
372 Ibyte *fontname = XSTRING_DATA (font);
|
428
|
373
|
872
|
374 if (stage)
|
|
375 return Qnil;
|
|
376
|
442
|
377 if (strchr ((const char *) fontname, '/'))
|
428
|
378 {
|
|
379 if (tty_font_spec_matches_charset (XDEVICE (device), charset, 0,
|
872
|
380 font, 0, -1, 0))
|
428
|
381 return font;
|
|
382 return Qnil;
|
|
383 }
|
|
384
|
|
385 if (UNBOUNDP (charset))
|
|
386 return font;
|
|
387
|
|
388 return concat3 (font, build_string ("/"),
|
|
389 Fsymbol_name (XCHARSET_NAME (charset)));
|
|
390 }
|
|
391
|
|
392 #endif /* MULE */
|
|
393
|
|
394
|
|
395 /************************************************************************/
|
|
396 /* initialization */
|
|
397 /************************************************************************/
|
|
398
|
|
399 void
|
|
400 syms_of_objects_tty (void)
|
|
401 {
|
3092
|
402 #ifdef NEW_GC
|
|
403 INIT_LRECORD_IMPLEMENTATION (tty_color_instance_data);
|
|
404 INIT_LRECORD_IMPLEMENTATION (tty_font_instance_data);
|
|
405 #endif /* NEW_GC */
|
|
406
|
428
|
407 DEFSUBR (Fregister_tty_color);
|
|
408 DEFSUBR (Funregister_tty_color);
|
|
409 DEFSUBR (Ffind_tty_color);
|
|
410 #if 0
|
|
411 DEFSUBR (Fset_tty_dynamic_color_specs);
|
|
412 DEFSUBR (Ftty_dynamic_color_specs);
|
|
413 #endif
|
|
414 }
|
|
415
|
|
416 void
|
|
417 console_type_create_objects_tty (void)
|
|
418 {
|
|
419 /* object methods */
|
|
420 CONSOLE_HAS_METHOD (tty, initialize_color_instance);
|
|
421 CONSOLE_HAS_METHOD (tty, mark_color_instance);
|
|
422 CONSOLE_HAS_METHOD (tty, print_color_instance);
|
|
423 CONSOLE_HAS_METHOD (tty, finalize_color_instance);
|
|
424 CONSOLE_HAS_METHOD (tty, color_instance_equal);
|
|
425 CONSOLE_HAS_METHOD (tty, color_instance_hash);
|
|
426 CONSOLE_HAS_METHOD (tty, valid_color_name_p);
|
2527
|
427 CONSOLE_HAS_METHOD (tty, color_list);
|
428
|
428
|
|
429 CONSOLE_HAS_METHOD (tty, initialize_font_instance);
|
|
430 CONSOLE_HAS_METHOD (tty, mark_font_instance);
|
|
431 CONSOLE_HAS_METHOD (tty, print_font_instance);
|
|
432 CONSOLE_HAS_METHOD (tty, finalize_font_instance);
|
2527
|
433 CONSOLE_HAS_METHOD (tty, font_list);
|
428
|
434 #ifdef MULE
|
|
435 CONSOLE_HAS_METHOD (tty, font_spec_matches_charset);
|
|
436 CONSOLE_HAS_METHOD (tty, find_charset_font);
|
|
437 #endif
|
|
438 }
|
|
439
|
|
440 void
|
|
441 vars_of_objects_tty (void)
|
|
442 {
|
|
443 staticpro (&Vtty_color_alist);
|
|
444 Vtty_color_alist = Qnil;
|
|
445
|
|
446 #if 0
|
|
447 staticpro (&Vtty_dynamic_color_fg);
|
|
448 Vtty_dynamic_color_fg = Qnil;
|
|
449
|
|
450 staticpro (&Vtty_dynamic_color_bg);
|
|
451 Vtty_dynamic_color_bg = Qnil;
|
|
452 #endif
|
|
453 }
|