summaryrefslogtreecommitdiffstats
path: root/stream.c
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* Introducing persistent error state on streams.Kaz Kylheku2015-02-251-27/+208
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * lib.c (cobj_ops): New function. * lib.h (cobj_ops): Declared. * stream.c (null_ops): Initializer updated. (struct stdio_handle): New member, err. (stdio_stream_mark): Mark the err member. (errno_to_string): New static function. (stdio_maybe_read_error, stdio_maybe_error): Set persistent error state. Use errno_to_string_function. (stdio_put_string, stdio_put_char, stdio_put_byte, stdio_seek, stdio_get_line): Set errno to zero, so that if the underlying operations do not set errno on err, we don't misinterpret some pervious errno value as pertaining to the failed stream operation. (stdio_get_error, stdio_get_error_str, stdio_clear_error): New static functions. (stdio_ops, tail_ops, pipe_ops): Update initializer with new functions. (string_in_get_error, string_in_get_error_str): New static functions. (string_in_ops): Update initializer with new functions. (byte_in_get_error, byte_in_get_error_str): New static functions. (byte_in_ops): Update initializer with new functions. (string_out_ops, strlist_out_ops): Update initializer with null pointers for new functions. (struct dir_handle): New struct type. (dir_destroy, dir_mark): New functions. (dir_get_line): Refactor for struct dir_handle context rather than DIR. Persist error state. (dir_close): Refactor for struct dir_handle. (dir_get_error, dir_get_error_str, dir_clear_error): New static functions. (dir_ops): Update initializer with new functions. (make_stdio_stream_common): Initialize new err member. (make_dir_stream): Refactor for struct dir_handle. (get_error, get_error_str, clear_error): New functions. (cat_get_error, cat_get_error_str, cat_clear_error): New static functions. (cat_stream_ops): Update initializer with new functions. (stream_init): Register get-error, get-error-str, clear-error intrinsics. * stream.h (struct strm_ops): New function pointer members, get_error, get_error_str and clear_error. (strm_ops_init): Macro extended with new arguments for new function pointers. (get_error, get_error_str, clear_error): Declared. * syslog.c (syslog_strm_ops): Update initializer with null pointers for new functions. * txr.1: Documented get-error, get-error-str and clear-error.
* Update copyright notices from 2014 to 2015.Kaz Kylheku2015-02-011-1/+1
| | | | | | | | | | | * arith.c, arith.h, combi.c, combi.h, debug.c, debug.h, eval.c, eval.h, filter.c, filter.h, gc.c, gc.h, hash.c, hash.h, lib.c, lib.h, match.c, match.h, parser.h, rand.c, rand.h, regex.c, regex.h, signal.c, signal.h, stream.c, stream.h, sysif.c, sysif.h, syslog.c, syslog.h, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Update. * LICENSE, METALICENSE: Likewise.
* Use macro to initialize strm_ops.Kaz Kylheku2015-01-291-202/+137
| | | | | | | | | | * stream.h (strm_ops_init): New macro. * stream.c (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): Initialize using macro. * syslog.c (syslog_strm_ops): Likewise.
* * stream.c (get_string): New argument, close_after_p.Kaz Kylheku2015-01-211-2/+7
| | | | | | | | | | | Close the stream unless close_after_p is specified and is nil, or when it is missing, an there is no compatibility or it's newer than version 102. * stream.h (get_string): Updated declartion. * txr.1: Documented default closing behavior of get-string and the new optional argument for overriding it.
* * lib.c (simple_lazy_stream_func): Bugfix: close the streamKaz Kylheku2014-12-251-3/+9
| | | | | | | | | | if get_line returns nil. * stream.c (cat_get_line, cat_get_char, cat_get_byte): The catenated stream read operations close an exhausted stream before popping to the next one. * txr.1: Document closing behavior of catenated streams.
* * stream.c (stream_init): Register make_catenated_stream inKaz Kylheku2014-12-251-1/+1
| | | | | | | | a different form as cat-streams. * txr.1: Document cat-streams. * tl.vim, txr.vim: Regenerated.
* * lib.c (chk_grow_vec): New function.Kaz Kylheku2014-10-301-4/+7
| | | | | | | | | (string_extend): Use chk_grow_vec. (vec_set_length): Avoid subtractions for comparing numbers. * lib.h (chk_grow_vec): Declared. * stream.c (snarf_line, string_out_put_string): Use chk_grow_vec.
* * Makefile: Removing trailing spaces.Kaz Kylheku2014-10-241-15/+15
| | | | | | | | | | (GREP_CHECK): New macro. (enforce): Rewritten using GREP_CHECK, with new checks. * arith.c, combi.c, debug.c, eval.c, filter.c, gc.c, hash.c, lib.c, * lib.h, match.c, parser.l, parser.y, rand.c, regex.c, signal.c, * signal.h, stream.c, syslog.c, txr.c, unwind.c, utf8.c: Remove trailing spaces.
* Converting cast expressions to macros that are retargettedKaz Kylheku2014-10-171-116/+122
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | to C++ style casts when compiling as C++. * lib.h (strip_qual, convert, coerce): New casting macros. (TAG_MASK, tag, type, wli_noex, auto_str, static_str, litptr, num_fast, chr, lit_noex, nil, nao): Use cast macros. * arith.c (mul, isqrt_fixnum, bit): Use cast macros. * configure (INT_PTR_MAX): Define using cast macro. * debug.c (debug_init): Use cast macro. * eval.c (do_eval, expand_macro, reg_op, reg_mac, eval_init): Use cast macros. * filter.c (filter_init): Use cast macro. * gc.c (more, mark_obj, in_heap, mark, sweep_one, unmark): Use cast macros. * hash.c (hash_double, equal_hash, eql_hash, hash_equal_op, hash_hash_op, hash_print_op, hash_mark, make_hash, make_similar_hash, copy_hash, gethash_c, gethash, gethash_f, gethash_n, remhash, hash_count, get_hash_userdata, set_hash_userdata, hash_iter_destroy, hash_iter_mark, hash_begin, hash_uni, hash_diff, hash_isec): Use cast macros. * lib.c (code2type, chk_malloc, chk_malloc_gc_more, chk_calloc, chk_realloc, chk_strdup, num, c_num, string, mkstring, mkustring, upcase_str, downcase_str, string_extend, sub_str, cat_str, trim_str, c_chr, vector, vec_set_length, copy_vec, sub_vec, cat_vec, cobj_print_op, obj_init): Likewise. * match.c (do_match_line, hv_trampoline, match_files, dir_tables_init): Likewise. * parser.l (grammar): Likewise. * parser.y (parse): Likewise. * rand.c (make_state, make_random_state, random_fixnum, random): Likewise. * regex.c (CHAR_SET_L2_LO, CHAR_SET_L2_HI, CHAR_SET_L1_LO, CHAR_SET_L1_HI, CHAR_SET_L0_LO, CHAR_SET_L0_HI, L0_full, L0_fill_range, L1_full, L1_fill_range, L1_contains, L1_free, L2_full, L2_fill_range, L2_contains, L2_free, L3_fill_range, L3_contains, L3_free, char_set_create, char_set_cobj_destroy, nfa_state_accept, nfa_state_empty, nfa_state_single, nfa_state_wild, nfa_state_set,
* Purge stray occurrences of "void *" from code base.Kaz Kylheku2014-10-171-6/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * lib.c (cobj_print_op): In the format call, cast the C pointer to val, since the ~p conversion now takes a val rather than void *. (cptr_equal_op, obj_print, obj_pprint): Remove cast to void *, since obj now already has the type that ~p expects. * lib.h (struct any): Use mem_t * instead of void *. * parser.h (yyscan_t): Repeat the definition from inside the Flex-generated lex.yy.c. (yylex_init, yylex_destroy, yyget_extra, yyset_extra): Re-declare using yyscan_t typedef in place of void *. * parser.l (yyget_column, yyerrprepf): Re-declare using yyscan_t. (grammar): Use yyg in place of yyscanner in calls to yyerrprepf. * parser.y (yylex, %lex-param): Use yyscan_t instead of void *. (parse): Use yyscan_t for local variable. * signal.c (stack): Change type from void * to mem_t *. * stream.c (vformat): Conversion specifier p extracts val instead of void *. (run): Use casts that only remove const, not all the way to void *. * txr.1: Documented p conversion specifier of format. * Makefile (OBJS-y): Initialize with := to make sure it is a simple variable, and not a macro. (SRCS): New variable, listing source files. (enforce): New rule for enforcing coding conventions. Currently checks for void * occurrences.
* Fix gc safety issue in abs_path_p function.Kaz Kylheku2014-10-091-4/+7
| | | | | | | * stream.c (ap_regex): New static variable. (abs_path_p): Remove local reg variable; replace uses of reg with ap_regex. (stream_init): gc-protect ap_regex.
* * stream.c (stream_init): No need to gc-protectKaz Kylheku2014-10-091-1/+0
| | | | | | | | | std_input, std_output, std_debug, std_error and std_null. These are not ordinary variables but macros which expand to locations in the variable binding environment that are already protected. This call was actually doing nothing, because the symbol involved in the expression std_input is not yet initialized and so &std_input yields a null pointer which causes protect to bail.
* Moving system interface functions to separate module out ofKaz Kylheku2014-10-081-298/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | the eval and stream modules. * Makefile (OBJS): Add sysif.o. * dep.mk: Regenerated. * eval.c (errno_wrap, daemon_wrap, exit_wrap, usleep_wrap, getpid_wrap, getppid_wrap, env_hash): Functions moved to sysif.c and changed to static functions. (eval_init): Registrations of functions moved to sysif.c. * lib.c (init): Call sysif_init. * stream.c (w_stat, statf, mkdir_wrap, chdir_wrap, getcwd_wrap, makedev_wrap, minor_wrap, major_wrap, mknod_wrap): Functions moved to sysif.c and become static functions. (stream_init): Registration of stat moved to sysif.c. (open_files, open_files_star): Bugfix: no longer erroneously included in #ifdef HAVE_UNISTD_H block. * stream.h (mkdir_wrap, chdir_wrap, getcwd_wrap, makedev_wrap, minor_wrap, major_wrap, mknod_wrap, symlink_wrap, link_wrap, readlink_wrap): Declarations removed. * sysif.c: New file. * sysif.h: New file.
* GC correctness fixes: make sure we pin down objects for which we borrowKaz Kylheku2014-08-251-7/+26
| | | | | | | | | | | | | | | low level C pointers, while we execute code that can cons memory. * lib.c (list_str): Protect the str argument. (int_str): Likewise. * regex.c (search_regex): protect the haystack string, while using the h pointer to its data, since regex_run can use the derivative-based engine which conses. * stream.c (vformat_str): Protect str argument, since put_char might conceivably cons. (vformat): Protect fmtstr.
* * Makefile, arith.c, arith.h, combi.c, combi.h, configure, debug.c,Kaz Kylheku2014-07-231-16/+16
| | | | | | | | debug.h, eval.c, eval.h, filter.c, filter.h, gc.c, gc.h, hash.c, hash.h, lib.c, lib.h, match.c, match.h, parser.h, parser.l, parser.y, rand.c, rand.h, regex.c, regex.h, signal.c, signal.h, stream.c, stream.h, syslog.c, syslog.h, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Synchronize license header with LICENSE.
* * stream.c (put_strings, put_lines): New functions.Kaz Kylheku2014-07-191-0/+20
| | | | | | | | (stream_init): Registered new functions as intrinsics. * stream.h (put_strings, put_lines): Declared. * txr.1: Documented.
* * eval.c (eval_init): Register get-lines as a synonym for lazy-stream-cons.Kaz Kylheku2014-07-191-0/+19
| | | | | | | | | | | * stream.c (get_string): New function. * stream.h (get_string): Declared. (stream_init): get_string registered as get-string intrinsic. * txr.1: Documented get-string, and get-lines as a synonym for lazy-stream-cons. Documented the behavioral difference of lazy-stream-cons lazy lists for real-time and non-real-time streams.
* * match.c (v_load): use the abs_path_p function instead ofKaz Kylheku2014-06-121-0/+21
| | | | | | | | | | | | | checking for leading slash. * stream.c (abs_path_p): New function. (stream_init): Register abs_path_p as abs-path-p. * stream.h (abs_path_p): Declared. * txr.1: Documented abs-path-p. * dep.mk: Updated.
* The dumping of bindings and printing of false must nowKaz Kylheku2014-06-091-11/+0
| | | | | | | | | | | | | | | | | | | | | | | | | be explicitly requested by the -B option. * match.c (opt_nobindings): Variable removed. (opt_print_bindings): New variable. (extract): Print bindings or "false" if opt_print_bindings is true. * stream.c (output_produced): Variable removed. (stdio_put_string, stdio_put_char, stdio_put_byte): Remove update of output_produced. * stream.h (output_produced): Declaration removed. * txr.1: Documentation updated. * txr.c (txr_main): Option 'b' does nothing. 'B', 'l', 'a', and '--lisp-bindings' set opt_print_bindings to 1. * txr.h (opt_nobindings): Declaration removed. (opt_print_bindings): Declared. * unwind.c (uw_throw): When exiting due to a query error or file error, print false when opt_print_bindings is true.
* * stream.c (get_line, get_char, get_byte): Fix outdated, incorrectKaz Kylheku2014-04-141-6/+3
| | | | optional argument defaulting logic.
* Change to how locations are passed around, for the sake of generationalKaz Kylheku2014-03-291-7/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | GC. The issue being solved here is the accuracy of the gc_set function. The existing impelmentation is too conservative. It has no generation information about the memory location being stored, and so it assumes the worst: that it is a location in the middle of a gen 1 object. This is sub-optimal, creating unacceptable pressure against the checkobj array and, worse, as a consequence causing unreachable gen 0 objects to be tenured into gen 1. To solve this problem, we replace "val *" pointers with a structure of type "loc" which keeps track of the object too, which lets us discover the generation. I tried another approach: using just a pointer with a bitfield indicating the generation. This turned out to have a serious issue: such a bitfield goes stale when the object is moved to a different generation. The object holding the memory location is in gen 1, but the annotated pointer still indicates gen 0. The gc_set function then makes the wrong decision, and premature reclamation takes place. * combi.c (perm_init_common, comb_gen_fun_common, rcomb_gen_fun_common, rcomb_list_gen_fun): Update to new interfaces for managing mutation. * debug.c (debug): Update to new interfaces for managing mutation. Avoid loc variable name. * eval.c (env_fbind, env_fbind): Update to new interfaces for managing mutation. (lookup_var_l, dwim_loc): Return loc type and update to new interfaces. (apply_frob_args, op_modplace, op_dohash, transform_op, mapcarv, mappendv, repeat_infinite_func, repeat_times_func): Update to new interfaces for managing mutation. * eval.h (lookup_var_l): Declaration updated. * filter.c (trie_add, trie_compress, trie_compress_intrinsic, * build_filter, built_filter_from_list, filter_init): Update to new * interfaces. * gc.c (gc_set): Rewritten to use loc type which provides the exact generation. We do not need the in_malloc_range hack any more, since we have the backpointer to the object. (gc_push): Take loc rather than raw pointer. * gc.h (gc_set, gc_push): Declarations updated. * hash.c (struct hash): The acons* functions use loc instead of val * now. (hash_equal_op, copy_hash, gethash_c, inhash, gethash_n, pushhash, Change to how locations are passed around, for the sake of generational GC. The issue being solved here is the accuracy of the gc_set function. The existing impelmentation is too conservative. It has no generation information about the memory location being stored, and so it assumes the worst: that it is a location in the middle of a gen 1 object. This is sub-optimal, creating unacceptable pressure against the checkobj array and, worse, as a consequence causing unreachable gen 0 objects to be tenured into gen 1. To solve this problem, we replace "val *" pointers with a structure of type "loc" which keeps track of the object too, which lets us discover the generation. I tried another approach: using just a pointer with a bitfield indicating the generation. This turned out to have a serious issue: such a bitfield goes stale when the object is moved to a different generation. The object holding the memory location is in gen 1, but the annotated pointer still indicates gen 0. The gc_set function then makes the wrong decision, and premature reclamation takes place. * combi.c (perm_init_common, comb_gen_fun_common, rcomb_gen_fun_common, rcomb_list_gen_fun): Update to new interfaces for managing mutation. * debug.c (debug): Update to new interfaces for managing mutation. Avoid loc variable name. * eval.c (env_fbind, env_fbind): Update to new interfaces for managing mutation. (lookup_var_l, dwim_loc): Return loc type and update to new interfaces. (apply_frob_args, op_modplace, op_dohash, transform_op, mapcarv, mappendv, repeat_infinite_func, repeat_times_func): Update to new interfaces for managing mutation. * eval.h (lookup_var_l): Declaration updated. * filter.c (trie_add, trie_compress, trie_compress_intrinsic, * build_filter, built_filter_from_list, filter_init): Update to new * interfaces. * gc.c (gc_set): Rewritten to use loc type which provides the exact generation. We do not need the in_malloc_range hack any more, since we have the backpointer to the object. (gc_push): Take loc rather than raw pointer. * gc.h (gc_set, gc_push): Declarations updated. * hash.c (struct hash): The acons* functions use loc instead of val * now. (hash_equal_op, copy_hash, gethash_c, inhash, gethash_n, pushhash,
* * stream.c (win_make_cmdline): I think I cracked the code ofKaz Kylheku2014-03-161-1/+4
| | | | | | | | | | | passing escaped arguments to Microsoft's popen and system functions. The first argument cannot be quoted, but the subsequent ones can. It is the quoting of the first argument that causes the whole thing to be quoted. So we just avoid quoting the first argument. (If it has spaces, too bad; don't do that). (open_process): Fix neglected optional argument handling in Windows version of this function.
* * configure: Detect _wspawn* functions.Kaz Kylheku2014-03-161-0/+24
| | | | * stream.c (run): Implement using _wspawnvp on MinGW.
* * stream.c (run): Fix MinGW build failures. The run function doesn'tKaz Kylheku2014-03-141-1/+1
| | | | work right with arguments, though: the win command line is broken.
* * stream.c (open_process): If execvp fails, use errno as theKaz Kylheku2014-03-131-1/+78
| | | | | | exit status. (sh, run): New static functions. (stream_init): sh and run registered as intrinsics.
* * eval.c (plus_s, prof_s): New symbol global variables.Kaz Kylheku2014-03-121-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (op_prof, me_pprof): New static functions. (eval_init): Intern prof symbol, store in prof_s. Captured interned + symbol in plus_s. Register prof operator and pprof macro. * gc.c (gc_bytes): New global variable. (more): Use nse function chk_malloc_gc_more instead of chk_malloc. (make_obj): Increment gc_bytes. * lib.c (malloc_bytes): New global variable. (chk_malloc, chk_realloc): Increment malloc_bytes. (chk_calloc): Bugfix: incorrect size in recursion into oom_realloc. Incorrect calculation of malloc_high_bound. Increment malloc_bytes. (chk_malloc_gc_more): New function. * lib.h (alloc_bytes_t): New typedef. (malloc_bytes, gc_bytes): Declared. (chk_malloc_gc_more): Declared. * stream.c (format_s): New symbol global. (stream_init): format_s inited. format_s used to register formatv function. * stream.h (format_s): Declared. * txr.1: Documented prof and pprof. * genvim.txr: Recognize reg_fun calls with intern followed by a preceding assignment or other syntax. * txr.vim: Updated.
* * configure: new test for fcntl.Kaz Kylheku2014-03-111-1/+11
| | | | | | | | | | | * stream.c (open_process): Fixed off-by one erroneous value of nargs, causing memory leak of one string. Fixed memory leak on fork failure. Fixed a deadlock that can occur in the pipe close function when multiple pipes are in existence. This is fixed by setting the FD_CLOEXEC flag on the pipe file descriptor. Without this, one child process can hold another's pipe open, causing that other one not to terminate when we're trying to shut it down, resulting in that child blocked on a write, while we block on waitpid.
* * stream.c (open_process): In the event of fdopen failure,Kaz Kylheku2014-03-111-1/+5
| | | | | | kill the child process less abruptly by hitting it with SIGINT and SIGTERM, rather than with SIGKILL. Also, collect the child process with waitpid.
* * stream.c (open_process): Close the original pipe file descriptorKaz Kylheku2014-03-111-0/+4
| | | | | in the child process after dup2-ing it to standard input or standard output, so the child doesn't have to references to the pipe.
* * stream.c (pipe_close): Restructured the function a bit.Kaz Kylheku2014-03-101-21/+22
| | | | | | | | | | Do not throw exceptions for normal process terminations, only for abnormal ones (terminated by a signal). Return the termination status instead of just t. * txr.1: Fixed the neglected documentation of the optional boolean argument of close-stream. Described the behaviors with regard to pipes in more detail.
* * eval.c (apply_intrinsic, lazy_mapcar): Changed linkage to external.Kaz Kylheku2014-03-061-0/+27
| | | | | | | | | | | | | * eval.h (apply_intrinsic, lazy_mapcar): Declarations added. * stream.c (open_files, open_file_star): New functions. (stream_init): Registered new functions as intrinsics. * txr.1: Documented open-files and open-files*. Added to make-catenated-stream documentation. * genvim.txr: Replace bunch of code with open-files. * txr.vim: Regenerated.
* * stream.c (vformat): Fix broken parsing of parameteric width andKaz Kylheku2014-03-051-9/+13
| | | | | | | | | | | | precision (i.e. given by *). The simplest way to do this is to add a state vf_star which is similar to vf_digits, and reuses much of the logic via a goto. Fixing forgotten --fmt (push back char) when moving from vf_precision to vf_spec state due to unhandled character. Also, allowing a leading zero before a precision given as * so that computed precisions can be combined with zero padding. * txr.1: Documented leading zero better so it is clear it combines with *. Restructured documentation.
* * stream.c (put_line): Default string argument to empty string.Kaz Kylheku2014-03-051-2/+2
| | | | | | | (stream_init): Change how put_line is registered to take advantage of new optional parameter. * txr.1: Updated.
* Bugfix: catenated stream objects not hooked into garbage collector,Kaz Kylheku2014-03-021-1/+7
| | | | | | | causing premature collection of the catenated stream list. * stream.c (cat_mark): new function. (cat_stream_ops): use cat_mark for gc mark function.
* Change in the design of how special variables work, to fix the brokenKaz Kylheku2014-02-281-45/+101
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | re-binding. C code now has to go through the dynamic environment lookup to access things like *random-state*, or *stdout*. As part of this, I'm moving some intrinsic variable and function initializations out of eval.c and into their respective modules. Macros are are used to make global variables look like ordinary C variables. This is very similar to the errno trick in POSIX threads implementations. * eval.c (looup_var, lookup_var_l): Restructured to eliminate silly goto, the cobjp handling is gone. (reg_fun, reg_var): Internal function becomes external. reg_var registers a simple cons cell binding now, without any C pointer tricks to real C global variables. (c_var_mark): Static function removed. (c_var_ops): Static struct removed. (eval_init): Numerous initializations for streams, syslog, rand, signals and others moved to their respective modules. The new symbol variables user_package_s, keyword_package_s and system_package_s are interned here, and the variables are created in a special way. * eval.h (reg_var, reg_fun): Declared. * gc.c (prot1): Added assert that the loc pointer isn't null. This happened, and blew up during garbage collection. * lib.c (system_package, keyword_package, user_package): Variables removed these become macros. (system_package_var, keyword_package_var, user_package_var): New global variables. (system_package_s, keyword_package_s, user_package_s): New symbol globals. (get_user_package, get_system_package, get_keyword_package): New functions. (obj_init): Protect new variables. Initialization order of modules tweaked: the modules sig_init, stream_init, and rand_init are moved after eval_init because they register variables. * lib.h (keyword_package, system_pckage, user_package): Variables turned into macros. (system_package_var, keyword_package_var, user_package_var): Declared. (system_package_s, keyword_package_s, user_package_s): Declared. (get_user_package, get_system_package, get_keyword_package): Declared. * rand.c (struct random_state): Renamed to struct rand_state to avoid clash with new random_state macro. (random_state): Global variable removed. (random_state_s): New symbol global. (make_state, rand32, make_random_state, random_fixnum, random): Follow rename of struct random_state.
* * configure: Make it an error to have implicit function declarations byKaz Kylheku2014-02-251-0/+9
| | | | | | | | | | | means of -Werror=implicit-function-declarations. Fix broken mkdir and mknod tests. Regenerate config.make if we add -U__STRICT_ANSI__ to the compiler options, so that later tests benefit from this. Regenerate config.make right away if adding -D_DARWIN_C_SOURCE. This allows the makedev test to pass. * stream.c: Include <sys/types.h> for makedev. (mknod_wrap): Don't rely on makedev wrappers to be there; test.
* * stream.c (getcwd_wrap): Implement correct test of getcwd'sKaz Kylheku2014-02-251-1/+2
| | | | return value.
* * configure: Added feature tests for makedev, link/symlink/readlink,Kaz Kylheku2014-02-251-1/+25
| | | | | | | | | | | | | | mkdir and mknod. * eval.c (eval_init): Wrap #ifdefs around the registrations of the wrappers for these functions. * stream.c (mkdir_wrap): Wrap in #ifdef HAVE_MKDIR, and provide a Windows version if HAVE_MKDIR is missing, but HAVE_WINDOWS_H is true. (makedev_wrap, major_wrap, minor_wrap): Wrap with #if HAVE_MAKEDEV. (mknod): Use #if HAVE_MKNOD. (symlink_wrap, link_wrap, readlink_wrap): Wrap with #if HAVE_SYMLINK.
* * eval.c (eval_init): Intern symlink_wrap, link_wrap, readlink_wrap.Kaz Kylheku2014-02-241-1/+58
| | | | | | | | * stream.c (symlink_wrap, link_wrap, readlink_wrap): New functions. * stream.h (symlink_wrap, link_wrap, readlink_wrap): Declared. * txr.1: Documented.
* * eval.c (eval_init): Register forgotten s_ifsock variable.Kaz Kylheku2014-02-241-0/+84
| | | | | | | | | | | | | | | | Register mkdir_wrap, chdir_wrap, getcwd_wrap, makedev_wrap, minor_wrap, major_wrap and mknod_wrap. * stream.c (mkdir_wrap, chdir_wrap, getcwd_wrap, makedev_wrap, minor_wrap, major_wrap, mknod_wrap): New functions. (stream_init): Initialize forgotten variable s-ifsock. * stream.h (s_ifsock): Declared. (mkdir_wrap, chdir_wrap, getcwd_wrap, makedev_wrap, minor_wrap, major_wrap, mknod_wrap): Declared. * txr.1: Forgotten documentation for remove-path and rename-path added. Forgotten mention of s-ifsock. Documented new Unix functions.
* * stream.c (get_string_from_stream): Bugfix: do not abort ifKaz Kylheku2014-02-231-5/+8
| | | | stream is not a string stream, but throw a proper error exception.
* Replacing uses of the eq function which are used only as C booleans,Kaz Kylheku2014-02-221-10/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | with just using the == operator. Removing cobj_equal_op since it's indistinguishable from eq. Streamlining missingp and null_or_missing_p. * eval.c (transform_op): eq to ==. (c_var_ops): cobj_equal_op to eq. * filter.c (trie_compress, trie_lookup_feed_char, filter_string_tree, html_hex_continue, html_dec_continue): eq to ==. * hash.c (hash_iter_ops): cobj_equal to eq. * lib.c (countq, getplist, getplist_f, search_str_tree, posq): eq to ==. (cobj_equal_op): Function removed. * lib.h (cobj_equal_op): Declaration removed. (missingp): Becomes a simple macro that yields a C boolean instead of t/nil val, because it's only used that way. (null_or_missing_p): Becomes inline function returning int. * match.c (v_output): eq to ==. * rand.c (random_state_ops): cobj_equal_op to eq. * regex.c (char_set_obj_ops, regex_obj_ops): cobj_equal_op to eq. (reg_derivative): Silly if3 expression replaced by null. (regexp): Redundant if2 expression wrapped around eq removed. * stream.c (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): cobj_equal_op to eq. * syslog.c (syslog_strm_ops): cobj_equal_op to eq.
* The mode argument in some stream-opening functions becomes optional.Kaz Kylheku2014-02-181-5/+6
| | | | | | | | | | * eval.c (eval_init): Change registration for open_file, open_tail and open_command. * stream.c (open_file, open_tail, open_command): mode_str argument defaulted. * txr.1: Updated.
* * stream.c (open_tail): Fix 2013-12-02 regression:Kaz Kylheku2014-02-181-2/+9
| | | | | | | | seek_to_end_p argument being ignored, with the behavior being no initial seek to the end. * txr.1: Clarified the behavior of the seek-to-end-p option.