diff --git a/torrent-stats.c b/torrent-stats.c index d25d706..20266cf 100644 --- a/torrent-stats.c +++ b/torrent-stats.c @@ -20,6 +20,8 @@ #include #include +#include + #include "configfile.h" #include "connection.h" #include "event.h" @@ -29,6 +31,14 @@ #include "sockaddr.h" #include "tcpsocket.h" +#define DEFAULT_CONFIG "torrent-stats.conf" + +static struct option opts[] = { + {"config", 1, 0, 'c'}, + {"help", 0, 0, 'h'}, + {0, 0, 0, 0} +}; + static int listen_cb(const char *parameter, void *privdata) { struct sockaddr_in addr; @@ -51,8 +61,37 @@ static int listen_cb(const char *parameter, void *privdata) int main(int argc, char *argv[]) { - if (config_parse("torrent-stats.conf") < 0) - return 1; + char *config = DEFAULT_CONFIG; + int code, arg = 0; + + do { + code = getopt_long(argc, argv, "c:h", opts, &arg); + + switch (code) { + case 'c': /* config */ + config = optarg; + break; + + case 'h': /* help */ + printf("Usage: torrent-stats [options]\n" + "Options: \n" + " --config -c configfile use this configfile\n" + " --help -h this help\n" + "\n"); + exit(0); + break; + + case '?': /* error */ + exit(1); + break; + + default: /* unknown / all options parsed */ + break; + } + } while (code != -1); + + if (config_parse(config) < 0) + exit(1); config_get_strings("global", "listen", listen_cb, ctcs_accept_handler); config_get_strings("global", "listen-http", listen_cb, httpd_accept_handler);