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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
/*
* btcheck.c
*
* $Id: btcheck.c 24 2012-02-19 22:16:12Z diraison $
*
* This file is part of the btcheck project (c) 2008-2009 distributed
* under the GNU GPLv3 license and created by Jean Diraison
* <jean.diraison@ac-rennes.fr>
*
* URL: http://sourceforge.net/projects/btcheck/
*
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "btree.h"
#include "bdecode.h"
#include "info.h"
#include "bencode.h"
#include "check.h"
#include "usage.h"
int Verbose;
int SkipCheck;
int ZeroFill;
int PrintInfo;
int PrintFileList;
static void fprint_btree(FILE *file, int c)
{
fprintf(file, "%c", c);
}
int main(int argc, char *argv[])
{
extern char *optarg;
extern int optind, opterr, optopt;
btree_t *torrentbtree;
FILE *torrent;
char *filename = NULL;
int c, failure = 0;
while ((c = getopt(argc, argv, "hVvqnizl")) != EOF) {
switch(c) {
case 'h': usage(argv[0], EXIT_SUCCESS);
case 'V': version();
case 'v': Verbose++;
break;
case 'q': Verbose--;
break;
case 'i': PrintInfo = 1;
break;
case 'z': ZeroFill = 1;
break;
case 'l': PrintFileList = 1;
case 'n': SkipCheck = 1;
break;
default: usage(argv[0], EXIT_FAILURE);
}
}
if (argc == (optind + 1)) {
filename = argv[optind];
} else {
usage(argv[0], EXIT_FAILURE);
}
torrent = fopen(filename, "rb");
if (torrent == NULL) {
perror("Can't open torrent file.");
exit(EXIT_FAILURE);
}
torrentbtree = bdecode(torrent);
// dump_btree(torrentbtree, 0);
if (PrintInfo)
print_info(torrentbtree);
// bencode(torrentbtree, (void *)fprint_btree, (void *)stdout);
if (PrintFileList)
print_files_list(torrentbtree);
if (SkipCheck == 0)
failure = check(torrentbtree);
free_btree(torrentbtree);
fclose(torrent);
exit(failure == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
|