summaryrefslogtreecommitdiffstats
path: root/src/pieces.c
blob: 9ce234cadd5b9558782215ca2c5cf5bfd7624e14 (plain)
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
69
70
71
72
73
74
75
76
77
78
/*
 * Copyright (C) 2007
 *       pancake <pancake@youterm.com>
 *
 * 0xFFFF 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 2 of the License, or
 * (at your option) any later version.
 *
 * 0xFFFF 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 0xFFFF; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

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

int pcs_n = 0;
struct piece_t pcs[10];

int add_piece(char *piece)
{
	int i,ok = 0;
	char *file;

	if (pcs_n==9) {
		fprintf(stderr, "Oops...cannot add more pieces. no sense operation!\n");
		return 0;
	}

	file = strchr(piece, '%');
	if (file) {
		file[0]='\0';
		file = file + 1;
		for(i=0;pieces[i];i++)
			if (!strcmp(pieces[i], piece))
				ok = 1;
		if (!ok) {
			printf("Invalid piece name.\n");
			printf("Pieces: ");
			for(i=0;pieces[i];i++)
				printf("%s ", pieces[i]);
			printf("\n");
			exit(1);
		}

		pcs[pcs_n].name = strdup(file);
		pcs[pcs_n].type = strdup(piece);
		pcs[pcs_n].vers = NULL; // TODO version string not yet supported
	} else {
		/*/ autodetect piece type */
		pcs[pcs_n].type = fpid_file(piece);
		if (pcs[pcs_n].type == NULL) {
			printf("Use -p [piece]:[file]\n");
			printf("Pieces: ");
			for(i=0;pieces[i];i++)
				printf("%s ", pieces[i]);
			printf("\n");
			exit(1);
		} else {
			pcs[pcs_n].name = strdup(piece);
			pcs[pcs_n].type = strdup(pcs[pcs_n].type);
			pcs[pcs_n].vers = NULL;
		}
	}

	pcs_n++;

	return 1;
}