summaryrefslogtreecommitdiffstats
path: root/eurephiadm/eurephiadm.c
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2008-12-04 10:37:52 +0100
committerDavid Sommerseth <dazo@users.sourceforge.net>2008-12-04 10:37:52 +0100
commit6880a718670b2090bfcc5e82f2e9a9e7278ce9c9 (patch)
treeea0e87b009cb8fc6ef7aeb98d6561924b3ac46b8 /eurephiadm/eurephiadm.c
parented64bb902b148702a09b6a701ff6721b2cdfff61 (diff)
downloadeurephia-6880a718670b2090bfcc5e82f2e9a9e7278ce9c9.tar.gz
eurephia-6880a718670b2090bfcc5e82f2e9a9e7278ce9c9.tar.xz
eurephia-6880a718670b2090bfcc5e82f2e9a9e7278ce9c9.zip
Wrote a replacement getopt for eurephiadm
This is because default getopt(...) is not flexible enough for eurephiadm. Example: eurephiadm -l test.log config -s var1 "value 1" eurephiadm config -s var2 value2 By using getopt in the eurephiadm.c, the -s argument will be parsed there as well, and it is no good solution how to just send arguments after the 'command' further to another argument parser. The new implementation is also not as feature rich as GNU getopt, but it is feature rich enough for the current needs.
Diffstat (limited to 'eurephiadm/eurephiadm.c')
-rw-r--r--eurephiadm/eurephiadm.c35
1 files changed, 17 insertions, 18 deletions
diff --git a/eurephiadm/eurephiadm.c b/eurephiadm/eurephiadm.c
index 85de55a..f4ad873 100644
--- a/eurephiadm/eurephiadm.c
+++ b/eurephiadm/eurephiadm.c
@@ -23,8 +23,6 @@
#include <string.h>
#include <assert.h>
#include <libgen.h>
-#define _GNU_SOURCE
-#include <getopt.h>
#include <eurephia_nullsafe.h>
#include <eurephia_context.h>
@@ -34,6 +32,7 @@
#include <eurephiadb_session_common.h>
#include <eurephiadb.h>
+#include "argparser.h"
#include "client_context.h"
#include "client_config.h"
#include "client_session.h"
@@ -214,6 +213,15 @@ int main(int argc, char **argv) {
int rc = 0, i = 0, found = 0, cmdargc = 0, argi = 0;
eurephiadm_functions *call_fnc;
+ // Global arguments we accept
+ static e_options argopts[] = {
+ {"--version", "-V", 0},
+ {"--help", "-h", 0},
+ {"--log", "-l", 1},
+ {"--log-level", "-L", 1},
+ {NULL, NULL, 0}
+ };
+
if( argc < 2 ) {
cmd_Help(NULL, NULL, NULL, argc, argv);
return 1;
@@ -221,23 +229,11 @@ int main(int argc, char **argv) {
// Parse argument line
argi = 1;
- while( 1 ) {
- int optidx = 0;
-
- /* global arguments */
- static struct option argopts[] = {
- {"version", 0, 0, 'V'},
- {"help", 0, 0, 'h'},
- {"log", 1, 0, 'l'},
- {"log-level", 1, 0, 'L'},
- {0,0,0,0}
- };
-
- i = getopt_long(argc, argv, "Vhl:L:", argopts, &optidx);
- if( i == -1 ) {
+ for( argi = 1; argi < argc; argi++ ) {
+ if( *argv[argi] != '-' ) {
break;
}
-
+ i = eurephia_getopt(argi, argc, argv, argopts);
switch( i ) {
case 'V':
print_version(argv[0]);
@@ -260,8 +256,11 @@ int main(int argc, char **argv) {
loglevel = atoi_nullsafe(optarg);
argi++;
break;
+
+ default:
+ return 1;
+ break;
}
- argi++;
}
if( argi >= argc ) {