- // Look for long argument
- if ((akt_p->substr(0,2)=="--")&&(free_parms_count==0)){
- int found=0;
- for (vector<opt_t>::iterator parm_p=opt_v.begin();parm_p<opt_v.end();parm_p++){
- if (akt_p->substr(2,parm_p->longname.length())==parm_p->longname){
- found=1;
- *(parm_p->status)=1;
- if (parm_p->target){
- if (akt_p->length()>2+parm_p->longname.length()){
- *(parm_p->target)=akt_p->substr(2+parm_p->longname.length());
-
- } else // Word not long enough
- if (akt_p+1<argv.end()) { // If next word existend
- *(parm_p->status)=1;
- *(parm_p->target)=*(++akt_p);
- } else { // No next word :-(
- result.insert(result.end(),
- "Parameter --"+parm_p->longname+parm_p->placeholder+" needs an Argument!");
- }
- } // arg needed
+ // Look for long parameters.
+ if ((argv[arg_no].substr(0,2)=="--")&&(free_parms_count==0)){
+ argstring=argv[arg_no].substr(2);
+
+ // Look for long switches.
+ for (unsigned int switch_no=0;switch_no<option_switches.size();switch_no++){
+ string switch_name=option_switches[switch_no].longname;
+ if (argstring.compare(0,switch_name.length(),switch_name,0,switch_name.length())==0){
+ string value=analyse_string(argstring);
+ bool result=analyse_bool(value);
+ if(option_switches[switch_no].allow_cmdline==true){
+ *(option_switches[switch_no].status)=result;
+ }else{
+ messages.insert(messages.end(),"Switch \"--"
+ +option_switches[switch_no].longname
+ +"\" is not allowed on the command line!");
+ }
+ found=true;
+ break;
+ }
+ }
+
+ // Look for long values.
+ for (unsigned int value_no=0;value_no<option_values.size();value_no++){
+ string value_name=option_values[value_no].longname;
+ if (argstring.compare(0,value_name.length(),value_name,0,value_name.length())==0){
+ string value=analyse_string(argstring);
+ if(option_values[value_no].allow_cmdline==true){
+ *(option_values[value_no].status)=1;
+ *(option_values[value_no].target)=value;
+ }else{
+ messages.insert(messages.end(),"Option value \"--"
+ +option_values[value_no].longname
+ +"\" is not allowed on the command line!");
+ }
+ found=true;
+ break;
+ }
+ }
+ if (! found) {
+ messages.insert(messages.begin(),"Unknown option: --"+argstring+"!");
+ found=true; // Oh!
+ }
+ }
+
+ // Look for short parameters
+ if ((argv[arg_no].substr(0,1)=="-")&&(free_parms_count==0)&&(!found)){ // Short parameters
+ found=true;
+ argstring=argv[arg_no].substr(1); // Reassign, with one more character now
+ for (unsigned int pos=0;pos < argstring.length();pos++){
+ bool short_found=false;
+
+ // First, find short switches
+ for (unsigned int switch_no=0;switch_no<option_switches.size();switch_no++){
+ string short_name=option_switches[switch_no].shortname;
+ if (short_name.compare(0,short_name.length(),argstring,pos,short_name.length())==0){
+ if(option_switches[switch_no].allow_cmdline==true){
+ *(option_switches[switch_no].status)=1;
+ }else{
+ messages.insert(messages.end(),"Switch \"-"
+ +option_switches[switch_no].shortname
+ +"\" is not allowed on the command line!");
+ }
+ short_found=true;
+ pos+=short_name.length()-1;
+ break;
+ }
+ }
+
+ // Now, find short values
+ if (!short_found){
+ for (unsigned int value_no=0;value_no<option_values.size();value_no++){
+ string short_name=option_values[value_no].shortname;
+
+ if (short_name.compare(0,short_name.length(),argstring,pos,short_name.length())==0){
+ if (pos==argstring.length()-1){ // Last character, where's the value?
+ if (arg_no<argv.size()-1){ // Take next complete argument as value!
+ *(option_values[value_no].status)=1;
+ *(option_values[value_no].target)=argv[arg_no+1];
+ arg_no+=1; // Consume the next argument
+ short_found=true;
+ } else { // No argument left!
+ messages.insert(messages.begin(),"Missing value for -"+short_name+"!");
+ short_found=true;
+ }
+ } else {
+ if(option_values[value_no].allow_cmdline==true){
+ *(option_values[value_no].status)=1;
+ *(option_values[value_no].target)=argstring.substr(pos+1);
+ }else{
+ messages.insert(messages.end(),"Option value \"-"
+ +option_values[value_no].shortname
+ +"\" is not allowed on the command line!");
+ }
+ pos=argstring.length(); // Do not analyse other characters.
+ short_found=true;
+ break;
+ }
+ }
+ }