add cmdline options

This commit is contained in:
Olaf Rempel 2008-11-02 13:14:53 +01:00
parent 148b0babda
commit b29d08d43b

View File

@ -20,6 +20,8 @@
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#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);