Mercurial > hg > quicktun
diff src/common.c @ 38:d9f5caa13898
Added support for NetBSD, added command line parsing to provide configuration options
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Mon, 06 May 2013 22:53:20 +0200 |
parents | 1fe62a94c28a |
children | 47a34fe75c57 |
line wrap: on
line diff
--- a/src/common.c Mon May 06 21:28:45 2013 +0200 +++ b/src/common.c Mon May 06 22:53:20 2013 +0200 @@ -84,6 +84,8 @@ char* (*getconf)(const char*) = getenv; int debug = 0; +static int gargc = 0; +static char** gargv = NULL; int errorexit(const char* text) { fprintf(stderr, "%s\n", text); @@ -95,7 +97,7 @@ } void print_header() { - fprintf(stderr, "UCIS QuickTun (c) 2010 Ivo Smits <Ivo@UCIS.nl>\n"); + fprintf(stderr, "UCIS QuickTun "QT_VERSION" (c) 2010-2013 Ivo Smits <Ivo@UCIS.nl>\n"); fprintf(stderr, "More information: http://wiki.ucis.nl/QuickTun\n"); } @@ -312,5 +314,34 @@ } return 0; } + +char* getconfcmdargs(const char* name) { + int i; + for (i = 1; i < gargc - 2; i++) { + if (strcmp(gargv[i], "-c")) continue; + if (strcmp(gargv[i + 1], name)) continue; + return gargv[i + 2]; + } + return NULL; +} + +int qtprocessargs(int argc, char** argv) { + int i; + for (i = 1; i < argc; i++) { + char* a = argv[i]; + if (!strcmp(a, "-h") || !strcmp(a, "--help")) { + return errorexit("Please read the documentation at http://wiki.ucis.nl/QuickTun"); + } else if (!strcmp(a, "-v") || !strcmp(a, "--version")) { + return errorexit("UCIS QuickTun "QT_VERSION); + } else if (!strcmp(a, "-c")) { + gargc = argc; + gargv = argv; + getconf = getconfcmdargs; + i += 2; + } else { + return errorexit("Unexpected command line argument"); + } + } +} #endif