summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2018-07-31 20:11:22 +0100
committerFreeArtMan <dos21h@gmail.com>2018-07-31 20:11:22 +0100
commitfe1705589c593618ba6d070639eb55d210e3a83c (patch)
treeec4b3723e9901d416624b1878ebc3671850aeb10
parentf88b7dea6effccf48b78be84e4a92bf197cf3c64 (diff)
downloadlibarg++-fe1705589c593618ba6d070639eb55d210e3a83c.tar.gz
libarg++-fe1705589c593618ba6d070639eb55d210e3a83c.zip
val and flag, tested and works
-rw-r--r--Makefile4
-rw-r--r--arg.c44
-rw-r--r--arg.h2
3 files changed, 38 insertions, 12 deletions
diff --git a/Makefile b/Makefile
index ab57711..8d3bdf1 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
PROJ=libarg
CC=g++
-CFLAGS=-Wall -fpermissive -fno-rtti -fno-exceptions -fno-unwind-tables -Wno-comment
+CFLAGS=-g3 -Wall -fpermissive -fno-rtti -fno-exceptions -fno-unwind-tables -Wno-comment
LDFLAGS=
SOURCE=arg
@@ -14,7 +14,7 @@ make: dynamic static
dynamic: CFLAGS+=-fPIC
dynamic: clean $(OBJECTS)
- $(CC) $(CFLAGS) $(OBJECTS) -shared -o $(PROJ).so
+ gcc $(CFLAGS) $(OBJECTS) -shared -o $(PROJ).so
static: clean $(OBJECTS)
ar rcs $(PROJ).a $(OBJECTS)
diff --git a/arg.c b/arg.c
index da34f92..c6cd489 100644
--- a/arg.c
+++ b/arg.c
@@ -1003,6 +1003,8 @@ CmdArg::CmdArg()
{
this->num = 0;
this->defaultArgs = NULL;
+ this->usedArgs = NULL;
+ this->usedArgsNum = -1;
}
void CmdArg::load(int argc, char **argv)
@@ -1010,8 +1012,11 @@ void CmdArg::load(int argc, char **argv)
int i;
int pos;
+ this->usedArgs = (int *)calloc(argc,sizeof(int)); //DNCHK
+ this->usedArgsNum = argc;
+
i = 1;
- while (i < argc) {
+ while (i < this->usedArgsNum) {
pos = this->searchArg(argv[i]);
@@ -1045,11 +1050,22 @@ void CmdArg::load(int argc, char **argv)
CmdArgVal *val=(CmdArgVal *)param->getResult();
CmdArgValConf *conf=(CmdArgValConf *)param->getDefault();
- param->setUsed();
- val->setUsed();
- //flag->setFlag();
- val->setValue(param->getParam());
- conf->setUsed();
+ if (i+1<argc)
+ {
+ if ((this->usedArgs[i] == 0)
+ && (this->usedArgs[i+1] == 0))
+ {
+
+ param->setUsed();
+ val->setUsed();
+ //CmdArgDefault *valArg = (CmdArgDefault *)this->defaultArgs[pos];
+ //valArg->setUsed();
+ val->setValue(argv[i+1]);
+ conf->setUsed();
+ this->usedArgs[i] = 1;
+ this->usedArgs[i+1] = 1;
+ }
+ }
break;
}
@@ -1058,10 +1074,18 @@ void CmdArg::load(int argc, char **argv)
CmdArgFlag *flag=(CmdArgFlag *)param->getResult();
CmdArgFlagConf *conf=(CmdArgFlagConf *)param->getDefault();
- param->setUsed();
- flag->setUsed();
- flag->setFlag();
- conf->setUsed();
+ PRINT("ARGT_FLAG\n");
+
+ if (this->usedArgs[pos] == 0)
+ {
+ param->setUsed();
+ flag->setUsed();
+ flag->setFlag();
+ conf->setUsed();
+ this->usedArgs[i] = 1;
+ }
+ //warn?
+
break;
}
diff --git a/arg.h b/arg.h
index 2b32c20..fde5afc 100644
--- a/arg.h
+++ b/arg.h
@@ -423,6 +423,8 @@ class CmdArg {
int num;
void **defaultArgs;
int searchArg(char *in);
+ int *usedArgs;
+ int usedArgsNum;
public:
CmdArg();
void load(int argc, char **argv);