summaryrefslogtreecommitdiffstats
path: root/txr.c
Commit message (Collapse)AuthorAgeFilesLines
* Application code is now in a package called pub.Kaz Kylheku2018-04-091-1/+2
| | | | | | | | | | | | | | | * lib.c (public_package): New variable. (obj_init): Protect public_package from gc. Initialize it with a package called "pub" which has the user package in its fallback list. * lib.h (public_package): Declared. * eval.c (eval_init): Initialize package_s to public_package rather than user_package, except in compat <= 190 mode. * txr.c (txr_main): Bind *package* to public_package rather than user_package, except in compat <= 190 mode.
* Implement compiled file loading.Kaz Kylheku2018-04-041-2/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | * eval.c (load): If open_txr_file indicates compiled file by setting txr_lisp_p to character #\o, use read_compiled_file. * match.c (v_load): Likewise. * parser.c (open_txr_file): Recognize the .tlo suffix, and also try to open a .tlo version of an unsuffixed file before trying it as .tl. Indicate a .tlo file by setting txr_lisp_p to the character #\o rather than t. (read_file_common): New static function, made from contents of read_eval_stream. Will either evaluate forms or load compiled code by instantiating virtual machine descriptions and performing their top-level execution. (read_eval_stream): Now a wrapper for read_file_common. (read_compiled_file): New function. * parser.h (read_compiled_file): Declared. * txr.c (help): List new --compiled option. (txr_main): If --compiled is specified, set txr_lisp_p to #\o to load as compiled code. Update error message that -c is not compatible with --lisp or --compiled. If txr_lisp_p is #\o, then use read_compiled_file.
* Eliminate always false expression.Kaz Kylheku2018-02-161-1/+1
| | | | | | * txr.c (txr_main): Since parser.errors being nonzero is handled earlier, it must be zero at the final return point and need not be tested.
* Copyright year bump 2018.Kaz Kylheku2018-02-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * LICENSE, LICENSE-CYG, METALICENSE, Makefile, args.c, args.h, arith.c, arith.h, buf.c, buf.h, cadr.c, cadr.h, combi.c, combi.h, configure, debug.c, debug.h, eval.c, eval.h, ffi.c, ffi.h, filter.c, filter.h, ftw.c, ftw.h, gc.c, gc.h, glob.c, glob.h, hash.c, hash.h, itypes.c, itypes.h, jmp.S, lib.c, lib.h, lisplib.c, lisplib.h, match.c, match.h, parser.c, parser.h, parser.l, parser.y, protsym.c, rand.c, rand.h, regex.c, regex.h, share/txr/stdlib/awk.tl, share/txr/stdlib/build.tl, share/txr/stdlib/cadr.tl, share/txr/stdlib/conv.tl, share/txr/stdlib/doloop.tl, share/txr/stdlib/error.tl, share/txr/stdlib/except.tl, share/txr/stdlib/ffi.tl, share/txr/stdlib/getopts.tl, share/txr/stdlib/getput.tl, share/txr/stdlib/hash.tl, share/txr/stdlib/ifa.tl, share/txr/stdlib/keyparams.tl, share/txr/stdlib/op.tl, share/txr/stdlib/package.tl, share/txr/stdlib/path-test.tl, share/txr/stdlib/place.tl, share/txr/stdlib/pmac.tl, share/txr/stdlib/socket.tl, share/txr/stdlib/stream-wrap.tl, share/txr/stdlib/struct.tl, share/txr/stdlib/tagbody.tl, share/txr/stdlib/termios.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, socket.c, socket.h, stream.c, stream.h, struct.c, struct.h, strudel.c, strudel.h, sysif.c, sysif.h, syslog.c, syslog.h, termios.c, termios.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h, win/cleansvg.txr: Extended Copyright line to 2018.
* tprint and -t option: handle infinite list.Kaz Kylheku2017-10-121-3/+9
| | | | | | | | | | | | | | | | Test case: txr -t '(gun "foo")' must run in constant memory. * eval.c (tprint): Rewritten to iterate over lists using open loop rather than mapdo. Classification of the sequence is done using the new seq_info, as must be for all new sequence functions. * txr.c (txr_main): Implementation of -t, -p and -P captures the result of the expression in a variable whose value is zapped when it is passed to the function. A gc_hint is added so that this isn't optimized away. Thus, this code won't hold on to the original pointer to a lazy, infinite list.
* txr -i honored despite parse-time exception.Kaz Kylheku2017-09-061-7/+25
| | | | | | | | | | | | | | | | | | | | | If an error is thrown while parsing a .txr file or while reading and evaluating the forms of a .tl file. * parser.y (parse_once, parse): Wording change in message when exception is caught. Only exceptions derived from error are caught. * txr.c (parse_once_noerr, read_eval_stream_noerr): New static functions. (txr_main): Use parse_once_noerr and read_eval_stream_noerr instead of parse_once and read_eval_stream. Don't exit if a TXR file has parser errors; in that situation, exit only if interactive mode is not requested, otherwise go interactive. Make sure *self-path* is registered to the name of the input source in this case also. * unwind.h (ignerr_func_body): New macro.
* Revising out-of-memory handling.Kaz Kylheku2017-08-181-14/+1
| | | | | | | | | | | | | | | | | | | | | We don't want to be aborting on OOM, but throwing an exception. * lib.c (alloc_error_s): New symbol variable. (oom_realloc): Global variable removed. (oom): New static function. (chk_malloc, chk_malloc_gc_more, chk_calloc, chk_realloc): Call oom instead of removed oom_realloc handler. (env): Throw alloc-error rather than error by calling oom. (obj_init): Initialize alloc_error_s. (init): Drop function pointer argument; do not initialize removed oom_realloc. * lib.h (alloc_error_s): Declared. (oom_realloc): Declaration removed. (init): Declaration updated. * txr.1: Type tree diagram includes alloc-error.
* Update banner to inform about cheatsheet command.Kaz Kylheku2017-06-141-1/+1
| | | | * txr.c (banner): Text updated.
* Refactoring hash bang support; hash bang null hack.Kaz Kylheku2017-05-301-64/+65
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The hash bang mechanism is handled in one place, and disentangled from all parsing logic. It is also endowed with special powers. * eval.c (load): Pass one less argument to read_eval_stream. * match.c (v_load): Likewise. * parser.c (read_eval_stream): hash_bang_support Boolean argument removed. Hash bang logic removed. (load_rcfile): Pass only two arguments to read_eval_stream. * parser.h (read_eval_stream): Declaration updated. * txr.c (remove_hash_bang_line): Function removed. (check_hash_bang): New static function. (txr_main): Recognize the script file name while still inside the argument processing loop. Open the file, and check for a hash bang line, doing the special processing which can generate more arguments from material after a null byte in the hash bang line. The parse_stream variable is now initialized to nil and doubles as a Boolean indicating whether a stream has been opened. After the loop, we remove the script file from the arguments, if we have an open stream and the spec_file_str matches. read_eval_stream is called only with two arguments. * txr.1: Revised existing documentation and described new features.
* command line: --eargs semantics change.Kaz Kylheku2017-05-301-3/+2
| | | | | | | | | | | | | | | | | The --eargs mechanism won't perform a blind substring replacement of {} with the following argument. Only arguments which match {} exactly are replaced. * eval.c (retf): Static function becomes extern. * eval.h (retf): Declared. * txr.c (txr_main): Replace the filtering logic on the split eargs argument list to just look for items equal to the string "{}" and replace with the following argument. * txr.1: Updated --eargs documentation.
* New variable: *args-eff*.Kaz Kylheku2017-05-301-3/+19
| | | | | | | | | | | | * txr.c (txr_main): As arguments are processed, collect them into a list called the effective arg list, which is eventually visible as the *args-eff* variable. This is the argument list which reflects the expansions that have been applied by --args or --eargs. Those two options take special care to remove themselves from that list. * txr.1: Documented *args-eff*.
* Adding base-name and dir-name functions.Kaz Kylheku2017-05-211-7/+1
| | | | | | | | | | | | | | | * stream.c (path_sep_chars): New global variable. (detect_path_separators): New static function. (base_name, dir_name): New functions. (stream_init): Call detect_path_separators. Register base-name and dir-name intrinsic functions, and path-sep-chars variable. * stream.h (path_sep_chars, base_name, dir_name): Declared. * txr.c (dirname): Static function removed. (sysroot_init): Use dir_name instead of dirname. * txr.1: Documented dir-name, base-name and path-sep-chars.
* Connect -n option to linenoise noninteractive mode.Kaz Kylheku2017-04-041-0/+2
| | | | | | | | | | * parser.c (repl): Set noninteractive mode from noninteractive option. * txr.c (help): Mention effect of -n upon listener. * txr.1: Documented effect of -n/--noninteractive on the listener.
* Bugfix: missing warnings when main file is .txr.Kaz Kylheku2017-03-221-2/+2
| | | | | | | | | | | | | | | | | | | If the main file of an application is a .txr file, unbound function and variable warnings are not being generated. * match.c (v_load): For consistency with the load function in eval.c, release deferred warnings in the normal return case, if we are not a recursive load. However, this doesn't fix anything because a load or include is always recursive being invoked from a .txr file that is being loaded. The problem is in fact that the recursive flag is nil when it shouldn't be, and then the uw_unwind block obliterates the warnings. * txr.c (txr_main): We must bind *load-recursive* to t around not just the loading of Lisp, but also of TXR. Otherwise the individual loads will release warnings, raising false positives for forward references.
* Better way for releasing deferred warnings.Kaz Kylheku2017-02-101-2/+2
| | | | | | | | | | | | | | | | | | | | We should be re-throwing deferred warnings as ordinary warnings, not dumping them to a stream. * eval.c (eval_exception): Use uw_release_deferred_warnings instead of uw_dupm_deferred_warnings. (load): Likewise. * parser.c (read_eval_ret_last): Likewise. * txr.c (txr_main): Likewise. * unwind.c (uw_release_deferred_warnings): New function. * unwind.h (uw_release_deferred_warnings): Declared. * txr.1: Documented release-deferred-warnings and updated documentation for dump-deferred-warnings.
* Suppress undef warnings in command line file.Kaz Kylheku2017-01-291-0/+3
| | | | | | * txr.c (txr_main): Bind sys:*load-recursive* to t before reading and evaluating forms, then bind to nil before entering repl.
* Bump copyright year to 2017.Kaz Kylheku2017-01-231-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | * LICENSE, LICENSE-CYG, 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, ftw.c, ftw.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, signal.c, signal.h, stream.c, stream.h, struct.c, struct.h, sysif.c, sysif.h, syslog.c, syslog.h, termios.c, termios.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h, share/txr/stdlib/awk.tl, share/txr/stdlib/build.tl, share/txr/stdlib/cadr.tl, share/txr/stdlib/conv.tl, share/txr/stdlib/except.tl, share/txr/stdlib/getopts.tl, share/txr/stdlib/getput.tl, share/txr/stdlib/hash.tl, share/txr/stdlib/ifa.tl, share/txr/stdlib/package.tl, share/txr/stdlib/path-test.tl, share/txr/stdlib/place.tl, share/txr/stdlib/socket.tl, share/txr/stdlib/struct.tl, share/txr/stdlib/tagbody.tl, share/txr/stdlib/termios.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: Add 2017 to all copyright headers and strings.
* Enable unbound warnings when expanding TXR code.Kaz Kylheku2017-01-221-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With this change, Lisp expansion-time warnings are no longer suppressed during the parsing of the TXR pattern language. Embedded Lisp expressions can refer to TXR pattern variables, which generates spurious warnings that must be suppressed. Since TXR pattern variables are dynamically introduced in a very flexible way, it's hard to do an exact job of this. We take the crude approach that warnings are suppressed for all pattern variables that appear anywhere in the TXR code. To do that, we identify, at parse time, all directives which can bind new variables, and register those variables as if they were tentative global defs, purging all pending warnings for them. * match.c (binding_directive_table): New static hash table. (match_reg_var, match_reg_params, match_reg_elem): New functions. (match_reg_var_rec): New static function. (dir_tables_init): gc-protect binding_directive_table, and populate its entries. * match.h (into_k, named_k): Declared. (match_reg_var, match_reg_params, match_reg_elem): Declared. * parser.y (process_catch_exprs): New static function. (elem): Call match_reg_elem for each basic directive, to process the variables in that directive according to its operator symbol. Do this for each compound form elem and variable elem. Te horizontal @(define) eleme has its own grammar production here, and we handle its parameter list in that rule. (define_clause): Handle the parameters of a vertical @(define). It binds pattern variables, and so we must suppress unbound warnings for those. (catch_clauses_opt): Process the parameters bound by @(catch) clauses. (output_clause): Suppress warnings for the variables nominated by any :into or :named argument. (expand_repeat_rep_args): Suppress warnings for :counter variable, and for :vars variables. (parse_once): Remove the warning-muffling handler frame set up around the yyparse call. * txr.c (txr_main): Suppress warnings for TXR variables defined using -D syntax on the command line. Dump deferred warnings after parsing a .txr file.
* Streamline repeated intern call in txr_main.Kaz Kylheku2017-01-221-3/+4
| | | | | * txr.c (txr_main): Reduce three repetitions of the same call to intern to one call.
* Deferred warnings.Kaz Kylheku2017-01-131-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Warnings about undefined functions and variables are now deferred during loading, so forward references do not generate nuisance diagnostics. * eval.c (load_recursive_s): New symbol variable. (eval_defr_warn): New static function. (op_defvarl, op_defun): Purge any deferred warning about the given function or variable not being defined. (load): Rebind the sys:*load-recursive* special var to true around the load. After the load, dump deferred warnings if the prior binding of sys:*load-recursive* is false. Discard deferred warnings in the case of termination by a nonlocal control transfer. (do_expand): Treat unbound vars and functions as deferrable warnings, specially tagged for individual purging frkm the deferred list. (eval_init): Intern sys:*load-recursive* and initialize load_recursive_s variable. * eval.h (load_recursive_s): Declared. * parse.c (repl_warning): Accept variable arguments. Check whether we are loading and if so, defer deferrable (repl): Adjustment for altered signature of repl_warning. warnings. * txr.c (txr_main): dump deferred warnings after evaluating Lisp stream. * unwind.c (deferred_warnings): New static variable. (uw_throw): When a deferrable warning is caught, suppress the usual message and add it to the deferred_warnings list. (uw_defer_warning, uw_dump_deferred_warnings, uw_dump_deferred_warnings, uw_purge_deferred_warnings): New functions. (uw_late_init): gc-protect deferred_warnings. * unwind.h (uw_defer_warning, uw_dump_deferred_warnings, uw_dump_deferred_warnings, uw_purge_deferred_warnings): New functions declared.
* Fix some C style casts to use casting macros.Kaz Kylheku2016-12-071-1/+1
| | | | | | | | | | | | | | | | | | | | This is uncovered by compiling with g++ using -Wold-style-cast. * mpi/mpi.c (mp_get_intptr): Use convert macro. Also in one of the rules producing REGCHAR. * parser.l (num_esc): Likewise. * struct.c (static_slot_set, static_slot_ens_rec, get_equal_method): Use coerce macro for int to pointer conversion. * sysif.c (setgroups_wrap): Use convert macro. * termios.c (termios_unpack, termios_pack): Likewise. * txr.c (sysroot_init): Likewise.
* Expose compat option value as sys:compat variable.Kaz Kylheku2016-11-291-0/+2
| | | | | | | * txr.c (compat): Update sys:compat variable with actual value. (txr_main): Register sys:compat variable with default zero value.
* Revive -b option for binding Lisp variables.Kaz Kylheku2016-11-201-3/+21
| | | | | | | | * txr.c (txr_main): Implement -b option that takes an argument. Ensure that -b produces an error if clumped with other options. * txr.1: Documented -b var=val.
* Switch to user package before entering repl.Kaz Kylheku2016-11-141-0/+1
| | | | | | * txr.c (txr_main): The file loaded by the -i command line argument could manipulate *package*. Let's reset *package* to the user package before running the REPL.
* Synchronize license comments with LICENSE.Kaz Kylheku2016-10-011-16/+17
| | | | | | | | | | | | | | | | | | | | * 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, ftw.c, ftw.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/awk.tl, share/txr/stdlib/build.tl, share/txr/stdlib/cadr.tl, share/txr/stdlib/conv.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/socket.tl, share/txr/stdlib/struct.tl, share/txr/stdlib/termios.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, socket.c, socket.h, stream.c, stream.h, struct.c, struct.h, sysif.c, sysif.h, syslog.c, syslog.h, termios.c, termios.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Revert to verbatim 2-Clause BSD.
* Overhaul of self-load-path mechanism.Kaz Kylheku2016-09-261-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The self-load-path symbol macro is as of now deprecated. It simply expands to *load-path*. *load-path* is a new special variable which is dynamically bound to the path of a file being loaded. * eval.c (self_load_path_s): Global variable renamed to load_path_s. (sys_load): Bind *load-path* around processing of loaded file. (me_load): Expand (load x) simply to (sys:load x *load-path*). (set_get_symacro): Function removed. (reg_symacro): New static function. (eval_init): Initialize renamed load_path_s with interned symbol having the name *load-path*. Register the *load-path* special variable. Set up the sel-load-path symbol macro aliasing for *load-path*. * eval.h (self_load_path_s): Declaration renamed. * match.c (v_load): Bind *load-path* around loading or inclusion. * parser.c (load_rcfile): Bind *load-path* around loading of .txr_profile file. * txr.c (txr_main): Bind *load-path* instead of self-load-path symbol macro. * txr.1: Updated documentation for @(load) directive and load macro. Replaced documentation of self-load-path with *load-path*.
* Change misleading missing license diagnostic.Kaz Kylheku2016-09-261-3/+3
| | | | | | | * txr.c (license): Do not say that the TXR installation might be unlicensed; there is no such licensing condition that the license must be present at run-time. Just state the fact of being unable to display it.
* Bugfix: -Dvar=val not seen in some Lisp code.Kaz Kylheku2016-09-231-0/+5
| | | | | | | | | | | | | | | | | | | TXR Lisp files run from the command line do not see -Dvar=val bindings, whereas -p expressions do. The REPL sees the bindings, but not code loaded from it using (load "file.tl") because they are lexical. Let's keep these bindings as local lexicals for -p and -e forms, but install them as global lexicals for the other situations. * parser.c (repl): Get rid of the local repl_env made from the bindings that are passed in. Instead, before starting the REPL, loop through the bindings and install them as global lexicals with reg_varl. * txr.c (txr_main): Before processing a Lisp file, install the bindings as global lexicals with reg_varl.
* Address -c not working with --lisp.Kaz Kylheku2016-09-011-0/+6
| | | | | | | | | | | * txr.c (txr_main): the --lisp option causes the parse stream to be processed as Lisp, which is fine if it is a file stream. If it is a byte string input stream created by the -c option, it won't work due to missing character operations on the stream, resulting in a strange error message and termination. That issue isn't being fixed here; just providing a more meaningful error message when --lisp is combined with -c.
* Preparations for bundling Cygwin library.Kaz Kylheku2016-06-271-11/+25
| | | | | | | | | | * LICENSE-CYG: New file. * METALICENSE: Include a note about the use of Cygwin in accordance with LGPL. * txr.c (license): Use glob to iterate over all files in the txr share directory which match the LICENSE* pattern.
* New --free-all option for freeing memory on exit.Kaz Kylheku2016-06-071-3/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Although we are garbage-collected, being able to clean up on shutdown is nevertheless useful for uncovering leaks. Leaks can occur, for instance, due to neglect to free out-of-heap satellite data from objects that are reclaimed by gc. This feature is long overdue. * arith.c, arith.h (arith_free_all): New function. * gc.c, gc.h (gc_free_all): New function. * lib.c (init): Remove program name parameter and redundant initialization of progname globl variable. * lib.h (progname): Superfluous declaration removed. This is already declared in txr.h. (init): Declaration updated. * regex.c (char_set_destroy): Do not check the static allocation flag here; just destroy the object. Do check for a null pointer, though. (char_set_cobj_destroy): This cobj destructor now checks the static flag of the char set object and avoids freeing it. Thus our char set singletons are left alone by gc, but our global freeing function takes care of them. (wide_cs): New static variable moved out of wide_display_char_p to static scope. (regex_free_all): New function. * regex.h (regex_free_all): Declared. * txr.c (progname): const qualifier and initializer removed. (main): Ensure progname is always dynamically allocated, even in the argv[0] == 0 case. Do not pass progname to init; it doesn't take that argument any more. (free_all): New static function. (txr_main): Implement --free-all option. * txr.h (progname): Declaration updated.
* The stdlib variable gets a trailing slash.Kaz Kylheku2016-06-051-1/+9
| | | | | | | | | | | | | | | | | | | * txr.c (sysroot_init): Add slash to stdlib_path. (sysroot_compat_fixup): Replace user-visible stdlib variable with a path that doesn't have a slash, if compatibility is 143 or lower. (compat): Call sysroot_compat_fixup. * lisplib.c (place_set_entries, ver_set_entries, ifa_set_entries, txr_case_set_entries, with_resources_set_entries, path_test_set_entries, struct_set_entries, with_stream_set_entries, hash_set_entries, except_set_entries, type_set_entries, yield_set_entries, sock_set_entries, termios_set_entries): Remove slash from format string since the directory includes it. * txr.1: Added note under stdlib about the slash, and also an entry COMPATIBILITY.
* Stand-alone application support.Kaz Kylheku2016-05-251-18/+43
| | | | | | | | | | | | | | | | | | | * txr.c (sysroot_init): Don't print "unable to calculate sysroot" error message in the fallback case, and use the absolute path of the executable directory as the sysroot in this case. (txr_main): Define static area prefixed by @(txr): header. If a string is present in this data area then process it as an argument. Treat the *args* variable carefully. If we use the stored string as the argument, save the args in orig_args variable, then later bind *args* to that. In the -e, -p and related options processing, we bind *args* to the original list so args are available to the expression being evaluated. If the expression mutates *args* then we keep the mutated args whether or not we are processing the stored string. * txr.1: Documented in new sction, STAND-ALONE APPLICATION SUPPORT.
* New variable: txr-path.Kaz Kylheku2016-05-251-0/+7
| | | | | | | * txr.c (dirname): New static function. (sysroot_init): Register txr-path variable. * txr.1: documented txr-path.
* Bugfix: strange diagostic for -B-c.Kaz Kylheku2016-05-231-2/+7
| | | | | | * txr.c (txr_main): Diagnose unrecognized long option in if/else statement that handles long options, rather than clumsily in switch for non-clumping options.
* Few more drop_privilege calls in txr_main.Kaz Kylheku2016-05-231-0/+2
| | | | | | * txr.c (txr_main): Drop setuid privilege as soon as we know we are just going to exit, before producing any diagnostic output, like in existing cases.
* Help text upkeep.Kaz Kylheku2016-05-181-0/+7
| | | | | * txr.c (help): Note the existence of --args and --eargs, without giving a full description.
* New feature: self-load-path symbol macro.Kaz Kylheku2016-05-181-0/+2
| | | | | | | | | | | | | | | | | | | | | * eval.c (self_load_path_s): New symbol variable. (sys_load): Save, set-up and restore self-load-path around load. (set_get_symacro): New function. (eval_init): Register load function using sys_load_s instead of redundant intern. * eval.h (set_get_symacro): Declared. * match.c (v_load): Save, set-up and restore self-load-path macro. * parser.c (load_rcfile): Likewise. * txr.c (txr_main: Set up self-load-path when opening file. * txr.1: Documented self-load-path.
* *args*, *args-full* and self-path in listener.Kaz Kylheku2016-05-071-8/+10
| | | | | | | * txr.c (txr_main): Register *args-full* variable before first branch to repl. In repl section, register or re-register *args* to any remaining args, and self-path to the string "listener".
* Copyright in --help text.Kaz Kylheku2016-05-051-1/+1
| | | | | txr.c (help): 2015 was so last year. Let's make it a range from 2009 to current.
* Condense --help text.Reini Urban2016-05-051-1/+0
| | | | | txr.c (help): Remove blank line between name and copyright line.
* Typo in --help.Reini Urban2016-05-051-1/+1
| | | | txr.c (help): "sare" -> "are".
* New --reexec option.Kaz Kylheku2016-05-051-0/+8
| | | | | | | | | | | | | | | | | This helps with setuid hash bang scripting on Mac OS, and other plaforms where the interpreter executed out of a hash bang script runs with orinary privilege, even if marked setuid. * sysif.c (exec_wrap): Static function turns extern. * sysif.h (exec-wrap): Declared. * txr.1: Documented --reexec. Added notes about setuid under Hash Bang Support. * txr.c (help): List --reexec option. (txr_main): Implement --reexec option.
* Fix treatment of "false" in out-of-memory handler.Kaz Kylheku2016-05-041-1/+2
| | | | | | * txr.c (oom_realloc_handler): When terminating, only print the word false if the print-bindings option -B is in effect. Also, print it to standard output, not standard error.
* Calculate sysroot even if executable is renamed.Kaz Kylheku2016-05-041-1/+17
| | | | | | | | | | | If txr is renamed to something else in the same installation directory, we can still calculate the sysroot. * txr.c (substitute_basename): New function. (sysroot_init): Make one more attempt to calculate the sysroot by substituting the actual base name of the program into the compile-time relative path, and using that path agains the full path name.
* Consolidate sysroot calculation.Kaz Kylheku2016-05-041-16/+19
| | | | | | | | | | | | * txr.c (sysroot_path): New static variable. (progpath): Variable renamed to prog_path. (sysroot_helper): Function removed. (maybe_sysroot): New function. (sysroot): Function now just catenates previously calculated sysroot path onto target without. (sysroot_init): Follow rename of progpath to prog_path. GC-protect sysroot_path. Calculate sysroot path; if not able, emit warning message and use empty string.
* Implement setgid script support.Kaz Kylheku2016-05-021-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | TXR now notices that it's running setgid, and implements setgid logic for scripts. * sysif.c (orig_egid, real_gid, is_setgid): New static variables. (repress_privilege): Treat real and effective group ID similarly to user ID. Save them in global variables, and set the is_setgid flag. (drop_privilege): Drop setgid privilege similarly to setuid. Operate selectively: if neither setuid nor setgid is in effect, do nothing, but if just one is in effect, don't do anything for the other. (simulate_setuid): Function renamed to simulate_setuid_setgid. A small change is made here: if the fstat fails, just drop privilege, don't abort. Implement setgid operation independently of setuid. The is_setgid and is_setuid flags are manipulated here now to get the drop_privileges function to selectively drop setuid if we are running a script which is only segid, or drop setgid if we are running a setuid only script. * sysif.h (simulate_setuid): Declaration name change to simulate_setuid_setgid. * txr.c (txr_main): Follow rename of simulate_setuid. * txr.1: SETUID OPERATION section changed to SETUID/SETGID operation, and setgid description worked into the text.
* Close source files after parsing.Kaz Kylheku2016-04-151-0/+4
| | | | | | | | | | | | | * eval.c (sys_load): close stream in all cases. * match.c (v_load): Likewise. * parser.c (load_rcfile): Close stream in unwind block, if open. * txr.c (txr_main): Close stream after parsing in all cases. If stream is std_input, or a string stream, close_stream does nothing.
* Adding --eargs mechanism.Kaz Kylheku2016-02-021-1/+22
| | | | | | * txr.c (txr_main): Implement --eargs. * txr.1: Documented.
* Support setuid operation.Kaz Kylheku2016-01-231-1/+28
| | | | | | | | | | | | | | | | | | | | | * sysif.c (orig_euid, real_uid, repress_called, is_setuid): New static variables. (repress_privilege, drop_privilage, simulate_setuid): New functions. (RC_MAGIC): New preprocessor symbol. * sysif.c (repress_privilege, drop_privilage, simulate_setuid): Declared. * txr.c (txr_main): Call repress_privilege to check and remember whether we are in setuid mode, and temporarily drop the effective uid to the real one. (txr_main): Permanently drop privileges in all cases except script execution. In script execution cases, go through simulate_setuid to either set or preserve the effective user ID, or else drop privs. * txr.1: Documented setuid operation in new section.