diff --git a/CMakeLists.txt b/CMakeLists.txt index ba9fa29..55e2611 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.16) -project(fun VERSION 0.17.4 LANGUAGES C) +project(fun VERSION 0.17.6 LANGUAGES C) set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) @@ -86,12 +86,16 @@ if(Threads_FOUND) target_link_libraries(fun_core PUBLIC Threads::Threads) endif() -# Playground / interpreter (future /usr/bin/fun) +# Interpreter /usr/bin/fun +option(FUN_WITH_REPL "Enable interactive REPL in the fun CLI" OFF) add_executable(fun src/fun.c ) # Provide version string to the CLI target_compile_definitions(fun PRIVATE FUN_VERSION=\"${PROJECT_VERSION}\") +if(FUN_WITH_REPL) + target_compile_definitions(fun PRIVATE FUN_WITH_REPL=0) +endif() target_link_libraries(fun PRIVATE fun_core) # Internal test programs @@ -113,12 +117,14 @@ add_custom_target(build # Convenience targets: repl, run, threads-demo, ops, examples set(FUN_RUN_SCRIPT "" CACHE STRING "Script to run with the 'run' target, e.g. -DFUN_RUN_SCRIPT=examples/strings_test.fun") -add_custom_target(repl - COMMAND $ - DEPENDS fun - USES_TERMINAL - COMMENT "Run Fun REPL" -) +if(FUN_WITH_REPL) + add_custom_target(repl + COMMAND $ + DEPENDS fun + USES_TERMINAL + COMMENT "Run Fun REPL" + ) +endif() add_custom_target(run COMMAND $ ${FUN_RUN_SCRIPT} diff --git a/src/fun.c b/src/fun.c index fd23001..6437595 100644 --- a/src/fun.c +++ b/src/fun.c @@ -710,11 +710,19 @@ static int buffer_looks_incomplete(const char *buf) { static void print_usage(const char *prog) { printf("Fun %s\n", FUN_VERSION); printf("Usage:\n"); +#ifdef FUN_WITH_REPL printf(" %s [script.fun]\n", prog ? prog : "fun"); printf(" %s --help | -h\n", prog ? prog : "fun"); printf(" %s --version | -V\n", prog ? prog : "fun"); printf("\n"); printf("When no script is provided, a REPL starts. Submit an empty line to execute the buffer.\n"); +#else + printf(" %s \n", prog ? prog : "fun"); + printf(" %s --help | -h\n", prog ? prog : "fun"); + printf(" %s --version | -V\n", prog ? prog : "fun"); + printf("\n"); + printf("REPL is disabled in this build. Please provide a script file to run.\n"); +#endif } static void show_repl_help(void) { @@ -836,6 +844,15 @@ int main(int argc, char **argv) { } } +#ifndef FUN_WITH_REPL + // When REPL is disabled, require a script file argument (allow --help/--version above). + if (argc <= 1) { + fprintf(stderr, "Error: REPL is disabled. Please provide a script to run.\n"); + print_usage(argv[0]); + return 2; + } +#endif + // If a script path is provided, parse and run it if (argc > 1) { const char *path = argv[1];