From 69b9b87dd4592b12d322d4363698d3ca7f0493f1 Mon Sep 17 00:00:00 2001 From: hanez Date: Thu, 19 Mar 2026 23:39:21 +0100 Subject: [PATCH] Added manpages for fun and funstx and some small code changes. (0.39.3) --- CMakeLists.txt | 10 ++++- examples/include_local.fun | 14 +++---- man/fun.1 | 74 ++++++++++++++++++++++++++++++++++++ man/funstx.1 | 77 ++++++++++++++++++++++++++++++++++++++ src/funstx.c | 26 ++++++++++--- 5 files changed, 188 insertions(+), 13 deletions(-) create mode 100644 man/fun.1 create mode 100644 man/funstx.1 diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e2a6fe..4de1877 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.10) -project(fun VERSION 0.39.2 LANGUAGES C) +project(fun VERSION 0.39.3 LANGUAGES C) set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD_REQUIRED ON) @@ -433,3 +433,11 @@ endif() install(FILES README.md LICENSE DESTINATION /usr/share/doc/fun ) + +# - Manpages +# Install section 1 manpages for the CLI tools +install(FILES + man/fun.1 + man/funstx.1 + DESTINATION /usr/share/man/man1 +) diff --git a/examples/include_local.fun b/examples/include_local.fun index be33c83..deee294 100755 --- a/examples/include_local.fun +++ b/examples/include_local.fun @@ -1,13 +1,13 @@ #!/usr/bin/env fun /* - * This file is part of the Fun programming language. - * https://fun-lang.xyz/ - * - * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the Apache-2.0 license. - * https://opensource.org/license/apache-2-0 - */ + * This file is part of the Fun programming language. + * https://fun-lang.xyz/ + * + * Copyright 2025 Johannes Findeisen + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 + */ // To test this you need to go to ./examples/ and test includes running ../build/fun include_local.fun // Local includes are always relative from the $PWD using "" and system includes are located at /usr/lib/fun using <>. diff --git a/man/fun.1 b/man/fun.1 new file mode 100644 index 0000000..b06063e --- /dev/null +++ b/man/fun.1 @@ -0,0 +1,74 @@ +.TH fun 1 "March 2026" "fun" "User Commands" +.SH NAME +fun \- Fun language runner and REPL +.SH SYNOPSIS +.B fun +\fR[\fIoptions\fR] [\fIscript.fun\fR] [\fB--\fR \fIargs...\fR] +.SH DESCRIPTION +\fBfun\fR runs programs written for the Fun virtual machine. When invoked +with a script path, it parses, compiles and executes the script. If no +script is provided and the binary was built with REPL support, \fBfun\fR +starts an interactive Read\-Eval\-Print Loop. +.SH OPTIONS +.TP +.B -i , --repl +Start the interactive REPL explicitly (if built with REPL support). +.TP +.B -v , --version +Print version and exit. +.TP +.B -h , --help +Show usage information and exit. +.PP +Note: Available options may vary by build configuration. Check +\fBfun --help\fR for your binary. +.SH ENVIRONMENT +.TP +.B FUN_LIB_DIR +Top\-priority search path for included Fun modules. Set this when running +from the source tree to point to \fI./lib\fR. +.TP +.B DEFAULT_LIB_DIR +Compiled\-in default library directory searched after \fBFUN_LIB_DIR\fR. +.SH EXIT STATUS +.TP +.B 0 +Success. +.TP +.B non\-zero +Error during parse, compile, or runtime. +.SH EXAMPLES +.TP +Run an installed example: +.nf + fun /usr/share/fun/examples/hello.fun +.fi +.TP +Run from a build tree without installing (point stdlib to repo): +.nf + FUN_LIB_DIR=./lib /path/to/build_dir/fun examples/hello.fun +.fi +.TP +Pass arguments to a script (after -- they are forwarded): +.nf + fun myscript.fun -- arg1 arg2 +.fi +.SH FILES +.TP +Binary (default install) +\fI/usr/bin/fun\fR +.TP +Standard library (default install) +\fI/usr/share/fun/lib\fR +.TP +Examples (optional, default install) +\fI/usr/share/fun/examples\fR +.SH SEE ALSO +\fBfunstx\fR(1) +.br +Project documentation: \fIdocs/fun.md\fR, \fIdocs/cli.md\fR, \fIdocs/includes.md\fR +.SH AUTHORS +The Fun project authors. +.SH COPYRIGHT +\(co The Fun authors. Licensed under the project license; see the +\fILICENSE\fR file distributed with this source. diff --git a/man/funstx.1 b/man/funstx.1 new file mode 100644 index 0000000..7df9fed --- /dev/null +++ b/man/funstx.1 @@ -0,0 +1,77 @@ +.TH funstx 1 "March 2026" "fun" "User Commands" +.SH NAME +funstx \- Fun syntax checker and fixer +.SH SYNOPSIS +.B funstx +\fR[\fB--fix\fR] \fIfile1.fun\fR [\fIfile2.fun\fR ...] +.SH DESCRIPTION +\fBfunstx\fR parses one or more \fI.fun\fR source files to verify syntax +without executing them. With \fB--fix\fR, it attempts conservative, +idempotent edits to align files with parser expectations and then +re\-checks before writing changes. +.SH OPTIONS +.TP +.B --fix +Attempt safe automatic corrections before re\-checking. Only writes a file +if the fixed version parses successfully. +.SH OUTPUT +.TP +On success +Prints "\fIpath/to/file.fun\fR: OK". +.TP +On failure +Prints "\fIpath/to/file.fun\fR:line:col: syntax error: ". +.SH EXIT STATUS +.TP +.B 0 +All provided files parsed successfully. +.TP +.B 1 +At least one file failed to parse (after optional fixing). +.TP +.B 2 +Incorrect usage (e.g., no files provided). +.SH AUTO\-FIX RULES +The fixer applies a small set of conservative transformations: +.IP \(bu 2 +Normalize line endings: CRLF/CR \(-> LF. +.IP \(bu 2 +Convert leading tabs to spaces; normalize indentation to multiples of two spaces. +.IP \(bu 2 +Trim trailing spaces. +.IP \(bu 2 +Ensure the file ends with a single newline. +.IP \(bu 2 +Normalize type aliases: \fIsint8|sint16|sint32|sint64\fR \(-> \fIint8|int16|int32|int64\fR (word\-boundary aware). +.PP +Structural issues that require semantic changes are not auto\-fixed; if +parsing still fails, the original file is left unchanged and an error is +reported. +.SH EXAMPLES +.TP +Check a single file +.nf + funstx examples/arrays.fun +.fi +.TP +Check and auto\-fix a file +.nf + funstx --fix examples/arrays.fun +.fi +.TP +Bulk check and auto\-fix all examples +.nf + find examples -type f -name '*.fun' -print0 | xargs -0 -n 50 funstx --fix +.fi +.SH BUILD AND INSTALL +Built as CMake target \fBfunstx\fR and installed alongside \fBfun\fR into +\fI/usr/bin\fR by default. +.SH SEE ALSO +\fBfun\fR(1) +.br +Project documentation: \fIdocs/funstx.md\fR +.SH AUTHORS +The Fun project authors. +.SH COPYRIGHT +\(co The Fun authors. Licensed under the project license; see the +\fILICENSE\fR file distributed with this source. diff --git a/src/funstx.c b/src/funstx.c index aedef9b..8dc8c13 100644 --- a/src/funstx.c +++ b/src/funstx.c @@ -16,7 +16,7 @@ #include "parser.h" static void usage(const char *prog) { - fprintf(stderr, "Usage: %s [--fix] [file2.fun ...]\n", prog); + fprintf(stderr, "Usage: %s [--fix] [--quiet] [file2.fun ...]\n", prog); } /* Read entire file into a malloc'd buffer terminated with '\0'. Returns 1 on success. */ @@ -244,16 +244,32 @@ static char *apply_fixes(const char *src, size_t len, size_t *out_len) { int main(int argc, char **argv) { int do_fix = 0; + int quiet = 0; int first_file_arg = 1; + + // Parse leading flags for (int i = 1; i < argc; i++) { if (strcmp(argv[i], "--fix") == 0) { do_fix = 1; first_file_arg++; - } else - break; + continue; + } + if (strcmp(argv[i], "--quiet") == 0) { + quiet = 1; + first_file_arg++; + continue; + } + // stop on first non-flag + if (argv[i][0] != '-') break; + // unknown flag -> usage error + if (strncmp(argv[i], "--", 2) == 0) { + usage(argv[0]); + return 2; + } + break; } - if (argc < 1 + (do_fix ? 1 : 0) + 1) { + if (first_file_arg >= argc) { usage(argv[0]); return 2; } @@ -328,7 +344,7 @@ int main(int argc, char **argv) { continue; // keep checking remaining files } - fprintf(stdout, "%s: OK\n", path); + if (!quiet) fprintf(stdout, "%s: OK\n", path); bytecode_free(bc); }