summaryrefslogtreecommitdiffstats
path: root/stream.c
Commit message (Collapse)AuthorAgeFilesLines
* Wrong argument defaulting in record-adapter.Kaz Kylheku2016-05-091-1/+1
| | | | | | | | * stream.c (record_adapter): Use default_bool_arg rather than tnil. Since rb->include_match ends up passed directly to read_until_match, which deals with argument defaulting, we could just store the argument value into the structure.
* Argument of flush-stream now optional.Kaz Kylheku2016-05-071-2/+3
| | | | | | | | | * stream.c (flush_stream): Default the argument to std_output. (stream_init): Register flush-stream as having one optional arg. * txr.1: Updated flush-stream description.
* Redundant addr in printed rep of string-input-stream.Kaz Kylheku2016-05-071-1/+1
| | | | | * stream.c (string_in_get_prop): Do not format stream address into name; the general stream_print_op already adds that.
* New: standard stream redirection for subprocesses.Kaz Kylheku2016-05-071-11/+141
| | | | | | | | | | | | | | | | | | | When subprocesses are created using open-command, open-process, run or sh, any streams not bound by those functions are obtained from *stdin*, *stdout* or *stderr*, as appropriate. Thus manipulating these variables has the effect of redirecting not only local output within the program but over coprocesses as well. * stream.c (struct save_fds): New type. (FDS_IN, FDS_OUT, FDS_ERR): New macros. (fds_init, fds_subst, fds_swizzle, fds_restore): New static functions. (open_command, open_process, run): "Swizzle" and restore the standard file descriptors. * txr.1: Updated documentation of affected function.
* Strengthen against resource leaks upon exceptions.Kaz Kylheku2016-04-211-1/+2
| | | | | | | | | | | | | | | | | | | | | | | * glob.c (glob_wrap): Perform argument conversions that might throw before allocating UTF-8 string. * parser.y (text): In the action for SPACE, the lexeme is not needed so free($1) right away. If regex_compile were to throw an exception, that lexeme will leak. * socket.c (getaddrinfo_wrap): Harden against leakage of node_u8 and service_u8 strings with an unwind block. For instance, the hints structure could contain bad values which cause addrinfo_in to throw. * stream.c (make_string_byte_input_stream): Perform possibly throwing argument conversions before allocating resources. * sysif.c (mkdir_wrap, mknod_wrap, chmod_wrap, symlink_wrap, link_wrap, setenv_wrap, crypt_wrap): Likewise. * syslog.c (openlog_wrap, syslog_wrapv): Likewise.
* Recycle conses in unget-char and read-until-match.Kaz Kylheku2016-04-201-1/+1
| | | | | | | | | | | | * regex.c (ead_until_match): Use rcyc_pop instead of pop to move the conses to the recycle list. We know these are not shared with anything. Adding additional logic to completely recycle the stack. * socket.c (dgram_get_char): Use rcyc_pop to get the character from the push-back list. * stream.c (stdio_get_char): Likewise.
* Bugfix: optional arg defaulting in get-string.Kaz Kylheku2016-04-201-1/+2
| | | | | * stream.c (get_string): The optional stream argument must be treated accordingly.
* read-until-match can optionally keep matched text.Kaz Kylheku2016-04-201-3/+5
| | | | | | | | | | | | | | | | | | | | * regex.c (read_until_match): New argument, include_match. Three times repeated termination code refactored into block reached by forward goto. (regex_init): Registration of read-until-match updated. * regex.h (read_until_match): Declaration updated. * stream.c (struct record_adapter_base): New member, include_match. (record_adapter_get_line): Pass match to read_until_match as new argument. (record_adapater): New argument, include_match. (stream_init): Update registration of record-adapter. * stream.h (record_adapter): Declaration updated. * txr.1: Updated.
* Allow unlimited character pushback in unget-char.Kaz Kylheku2016-04-191-10/+5
| | | | | | | | | | | | | | | | Fixing read_until_match will require this feature. * socket.c (dgram_get_char): Treat unget_c as a cons-based stack; pop a character from it if available. (dgram_unget_char): Push the character onto unget_c rather than storing the characer into unget_c. * stream.c (stdio_get_char, stdio_unget_char): Closely analogous changes to the ones in dgram_get_char and dgram_unget_char, respectively. * txr.1: Documentation improved and updated.
* Incorrect format args in string stream code.Kaz Kylheku2016-04-191-1/+1
| | | | | * stream.c (string_in_unget_char): Missing argument in uw_throwf call.
* Fix broken unget_char over string input streams.Kaz Kylheku2016-04-191-1/+1
| | | | | | * stream.c (string_in_unget_char): Store the updated position into the stream, rather than the original value, which does nothing.
* Make open_socket static and register in socket.c.Kaz Kylheku2016-04-141-3/+0
| | | | | | | | | | | | | | * lisplib.c (sock_set_entries): Add auto-load entry for open-socket. * socket.c (open_socket): Change to static. (sock_load_init): Register open-socket intrinsic here rather than in stream.c. * stream.c (stream_init): Remove registration of open-socket intrinsic. * stream.h (open_socket): Declaration removed.
* Socket mode strings defaulted and checked.Kaz Kylheku2016-04-141-6/+12
| | | | | | | | | | | | * stream.c (do_parse_mode): New static function. (parse_mode): Logic moved into do_parse_mode, leaving this function as a wrapper for do_parse_mode. Check added for malformed mode, so functions which call parse_mode now have the check. Added defaulting for mode_str argument, inside do_parse_mode. (normalize_mode): Call do_parse_mode instead of parse_mode. Don't default mode_str argument, since do_parse_mode does that.
* Adding fmt function.Kaz Kylheku2016-04-141-0/+6
| | | | | | | | * stream.c (fmt): New function. * stream.h (fmt): Declared. * txr.1: Documented.
* Wrap #if HAVE_SOCKETS around some functions.Kaz Kylheku2016-03-311-0/+4
| | | | | | * stream.c (delegate_get_sock_family, delegate_get_sock_type, delegate_get_sock_peer, delegate_set_sock_peer): These functions should only be defined if HAVE_SOCKETS is true.
* UTF-8 API overhaul: security, and other concerns.Kaz Kylheku2016-03-311-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The main aim here is to pave the way for conversion between arbitrary buffers of bytes (that may include embedded NUL characters) and a wide string. Also, a potential security hole is closed. When we convert a TXR string to UTF-8 for use with some C library API, any embedded pnul characters (U+DC00) turn into NUL bytes which effectively cut the UTF-8 string short, and silently so. The C library function receives a shortened string. This could be exploitable in some situations. * lib.c (int_str): Use utf8_dup_to_buf instead of utf8_dup_to_uc. Pass 1 to have the buffer null-terminated, since mp_read_radix depends on it. * stream.c (make_string_byte_input_stream): Use utf8_dup_to_buf. This gives us the size, soo we don't have to call strlen. The buffer is no longer null terminated, but the byte input stream implementation never relied on this. * utf8.c (utf8_from_buf): Replacement fors utf8_from_uc which doesn't assume that the buffer of bytes is null-terminated. It can produce a wide string containing U+DC00 characters corresponding to embedded nulls in the original buffer. (utf8_from): Calculate length of null-terminated string and use utf8_from_buf. (utf8_to_buf): Replacement for utf8_to_uc. Can produce a buffer which is or is not null-terminated, based on new argument. (utf8_to): Use utf8_to_buf, and ask it to null-terminate, thus preserving behavior. (utf8_dup_from_uc): This function was not used anywhere and is removed. (utf8_dup_to_buf): Replacement for utf8_dup_to_uc which takes an extra agrgument, whether to null-terminate or not. (utf8_dup_to): Apply security check here: is the resulting string as long as utf8_to says it should be? If not, it contains embedded nulls. Throw an exception. * utf.h (utf8_from_uc, utf8_to_uc, utf8_dup_from_uc, utf8_dup_to_uc): Declarations removed. (utf8_from_buf, utf8_to_buf, utf8_dup_to_buf): Declared.
* Expose sock-set-peer function.Kaz Kylheku2016-03-311-0/+1
| | | | * stream.c (stream_init): Register sock-set-peer intrinsic.
* Replace all stray C style casts with macros.Kaz Kylheku2016-03-291-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * gc.c (gc_report_copies): C style casts found in this function. * linenoise.c (strip_qual, convert, coerce): Copy and paste the macros here. (record_undo, compare_completions, lino_add_completion, history_search, ab_append, sync_data_to_buf, refresh_singleline, screen_rows, refresh_multiline, find_nearest_paren, paren_jump, yank_sel, edit_move_matching_paren, edit, lino_make, lino_copy, lino_hist_add, lino_hist_set_max_len): C style casts replaced. * mpi/mpi-types.h (MP_DIGIT_BIT, MP_DIGIT_MAX, MP_WORD_BIT, MP_WORD_MAX, RADIX): C style casts replaced. * mpi/mpi.c (convert, coerce): Copy and paste the macros here. (mp_init_size, mp_init_copy, mp_copy, mp_set_int, mp_div_d, mp_bit, mp_to_double, mp_to_signed_bin, mp_to_unsigned_bin, mp_to_unsigned_buf, mp_toradix_case, mp_grow, s_mp_set_bit, s_mp_mod_2d, s_mp_mul_2d, s_mp_div_2d, s_mp_mul_d, s_mp_mul, s_mp_sqr, s_mp_div, s_mp_2expt, s_mp_todigit): C style casts replaced. * mpi/mplogic (convert): Macro copy and pasted here. (mpl_num_set, mpl_num_clear): C style casts replaced. * parser.c (provide_completions): Likewise. * signal.c (small_sigfillset): Likewise. * stream.c (stdio_truncate, test_set_indent_mode, set_indent_mode): Likewise.
* Improve treatment of open mode in tail streams.Kaz Kylheku2016-03-191-2/+9
| | | | | | | | | * stream.c (tail_strategy): Apply the mode whenever a new stream is opened. (open_tail): Store the original mode string in h->mode rather than the normalized one, so in tail_strategy we can apply all the same attributes to a newly opened stream that we applied to the original stream.
* Permissive stream open mode strings.Kaz Kylheku2016-03-191-28/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There is more to this patch than just more permissive mode strings. Now if a socket can be opened with mode "l2" for instance, and these options are effectively applied to the socket-specific "r+b" default, not to "r". * stream.c (parse_mode): New argument specifying a default mode. The syntax is relaxed, allowing previously required elements to be omitted. (normalize_mode): New argument specifying a default mode. Format mode is always called now, because an input string is no longer necessarily a valid fopen string even in cases when it doesn't specify any extensions. (open_file, open_fileno, open_tail, open_command, open_process): Use new normalize_mode argument for defaulting; normalize_mode no longer defaults to "r". * stream.h (stdio_mode_init_trivial): Macro removed. (stdio_mode_init_blank, stdio_mode_init_r, stdio_mode_init_rpb): New initializer macros. (parse_mode, normalize_mode): Declarations updated. * socket.c (sock_accept): In datagram socket case, use new parse_mode argument for defaulting using stdio_mode_init_rpb, rather than overriding a missing string with "r+b". (open_sockfd): Likewise, and use new normalize_mode argument similarly for defaulting the mode on a stream socket. * txr.1: Documented mode string permissiveness.
* Size mode meaningful in datagram sockets.Kaz Kylheku2016-03-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | * socket.c (struct dgram_stream): new rx_max member. (make_dgram_sock_stream): New arguments: a struct stdio_mode, and pointer to prototype dgram socket. If a size is specified in the mode, then use that as rx_max. Otherwise if a prototype socket is specified, use its rx_max as the new socket's rx_max. Otherwise default on 65536. (dgram_get_byte_callback): Use d->rx_max as the capture size, rather than a hard-coded 65536. (sock_accept): Use d->rx_max as capture size for datagram. Parse the mode. Pass the parsed mode to make_dgram_sock_stream, as well as the accepting socket, so it can set up the rx_max for the new socket. (open_sockfd): Parse the mode and pass to make_dgram_sock_stream. * stream.c (parse_mode): Static function becomes extern. * stream.h (parse_mode): Declared. * txr.1: Documented.
* Buffer size digit in file open mode string.Kaz Kylheku2016-03-191-2/+25
| | | | | | | | | | | | | | | | | * streamn.c (struct stdio_handle): New member, buf. (stdio_stream_destroy): Free the stdio_handle's buf. (parse_mode): Handle digit character, converting it to integer value stored in m.buforder. (set_mode_props): Allocate a buffer and install into FILE * stream if the mode specifies a buforder. (make_stdio_stream_common): Initialize buffer to null. * stream.h (struct stdio_mode): New signed bitfield member, buforder. (stdio_mode_init_trivial): Initialize buforder member to -1. * txr.1: Documented size order digit.
* New l and u letters in stream open mode strings.Kaz Kylheku2016-03-181-4/+24
| | | | | | | | | | | | | | * stream.c (parse_mode): Recognize "l" and "u", and set new flags. (set_mode_props): More complicated behavior to integrate the new options with the line mode defaulting behavior of "i". * stream.h (struct stdio_mode): New members unbuf and linebuf. All members become bit fields of width 1. (stdio_mode_init_trivial): Initializers for new members. * txr.1: Documented.
* Bugfix: set errno to zero in stdio_unget_byte.Kaz Kylheku2016-03-151-0/+1
| | | | | | * stream.c (stdio_unget_byte): Set errno to zero before ungetc, because ungetc probably almost certainly doesn't set errno when it fails.
* Implement socket timeouts.Kaz Kylheku2016-03-151-0/+8
| | | | | | | | | | | | | | | | | * lib.c (timeout_error_s): New symbol variable. (obj_init): Intern timeout-error, init new variable. * lib.h (timeout_error_s): Declared. * socket.c (sock_timeout, sock_send_timeout, sock_recv_timeout): New static functions. (sock_load_init): Register sock-send-timeout and sock-recv-timeout intrinsics. * stream.c (stdio_maybe_read_error, stdio_maybe_error): Convert EAGAIN into timeout_error_s. * txr.1: Documented.
* All stdio streams get line buffering with i mode.Kaz Kylheku2016-03-141-1/+6
| | | | | | | | | | | * socket.c (open_sockfd): We no longer need to set stream sockets to line buffered mode here; it's done in set_mode_props. * stream.c (set_mode_props): If the mode specifies interactive, streams open for writing are also switched to line buffering. * txr.1: Documented under open-file, and open-socket.
* Workaround for apparent putc bug in Cygwin.Kaz Kylheku2016-03-101-0/+7
| | | | | | | | | | | This fix is required for the stream socket test case to pass. Some interaction between a stdio stream in line buffering mode and the putc function causes a stream to lose data. If we use fputs instead to output a character, the issue goes away. * stream.c (se_putc): When compiling for Cygwin, construct a one-character-long string and use fputs, rather than putc.
* Record adapter passes through socket ops.Kaz Kylheku2016-03-071-0/+29
| | | | | | | * stream.c (delegate_get_sock_family, delegate_get_sock_type, delegate_get_sock_peer, delegate_set_sock_peer): New static functions. (stream_init): Wire new functions in record_adapter_ops.
* Revamped naming for socket streams.Kaz Kylheku2016-03-071-4/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * socket.c (struct dgram_stream): New member, addr. (make_dgram_sock_stream): Initialize addr to nil. (dgram_print): Instead of printing the numeric fd, print the stream description, obtained from the name_k property. (dgram_mark): Mark the addr member. (dgram_get_prop): Calculate a descriptive string from the dgram stream state for the name_k property. (dgram_set_prop): New static function. (dgram_strm_ops): Name change to dgram-sock. Wire in dgram_set_prop function. (sock_bind): Set the addr_k property of the stream to the local address that was just bound. * stream.c (addr_k): New keyword symbol variable. (stdio_handle): New member, addr. (stdio_stream_print): Obtain descr by calling get_prop method rather than directly from h->descr, in case it is dynamically computed. Use ~a rather than ~s for incorporating string properties into printed form, to eliminate quotes. (stdio_stream_mark): Mark new addr member. (sock_get_prop, sock_set_prop): New static functions. (stdio_set_sock_peer): Invalidate h->descr by setting it to nil. (make_stdio_stream_common): Initialize h->addr to nil. (make_sock_stream): Specify description as nil rather than "socket". (stream_init): Intern the addr keyword, and initialize the addr_k variable. Set the name of stdio_sock_ops to "stream-sock" rather than leaving it inherited as "file-stream". Wire in the sock_get_prop and sock_set_prop functions into stdio_sock_ops. * stream.h (addr_k): Declared.
* gc bugs: more instances of wrong mutations.Kaz Kylheku2016-03-071-1/+1
| | | | | | | | * socket.c (dgram_set_sock_peer): Assign to struct dgram_stream using using set macro. * stream.c (stdio_set_sock_peer): Assign to struct stdio_handle peer using set macro.
* Bugfix: incorrect error string from stdio streams.Kaz Kylheku2016-03-071-1/+1
| | | | | | | * stream.c (errno_to_string): Fix wrong test; it is a nil value of err which is the "no error" case, not non-nil. Due to this bug, any non-numeric error condition will be reported as "no error", including the case t ("eof").
* Special implementation of dgram socket streams.Kaz Kylheku2016-03-061-32/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * socket.c (struct dgram_stream): New struct. (make_dgram_sock_stream, dgram_print, dgram_mark, dgram_destroy, dgram_overflow, dgram_put_byte_callback, dgram_put_string, dgram_put_char, dgram_put_byte, dgram_get_byte_callback, dgram_get_char, dgram_get_byte, dgram_unget_char, dgram_unget_byte, dgram_flush, dgram_close, dgram_get_prop, dgram_get_fd, dgram_get_sock_family, dgram_get_sock_type, dgram_get_sock_peer, dgram_set_sock_peer, dgram_get_error, dgram_get_error_str, dgram_clear_error): New static functions. (dgram_strm_ops): New static structure. (sock_listen): Check against datagram sockets which have a peer; otherwise a no-op for datagram sockets. (sock_accept): Special logic for dgram sockets. (open_sockfd): Function moved here from stream.c, and augmented to open dgram stream for dgram sockets. (open_socket): Function moved here from stream.c. (sock_load_init): Fill in some operations in dgram_strm_ops. * stream.c (generic_get_line, make_sock_stream, errno_to_string): Statics become external. (open_sockfd, open_socket): Functions removed from here, moved to socket.c. * stream.h (generic_get_line, make_sock_stream, errno_to_string): Declared.
* Bugfix: get-string closing stream when told not to.Kaz Kylheku2016-03-061-1/+1
| | | | | | * stream.c (get_string): Use default_arg_strict instead of default_arg, so that the t value is only substituted for a missing argument, not for a nil argument.
* Move error check from operation to wrapper.Kaz Kylheku2016-03-061-3/+2
| | | | | | * stream.c (stdio_unget_char): Remove not-a-character check from character argument. (unget_char): Perform check here, thus for all stream types.
* Access to file descriptor now via stream virtual.Kaz Kylheku2016-03-061-15/+45
| | | | | | | | | | | | | | | | | | | | | | | | | * stream.c (unimpl_get_fd, null_get_fd): New static functions. (fill_stream_ops): Set up get_fd function pointer in strm_ops. (null_ops): Add null_get_fd. (stdio_get_fd): New static function. (stdio_ops, tail_ops, pipe_ops): Specify stdio_get_fd as get_fd function. (stream_fd): Rewritten as call to get_fd operation. (dir_ops, string_in_ops, byte_in_ops, string_out_ops, strlist_out_ops, cat_stream_ops): Specify null as get_fd function, to be defaulted by fill_stream_ops. (delegate_get_fd): New static function. (record_adapter_ops): Specify delegate_get_fd as get_fd function. (stream_init): Change fileno intrinsic registration to point to stream_fd function. * stream.h (struct strm_ops): New member, get_fd. (strm_ops_init): New macro parameter, get_fd. * syslog.c (syslog_strm_ops): Specify null as get_fd function.
* Make stdio_mode type public.Kaz Kylheku2016-03-061-14/+2
| | | | | | | | | | | | * stream.c (struct stdio_mode, stdio_mode_init_trivial): Struct declaration and macro removed from here; moved into stream.h. (normalize_mode, set_mode_props): Static functions made external. * stream.h (struct stdio_mode, stdio_mode_init_trivial): Moved here. (normalize_mode, set_mode_props): Declared.
* Replace stdio_get_line with generic routine.Kaz Kylheku2016-03-051-25/+23
| | | | | | | | | | * stream.c (snarf_line): Function renamed to generic_get_line. Interface and implementation changed so it can be used directly as get_line virtual. (stdio_get_line): Function removed. (stdio_ops, pipe_ops): Point get_line to generic_get_line. (tail_get_line): Call generic_get_line instead of stdio_get_line.
* Socket operations become proper stream virtuals.Kaz Kylheku2016-03-041-13/+77
| | | | | | | | | | | | | | | | | | | | | | | * stream.c (unimpl_get_sock_family, unimpl_get_sock_type, unimpl_get_sock_peer, unimpl_set_sock_peer): New static functions. (fill_stream_ops): Set new function pointers in struct strm_ops to point to the unimpl_* functions. (stdio_get_sock_family, stdio_get_sock_type, stdio_get_sock_peer, stdio_set_sock_peer): New static functions. (stdio_sock_ops): New static structure. (make_sock_stream): Use stdio_sock_ops for socket object. (sock_family, sock_type, sock_peer, sock_set_peer): These API functions now just call their corresponding virtuals. (stream_init): Set up stdio_sock_ops as a copy of stdio_ops, and then override the socket-specific virtuals from the unimpl_* stubs to the stdio_get_sock_* and stdio_set_sock_* functions. * stream.h (struct strm_ops): New members, get_sock_family, get_sock_type, get_sock_peer and set_sock_peer. (strm_ops_init): Set new members to zero.
* Make make_sock_stream static in stream.c.Kaz Kylheku2016-03-041-1/+1
| | | | | | | * stream.c (make_sock_stream): External function becomes static; it is not used outside of this source file. * stream.h (make_sock_stream): Declaration removed.
* Socket streams know their connected peer address.Kaz Kylheku2016-02-271-0/+18
| | | | | | | | | | | | * stream.c (struct stdio_handle): New member, peer. (stdio_stream_mark): Mark the new member. (sock_peer, sock_set_peer): New functions. (stream_init): Registered sock-peer intrinsic. * stream.h (sock_peer, sock_set_peer): Declared. * socket.c (sock_connect): If the connect is successful, then store the address into the stream as the peer.
* Fix descriptor leak on exception in open-fileno.Kaz Kylheku2016-02-271-1/+3
| | | | | * stream.c (open_fileno): If w_fdopen fails, close the file descriptor before throwing exception.
* open-fileno: errno usage.Kaz Kylheku2016-02-271-1/+1
| | | | * stream.c (open_fileno): clear errno to 0 before fdopen.
* Adding socket support: unix, ipv4, ipv6.Kaz Kylheku2016-02-261-0/+96
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * socket.c, socket.h: New files. * Makefile: include new socket.o among objects if have_objects variable is defined to 'y'. * configure (have_sockets): New variable. New configure test for socket-related functionality. (HAVE_SOCKETS, HAVE_GETADDRINFO): New configuration preprocessor symbols. Also, reordering the shell probing so that /usr/xpg4/bin/sh is the last fallback. On Solaris, it chokes on some code that is needed for Solaris. * lisplib.c (sock_set_entries, sock_instantiate): New static functions. (lisplib_init): Register new functions as autoload hooks. * share/txr/stdlib/socket.tl: New file. * stream.c (socket_error_s): New symbol variable. (struct stdio_handle): New members, family and type, helping stdio streams represent sockets too. (stdio_stream_mark): Mark new members of struct stdio_handle. (make_stdio_stream_common): Initialize new members. (make_sock_stream, stream_fd, sock_family, sock_type, open_socket, open_sockfd): New functions. (stream_init): Initialize socket_error_s variable. Register sock-family, sock-type and open-socket intrinsic functions. Register socket-error subtype. * stream.h (socket_error_s, make_sock_stream, stream_fd, sock_family, sock_type, open_socket, open_sockfd): Declared.
* Place C standard I/O based streams into subtype.Kaz Kylheku2016-02-261-2/+5
| | | | | | | | | | | | | | | | | | | * lib.c (subtypep): Handle subtype check here between stream and stdio-stream as a special case, since streams aren't structures related by inheritance, but built-ins. (class_check): If the type of obj doesn't match the class exactly, use a subtypep check. We need this because stream functions use this check, and stdio streams are not of the stream type now. * stream.c (stdio_stream_s): New global symbol variable. (make_stdio_stream_common): Use stdio_stream_s symbol for the type of stdio streams. (stream_init): Intern the stdio-stream symbol, and store in stdio_stream_s variable. (streamp): Replace exact check with typep. * stream.h (stdio_stream_s): Declared.
* Fix regression: get-char on string input stream.Kaz Kylheku2016-01-191-2/+3
| | | | | | | | | | This happened on 2015-07-29, before TXR 111, "Deriving streams from the same base" commit. * stream.c (string_in_get_char): Must retrieve the character at the previous position, not the incremented one. Otherwise we lose the first character, and of course we blow up with an out of range access when we hit the end of the string.
* Record-delimiting stream adapter.Kaz Kylheku2016-01-011-0/+181
| | | | | | | | | | | | | | | | | | | | | | | | | | * regex.c (read_until_match): New function. (regex_init): Registered read-until-match intrinsic. * regex.h (read_until_match): Declared. * stream.c (struct delegate_base): New struct type. (delegate_base_mark, delegate_put_string, delegate_put_char, delegate_put_byte, delegate_get_char, delegate_get_byte, delegate_unget_char, delegate_unget_byte, delegate_close, delegate_flush, delegate_seek, delegate_truncate, delegate_get_prop, delegate_set_prop, delegate_get_error, delegate_get_error_str, delegate_clear_error, make_delegate_stream): New static functions. (struct record_adapter_base): New struct type. (record_adapter_base_mark, record_adapter_mark_op, record_adapter_get_line): New static functions. (record_adapter_ops): New static structure. (record_adapter): New function. (stream_init): Registered record-adapter intrinsic. * stream.h (record_adapter): Declared. * txr.1: Documented read-until-match and record-adapter.
* Copyright year bump.Kaz Kylheku2015-12-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | * LICENSE, METALICENSE, Makefile, args.c, args.h, arith.c, arith.h, cadr.c, cadr.h, combi.c, combi.h, configure, debug.c, debug.h, eval.c, eval.h, filter.c, filter.h, gc.c, gc.h, glob.c, glob.h, hash.c, hash.h, jmp.S, lib.c, lib.h, lisplib.c, lisplib.h, match.c, match.h, parser.c, parser.h, parser.l, parser.y, rand.c, rand.h, regex.c, regex.h, share/txr/stdlib/cadr.tl, share/txr/stdlib/except.tl, share/txr/stdlib/hash.tl, share/txr/stdlib/ifa.tl, share/txr/stdlib/path-test.tl, share/txr/stdlib/place.tl, share/txr/stdlib/struct.tl, share/txr/stdlib/txr-case.tl, share/txr/stdlib/type.tl, share/txr/stdlib/with-resources.tl, share/txr/stdlib/with-stream.tl, share/txr/stdlib/yield.tl, signal.c, signal.h, stream.c, stream.h, struct.c, struct.h, sysif.c, sysif.h, syslog.c, syslog.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Add 2016 copyright. * linenoise/LICENSE, linenoise/linenoise.c, linenoise/linenoise.h: Bump one principal author's copyright from 2014 to 2015. The code is based on a snapshot of 2015 upstream work.
* New variables for floating-point printing control.Kaz Kylheku2015-12-281-4/+15
| | | | | | | | | | | | | | | | | * lib.c (obj_print_impl): Instead of hard-coded "~s", obtain the format string for floats from the *print-flo-format* special variable, whose default value is "~s". * stream.c (print_flo_digits_s, print_flo_format_s): New symbol variables. (formatv): Use *print-flo-digits* value for default precision for ~f and ~e, rather than hard-coded 3. (stream_init): Initialize print_flo_digits_s and print_flo_format_s, and register special variables under those symbols. * stream.h (print_flo_digits_s, print_flo_format_s): Declared. * txr.1: Documented new specials.
* Overhaul printing of lazy strings.Kaz Kylheku2015-12-281-26/+31
| | | | | | | | | | | | | | | | | | The #<lazy-string ...> print syntax is gone. Lazy strings are now printed by traversing their structure, without forcing them to the flat representation. * lib.c (lazy_str_put): New function. (out_str_char, out_str_pretty, out_lazy_str): New static functions. (obj_print_impl): Use out_str_pretty for standard-printing regular strings. Use lazy_put_str for pretty-printing lazy strings, and out_lazy_str for standard-printing them. * lib.h (lazy_str_put): Declared. * stream.c (put_string): Check for a lazy string and route to lazy_str_put, so the string doesn't get forced (though of course the underlying list does, if it is lazy).
* Bugfix: crash in get_line.Kaz Kylheku2015-12-091-8/+6
| | | | | | | | | | | Incorrect, irrelevant handle test inside stdio_get_line virtual function fails to detect closed stream, leading to a null pointer passed to the stdio library. * stream.c (snarf_line): Rewrite according to pattern followed by the other functions. We must test h->f for null, not stream->co.handle, which never goes null until the object is being reclaimed by gc.