aboutsummaryrefslogtreecommitdiff
path: root/tasm/src/main.c
blob: bb6a1ac8c294adbee241ee9ff2e12528dc5ab752 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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;
}