summaryrefslogtreecommitdiffstats
path: root/src/pieces.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pieces.c')
-rw-r--r--src/pieces.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/pieces.c b/src/pieces.c
new file mode 100644
index 0000000..9ce234c
--- /dev/null
+++ b/src/pieces.c
@@ -0,0 +1,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;
+}