Merge from mainline.
[bpt/emacs.git] / src / xfaces.c
index 8ef3c81..a26289e 100644 (file)
@@ -1,8 +1,6 @@
 /* xfaces.c -- "Face" primitives.
 
-Copyright (C) 1993, 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-  2005, 2006, 2007, 2008, 2009, 2010
-  Free Software Foundation, Inc.
+Copyright (C) 1993-1994, 1998-2011  Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -275,6 +273,8 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <X11/Xos.h>
 #define USG
 #define __TIMEVAL__
+#if defined USG || defined __TIMEVAL__ /* Don't warn about unused macros.  */
+#endif
 #else /* not XOS_NEEDS_TIME_H */
 #include <X11/Xos.h>
 #endif /* not XOS_NEEDS_TIME_H */
@@ -299,16 +299,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
 
-/* Make a copy of string S on the stack using alloca.  Value is a pointer
-   to the copy.  */
-
-#define STRDUPA(S) strcpy ((char *) alloca (strlen ((S)) + 1), (S))
-
-/* Make a copy of the contents of Lisp string S on the stack using
-   alloca.  Value is a pointer to the copy.  */
-
-#define LSTRDUPA(S) STRDUPA (SDATA ((S)))
-
 /* Size of hash table of realized faces in face caches (should be a
    prime number).  */
 
@@ -316,25 +306,33 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 /* Keyword symbols used for face attribute names.  */
 
-Lisp_Object QCfamily, QCheight, QCweight, QCslant, QCunderline;
-Lisp_Object QCinverse_video, QCforeground, QCbackground, QCstipple;
-Lisp_Object QCwidth, QCfont, QCbold, QCitalic;
-Lisp_Object QCreverse_video;
-Lisp_Object QCoverline, QCstrike_through, QCbox, QCinherit;
-Lisp_Object QCfontset;
+Lisp_Object QCfamily, QCheight, QCweight, QCslant;
+static Lisp_Object QCunderline;
+static Lisp_Object QCinverse_video, QCstipple;
+Lisp_Object QCforeground, QCbackground;
+Lisp_Object QCwidth;
+static Lisp_Object QCfont, QCbold, QCitalic;
+static Lisp_Object QCreverse_video;
+static Lisp_Object QCoverline, QCstrike_through, QCbox, QCinherit;
+static Lisp_Object QCfontset;
 
 /* Symbols used for attribute values.  */
 
-Lisp_Object Qnormal, Qbold, Qultra_light, Qextra_light, Qlight;
-Lisp_Object Qsemi_light, Qsemi_bold, Qextra_bold, Qultra_bold;
-Lisp_Object Qoblique, Qitalic, Qreverse_oblique, Qreverse_italic;
-Lisp_Object Qultra_condensed, Qextra_condensed, Qcondensed;
-Lisp_Object Qsemi_condensed, Qsemi_expanded, Qexpanded, Qextra_expanded;
-Lisp_Object Qultra_expanded;
-Lisp_Object Qreleased_button, Qpressed_button;
-Lisp_Object QCstyle, QCcolor, QCline_width;
-Lisp_Object Qunspecified;
-Lisp_Object Qignore_defface;
+Lisp_Object Qnormal;
+Lisp_Object Qbold;
+static Lisp_Object Qultra_light, Qextra_light, Qlight;
+static Lisp_Object Qsemi_light, Qsemi_bold, Qextra_bold, Qultra_bold;
+static Lisp_Object Qoblique, Qreverse_oblique, Qreverse_italic;
+Lisp_Object Qitalic;
+static Lisp_Object Qultra_condensed, Qextra_condensed;
+Lisp_Object Qcondensed;
+static Lisp_Object Qsemi_condensed, Qsemi_expanded, Qextra_expanded;
+Lisp_Object Qexpanded;
+static Lisp_Object Qultra_expanded;
+static Lisp_Object Qreleased_button, Qpressed_button;
+static Lisp_Object QCstyle, QCcolor, QCline_width;
+Lisp_Object Qunspecified;      /* used in dosfns.c */
+static Lisp_Object Qignore_defface;
 
 char unspecified_fg[] = "unspecified-fg", unspecified_bg[] = "unspecified-bg";
 
@@ -345,22 +343,18 @@ Lisp_Object Qframe_set_background_mode;
 
 /* Names of basic faces.  */
 
-Lisp_Object Qdefault, Qtool_bar, Qregion, Qfringe;
-Lisp_Object Qheader_line, Qscroll_bar, Qcursor, Qborder, Qmouse, Qmenu;
-Lisp_Object Qmode_line_inactive, Qvertical_border;
+Lisp_Object Qdefault, Qtool_bar, Qfringe;
+static Lisp_Object Qregion;
+Lisp_Object Qheader_line, Qscroll_bar, Qcursor;
+static Lisp_Object Qborder, Qmouse, Qmenu;
+Lisp_Object Qmode_line_inactive;
+static Lisp_Object Qvertical_border;
 
 /* The symbol `face-alias'.  A symbols having that property is an
    alias for another face.  Value of the property is the name of
    the aliased face.  */
 
-Lisp_Object Qface_alias;
-
-/* Default stipple pattern used on monochrome displays.  This stipple
-   pattern is used on monochrome displays instead of shades of gray
-   for a face background color.  See `set-face-stipple' for possible
-   values for this variable.  */
-
-Lisp_Object Vface_default_stipple;
+static Lisp_Object Qface_alias;
 
 /* Alist of alternative font families.  Each element is of the form
    (FAMILY FAMILY1 FAMILY2 ...).  If fonts of FAMILY can't be loaded,
@@ -380,20 +374,8 @@ Lisp_Object Vface_alternative_font_registry_alist;
    font may be scaled if its name matches a regular expression in the
    list.  */
 
-Lisp_Object Vscalable_fonts_allowed, Qscalable_fonts_allowed;
-
-/* List of regular expressions that matches names of fonts to ignore. */
-
-Lisp_Object Vface_ignored_fonts;
-
-/* Alist of font name patterns vs the rescaling factor.  */
-
-Lisp_Object Vface_font_rescale_alist;
+static Lisp_Object Qscalable_fonts_allowed;
 
-/* Maximum number of fonts to consider in font_list.  If not an
-   integer > 0, DEFAULT_FONT_LIST_LIMIT is used instead.  */
-
-Lisp_Object Vfont_list_limit;
 #define DEFAULT_FONT_LIST_LIMIT 100
 
 /* The symbols `foreground-color' and `background-color' which can be
@@ -408,35 +390,11 @@ Lisp_Object Qface;
 
 /* Property for basic faces which other faces cannot inherit.  */
 
-Lisp_Object Qface_no_inherit;
+static Lisp_Object Qface_no_inherit;
 
 /* Error symbol for wrong_type_argument in load_pixmap.  */
 
-Lisp_Object Qbitmap_spec_p;
-
-/* Alist of global face definitions.  Each element is of the form
-   (FACE . LFACE) where FACE is a symbol naming a face and LFACE
-   is a Lisp vector of face attributes.  These faces are used
-   to initialize faces for new frames.  */
-
-Lisp_Object Vface_new_frame_defaults;
-
-/* Alist of face remappings.  Each element is of the form:
-   (FACE REPLACEMENT...) which causes display of the face FACE to use
-   REPLACEMENT... instead.  REPLACEMENT... is interpreted the same way
-   the value of a `face' text property is: it may be (1) A face name,
-   (2) A list of face names, (3) A property-list of face attribute/value
-   pairs, or (4) A list of face names intermixed with lists containing
-   face attribute/value pairs.
-
-   Multiple entries in REPLACEMENT... are merged together to form the final
-   result, with faces or attributes earlier in the list taking precedence
-   over those that are later.
-
-   Face-name remapping cycles are suppressed; recursive references use
-   the underlying face instead of the remapped face.  */
-
-Lisp_Object Vface_remapping_alist;
+static Lisp_Object Qbitmap_spec_p;
 
 /* The next ID to assign to Lisp faces.  */
 
@@ -449,15 +407,11 @@ static int lface_id_to_name_size;
 
 /* TTY color-related functions (defined in tty-colors.el).  */
 
-Lisp_Object Qtty_color_desc, Qtty_color_by_index, Qtty_color_standard_values;
+static Lisp_Object Qtty_color_desc, Qtty_color_by_index, Qtty_color_standard_values;
 
 /* The name of the function used to compute colors on TTYs.  */
 
-Lisp_Object Qtty_color_alist;
-
-/* An alist of defined terminal colors and their RGB values.  */
-
-Lisp_Object Vtty_defined_color_alist;
+static Lisp_Object Qtty_color_alist;
 
 /* Counter for calls to clear_face_cache.  If this counter reaches
    CLEAR_FONT_TABLE_COUNT, and a frame has more than
@@ -477,7 +431,7 @@ int face_change_count;
    display.   This is a kluge to suppress `bold black' foreground text
    which is hard to read on an LCD monitor.  */
 
-int tty_suppress_bold_inverse_default_colors_p;
+static int tty_suppress_bold_inverse_default_colors_p;
 
 /* A list of the form `((x . y))' used to avoid consing in
    Finternal_set_lisp_face_attribute.  */
@@ -495,7 +449,7 @@ static int ngcs;
 /* Non-zero means the definition of the `menu' face for new frames has
    been changed.  */
 
-int menu_face_changed_default;
+static int menu_face_changed_default;
 
 \f
 /* Function prototypes.  */
@@ -665,6 +619,8 @@ x_free_colors (struct frame *f, long unsigned int *pixels, int npixels)
 }
 
 
+#ifdef USE_X_TOOLKIT
+
 /* Free colors used on frame F.  PIXELS is an array of NPIXELS pixel
    color values.  Interrupt input must be blocked when this function
    is called.  */
@@ -685,7 +641,7 @@ x_free_dpy_colors (Display *dpy, Screen *screen, Colormap cmap, long unsigned in
       XFreeColors (dpy, cmap, pixels, npixels, 0);
     }
 }
-
+#endif /* USE_X_TOOLKIT */
 
 /* Create and return a GC for use on frame F.  GC values and mask
    are given by XGCV and MASK.  */
@@ -765,12 +721,14 @@ x_free_gc (struct frame *f, GC gc)
    are in ISO8859-1.  */
 
 int
-xstrcasecmp (const unsigned char *s1, const unsigned char *s2)
+xstrcasecmp (const char *s1, const char *s2)
 {
   while (*s1 && *s2)
     {
-      unsigned char c1 = tolower (*s1);
-      unsigned char c2 = tolower (*s2);
+      unsigned char b1 = *s1;
+      unsigned char b2 = *s2;
+      unsigned char c1 = tolower (b1);
+      unsigned char c2 = tolower (b2);
       if (c1 != c2)
        return c1 < c2 ? -1 : 1;
       ++s1, ++s2;
@@ -894,7 +852,6 @@ clear_face_cache (int clear_fonts_p)
 {
 #ifdef HAVE_WINDOW_SYSTEM
   Lisp_Object tail, frame;
-  struct frame *f;
 
   if (clear_fonts_p
       || ++clear_font_table_count == CLEAR_FONT_TABLE_COUNT)
@@ -922,7 +879,7 @@ clear_face_cache (int clear_fonts_p)
       /* Clear GCs of realized faces.  */
       FOR_EACH_FRAME (tail, frame)
        {
-         f = XFRAME (frame);
+         struct frame *f = XFRAME (frame);
          if (FRAME_WINDOW_P (f))
              clear_face_gcs (FRAME_FACE_CACHE (f));
        }
@@ -1028,7 +985,7 @@ load_pixmap (FRAME_PTR f, Lisp_Object name, unsigned int *w_ptr, unsigned int *h
       h = XINT (Fcar (Fcdr (name)));
       bits = Fcar (Fcdr (Fcdr (name)));
 
-      bitmap_id = x_create_bitmap_from_data (f, SDATA (bits),
+      bitmap_id = x_create_bitmap_from_data (f, SSDATA (bits),
                                             w, h);
     }
   else
@@ -1160,7 +1117,7 @@ tty_lookup_color (struct frame *f, Lisp_Object color, XColor *tty_color, XColor
 
 /* A version of defined_color for non-X frames.  */
 
-int
+static int
 tty_defined_color (struct frame *f, const char *color_name,
                   XColor *color_def, int alloc)
 {
@@ -1196,7 +1153,7 @@ tty_defined_color (struct frame *f, const char *color_name,
 
    This does the right thing for any type of frame.  */
 
-int
+static int
 defined_color (struct frame *f, const char *color_name, XColor *color_def, int alloc)
 {
   if (!FRAME_WINDOW_P (f))
@@ -1320,7 +1277,7 @@ If FRAME is nil or omitted, use the selected frame.  */)
   else
     CHECK_FRAME (frame);
   f = XFRAME (frame);
-  return face_color_gray_p (f, SDATA (color)) ? Qt : Qnil;
+  return face_color_gray_p (f, SSDATA (color)) ? Qt : Qnil;
 }
 
 
@@ -1341,7 +1298,7 @@ COLOR must be a valid color name.  */)
   else
     CHECK_FRAME (frame);
   f = XFRAME (frame);
-  if (face_color_supported_p (f, SDATA (color), !NILP (background_p)))
+  if (face_color_supported_p (f, SSDATA (color), !NILP (background_p)))
     return Qt;
   return Qnil;
 }
@@ -1371,7 +1328,7 @@ load_color (struct frame *f, struct face *face, Lisp_Object name, enum lface_att
 
   /* if the color map is full, defined_color will return a best match
      to the values in an existing cell. */
-  if (!defined_color (f, SDATA (name), &color, 1))
+  if (!defined_color (f, SSDATA (name), &color, 1))
     {
       add_to_log ("Unable to load color \"%s\"", name, Qnil);
 
@@ -1448,7 +1405,7 @@ load_face_colors (struct frame *f, struct face *face, Lisp_Object *attrs)
      face_color_supported_p is smart enough to know that grays are
      "supported" as background because we are supposed to use stipple
      for them.  */
-  if (!face_color_supported_p (f, SDATA (bg), 0)
+  if (!face_color_supported_p (f, SSDATA (bg), 0)
       && !NILP (Fbitmap_spec_p (Vface_default_stipple)))
     {
       x_destroy_bitmap (f, face->stipple);
@@ -1635,7 +1592,7 @@ compare_fonts_by_sort_order (const void *v1, const void *v2)
       if (idx <= FONT_REGISTRY_INDEX)
        {
          if (STRINGP (val1))
-           result = STRINGP (val2) ? strcmp (SDATA (val1), SDATA (val2)) : -1;
+           result = STRINGP (val2) ? strcmp (SSDATA (val1), SSDATA (val2)) : -1;
          else
            result = STRINGP (val2) ? 1 : 0;
        }
@@ -1768,7 +1725,7 @@ the WIDTH times as wide as FACE on FRAME.  */)
   (Lisp_Object pattern, Lisp_Object face, Lisp_Object frame, Lisp_Object maximum, Lisp_Object width)
 {
   struct frame *f;
-  int size, avgwidth;
+  int size, avgwidth IF_LINT (= 0);
 
   check_x ();
   CHECK_STRING (pattern);
@@ -1801,14 +1758,14 @@ the WIDTH times as wide as FACE on FRAME.  */)
       /* This is of limited utility since it works with character
         widths.  Keep it for compatibility.  --gerd.  */
       int face_id = lookup_named_face (f, face, 0);
-      struct face *face = (face_id < 0
-                          ? NULL
-                          : FACE_FROM_ID (f, face_id));
+      struct face *width_face = (face_id < 0
+                                ? NULL
+                                : FACE_FROM_ID (f, face_id));
 
-      if (face && face->font)
+      if (width_face && width_face->font)
        {
-         size = face->font->pixel_size;
-         avgwidth = face->font->average_width;
+         size = width_face->font->pixel_size;
+         avgwidth = width_face->font->average_width;
        }
       else
        {
@@ -1844,7 +1801,7 @@ the WIDTH times as wide as FACE on FRAME.  */)
          {
            /* This is a scalable font.  For backward compatibility,
               we set the specified size. */
-           font_entity = Fcopy_font_spec (font_entity);
+           font_entity = copy_font_spec (font_entity);
            ASET (font_entity, FONT_SIZE_INDEX,
                  AREF (font_spec, FONT_SIZE_INDEX));
          }
@@ -1885,13 +1842,15 @@ the WIDTH times as wide as FACE on FRAME.  */)
 #define LFACE_INHERIT(LFACE)       AREF ((LFACE), LFACE_INHERIT_INDEX)
 #define LFACE_FONTSET(LFACE)       AREF ((LFACE), LFACE_FONTSET_INDEX)
 
+#if XASSERTS
 /* Non-zero if LFACE is a Lisp face.  A Lisp face is a vector of size
    LFACE_VECTOR_SIZE which has the symbol `face' in slot 0.  */
 
 #define LFACEP(LFACE)                                  \
      (VECTORP (LFACE)                                  \
-      && XVECTOR (LFACE)->size == LFACE_VECTOR_SIZE    \
+      && ASIZE (LFACE) == LFACE_VECTOR_SIZE            \
       && EQ (AREF (LFACE, 0), Qface))
+#endif
 
 
 #if GLYPH_DEBUG
@@ -2080,7 +2039,7 @@ resolve_face_name (Lisp_Object face_name, int signal_p)
   Lisp_Object tortoise, hare;
 
   if (STRINGP (face_name))
-    face_name = intern (SDATA (face_name));
+    face_name = intern (SSDATA (face_name));
 
   if (NILP (face_name) || !SYMBOLP (face_name))
     return face_name;
@@ -2299,7 +2258,7 @@ set_lface_from_font (struct frame *f, Lisp_Object lface, Lisp_Object font_object
    `relative' heights; the returned value is always an absolute height
    unless both FROM and TO are relative.  */
 
-Lisp_Object
+static Lisp_Object
 merge_face_heights (Lisp_Object from, Lisp_Object to, Lisp_Object invalid)
 {
   Lisp_Object result = invalid;
@@ -2366,9 +2325,9 @@ merge_face_vectors (struct frame *f, Lisp_Object *from, Lisp_Object *to, struct
   if (!UNSPECIFIEDP (from[i]))
     {
       if (!UNSPECIFIEDP (to[i]))
-       to[i] = Fmerge_font_spec (from[i], to[i]);
+       to[i] = merge_font_spec (from[i], to[i]);
       else
-       to[i] = Fcopy_font_spec (from[i]);
+       to[i] = copy_font_spec (from[i]);
       if (! NILP (AREF (to[i], FONT_FOUNDRY_INDEX)))
        to[LFACE_FOUNDRY_INDEX] = SYMBOL_NAME (AREF (to[i], FONT_FOUNDRY_INDEX));
       if (! NILP (AREF (to[i], FONT_FAMILY_INDEX)))
@@ -2946,7 +2905,7 @@ FRAME 0 means change the face on all frames, and change the default
            {
              /* The default face must have an absolute size.  */
              if (!INTEGERP (value) || XINT (value) <= 0)
-               signal_error ("Invalid default face height", value);
+               signal_error ("Default face height not absolute and positive", value);
            }
          else
            {
@@ -2956,7 +2915,7 @@ FRAME 0 means change the face on all frames, and change the default
                                                     make_number (10),
                                                     Qnil);
              if (!INTEGERP (test) || XINT (test) <= 0)
-               signal_error ("Invalid face height", value);
+               signal_error ("Face height does not produce a positive integer", value);
            }
        }
 
@@ -3515,13 +3474,13 @@ face_boolean_x_resource_value (Lisp_Object value, int signal_p)
 
   xassert (STRINGP (value));
 
-  if (xstrcasecmp (SDATA (value), "on") == 0
-      || xstrcasecmp (SDATA (value), "true") == 0)
+  if (xstrcasecmp (SSDATA (value), "on") == 0
+      || xstrcasecmp (SSDATA (value), "true") == 0)
     result = Qt;
-  else if (xstrcasecmp (SDATA (value), "off") == 0
-          || xstrcasecmp (SDATA (value), "false") == 0)
+  else if (xstrcasecmp (SSDATA (value), "off") == 0
+          || xstrcasecmp (SSDATA (value), "false") == 0)
     result = Qnil;
-  else if (xstrcasecmp (SDATA (value), "unspecified") == 0)
+  else if (xstrcasecmp (SSDATA (value), "unspecified") == 0)
     result = Qunspecified;
   else if (signal_p)
     signal_error ("Invalid face attribute value from X resource", value);
@@ -3540,7 +3499,7 @@ DEFUN ("internal-set-lisp-face-attribute-from-resource",
   CHECK_SYMBOL (attr);
   CHECK_STRING (value);
 
-  if (xstrcasecmp (SDATA (value), "unspecified") == 0)
+  if (xstrcasecmp (SSDATA (value), "unspecified") == 0)
     value = Qunspecified;
   else if (EQ (attr, QCheight))
     {
@@ -3551,7 +3510,7 @@ DEFUN ("internal-set-lisp-face-attribute-from-resource",
   else if (EQ (attr, QCbold) || EQ (attr, QCitalic))
     value = face_boolean_x_resource_value (value, 1);
   else if (EQ (attr, QCweight) || EQ (attr, QCslant) || EQ (attr, QCwidth))
-    value = intern (SDATA (value));
+    value = intern (SSDATA (value));
   else if (EQ (attr, QCreverse_video) || EQ (attr, QCinverse_video))
     value = face_boolean_x_resource_value (value, 1);
   else if (EQ (attr, QCunderline)
@@ -3596,7 +3555,7 @@ x_update_menu_appearance (struct frame *f)
       char line[512];
       Lisp_Object lface = lface_from_face_name (f, Qmenu, 1);
       struct face *face = FACE_FROM_ID (f, MENU_FACE_ID);
-      const char *myname = SDATA (Vx_resource_name);
+      const char *myname = SSDATA (Vx_resource_name);
       int changed_p = 0;
 #ifdef USE_MOTIF
       const char *popup_path = "popup_menu";
@@ -3657,9 +3616,9 @@ x_update_menu_appearance (struct frame *f)
          if (! NILP (xlfd))
            {
 #if defined HAVE_X_I18N
-             char *fontsetname = xic_create_fontsetname (SDATA (xlfd), motif);
+             char *fontsetname = xic_create_fontsetname (SSDATA (xlfd), motif);
 #else
-             char *fontsetname = (char *) SDATA (xlfd);
+             char *fontsetname = SSDATA (xlfd);
 #endif
              sprintf (line, "%s.pane.menubar*font%s: %s",
                       myname, suffix, fontsetname);
@@ -3668,7 +3627,7 @@ x_update_menu_appearance (struct frame *f)
                       myname, popup_path, suffix, fontsetname);
              XrmPutLineResource (&rdb, line);
              changed_p = 1;
-             if (fontsetname != (char *) SDATA (xlfd))
+             if (fontsetname != SSDATA (xlfd))
                xfree (fontsetname);
            }
        }
@@ -3916,19 +3875,19 @@ return the font name used for CHARACTER.  */)
     {
       struct frame *f = frame_or_selected_frame (frame, 1);
       int face_id = lookup_named_face (f, face, 1);
-      struct face *face = FACE_FROM_ID (f, face_id);
+      struct face *fface = FACE_FROM_ID (f, face_id);
 
-      if (! face)
+      if (! fface)
        return Qnil;
 #ifdef HAVE_WINDOW_SYSTEM
       if (FRAME_WINDOW_P (f) && !NILP (character))
        {
          CHECK_CHARACTER (character);
-         face_id = FACE_FOR_CHAR (f, face, XINT (character), -1, Qnil);
-         face = FACE_FROM_ID (f, face_id);
+         face_id = FACE_FOR_CHAR (f, fface, XINT (character), -1, Qnil);
+         fface = FACE_FROM_ID (f, face_id);
        }
-      return (face->font
-             ? face->font->props[FONT_NAME_INDEX]
+      return (fface->font
+             ? fface->font->props[FONT_NAME_INDEX]
              : Qnil);
 #else  /* !HAVE_WINDOW_SYSTEM */
       return build_string (FRAME_MSDOS_P (f)
@@ -4100,10 +4059,10 @@ lface_same_font_attributes_p (Lisp_Object *lface1, Lisp_Object *lface2)
 {
   xassert (lface_fully_specified_p (lface1)
           && lface_fully_specified_p (lface2));
-  return (xstrcasecmp (SDATA (lface1[LFACE_FAMILY_INDEX]),
-                       SDATA (lface2[LFACE_FAMILY_INDEX])) == 0
-         && xstrcasecmp (SDATA (lface1[LFACE_FOUNDRY_INDEX]),
-                         SDATA (lface2[LFACE_FOUNDRY_INDEX])) == 0
+  return (xstrcasecmp (SSDATA (lface1[LFACE_FAMILY_INDEX]),
+                       SSDATA (lface2[LFACE_FAMILY_INDEX])) == 0
+         && xstrcasecmp (SSDATA (lface1[LFACE_FOUNDRY_INDEX]),
+                         SSDATA (lface2[LFACE_FOUNDRY_INDEX])) == 0
          && EQ (lface1[LFACE_HEIGHT_INDEX], lface2[LFACE_HEIGHT_INDEX])
          && EQ (lface1[LFACE_SWIDTH_INDEX], lface2[LFACE_SWIDTH_INDEX])
          && EQ (lface1[LFACE_WEIGHT_INDEX], lface2[LFACE_WEIGHT_INDEX])
@@ -4112,8 +4071,8 @@ lface_same_font_attributes_p (Lisp_Object *lface1, Lisp_Object *lface2)
          && (EQ (lface1[LFACE_FONTSET_INDEX], lface2[LFACE_FONTSET_INDEX])
              || (STRINGP (lface1[LFACE_FONTSET_INDEX])
                  && STRINGP (lface2[LFACE_FONTSET_INDEX])
-                 && ! xstrcasecmp (SDATA (lface1[LFACE_FONTSET_INDEX]),
-                                    SDATA (lface2[LFACE_FONTSET_INDEX]))))
+                 && ! xstrcasecmp (SSDATA (lface1[LFACE_FONTSET_INDEX]),
+                                    SSDATA (lface2[LFACE_FONTSET_INDEX]))))
          );
 }
 
@@ -4140,7 +4099,7 @@ make_realized_face (Lisp_Object *attr)
 /* Free realized face FACE, including its X resources.  FACE may
    be null.  */
 
-void
+static void
 free_realized_face (struct frame *f, struct face *face)
 {
   if (face)
@@ -4253,10 +4212,10 @@ If FRAME is unspecified or nil, the current frame is used.  */)
   f = XFRAME (frame);
 
   if (!(CONSP (color1) && parse_rgb_list (color1, &cdef1))
-      && !(STRINGP (color1) && defined_color (f, SDATA (color1), &cdef1, 0)))
+      && !(STRINGP (color1) && defined_color (f, SSDATA (color1), &cdef1, 0)))
     signal_error ("Invalid color", color1);
   if (!(CONSP (color2) && parse_rgb_list (color2, &cdef2))
-      && !(STRINGP (color2) && defined_color (f, SDATA (color2), &cdef2, 0)))
+      && !(STRINGP (color2) && defined_color (f, SSDATA (color2), &cdef2, 0)))
     signal_error ("Invalid color", color2);
 
   return make_number (color_distance (&cdef1, &cdef2));
@@ -4360,45 +4319,6 @@ free_realized_faces (struct face_cache *c)
 }
 
 
-/* Free all realized faces that are using FONTSET on frame F.  */
-
-void
-free_realized_faces_for_fontset (struct frame *f, int fontset)
-{
-  struct face_cache *cache = FRAME_FACE_CACHE (f);
-  struct face *face;
-  int i;
-
-  /* We must block input here because we can't process X events safely
-     while only some faces are freed, or when the frame's current
-     matrix still references freed faces.  */
-  BLOCK_INPUT;
-
-  for (i = 0; i < cache->used; i++)
-    {
-      face = cache->faces_by_id[i];
-      if (face
-         && face->fontset == fontset)
-       {
-         uncache_face (cache, face);
-         free_realized_face (f, face);
-       }
-    }
-
-  /* Must do a thorough redisplay the next time.  Mark current
-     matrices as invalid because they will reference faces freed
-     above.  This function is also called when a frame is destroyed.
-     In this case, the root window of F is nil.  */
-  if (WINDOWP (f->root_window))
-    {
-      clear_current_matrices (f);
-      ++windows_or_buffers_changed;
-    }
-
-  UNBLOCK_INPUT;
-}
-
-
 /* Free all realized faces on FRAME or on all frames if FRAME is nil.
    This is done after attributes of a named face have been changed,
    because we can't tell which realized faces depend on that face.  */
@@ -4540,7 +4460,7 @@ uncache_face (struct face_cache *c, struct face *face)
    Value is the ID of the face found.  If no suitable face is found,
    realize a new one.  */
 
-INLINE int
+static INLINE int
 lookup_face (struct frame *f, Lisp_Object *attr)
 {
   struct face_cache *cache = FRAME_FACE_CACHE (f);
@@ -4697,26 +4617,6 @@ lookup_basic_face (struct frame *f, int face_id)
 }
 
 
-/* Return the ID of the realized ASCII face of Lisp face with ID
-   LFACE_ID on frame F.  Value is -1 if LFACE_ID isn't valid.  */
-
-int
-ascii_face_of_lisp_face (struct frame *f, int lface_id)
-{
-  int face_id;
-
-  if (lface_id >= 0 && lface_id < lface_id_to_name_size)
-    {
-      Lisp_Object face_name = lface_id_to_name[lface_id];
-      face_id = lookup_named_face (f, face_name, 1);
-    }
-  else
-    face_id = -1;
-
-  return face_id;
-}
-
-
 /* Return a face for charset ASCII that is like the face with id
    FACE_ID on frame F, but has a font that is STEPS steps smaller.
    STEPS < 0 means larger.  Value is the id of the face.  */
@@ -5334,10 +5234,6 @@ be found.  Value is ALIST.  */)
 
 #ifdef HAVE_WINDOW_SYSTEM
 
-/* Ignore the difference of font point size less than this value.  */
-
-#define FONT_POINT_SIZE_QUANTUM 5
-
 /* Return the fontset id of the base fontset name or alias name given
    by the fontset attribute of ATTRS.  Value is -1 if the fontset
    attribute of ATTRS doesn't name a fontset.  */
@@ -5543,7 +5439,6 @@ realize_named_face (struct frame *f, Lisp_Object symbol, int id)
   Lisp_Object lface = lface_from_face_name (f, symbol, 0);
   Lisp_Object attrs[LFACE_VECTOR_SIZE];
   Lisp_Object symbol_attrs[LFACE_VECTOR_SIZE];
-  struct face *new_face;
 
   /* The default face must exist and be fully specified.  */
   get_lface_attributes_no_remap (f, Qdefault, attrs, 1);
@@ -5563,7 +5458,7 @@ realize_named_face (struct frame *f, Lisp_Object symbol, int id)
   merge_face_vectors (f, symbol_attrs, attrs, 0);
 
   /* Realize the face.  */
-  new_face = realize_face (c, attrs, id);
+  realize_face (c, attrs, id);
 }
 
 
@@ -5860,21 +5755,16 @@ map_tty_color (struct frame *f, struct face *face, enum lface_attribute_index id
 {
   Lisp_Object frame, color, def;
   int foreground_p = idx == LFACE_FOREGROUND_INDEX;
-  unsigned long default_pixel, default_other_pixel, pixel;
+  unsigned long default_pixel =
+    foreground_p ? FACE_TTY_DEFAULT_FG_COLOR : FACE_TTY_DEFAULT_BG_COLOR;
+  unsigned long pixel = default_pixel;
+#ifdef MSDOS
+  unsigned long default_other_pixel =
+    foreground_p ? FACE_TTY_DEFAULT_BG_COLOR : FACE_TTY_DEFAULT_FG_COLOR;
+#endif
 
   xassert (idx == LFACE_FOREGROUND_INDEX || idx == LFACE_BACKGROUND_INDEX);
 
-  if (foreground_p)
-    {
-      pixel = default_pixel = FACE_TTY_DEFAULT_FG_COLOR;
-      default_other_pixel = FACE_TTY_DEFAULT_BG_COLOR;
-    }
-  else
-    {
-      pixel = default_pixel = FACE_TTY_DEFAULT_BG_COLOR;
-      default_other_pixel = FACE_TTY_DEFAULT_FG_COLOR;
-    }
-
   XSETFRAME (frame, f);
   color = face->lface[idx];
 
@@ -6017,7 +5907,7 @@ compute_char_face (struct frame *f, int ch, Lisp_Object prop)
 {
   int face_id;
 
-  if (NILP (current_buffer->enable_multibyte_characters))
+  if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
     ch = 0;
 
   if (NILP (prop))
@@ -6295,7 +6185,7 @@ face_at_string_position (struct window *w, Lisp_Object string,
             if we don't have fonts, so we can stop here if not working
             on a window-system frame.  */
          || !FRAME_WINDOW_P (f)
-         || FACE_SUITABLE_FOR_CHAR_P (base_face, 0)))
+         || FACE_SUITABLE_FOR_ASCII_CHAR_P (base_face, 0)))
     return base_face->id;
 
   /* Begin with attributes from the base face.  */
@@ -6396,7 +6286,7 @@ where R,G,B are numbers between 0 and 255 and name is an arbitrary string.  */)
   CHECK_STRING (filename);
   abspath = Fexpand_file_name (filename, Qnil);
 
-  fp = fopen (SDATA (filename), "rt");
+  fp = fopen (SDATA (abspath), "rt");
   if (fp)
     {
       char buf[512];
@@ -6715,29 +6605,29 @@ syms_of_xfaces (void)
   defsubr (&Sdump_colors);
 #endif
 
-  DEFVAR_LISP ("font-list-limit", &Vfont_list_limit,
+  DEFVAR_LISP ("font-list-limit", Vfont_list_limit,
               doc: /* *Limit for font matching.
 If an integer > 0, font matching functions won't load more than
 that number of fonts when searching for a matching font.  */);
   Vfont_list_limit = make_number (DEFAULT_FONT_LIST_LIMIT);
 
-  DEFVAR_LISP ("face-new-frame-defaults", &Vface_new_frame_defaults,
+  DEFVAR_LISP ("face-new-frame-defaults", Vface_new_frame_defaults,
     doc: /* List of global face definitions (for internal use only.)  */);
   Vface_new_frame_defaults = Qnil;
 
-  DEFVAR_LISP ("face-default-stipple", &Vface_default_stipple,
+  DEFVAR_LISP ("face-default-stipple", Vface_default_stipple,
     doc: /* *Default stipple pattern used on monochrome displays.
 This stipple pattern is used on monochrome displays
 instead of shades of gray for a face background color.
 See `set-face-stipple' for possible values for this variable.  */);
   Vface_default_stipple = make_pure_c_string ("gray3");
 
-  DEFVAR_LISP ("tty-defined-color-alist", &Vtty_defined_color_alist,
+  DEFVAR_LISP ("tty-defined-color-alist", Vtty_defined_color_alist,
    doc: /* An alist of defined terminal colors and their RGB values.
 See the docstring of `tty-color-alist' for the details.  */);
   Vtty_defined_color_alist = Qnil;
 
-  DEFVAR_LISP ("scalable-fonts-allowed", &Vscalable_fonts_allowed,
+  DEFVAR_LISP ("scalable-fonts-allowed", Vscalable_fonts_allowed,
               doc: /* Allowed scalable fonts.
 A value of nil means don't allow any scalable fonts.
 A value of t means allow any scalable font.
@@ -6747,13 +6637,13 @@ Note that if value is nil, a scalable font might still be used, if no
 other font of the appropriate family and registry is available.  */);
   Vscalable_fonts_allowed = Qnil;
 
-  DEFVAR_LISP ("face-ignored-fonts", &Vface_ignored_fonts,
+  DEFVAR_LISP ("face-ignored-fonts", Vface_ignored_fonts,
               doc: /* List of ignored fonts.
 Each element is a regular expression that matches names of fonts to
 ignore.  */);
   Vface_ignored_fonts = Qnil;
 
-  DEFVAR_LISP ("face-remapping-alist", &Vface_remapping_alist,
+  DEFVAR_LISP ("face-remapping-alist", Vface_remapping_alist,
               doc: /* Alist of face remappings.
 Each element is of the form:
 
@@ -6794,7 +6684,7 @@ buffer contents change, you may need to call `redraw-display' after
 changing this variable for it to take effect.  */);
   Vface_remapping_alist = Qnil;
 
-  DEFVAR_LISP ("face-font-rescale-alist", &Vface_font_rescale_alist,
+  DEFVAR_LISP ("face-font-rescale-alist", Vface_font_rescale_alist,
               doc: /* Alist of fonts vs the rescaling factors.
 Each element is a cons (FONT-PATTERN . RESCALE-RATIO), where
 FONT-PATTERN is a font-spec or a regular expression matching a font name, and
@@ -6810,4 +6700,3 @@ a font of 10 point, we actually use a font of 10 * RESCALE-RATIO point.  */);
   defsubr (&Sx_family_fonts);
 #endif
 }
-