From b68715dab6731f4f2a3a886fe317c380425cbd0f Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Wed, 5 Oct 2011 20:51:40 +1100 Subject: [PATCH] + aded few options to 'json2torrent' --- src/json2torrent.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/json2torrent.c b/src/json2torrent.c index c041c3b..a9da370 100644 --- a/src/json2torrent.c +++ b/src/json2torrent.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -82,6 +83,7 @@ int main(int argc, char **argv) { static unsigned char buf[BUF_SIZE]; + char opt = '\0'; size_t read = 0; /* FILE */ in = stdin; /* FILE */ out = stdout; @@ -100,6 +102,31 @@ main(int argc, char **argv) exit(EXIT_FAILURE); } + while ((opt = getopt(argc, argv, "hi:o:")) != -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; + default : + usage(EXIT_FAILURE); + break; + } + yajl_config(handle, yajl_allow_comments, 1); yajl_config(handle, yajl_dont_validate_strings, 1);