fex2bin.c 1.58 KB
Newer Older
Alejandro Mery's avatar
Alejandro Mery committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
 * Copyright (C) 2012  Alejandro Mery <amery@geeks.cl>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
Alejandro Mery's avatar
Alejandro Mery committed
17
#include "fex2bin.h"
Alejandro Mery's avatar
Alejandro Mery committed
18

19
20
21
22
23
24
25
#include <errno.h>
#include <stdio.h>
#include <string.h>

/**
 */
int main(int argc, char *argv[])
Alejandro Mery's avatar
Alejandro Mery committed
26
{
27
28
29
	int ret = -1;
	FILE *in = stdin, *out = stdout;
	const char *fn[] = {"stdin", "stdout"};
30
	struct script *script;
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

	if (argc>1) {
		if (strcmp(argv[1],"-") == 0)
			; /* we are using stdin anyway */
		else if ((fn[0] = argv[1]) &&
			 (in = fopen(fn[0], "r")) == NULL) {
			errf("%s: %s\n", fn[0], strerror(errno));
			goto usage;
		}

		if (argc>2) {
			fn[1] = argv[2];

			if ((out = fopen(fn[1], "w")) == NULL) {
				errf("%s: %s\n", fn[1], strerror(errno));
				goto usage;
			}
		}
	}
50
51
52
53
54
55
56

	if ((script = script_new()) == NULL) {
		errf("malloc: %s\n", strerror(errno));
		goto done;
	}

	script_delete(script);
57
58
59
60
61
62
63
64
	goto done;
usage:
	errf("Usage: %s [<script.fex> [<script.bin>]\n", argv[0]);

done:
	if (in != stdin) fclose(in);
	if (out != stdout) fclose(out);
	return ret;
Alejandro Mery's avatar
Alejandro Mery committed
65
}