*** empty log message ***
[bpt/emacs.git] / src / casetab.c
index 1660b57..9ee8f57 100644 (file)
@@ -71,7 +71,7 @@ check_case_table (obj)
   while (tem = Fcase_table_p (obj), NILP (tem))
     obj = wrong_type_argument (Qcase_table_p, obj);
   return (obj);
-}   
+}
 
 DEFUN ("current-case-table", Fcurrent_case_table, Scurrent_case_table, 0, 0, 0,
        doc: /* Return the case table of the current buffer.  */)
@@ -127,7 +127,6 @@ set_case_table (table, standard)
      int standard;
 {
   Lisp_Object up, canon, eqv;
-  Lisp_Object indices[3];
 
   check_case_table (table);
 
@@ -138,8 +137,8 @@ set_case_table (table, standard)
   if (NILP (up))
     {
       up = Fmake_char_table (Qcase_table, Qnil);
-      map_char_table (set_identity, Qnil, table, up, 0, indices);
-      map_char_table (shuffle, Qnil, table, up, 0, indices);
+      map_char_table (set_identity, Qnil, table, up);
+      map_char_table (shuffle, Qnil, table, up);
       XCHAR_TABLE (table)->extras[0] = up;
     }
 
@@ -147,17 +146,20 @@ set_case_table (table, standard)
     {
       canon = Fmake_char_table (Qcase_table, Qnil);
       XCHAR_TABLE (table)->extras[1] = canon;
-      map_char_table (set_canon, Qnil, table, table, 0, indices);
+      map_char_table (set_canon, Qnil, table, table);
     }
 
   if (NILP (eqv))
     {
       eqv = Fmake_char_table (Qcase_table, Qnil);
-      map_char_table (set_identity, Qnil, canon, eqv, 0, indices);
-      map_char_table (shuffle, Qnil, canon, eqv, 0, indices);
+      map_char_table (set_identity, Qnil, canon, eqv);
+      map_char_table (shuffle, Qnil, canon, eqv);
       XCHAR_TABLE (table)->extras[2] = eqv;
     }
 
+  /* This is so set_image_of_range_1 in regex.c can find the EQV table.  */
+  XCHAR_TABLE (canon)->extras[2] = eqv;
+
   if (standard)
     Vascii_downcase_table = table;
   else
@@ -173,9 +175,10 @@ set_case_table (table, standard)
 \f
 /* The following functions are called in map_char_table.  */
 
-/*  Set CANON char-table element for C to a translated ELT by UP and
-   DOWN char-tables.  This is done only when ELT is a character.  The
-   char-tables CANON, UP, and DOWN are in CASE_TABLE.  */
+/* Set CANON char-table element for characters in RANGE to a
+   translated ELT by UP and DOWN char-tables.  This is done only when
+   ELT is a character.  The char-tables CANON, UP, and DOWN are in
+   CASE_TABLE.  */
 
 static void
 set_canon (case_table, range, elt)
@@ -183,78 +186,61 @@ set_canon (case_table, range, elt)
 {
   Lisp_Object up = XCHAR_TABLE (case_table)->extras[0];
   Lisp_Object canon = XCHAR_TABLE (case_table)->extras[1];
-  int from, to;
 
+  if (NATNUMP (elt))
+    Fset_char_table_range (canon, range, Faref (case_table, Faref (up, elt)));
+}
+
+/* Set elements of char-table TABLE for C to C itself.  C may be a
+   cons specifying a character range.  In that case, set characters in
+   that range to themselves.  This is done only when ELT is a
+   character.  This is called in map_char_table.  */
+
+static void
+set_identity (table, c, elt)
+     Lisp_Object table, c, elt;
+{
   if (NATNUMP (elt))
     {
-      if (CONSP (range))
+      int from, to;
+
+      if (CONSP (c))
        {
-         from = XINT (XCAR (range));
-         to = XINT (XCDR (range));
+         from = XINT (XCAR (c));
+         to = XINT (XCDR (c));
        }
       else
-       from = to = XINT (range);
-
+       from = to = XINT (c);
       for (; from <= to; from++)
-       {
-         Lisp_Object val1, val2;
-
-         val1 = Faref (up, elt);
-         if (EQ (val1, Qt))
-           val1 = elt;
-         else if (! NATNUMP (val1))
-           continue;
-         val2 = Faref (case_table, val1);
-         if (EQ (val2, Qt))
-           val2 = val1;
-         else if (! NATNUMP (val2))
-           continue;
-         Faset (canon, make_number (from), val2);
-       }
+       CHAR_TABLE_SET (table, from, make_number (from));
     }
 }
 
-/* Set elements of char-table TABLE for characters in RANGE to
-   themselves.  This is done only when ELT is a character.  This is
-   called in map_char_table.  */
-
-static void
-set_identity (table, range, elt)
-     Lisp_Object table, range, elt;
-{
-  if (EQ (elt, Qt) || NATNUMP (elt))
-    Fset_char_table_range (table, range, Qt);
-}
-
 /* Permute the elements of TABLE (which is initially an identity
    mapping) so that it has one cycle for each equivalence class
    induced by the translation table on which map_char_table is
    operated.  */
 
 static void
-shuffle (table, range, elt)
-     Lisp_Object table, range, elt;
+shuffle (table, c, elt)
+     Lisp_Object table, c, elt;
 {
-  int from, to;
-
   if (NATNUMP (elt))
     {
-      Lisp_Object tem;
+      Lisp_Object tem = Faref (table, elt);
+      int from, to;
 
-      if (CONSP (range))
+      if (CONSP (c))
        {
-         from = XINT (XCAR (range));
-         to = XINT (XCDR (range));
+         from = XINT (XCAR (c));
+         to = XINT (XCDR (c));
        }
       else
-       from = to = XINT (range);
+       from = to = XINT (c);
 
       for (; from <= to; from++)
        if (from != XINT (elt))
          {
-           tem = Faref (table, elt);
-           if (EQ (tem, Qt))
-             tem = elt;
            Faset (table, elt, make_number (from));
            Faset (table, make_number (from), tem);
          }
@@ -283,8 +269,10 @@ init_casetab_once ()
   XCHAR_TABLE (down)->purpose = Qcase_table;
 
   for (i = 0; i < 128; i++)
-    CHAR_TABLE_SET (down, i,
-                   make_number ((i >= 'A' && i <= 'Z') ? i + ('a' - 'A') : i));
+    {
+      int c = (i >= 'A' && i <= 'Z') ? i + ('a' - 'A') : i;
+      CHAR_TABLE_SET (down, i, make_number (c));
+    }
 
   XCHAR_TABLE (down)->extras[1] = Fcopy_sequence (down);
 
@@ -292,11 +280,12 @@ init_casetab_once ()
   XCHAR_TABLE (down)->extras[0] = up;
 
   for (i = 0; i < 128; i++)
-    CHAR_TABLE_SET (up, i, make_number ((i >= 'A' && i <= 'Z')
-                                       ? i + ('a' - 'A')
-                                       : ((i >= 'a' && i <= 'z')
-                                          ? i + ('A' - 'a')
-                                          : i)));
+    {
+      int c = ((i >= 'A' && i <= 'Z') ? i + ('a' - 'A')
+              : ((i >= 'a' && i <= 'z') ? i + ('A' - 'a')
+                 : i));;
+      CHAR_TABLE_SET (up, i, make_number (c));
+    }
 
   XCHAR_TABLE (down)->extras[2] = Fcopy_sequence (up);
 }