X-Git-Url: http://gitweb.hachti.de/?a=blobdiff_plain;f=pc-tools%2Fldc2%2Fsrc%2Fargument_reader.cpp;h=f9241c173d12cd9c86f4f984a6ce6b1a2506a8fb;hb=fed2c751d37bf5e314fd26c98909471157cc86c0;hp=e927a37c95f997b7d3421884598385f909aadd5d;hpb=632a71a231a9bdd73a670ec686e13dd049921182;p=h316.git diff --git a/pc-tools/ldc2/src/argument_reader.cpp b/pc-tools/ldc2/src/argument_reader.cpp index e927a37..f9241c1 100644 --- a/pc-tools/ldc2/src/argument_reader.cpp +++ b/pc-tools/ldc2/src/argument_reader.cpp @@ -5,11 +5,11 @@ *\brief Constructor. * * This constructor makes a new argument_reader ready to use. - *\arg app_name Name of the application as mentioned in the + *\arg name Name of the application as mentioned in the * "Use: ..." help message. */ -argument_reader::argument_reader(string app_name){ - progname=app_name; +argument_reader::argument_reader(string name){ + app_name=app_name; } @@ -31,8 +31,8 @@ void argument_reader::add_param (string shortname, string longname, string description, int * status, string * target, string placeholder){ - if(status!=NULL) arguments.insert(arguments.end(), - parameter(shortname,longname, description, + if(status!=NULL) opt_v.insert(opt_v.end(), + opt_t(shortname,longname, description, status,target,placeholder) ); } @@ -52,13 +52,13 @@ void argument_reader::add_param (string shortname, string longname, */ void argument_reader::add_argument(string placeholder, string description, int * status, string * target){ if (target!=NULL) if(status!=NULL) - free_arguments.insert(free_arguments.end(),free_parameter(placeholder,description,status,target)); + arg_v.insert(arg_v.end(),arg_t(placeholder,description,status,target)); } /*! - * Read in the args passed to main(). - *\returns empty vector on success or the error messages to be output. + *\Read in the args passed to main(). + *\returns empty vector on success or the error messages to be output. */ vector argument_reader::read_args(int argc, char ** args){ vector result; @@ -71,7 +71,7 @@ vector argument_reader::read_args(int argc, char ** args){ // Look for long argument if ((akt_p->substr(0,2)=="--")&&(free_parms_count==0)){ int found=0; - for (vector::iterator parm_p=arguments.begin();parm_p::iterator parm_p=opt_v.begin();parm_psubstr(2,parm_p->longname.length())==parm_p->longname){ found=1; *(parm_p->status)=1; @@ -96,7 +96,7 @@ vector argument_reader::read_args(int argc, char ** args){ int stop_char_loop=0; for (unsigned int pos=1; poslength()&& !stop_char_loop ;pos++){ int found=0; - for (vector::iterator parm_p=arguments.begin();parm_p::iterator parm_p=opt_v.begin();parm_pshortname[0]==(*akt_p)[pos]){ found=1; (*parm_p->status)=1; @@ -120,21 +120,19 @@ vector argument_reader::read_args(int argc, char ** args){ } // char loop }// switch found else{ // no switch found - if (free_parms_countfree_arguments.size()) result.insert(result.begin(),"Too many arguments!"); + if (free_parms_count>arg_v.size()) result.insert(result.begin(),"Too many arguments!"); if (!result.empty()){ result.insert(result.begin(),"Error!"); result.insert(result.begin(),""); } -// if (!result.empty()){ -// get_help(result); -// } return result; } @@ -143,34 +141,33 @@ vector argument_reader::read_args(int argc, char ** args){ *\arg target Reference to a vector to which lots of helpful * strings are appended. */ -void argument_reader::get_help(vector & result){ - - result.insert(result.end(),""); - string line="Usage: "+progname; - for (vector::iterator parm_p=arguments.begin();parm_p & target){ + target.insert(target.end(),""); + string line="Usage: "+app_name; + for (vector::iterator parm_p=opt_v.begin();parm_pshortname; if (parm_p->target!=0) addstr+=parm_p->placeholder; addstr+="]"; if (line.length()+addstr.length()>79){ - result.insert(result.end(),line); - line=string(7+progname.length(),' '); + target.insert(target.end(),line); + line=string(7+app_name.length(),' '); } line+=addstr; } - for (vector::iterator parm_p=free_arguments.begin();parm_p::iterator parm_p=arg_v.begin();parm_pplaceholder.length()>79){ - result.insert(result.end(),line); - line=string(7+progname.length(),' '); + target.insert(target.end(),line); + line=string(7+app_name.length(),' '); } line+=" ["+parm_p->placeholder+"]"; } - result.insert(result.end(),line); + target.insert(target.end(),line); /*******************************/ vector left,right; - for (vector::iterator parm_p=arguments.begin();parm_p::iterator parm_p=opt_v.begin();parm_pdescription; string st2=" -"+parm_p->shortname; if (parm_p->target)st2+=" "+parm_p->placeholder; @@ -180,7 +177,7 @@ void argument_reader::get_help(vector & result){ right.insert(right.end(),line); } - for (vector::iterator parm_p=free_arguments.begin();parm_p::iterator parm_p=arg_v.begin();parm_pdescription; st2+=" "+parm_p->placeholder; @@ -188,36 +185,35 @@ void argument_reader::get_help(vector & result){ right.insert(right.end(),line); } - if (arguments.size()){ - result.insert(result.end(),""); - result.insert(result.end(),"Options:"); + if (opt_v.size()){ + target.insert(target.end(),""); + target.insert(target.end(),"Options:"); } unsigned int max_width=0; - for (unsigned int c=0; cmax_width) max_width=left[c].length(); - for (unsigned int c=0; c80){ // Too long??? int limit=nl.find_last_of(' ',80); - printf("limit:%i\n",limit); - result.insert(result.end(),nl.substr(0,limit)); + target.insert(target.end(),nl.substr(0,limit)); nl=string(max_width+2,' ')+nl.substr(limit+1); } - result.insert(result.end(),nl); + target.insert(target.end(),nl); } - if (free_arguments.size()){ - result.insert(result.end(),""); - result.insert(result.end(),"Arguments:"); + if (arg_v.size()){ + target.insert(target.end(),""); + target.insert(target.end(),"Arguments:"); } max_width=0; - for (unsigned int c=arguments.size(); cmax_width) max_width=left[c].length(); - for (unsigned int c=arguments.size(); c & result){ while (nl.length()>80){ // Too long??? int limit=nl.find_last_of(' ',80); printf("limit:%i\n",limit); - result.insert(result.end(),nl.substr(0,limit)); + target.insert(target.end(),nl.substr(0,limit)); nl=string(max_width+2,' ')+nl.substr(limit+1); } - result.insert(result.end(),nl); + target.insert(target.end(),nl); } - result.insert(result.end(),""); + target.insert(target.end(),""); } /*! @@ -247,7 +243,7 @@ vector argument_reader::get_help(){ /**************************************************/ -argument_reader::parameter::parameter(string n_shortname, string n_longname,string n_description, int * n_status, +argument_reader::opt_t::opt_t(string n_shortname, string n_longname,string n_description, int * n_status, string * n_target, string n_placeholder){ shortname=n_shortname; longname=n_longname; @@ -258,7 +254,7 @@ argument_reader::parameter::parameter(string n_shortname, string n_longname,stri if (status) *status=0; } -argument_reader::free_parameter::free_parameter( string n_placeholder, string n_description, +argument_reader::arg_t::arg_t( string n_placeholder, string n_description, int * n_status, string * n_target){ description=n_description; status=n_status;