aboutsummaryrefslogtreecommitdiff
path: root/tasm/src/main.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2023-10-28 00:00:21 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2023-10-28 00:00:21 +0300
commitd96b8c7d12fc61ec609d6138627b9d6d18139a9a (patch)
tree82bc9a4c2b22de6c021097fb79a57b6d7756a127 /tasm/src/main.c
downloadtri-d96b8c7d12fc61ec609d6138627b9d6d18139a9a.tar.gz
tri-d96b8c7d12fc61ec609d6138627b9d6d18139a9a.zip
move to monorepo
+ Will probably have to make some changes to dir layout to make things make more sense
Diffstat (limited to 'tasm/src/main.c')
-rw-r--r--tasm/src/main.c68
1 files changed, 68 insertions, 0 deletions
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 <tasm/assembler.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+
+static const char *cmdline_usage =
+"tasm trinary assembler usage:\n"
+" tasm [-I <dir>...] -o outfile infile\n"
+" -h Show usage (this)\n"
+" -I <dir> Add directory to include path\n"
+" -o <outfile> 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;
+}