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

Diff of /emacs/src/coding.c

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

revision 1.271 by handa, Thu Mar 13 11:32:18 2003 UTC revision 1.272 by handa, Tue Mar 18 04:26:15 2003 UTC
# Line 506  Lisp_Object Vtranslation_table_for_input Line 506  Lisp_Object Vtranslation_table_for_input
506     to avoid infinite recursive call.  */     to avoid infinite recursive call.  */
507  static int inhibit_pre_post_conversion;  static int inhibit_pre_post_conversion;
508    
 /* Char-table containing safe coding systems of each character.  */  
 Lisp_Object Vchar_coding_system_table;  
509  Lisp_Object Qchar_coding_system;  Lisp_Object Qchar_coding_system;
510    
511  /* Return `safe-chars' property of CODING_SYSTEM (symbol).  Don't check  /* Return `safe-chars' property of CODING_SYSTEM (symbol).  Don't check
# Line 6388  highest priority.  */) Line 6386  highest priority.  */)
6386                                 STRING_MULTIBYTE (string));                                 STRING_MULTIBYTE (string));
6387  }  }
6388    
 /* Return an intersection of lists L1 and L2.  */  
   
 static Lisp_Object  
 intersection (l1, l2)  
      Lisp_Object l1, l2;  
 {  
   Lisp_Object val = Fcons (Qnil, Qnil), tail;  
   
   for (tail = val; CONSP (l1); l1 = XCDR (l1))  
     {  
       if (!NILP (Fmemq (XCAR (l1), l2)))  
         {  
           XSETCDR (tail, Fcons (XCAR (l1), Qnil));  
           tail = XCDR (tail);  
         }  
     }  
   return XCDR (val);  
 }  
   
   
6389  /*  Subroutine for Fsafe_coding_systems_region_internal.  /*  Subroutine for Fsafe_coding_systems_region_internal.
6390    
6391      Return a list of coding systems that safely encode the multibyte      Return a list of coding systems that safely encode the multibyte
# Line 6427  find_safe_codings (p, pend, safe_codings Line 6405  find_safe_codings (p, pend, safe_codings
6405       Lisp_Object safe_codings, work_table;       Lisp_Object safe_codings, work_table;
6406       int *single_byte_char_found;       int *single_byte_char_found;
6407  {  {
   int c, len, idx;  
   Lisp_Object val;  
   
   while (p < pend)  
     {  
       c = STRING_CHAR_AND_LENGTH (p, pend - p, len);  
       p += len;  
       if (ASCII_BYTE_P (c))  
         /* We can ignore ASCII characters here.  */  
         continue;  
       if (SINGLE_BYTE_CHAR_P (c))  
         *single_byte_char_found = 1;  
       if (NILP (safe_codings))  
         continue;  
       /* Check the safe coding systems for C.  */  
       val = char_table_ref_and_index (work_table, c, &idx);  
       if (EQ (val, Qt))  
         /* This element was already checked.  Ignore it.  */  
         continue;  
       /* Remember that we checked this element.  */  
       CHAR_TABLE_SET (work_table, make_number (idx), Qt);  
   
       /* If there are some safe coding systems for C and we have  
          already found the other set of coding systems for the  
          different characters, get the intersection of them.  */  
       if (!EQ (safe_codings, Qt) && !NILP (val))  
         val = intersection (safe_codings, val);  
       safe_codings = val;  
     }  
   return safe_codings;  
 }  
   
   
 /* Return a list of coding systems that safely encode the text between  
    START and END.  If the text contains only ASCII or is unibyte,  
    return t.  */  
   
 DEFUN ("find-coding-systems-region-internal",  
        Ffind_coding_systems_region_internal,  
        Sfind_coding_systems_region_internal, 2, 2, 0,  
        doc: /* Internal use only.  */)  
      (start, end)  
      Lisp_Object start, end;  
 {  
   Lisp_Object work_table, safe_codings;  
   int non_ascii_p = 0;  
   int single_byte_char_found = 0;  
   const unsigned char *p1, *p1end, *p2, *p2end, *p;  
   
   if (STRINGP (start))  
     {  
       if (!STRING_MULTIBYTE (start))  
         return Qt;  
       p1 = SDATA (start), p1end = p1 + SBYTES (start);  
       p2 = p2end = p1end;  
       if (SCHARS (start) != SBYTES (start))  
         non_ascii_p = 1;  
     }  
   else  
     {  
       int from, to, stop;  
   
       CHECK_NUMBER_COERCE_MARKER (start);  
       CHECK_NUMBER_COERCE_MARKER (end);  
       if (XINT (start) < BEG || XINT (end) > Z || XINT (start) > XINT (end))  
         args_out_of_range (start, end);  
       if (NILP (current_buffer->enable_multibyte_characters))  
         return Qt;  
       from = CHAR_TO_BYTE (XINT (start));  
       to = CHAR_TO_BYTE (XINT (end));  
       stop = from < GPT_BYTE && GPT_BYTE < to ? GPT_BYTE : to;  
       p1 = BYTE_POS_ADDR (from), p1end = p1 + (stop - from);  
       if (stop == to)  
         p2 = p2end = p1end;  
       else  
         p2 = BYTE_POS_ADDR (stop), p2end = p2 + (to - stop);  
       if (XINT (end) - XINT (start) != to - from)  
         non_ascii_p = 1;  
     }  
   
   if (!non_ascii_p)  
     {  
       /* We are sure that the text contains no multibyte character.  
          Check if it contains eight-bit-graphic.  */  
       p = p1;  
       for (p = p1; p < p1end && ASCII_BYTE_P (*p); p++);  
       if (p == p1end)  
         {  
           for (p = p2; p < p2end && ASCII_BYTE_P (*p); p++);  
           if (p == p2end)  
             return Qt;  
         }  
     }  
   
   /* The text contains non-ASCII characters.  */  
   work_table = Fcopy_sequence (Vchar_coding_system_table);  
   safe_codings = find_safe_codings (p1, p1end, Qt, work_table,  
                                     &single_byte_char_found);  
   if (p2 < p2end)  
     safe_codings = find_safe_codings (p2, p2end, safe_codings, work_table,  
                                       &single_byte_char_found);  
   
   if (EQ (safe_codings, Qt))  
     ; /* Nothing to be done.  */  
   else if (!single_byte_char_found)  
     {  
       /* Append generic coding systems.  */  
       Lisp_Object args[2];  
       args[0] = safe_codings;  
       args[1] = Fchar_table_extra_slot (Vchar_coding_system_table,  
                                         make_number (0));  
       safe_codings = Fappend (2, args);  
     }  
   else  
     safe_codings = Fcons (Qraw_text,  
                           Fcons (Qemacs_mule,  
                                  Fcons (Qno_conversion, safe_codings)));  
   return safe_codings;  
 }  
   
   
 static Lisp_Object  
 find_safe_codings_2 (p, pend, safe_codings, work_table, single_byte_char_found)  
      unsigned char *p, *pend;  
      Lisp_Object safe_codings, work_table;  
      int *single_byte_char_found;  
 {  
6408    int c, len, i;    int c, len, i;
6409    Lisp_Object val, ch;    Lisp_Object val, ch;
6410    Lisp_Object prev, tail;    Lisp_Object prev, tail;
# Line 6597  find_safe_codings_2 (p, pend, safe_codin Line 6448  find_safe_codings_2 (p, pend, safe_codin
6448    return safe_codings;    return safe_codings;
6449  }  }
6450    
6451  DEFUN ("find-coding-systems-region-internal-2",  DEFUN ("find-coding-systems-region-internal",
6452         Ffind_coding_systems_region_internal_2,         Ffind_coding_systems_region_internal,
6453         Sfind_coding_systems_region_internal_2, 2, 2, 0,         Sfind_coding_systems_region_internal, 2, 2, 0,
6454         doc: /* Internal use only.  */)         doc: /* Internal use only.  */)
6455       (start, end)       (start, end)
6456       Lisp_Object start, end;       Lisp_Object start, end;
# Line 6659  DEFUN ("find-coding-systems-region-inter Line 6510  DEFUN ("find-coding-systems-region-inter
6510    work_table = Fmake_char_table (Qchar_coding_system, Qnil);    work_table = Fmake_char_table (Qchar_coding_system, Qnil);
6511    safe_codings = Fcopy_sequence (XCDR (Vcoding_system_safe_chars));    safe_codings = Fcopy_sequence (XCDR (Vcoding_system_safe_chars));
6512    
6513    safe_codings = find_safe_codings_2 (p1, p1end, safe_codings, work_table,    safe_codings = find_safe_codings (p1, p1end, safe_codings, work_table,
6514                                        &single_byte_char_found);                                      &single_byte_char_found);
6515    if (p2 < p2end)    if (p2 < p2end)
6516      safe_codings = find_safe_codings_2 (p2, p2end, safe_codings, work_table,      safe_codings = find_safe_codings (p2, p2end, safe_codings, work_table,
6517                                          &single_byte_char_found);                                        &single_byte_char_found);
6518    if (EQ (safe_codings, XCDR (Vcoding_system_safe_chars)))    if (EQ (safe_codings, XCDR (Vcoding_system_safe_chars)))
6519      safe_codings = Qt;      safe_codings = Qt;
6520    else    else
# Line 7534  syms_of_coding () Line 7385  syms_of_coding ()
7385       But don't staticpro it here--that is done in alloc.c.  */       But don't staticpro it here--that is done in alloc.c.  */
7386    Qchar_table_extra_slots = intern ("char-table-extra-slots");    Qchar_table_extra_slots = intern ("char-table-extra-slots");
7387    Fput (Qsafe_chars, Qchar_table_extra_slots, make_number (0));    Fput (Qsafe_chars, Qchar_table_extra_slots, make_number (0));
7388    Fput (Qchar_coding_system, Qchar_table_extra_slots, make_number (2));    Fput (Qchar_coding_system, Qchar_table_extra_slots, make_number (0));
7389    
7390    Qvalid_codes = intern ("valid-codes");    Qvalid_codes = intern ("valid-codes");
7391    staticpro (&Qvalid_codes);    staticpro (&Qvalid_codes);
# Line 7552  syms_of_coding () Line 7403  syms_of_coding ()
7403    defsubr (&Sdetect_coding_region);    defsubr (&Sdetect_coding_region);
7404    defsubr (&Sdetect_coding_string);    defsubr (&Sdetect_coding_string);
7405    defsubr (&Sfind_coding_systems_region_internal);    defsubr (&Sfind_coding_systems_region_internal);
   defsubr (&Sfind_coding_systems_region_internal_2);  
7406    defsubr (&Sunencodable_char_position);    defsubr (&Sunencodable_char_position);
7407    defsubr (&Sdecode_coding_region);    defsubr (&Sdecode_coding_region);
7408    defsubr (&Sencode_coding_region);    defsubr (&Sencode_coding_region);
# Line 7774  called even if `coding-system-for-write' Line 7624  called even if `coding-system-for-write'
7624    coding_system_require_warning = 0;    coding_system_require_warning = 0;
7625    
7626    
   DEFVAR_LISP ("char-coding-system-table", &Vchar_coding_system_table,  
                doc: /* Char-table containing safe coding systems of each characters.  
 Each element doesn't include such generic coding systems that can  
 encode any characters.  They are in the first extra slot.  */);  
   Vchar_coding_system_table = Fmake_char_table (Qchar_coding_system, Qnil);  
   
7627    DEFVAR_BOOL ("inhibit-iso-escape-detection",    DEFVAR_BOOL ("inhibit-iso-escape-detection",
7628                 &inhibit_iso_escape_detection,                 &inhibit_iso_escape_detection,
7629                 doc: /* If non-nil, Emacs ignores ISO2022's escape sequence on code detection.                 doc: /* If non-nil, Emacs ignores ISO2022's escape sequence on code detection.

Legend:
Removed from v.1.271  
changed lines
  Added in v.1.272

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