Mercurial > hg > xemacs-beta
comparison src/file-coding.c @ 5125:b5df3737028a ben-lisp-object
merge
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Wed, 24 Feb 2010 01:58:04 -0600 |
parents | 623d57b7fbe8 16112448d484 |
children | 2a462149bd6a |
comparison
equal
deleted
inserted
replaced
5124:623d57b7fbe8 | 5125:b5df3737028a |
---|---|
295 print_coding_system (Lisp_Object obj, Lisp_Object printcharfun, | 295 print_coding_system (Lisp_Object obj, Lisp_Object printcharfun, |
296 int UNUSED (escapeflag)) | 296 int UNUSED (escapeflag)) |
297 { | 297 { |
298 Lisp_Coding_System *c = XCODING_SYSTEM (obj); | 298 Lisp_Coding_System *c = XCODING_SYSTEM (obj); |
299 if (print_readably) | 299 if (print_readably) |
300 printing_unreadable_object | 300 printing_unreadable_lcrecord (obj, 0); |
301 ("printing unreadable object #<coding-system 0x%x>", c->header.uid); | |
302 | 301 |
303 write_fmt_string_lisp (printcharfun, "#<coding-system %s ", 1, c->name); | 302 write_fmt_string_lisp (printcharfun, "#<coding-system %s ", 1, c->name); |
304 print_coding_system_properties (obj, printcharfun); | 303 print_coding_system_properties (obj, printcharfun); |
305 write_c_string (printcharfun, ">"); | 304 write_ascstring (printcharfun, ">"); |
306 } | 305 } |
307 | 306 |
308 /* Print an abbreviated version of a coding system (but still containing | 307 /* Print an abbreviated version of a coding system (but still containing |
309 all the information), for use within a coding system print method. */ | 308 all the information), for use within a coding system print method. */ |
310 | 309 |
312 print_coding_system_in_print_method (Lisp_Object cs, Lisp_Object printcharfun, | 311 print_coding_system_in_print_method (Lisp_Object cs, Lisp_Object printcharfun, |
313 int UNUSED (escapeflag)) | 312 int UNUSED (escapeflag)) |
314 { | 313 { |
315 write_fmt_string_lisp (printcharfun, "%s[", 1, XCODING_SYSTEM_NAME (cs)); | 314 write_fmt_string_lisp (printcharfun, "%s[", 1, XCODING_SYSTEM_NAME (cs)); |
316 print_coding_system_properties (cs, printcharfun); | 315 print_coding_system_properties (cs, printcharfun); |
317 write_c_string (printcharfun, "]"); | 316 write_ascstring (printcharfun, "]"); |
318 } | 317 } |
319 | 318 |
320 #ifndef NEW_GC | 319 #ifndef NEW_GC |
321 static void | 320 static void |
322 finalize_coding_system (void *header) | 321 finalize_coding_system (void *header) |
495 else | 494 else |
496 { | 495 { |
497 fail_range_start = pos; | 496 fail_range_start = pos; |
498 while ((pos < end) && | 497 while ((pos < end) && |
499 (EQ (Qnil, get_char_table (ch, safe_chars)) | 498 (EQ (Qnil, get_char_table (ch, safe_chars)) |
500 && (failed_reason = query_coding_unencodable)) | 499 && (failed_reason = query_coding_unencodable, |
501 && (previous_failed_reason == query_coding_succeeded | 500 (previous_failed_reason == query_coding_succeeded |
502 || previous_failed_reason == failed_reason)) | 501 || previous_failed_reason == failed_reason)))) |
503 { | 502 { |
504 pos++; | 503 pos++; |
505 INC_BYTEBPOS (buf, pos_byte); | 504 INC_BYTEBPOS (buf, pos_byte); |
506 ch = BYTE_BUF_FETCH_CHAR (buf, pos_byte); | 505 ch = BYTE_BUF_FETCH_CHAR (buf, pos_byte); |
507 previous_failed_reason = failed_reason; | 506 previous_failed_reason = failed_reason; |
517 { | 516 { |
518 assert (previous_failed_reason == query_coding_unencodable); | 517 assert (previous_failed_reason == query_coding_unencodable); |
519 | 518 |
520 if (flags & QUERY_METHOD_ERRORP) | 519 if (flags & QUERY_METHOD_ERRORP) |
521 { | 520 { |
522 DECLARE_EISTRING (error_details); | 521 signal_error_2 |
523 | 522 (Qtext_conversion_error, |
524 eicpy_ascii (error_details, "Cannot encode "); | 523 "Cannot encode using coding system", |
525 eicat_lstr (error_details, | 524 make_string_from_buffer (buf, fail_range_start, |
526 make_string_from_buffer (buf, fail_range_start, | 525 pos - fail_range_start), |
527 pos - | 526 XCODING_SYSTEM_NAME (codesys)); |
528 fail_range_start)); | |
529 eicat_ascii (error_details, " using coding system"); | |
530 | |
531 signal_error (Qtext_conversion_error, | |
532 (const CIbyte *)(eidata (error_details)), | |
533 XCODING_SYSTEM_NAME (codesys)); | |
534 } | 527 } |
535 | 528 |
536 if (NILP (result)) | 529 if (NILP (result)) |
537 { | 530 { |
538 result = Fmake_range_table (Qstart_closed_end_open); | 531 result = Fmake_range_table (Qstart_closed_end_open); |
675 eidel (desired_base, length - (sizeof ("-dos") - 1), -1, | 668 eidel (desired_base, length - (sizeof ("-dos") - 1), -1, |
676 4, 4); | 669 4, 4); |
677 } | 670 } |
678 } | 671 } |
679 | 672 |
680 coding_system_or_name = intern_int (eidata (desired_base)); | 673 coding_system_or_name = intern_istring (eidata (desired_base)); |
681 | 674 |
682 /* Remove this coding system and its subsidiary coding | 675 /* Remove this coding system and its subsidiary coding |
683 systems from the hash, to avoid calling this code recursively. */ | 676 systems from the hash, to avoid calling this code recursively. */ |
684 Fremhash (coding_system_or_name, Vcoding_system_hash_table); | 677 Fremhash (coding_system_or_name, Vcoding_system_hash_table); |
685 Fremhash (add_suffix_to_symbol(coding_system_or_name, "-unix"), | 678 Fremhash (add_suffix_to_symbol(coding_system_or_name, "-unix"), |
693 eicat_lstr (warning_info, XSYMBOL_NAME (coding_system_or_name)); | 686 eicat_lstr (warning_info, XSYMBOL_NAME (coding_system_or_name)); |
694 | 687 |
695 /* Keep around the form so it doesn't disappear from under | 688 /* Keep around the form so it doesn't disappear from under |
696 #'eval's feet. */ | 689 #'eval's feet. */ |
697 GCPRO1 (lookup); | 690 GCPRO1 (lookup); |
698 call1_trapping_problems ((const CIbyte *)eidata (warning_info), | 691 call1_trapping_problems ((const CIbyte *) eidata (warning_info), |
699 Qeval, lookup, 0); | 692 Qeval, lookup, 0); |
700 UNGCPRO; | 693 UNGCPRO; |
701 | 694 |
702 lookup = | 695 lookup = |
703 Fgethash (coding_system_or_name, Vcoding_system_hash_table, Qnil); | 696 Fgethash (coding_system_or_name, Vcoding_system_hash_table, Qnil); |
1102 const Ascbyte *extension = coding_subsidiary_list[i].extension; | 1095 const Ascbyte *extension = coding_subsidiary_list[i].extension; |
1103 const Ascbyte *mnemonic_ext = coding_subsidiary_list[i].mnemonic_ext; | 1096 const Ascbyte *mnemonic_ext = coding_subsidiary_list[i].mnemonic_ext; |
1104 enum eol_type eol = coding_subsidiary_list[i].eol; | 1097 enum eol_type eol = coding_subsidiary_list[i].eol; |
1105 | 1098 |
1106 qxestrcpy_ascii (codesys_name + len, extension); | 1099 qxestrcpy_ascii (codesys_name + len, extension); |
1107 codesys_name_sym = intern_int (codesys_name); | 1100 codesys_name_sym = intern_istring (codesys_name); |
1108 if (mlen != -1) | 1101 if (mlen != -1) |
1109 qxestrcpy_ascii (codesys_mnemonic + mlen, mnemonic_ext); | 1102 qxestrcpy_ascii (codesys_mnemonic + mlen, mnemonic_ext); |
1110 | 1103 |
1111 sub_codesys = Fcopy_coding_system (codesys, codesys_name_sym); | 1104 sub_codesys = Fcopy_coding_system (codesys, codesys_name_sym); |
1112 if (mlen != -1) | 1105 if (mlen != -1) |
1113 XCODING_SYSTEM_MNEMONIC (sub_codesys) = | 1106 XCODING_SYSTEM_MNEMONIC (sub_codesys) = |
1114 build_intstring (codesys_mnemonic); | 1107 build_istring (codesys_mnemonic); |
1115 | 1108 |
1116 if (eol != EOL_LF) | 1109 if (eol != EOL_LF) |
1117 { | 1110 { |
1118 Lisp_Object chain = list2 (get_coding_system_for_text_file | 1111 Lisp_Object chain = list2 (get_coding_system_for_text_file |
1119 (codesys, 0), | 1112 (codesys, 0), |
1122 Lisp_Object canon = | 1115 Lisp_Object canon = |
1123 make_internal_coding_system | 1116 make_internal_coding_system |
1124 (sub_codesys, "internal-subsidiary-eol-wrapper", | 1117 (sub_codesys, "internal-subsidiary-eol-wrapper", |
1125 Qchain, Qunbound, | 1118 Qchain, Qunbound, |
1126 mlen != -1 ? | 1119 mlen != -1 ? |
1127 list6 (Qmnemonic, build_intstring (codesys_mnemonic), | 1120 list6 (Qmnemonic, build_istring (codesys_mnemonic), |
1128 Qchain, chain, | 1121 Qchain, chain, |
1129 Qcanonicalize_after_coding, sub_codesys) : | 1122 Qcanonicalize_after_coding, sub_codesys) : |
1130 list4 (Qchain, chain, | 1123 list4 (Qchain, chain, |
1131 Qcanonicalize_after_coding, sub_codesys)); | 1124 Qcanonicalize_after_coding, sub_codesys)); |
1132 XCODING_SYSTEM_CANONICAL (sub_codesys) = canon; | 1125 XCODING_SYSTEM_CANONICAL (sub_codesys) = canon; |
1208 prefix, | 1201 prefix, |
1209 NILP (name_or_existing) ? (Ibyte *) "nil" : | 1202 NILP (name_or_existing) ? (Ibyte *) "nil" : |
1210 XSTRING_DATA (Fsymbol_name (XCODING_SYSTEM_NAME | 1203 XSTRING_DATA (Fsymbol_name (XCODING_SYSTEM_NAME |
1211 (name_or_existing))), | 1204 (name_or_existing))), |
1212 ++coding_system_tick); | 1205 ++coding_system_tick); |
1213 name_or_existing = intern_int (newname); | 1206 name_or_existing = intern_istring (newname); |
1214 xfree (newname, Ibyte *); | 1207 xfree (newname); |
1215 | 1208 |
1216 if (UNBOUNDP (description)) | 1209 if (UNBOUNDP (description)) |
1217 { | 1210 { |
1218 newname = | 1211 newname = |
1219 emacs_sprintf_malloc | 1212 emacs_sprintf_malloc |
1220 (NULL, "For Internal Use (%s)", | 1213 (NULL, "For Internal Use (%s)", |
1221 XSTRING_DATA (Fsymbol_name (name_or_existing))); | 1214 XSTRING_DATA (Fsymbol_name (name_or_existing))); |
1222 description = build_intstring (newname); | 1215 description = build_istring (newname); |
1223 xfree (newname, Ibyte *); | 1216 xfree (newname); |
1224 } | 1217 } |
1225 | 1218 |
1226 newname = emacs_sprintf_malloc (NULL, "Int%d", coding_system_tick); | 1219 newname = emacs_sprintf_malloc (NULL, "Int%d", coding_system_tick); |
1227 defmnem = build_intstring (newname); | 1220 defmnem = build_istring (newname); |
1228 xfree (newname, Ibyte *); | 1221 xfree (newname); |
1229 } | 1222 } |
1230 else | 1223 else |
1231 CHECK_SYMBOL (name_or_existing); | 1224 CHECK_SYMBOL (name_or_existing); |
1232 | 1225 |
1233 /* See is there an entry for name_or_existing in the defined coding system | 1226 /* See is there an entry for name_or_existing in the defined coding system |
1243 csobj = wrap_coding_system (cs); | 1236 csobj = wrap_coding_system (cs); |
1244 | 1237 |
1245 cs->internal_p = !!prefix; | 1238 cs->internal_p = !!prefix; |
1246 | 1239 |
1247 if (NILP (description)) | 1240 if (NILP (description)) |
1248 description = build_string (""); | 1241 description = build_ascstring (""); |
1249 else | 1242 else |
1250 CHECK_STRING (description); | 1243 CHECK_STRING (description); |
1251 CODING_SYSTEM_DESCRIPTION (cs) = description; | 1244 CODING_SYSTEM_DESCRIPTION (cs) = description; |
1252 | 1245 |
1253 if (!NILP (defmnem)) | 1246 if (!NILP (defmnem)) |
1371 Ibyte *newname = | 1364 Ibyte *newname = |
1372 emacs_sprintf_malloc | 1365 emacs_sprintf_malloc |
1373 (NULL, "internal-eol-copy-%s-%d", | 1366 (NULL, "internal-eol-copy-%s-%d", |
1374 XSTRING_DATA (Fsymbol_name (name_or_existing)), | 1367 XSTRING_DATA (Fsymbol_name (name_or_existing)), |
1375 ++coding_system_tick); | 1368 ++coding_system_tick); |
1376 Lisp_Object newnamesym = intern_int (newname); | 1369 Lisp_Object newnamesym = intern_istring (newname); |
1377 Lisp_Object copied = Fcopy_coding_system (csobj, newnamesym); | 1370 Lisp_Object copied = Fcopy_coding_system (csobj, newnamesym); |
1378 xfree (newname, Ibyte *); | 1371 xfree (newname); |
1379 | 1372 |
1380 XCODING_SYSTEM_CANONICAL (csobj) = | 1373 XCODING_SYSTEM_CANONICAL (csobj) = |
1381 make_internal_coding_system | 1374 make_internal_coding_system |
1382 (csobj, | 1375 (csobj, |
1383 "internal-eol-wrapper", | 1376 "internal-eol-wrapper", |
1836 most SIZE bytes, and delete the data from convert_to. */ | 1829 most SIZE bytes, and delete the data from convert_to. */ |
1837 if (Dynarr_length (str->convert_to) > 0) | 1830 if (Dynarr_length (str->convert_to) > 0) |
1838 { | 1831 { |
1839 Bytecount chunk = | 1832 Bytecount chunk = |
1840 min (size, (Bytecount) Dynarr_length (str->convert_to)); | 1833 min (size, (Bytecount) Dynarr_length (str->convert_to)); |
1841 memcpy (data, Dynarr_atp (str->convert_to, 0), chunk); | 1834 memcpy (data, Dynarr_begin (str->convert_to), chunk); |
1842 Dynarr_delete_many (str->convert_to, 0, chunk); | 1835 Dynarr_delete_many (str->convert_to, 0, chunk); |
1843 data += chunk; | 1836 data += chunk; |
1844 size -= chunk; | 1837 size -= chunk; |
1845 } | 1838 } |
1846 | 1839 |
1865 Dynarr_add_many (str->convert_from, 0, readmore); | 1858 Dynarr_add_many (str->convert_from, 0, readmore); |
1866 read_size = Lstream_read (str->other_end, | 1859 read_size = Lstream_read (str->other_end, |
1867 Dynarr_atp (str->convert_from, rejected), | 1860 Dynarr_atp (str->convert_from, rejected), |
1868 readmore); | 1861 readmore); |
1869 /* Trim size down to how much we actually got */ | 1862 /* Trim size down to how much we actually got */ |
1870 Dynarr_set_size (str->convert_from, rejected + max (0, read_size)); | 1863 Dynarr_set_length (str->convert_from, rejected + max (0, read_size)); |
1871 } | 1864 } |
1872 | 1865 |
1873 if (read_size < 0) /* LSTREAM_ERROR */ | 1866 if (read_size < 0) /* LSTREAM_ERROR */ |
1874 { | 1867 { |
1875 error_occurred = 1; | 1868 error_occurred = 1; |
1887 Bytecount to_process = Dynarr_length (str->convert_from); | 1880 Bytecount to_process = Dynarr_length (str->convert_from); |
1888 | 1881 |
1889 /* Convert the data, and save any rejected data in convert_from */ | 1882 /* Convert the data, and save any rejected data in convert_from */ |
1890 processed = | 1883 processed = |
1891 XCODESYSMETH (str->codesys, convert, | 1884 XCODESYSMETH (str->codesys, convert, |
1892 (str, Dynarr_atp (str->convert_from, 0), | 1885 (str, Dynarr_begin (str->convert_from), |
1893 str->convert_to, to_process)); | 1886 str->convert_to, to_process)); |
1894 if (processed < 0) | 1887 if (processed < 0) |
1895 { | 1888 { |
1896 error_occurred = 1; | 1889 error_occurred = 1; |
1897 break; | 1890 break; |
1898 } | 1891 } |
1899 assert (processed <= to_process); | 1892 assert (processed <= to_process); |
1900 if (processed < to_process) | 1893 if (processed < to_process) |
1901 memmove (Dynarr_atp (str->convert_from, 0), | 1894 memmove (Dynarr_begin (str->convert_from), |
1902 Dynarr_atp (str->convert_from, processed), | 1895 Dynarr_atp (str->convert_from, processed), |
1903 to_process - processed); | 1896 to_process - processed); |
1904 Dynarr_set_size (str->convert_from, to_process - processed); | 1897 Dynarr_set_length (str->convert_from, to_process - processed); |
1905 } | 1898 } |
1906 } | 1899 } |
1907 | 1900 |
1908 if (data - orig_data == 0) | 1901 if (data - orig_data == 0) |
1909 return error_occurred ? -1 : 0; | 1902 return error_occurred ? -1 : 0; |
1919 /* Convert all our data into convert_to, and then attempt to write | 1912 /* Convert all our data into convert_to, and then attempt to write |
1920 it all out to the other end. */ | 1913 it all out to the other end. */ |
1921 Dynarr_reset (str->convert_to); | 1914 Dynarr_reset (str->convert_to); |
1922 size = XCODESYSMETH (str->codesys, convert, | 1915 size = XCODESYSMETH (str->codesys, convert, |
1923 (str, data, str->convert_to, size)); | 1916 (str, data, str->convert_to, size)); |
1924 if (Lstream_write (str->other_end, Dynarr_atp (str->convert_to, 0), | 1917 if (Lstream_write (str->other_end, Dynarr_begin (str->convert_to), |
1925 Dynarr_length (str->convert_to)) < 0) | 1918 Dynarr_length (str->convert_to)) < 0) |
1926 return -1; | 1919 return -1; |
1927 else | 1920 else |
1928 /* The return value indicates how much of the incoming data was | 1921 /* The return value indicates how much of the incoming data was |
1929 processed, not how many bytes were written. */ | 1922 processed, not how many bytes were written. */ |
2054 | 2047 |
2055 assert (!str->finalized); | 2048 assert (!str->finalized); |
2056 MAYBE_XCODESYSMETH (str->codesys, finalize_coding_stream, (str)); | 2049 MAYBE_XCODESYSMETH (str->codesys, finalize_coding_stream, (str)); |
2057 if (str->data) | 2050 if (str->data) |
2058 { | 2051 { |
2059 xfree (str->data, void *); | 2052 xfree (str->data); |
2060 str->data = 0; | 2053 str->data = 0; |
2061 } | 2054 } |
2062 str->finalized = 1; | 2055 str->finalized = 1; |
2063 } | 2056 } |
2064 | 2057 |
2113 str->orig_codesys = codesys; | 2106 str->orig_codesys = codesys; |
2114 str->codesys = coding_system_real_canonical (codesys); | 2107 str->codesys = coding_system_real_canonical (codesys); |
2115 | 2108 |
2116 if (str->data) | 2109 if (str->data) |
2117 { | 2110 { |
2118 xfree (str->data, void *); | 2111 xfree (str->data); |
2119 str->data = 0; | 2112 str->data = 0; |
2120 } | 2113 } |
2121 if (XCODING_SYSTEM_METHODS (str->codesys)->coding_data_size) | 2114 if (XCODING_SYSTEM_METHODS (str->codesys)->coding_data_size) |
2122 { | 2115 { |
2123 str->data = | 2116 str->data = |
2607 static void | 2600 static void |
2608 chain_print (Lisp_Object cs, Lisp_Object printcharfun, int escapeflag) | 2601 chain_print (Lisp_Object cs, Lisp_Object printcharfun, int escapeflag) |
2609 { | 2602 { |
2610 int i; | 2603 int i; |
2611 | 2604 |
2612 write_c_string (printcharfun, "("); | 2605 write_ascstring (printcharfun, "("); |
2613 for (i = 0; i < XCODING_SYSTEM_CHAIN_COUNT (cs); i++) | 2606 for (i = 0; i < XCODING_SYSTEM_CHAIN_COUNT (cs); i++) |
2614 { | 2607 { |
2615 write_c_string (printcharfun, i == 0 ? "" : "->"); | 2608 write_ascstring (printcharfun, i == 0 ? "" : "->"); |
2616 print_coding_system_in_print_method (XCODING_SYSTEM_CHAIN_CHAIN (cs)[i], | 2609 print_coding_system_in_print_method (XCODING_SYSTEM_CHAIN_CHAIN (cs)[i], |
2617 printcharfun, escapeflag); | 2610 printcharfun, escapeflag); |
2618 } | 2611 } |
2619 { | 2612 { |
2620 Lisp_Object cac = XCODING_SYSTEM_CHAIN_CANONICALIZE_AFTER_CODING (cs); | 2613 Lisp_Object cac = XCODING_SYSTEM_CHAIN_CANONICALIZE_AFTER_CODING (cs); |
2621 if (!NILP (cac)) | 2614 if (!NILP (cac)) |
2622 { | 2615 { |
2623 if (i > 0) | 2616 if (i > 0) |
2624 write_c_string (printcharfun, " "); | 2617 write_ascstring (printcharfun, " "); |
2625 write_c_string (printcharfun, "canonicalize-after-coding="); | 2618 write_ascstring (printcharfun, "canonicalize-after-coding="); |
2626 print_coding_system_in_print_method (cac, printcharfun, escapeflag); | 2619 print_coding_system_in_print_method (cac, printcharfun, escapeflag); |
2627 } | 2620 } |
2628 } | 2621 } |
2629 | 2622 |
2630 write_c_string (printcharfun, ")"); | 2623 write_ascstring (printcharfun, ")"); |
2631 } | 2624 } |
2632 | 2625 |
2633 static void | 2626 static void |
2634 chain_rewind_coding_stream_1 (struct chain_coding_stream *data) | 2627 chain_rewind_coding_stream_1 (struct chain_coding_stream *data) |
2635 { | 2628 { |
2720 both directions, you'd have to disconnect the pointers to a | 2713 both directions, you'd have to disconnect the pointers to a |
2721 particular object before deleting it. */ | 2714 particular object before deleting it. */ |
2722 for (i = 0; i < data->lstream_count; i++) | 2715 for (i = 0; i < data->lstream_count; i++) |
2723 Lstream_delete (XLSTREAM ((data->lstreams)[i])); | 2716 Lstream_delete (XLSTREAM ((data->lstreams)[i])); |
2724 } | 2717 } |
2725 xfree (data->lstreams, Lisp_Object *); | 2718 xfree (data->lstreams); |
2726 } | 2719 } |
2727 } | 2720 } |
2728 | 2721 |
2729 static void | 2722 static void |
2730 chain_finalize_coding_stream (struct coding_stream *str) | 2723 chain_finalize_coding_stream (struct coding_stream *str) |
2734 | 2727 |
2735 static void | 2728 static void |
2736 chain_finalize (Lisp_Object c) | 2729 chain_finalize (Lisp_Object c) |
2737 { | 2730 { |
2738 if (XCODING_SYSTEM_CHAIN_CHAIN (c)) | 2731 if (XCODING_SYSTEM_CHAIN_CHAIN (c)) |
2739 xfree (XCODING_SYSTEM_CHAIN_CHAIN (c), Lisp_Object *); | 2732 xfree (XCODING_SYSTEM_CHAIN_CHAIN (c)); |
2740 } | 2733 } |
2741 | 2734 |
2742 static int | 2735 static int |
2743 chain_putprop (Lisp_Object codesys, Lisp_Object key, Lisp_Object value) | 2736 chain_putprop (Lisp_Object codesys, Lisp_Object key, Lisp_Object value) |
2744 { | 2737 { |
3265 { | 3258 { |
3266 struct undecided_coding_system *data = | 3259 struct undecided_coding_system *data = |
3267 XCODING_SYSTEM_TYPE_DATA (cs, undecided); | 3260 XCODING_SYSTEM_TYPE_DATA (cs, undecided); |
3268 int need_space = 0; | 3261 int need_space = 0; |
3269 | 3262 |
3270 write_c_string (printcharfun, "("); | 3263 write_ascstring (printcharfun, "("); |
3271 if (data->do_eol) | 3264 if (data->do_eol) |
3272 { | 3265 { |
3273 write_c_string (printcharfun, "do-eol"); | 3266 write_ascstring (printcharfun, "do-eol"); |
3274 need_space = 1; | 3267 need_space = 1; |
3275 } | 3268 } |
3276 if (data->do_coding) | 3269 if (data->do_coding) |
3277 { | 3270 { |
3278 if (need_space) | 3271 if (need_space) |
3279 write_c_string (printcharfun, " "); | 3272 write_ascstring (printcharfun, " "); |
3280 write_c_string (printcharfun, "do-coding"); | 3273 write_ascstring (printcharfun, "do-coding"); |
3281 need_space = 1; | 3274 need_space = 1; |
3282 } | 3275 } |
3283 if (!NILP (data->cs)) | 3276 if (!NILP (data->cs)) |
3284 { | 3277 { |
3285 if (need_space) | 3278 if (need_space) |
3286 write_c_string (printcharfun, " "); | 3279 write_ascstring (printcharfun, " "); |
3287 write_c_string (printcharfun, "coding-system="); | 3280 write_ascstring (printcharfun, "coding-system="); |
3288 print_coding_system_in_print_method (data->cs, printcharfun, escapeflag); | 3281 print_coding_system_in_print_method (data->cs, printcharfun, escapeflag); |
3289 } | 3282 } |
3290 write_c_string (printcharfun, ")"); | 3283 write_ascstring (printcharfun, ")"); |
3291 } | 3284 } |
3292 | 3285 |
3293 static void | 3286 static void |
3294 undecided_mark_coding_stream (struct coding_stream *str) | 3287 undecided_mark_coding_stream (struct coding_stream *str) |
3295 { | 3288 { |
3361 if (Dynarr_at (all_coding_detectors, i).finalize_detection_state_method) | 3354 if (Dynarr_at (all_coding_detectors, i).finalize_detection_state_method) |
3362 Dynarr_at (all_coding_detectors, i).finalize_detection_state_method | 3355 Dynarr_at (all_coding_detectors, i).finalize_detection_state_method |
3363 (st); | 3356 (st); |
3364 } | 3357 } |
3365 | 3358 |
3366 xfree (st, struct detection_state *); | 3359 xfree (st); |
3367 } | 3360 } |
3368 | 3361 |
3369 static int | 3362 static int |
3370 coding_category_symbol_to_id (Lisp_Object symbol) | 3363 coding_category_symbol_to_id (Lisp_Object symbol) |
3371 { | 3364 { |
3714 "0123456789" | 3707 "0123456789" |
3715 "!$%&*+-.^_{|}~"); | 3708 "!$%&*+-.^_{|}~"); |
3716 if (n > 0) | 3709 if (n > 0) |
3717 { | 3710 { |
3718 name[n] = '\0'; | 3711 name[n] = '\0'; |
3719 /* This call to intern_int() is OK because we already verified that | 3712 /* This call to intern_istring() is OK because we already verified that |
3720 there are only ASCII characters in the string */ | 3713 there are only ASCII characters in the string */ |
3721 return find_coding_system_for_text_file (intern_int ((Ibyte *) name), 0); | 3714 return find_coding_system_for_text_file (intern_istring ((Ibyte *) name), 0); |
3722 } | 3715 } |
3723 | 3716 |
3724 return Qnil; | 3717 return Qnil; |
3725 } | 3718 } |
3726 | 3719 |
4307 static void | 4300 static void |
4308 gzip_print (Lisp_Object cs, Lisp_Object printcharfun, int escapeflag) | 4301 gzip_print (Lisp_Object cs, Lisp_Object printcharfun, int escapeflag) |
4309 { | 4302 { |
4310 struct gzip_coding_system *data = XCODING_SYSTEM_TYPE_DATA (cs, gzip); | 4303 struct gzip_coding_system *data = XCODING_SYSTEM_TYPE_DATA (cs, gzip); |
4311 | 4304 |
4312 write_c_string (printcharfun, "("); | 4305 write_ascstring (printcharfun, "("); |
4313 if (data->level == -1) | 4306 if (data->level == -1) |
4314 write_c_string (printcharfun, "default"); | 4307 write_ascstring (printcharfun, "default"); |
4315 else | 4308 else |
4316 print_internal (make_int (data->level), printcharfun, 0); | 4309 print_internal (make_int (data->level), printcharfun, 0); |
4317 write_c_string (printcharfun, ")"); | 4310 write_ascstring (printcharfun, ")"); |
4318 } | 4311 } |
4319 | 4312 |
4320 static int | 4313 static int |
4321 gzip_putprop (Lisp_Object codesys, Lisp_Object key, Lisp_Object value) | 4314 gzip_putprop (Lisp_Object codesys, Lisp_Object key, Lisp_Object value) |
4322 { | 4315 { |
4424 data->stream.next_out = | 4417 data->stream.next_out = |
4425 Dynarr_atp (dst, Dynarr_length (dst) - reserved); | 4418 Dynarr_atp (dst, Dynarr_length (dst) - reserved); |
4426 data->stream.avail_out = reserved; | 4419 data->stream.avail_out = reserved; |
4427 zerr = inflate (&data->stream, Z_NO_FLUSH); | 4420 zerr = inflate (&data->stream, Z_NO_FLUSH); |
4428 /* Lop off the unused portion */ | 4421 /* Lop off the unused portion */ |
4429 Dynarr_set_size (dst, Dynarr_length (dst) - data->stream.avail_out); | 4422 Dynarr_set_length (dst, Dynarr_length (dst) - data->stream.avail_out); |
4430 if (zerr != Z_OK) | 4423 if (zerr != Z_OK) |
4431 break; | 4424 break; |
4432 } | 4425 } |
4433 | 4426 |
4434 if (zerr == Z_STREAM_END) | 4427 if (zerr == Z_STREAM_END) |
4484 data->stream.avail_out = reserved; | 4477 data->stream.avail_out = reserved; |
4485 zerr = | 4478 zerr = |
4486 deflate (&data->stream, | 4479 deflate (&data->stream, |
4487 str->eof ? Z_FINISH : Z_NO_FLUSH); | 4480 str->eof ? Z_FINISH : Z_NO_FLUSH); |
4488 /* Lop off the unused portion */ | 4481 /* Lop off the unused portion */ |
4489 Dynarr_set_size (dst, Dynarr_length (dst) - data->stream.avail_out); | 4482 Dynarr_set_length (dst, Dynarr_length (dst) - data->stream.avail_out); |
4490 if (zerr != Z_OK) | 4483 if (zerr != Z_OK) |
4491 break; | 4484 break; |
4492 } | 4485 } |
4493 | 4486 |
4494 if ((Bytecount) data->stream.avail_in < n) | 4487 if ((Bytecount) data->stream.avail_in < n) |
4745 vars_of_file_coding (void) | 4738 vars_of_file_coding (void) |
4746 { | 4739 { |
4747 /* We always have file-coding support */ | 4740 /* We always have file-coding support */ |
4748 Fprovide (intern ("file-coding")); | 4741 Fprovide (intern ("file-coding")); |
4749 | 4742 |
4750 QScoding_system_cookie = build_string (";;;###coding system: "); | 4743 QScoding_system_cookie = build_ascstring (";;;###coding system: "); |
4751 staticpro (&QScoding_system_cookie); | 4744 staticpro (&QScoding_system_cookie); |
4752 | 4745 |
4753 #ifdef HAVE_DEFAULT_EOL_DETECTION | 4746 #ifdef HAVE_DEFAULT_EOL_DETECTION |
4754 /* #### Find a more appropriate place for this comment. | 4747 /* #### Find a more appropriate place for this comment. |
4755 WARNING: The existing categories are intimately tied to the function | 4748 WARNING: The existing categories are intimately tied to the function |
4833 void | 4826 void |
4834 complex_vars_of_file_coding (void) | 4827 complex_vars_of_file_coding (void) |
4835 { | 4828 { |
4836 Fmake_coding_system_internal | 4829 Fmake_coding_system_internal |
4837 (Qconvert_eol_cr, Qconvert_eol, | 4830 (Qconvert_eol_cr, Qconvert_eol, |
4838 build_msg_string ("Convert CR to LF"), | 4831 build_defer_string ("Convert CR to LF"), |
4839 nconc2 (list6 (Qdocumentation, | 4832 nconc2 (list6 (Qdocumentation, |
4840 build_msg_string ( | 4833 build_defer_string ( |
4841 "Converts CR (used to mark the end of a line on Macintosh systems) to LF\n" | 4834 "Converts CR (used to mark the end of a line on Macintosh systems) to LF\n" |
4842 "(used internally and under Unix to mark the end of a line)."), | 4835 "(used internally and under Unix to mark the end of a line)."), |
4843 Qmnemonic, build_string ("CR->LF"), | 4836 Qmnemonic, build_ascstring ("CR->LF"), |
4844 Qsubtype, Qcr), | 4837 Qsubtype, Qcr), |
4845 /* VERY IMPORTANT! Tell make-coding-system not to generate | 4838 /* VERY IMPORTANT! Tell make-coding-system not to generate |
4846 subsidiaries -- it needs the coding systems we're creating | 4839 subsidiaries -- it needs the coding systems we're creating |
4847 to do so! */ | 4840 to do so! */ |
4848 list4 (Qeol_type, Qlf, | 4841 list4 (Qeol_type, Qlf, |
4849 Qsafe_charsets, Qt))); | 4842 Qsafe_charsets, Qt))); |
4850 | 4843 |
4851 Fmake_coding_system_internal | 4844 Fmake_coding_system_internal |
4852 (Qconvert_eol_lf, Qconvert_eol, | 4845 (Qconvert_eol_lf, Qconvert_eol, |
4853 build_msg_string ("Convert LF to LF (do nothing)"), | 4846 build_defer_string ("Convert LF to LF (do nothing)"), |
4854 nconc2 (list6 (Qdocumentation, | 4847 nconc2 (list6 (Qdocumentation, |
4855 build_msg_string ( | 4848 build_defer_string ( |
4856 "Do nothing."), | 4849 "Do nothing."), |
4857 Qmnemonic, build_string ("LF->LF"), | 4850 Qmnemonic, build_ascstring ("LF->LF"), |
4858 Qsubtype, Qlf), | 4851 Qsubtype, Qlf), |
4859 /* VERY IMPORTANT! Tell make-coding-system not to generate | 4852 /* VERY IMPORTANT! Tell make-coding-system not to generate |
4860 subsidiaries -- it needs the coding systems we're creating | 4853 subsidiaries -- it needs the coding systems we're creating |
4861 to do so! */ | 4854 to do so! */ |
4862 list4 (Qeol_type, Qlf, | 4855 list4 (Qeol_type, Qlf, |
4863 Qsafe_charsets, Qt))); | 4856 Qsafe_charsets, Qt))); |
4864 | 4857 |
4865 Fmake_coding_system_internal | 4858 Fmake_coding_system_internal |
4866 (Qconvert_eol_crlf, Qconvert_eol, | 4859 (Qconvert_eol_crlf, Qconvert_eol, |
4867 build_msg_string ("Convert CRLF to LF"), | 4860 build_defer_string ("Convert CRLF to LF"), |
4868 nconc2 (list6 (Qdocumentation, | 4861 nconc2 (list6 (Qdocumentation, |
4869 build_msg_string ( | 4862 build_defer_string ( |
4870 "Converts CR+LF (used to mark the end of a line on Macintosh systems) to LF\n" | 4863 "Converts CR+LF (used to mark the end of a line on Macintosh systems) to LF\n" |
4871 "(used internally and under Unix to mark the end of a line)."), | 4864 "(used internally and under Unix to mark the end of a line)."), |
4872 Qmnemonic, build_string ("CRLF->LF"), | 4865 Qmnemonic, build_ascstring ("CRLF->LF"), |
4873 Qsubtype, Qcrlf), | 4866 Qsubtype, Qcrlf), |
4874 | 4867 |
4875 /* VERY IMPORTANT! Tell make-coding-system not to generate | 4868 /* VERY IMPORTANT! Tell make-coding-system not to generate |
4876 subsidiaries -- it needs the coding systems we're creating | 4869 subsidiaries -- it needs the coding systems we're creating |
4877 to do so! */ | 4870 to do so! */ |
4878 list4 (Qeol_type, Qlf, | 4871 list4 (Qeol_type, Qlf, |
4879 Qsafe_charsets, Qt))); | 4872 Qsafe_charsets, Qt))); |
4880 | 4873 |
4881 Fmake_coding_system_internal | 4874 Fmake_coding_system_internal |
4882 (Qconvert_eol_autodetect, Qconvert_eol, | 4875 (Qconvert_eol_autodetect, Qconvert_eol, |
4883 build_msg_string ("Autodetect EOL type"), | 4876 build_defer_string ("Autodetect EOL type"), |
4884 nconc2 (list6 (Qdocumentation, | 4877 nconc2 (list6 (Qdocumentation, |
4885 build_msg_string ( | 4878 build_defer_string ( |
4886 "Autodetect the end-of-line type."), | 4879 "Autodetect the end-of-line type."), |
4887 Qmnemonic, build_string ("Auto-EOL"), | 4880 Qmnemonic, build_ascstring ("Auto-EOL"), |
4888 Qsubtype, Qnil), | 4881 Qsubtype, Qnil), |
4889 /* VERY IMPORTANT! Tell make-coding-system not to generate | 4882 /* VERY IMPORTANT! Tell make-coding-system not to generate |
4890 subsidiaries -- it needs the coding systems we're creating | 4883 subsidiaries -- it needs the coding systems we're creating |
4891 to do so! */ | 4884 to do so! */ |
4892 list4 (Qeol_type, Qlf, | 4885 list4 (Qeol_type, Qlf, |
4893 Qsafe_charsets, Qt))); | 4886 Qsafe_charsets, Qt))); |
4894 | 4887 |
4895 Fmake_coding_system_internal | 4888 Fmake_coding_system_internal |
4896 (Qundecided, Qundecided, | 4889 (Qundecided, Qundecided, |
4897 build_msg_string ("Undecided (auto-detect)"), | 4890 build_defer_string ("Undecided (auto-detect)"), |
4898 nconc2 (list4 (Qdocumentation, | 4891 nconc2 (list4 (Qdocumentation, |
4899 build_msg_string | 4892 build_defer_string |
4900 ("Automatically detects the correct encoding."), | 4893 ("Automatically detects the correct encoding."), |
4901 Qmnemonic, build_string ("Auto")), | 4894 Qmnemonic, build_ascstring ("Auto")), |
4902 list6 (Qdo_eol, Qt, Qdo_coding, Qt, | 4895 list6 (Qdo_eol, Qt, Qdo_coding, Qt, |
4903 /* We do EOL detection ourselves so we don't need to be | 4896 /* We do EOL detection ourselves so we don't need to be |
4904 wrapped in an EOL detector. (It doesn't actually hurt, | 4897 wrapped in an EOL detector. (It doesn't actually hurt, |
4905 though, I don't think.) */ | 4898 though, I don't think.) */ |
4906 Qeol_type, Qlf))); | 4899 Qeol_type, Qlf))); |
4907 | 4900 |
4908 Fmake_coding_system_internal | 4901 Fmake_coding_system_internal |
4909 (intern ("undecided-dos"), Qundecided, | 4902 (intern ("undecided-dos"), Qundecided, |
4910 build_msg_string ("Undecided (auto-detect) (CRLF)"), | 4903 build_defer_string ("Undecided (auto-detect) (CRLF)"), |
4911 nconc2 (list4 (Qdocumentation, | 4904 nconc2 (list4 (Qdocumentation, |
4912 build_msg_string | 4905 build_defer_string |
4913 ("Automatically detects the correct encoding; EOL type of CRLF forced."), | 4906 ("Automatically detects the correct encoding; EOL type of CRLF forced."), |
4914 Qmnemonic, build_string ("Auto")), | 4907 Qmnemonic, build_ascstring ("Auto")), |
4915 list4 (Qdo_coding, Qt, | 4908 list4 (Qdo_coding, Qt, |
4916 Qeol_type, Qcrlf))); | 4909 Qeol_type, Qcrlf))); |
4917 | 4910 |
4918 Fmake_coding_system_internal | 4911 Fmake_coding_system_internal |
4919 (intern ("undecided-unix"), Qundecided, | 4912 (intern ("undecided-unix"), Qundecided, |
4920 build_msg_string ("Undecided (auto-detect) (LF)"), | 4913 build_defer_string ("Undecided (auto-detect) (LF)"), |
4921 nconc2 (list4 (Qdocumentation, | 4914 nconc2 (list4 (Qdocumentation, |
4922 build_msg_string | 4915 build_defer_string |
4923 ("Automatically detects the correct encoding; EOL type of LF forced."), | 4916 ("Automatically detects the correct encoding; EOL type of LF forced."), |
4924 Qmnemonic, build_string ("Auto")), | 4917 Qmnemonic, build_ascstring ("Auto")), |
4925 list4 (Qdo_coding, Qt, | 4918 list4 (Qdo_coding, Qt, |
4926 Qeol_type, Qlf))); | 4919 Qeol_type, Qlf))); |
4927 | 4920 |
4928 Fmake_coding_system_internal | 4921 Fmake_coding_system_internal |
4929 (intern ("undecided-mac"), Qundecided, | 4922 (intern ("undecided-mac"), Qundecided, |
4930 build_msg_string ("Undecided (auto-detect) (CR)"), | 4923 build_defer_string ("Undecided (auto-detect) (CR)"), |
4931 nconc2 (list4 (Qdocumentation, | 4924 nconc2 (list4 (Qdocumentation, |
4932 build_msg_string | 4925 build_defer_string |
4933 ("Automatically detects the correct encoding; EOL type of CR forced."), | 4926 ("Automatically detects the correct encoding; EOL type of CR forced."), |
4934 Qmnemonic, build_string ("Auto")), | 4927 Qmnemonic, build_ascstring ("Auto")), |
4935 list4 (Qdo_coding, Qt, | 4928 list4 (Qdo_coding, Qt, |
4936 Qeol_type, Qcr))); | 4929 Qeol_type, Qcr))); |
4937 | 4930 |
4938 /* Need to create this here or we're really screwed. */ | 4931 /* Need to create this here or we're really screwed. */ |
4939 Fmake_coding_system_internal | 4932 Fmake_coding_system_internal |
4940 (Qraw_text, Qno_conversion, | 4933 (Qraw_text, Qno_conversion, |
4941 build_msg_string ("Raw Text"), | 4934 build_defer_string ("Raw Text"), |
4942 nconc2 (list4 (Qdocumentation, | 4935 nconc2 (list4 (Qdocumentation, |
4943 build_msg_string ("Raw text converts only line-break " | 4936 build_defer_string ("Raw text converts only line-break " |
4944 "codes, and acts otherwise like " | 4937 "codes, and acts otherwise like " |
4945 "`binary'."), | 4938 "`binary'."), |
4946 Qmnemonic, build_string ("Raw")), | 4939 Qmnemonic, build_ascstring ("Raw")), |
4947 #ifdef MULE | 4940 #ifdef MULE |
4948 list2 (Qsafe_charsets, list3 (Vcharset_ascii, Vcharset_control_1, | 4941 list2 (Qsafe_charsets, list3 (Vcharset_ascii, Vcharset_control_1, |
4949 Vcharset_latin_iso8859_1)))); | 4942 Vcharset_latin_iso8859_1)))); |
4950 | 4943 |
4951 #else | 4944 #else |
4952 Qnil)); | 4945 Qnil)); |
4953 #endif | 4946 #endif |
4954 | 4947 |
4955 Fmake_coding_system_internal | 4948 Fmake_coding_system_internal |
4956 (Qbinary, Qno_conversion, | 4949 (Qbinary, Qno_conversion, |
4957 build_msg_string ("Binary"), | 4950 build_defer_string ("Binary"), |
4958 nconc2 (list6 (Qdocumentation, | 4951 nconc2 (list6 (Qdocumentation, |
4959 build_msg_string ( | 4952 build_defer_string ( |
4960 "This coding system is as close as it comes to doing no conversion.\n" | 4953 "This coding system is as close as it comes to doing no conversion.\n" |
4961 "On input, each byte is converted directly into the character\n" | 4954 "On input, each byte is converted directly into the character\n" |
4962 "with the corresponding code -- i.e. from the `ascii', `control-1',\n" | 4955 "with the corresponding code -- i.e. from the `ascii', `control-1',\n" |
4963 "or `latin-1' character sets. On output, these characters are\n" | 4956 "or `latin-1' character sets. On output, these characters are\n" |
4964 "converted back to the corresponding bytes, and other characters\n" | 4957 "converted back to the corresponding bytes, and other characters\n" |
4965 "are converted to the default character, i.e. `~'."), | 4958 "are converted to the default character, i.e. `~'."), |
4966 Qeol_type, Qlf, | 4959 Qeol_type, Qlf, |
4967 Qmnemonic, build_string ("Binary")), | 4960 Qmnemonic, build_ascstring ("Binary")), |
4968 #ifdef MULE | 4961 #ifdef MULE |
4969 list2 (Qsafe_charsets, list3 (Vcharset_ascii, Vcharset_control_1, | 4962 list2 (Qsafe_charsets, list3 (Vcharset_ascii, Vcharset_control_1, |
4970 Vcharset_latin_iso8859_1)))); | 4963 Vcharset_latin_iso8859_1)))); |
4971 | 4964 |
4972 #else | 4965 #else |