1
0
Fork 0
forked from fun/fun

Added --help/-h and --version/-V. So, this is version 0.2.0 of Fun! :)

This commit is contained in:
Johannes Findeisen 2025-09-14 21:59:26 +02:00
commit b69c8305f6
3 changed files with 74 additions and 23 deletions

View file

@ -6,6 +6,10 @@
#include <string.h>
#include <stdlib.h>
#ifndef FUN_VERSION
#define FUN_VERSION "0.0.0-dev"
#endif
static int is_blank_line(const char *s) {
for (const char *p = s; *p; ++p) {
if (*p != ' ' && *p != '\t' && *p != '\r' && *p != '\n') return 0;
@ -13,10 +17,33 @@ static int is_blank_line(const char *s) {
return 1;
}
static void print_usage(const char *prog) {
printf("Fun %s\n", FUN_VERSION);
printf("Usage:\n");
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");
}
int main(int argc, char **argv) {
VM vm;
vm_init(&vm);
// CLI flags
if (argc > 1) {
const char *arg = argv[1];
if (strcmp(arg, "--help") == 0 || strcmp(arg, "-h") == 0) {
print_usage(argv[0]);
return 0;
}
if (strcmp(arg, "--version") == 0 || strcmp(arg, "-V") == 0) {
printf("Fun %s\n", FUN_VERSION);
return 0;
}
}
// If a script path is provided, parse and run it
if (argc > 1) {
const char *path = argv[1];