summaryrefslogtreecommitdiffstats
path: root/stream.c
Commit message (Collapse)AuthorAgeFilesLines
...
* Implementing truncate-stream.Kaz Kylheku2015-10-211-7/+50
| | | | | | | | | | | | | | | | | | | | | | | * configure: Test for ftruncate and chsize. * stream.c (unimpl_truncate): New static function. (fill_stream_ops): Default the truncate operation to unimpl_truncate. (null_ops): Initialize truncate to unimpl_truncate. (stdio_truncate): New static function. (stdio_ops, tail_ops): Initialize truncate to stdio_truncate. (pipe_ops, dir_ops, string_ops, byte_in_ops, string_out_ops, strlist_out_ops, cat_stream_ops): Initialize truncate to null, so it gets defaulted by fill_stream_ops. (truncate_stream): New function. (stream_init): Register truncate-stream intrinsic. * stream.h (struct strm_ops): New member, truncate. (strm_ops_init): New truncate argument added to macro. (truncate_stream): Declared. *syslog.c (syslog_strm_ops): Initialize truncate to null. * txr.1: Documented.
* Correction in error message on unimplemented seek.Kaz Kylheku2015-10-211-1/+1
| | | | | * stream.c (unimpl_seek): Function should identify itself as seek-stream, not seek.
* Support binary specifier in format.Kaz Kylheku2015-10-171-5/+26
| | | | | | | | * stream.c (formatv): New 'b' case along side 'o', handling binary in straightforward way for bignums, and with binary formatting loop code for fixnums. * txr.1: Documented b.
* Remove use of the system function.Kaz Kylheku2015-10-161-19/+10
| | | | | | | | | | System depends on environment variables, and also causes SIGINT and SIGQUIT to be ignored. * stream.c (sh): Function rewritten in terms of sh, in two platform variants. * txr.1: Documented that sh doesn't use system as of TXR 120.
* Don't force lazy string in string input streams.Kaz Kylheku2015-09-261-11/+5
| | | | | | | | | * stream.c (find_char): Don't extract C string from string; use abstract access to find the character, without calculating length. (string_in_get_line, string_in_get_char): Don't calculate the length of the string to compare it to the position; use the lazy-safe length_str_gt function instead.
* Introduce chk_wmalloc function.Kaz Kylheku2015-09-221-1/+1
| | | | | | | | | | | | | | | Two-fold benefit. Simplifies code which allocates wchar_t arrays. Provides overflow check for the multiplication. * lib.c (chk_wmalloc): New function. (chk_strdup, mkstring, mkustring, upcase_str, downcase_str, sub_str, cat_str, trim_str): Use chk_wmalloc. * lib.h (chk_wmalloc): Declared. * stream.c (make_string_output_stream): Use chk_wmalloc. * utf8.c (utf8_dup_from_uc, utf8_dup_from): Likewise.
* Don't use prot1 for temporary gc protection.Kaz Kylheku2015-09-071-10/+4
| | | | | | | | | | | | * lib.c (split_str, split_str_set, list_str, int_str): Use gc_hint rather than prot1/rel1. More efficient, doesn't use space in the prot_stack array. * regex.c (search_regex): Likewise. * stream.c (vformat_str, formatv, run): Likewise. In formatv, rel1 wasn't being called in the uw_unwind block, so this fixes a bug.
* Move stat functions to use a struct.Kaz Kylheku2015-08-301-16/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * lib.c (init): Move hash_init and struct init before sysif_init. * share/txr/stdlib/path-test.tl (sys:path-test-mode, path-mine-p, path-my-group-p, sys:path-access, path-newer, path-examine): Convert to struct return of stat functions. * stream.c (dev_k, ino_k, mode_k, nlink_k, uid_k, gid_k, rdev_k, size_k, blksize_k, blocks_k, atime_k, mtime_k, ctime_k): Global variable definitions removed from here. (stream_init): Initializations of moved global variables removed from here. * stream.h (dev_k, ino_k, mode_k, nlink_k, uid_k, gid_k, rdev_k, size_k, blksize_k, blocks_k, atime_k, mtime_k, ctime_k): Declarations removed from here. * sysif.c (stat_s, dev_s, ino_s, mode_s, nlink_s, uid_s, gid_s, rdev_s, size_s, blksize_s, blocks_s, atime_s, mtime_s, ctime_s): New global variables. (dev_k, ino_k, mode_k, nlink_k, uid_k, gid_k, rdev_k, size_k, blksize_k, blocks_k, atime_k, mtime_k, ctime_k): Existing variables moved here. (stat_to_struct): New static function. (stat_impl): Use stat_to_struct, except under 113 compatibility. (sysif_init): Initialize new symbol variables. Make stat struct type. * sysif.h (stat_s, dev_s, ino_s, mode_s, nlink_s, uid_s, gid_s, rdev_s, size_s, blksize_s, blocks_s, atime_s, mtime_s, ctime_s): Declared.
* Renaming c_true to tnil.Kaz Kylheku2015-08-271-1/+1
| | | | | | | | | | | | | | | | | | | | Macros called c_* should produce C counterparts of Lisp val objects, like c_num and c_str. * lib.h (c_true): Renamed to tnil. * eval.c (lexical_var_p, lexical_fun_p): c_true to tnil. * lib.c (less, chr_isalnum, chr_isalnum, chr_isalpha, chr_isascii, chr_iscntrl, chr_isdigit, chr_isgraph, chr_islower, chr_isprint, chr_ispunct, chr_isspace, chr_isblank, chr_isunisp, chr_isupper, chr_isxdigit, chr_toupper, keywordp): Likewise. * stream.c (catenated_stream_p): Likewise. * sysif.c (wifexited, wifsignaled, wcoredump, wifstopped, wifcontinued): Likewise.
* Replace two-step initialization of args with macros.Kaz Kylheku2015-08-241-2/+1
| | | | | | | | | | | | | | | | | | | | | * args.h (args_init_list, args_init): Return the struct args * pointer. (args_decl_list, args_decl): New macros. * eval.c (apply, do_eval, expand_macro, op_dwim, op_catch, (mapcarl, lazy_mapcarl): Switch to new macros. * hash.c (hashl): Likewise. * lib.c (generic_funcall, lazy_appendl, maxl, minl, funcall, funcal1, funcall2, funcall3, funcall4, transpose, juxtv, do_and, do_or, do_iff, unique): Likewise. * match.c (h_fun, v_fun): Likewise. * stream.c (vformat): Likewise. * syslog.c (syslog_wrap): Likewise.
* Large scale conversion to new way of handling arguments.Kaz Kylheku2015-08-231-26/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Function arguments are now allocated on the stack using alloca, in conjunction with the struct alloc header structure. The generic_funcall and apply functions are refactored for this, as are most functions that take variadic arguments. * args.c (args_add_list, args_cons_list): Functions removed. (args_normalize, args_normalize_fill): New functions. (args_get_checked): Draw arguments from list when array runs out. (args_copy, args_copy_zap): New functions. * args.h (ARGS_MAX): Reduced to 32. (ARGS_MIN): New preprocessor symbol. (args_init): Call args_init_list. (args_add2, args_add3, args_add4): New inline functions. (args_more): Take into account list, which may hold additional arguments. (args_two_more): New inline function. (args_normalize, args_normalize_fill): Declared. (args_get_list): Normalize all arguments into one list and return it. (args_get_rest, args_at, args_atz): New inline functions. (args_get): Draw arguments from list when array runs out. (args_clear): New inline function. * arith.c (maskv): Convert to new args. * eval.c (APPLY_ARGS): Preprocessor symbol removed. (bind_args): Converted to accept struct args. (apply): Function reduced down to trivial adapter which converts a list of arguments to args, and calls the new generic_funcall. (applyv): New static function: struct args wrapper around apply_intrinsic. (iapply): Converted to struct args. (call): Static function removed. The call intrinsic function binding now goes directly to generic_funcall. (list_star_intrinsic, interp_fun): Converted to struct args. (op_catch): Adjustments for bind_args, which requires a struct args arglist. (me_op): Must use the new minl and maxl, since minv and maxv don't take lists any more. (mapcarv, mappendv, lazy_mapcarv, lazy_mappendv, mapdov, weavev, or_fun, and_fun, tf, nilf, do_retf, do_apf, do_ipf, callf, do_mapf, mapf): Converted. (mapcarl): New function, like the old mapcarv. (eval_init): call_f initialized from generic_funcall rather than call. apply registered to applyv rather than apply_intrinsic. Registrations for zip, hash_from_pairs, vec, alist-remove, alist-nremove, and throw similarly updated to new or renamed functions. * eval.h (interp_fun, mapcarv): Declarations updated. (mapcarl): Declard. * hash.c (hashv): Converted to struct args. (hashl): New function. (hash_construct): Use hashl, not hashv. (hash_from_pairs, hash_list, group_by): Converted. * hash.h (hashv, hash_construct, hash_from_pairs, hash_list, group_by): Declarations updated. (hashl): Declared. * lib.c (appendv, nconcv, lazy_appendv): Converted to struct args. (lazy_appendl): New function. (multi): Converted. (listv): New function. (nary_op, plusv, mulv, logandv, logiorv, gtv, ltv, gev, lev, numeqv, numneqv, maxv, minv): Converted. (maxl, minl): New functions, like old maxv and minv. (exptv, gcdv, lcmv, lessv, greaterv, lequalv, gequalv): Converted. (func_f0v, func_f1v, func_f2v, func_f3v, func_f4v): Converted. (func_n0v, func_n1v, func_n2v, func_n3v, func_n4v): Converted. (func_n0v, func_n1v, func_n2v, func_n3v, func_n4v): Converted. (func_n1ov, func_n2ov, func_n3ov): Converted. (generic_funcall): Converted to take struct args. (funcall, funcall1, funcall2, funcall4): Pass stack-allocated struct args as trailing arguments to variadic functions, and to generic_funcall. (do_curry_12_1_v): New struct-args-based static function, needed to implement curry_12_1_v now. (curry_12_1_v): Converted. (transposev): New function based on previous tranpose. (transpose): Now a wrapper for transposev. (do_chain, chainv, do_chand, chandv, do_juxt, juxtv, do_and, andv, do_or, orv, do_not, do_iff): Converted. (vectorv): New function. Implementation basis for vec intrinsic function. (alist_removev, alist_nremovev): New functions. (multi_sort): Switch from mapcarv to mapcarl. (unique): Converted. (uniq): Allocate struct args for calling unique. (obj_init): list_f function now based on new listv, rather than identity. * list.h (varg): New typedef. (struct func): All variadic function pointers converted to use struct args. (appendv, nconcv, lazy_appendv, multi, nary_op, plusv, minusv, mulv, gtv, ltv, gev, lev, numeqv, numneqv, maxv, minv, exptv, gcdv, lcmv, logadnv, logiorv, maskv, lessv, greaterv, lequalv, gequalv, func_f0v, func_f1v, func_f2v, func_f3v, func_f4v, func_n0v, func_n1v, func_n2v, func_n3v, func_n4v, func_n0v, func_n1v, func_n2v, func_n3v, func_n4v, func_n1ov, func_n2ov, func_n3ov, generic_funcall, chainv, chandv, juxtv, adnv, orv, unique): Declarations updated. (lazy_appendl, listv, maxl, minl, transposev, vectorv, alist_removev, alist_nremovev): Declared. * stream.c (make_catenated_stream_v): New function. (aformat): Renamed to formatv. The recognition of the nil and t streams (standard output and string) is done here now. (vformat): Follow rename of aformat to formatv. (formatv): Function removed. Nobody calls this anymore. (stream_init): make-catenated-stream re-registered to new make_catenated_stream_v function. * stream.h (formatv): Declaration updated. (make_catenated_v): Declared. * syslog.c (syslog_init): syslog registred to syslog_wrapv. (syslog_wrapv): New function based on syslog_wrap converted to struct args. (syslog_wrap): Now wrapper for syslog_wrapv. * syslog.h (syslog_wrapv): Declared. * unwind.h (uw_throwv): New function. (uw_throwfv, uw_errorfv): Converted to struct args. * unwind.h (uw_throwv): Declared. (uw_throwfv, uw_errorfv): Declarations updated.
* Remove silly use of apply from open-files.Kaz Kylheku2015-08-211-5/+2
| | | | * stream.c (open_files, open_files_star): Refactored.
* Streamlining format with new args module.Kaz Kylheku2015-08-171-66/+48
| | | | | | | | | | | * stream.c (vformat): split into a new function called aformat, and a small wrapper which retains the vformat name. (aformat): New function formed from most of vformat. Takes struct args * instead of va_list. (formatv): Big switch statement hack gone. Now the function fills in a struct args, allocated on the stack, with an accurate size based on the args list. This is passed directly to aformat.
* Observe display width in format.Kaz Kylheku2015-08-131-6/+36
| | | | | | | | | | | | | Take into account string display width in field trimming and padding calculations, including situations where only half a character fits. * stream.c (calc_fitlen): New function. (vformat_str): Revised to use calc_fitlen. If calc_fitlen indicates that there is no trimming or padding, then use put_string rather than put_char. * txr.1: Update description of format with regard to use of dispaly width in field calculations.
* Fix regression in string field formatting.Kaz Kylheku2015-08-121-4/+0
| | | | | * stream.c (vformat_str): Remove stray bogus code that unconditionally outputs extra left padding.
* Catenated stream reads must not close last stream.Kaz Kylheku2015-08-121-6/+9
| | | | | | * stream.c (cat_get_line, cat_get_char, cat_get_byte) Only close the head stream when popping it off the list.
* Count East Asian Wide and Full Fidth chars as two columns.Kaz Kylheku2015-08-101-4/+5
| | | | | | | | | | | | | | | | | * regex.c (create_wide_cs): New static function. (wide_display_char_p): New function. * regex.h (wide_display_char_p): Declared. * stream.c (put_string, put_char): Use wide_display_char_p to determine whether an extra column need be counted. Also bugfix: iswprint evidently cannot be relied to work over the entire Unicode range, at least not in the C locale. Glibc's version and is reporting valid Japanese characters as unprintable on Ubuntu. As a hack we instead check for control characters and invert the result: control chars are unprintable. * tests/009/json.expected: Updated.
* C++ upkeep: conversions, clashes, warnings.Kaz Kylheku2015-08-071-1/+1
| | | | | | | | | * glob.c (glob_wrap): Fix signed/unsigned comparison. * stream.c (make_null_stream): Fix convert beign used where coerce is needed. * sysif.c (dup_wrap): Fix use of C++ new keyword.
* * stream.c: Include <wctype.h> header for iswprint.Kaz Kylheku2015-08-071-0/+1
| | | | Needed on Cygwin.
* * stream.c (stream_init): Register get-indent-mode, set-indent-mode,Kaz Kylheku2015-08-051-0/+11
| | | | | | | | test-set-indent-mode, get-indent, set-indent, inc-indent and width-check intrinsic functions. Register indent-off, indent-data and indent-code variables. * txr.1: Documented stream output indentation API.
* * stream.c (width_check): Just use the publicKaz Kylheku2015-08-051-11/+4
| | | | | put_char function; no need to manipulate column or call put_indent.
* * stream.c (put_string): In indent mode, put_string hasKaz Kylheku2015-08-041-6/+7
| | | | | | | | to process all the characters as if by put_char, (which we now do literally that way). (set_indent_mode): Bugfix: no longer reset the column to zero when turning off indent mode. This is wrong since streams do column counting all the time.
* * stream.c (vformat): Implement ~! format directive for indentation.Kaz Kylheku2015-08-041-7/+37
| | | | | | | Allow negative widths to be specified with a leading minus sign, so that we can indent to the left. * txr.1: Document ~! format directive.
* * stream.c (put_string, put_char): Do not put out the indentationKaz Kylheku2015-08-041-2/+13
| | | | | immediately after outputting a newline. Rather, delay the output of the indentation until some output occurs at column zero.
* * stream.c (inc_indent): If a negative indentation increment goes belowKaz Kylheku2015-08-041-0/+4
| | | | | zero, clamp it at zero. (set_indent): Clamp indentation value to zero.
* * stream.c (vormat): Bugfix: when width specified as *Kaz Kylheku2015-08-041-1/+1
| | | | | | meets a negative argument, the width should be treated as positive and the field left aligned. Instead, the width is treated as zero.
* * stream.c (string_out_put_string): Do not return nil whenKaz Kylheku2015-08-041-2/+4
| | | | buffer calculations overflow, but throw exception.
* Remove useless return values and checks.Kaz Kylheku2015-08-041-78/+41
| | | | | | | | | | | | | | | * stream.c (vformat_align_pre, vformat_align_post): Change to void return. Do not check return value of put_char. (vformat_num, vformat_str): Change to void return. Do not check return value of vformat_align_pre, vformat_aign_post or put_char. (vformat): Do not check return value of vformat_str or vformat_num. nilout exit point no longer needed. (put_string): Do not intercept return value of ops->put_string. Return t. (put_char): Do not intercept return value of ops->put_char. Do not check return value of put_indent. Return t. * txr.1: Document t return of put-char, put-byte and put-string.
* * stream.c (indent_mode_put_string): Function removed,Kaz Kylheku2015-08-041-17/+4
| | | | | | | logic hoisted into put_string. (put_string, put_char): Always count column, indent mode or not. * tests/009/json.expected: Updated.
* Pass pretty flag to cobj print operation.Kaz Kylheku2015-08-011-3/+8
| | | | | | | | | | | | | | | | | | | | | * hash.c (hash_print_op): Take third argument, and call cobj_print_impl rather than cobj_print. * lib.c (cobj_print_op): Take third argument. The object class is * printed with obj_print_impl. (obj_print_impl): Static function becomes extern. Passes its pretty flag argument to cobj print virtual function. * lib.h (cobj_ops): print takes third argument. (cobj_print_op): Declaration updated. (obj_print_impl): Declared. * regex.c (regex_print): Takes third argument, and ignores it. * stream.c (stream_print_op, stdio_stream_print, cat_stream_print): Take third argument, and ignore it. * stream.h (stream_print_op): Declaration updated.
* string_output renamed to string_outKaz Kylheku2015-07-311-8/+8
| | | | | | | * stream.c (struct string_output): Renamed to string_out. (string_out_stream_destroy, string_out_byte_callback, string_out_put_char, strnig_out_put_string, string_out_put_byte, make_string_output_stream, get_string_from_stream): Follow rename.
* Simplify type check code in stream module.Kaz Kylheku2015-07-311-191/+100
| | | | | | | | | | | | | | | * stream.c (get_string_from_stream, get_list_from_stream, stream_set_prop, stream_get_prop, close_stream, get_line, get_char, get_byte, unget_char, unget_byte, put_string, put_char, put_byte, flush_stream, seek_stream): Use cobj_handle and cobj_ops instead of type_check and type_assert. (get_indent_mode, test_set_indent_mode, set_indent_mode, get_indent, set_indent, inc_indent, width_check): Use cobj_handle and cobj_ops instead of stream->co.handle and stream->co.ops for safety. (vformat, format): Use class_check instead of type_check and type_assert.
* Multi-line, indented printing of structure.Kaz Kylheku2015-07-311-3/+145
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * eval.c (op_error): New static function. (macro_form_p, fboundp): Static to external. (special_operator_p): New function. (eval_init): Register macrolet and symacrolet to op_error. These are recognized and processed by expand, but we want them in the op table so they are reported by special_operator_p. * eval.h (fboundp, macro_form_p, special_operator_p): Declared. * hash.c (print_key_val): Break long lines on spaces between pairs with stream_width_check. (hash_print_op): Implement split and indented printing. * lib.c (obj_print_impl): New static function, resulting from a merge of obj_print and obj_pprint. Fixes some wrong-way recursion bugs: obj_pprint recursed into obj_print in some places. Adds support for multi-line printing of vectors and lists, with indentation using the new interfaces in streams. * stream.c (strm_base_init): Update initializer. (put_indent, indent_mode_put_string): New static functions. (put_string): Use indent_mode_put_string in either of the two indent modes. (put_char): Implement indent mode. (get_indent_mode, test_set_indent_mode, set_indent_mode, get_indent, set_indent, inc_indent, width_check): New functions. * stream.h (enum indent_mode): New. (struct strm_base): indent_on member becomes indent_mode. New members data_width and code_width. (get_indent_mode, test_set_indent_mode, set_indent_mode, get_indent, set_indent, inc_indent, width_check): Declared. * tests/009/json.expected: Updated. * tests/010/seq.expected: Likewise. * tests/011/macros-2.expected: Likewise.
* Deriving streams from the same base, soKaz Kylheku2015-07-291-106/+175
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | we can give streams some common slots. * stream.c (strm_base_init, strm_base_cleanup, strm_base_mark, stream_destroy_op, stream_mark_op): New functions. (null_ops): Switch to stream_destroy_op and stream_mark_op. (make_null_stream): Associate a strm_base instance with the cobj handle rather than a null pointer. (struct stdio_handle): Inherit struct strm_base. (stdio_stream_destroy): Clean up the strm_base part. (stdio_stream_mark): Mark the strm_base part. (make_stdio_stream_common): Initialize the strm_base part. (struct dir_handle): Inherit struct strm_base. (dir_destroy): Clean up the strm_base part. (dir_mark): Mark the strm_base part. (make_dir_stream): Initialize the strm_base part. (struct string_in): New structure. Replaces ad-hoc cons cell used for string input streams. (string_in_stream_mark): Mark new structure. (string_in_get_line, string_in_get_char, string_in_unget_char, string_in_get_prop, string_in_get_error, make_string_input_stream): Convert to new structure. (string_in_ops): Switch to stream_destroy_op. (struct byte_input): Inherit struct strm_base. (byte_in_stream_destroy): No need to check handle for null. No need to set handle to null after freeing: gc does it. Clean up the strm_base part. (byte_in_ops): Switch to stream_mark_op. (make_string_byte_input_stream): Initialize the strm_base part. (struct string_output): Inherit struct strm_base. (string_out_stream_destroy): No need to check handle for null since the logic elsewhere has changed. Clean up the strm_base part. No need to set handle to null. (string_out_ops): Switch to stream_mark_op. (make_string_output_stream): Initialize the strm_base part. (get_string_from_stream): Don't free the handle. Null out the buffer so->buf whose ownership passes to the string. (struct strlist_out): New structure. Replaces ad-hoc cons cell used for string list output stream. (strlist_mark): Renamed to strlist_out_mark. Mark the strm_base part. (strlist_out_put_string, strlist_out_put_char, make_strlist_output_stream, get_list_from_stream): Convert to new structure. (strlist_out_ops): Switch to stream_destroy_op. Follow rename of strlist_mark. (struct cat_strm): New structure, replacing ad-hoc list pointer
* * stream.c (common_destroy): Function removed.Kaz Kylheku2015-07-291-7/+2
| | | | (stdio_stream_destroy, dir_destroy): Call close_stream directly.
* * stream.c: Rearranging definitions and declarations so thatKaz Kylheku2015-07-291-432/+431
| | | | | | code for each stream type is together. Moving catenated streams above utility functions, so they are together with other stream definitions.
* Centered fields in format.Kaz Kylheku2015-07-281-25/+69
| | | | | | | | | | | | * stream.c (enum align): New enum. (vformat_align_pre, vformat_align_post): New static functions. (vformat_num, vformat_str): Argument left renamed to align, and changed to enum align. vformat_align_pre and vformat_align_post are called to generate the correct padding for left, center and right alignment. (vformat): Two-valued local variable left turned into three-valued align. The ^ prefix on the width field is recognized. * txr.1: Documented ^ width prefix.
* * stream.c (byte_in_unget_byte): Wrong function name in error message.Kaz Kylheku2015-07-101-1/+1
|
* Fix unget-byte and unget-char on catenated streams.Kaz Kylheku2015-07-101-2/+2
| | | | | * stream.c (cat_unget_byte, cat_unget_char): Recursive call to unget_byte and unget_char with reversed arguments.
* Improved printing of stream objects.Kaz Kylheku2015-07-071-16/+38
| | | | | | | | | | | | | | | | | | | | | * stream.c (null_stream_print): Static function removed. (stream_print_op): New function. Prints stream's name and address. (null_get_prop): Pull stream name from strm_ops structure rather than hard-coding to "null-stream". (null_ops, stdio_ops, tail_ops, pipe_ops, string_in_ops, byte_in_ops, string_out_ops, strlist_out_ops, dir_ops, cat_stream_ops): Use stream_print_op in place of cobj_print_op. Initialize name. (stdio_stream_print): Use name from ops structure, and include object address. (string_in_get_prop): Likewise. (cat_stream_print): Likewise. * stream.h (struct strm_ops): New member, name. (strm_ops_init): Initialize name. (stream_print_op): Declared. * syslog.c (syslog_strm_ops): Use stream_print_op. Initialize name.
* Bugfix in printed rep of stdio stream.Kaz Kylheku2015-07-061-2/+3
| | | | | | * stream.c (stdio_stream_print): Wrong way test on h->pid; if it is nonzero it must be printed. Was printed wrong: argument of integer type passed to ~s which expects a val.
* Clarify clear-error and flush return value.Kaz Kylheku2015-07-061-16/+7
| | | | | | | | | | | * stream.c (stdio_clear_error): Return the prior value of h->err. Do not inspect feof(h->f) or ferror(h->f); just clear the error status of the stream. (stdio_close): Set h->err from errno if fclose failed. (dir_clear_error): Return prior value of h->err. * txr.1: Document return value convetion for clear-error, and flush-stream.
* Tightening behavior for unimplemented stream ops.Kaz Kylheku2015-07-061-25/+208
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In many cases, if a stream operation is not applicable to a stream, it is not appropriate to just do nothing and return nil. An error must be thrown. * stream.c (unimpl, unimpl_put_string, unimpl_put_char, unimpl_put_byte, unimpl_get_line, unimpl_get_char, unimpl_get_byte, unimpl_unget_char, unimpl_unget_byte, unimpl_seek, null_put_string, null_put_char, null_put_byte, null_get_line, null_get_char, null_get_byte, null_close, null_flush, null_seek, null_set_prop, null_get_error, null_get_error_str, null_clear_error): New static functions. (fill_stream_ops): New function. (null_ops): Use null_put_string, etc., instead of null pointers. (stdio_clear_error, dir_clear_error, cat_clear_error): Return value now indicating whether an error was cleared. (stream_set_prop, stream_get_prop, real_time_stream_p, close_stream, get_error, get_error_str, clear_error, get_line, get_char, get_byte, unget_char, unget_byte, put_string, put_char, put_byte, flush_stream): Do not test whether a function in the ops table is defined; just call it, and return its value. (stream_init): Call fill_stream_ops on all stream operation structures so any null pointers are defaulted to appropriate functions. * stream.h (struct strm_ops): clear_error gets return value. (fill_stream_ops): Declared. * syslog.c (syslog_init): Call fill_stream_ops on syslog_strm_ops.
* * stream.c (catenated_stream_p, catenated_stream_push): New functions.Kaz Kylheku2015-06-071-0/+24
| | | | * stream.h (catenated_stream_p, catenated_stream_push): Declared.
* Fix escaping issues in open-process on Windows.Kaz Kylheku2015-04-151-12/+47
| | | | | | | | | | | | | | | This can now execute programs with spaces in their path names. Arguments can contain embedded double quotes, and other characters that are special to cmd.exe, like &, |, (, ), ^ and others. * stream.c (string_extend_count, win_escape_cmd): New static functions. (win_escape_arg): Fix and extend escaping scheme to cover not only the argument processing scheme implemented by programs which use Microsoft's C library, but also to smuggle the command line through cmd.exe. (win_make_cmdline): Use win_escape_cmd to wrap the command. Escape the quotes which are placed around arguments, so cmd.exe doesn't interpret them, which will cause it to suppress its processing of the caret escapes.
* Functions open-fileno and fileno.Kaz Kylheku2015-04-101-1/+20
| | | | | | | | | | | | | | | | * stream.c (fd_k): New keyword variable. (stdio_get_prop): Handle the :fd property by returning the file descriptor. (open_fileno): New function. (stream_init): Initialize fd_k, and register fileno and open-fileno. * stream.h (open_fileno): Declared. * txr.1: Documented open-fileno and fileno. * utf8.c (w_fdopen): New function. * utf8.h (w_fdopen): Declared.
* * stream.c (vformat): Bugfix: ~X printing in lower case, like ~x,Kaz Kylheku2015-03-301-1/+1
| | | | when argument is a bignum integer.
* New -n option. New "i" mode letter in file opening functions.Kaz Kylheku2015-03-291-10/+137
| | | | | | | | | | | | | | | | | | | | | | | | * stream.c (struct stdio_mode): New struct type. (stdio_mode_init_trivial): New initializer macro. (parse_mode, format_mode, normalize_mode, set_mode_props): New static functions. (make_stdio_stream_common): the isatty check, and automatic marking of tty device streams as real-time is no longer done, unless backward compatibility 105 or earlier is requested. (open_file, open_tail, open_command, open_process): Use new mode parsing, which supports the "i" flag. (stream_init): If we have isatty, and standard input is a tty, then mark the *std-input* stream as real-time. * txr.1: Document -n/--noninteractive option. Fix typo where real-time-stream-p is referred to as stream-real-time-p. Document "i" flag on open-file and others. * txr.c (opt_noninteractive): New global. (help): Help text for -n/--noninteractive. (txr_main): Handle new options. * txr.h (opt_noninteractive): Declared.
* * stream.c (run): In Windows version, fix nasty corruption bug:Kaz Kylheku2015-03-111-2/+0
| | | | | we were freeing C strings that were not duplicated, but only borrowed from string objects.
* * stream.c (open_process, run, sh): Eliminate utf8name local variableKaz Kylheku2015-03-111-10/+6
| | | | | and associated memory leak. Correctly allocate only nargs + 1 elements for argv array, not nargs + 2.