diff -r f52628c1d1c6895317ea5dfa5e0b8f6bdbddaaad -r e92cdf39e4c3f00aa8ed6aa8ad54c3f3307690f8 src/ppparser.cxx --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ppparser.cxx Tue May 28 19:11:02 2013 -0500 @@ -0,0 +1,161 @@ +#include "ptypes.h" +#include "pstreams.h" + +USING_PTYPES + +pparser::pparser(int argc, char * argv[], const tobjlist & parameters) +{ + this->checkreq = true; + // Assumptions: + // *) options will not start with - + // *) parameters will not be repeated + int z = 0; + tpodlist parasused; + bool docontinue = false; + for(int i = 1; i < argc; i++) + { + + if (argv[i][0] == '-') + { + if (z != parameters.get_count()) + { + + for (int zz = 0; zz < parameters.get_count(); zz++) + { + docontinue = false; + for (int pu = 0; pu < parasused.get_count(); pu++) + { + if (parasused[pu] == zz) + { + docontinue = true; + break; + } + } + if (docontinue) + continue; + + if (argv[i] == ("-" + parameters[zz]->longparameter) || argv[i] == ("-" + parameters[zz]->shortparameter)) + { + if (parameters[zz]->numberofparameters == 0) + { + put(this->choices, argv[i], ""); + } else { + variant options; + if ((i+parameters[zz]->numberofparameters) <= argc) + { + for(int ii = 0; ii < parameters[zz]->numberofparameters; ii++) + { + add(options, (pt::string)argv[ii+i+1]); + } + put(this->choices, argv[i], options); + i += parameters[zz]->numberofparameters; + } else { + this->checkreq = false; + } + } + z++; + parasused.add(zz); + break; + } + } + + } else { + // hit the end of scanned parameters but user provided parameters still exist? + this->checkreq = false; + this->invalidparas.add(argv[i]); + } + + } else { + //should never look at a parameter that doesn't start with a - + this->checkreq = false; + this->invalidparas.add(argv[i]); + } + + this->argv.add(argv[i]); + } + + if (z != parameters.get_count()) + { + //scan through parameters for missing paras + for(int zz = z; zz < parameters.get_count(); zz++) + { + if (parameters[zz]->required) + { + this->checkreq = false; + this->missingparas.add(const_cast ((const char *)parameters[zz]->shortparameter)); + } + } + } + this->paras = const_cast *>(¶meters); + + +} + +void pparser::printusage(const char * header, const char * pname, const char * footer) +{ + pout.put(header); + pout.put("\n"); + if (this->invalidparas.get_count() > 0) + { + pout.put("Invalid parameters: "); + for(int i = 0; i < this->invalidparas.get_count(); i++) + { + pout.put(this->invalidparas[i]); + pout.put(" "); + } + pout.put("\n\n"); + } + + if (this->missingparas.get_count() > 0) + { + pout.put("Missing parameters: "); + for(int i = 0; i < this->missingparas.get_count(); i++) + { + pout.put("-"); + pout.put(this->missingparas[i]); + pout.put(" "); + } + pout.put("\n\n"); + } + pout.put("USAGE: "); + pout.put(pname); + pout.put(" "); + string parameterlist; + string paralisthints; + for(int i = 0; i < this->paras->get_count(); i++) + { + if ((*this->paras)[i]->required) + parameterlist += "-" + (*this->paras)[i]->shortparameter + " "; + else + parameterlist += "[-" + (*this->paras)[i]->shortparameter + "] "; + + paralisthints += "-" + (*this->paras)[i]->shortparameter + ", --" + (*this->paras)[i]->longparameter + "\n" + (*this->paras)[i]->hint + "\n\n"; + } + pout.put(parameterlist); + pout.put("\n"); + pout.put("\n"); + pout.put(paralisthints); + + pout.put(footer); + pout.put("\n"); +} + +bool pparser::isparameterset(const Parameter * para) +{ + if (get(this->choices, "--" + para->longparameter) == nullvar && get(this->choices, "-" + para->shortparameter) == nullvar) + { + return false; + } + return true; +} + +variant pparser::getoptions(const Parameter * para) +{ + if (get(this->choices, "--" + para->longparameter) != nullvar) + return get(this->choices, "--" + para->longparameter); + + if (get(this->choices, "-" + para->shortparameter) != nullvar) + return get(this->choices, "-" + para->shortparameter); + + return nullvar; +} \ No newline at end of file diff -r f52628c1d1c6895317ea5dfa5e0b8f6bdbddaaad -r e92cdf39e4c3f00aa8ed6aa8ad54c3f3307690f8 win32/PTypes_Lib.vcxproj --- a/win32/PTypes_Lib.vcxproj Tue May 28 19:00:54 2013 -0500 +++ b/win32/PTypes_Lib.vcxproj Tue May 28 19:11:02 2013 -0500 @@ -163,6 +163,7 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) @@ -434,7 +435,6 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - diff -r f52628c1d1c6895317ea5dfa5e0b8f6bdbddaaad -r e92cdf39e4c3f00aa8ed6aa8ad54c3f3307690f8 win32/PTypes_Lib.vcxproj.filters --- a/win32/PTypes_Lib.vcxproj.filters Tue May 28 19:00:54 2013 -0500 +++ b/win32/PTypes_Lib.vcxproj.filters Tue May 28 19:11:02 2013 -0500 @@ -188,7 +188,7 @@ Types - + Types diff -r f52628c1d1c6895317ea5dfa5e0b8f6bdbddaaad -r e92cdf39e4c3f00aa8ed6aa8ad54c3f3307690f8 win32/PTypes_Lib.vcxproj.user --- a/win32/PTypes_Lib.vcxproj.user Tue May 28 19:00:54 2013 -0500 +++ b/win32/PTypes_Lib.vcxproj.user Tue May 28 19:11:02 2013 -0500 @@ -1,3 +1,6 @@  + + false + \ No newline at end of file diff -r f52628c1d1c6895317ea5dfa5e0b8f6bdbddaaad -r e92cdf39e4c3f00aa8ed6aa8ad54c3f3307690f8 win32/ppparser.cxx --- a/win32/ppparser.cxx Tue May 28 19:00:54 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,161 +0,0 @@ -#include "ptypes.h" -#include "pstreams.h" - -USING_PTYPES - -pparser::pparser(int argc, char * argv[], const tobjlist & parameters) -{ - this->checkreq = true; - // Assumptions: - // *) options will not start with - - // *) parameters will not be repeated - int z = 0; - tpodlist parasused; - bool docontinue = false; - for(int i = 1; i < argc; i++) - { - - if (argv[i][0] == '-') - { - if (z != parameters.get_count()) - { - - for (int zz = 0; zz < parameters.get_count(); zz++) - { - docontinue = false; - for (int pu = 0; pu < parasused.get_count(); pu++) - { - if (parasused[pu] == zz) - { - docontinue = true; - break; - } - } - if (docontinue) - continue; - - if (argv[i] == ("-" + parameters[zz]->longparameter) || argv[i] == ("-" + parameters[zz]->shortparameter)) - { - if (parameters[zz]->numberofparameters == 0) - { - put(this->choices, argv[i], ""); - } else { - variant options; - if ((i+parameters[zz]->numberofparameters) <= argc) - { - for(int ii = 0; ii < parameters[zz]->numberofparameters; ii++) - { - add(options, (pt::string)argv[ii+i+1]); - } - put(this->choices, argv[i], options); - i += parameters[zz]->numberofparameters; - } else { - this->checkreq = false; - } - } - z++; - parasused.add(zz); - break; - } - } - - } else { - // hit the end of scanned parameters but user provided parameters still exist? - this->checkreq = false; - this->invalidparas.add(argv[i]); - } - - } else { - //should never look at a parameter that doesn't start with a - - this->checkreq = false; - this->invalidparas.add(argv[i]); - } - - this->argv.add(argv[i]); - } - - if (z != parameters.get_count()) - { - //scan through parameters for missing paras - for(int zz = z; zz < parameters.get_count(); zz++) - { - if (parameters[zz]->required) - { - this->checkreq = false; - this->missingparas.add(const_cast ((const char *)parameters[zz]->shortparameter)); - } - } - } - this->paras = const_cast *>(¶meters); - - -} - -void pparser::printusage(const char * header, const char * pname, const char * footer) -{ - pout.put(header); - pout.put("\n"); - if (this->invalidparas.get_count() > 0) - { - pout.put("Invalid parameters: "); - for(int i = 0; i < this->invalidparas.get_count(); i++) - { - pout.put(this->invalidparas[i]); - pout.put(" "); - } - pout.put("\n\n"); - } - - if (this->missingparas.get_count() > 0) - { - pout.put("Missing parameters: "); - for(int i = 0; i < this->missingparas.get_count(); i++) - { - pout.put("-"); - pout.put(this->missingparas[i]); - pout.put(" "); - } - pout.put("\n\n"); - } - pout.put("USAGE: "); - pout.put(pname); - pout.put(" "); - string parameterlist; - string paralisthints; - for(int i = 0; i < this->paras->get_count(); i++) - { - if ((*this->paras)[i]->required) - parameterlist += "-" + (*this->paras)[i]->shortparameter + " "; - else - parameterlist += "[-" + (*this->paras)[i]->shortparameter + "] "; - - paralisthints += "-" + (*this->paras)[i]->shortparameter + ", --" + (*this->paras)[i]->longparameter + "\n" + (*this->paras)[i]->hint + "\n\n"; - } - pout.put(parameterlist); - pout.put("\n"); - pout.put("\n"); - pout.put(paralisthints); - - pout.put(footer); - pout.put("\n"); -} - -bool pparser::isparameterset(const Parameter * para) -{ - if (get(this->choices, "--" + para->longparameter) == nullvar && get(this->choices, "-" + para->shortparameter) == nullvar) - { - return false; - } - return true; -} - -variant pparser::getoptions(const Parameter * para) -{ - if (get(this->choices, "--" + para->longparameter) != nullvar) - return get(this->choices, "--" + para->longparameter); - - if (get(this->choices, "-" + para->shortparameter) != nullvar) - return get(this->choices, "-" + para->shortparameter); - - return nullvar; -} \ No newline at end of file