aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding.c
diff options
context:
space:
mode:
authorKenichi Handa2003-01-31 04:03:07 +0000
committerKenichi Handa2003-01-31 04:03:07 +0000
commit6b89e3aa2801c5be6b42d8a1ac8337f355ed216c (patch)
tree9d5b28a024ab2e44c8d0169f2a337a720d1aa5c8 /src/coding.c
parentbc6371a658fc753f1b9872c708868b2da468f2ee (diff)
downloademacs-6b89e3aa2801c5be6b42d8a1ac8337f355ed216c.tar.gz
emacs-6b89e3aa2801c5be6b42d8a1ac8337f355ed216c.zip
(syms_of_coding): Add `...' for symbols in the docstring of
`coding-system-require-warning'.
Diffstat (limited to 'src/coding.c')
-rw-r--r--src/coding.c213
1 files changed, 201 insertions, 12 deletions
diff --git a/src/coding.c b/src/coding.c
index 3dba84efe63..fb7cd0cd9db 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -381,6 +381,16 @@ int system_eol_type;
381 381
382#ifdef emacs 382#ifdef emacs
383 383
384/* Information about which coding system is safe for which chars.
385 The value has the form (GENERIC-LIST . NON-GENERIC-ALIST).
386
387 GENERIC-LIST is a list of generic coding systems which can encode
388 any characters.
389
390 NON-GENERIC-ALIST is an alist of non generic coding systems vs the
391 corresponding char table that contains safe chars. */
392Lisp_Object Vcoding_system_safe_chars;
393
384Lisp_Object Vcoding_system_list, Vcoding_system_alist; 394Lisp_Object Vcoding_system_list, Vcoding_system_alist;
385 395
386Lisp_Object Qcoding_system_p, Qcoding_system_error; 396Lisp_Object Qcoding_system_p, Qcoding_system_error;
@@ -500,16 +510,16 @@ static int inhibit_pre_post_conversion;
500Lisp_Object Vchar_coding_system_table; 510Lisp_Object Vchar_coding_system_table;
501Lisp_Object Qchar_coding_system; 511Lisp_Object Qchar_coding_system;
502 512
503/* Return `safe-chars' property of coding system CODING. Don't check 513/* Return `safe-chars' property of CODING_SYSTEM (symbol). Don't check
504 validity of CODING. */ 514 its validity. */
505 515
506Lisp_Object 516Lisp_Object
507coding_safe_chars (coding) 517coding_safe_chars (coding_system)
508 struct coding_system *coding; 518 Lisp_Object coding_system;
509{ 519{
510 Lisp_Object coding_spec, plist, safe_chars; 520 Lisp_Object coding_spec, plist, safe_chars;
511 521
512 coding_spec = Fget (coding->symbol, Qcoding_system); 522 coding_spec = Fget (coding_system, Qcoding_system);
513 plist = XVECTOR (coding_spec)->contents[3]; 523 plist = XVECTOR (coding_spec)->contents[3];
514 safe_chars = Fplist_get (XVECTOR (coding_spec)->contents[3], Qsafe_chars); 524 safe_chars = Fplist_get (XVECTOR (coding_spec)->contents[3], Qsafe_chars);
515 return (CHAR_TABLE_P (safe_chars) ? safe_chars : Qt); 525 return (CHAR_TABLE_P (safe_chars) ? safe_chars : Qt);
@@ -1310,7 +1320,7 @@ enum iso_code_class_type iso_code_class[256];
1310#define CHARSET_OK(idx, charset, c) \ 1320#define CHARSET_OK(idx, charset, c) \
1311 (coding_system_table[idx] \ 1321 (coding_system_table[idx] \
1312 && (charset == CHARSET_ASCII \ 1322 && (charset == CHARSET_ASCII \
1313 || (safe_chars = coding_safe_chars (coding_system_table[idx]), \ 1323 || (safe_chars = coding_safe_chars (coding_system_table[idx]->symbol), \
1314 CODING_SAFE_CHAR_P (safe_chars, c))) \ 1324 CODING_SAFE_CHAR_P (safe_chars, c))) \
1315 && (CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding_system_table[idx], \ 1325 && (CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding_system_table[idx], \
1316 charset) \ 1326 charset) \
@@ -1739,7 +1749,7 @@ decode_coding_iso2022 (coding, source, destination, src_bytes, dst_bytes)
1739 Lisp_Object translation_table; 1749 Lisp_Object translation_table;
1740 Lisp_Object safe_chars; 1750 Lisp_Object safe_chars;
1741 1751
1742 safe_chars = coding_safe_chars (coding); 1752 safe_chars = coding_safe_chars (coding->symbol);
1743 1753
1744 if (NILP (Venable_character_translation)) 1754 if (NILP (Venable_character_translation))
1745 translation_table = Qnil; 1755 translation_table = Qnil;
@@ -2492,7 +2502,7 @@ encode_coding_iso2022 (coding, source, destination, src_bytes, dst_bytes)
2492 Lisp_Object translation_table; 2502 Lisp_Object translation_table;
2493 Lisp_Object safe_chars; 2503 Lisp_Object safe_chars;
2494 2504
2495 safe_chars = coding_safe_chars (coding); 2505 safe_chars = coding_safe_chars (coding->symbol);
2496 2506
2497 if (NILP (Venable_character_translation)) 2507 if (NILP (Venable_character_translation))
2498 translation_table = Qnil; 2508 translation_table = Qnil;
@@ -6495,6 +6505,146 @@ DEFUN ("find-coding-systems-region-internal",
6495} 6505}
6496 6506
6497 6507
6508static Lisp_Object
6509find_safe_codings_2 (p, pend, safe_codings, work_table, single_byte_char_found)
6510 unsigned char *p, *pend;
6511 Lisp_Object safe_codings, work_table;
6512 int *single_byte_char_found;
6513{
6514 int c, len, i;
6515 Lisp_Object val, ch;
6516 Lisp_Object prev, tail;
6517
6518 while (p < pend)
6519 {
6520 c = STRING_CHAR_AND_LENGTH (p, pend - p, len);
6521 p += len;
6522 if (ASCII_BYTE_P (c))
6523 /* We can ignore ASCII characters here. */
6524 continue;
6525 if (SINGLE_BYTE_CHAR_P (c))
6526 *single_byte_char_found = 1;
6527 if (NILP (safe_codings))
6528 /* Already all coding systems are excluded. */
6529 continue;
6530 /* Check the safe coding systems for C. */
6531 ch = make_number (c);
6532 val = Faref (work_table, ch);
6533 if (EQ (val, Qt))
6534 /* This element was already checked. Ignore it. */
6535 continue;
6536 /* Remember that we checked this element. */
6537 Faset (work_table, ch, Qt);
6538
6539 for (prev = tail = safe_codings; CONSP (tail); tail = XCDR (tail))
6540 {
6541 val = XCAR (tail);
6542 if (NILP (Faref (XCDR (val), ch)))
6543 {
6544 /* Exclued this coding system from SAFE_CODINGS. */
6545 if (EQ (tail, safe_codings))
6546 safe_codings = XCDR (safe_codings);
6547 else
6548 XSETCDR (prev, XCDR (tail));
6549 }
6550 else
6551 prev = tail;
6552 }
6553 }
6554 return safe_codings;
6555}
6556
6557DEFUN ("find-coding-systems-region-internal-2",
6558 Ffind_coding_systems_region_internal_2,
6559 Sfind_coding_systems_region_internal_2, 2, 2, 0,
6560 doc: /* Internal use only. */)
6561 (start, end)
6562 Lisp_Object start, end;
6563{
6564 Lisp_Object work_table, safe_codings;
6565 int non_ascii_p = 0;
6566 int single_byte_char_found = 0;
6567 const unsigned char *p1, *p1end, *p2, *p2end, *p;
6568
6569 if (STRINGP (start))
6570 {
6571 if (!STRING_MULTIBYTE (start))
6572 return Qt;
6573 p1 = SDATA (start), p1end = p1 + SBYTES (start);
6574 p2 = p2end = p1end;
6575 if (SCHARS (start) != SBYTES (start))
6576 non_ascii_p = 1;
6577 }
6578 else
6579 {
6580 int from, to, stop;
6581
6582 CHECK_NUMBER_COERCE_MARKER (start);
6583 CHECK_NUMBER_COERCE_MARKER (end);
6584 if (XINT (start) < BEG || XINT (end) > Z || XINT (start) > XINT (end))
6585 args_out_of_range (start, end);
6586 if (NILP (current_buffer->enable_multibyte_characters))
6587 return Qt;
6588 from = CHAR_TO_BYTE (XINT (start));
6589 to = CHAR_TO_BYTE (XINT (end));
6590 stop = from < GPT_BYTE && GPT_BYTE < to ? GPT_BYTE : to;
6591 p1 = BYTE_POS_ADDR (from), p1end = p1 + (stop - from);
6592 if (stop == to)
6593 p2 = p2end = p1end;
6594 else
6595 p2 = BYTE_POS_ADDR (stop), p2end = p2 + (to - stop);
6596 if (XINT (end) - XINT (start) != to - from)
6597 non_ascii_p = 1;
6598 }
6599
6600 if (!non_ascii_p)
6601 {
6602 /* We are sure that the text contains no multibyte character.
6603 Check if it contains eight-bit-graphic. */
6604 p = p1;
6605 for (p = p1; p < p1end && ASCII_BYTE_P (*p); p++);
6606 if (p == p1end)
6607 {
6608 for (p = p2; p < p2end && ASCII_BYTE_P (*p); p++);
6609 if (p == p2end)
6610 return Qt;
6611 }
6612 }
6613
6614 /* The text contains non-ASCII characters. */
6615
6616 work_table = Fmake_char_table (Qchar_coding_system, Qnil);
6617 safe_codings = Fcopy_sequence (XCDR (Vcoding_system_safe_chars));
6618
6619 safe_codings = find_safe_codings_2 (p1, p1end, safe_codings, work_table,
6620 &single_byte_char_found);
6621 if (p2 < p2end)
6622 safe_codings = find_safe_codings_2 (p2, p2end, safe_codings, work_table,
6623 &single_byte_char_found);
6624 if (EQ (safe_codings, XCDR (Vcoding_system_safe_chars)))
6625 safe_codings = Qt;
6626 else
6627 {
6628 /* Turn safe_codings to a list of coding systems... */
6629 Lisp_Object val;
6630
6631 if (single_byte_char_found)
6632 /* ... and append these for eight-bit chars. */
6633 val = Fcons (Qraw_text,
6634 Fcons (Qemacs_mule, Fcons (Qno_conversion, Qnil)));
6635 else
6636 /* ... and append generic coding systems. */
6637 val = Fcopy_sequence (XCAR (Vcoding_system_safe_chars));
6638
6639 for (; CONSP (safe_codings); safe_codings = XCDR (safe_codings))
6640 val = Fcons (XCAR (XCAR (safe_codings)), val);
6641 safe_codings = val;
6642 }
6643
6644 return safe_codings;
6645}
6646
6647
6498/* Search from position POS for such characters that are unencodable 6648/* Search from position POS for such characters that are unencodable
6499 accoding to SAFE_CHARS, and return a list of their positions. P 6649 accoding to SAFE_CHARS, and return a list of their positions. P
6500 points where in the memory the character at POS exists. Limit the 6650 points where in the memory the character at POS exists. Limit the
@@ -6609,7 +6759,7 @@ to the string. */)
6609 if (coding.type == coding_type_undecided) 6759 if (coding.type == coding_type_undecided)
6610 safe_chars = Qnil; 6760 safe_chars = Qnil;
6611 else 6761 else
6612 safe_chars = coding_safe_chars (&coding); 6762 safe_chars = coding_safe_chars (coding_system);
6613 6763
6614 if (STRINGP (string) 6764 if (STRINGP (string)
6615 || from >= GPT || to <= GPT) 6765 || from >= GPT || to <= GPT)
@@ -7127,6 +7277,40 @@ This function is internal use only. */)
7127 return Qnil; 7277 return Qnil;
7128} 7278}
7129 7279
7280DEFUN ("define-coding-system-internal", Fdefine_coding_system_internal,
7281 Sdefine_coding_system_internal, 1, 1, 0,
7282 doc: /* Register CODING-SYSTEM as a base coding system.
7283This function is internal use only. */)
7284 (coding_system)
7285 Lisp_Object coding_system;
7286{
7287 Lisp_Object safe_chars, slot;
7288
7289 if (NILP (Fcheck_coding_system (coding_system)))
7290 Fsignal (Qcoding_system_error, Fcons (coding_system, Qnil));
7291 safe_chars = coding_safe_chars (coding_system);
7292 if (! EQ (safe_chars, Qt) && ! CHAR_TABLE_P (safe_chars))
7293 error ("No valid safe-chars property for %s",
7294 SDATA (SYMBOL_NAME (coding_system)));
7295 if (EQ (safe_chars, Qt))
7296 {
7297 if (NILP (Fmemq (coding_system, XCAR (Vcoding_system_safe_chars))))
7298 XSETCAR (Vcoding_system_safe_chars,
7299 Fcons (coding_system, XCAR (Vcoding_system_safe_chars)));
7300 }
7301 else
7302 {
7303 slot = Fassq (coding_system, XCDR (Vcoding_system_safe_chars));
7304 if (NILP (slot))
7305 XSETCDR (Vcoding_system_safe_chars,
7306 nconc2 (XCDR (Vcoding_system_safe_chars),
7307 Fcons (Fcons (coding_system, safe_chars), Qnil)));
7308 else
7309 XSETCDR (slot, safe_chars);
7310 }
7311 return Qnil;
7312}
7313
7130#endif /* emacs */ 7314#endif /* emacs */
7131 7315
7132 7316
@@ -7280,6 +7464,9 @@ syms_of_coding ()
7280 } 7464 }
7281 } 7465 }
7282 7466
7467 Vcoding_system_safe_chars = Fcons (Qnil, Qnil);
7468 staticpro (&Vcoding_system_safe_chars);
7469
7283 Qtranslation_table = intern ("translation-table"); 7470 Qtranslation_table = intern ("translation-table");
7284 staticpro (&Qtranslation_table); 7471 staticpro (&Qtranslation_table);
7285 Fput (Qtranslation_table, Qchar_table_extra_slots, make_number (1)); 7472 Fput (Qtranslation_table, Qchar_table_extra_slots, make_number (1));
@@ -7322,6 +7509,7 @@ syms_of_coding ()
7322 defsubr (&Sdetect_coding_region); 7509 defsubr (&Sdetect_coding_region);
7323 defsubr (&Sdetect_coding_string); 7510 defsubr (&Sdetect_coding_string);
7324 defsubr (&Sfind_coding_systems_region_internal); 7511 defsubr (&Sfind_coding_systems_region_internal);
7512 defsubr (&Sfind_coding_systems_region_internal_2);
7325 defsubr (&Sunencodable_char_position); 7513 defsubr (&Sunencodable_char_position);
7326 defsubr (&Sdecode_coding_region); 7514 defsubr (&Sdecode_coding_region);
7327 defsubr (&Sencode_coding_region); 7515 defsubr (&Sencode_coding_region);
@@ -7339,6 +7527,7 @@ syms_of_coding ()
7339 defsubr (&Sfind_operation_coding_system); 7527 defsubr (&Sfind_operation_coding_system);
7340 defsubr (&Supdate_coding_systems_internal); 7528 defsubr (&Supdate_coding_systems_internal);
7341 defsubr (&Sset_coding_priority_internal); 7529 defsubr (&Sset_coding_priority_internal);
7530 defsubr (&Sdefine_coding_system_internal);
7342 7531
7343 DEFVAR_LISP ("coding-system-list", &Vcoding_system_list, 7532 DEFVAR_LISP ("coding-system-list", &Vcoding_system_list,
7344 doc: /* List of coding systems. 7533 doc: /* List of coding systems.
@@ -7536,9 +7725,9 @@ The default value is `select-safe-coding-system' (which see). */);
7536 DEFVAR_BOOL ("coding-system-require-warning", 7725 DEFVAR_BOOL ("coding-system-require-warning",
7537 &coding_system_require_warning, 7726 &coding_system_require_warning,
7538 doc: /* Internal use only. 7727 doc: /* Internal use only.
7539If non-nil, on writing a file, select-safe-coding-system-function is 7728If non-nil, on writing a file, `select-safe-coding-system-function' is
7540called even if coding-system-for-write is non-nil. The command 7729called even if `coding-system-for-write' is non-nil. The command
7541universal-coding-system-argument binds this variable to t temporarily. */); 7730`universal-coding-system-argument' binds this variable to t temporarily. */);
7542 coding_system_require_warning = 0; 7731 coding_system_require_warning = 0;
7543 7732
7544 7733