/[emacs]/emacs/src/category.c
ViewVC logotype

Diff of /emacs/src/category.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.30 by monnier, Wed Nov 28 20:44:42 2001 UTC revision 1.30.2.1 by handa, Fri Mar 1 01:13:23 2002 UTC
# Line 1  Line 1 
1  /* GNU Emacs routines to deal with category tables.  /* GNU Emacs routines to deal with category tables.
2     Copyright (C) 1995, 1997 Electrotechnical Laboratory, JAPAN.     Copyright (C) 1995, 1997 Electrotechnical Laboratory, JAPAN.
3     Licensed to the Free Software Foundation.     Licensed to the Free Software Foundation.
4       Copyright (C) 2001, 2002
5         National Institute of Advanced Industrial Science and Technology (AIST)
6         Registration Number H13PRO009
7    
8  This file is part of GNU Emacs.  This file is part of GNU Emacs.
9    
# Line 27  Boston, MA 02111-1307, USA.  */ Line 30  Boston, MA 02111-1307, USA.  */
30  #include <ctype.h>  #include <ctype.h>
31  #include "lisp.h"  #include "lisp.h"
32  #include "buffer.h"  #include "buffer.h"
33    #include "character.h"
34  #include "charset.h"  #include "charset.h"
35  #include "category.h"  #include "category.h"
36  #include "keymap.h"  #include "keymap.h"
# Line 186  This is the one used for new buffers.  * Line 190  This is the one used for new buffers.  *
190    return Vstandard_category_table;    return Vstandard_category_table;
191  }  }
192    
193    
194    static void
195    copy_category_entry (table, range, val)
196         Lisp_Object table, range, val;
197    {
198      char_table_set_range (table, XINT (XCAR (range)), XINT (XCDR (range)),
199                            Fcopy_sequence (val));
200    }
201    
202  /* Return a copy of category table TABLE.  We can't simply use the  /* Return a copy of category table TABLE.  We can't simply use the
203     function copy-sequence because no contents should be shared between     function copy-sequence because no contents should be shared between
204     the original and the copy.  This function is called recursively by     the original and the copy.  This function is called recursively by
# Line 195  Lisp_Object Line 208  Lisp_Object
208  copy_category_table (table)  copy_category_table (table)
209       Lisp_Object table;       Lisp_Object table;
210  {  {
211    Lisp_Object tmp;    table = copy_char_table (table);
   int i, to;  
212    
213    if (!NILP (XCHAR_TABLE (table)->top))    if (! NILP (XCHAR_TABLE (table)->defalt))
214      {      XCHAR_TABLE (table)->defalt
215        /* TABLE is a top level char table.        = Fcopy_sequence (XCHAR_TABLE (table)->defalt);
216           At first, make a copy of tree structure of the table.  */    XCHAR_TABLE (table)->extras[0]
217        table = Fcopy_sequence (table);      = Fcopy_sequence (XCHAR_TABLE (table)->extras[0]);
   
       /* Then, copy elements for single byte characters one by one.  */  
       for (i = 0; i < CHAR_TABLE_SINGLE_BYTE_SLOTS; i++)  
         if (!NILP (tmp = XCHAR_TABLE (table)->contents[i]))  
           XCHAR_TABLE (table)->contents[i] = Fcopy_sequence (tmp);  
       to = CHAR_TABLE_ORDINARY_SLOTS;  
   
       /* Also copy the first (and sole) extra slot.  It is a vector  
          containing docstring of each category.  */  
       Fset_char_table_extra_slot  
         (table, make_number (0),  
          Fcopy_sequence (Fchar_table_extra_slot (table, make_number (0))));  
     }  
   else  
     {  
       i  = 32;  
       to = SUB_CHAR_TABLE_ORDINARY_SLOTS;  
     }  
218    
219    /* If the table has non-nil default value, copy it.  */    map_char_table (copy_category_entry, Qnil, table, table, 0, NULL);
   if (!NILP (tmp = XCHAR_TABLE (table)->defalt))  
     XCHAR_TABLE (table)->defalt = Fcopy_sequence (tmp);  
   
   /* At last, copy the remaining elements while paying attention to a  
      sub char table.  */  
   for (; i < to; i++)  
     if (!NILP (tmp = XCHAR_TABLE (table)->contents[i]))  
       XCHAR_TABLE (table)->contents[i]  
         = (SUB_CHAR_TABLE_P (tmp)  
            ? copy_category_table (tmp) : Fcopy_sequence (tmp));  
220    
221    return table;    return table;
222  }  }
# Line 258  DEFUN ("make-category-table", Fmake_cate Line 242  DEFUN ("make-category-table", Fmake_cate
242       ()       ()
243  {  {
244    Lisp_Object val;    Lisp_Object val;
245      int i;
246    
247    val = Fmake_char_table (Qcategory_table, Qnil);    val = Fmake_char_table (Qcategory_table, Qnil);
248    XCHAR_TABLE (val)->defalt = MAKE_CATEGORY_SET;    XCHAR_TABLE (val)->defalt = MAKE_CATEGORY_SET;
249      for (i = 0; i < (1 << CHARTAB_SIZE_BITS_0); i++)  
250        XCHAR_TABLE (val)->contents[i] = MAKE_CATEGORY_SET;
251    Fset_char_table_extra_slot (val, make_number (0),    Fset_char_table_extra_slot (val, make_number (0),
252                                Fmake_vector (make_number (95), Qnil));                                Fmake_vector (make_number (95), Qnil));
253    return val;    return val;
# Line 281  DEFUN ("set-category-table", Fset_catego Line 268  DEFUN ("set-category-table", Fset_catego
268  }  }
269    
270    
271    Lisp_Object
272    char_category_set (c)
273         int c;
274    {
275      return CHAR_TABLE_REF (current_buffer->category_table, c);
276    }
277    
278  DEFUN ("char-category-set", Fchar_category_set, Schar_category_set, 1, 1, 0,  DEFUN ("char-category-set", Fchar_category_set, Schar_category_set, 1, 1, 0,
279         doc: /* Return the category set of CHAR.  */)         doc: /* Return the category set of CHAR.  */)
280       (ch)       (ch)
# Line 313  The return value is a string containing Line 307  The return value is a string containing
307    return build_string (str);    return build_string (str);
308  }  }
309    
 /* Modify all category sets stored under sub char-table TABLE so that  
    they contain (SET_VALUE is t) or don't contain (SET_VALUE is nil)  
    CATEGORY.  */  
   
 void  
 modify_lower_category_set (table, category, set_value)  
      Lisp_Object table, category, set_value;  
 {  
   Lisp_Object val;  
   int i;  
   
   val = XCHAR_TABLE (table)->defalt;  
   if (!CATEGORY_SET_P (val))  
     val = MAKE_CATEGORY_SET;  
   SET_CATEGORY_SET (val, category, set_value);  
   XCHAR_TABLE (table)->defalt = val;  
   
   for (i = 32; i < SUB_CHAR_TABLE_ORDINARY_SLOTS; i++)  
     {  
       val = XCHAR_TABLE (table)->contents[i];  
   
       if (CATEGORY_SET_P (val))  
         SET_CATEGORY_SET (val, category, set_value);  
       else if (SUB_CHAR_TABLE_P (val))  
         modify_lower_category_set (val, category, set_value);  
     }  
 }  
   
310  void  void
311  set_category_set (category_set, category, val)  set_category_set (category_set, category, val)
312       Lisp_Object category_set, category, val;       Lisp_Object category_set, category, val;
# Line 369  then delete CATEGORY from the category s Line 335  then delete CATEGORY from the category s
335    int c, charset, c1, c2;    int c, charset, c1, c2;
336    Lisp_Object set_value;        /* Actual value to be set in category sets.  */    Lisp_Object set_value;        /* Actual value to be set in category sets.  */
337    Lisp_Object val, category_set;    Lisp_Object val, category_set;
338      int start, end;
339      int from, to;
340    
341      if (INTEGERP (character))
342        {
343          CHECK_CHARACTER (character);
344          start = end = XFASTINT (character);
345        }
346      else
347        {
348          CHECK_CONS (character);
349          CHECK_CHARACTER (XCAR (character));
350          CHECK_CHARACTER (XCDR (character));
351          start = XFASTINT (XCAR (character));
352          end = XFASTINT (XCDR (character));
353        }
354    
   CHECK_NUMBER (character);  
   c = XINT (character);  
355    CHECK_CATEGORY (category);    CHECK_CATEGORY (category);
356    table = check_category_table (table);    table = check_category_table (table);
357    
# Line 380  then delete CATEGORY from the category s Line 360  then delete CATEGORY from the category s
360        
361    set_value = NILP (reset) ? Qt : Qnil;    set_value = NILP (reset) ? Qt : Qnil;
362    
363    if (c < CHAR_TABLE_SINGLE_BYTE_SLOTS)    while (start <= end)
     {  
       val = XCHAR_TABLE (table)->contents[c];  
       if (!CATEGORY_SET_P (val))  
         XCHAR_TABLE (table)->contents[c] = (val = MAKE_CATEGORY_SET);  
       SET_CATEGORY_SET (val, category, set_value);  
       return Qnil;  
     }  
   
   SPLIT_CHAR (c, charset, c1, c2);  
   
   /* The top level table.  */  
   val = XCHAR_TABLE (table)->contents[charset + 128];  
   if (CATEGORY_SET_P (val))  
     category_set = val;  
   else if (!SUB_CHAR_TABLE_P (val))  
     {  
       category_set = val = MAKE_CATEGORY_SET;  
       XCHAR_TABLE (table)->contents[charset + 128] = category_set;  
     }  
   
   if (c1 <= 0)  
     {  
       /* Only a charset is specified.  */  
       if (SUB_CHAR_TABLE_P (val))  
         /* All characters in CHARSET should be the same as for having  
            CATEGORY or not.  */  
         modify_lower_category_set (val, category, set_value);  
       else  
         SET_CATEGORY_SET (category_set, category, set_value);  
       return Qnil;  
     }  
   
   /* The second level table.  */  
   if (!SUB_CHAR_TABLE_P (val))  
     {  
       val = make_sub_char_table (Qnil);  
       XCHAR_TABLE (table)->contents[charset + 128] = val;  
       /* We must set default category set of CHARSET in `defalt' slot.  */  
       XCHAR_TABLE (val)->defalt = category_set;  
     }  
   table = val;  
   
   val = XCHAR_TABLE (table)->contents[c1];  
   if (CATEGORY_SET_P (val))  
     category_set = val;  
   else if (!SUB_CHAR_TABLE_P (val))  
     {  
       category_set = val = Fcopy_sequence (XCHAR_TABLE (table)->defalt);  
       XCHAR_TABLE (table)->contents[c1] = category_set;  
     }  
   
   if (c2 <= 0)  
     {  
       if (SUB_CHAR_TABLE_P (val))  
         /* All characters in C1 group of CHARSET should be the same as  
            for CATEGORY.  */  
         modify_lower_category_set (val, category, set_value);  
       else  
         SET_CATEGORY_SET (category_set, category, set_value);  
       return Qnil;  
     }  
   
   /* The third (bottom) level table.  */  
   if (!SUB_CHAR_TABLE_P (val))  
     {  
       val = make_sub_char_table (Qnil);  
       XCHAR_TABLE (table)->contents[c1] = val;  
       /* We must set default category set of CHARSET and C1 in  
          `defalt' slot.  */  
       XCHAR_TABLE (val)->defalt = category_set;  
     }  
   table = val;  
   
   val = XCHAR_TABLE (table)->contents[c2];  
   if (CATEGORY_SET_P (val))  
     category_set = val;  
   else if (!SUB_CHAR_TABLE_P (val))  
364      {      {
365        category_set = Fcopy_sequence (XCHAR_TABLE (table)->defalt);        category_set = char_table_ref_and_range (table, start, &from, &to);
366        XCHAR_TABLE (table)->contents[c2] = category_set;        if (from < start || to > end)
367            category_set = Fcopy_sequence (category_set);
368          SET_CATEGORY_SET (category_set, category, set_value);
369          if (from < start)
370            {
371              if (to > end)
372                char_table_set_range (table, start, end, category_set);
373              else
374                char_table_set_range (table, start, to, category_set);
375            }
376          else if (to > end)
377            char_table_set_range (table, start, end, category_set);
378          start = to + 1;
379      }      }
   else  
     /* This should never happen.  */  
     error ("Invalid category table");  
   
   SET_CATEGORY_SET (category_set, category, set_value);  
   
380    return Qnil;    return Qnil;
381  }  }
382    

Legend:
Removed from v.1.30  
changed lines
  Added in v.1.30.2.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26