mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2026-03-07 04:40:35 -08:00
Better support for external formats, including the :CR, :LF and :CRLF options.
This commit is contained in:
parent
7d60ada4af
commit
9cdbb57dbc
10 changed files with 493 additions and 327 deletions
|
|
@ -1182,7 +1182,7 @@ also known as unix-domain sockets."))
|
|||
buffering)
|
||||
(t :int :int :object)
|
||||
t
|
||||
"si_set_buffering_mode(ecl_make_stream_from_fd(#0,#1,(enum ecl_smmode)#2,8,1), #3)"
|
||||
"si_set_buffering_mode(ecl_make_stream_from_fd(#0,#1,(enum ecl_smmode)#2,8,ECL_STREAM_DEFAULT_FORMAT,Cnil), #3)"
|
||||
:one-liner t))
|
||||
|
||||
(defmethod socket-make-stream ((socket socket) &rest args &key (buffering-mode NIL))
|
||||
|
|
|
|||
|
|
@ -24,6 +24,11 @@ ECL 9.1.0:
|
|||
- When a string is read, if the characters are base-char, the string is read
|
||||
as a base-string.
|
||||
|
||||
- ECL supports external formats. They may be a symbol, denoting the encoding
|
||||
or an encoding option, or a list of symbols. Valid symbols are :DEFAULT,
|
||||
:LATIN-1, :ISO-8859-1, :UTF-8, :UCS-2, :UCS-4, :CR, :LF and :CRLF. Default
|
||||
option is :LF.
|
||||
|
||||
* Bugs fixed:
|
||||
|
||||
- (FLOOR X X), (CEILING X X), etc, might return a second value which is a
|
||||
|
|
|
|||
748
src/c/file.d
748
src/c/file.d
File diff suppressed because it is too large
Load diff
|
|
@ -431,7 +431,7 @@ si_load_source(cl_object source, cl_object verbose, cl_object print)
|
|||
strm = source;
|
||||
} else {
|
||||
strm = ecl_open_stream(source, smm_input, Cnil, Cnil, 8,
|
||||
ECL_STREAM_DEFAULT_FORMAT);
|
||||
ECL_STREAM_DEFAULT_FORMAT, Cnil);
|
||||
if (Null(strm))
|
||||
@(return Cnil)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1728,5 +1728,9 @@ cl_symbols[] = {
|
|||
{EXT_ "MAYBE-QUOTE", EXT_ORDINARY, NULL, -1, OBJNULL},
|
||||
{EXT_ "MAYBE-UNQUOTE", EXT_ORDINARY, NULL, -1, OBJNULL},
|
||||
|
||||
{KEY_ "CR", KEYWORD, NULL, -1, OBJNULL},
|
||||
{KEY_ "LF", KEYWORD, NULL, -1, OBJNULL},
|
||||
{KEY_ "CRLF", KEYWORD, NULL, -1, OBJNULL},
|
||||
|
||||
/* Tag for end of list */
|
||||
{NULL, CL_ORDINARY, NULL, -1, OBJNULL}};
|
||||
|
|
|
|||
|
|
@ -1728,5 +1728,9 @@ cl_symbols[] = {
|
|||
{EXT_ "MAYBE-QUOTE",NULL},
|
||||
{EXT_ "MAYBE-UNQUOTE",NULL},
|
||||
|
||||
{KEY_ "CR",NULL},
|
||||
{KEY_ "LF",NULL},
|
||||
{KEY_ "CRLF",NULL},
|
||||
|
||||
/* Tag for end of list */
|
||||
{NULL,NULL}};
|
||||
|
|
|
|||
|
|
@ -283,9 +283,9 @@ si_open_client_stream(cl_object host, cl_object port)
|
|||
@(return Cnil)
|
||||
|
||||
#if defined(_MSC_VER) || defined(mingw32)
|
||||
stream = ecl_make_stream_from_fd(host, fd, smm_io_wsock, 8, 0);
|
||||
stream = ecl_make_stream_from_fd(host, fd, smm_io_wsock, 8, 0, Cnil);
|
||||
#else
|
||||
stream = ecl_make_stream_from_fd(host, fd, smm_io, 8, 0);
|
||||
stream = ecl_make_stream_from_fd(host, fd, smm_io, 8, 0, Cnil);
|
||||
#endif
|
||||
|
||||
@(return stream)
|
||||
|
|
@ -303,7 +303,7 @@ si_open_server_stream(cl_object port)
|
|||
fd = create_server_port(p);
|
||||
ecl_enable_interrupts();
|
||||
|
||||
@(return ((fd == 0)? Cnil : ecl_make_stream_from_fd(Cnil, fd, smm_io, 8, 0)))
|
||||
@(return ((fd == 0)? Cnil : ecl_make_stream_from_fd(Cnil, fd, smm_io, 8, 0, Cnil)))
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
|
|
@ -341,7 +341,7 @@ si_open_unix_socket_stream(cl_object path)
|
|||
@(return Cnil)
|
||||
}
|
||||
|
||||
@(return ecl_make_stream_from_fd(path, fd, smm_io, 8, 0))
|
||||
@(return ecl_make_stream_from_fd(path, fd, smm_io, 8, 0, Cnil))
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -63,9 +63,11 @@ si_make_pipe()
|
|||
output = Cnil;
|
||||
} else {
|
||||
cl_object fake_in_name = make_simple_base_string("PIPE-READ-ENDPOINT");
|
||||
cl_object in = ecl_make_stream_from_fd(fake_in_name, fds[0], smm_input, 8, 0);
|
||||
cl_object in = ecl_make_stream_from_fd(fake_in_name, fds[0], smm_input, 8,
|
||||
ECL_STREAM_DEFAULT_FORMAT, Cnil);
|
||||
cl_object fake_out_name = make_simple_base_string("PIPE-WRITE-ENDPOINT");
|
||||
cl_object out = ecl_make_stream_from_fd(fake_out_name, fds[1], smm_output, 8, 0);
|
||||
cl_object out = ecl_make_stream_from_fd(fake_out_name, fds[1], smm_output, 8,
|
||||
ECL_STREAM_DEFAULT_FORMAT, Cnil);
|
||||
output = cl_make_two_way_stream(in, out);
|
||||
}
|
||||
@(return output)
|
||||
|
|
@ -355,14 +357,16 @@ si_make_pipe()
|
|||
}
|
||||
if (parent_write > 0) {
|
||||
stream_write = ecl_make_stream_from_fd(command, parent_write,
|
||||
smm_output, 8, 0);
|
||||
smm_output, 8,
|
||||
ECL_STREAM_DEFAULT_FORMAT, Ct);
|
||||
} else {
|
||||
parent_write = 0;
|
||||
stream_write = cl_core.null_stream;
|
||||
}
|
||||
if (parent_read > 0) {
|
||||
stream_read = ecl_make_stream_from_fd(command, parent_read,
|
||||
smm_input, 8, 0);
|
||||
smm_input, 8,
|
||||
ECL_STREAM_DEFAULT_FORMAT, Ct);
|
||||
} else {
|
||||
parent_read = 0;
|
||||
stream_read = cl_core.null_stream;
|
||||
|
|
|
|||
|
|
@ -604,7 +604,7 @@ extern ECL_API bool ecl_input_stream_p(cl_object strm);
|
|||
extern ECL_API bool ecl_output_stream_p(cl_object strm);
|
||||
extern ECL_API cl_object ecl_stream_element_type(cl_object strm);
|
||||
extern ECL_API bool ecl_interactive_stream_p(cl_object strm);
|
||||
extern ECL_API cl_object ecl_open_stream(cl_object fn, enum ecl_smmode smm, cl_object if_exists, cl_object if_does_not_exist, cl_fixnum byte_size, int flags);
|
||||
extern ECL_API cl_object ecl_open_stream(cl_object fn, enum ecl_smmode smm, cl_object if_exists, cl_object if_does_not_exist, cl_fixnum byte_size, int flags, cl_object external_format);
|
||||
extern ECL_API cl_object ecl_make_string_input_stream(cl_object strng, cl_index istart, cl_index iend);
|
||||
extern ECL_API cl_object ecl_make_string_output_stream(cl_index line_length, int extended);
|
||||
extern ECL_API cl_object ecl_read_byte(cl_object strm);
|
||||
|
|
@ -624,8 +624,8 @@ extern ECL_API cl_object ecl_file_position(cl_object strm);
|
|||
extern ECL_API cl_object ecl_file_position_set(cl_object strm, cl_object disp);
|
||||
extern ECL_API cl_object ecl_file_length(cl_object strm);
|
||||
extern ECL_API int ecl_file_column(cl_object strm);
|
||||
extern ECL_API cl_object ecl_make_stream_from_fd(cl_object fname, int fd, enum ecl_smmode smm, cl_fixnum byte_size, int char_stream_p);
|
||||
extern ECL_API cl_object ecl_make_stream_from_FILE(cl_object fname, void *fd, enum ecl_smmode smm, cl_fixnum byte_size, int char_stream_p);
|
||||
extern ECL_API cl_object ecl_make_stream_from_fd(cl_object fname, int fd, enum ecl_smmode smm, cl_fixnum byte_size, int flags, cl_object external_format);
|
||||
extern ECL_API cl_object ecl_make_stream_from_FILE(cl_object fname, void *fd, enum ecl_smmode smm, cl_fixnum byte_size, int flags, cl_object external_format);
|
||||
extern ECL_API int ecl_stream_to_handle(cl_object s, bool output);
|
||||
|
||||
/* finalize.c */
|
||||
|
|
|
|||
|
|
@ -137,6 +137,9 @@ typedef cl_object (*cl_objectfn_fixed)();
|
|||
#define CODE_CHAR(c) ((cl_object)(((cl_fixnum)((c & 0xff) << 2)|CHARACTER_TAG)))
|
||||
#define CHAR_CODE(obje) ((((cl_fixnum)(obje)) >> 2) & 0xff)
|
||||
#endif
|
||||
#define ECL_CHAR_CODE_RETURN 13
|
||||
#define ECL_CHAR_CODE_NEWLINE 10
|
||||
#define ECL_CHAR_CODE_LINEFEED 10
|
||||
|
||||
#define ECL_NUMBER_TYPE_P(t) (t >= t_fixnum && t <= t_complex)
|
||||
#define REAL_TYPE(t) (t >= t_fixnum && t < t_complex)
|
||||
|
|
@ -508,7 +511,7 @@ struct ecl_file_ops {
|
|||
|
||||
enum {
|
||||
ECL_STREAM_BINARY = 0,
|
||||
ECL_STREAM_FORMAT = 0xF,
|
||||
ECL_STREAM_FORMAT = 0x1F,
|
||||
#ifdef ECL_UNICODE
|
||||
ECL_STREAM_DEFAULT_FORMAT = 2,
|
||||
#else
|
||||
|
|
@ -519,26 +522,38 @@ enum {
|
|||
ECL_STREAM_UTF_8 = 2,
|
||||
ECL_STREAM_UCS_2 = 3,
|
||||
ECL_STREAM_UCS_4 = 4,
|
||||
ECL_STREAM_SIGNED_BYTES = 16,
|
||||
ECL_STREAM_C_STREAM = 32,
|
||||
ECL_STREAM_MIGHT_SEEK = 64
|
||||
ECL_STREAM_8BIT = 5,
|
||||
ECL_STREAM_CR = 8,
|
||||
ECL_STREAM_LF = 16,
|
||||
ECL_STREAM_SIGNED_BYTES = 32,
|
||||
ECL_STREAM_C_STREAM = 64,
|
||||
ECL_STREAM_MIGHT_SEEK = 128,
|
||||
};
|
||||
|
||||
typedef int (*cl_eformat_encoder)(unsigned char *buffer, int c);
|
||||
typedef cl_index (*cl_eformat_read_byte8)(cl_object object, unsigned char *buffer, cl_index n);
|
||||
typedef int (*cl_eformat_decoder)(cl_eformat_read_byte8 read_byte8, cl_object source);
|
||||
|
||||
struct ecl_stream {
|
||||
HEADER2(mode,closed);
|
||||
/* stream mode of enum smmode */
|
||||
HEADER2(mode,closed); /* stream mode of enum smmode */
|
||||
/* closed stream? */
|
||||
struct ecl_file_ops *ops; /* dispatch table */
|
||||
void *file; /* file pointer */
|
||||
cl_object object0; /* some object */
|
||||
cl_object object1; /* some object */
|
||||
cl_fixnum unread; /* one-char buffer for unread-char */
|
||||
cl_object byte_stack; /* buffer for unread bytes */
|
||||
cl_fixnum last_char; /* last character read */
|
||||
cl_fixnum last_code[2]; /* actual composition of last character */
|
||||
cl_fixnum int0; /* some int */
|
||||
cl_fixnum int1; /* some int */
|
||||
cl_index byte_size; /* size of byte in binary streams */
|
||||
cl_fixnum last_op; /* 0: unknown, 1: reading, -1: writing */
|
||||
char *buffer; /* buffer for FILE */
|
||||
cl_object format; /* external format */
|
||||
cl_eformat_encoder encoder;
|
||||
cl_eformat_decoder decoder;
|
||||
cl_object encoder_table;
|
||||
cl_object decoder_table;
|
||||
int flags; /* character table, flags, etc */
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue