diff options
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | arg.c | 44 | ||||
-rw-r--r-- | arg.h | 2 |
3 files changed, 38 insertions, 12 deletions
@@ -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) @@ -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; } @@ -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); |