Mercurial > hg > xemacs-beta
annotate src/objects-tty.c @ 5126:2a462149bd6a ben-lisp-object
merge
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Wed, 24 Feb 2010 19:04:27 -0600 |
parents | b5df3737028a d4f666cda5e6 |
children | a9c41067dd88 |
rev | line source |
---|---|
428 | 1 /* TTY-specific Lisp objects. |
2 Copyright (C) 1995 Board of Trustees, University of Illinois. | |
5015
d95c102a96d3
cleanups for specifier font stages, from ben-unicode-internal (preparation for eliminating shadowed warnings)
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
3 Copyright (C) 1995, 1996, 2001, 2002, 2010 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 |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents:
4710
diff
changeset
|
46 DEFINE_DUMPABLE_INTERNAL_LISP_OBJECT ("tty-color-instance-data", |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents:
4710
diff
changeset
|
47 tty_color_instance_data, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents:
4710
diff
changeset
|
48 0, tty_color_instance_data_description_1, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents:
4710
diff
changeset
|
49 struct tty_color_instance_data); |
3092 | 50 #else /* not NEW_GC */ |
1204 | 51 const struct sized_memory_description tty_color_instance_data_description = { |
52 sizeof (struct tty_color_instance_data), tty_color_instance_data_description_1 | |
53 }; | |
3092 | 54 #endif /* not NEW_GC */ |
1204 | 55 |
56 static const struct memory_description tty_font_instance_data_description_1 [] = { | |
57 { XD_LISP_OBJECT, offsetof (struct tty_font_instance_data, charset) }, | |
58 { XD_END } | |
59 }; | |
60 | |
3092 | 61 #ifdef NEW_GC |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents:
4710
diff
changeset
|
62 DEFINE_DUMPABLE_INTERNAL_LISP_OBJECT ("tty-font-instance-data", |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents:
4710
diff
changeset
|
63 tty_font_instance_data, 0, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents:
4710
diff
changeset
|
64 tty_font_instance_data_description_1, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents:
4710
diff
changeset
|
65 struct tty_font_instance_data); |
3092 | 66 #else /* not NEW_GC */ |
1204 | 67 const struct sized_memory_description tty_font_instance_data_description = { |
68 sizeof (struct tty_font_instance_data), tty_font_instance_data_description_1 | |
69 }; | |
3092 | 70 #endif /* not NEW_GC */ |
1204 | 71 |
428 | 72 DEFUN ("register-tty-color", Fregister_tty_color, 3, 3, 0, /* |
73 Register COLOR as a recognized TTY color. | |
74 COLOR should be a string. | |
75 Strings FG-STRING and BG-STRING should specify the escape sequences to | |
76 set the foreground and background to the given color, respectively. | |
77 */ | |
78 (color, fg_string, bg_string)) | |
79 { | |
80 CHECK_STRING (color); | |
81 CHECK_STRING (fg_string); | |
82 CHECK_STRING (bg_string); | |
83 | |
84 color = Fintern (color, Qnil); | |
85 Vtty_color_alist = Fremassq (color, Vtty_color_alist); | |
86 Vtty_color_alist = Fcons (Fcons (color, Fcons (fg_string, bg_string)), | |
87 Vtty_color_alist); | |
88 | |
89 return Qnil; | |
90 } | |
91 | |
92 DEFUN ("unregister-tty-color", Funregister_tty_color, 1, 1, 0, /* | |
93 Unregister COLOR as a recognized TTY color. | |
94 */ | |
95 (color)) | |
96 { | |
97 CHECK_STRING (color); | |
98 | |
99 color = Fintern (color, Qnil); | |
100 Vtty_color_alist = Fremassq (color, Vtty_color_alist); | |
101 return Qnil; | |
102 } | |
103 | |
104 DEFUN ("find-tty-color", Ffind_tty_color, 1, 1, 0, /* | |
105 Look up COLOR in the list of registered TTY colors. | |
106 If it is found, return a list (FG-STRING BG-STRING) of the escape | |
107 sequences used to set the foreground and background to the color, respectively. | |
108 If it is not found, return nil. | |
109 */ | |
110 (color)) | |
111 { | |
112 Lisp_Object result; | |
113 | |
114 CHECK_STRING (color); | |
115 | |
116 result = Fassq (Fintern (color, Qnil), Vtty_color_alist); | |
117 if (!NILP (result)) | |
118 return list2 (Fcar (Fcdr (result)), Fcdr (Fcdr (result))); | |
119 else | |
120 return Qnil; | |
121 } | |
122 | |
2527 | 123 static Lisp_Object |
124 tty_color_list (void) | |
428 | 125 { |
126 Lisp_Object result = Qnil; | |
127 Lisp_Object rest; | |
128 | |
129 LIST_LOOP (rest, Vtty_color_alist) | |
130 { | |
131 result = Fcons (Fsymbol_name (XCAR (XCAR (rest))), result); | |
132 } | |
133 | |
134 return Fnreverse (result); | |
135 } | |
136 | |
137 #if 0 | |
138 | |
139 /* This approach is too simplistic. The problem is that the | |
140 dynamic color settings apply to *all* text in the default color, | |
141 not just the text output after the escape sequence has been given. */ | |
142 | |
143 DEFUN ("set-tty-dynamic-color-specs", Fset_tty_dynamic_color_specs, 2, 2, 0, /* | |
144 Set the dynamic color specifications for TTY's. | |
145 FG and BG should be either nil or vaguely printf-like strings, | |
146 where each occurrence of %s is replaced with the color name and each | |
147 occurrence of %% is replaced with a single % character. | |
148 */ | |
149 (fg, bg)) | |
150 { | |
151 if (!NILP (fg)) | |
152 CHECK_STRING (fg); | |
153 if (!NILP (bg)) | |
154 CHECK_STRING (bg); | |
155 | |
156 Vtty_dynamic_color_fg = fg; | |
157 Vtty_dynamic_color_bg = bg; | |
158 | |
159 return Qnil; | |
160 } | |
161 | |
162 DEFUN ("tty-dynamic-color-specs", Ftty_dynamic_color_specs, 0, 0, 0, /* | |
163 Return the dynamic color specifications for TTY's as a list of (FG BG). | |
164 See `set-tty-dynamic-color-specs'. | |
165 */ | |
166 ()) | |
167 { | |
168 return list2 (Vtty_dynamic_color_fg, Vtty_dynamic_color_bg); | |
169 } | |
170 | |
171 #endif /* 0 */ | |
172 | |
173 static int | |
440 | 174 tty_initialize_color_instance (Lisp_Color_Instance *c, Lisp_Object name, |
2286 | 175 Lisp_Object UNUSED (device), |
176 Error_Behavior UNUSED (errb)) | |
428 | 177 { |
178 Lisp_Object result; | |
179 | |
180 name = Fintern (name, Qnil); | |
181 result = assq_no_quit (name, Vtty_color_alist); | |
182 | |
183 if (NILP (result)) | |
184 { | |
185 #if 0 | |
186 if (!STRINGP (Vtty_dynamic_color_fg) | |
187 && !STRINGP (Vtty_dynamic_color_bg)) | |
188 #endif | |
189 return 0; | |
190 } | |
191 | |
192 /* Don't allocate the data until we're sure that we will succeed. */ | |
3092 | 193 #ifdef NEW_GC |
5120
d1247f3cc363
latest work on lisp-object workspace;
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
194 c->data = |
d1247f3cc363
latest work on lisp-object workspace;
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
195 XTTY_COLOR_INSTANCE_DATA (ALLOC_LISP_OBJECT (tty_color_instance_data)); |
3092 | 196 #else /* not NEW_GC */ |
428 | 197 c->data = xnew (struct tty_color_instance_data); |
3092 | 198 #endif /* not NEW_GC */ |
428 | 199 COLOR_INSTANCE_TTY_SYMBOL (c) = name; |
200 | |
201 return 1; | |
202 } | |
203 | |
204 static void | |
440 | 205 tty_mark_color_instance (Lisp_Color_Instance *c) |
428 | 206 { |
207 mark_object (COLOR_INSTANCE_TTY_SYMBOL (c)); | |
208 } | |
209 | |
210 static void | |
2286 | 211 tty_print_color_instance (Lisp_Color_Instance *UNUSED (c), |
212 Lisp_Object UNUSED (printcharfun), | |
213 int UNUSED (escapeflag)) | |
428 | 214 { |
215 } | |
216 | |
217 static void | |
4710
3a87551bfeb5
Fixes for a number of minor warnings issued by gcc. See xemacs-patches message
Jerry James <james@xemacs.org>
parents:
4353
diff
changeset
|
218 tty_finalize_color_instance (Lisp_Color_Instance *UNUSED_IF_NEW_GC (c)) |
428 | 219 { |
4141 | 220 #ifndef NEW_GC |
428 | 221 if (c->data) |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
222 xfree (c->data); |
4141 | 223 #endif /* not NEW_GC */ |
4117 | 224 } |
428 | 225 |
226 static int | |
440 | 227 tty_color_instance_equal (Lisp_Color_Instance *c1, |
228 Lisp_Color_Instance *c2, | |
2286 | 229 int UNUSED (depth)) |
428 | 230 { |
231 return (EQ (COLOR_INSTANCE_TTY_SYMBOL (c1), | |
232 COLOR_INSTANCE_TTY_SYMBOL (c2))); | |
233 } | |
234 | |
2515 | 235 static Hashcode |
2286 | 236 tty_color_instance_hash (Lisp_Color_Instance *c, int UNUSED (depth)) |
428 | 237 { |
238 return LISP_HASH (COLOR_INSTANCE_TTY_SYMBOL (c)); | |
239 } | |
240 | |
241 static int | |
2286 | 242 tty_valid_color_name_p (struct device *UNUSED (d), Lisp_Object color) |
428 | 243 { |
244 return (!NILP (assoc_no_quit (Fintern (color, Qnil), Vtty_color_alist))); | |
245 #if 0 | |
246 || STRINGP (Vtty_dynamic_color_fg) | |
247 || STRINGP (Vtty_dynamic_color_bg) | |
248 #endif | |
249 } | |
250 | |
251 | |
252 static int | |
440 | 253 tty_initialize_font_instance (Lisp_Font_Instance *f, Lisp_Object name, |
2286 | 254 Lisp_Object UNUSED (device), |
255 Error_Behavior UNUSED (errb)) | |
428 | 256 { |
867 | 257 Ibyte *str = XSTRING_DATA (name); |
428 | 258 Lisp_Object charset = Qnil; |
259 | |
2367 | 260 if (qxestrncmp_ascii (str, "normal", 6)) |
428 | 261 return 0; |
262 str += 6; | |
263 if (*str) | |
264 { | |
265 #ifdef MULE | |
266 if (*str != '/') | |
267 return 0; | |
268 str++; | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
269 charset = Ffind_charset (intern_istring (str)); |
428 | 270 if (NILP (charset)) |
271 return 0; | |
272 #else | |
273 return 0; | |
274 #endif | |
275 } | |
276 | |
277 /* Don't allocate the data until we're sure that we will succeed. */ | |
3092 | 278 #ifdef NEW_GC |
5120
d1247f3cc363
latest work on lisp-object workspace;
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
279 f->data = |
d1247f3cc363
latest work on lisp-object workspace;
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
280 XTTY_FONT_INSTANCE_DATA (ALLOC_LISP_OBJECT (tty_font_instance_data)); |
3092 | 281 #else /* not NEW_GC */ |
428 | 282 f->data = xnew (struct tty_font_instance_data); |
3092 | 283 #endif /* not NEW_GC */ |
428 | 284 FONT_INSTANCE_TTY_CHARSET (f) = charset; |
285 #ifdef MULE | |
286 if (CHARSETP (charset)) | |
287 f->width = XCHARSET_COLUMNS (charset); | |
288 else | |
289 #endif | |
290 f->width = 1; | |
291 | |
292 f->proportional_p = 0; | |
293 f->ascent = f->height = 1; | |
294 f->descent = 0; | |
295 | |
296 return 1; | |
297 } | |
298 | |
299 static void | |
440 | 300 tty_mark_font_instance (Lisp_Font_Instance *f) |
428 | 301 { |
302 mark_object (FONT_INSTANCE_TTY_CHARSET (f)); | |
303 } | |
304 | |
305 static void | |
2286 | 306 tty_print_font_instance (Lisp_Font_Instance *UNUSED (f), |
307 Lisp_Object UNUSED (printcharfun), | |
308 int UNUSED (escapeflag)) | |
428 | 309 { |
310 } | |
311 | |
312 static void | |
4710
3a87551bfeb5
Fixes for a number of minor warnings issued by gcc. See xemacs-patches message
Jerry James <james@xemacs.org>
parents:
4353
diff
changeset
|
313 tty_finalize_font_instance (Lisp_Font_Instance *UNUSED_IF_NEW_GC (f)) |
428 | 314 { |
4141 | 315 #ifndef NEW_GC |
428 | 316 if (f->data) |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
317 xfree (f->data); |
4141 | 318 #endif /* not NEW_GC */ |
4117 | 319 } |
428 | 320 |
321 static Lisp_Object | |
2527 | 322 tty_font_list (Lisp_Object UNUSED (pattern), Lisp_Object UNUSED (device), |
2286 | 323 Lisp_Object UNUSED (maxnumber)) |
428 | 324 { |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4710
diff
changeset
|
325 return list1 (build_ascstring ("normal")); |
428 | 326 } |
327 | |
328 #ifdef MULE | |
329 | |
330 static int | |
2286 | 331 tty_font_spec_matches_charset (struct device *UNUSED (d), Lisp_Object charset, |
867 | 332 const Ibyte *nonreloc, Lisp_Object reloc, |
872 | 333 Bytecount offset, Bytecount length, |
3841 | 334 enum font_specifier_matchspec_stages stage) |
428 | 335 { |
867 | 336 const Ibyte *the_nonreloc = nonreloc; |
428 | 337 |
5015
d95c102a96d3
cleanups for specifier font stages, from ben-unicode-internal (preparation for eliminating shadowed warnings)
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
338 if (stage == STAGE_FINAL) |
872 | 339 return 0; |
340 | |
428 | 341 if (!the_nonreloc) |
342 the_nonreloc = XSTRING_DATA (reloc); | |
343 fixup_internal_substring (nonreloc, reloc, offset, &length); | |
344 the_nonreloc += offset; | |
345 | |
4353
4143b78d0df0
Merge an old patch of Ben's, involving font instantiation and charsets.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4141
diff
changeset
|
346 if (NILP (charset)) |
428 | 347 return !memchr (the_nonreloc, '/', length); |
867 | 348 the_nonreloc = (const Ibyte *) memchr (the_nonreloc, '/', length); |
428 | 349 if (!the_nonreloc) |
350 return 0; | |
351 the_nonreloc++; | |
352 { | |
793 | 353 Lisp_Object s = symbol_name (XSYMBOL (XCHARSET_NAME (charset))); |
354 return !qxestrcmp (the_nonreloc, XSTRING_DATA (s)); | |
428 | 355 } |
356 } | |
357 | |
358 /* find a font spec that matches font spec FONT and also matches | |
359 (the registry of) CHARSET. */ | |
360 static Lisp_Object | |
361 tty_find_charset_font (Lisp_Object device, Lisp_Object font, | |
3659 | 362 Lisp_Object charset, |
363 enum font_specifier_matchspec_stages stage) | |
428 | 364 { |
867 | 365 Ibyte *fontname = XSTRING_DATA (font); |
428 | 366 |
5015
d95c102a96d3
cleanups for specifier font stages, from ben-unicode-internal (preparation for eliminating shadowed warnings)
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
367 if (stage == STAGE_FINAL) |
872 | 368 return Qnil; |
369 | |
442 | 370 if (strchr ((const char *) fontname, '/')) |
428 | 371 { |
372 if (tty_font_spec_matches_charset (XDEVICE (device), charset, 0, | |
5015
d95c102a96d3
cleanups for specifier font stages, from ben-unicode-internal (preparation for eliminating shadowed warnings)
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
373 font, 0, -1, STAGE_INITIAL)) |
428 | 374 return font; |
375 return Qnil; | |
376 } | |
377 | |
4353
4143b78d0df0
Merge an old patch of Ben's, involving font instantiation and charsets.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4141
diff
changeset
|
378 if (NILP (charset)) |
428 | 379 return font; |
380 | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4710
diff
changeset
|
381 return concat3 (font, build_ascstring ("/"), |
428 | 382 Fsymbol_name (XCHARSET_NAME (charset))); |
383 } | |
384 | |
385 #endif /* MULE */ | |
386 | |
387 | |
388 /************************************************************************/ | |
389 /* initialization */ | |
390 /************************************************************************/ | |
391 | |
392 void | |
393 syms_of_objects_tty (void) | |
394 { | |
3092 | 395 #ifdef NEW_GC |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents:
4710
diff
changeset
|
396 INIT_LISP_OBJECT (tty_color_instance_data); |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents:
4710
diff
changeset
|
397 INIT_LISP_OBJECT (tty_font_instance_data); |
3092 | 398 #endif /* NEW_GC */ |
399 | |
428 | 400 DEFSUBR (Fregister_tty_color); |
401 DEFSUBR (Funregister_tty_color); | |
402 DEFSUBR (Ffind_tty_color); | |
403 #if 0 | |
404 DEFSUBR (Fset_tty_dynamic_color_specs); | |
405 DEFSUBR (Ftty_dynamic_color_specs); | |
406 #endif | |
407 } | |
408 | |
409 void | |
410 console_type_create_objects_tty (void) | |
411 { | |
412 /* object methods */ | |
413 CONSOLE_HAS_METHOD (tty, initialize_color_instance); | |
414 CONSOLE_HAS_METHOD (tty, mark_color_instance); | |
415 CONSOLE_HAS_METHOD (tty, print_color_instance); | |
416 CONSOLE_HAS_METHOD (tty, finalize_color_instance); | |
417 CONSOLE_HAS_METHOD (tty, color_instance_equal); | |
418 CONSOLE_HAS_METHOD (tty, color_instance_hash); | |
419 CONSOLE_HAS_METHOD (tty, valid_color_name_p); | |
2527 | 420 CONSOLE_HAS_METHOD (tty, color_list); |
428 | 421 |
422 CONSOLE_HAS_METHOD (tty, initialize_font_instance); | |
423 CONSOLE_HAS_METHOD (tty, mark_font_instance); | |
424 CONSOLE_HAS_METHOD (tty, print_font_instance); | |
425 CONSOLE_HAS_METHOD (tty, finalize_font_instance); | |
2527 | 426 CONSOLE_HAS_METHOD (tty, font_list); |
428 | 427 #ifdef MULE |
428 CONSOLE_HAS_METHOD (tty, font_spec_matches_charset); | |
429 CONSOLE_HAS_METHOD (tty, find_charset_font); | |
430 #endif | |
431 } | |
432 | |
433 void | |
434 vars_of_objects_tty (void) | |
435 { | |
436 staticpro (&Vtty_color_alist); | |
437 Vtty_color_alist = Qnil; | |
438 | |
439 #if 0 | |
440 staticpro (&Vtty_dynamic_color_fg); | |
441 Vtty_dynamic_color_fg = Qnil; | |
442 | |
443 staticpro (&Vtty_dynamic_color_bg); | |
444 Vtty_dynamic_color_bg = Qnil; | |
445 #endif | |
446 } |