From ef8c80b7194751ccf624a2abf7e1b74c0165718c Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Wed, 5 Oct 2011 20:35:04 +1100 Subject: [PATCH] + added few options to 'torrent2json' --- src/torrent2json.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/torrent2json.c b/src/torrent2json.c index 6af785c..d3905b0 100644 --- a/src/torrent2json.c +++ b/src/torrent2json.c @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -160,6 +161,7 @@ main(int argc, char **argv) void (*handler)(int) = NULL; int c = '\0'; const unsigned char *buf = NULL; + char opt = '\0'; size_t len = 0; /* FILE */ in = stdin; @@ -174,6 +176,34 @@ main(int argc, char **argv) yajl_gen_config(gen, yajl_gen_beautify, 1); yajl_gen_config(gen, yajl_gen_indent_string, "\t"); + while ((opt = getopt(argc, argv, "hi:o:c")) != -1) + switch (opt) + { + case 'h' : + usage(EXIT_SUCCESS); + break; + case 'i' : + if ((in = fopen(optarg, "r")) == NULL) + { + fprintf(stderr, "Can't open input file '%s'. Exiting.", optarg); + exit(EXIT_FAILURE); + } + break; + case 'o' : + if ((out = fopen(optarg, "w")) == NULL) + { + fprintf(stderr, "Can't open output file '%s'. Exiting.", optarg); + exit(EXIT_FAILURE); + } + break; + case 'c' : + yajl_gen_config(gen, yajl_gen_beautify, 0); + break; + default : + usage(EXIT_FAILURE); + break; + } + while ((c = fgetc(in)) != EOF) { handler = select_handler(c);