aboutsummaryrefslogtreecommitdiff
path: root/zetsubou/main.c
blob: e05dd3a437ad5f253ff5d15e2f3521cb4218ecd2 (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
/*
 *  main.c
 *  Zetsubou
 *
 *  Created by Alex Marshall on 09/03/17.
 *  Copyright 2009 __MyCompanyName__. All rights reserved.
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "types.h"
#include "tpl.h"

int main(int argc, char *argv[])
{
	printf("Zetsubou v0.1. Written by SquidMan (Alex Marshall)\nRGB5A3 code was contributed by booto.\n\n");
	if(argc != 2) {
		printf("Invalid usage. Usage:\n\t%s <file.tpl>\n", argv[0]);
		exit(1);
	}
	FILE* fp = fopen(argv[1], "rb");
	if(fp == NULL) {
		printf("Error opening %s.\n", argv[1]);
		exit(1);
	}
	char *basename = (char*)calloc(strlen(argv[1]) + 1, 1);
	int arg1strlen = strlen(argv[1]);
	int i;
	for(i = 0; (i < arg1strlen) && (argv[1][i] != '.'); i++) basename[i] = argv[1][i];
	fseek(fp, 0, SEEK_END);
	u32 tplsize = ftell(fp);
	u8* tplbuf  = (u8*)malloc(tplsize);
	fseek(fp, 0, SEEK_SET);
	fread(tplbuf, tplsize, 1, fp);
	fclose(fp);
	int ret = TPL_ConvertToBMP(tplbuf, tplsize, basename);
	if(ret < 0) {
		printf("Error converting to BMP.\n");
		exit(1);
	}
	return 0;
}