diff options
author | FreeArtMan <dos21h@gmail.com> | 2018-06-03 12:33:36 +0100 |
---|---|---|
committer | FreeArtMan <dos21h@gmail.com> | 2018-06-03 12:33:36 +0100 |
commit | bdf536e69839edd86fbd3a4be31a5f1c0debe82e (patch) | |
tree | 61dc81bad31792e464ea0f880b115dfc8035f927 /arg.c | |
parent | 587dd24b5970aa3605cc2bc2826f7e35344b4317 (diff) | |
download | libarg++-bdf536e69839edd86fbd3a4be31a5f1c0debe82e.tar.gz libarg++-bdf536e69839edd86fbd3a4be31a5f1c0debe82e.zip |
Flag type works
Diffstat (limited to 'arg.c')
-rw-r--r-- | arg.c | 129 |
1 files changed, 127 insertions, 2 deletions
@@ -827,6 +827,18 @@ int CmdArgFlag::get() return this->flag; } +void CmdArgFlag::setUsed() { + this->used = 1; +} + +int CmdArgFlag::getValue() { + return this->flag; +} + +void CmdArgFlag::setFlag() { + this->flag = 1; +} + CmdArgFlagConf::CmdArgFlagConf() { this->used = 0; @@ -846,6 +858,10 @@ int CmdArgFlagConf::isUsed() return this->used; } +void CmdArgFlagConf::setUsed() { + this->used=1; +} + void CmdArgFlagConf::link(CmdArgFlag *flagArg) { this->result = flagArg; @@ -875,7 +891,7 @@ CmdArgDefault::CmdArgDefault(char *param, uint32_t type, void *def, char *help, CmdArgDefault::CmdArgDefault(char *param, CmdArgFlagConf *def, char *help, CmdArgFlag *result) { - printf("Construct CmdArgDefault::CmdArgDefault(char *param, CmdArgFlagConf *def, char *help, CmdArgFlag *result)\n"); + //printf("Construct CmdArgDefault::CmdArgDefault(char *param, CmdArgFlagConf *def, char *help, CmdArgFlag *result)\n"); this->param = param; this->type = ARGT_FLAG; this->def = (void *)def; @@ -890,11 +906,20 @@ void CmdArgDefault::setParam(char *param) this->param = param; } +char* CmdArgDefault::getParam() { + return this->param; +} + void CmdArgDefault::setType(uint32_t type) { this->type = type; } +uint32_t CmdArgDefault::getType() +{ + return this->type; +} + void CmdArgDefault::setDefValue(void *def) { this->def = def; @@ -905,6 +930,10 @@ int CmdArgDefault::isUsed() return this->used; } +void CmdArgDefault::setUsed() { + this->used = 1; +} + void CmdArgDefault::setHelp(char *help) { this->help = help; @@ -916,17 +945,113 @@ void CmdArgDefault::link(void *result) this->result = result; } +void *CmdArgDefault::getResult() { + return this->result; +} + +void *CmdArgDefault::getDefault() { + return this->def; +} + + CmdArg::CmdArg() { - + this->num = 0; + this->defaultArgs = NULL; } void CmdArg::load(int argc, char **argv) { + int i; + int pos; + + i = 1; + while (i < argc) { + + pos = this->searchArg(argv[i]); + + if (pos==-1) { + printf("Couldnt find any arguments\n"); + break; + } + CmdArgDefault *param = (CmdArgDefault *)this->defaultArgs[pos]; + switch (param->getType()) { + case ARGT_IP: { + break; + } + case ARGT_RANGE: { + break; + } + + case ARGT_FLOAT: { + break; + } + + case ARGT_LIST: { + break; + } + + case ARGT_FILE: { + break; + } + + case ARGT_VAL: { + break; + } + + case ARGT_FLAG: { + + CmdArgFlag *flag=(CmdArgFlag *)param->getResult(); + CmdArgFlagConf *conf=(CmdArgFlagConf *)param->getDefault(); + + param->setUsed(); + flag->setUsed(); + flag->setFlag(); + conf->setUsed(); + + break; + } + default: { + printf("Unknown type\n"); + } + } + + i++; + } } void CmdArg::add(CmdArgDefault *param) { + if (param == NULL) { + return; + } + + this->num += 1; + void *new_ptr=NULL; + new_ptr = realloc(this->defaultArgs, sizeof(void *)*this->num); + if (new_ptr != NULL) + { + this->defaultArgs = (void **)new_ptr; + new_ptr = NULL; + } else { + this->num-=1; + printf("Couldnt allocate memory\n"); + return; + } + CmdArgDefault *p = (CmdArgDefault *)param; + printf("Added type %d\n", p->getType()); + + this->defaultArgs[this->num-1] = param; +} +int CmdArg::searchArg(char *in) { + int i; + for (i=0;i<this->num;i++) { + CmdArgDefault *param = (CmdArgDefault *)this->defaultArgs[i]; + if (strncmp(param->getParam(), in, strlen(in)) == 0) { + return i; + } + } + return -1; }
\ No newline at end of file |