428
+ − 1 /* TTY-specific Lisp objects.
+ − 2 Copyright (C) 1995 Board of Trustees, University of Illinois.
771
+ − 3 Copyright (C) 1995, 1996, 2001 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
+ − 27 #include "console-tty.h"
+ − 28 #include "insdel.h"
+ − 29 #include "objects-tty.h"
+ − 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
+ − 40 DEFUN ("register-tty-color", Fregister_tty_color, 3, 3, 0, /*
+ − 41 Register COLOR as a recognized TTY color.
+ − 42 COLOR should be a string.
+ − 43 Strings FG-STRING and BG-STRING should specify the escape sequences to
+ − 44 set the foreground and background to the given color, respectively.
+ − 45 */
+ − 46 (color, fg_string, bg_string))
+ − 47 {
+ − 48 CHECK_STRING (color);
+ − 49 CHECK_STRING (fg_string);
+ − 50 CHECK_STRING (bg_string);
+ − 51
+ − 52 color = Fintern (color, Qnil);
+ − 53 Vtty_color_alist = Fremassq (color, Vtty_color_alist);
+ − 54 Vtty_color_alist = Fcons (Fcons (color, Fcons (fg_string, bg_string)),
+ − 55 Vtty_color_alist);
+ − 56
+ − 57 return Qnil;
+ − 58 }
+ − 59
+ − 60 DEFUN ("unregister-tty-color", Funregister_tty_color, 1, 1, 0, /*
+ − 61 Unregister COLOR as a recognized TTY color.
+ − 62 */
+ − 63 (color))
+ − 64 {
+ − 65 CHECK_STRING (color);
+ − 66
+ − 67 color = Fintern (color, Qnil);
+ − 68 Vtty_color_alist = Fremassq (color, Vtty_color_alist);
+ − 69 return Qnil;
+ − 70 }
+ − 71
+ − 72 DEFUN ("find-tty-color", Ffind_tty_color, 1, 1, 0, /*
+ − 73 Look up COLOR in the list of registered TTY colors.
+ − 74 If it is found, return a list (FG-STRING BG-STRING) of the escape
+ − 75 sequences used to set the foreground and background to the color, respectively.
+ − 76 If it is not found, return nil.
+ − 77 */
+ − 78 (color))
+ − 79 {
+ − 80 Lisp_Object result;
+ − 81
+ − 82 CHECK_STRING (color);
+ − 83
+ − 84 result = Fassq (Fintern (color, Qnil), Vtty_color_alist);
+ − 85 if (!NILP (result))
+ − 86 return list2 (Fcar (Fcdr (result)), Fcdr (Fcdr (result)));
+ − 87 else
+ − 88 return Qnil;
+ − 89 }
+ − 90
+ − 91 DEFUN ("tty-color-list", Ftty_color_list, 0, 0, 0, /*
+ − 92 Return a list of the registered TTY colors.
+ − 93 */
+ − 94 ())
+ − 95 {
+ − 96 Lisp_Object result = Qnil;
+ − 97 Lisp_Object rest;
+ − 98
+ − 99 LIST_LOOP (rest, Vtty_color_alist)
+ − 100 {
+ − 101 result = Fcons (Fsymbol_name (XCAR (XCAR (rest))), result);
+ − 102 }
+ − 103
+ − 104 return Fnreverse (result);
+ − 105 }
+ − 106
+ − 107 #if 0
+ − 108
+ − 109 /* This approach is too simplistic. The problem is that the
+ − 110 dynamic color settings apply to *all* text in the default color,
+ − 111 not just the text output after the escape sequence has been given. */
+ − 112
+ − 113 DEFUN ("set-tty-dynamic-color-specs", Fset_tty_dynamic_color_specs, 2, 2, 0, /*
+ − 114 Set the dynamic color specifications for TTY's.
+ − 115 FG and BG should be either nil or vaguely printf-like strings,
+ − 116 where each occurrence of %s is replaced with the color name and each
+ − 117 occurrence of %% is replaced with a single % character.
+ − 118 */
+ − 119 (fg, bg))
+ − 120 {
+ − 121 if (!NILP (fg))
+ − 122 CHECK_STRING (fg);
+ − 123 if (!NILP (bg))
+ − 124 CHECK_STRING (bg);
+ − 125
+ − 126 Vtty_dynamic_color_fg = fg;
+ − 127 Vtty_dynamic_color_bg = bg;
+ − 128
+ − 129 return Qnil;
+ − 130 }
+ − 131
+ − 132 DEFUN ("tty-dynamic-color-specs", Ftty_dynamic_color_specs, 0, 0, 0, /*
+ − 133 Return the dynamic color specifications for TTY's as a list of (FG BG).
+ − 134 See `set-tty-dynamic-color-specs'.
+ − 135 */
+ − 136 ())
+ − 137 {
+ − 138 return list2 (Vtty_dynamic_color_fg, Vtty_dynamic_color_bg);
+ − 139 }
+ − 140
+ − 141 #endif /* 0 */
+ − 142
+ − 143 static int
440
+ − 144 tty_initialize_color_instance (Lisp_Color_Instance *c, Lisp_Object name,
578
+ − 145 Lisp_Object device, Error_Behavior errb)
428
+ − 146 {
+ − 147 Lisp_Object result;
+ − 148
+ − 149 name = Fintern (name, Qnil);
+ − 150 result = assq_no_quit (name, Vtty_color_alist);
+ − 151
+ − 152 if (NILP (result))
+ − 153 {
+ − 154 #if 0
+ − 155 if (!STRINGP (Vtty_dynamic_color_fg)
+ − 156 && !STRINGP (Vtty_dynamic_color_bg))
+ − 157 #endif
+ − 158 return 0;
+ − 159 }
+ − 160
+ − 161 /* Don't allocate the data until we're sure that we will succeed. */
+ − 162 c->data = xnew (struct tty_color_instance_data);
+ − 163 COLOR_INSTANCE_TTY_SYMBOL (c) = name;
+ − 164
+ − 165 return 1;
+ − 166 }
+ − 167
+ − 168 static void
440
+ − 169 tty_mark_color_instance (Lisp_Color_Instance *c)
428
+ − 170 {
+ − 171 mark_object (COLOR_INSTANCE_TTY_SYMBOL (c));
+ − 172 }
+ − 173
+ − 174 static void
440
+ − 175 tty_print_color_instance (Lisp_Color_Instance *c,
428
+ − 176 Lisp_Object printcharfun,
+ − 177 int escapeflag)
+ − 178 {
+ − 179 }
+ − 180
+ − 181 static void
440
+ − 182 tty_finalize_color_instance (Lisp_Color_Instance *c)
428
+ − 183 {
+ − 184 if (c->data)
+ − 185 xfree (c->data);
+ − 186 }
+ − 187
+ − 188 static int
440
+ − 189 tty_color_instance_equal (Lisp_Color_Instance *c1,
+ − 190 Lisp_Color_Instance *c2,
428
+ − 191 int depth)
+ − 192 {
+ − 193 return (EQ (COLOR_INSTANCE_TTY_SYMBOL (c1),
+ − 194 COLOR_INSTANCE_TTY_SYMBOL (c2)));
+ − 195 }
+ − 196
+ − 197 static unsigned long
440
+ − 198 tty_color_instance_hash (Lisp_Color_Instance *c, int depth)
428
+ − 199 {
+ − 200 return LISP_HASH (COLOR_INSTANCE_TTY_SYMBOL (c));
+ − 201 }
+ − 202
+ − 203 static int
+ − 204 tty_valid_color_name_p (struct device *d, Lisp_Object color)
+ − 205 {
+ − 206 return (!NILP (assoc_no_quit (Fintern (color, Qnil), Vtty_color_alist)));
+ − 207 #if 0
+ − 208 || STRINGP (Vtty_dynamic_color_fg)
+ − 209 || STRINGP (Vtty_dynamic_color_bg)
+ − 210 #endif
+ − 211 }
+ − 212
+ − 213
+ − 214 static int
440
+ − 215 tty_initialize_font_instance (Lisp_Font_Instance *f, Lisp_Object name,
578
+ − 216 Lisp_Object device, Error_Behavior errb)
428
+ − 217 {
665
+ − 218 Intbyte *str = XSTRING_DATA (name);
428
+ − 219 Lisp_Object charset = Qnil;
+ − 220
771
+ − 221 if (qxestrncmp_c (str, "normal", 6))
428
+ − 222 return 0;
+ − 223 str += 6;
+ − 224 if (*str)
+ − 225 {
+ − 226 #ifdef MULE
+ − 227 if (*str != '/')
+ − 228 return 0;
+ − 229 str++;
771
+ − 230 charset = Ffind_charset (intern_int (str));
428
+ − 231 if (NILP (charset))
+ − 232 return 0;
+ − 233 #else
+ − 234 return 0;
+ − 235 #endif
+ − 236 }
+ − 237
+ − 238 /* Don't allocate the data until we're sure that we will succeed. */
+ − 239 f->data = xnew (struct tty_font_instance_data);
+ − 240 FONT_INSTANCE_TTY_CHARSET (f) = charset;
+ − 241 #ifdef MULE
+ − 242 if (CHARSETP (charset))
+ − 243 f->width = XCHARSET_COLUMNS (charset);
+ − 244 else
+ − 245 #endif
+ − 246 f->width = 1;
+ − 247
+ − 248 f->proportional_p = 0;
+ − 249 f->ascent = f->height = 1;
+ − 250 f->descent = 0;
+ − 251
+ − 252 return 1;
+ − 253 }
+ − 254
+ − 255 static void
440
+ − 256 tty_mark_font_instance (Lisp_Font_Instance *f)
428
+ − 257 {
+ − 258 mark_object (FONT_INSTANCE_TTY_CHARSET (f));
+ − 259 }
+ − 260
+ − 261 static void
440
+ − 262 tty_print_font_instance (Lisp_Font_Instance *f,
428
+ − 263 Lisp_Object printcharfun,
+ − 264 int escapeflag)
+ − 265 {
+ − 266 }
+ − 267
+ − 268 static void
440
+ − 269 tty_finalize_font_instance (Lisp_Font_Instance *f)
428
+ − 270 {
+ − 271 if (f->data)
+ − 272 xfree (f->data);
+ − 273 }
+ − 274
+ − 275 static Lisp_Object
+ − 276 tty_list_fonts (Lisp_Object pattern, Lisp_Object device)
+ − 277 {
+ − 278 return list1 (build_string ("normal"));
+ − 279 }
+ − 280
+ − 281 #ifdef MULE
+ − 282
+ − 283 static int
+ − 284 tty_font_spec_matches_charset (struct device *d, Lisp_Object charset,
665
+ − 285 const Intbyte *nonreloc, Lisp_Object reloc,
428
+ − 286 Bytecount offset, Bytecount length)
+ − 287 {
665
+ − 288 const Intbyte *the_nonreloc = nonreloc;
428
+ − 289
+ − 290 if (!the_nonreloc)
+ − 291 the_nonreloc = XSTRING_DATA (reloc);
+ − 292 fixup_internal_substring (nonreloc, reloc, offset, &length);
+ − 293 the_nonreloc += offset;
+ − 294
+ − 295 if (UNBOUNDP (charset))
+ − 296 return !memchr (the_nonreloc, '/', length);
665
+ − 297 the_nonreloc = (const Intbyte *) memchr (the_nonreloc, '/', length);
428
+ − 298 if (!the_nonreloc)
+ − 299 return 0;
+ − 300 the_nonreloc++;
+ − 301 {
440
+ − 302 Lisp_String *s = symbol_name (XSYMBOL (XCHARSET_NAME (charset)));
442
+ − 303 return !strcmp ((const char *) the_nonreloc,
+ − 304 (const char *) string_data (s));
428
+ − 305 }
+ − 306 }
+ − 307
+ − 308 /* find a font spec that matches font spec FONT and also matches
+ − 309 (the registry of) CHARSET. */
+ − 310 static Lisp_Object
+ − 311 tty_find_charset_font (Lisp_Object device, Lisp_Object font,
+ − 312 Lisp_Object charset)
+ − 313 {
665
+ − 314 Intbyte *fontname = XSTRING_DATA (font);
428
+ − 315
442
+ − 316 if (strchr ((const char *) fontname, '/'))
428
+ − 317 {
+ − 318 if (tty_font_spec_matches_charset (XDEVICE (device), charset, 0,
+ − 319 font, 0, -1))
+ − 320 return font;
+ − 321 return Qnil;
+ − 322 }
+ − 323
+ − 324 if (UNBOUNDP (charset))
+ − 325 return font;
+ − 326
+ − 327 return concat3 (font, build_string ("/"),
+ − 328 Fsymbol_name (XCHARSET_NAME (charset)));
+ − 329 }
+ − 330
+ − 331 #endif /* MULE */
+ − 332
+ − 333
+ − 334 /************************************************************************/
+ − 335 /* initialization */
+ − 336 /************************************************************************/
+ − 337
+ − 338 void
+ − 339 syms_of_objects_tty (void)
+ − 340 {
+ − 341 DEFSUBR (Fregister_tty_color);
+ − 342 DEFSUBR (Funregister_tty_color);
+ − 343 DEFSUBR (Ffind_tty_color);
+ − 344 DEFSUBR (Ftty_color_list);
+ − 345 #if 0
+ − 346 DEFSUBR (Fset_tty_dynamic_color_specs);
+ − 347 DEFSUBR (Ftty_dynamic_color_specs);
+ − 348 #endif
+ − 349 }
+ − 350
+ − 351 void
+ − 352 console_type_create_objects_tty (void)
+ − 353 {
+ − 354 /* object methods */
+ − 355 CONSOLE_HAS_METHOD (tty, initialize_color_instance);
+ − 356 CONSOLE_HAS_METHOD (tty, mark_color_instance);
+ − 357 CONSOLE_HAS_METHOD (tty, print_color_instance);
+ − 358 CONSOLE_HAS_METHOD (tty, finalize_color_instance);
+ − 359 CONSOLE_HAS_METHOD (tty, color_instance_equal);
+ − 360 CONSOLE_HAS_METHOD (tty, color_instance_hash);
+ − 361 CONSOLE_HAS_METHOD (tty, valid_color_name_p);
+ − 362
+ − 363 CONSOLE_HAS_METHOD (tty, initialize_font_instance);
+ − 364 CONSOLE_HAS_METHOD (tty, mark_font_instance);
+ − 365 CONSOLE_HAS_METHOD (tty, print_font_instance);
+ − 366 CONSOLE_HAS_METHOD (tty, finalize_font_instance);
+ − 367 CONSOLE_HAS_METHOD (tty, list_fonts);
+ − 368 #ifdef MULE
+ − 369 CONSOLE_HAS_METHOD (tty, font_spec_matches_charset);
+ − 370 CONSOLE_HAS_METHOD (tty, find_charset_font);
+ − 371 #endif
+ − 372 }
+ − 373
+ − 374 void
+ − 375 vars_of_objects_tty (void)
+ − 376 {
+ − 377 staticpro (&Vtty_color_alist);
+ − 378 Vtty_color_alist = Qnil;
+ − 379
+ − 380 #if 0
+ − 381 staticpro (&Vtty_dynamic_color_fg);
+ − 382 Vtty_dynamic_color_fg = Qnil;
+ − 383
+ − 384 staticpro (&Vtty_dynamic_color_bg);
+ − 385 Vtty_dynamic_color_bg = Qnil;
+ − 386 #endif
+ − 387 }