comparison src/file-coding.c @ 800:a5954632b187

[xemacs-hg @ 2002-03-31 08:27:14 by ben] more fixes, first crack at finishing behavior implementation TODO.ben-mule-21-5: Update. configure.in: Fix for new error-checking types. make-mswin-unicode.pl: Don't be fucked up by CRLF. Output code to force errors when nonintercepted Windows calls issued. behavior.el, dumped-lisp.el, menubar-items.el: Add support for saving using custom. Load into a dumped XEmacs. Correct :title to :short-doc in accordance with behavior-defs.el. Add a submenu under Options for turning on/off behaviors. cl-macs.el: Properly document `loop'. Fix a minor bug in keymap iteration and add support for bit-vector iteration. lisp-mode.el: Rearrange and add items for macro expanding. menubar-items.el: Document connection between these two functions. window.el: Port stuff from GNU 21.1. config.inc.samp, xemacs.mak: Separate out and add new variable for controlling error-checking. s/windowsnt.h: Use new ERROR_CHECK_ALL; not related to DEBUG_XEMACS. alloc.c, backtrace.h, buffer.c, buffer.h, bytecode.c, callproc.c, casetab.c, charset.h, chartab.c, cmdloop.c, config.h.in, console-msw.c, console-stream.c, console-tty.c, console.c, console.h, data.c, device-msw.c, device.c, device.h, dired-msw.c, dired.c, dumper.c, editfns.c, eldap.c, elhash.c, emacs.c, eval.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, events.c, extents.c, faces.c, file-coding.c, file-coding.h, fileio.c, frame-msw.c, frame.c, frame.h, glyphs-gtk.c, glyphs-msw.c, glyphs-shared.c, glyphs-widget.c, glyphs-x.c, glyphs.c, glyphs.h, insdel.c, intl-auto-encap-win32.c, intl-auto-encap-win32.h, intl-encap-win32.c, intl-win32.c, keymap.c, lisp-union.h, lisp.h, lread.c, lrecord.h, lstream.c, lstream.h, macros.c, marker.c, md5.c, menubar-x.c, menubar.c, mule-coding.c, ntproc.c, objects-gtk.c, objects-msw.c, objects-x.c, objects.c, opaque.c, print.c, process-nt.c, process-unix.c, process.c, rangetab.c, redisplay-msw.c, redisplay-output.c, redisplay.c, regex.c, scrollbar-msw.c, select-msw.c, signal.c, specifier.c, specifier.h, symbols.c, sysdep.c, syswindows.h, text.c, text.h, toolbar-msw.c, tooltalk.c, ui-gtk.c, unicode.c, window.c: Redo error-checking macros: ERROR_CHECK_TYPECHECK -> ERROR_CHECK_TYPES, ERROR_CHECK_CHARBPOS -> ERROR_CHECK_TEXT, add ERROR_CHECK_DISPLAY, ERROR_CHECK_STRUCTURES. Document these in config.h.in. Fix code to follow docs. Fix *_checking_assert() in accordance with new names. Attempt to fix periodic redisplay crash freeing display line structures. Add first implementation of sledgehammer redisplay check. Redo print_*() to use write_fmt_string(), write_fmt_string_lisp(). Fix bug in md5 handling. Rename character-to-unicode to char-to-unicode; same for unicode-to-char{acter}. Move chartab documentation to `make-char-table'. Some header cleanup. Clean up remaining places where nonintercepted Windows calls are being used. automated/mule-tests.el: Fix for new Unicode support.
author ben
date Sun, 31 Mar 2002 08:30:17 +0000
parents e38acbeb1cae
children 2b676dc88c66
comparison
equal deleted inserted replaced
799:03d9f9084848 800:a5954632b187
558 558
559 static void 559 static void
560 print_coding_system_in_print_method (Lisp_Object cs, Lisp_Object printcharfun, 560 print_coding_system_in_print_method (Lisp_Object cs, Lisp_Object printcharfun,
561 int escapeflag) 561 int escapeflag)
562 { 562 {
563 print_internal (XCODING_SYSTEM_NAME (cs), printcharfun, 0); 563 write_fmt_string_lisp (printcharfun, "%s[", 1, XCODING_SYSTEM_NAME (cs));
564 write_c_string ("[", printcharfun);
565 print_coding_system_properties (cs, printcharfun); 564 print_coding_system_properties (cs, printcharfun);
566 write_c_string ("]", printcharfun); 565 write_c_string ("]", printcharfun);
567 } 566 }
568 567
569 static void 568 static void
2207 { 2206 {
2208 Dynarr_free (str->convert_from); 2207 Dynarr_free (str->convert_from);
2209 str->convert_from = 0; 2208 str->convert_from = 0;
2210 } 2209 }
2211 2210
2212 return Lstream_close (str->other_end); 2211 if (str->no_close_other)
2212 return Lstream_flush (str->other_end);
2213 else
2214 return Lstream_close (str->other_end);
2213 } 2215 }
2214 2216
2215 static void 2217 static void
2216 coding_finalizer (Lstream *stream) 2218 coding_finalizer (Lstream *stream)
2217 { 2219 {
2300 stream for reading using a non-fully-specified coding system and 2302 stream for reading using a non-fully-specified coding system and
2301 a non-seekable input stream. */ 2303 a non-seekable input stream. */
2302 2304
2303 static Lisp_Object 2305 static Lisp_Object
2304 make_coding_stream_1 (Lstream *stream, Lisp_Object codesys, 2306 make_coding_stream_1 (Lstream *stream, Lisp_Object codesys,
2305 const char *mode, enum encode_decode direction) 2307 const char *mode, enum encode_decode direction,
2308 int no_close_other)
2306 { 2309 {
2307 Lstream *lstr = Lstream_new (lstream_coding, mode); 2310 Lstream *lstr = Lstream_new (lstream_coding, mode);
2308 struct coding_stream *str = CODING_STREAM_DATA (lstr); 2311 struct coding_stream *str = CODING_STREAM_DATA (lstr);
2309 2312
2310 codesys = Fget_coding_system (codesys); 2313 codesys = Fget_coding_system (codesys);
2314 str->us = lstr; 2317 str->us = lstr;
2315 str->other_end = stream; 2318 str->other_end = stream;
2316 str->convert_to = Dynarr_new (unsigned_char); 2319 str->convert_to = Dynarr_new (unsigned_char);
2317 str->convert_from = Dynarr_new (unsigned_char); 2320 str->convert_from = Dynarr_new (unsigned_char);
2318 str->direction = direction; 2321 str->direction = direction;
2322 str->no_close_other = no_close_other;
2319 set_coding_stream_coding_system (lstr, codesys); 2323 set_coding_stream_coding_system (lstr, codesys);
2320 return wrap_lstream (lstr); 2324 return wrap_lstream (lstr);
2321 } 2325 }
2322 2326
2327 /* If NO_CLOSE_OTHER is non-zero, don't close STREAM (the stream at the
2328 other end) when this stream is closed. */
2323 Lisp_Object 2329 Lisp_Object
2324 make_coding_input_stream (Lstream *stream, Lisp_Object codesys, 2330 make_coding_input_stream (Lstream *stream, Lisp_Object codesys,
2325 enum encode_decode direction) 2331 enum encode_decode direction, int no_close_other)
2326 { 2332 {
2327 return make_coding_stream_1 (stream, codesys, "r", direction); 2333 return make_coding_stream_1 (stream, codesys, "r", direction,
2328 } 2334 no_close_other);
2329 2335 }
2336
2337 /* If NO_CLOSE_OTHER is non-zero, don't close STREAM (the stream at the
2338 other end) when this stream is closed. */
2330 Lisp_Object 2339 Lisp_Object
2331 make_coding_output_stream (Lstream *stream, Lisp_Object codesys, 2340 make_coding_output_stream (Lstream *stream, Lisp_Object codesys,
2332 enum encode_decode direction) 2341 enum encode_decode direction, int no_close_other)
2333 { 2342 {
2334 return make_coding_stream_1 (stream, codesys, "w", direction); 2343 return make_coding_stream_1 (stream, codesys, "w", direction,
2344 no_close_other);
2335 } 2345 }
2336 2346
2337 static Lisp_Object 2347 static Lisp_Object
2338 encode_decode_coding_region (Lisp_Object start, Lisp_Object end, 2348 encode_decode_coding_region (Lisp_Object start, Lisp_Object end,
2339 Lisp_Object coding_system, Lisp_Object buffer, 2349 Lisp_Object coding_system, Lisp_Object buffer,
2370 2380
2371 if (direction == CODING_DECODE && 2381 if (direction == CODING_DECODE &&
2372 XCODING_SYSTEM_EOL_TYPE (coding_system) == EOL_AUTODETECT) 2382 XCODING_SYSTEM_EOL_TYPE (coding_system) == EOL_AUTODETECT)
2373 next = auto_outstream = 2383 next = auto_outstream =
2374 make_coding_output_stream 2384 make_coding_output_stream
2375 (XLSTREAM (next), Fget_coding_system (Qconvert_eol_autodetect), CODING_DECODE); 2385 (XLSTREAM (next), Fget_coding_system (Qconvert_eol_autodetect),
2386 CODING_DECODE, 0);
2376 2387
2377 if (!sink_char) 2388 if (!sink_char)
2378 next = from_outstream = 2389 next = from_outstream =
2379 make_coding_output_stream (XLSTREAM (next), Qbinary, CODING_DECODE); 2390 make_coding_output_stream (XLSTREAM (next), Qbinary, CODING_DECODE, 0);
2380 outstream = make_coding_output_stream (XLSTREAM (next), coding_system, 2391 outstream = make_coding_output_stream (XLSTREAM (next), coding_system,
2381 direction); 2392 direction, 0);
2382 if (!source_char) 2393 if (!source_char)
2383 { 2394 {
2384 to_outstream = 2395 to_outstream =
2385 make_coding_output_stream (XLSTREAM (outstream), 2396 make_coding_output_stream (XLSTREAM (outstream),
2386 Qbinary, CODING_ENCODE); 2397 Qbinary, CODING_ENCODE, 0);
2387 ostr = XLSTREAM (to_outstream); 2398 ostr = XLSTREAM (to_outstream);
2388 } 2399 }
2389 else 2400 else
2390 ostr = XLSTREAM (outstream); 2401 ostr = XLSTREAM (outstream);
2391 istr = XLSTREAM (instream); 2402 istr = XLSTREAM (instream);
2689 { 2700 {
2690 data->lstreams[i] = 2701 data->lstreams[i] =
2691 make_coding_output_stream 2702 make_coding_output_stream
2692 (XLSTREAM (lstream_out), 2703 (XLSTREAM (lstream_out),
2693 codesys[direction == CODING_ENCODE ? ncodesys - (i + 1) : i], 2704 codesys[direction == CODING_ENCODE ? ncodesys - (i + 1) : i],
2694 direction); 2705 direction, 0);
2695 lstream_out = data->lstreams[i]; 2706 lstream_out = data->lstreams[i];
2696 Lstream_set_buffering (XLSTREAM (lstream_out), LSTREAM_UNBUFFERED, 2707 Lstream_set_buffering (XLSTREAM (lstream_out), LSTREAM_UNBUFFERED,
2697 0); 2708 0);
2698 } 2709 }
2699 data->initted = 1; 2710 data->initted = 1;
3902 { 3913 {
3903 data->c.lstreams[1] = 3914 data->c.lstreams[1] =
3904 make_coding_output_stream 3915 make_coding_output_stream
3905 (XLSTREAM (data->c.lstreams[data->c.lstream_count - 1]), 3916 (XLSTREAM (data->c.lstreams[data->c.lstream_count - 1]),
3906 Fget_coding_system (Qconvert_eol_autodetect), 3917 Fget_coding_system (Qconvert_eol_autodetect),
3907 CODING_DECODE); 3918 CODING_DECODE, 0);
3908 Lstream_set_buffering 3919 Lstream_set_buffering
3909 (XLSTREAM (data->c.lstreams[1]), 3920 (XLSTREAM (data->c.lstreams[1]),
3910 LSTREAM_UNBUFFERED, 0); 3921 LSTREAM_UNBUFFERED, 0);
3911 } 3922 }
3912 3923
3913 data->c.lstreams[0] = 3924 data->c.lstreams[0] =
3914 make_coding_output_stream 3925 make_coding_output_stream
3915 (XLSTREAM (data->c.lstreams[1]), 3926 (XLSTREAM (data->c.lstreams[1]),
3916 /* Substitute binary if we need to detect the encoding */ 3927 /* Substitute binary if we need to detect the encoding */
3917 csdata->do_coding ? Qbinary : csdata->cs, 3928 csdata->do_coding ? Qbinary : csdata->cs,
3918 CODING_DECODE); 3929 CODING_DECODE, 0);
3919 Lstream_set_buffering (XLSTREAM (data->c.lstreams[0]), 3930 Lstream_set_buffering (XLSTREAM (data->c.lstreams[0]),
3920 LSTREAM_UNBUFFERED, 0); 3931 LSTREAM_UNBUFFERED, 0);
3921 3932
3922 first_time = 1; 3933 first_time = 1;
3923 data->c.initted = 1; 3934 data->c.initted = 1;
4122 if (!NILP (sys)) 4133 if (!NILP (sys))
4123 return XCODING_SYSTEM_NAME (sys); 4134 return XCODING_SYSTEM_NAME (sys);
4124 return Qnil; 4135 return Qnil;
4125 } 4136 }
4126 4137
4138 /* Detect the encoding of STREAM. Assumes stream is at the begnning and will
4139 read through to the end of STREAM, leaving it there but open. */
4140
4127 Lisp_Object 4141 Lisp_Object
4128 detect_coding_stream (Lisp_Object stream) 4142 detect_coding_stream (Lisp_Object stream)
4129 { 4143 {
4130 Lisp_Object val = Qnil; 4144 Lisp_Object val = Qnil;
4131 struct gcpro gcpro1, gcpro2, gcpro3; 4145 struct gcpro gcpro1, gcpro2, gcpro3;
4132 UExtbyte random_buffer[65536]; 4146 UExtbyte random_buffer[65536];
4133 Lisp_Object binary_instream = 4147 Lisp_Object binary_instream =
4134 make_coding_input_stream 4148 make_coding_input_stream
4135 (XLSTREAM (stream), Qbinary, 4149 (XLSTREAM (stream), Qbinary,
4136 CODING_ENCODE); 4150 CODING_ENCODE, 1);
4137 Lisp_Object decstream = 4151 Lisp_Object decstream =
4138 make_coding_input_stream 4152 make_coding_input_stream
4139 (XLSTREAM (binary_instream), 4153 (XLSTREAM (binary_instream),
4140 Qundecided, CODING_DECODE); 4154 Qundecided, CODING_DECODE, 0);
4141 Lstream *decstr = XLSTREAM (decstream); 4155 Lstream *decstr = XLSTREAM (decstream);
4142 4156
4143 GCPRO3 (decstream, stream, binary_instream); 4157 GCPRO3 (decstream, stream, binary_instream);
4144 /* Read and discard all data; detection happens as a side effect of this, 4158 /* Read and discard all data; detection happens as a side effect of this,
4145 and we examine what was detected afterwards. */ 4159 and we examine what was detected afterwards. */