Commit 096865d7 authored by Arnaud Blanchard's avatar Arnaud Blanchard
Browse files

Fix bug with multiple parameters

parent d4118cbf
......@@ -101,10 +101,12 @@ void blc_program_add_parameter(char const**result, char const *name, int require
{
Program_parameter parameter;
if (required!=0 && required!=1) EXIT_ON_ERROR("You can only have '0' or '1' required parameter but you have '%d'", required);
parameter.type=STRING;
parameter.string_pt=result;
parameter.name=name;
parameter.required_nb=(required!=0); //At this moment only binary choices are possible
parameter.required_nb=required; //At this moment only binary choices are possible
parameter.help=help;
parameter.default_value=default_value;
......@@ -343,9 +345,9 @@ static void blc_program_interpret_parameters(int *argc, char **argv[]){
else EXIT_ON_SYSTEM_ERROR("Reading input for parameter");
}
tmp_parameter[parameter_read-1]=0;//Remove the last return;
APPEND_ITEM(program_parameter.string_list_pt, &list_parameters_nb, &tmp_parameter);
linecap=0;
tmp_parameter=nullptr;
APPEND_ITEM(program_parameter.string_list_pt, &list_parameters_nb, tmp_parameter);
fprintf(stderr, "Parameters '%s' %ld\n", tmp_parameter, parameter_read );
}
while(parameter_read>0);
......@@ -358,7 +360,6 @@ static void blc_program_interpret_parameters(int *argc, char **argv[]){
(*argv)++;
}
}
tmp_parameter=nullptr;
APPEND_ITEM(program_parameter.string_list_pt, &list_parameters_nb, &tmp_parameter);
break;
......@@ -405,10 +406,28 @@ void blc_program_args_display_help()
for(auto const &parameter : program_parameters)
{
if (parameter.type==STRING){
if (parameter.required_nb==0) fprintf(stderr, " [%s]", parameter.name);
else if (parameter.required_nb==-1) fprintf(stderr, " %s ...", parameter.name);
else if (parameter.required_nb==1) fprintf(stderr, " %s", parameter.name);
else FOR(i, parameter.required_nb) fprintf(stderr, " %s%d", parameter.name, i+1);
}
else
if (parameter.type==STRING_LIST){
if (parameter.required_nb==0) fprintf(stderr, " [%s ...]", parameter.name);
else if (parameter.required_nb > 0) {
FOR(i, parameter.required_nb){
fprintf(stderr, " %s", parameter.name);
}
}
else if (parameter.required_nb < 0){
FOR(i, -parameter.required_nb){
fprintf(stderr, " %s", parameter.name);
}
fprintf(stderr, "[%s ...]", parameter.name);
}
}
option_length_max=MAX(option_length_max, (int)strlen(parameter.name));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment