diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-05-12 07:54:52 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-05-12 07:54:52 -0700 |
commit | fca75faa1a6c3737b038d5fee6ce714a1f554280 (patch) | |
tree | fd36c5c47a0e22e4cd8fe723f7643cd9e919deb0 /txr.c | |
parent | 1162a735b61c1c5086fb6055471ee35cc8ed62a4 (diff) | |
download | txr-fca75faa1a6c3737b038d5fee6ce714a1f554280.tar.gz txr-fca75faa1a6c3737b038d5fee6ce714a1f554280.tar.bz2 txr-fca75faa1a6c3737b038d5fee6ce714a1f554280.zip |
New options: --in-package and --compile.
* txr.c (help): Mention new options.
(do_compile_opt, do_in_package_opt): New static functions.
(txr_main): Implement options.
* Makefile (COMPILE_TL): Use the options instead of -e.
* txr.1: Document.
Diffstat (limited to 'txr.c')
-rw-r--r-- | txr.c | 53 |
1 files changed, 53 insertions, 0 deletions
@@ -165,6 +165,8 @@ static void help(void) "--backtrace Enable backtraces.\n" "--noninteractive Synonym for -n.\n" "--compat=N Synonym for -C N.\n" +"--in-package=name Switch to specified package\n" +"--compile=src[:target] Compile a file.\n" "--gc-delta=N Invoke garbage collection when malloc activity\n" " increments by N megabytes since last collection.\n" "--args... Allows multiple arguments to be encoded as a single\n" @@ -434,6 +436,36 @@ static void requires_arg(val opt) prog_string, opt, nao); } +static void do_compile_opt(val arg) +{ + val compile_update_file = intern(lit("compile-update-file"), user_package); + val col_pos = search_str(arg, lit(":"), nil, nil); + val source = arg; + val target = nil; + + if (col_pos) { + target = sub_str(source, succ(col_pos), t); + source = sub_str(source, zero, col_pos); + } + + funcall2(compile_update_file, source, target); +} + +static int do_in_package_opt(val opt, val arg) +{ + val pkg_binding = lookup_var(nil, package_s); + val package = find_package(arg); + + if (!package) { + format(std_error, lit("~a: option --~a: ~a package not found\n"), + prog_string, opt, arg, nao); + return 0; + } + + rplacd(pkg_binding, package); + return 1; +} + static int do_fixnum_opt(int (*opt_func)(val), val opt, val arg) { if (arg) { @@ -716,6 +748,27 @@ int txr_main(int argc, char **argv) continue; } + if (equal(opt, lit("compile"))) { + if (!org) { + requires_arg(opt); + return EXIT_FAILURE; + } + reg_var(args_s, or2(orig_args, arg_list)); + do_compile_opt(org); + evaled = t; + continue; + } + + if (equal(opt, lit("in-package"))) { + if (!org) { + requires_arg(opt); + return EXIT_FAILURE; + } + if (!do_in_package_opt(opt, org)) + return EXIT_FAILURE; + continue; + } + /* Long opts with no arguments */ if (0) noarg: { drop_privilege(); |