From d96b8c7d12fc61ec609d6138627b9d6d18139a9a Mon Sep 17 00:00:00 2001 From: Kimplul Date: Sat, 28 Oct 2023 00:00:21 +0300 Subject: move to monorepo + Will probably have to make some changes to dir layout to make things make more sense --- tasm/src/main.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 tasm/src/main.c (limited to 'tasm/src/main.c') diff --git a/tasm/src/main.c b/tasm/src/main.c new file mode 100644 index 0000000..bb6a1ac --- /dev/null +++ b/tasm/src/main.c @@ -0,0 +1,68 @@ +#include +#include +#include +#include + +static const char *cmdline_usage = +"tasm trinary assembler usage:\n" +" tasm [-I ...] -o outfile infile\n" +" -h Show usage (this)\n" +" -I Add directory to include path\n" +" -o File to output to\n" +" infile Top file to assemble\n" +; + +static void usage() +{ + fprintf(stderr, cmdline_usage); +} + +int main(int argc, char *argv[]) +{ + const char *outfile = NULL; + int opt; + while ((opt = getopt(argc, argv, "hI:o:")) != -1) { + switch (opt) { + case 'I': + fprintf(stderr, "include paths not yet implemented\n"); + break; + + case 'o': + outfile = optarg; + break; + + case 'h': + usage(); + exit(EXIT_SUCCESS); + break; + + default: + usage(); + exit(EXIT_FAILURE); + break; + } + } + + if (!outfile) { + fprintf(stderr, "no output file\n"); + usage(); + exit(EXIT_FAILURE); + } + + if (optind >= argc) { + fprintf(stderr, "no input files\n"); + usage(); + exit(EXIT_FAILURE); + } + + if (optind != argc - 1) { + fprintf(stderr, "too many input files\n"); + usage(); + exit(EXIT_FAILURE); + } + + if (assemble(outfile, argv[optind])) + exit(EXIT_FAILURE); + + return EXIT_SUCCESS; +} -- cgit v1.3