diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-03-07 02:18:26 +0200 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-03-07 02:18:26 +0200 |
| commit | ae5fee63f160643a397d18e9e0658275606bc4d4 (patch) | |
| tree | f68af302374f9ae3c9dbb28dab5547036252d559 /src/main.c | |
| download | ek-ae5fee63f160643a397d18e9e0658275606bc4d4.tar.gz ek-ae5fee63f160643a397d18e9e0658275606bc4d4.zip | |
initial commit
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..93b9dfa --- /dev/null +++ b/src/main.c @@ -0,0 +1,57 @@ +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> + +#include <ct/ctpp.h> +#include <ct/debug.h> +#include <ct/imports.h> +#include <ct/compiler.h> + +static const char *cmdline_usage = +"C with traits compiler usage:\n" +" ct [-I <dir>...] [-D <var>...] infile...\n" +" -h Show usage (this)\n" +" -I <dir> Add directory to import path\n" +" -D <var> Add predefined variable\n" +" infile Top file to compile\n" +; + +static void usage() +{ + fprintf(stderr, cmdline_usage); +} + +int main(int argc, char *argv[]) +{ + int opt; + while ((opt = getopt(argc, argv, "hI:D:")) != -1) { + switch (opt) { + case 'I': + add_import_path(optarg); + break; + + case 'D': + add_predefined_variable(optarg); + break; + + case 'h': + usage(); + exit(EXIT_SUCCESS); + default: + usage(); + exit(EXIT_FAILURE); + } + } + + if (optind >= argc) { + error("no input files\n"); + exit(EXIT_FAILURE); + } + + for (int i = optind; i < argc; ++i) { + debug("starting compilation of '%s'\n", argv[i]); + compile(argv[i]); + } + + return 0; +} |
