Commit 27e1067e authored by Arnaud Blanchard's avatar Arnaud Blanchard
Browse files

Fix problem with interpretation of -h --help

parent 86e25a34
......@@ -110,7 +110,7 @@ void blc_program_add_parameter(char const**result, char const *name, int require
program_parameters.push_back(parameter);
// APPEND_ITEM(&blc_program_parameters, &blc_program_parameters_nb, &parameter);
// APPEND_ITEM(&blc_program_parameters, &blc_program_parameters_nb, &parameter);
}
void blc_program_add_multiple_parameters(char ***result_list, char const *name, int required_nb, char const *help)
......@@ -174,7 +174,7 @@ void blc_program_add_output_pipe_option(FILE *file, char letter, char const *lon
program_options.push_back(tmp_program_option);
}
static void blc_program_option_interpret(int *argc, char **argv[])
static bool blc_program_option_interpret(int *argc, char **argv[])
{
char *optstring;
int ret, option_index;
......@@ -224,38 +224,39 @@ static void blc_program_option_interpret(int *argc, char **argv[])
}
else{
switch (program_option.type){
case STRING:
case STRING:
*program_option.string_pt = optarg;
break;
//Pipe not in use anymore
case INPUT_PIPE:
case INPUT_PIPE:
SPRINTF(pipe_name, "/tmp/blc_pipes/%s", optarg);
SYSTEM_ERROR_CHECK(freopen(optarg, "r", program_option.pipe), NULL, NULL);
break;
case OUTPUT_PIPE:
case OUTPUT_PIPE:
mkdir("/tmp/blc_pipes", S_IRWXU);
SPRINTF(pipe_name, "/tmp/blc_pipes/%s", optarg);
if (mkfifo(pipe_name, S_IRWXU) !=0)
{
if (errno==EEXIST)
{
SYSTEM_SUCCESS_CHECK(stat(pipe_name, &stat_data), 0, "Checking data of '%s'.", pipe_name);
if (stat_data.st_mode == S_IFIFO){
SYSTEM_ERROR_CHECK(freopen(pipe_name, "w", program_option.pipe), NULL, NULL);
if (errno==EEXIST)
{
SYSTEM_SUCCESS_CHECK(stat(pipe_name, &stat_data), 0, "Checking data of '%s'.", pipe_name);
if (stat_data.st_mode == S_IFIFO){
SYSTEM_ERROR_CHECK(freopen(pipe_name, "w", program_option.pipe), NULL, NULL);
}
else EXIT_ON_ERROR("Cannot use '%s' as a output pipe.", pipe_name);
}
else EXIT_ON_ERROR("Cannot use '%s' as a output pipe.", pipe_name);
else EXIT_ON_SYSTEM_ERROR("Creating output pipe '%s'.", pipe_name);
}
else EXIT_ON_SYSTEM_ERROR("Creating output pipe '%s'.", pipe_name);
}
break;
default:EXIT_ON_ERROR("Type %d not managed.", program_option.type);
}
}
}
if (ret=='h') { // We need to check it now otherwise, it may ask for parameter (blocking scanf)
FREE(long_options);
return;
if (ret=='h') { // We need to check it now otherwise, it may ask for parameter (blocking scanf)
FREE(long_options);
return false ;
}
}
}
}
......@@ -265,13 +266,15 @@ static void blc_program_option_interpret(int *argc, char **argv[])
for(auto const &program_option:program_options)
{
switch (program_option.type){
case STRING:
case STRING:
if (*program_option.string_pt==NULL) *program_option.string_pt=(char*)program_option.default_value;
break;
}
}
(*argc)-=optind;
(*argv)+=optind;
return true;
}
......@@ -285,7 +288,7 @@ static void blc_program_interpret_parameters(int *argc, char **argv[]){
for(auto const &program_parameter :program_parameters){
switch(program_parameter.type){
case STRING :
case STRING :
if ((*argc)==0){//There is no more argument to interpret
if (program_parameter.required_nb){
if (isatty(STDIN_FILENO)) fprintf(stderr, "%s: %s? ", program_parameter.help, program_parameter.name);
......@@ -313,7 +316,7 @@ static void blc_program_interpret_parameters(int *argc, char **argv[]){
}
break;
case STRING_LIST:
case STRING_LIST:
if (isatty(STDIN_FILENO)) {
missing_parameters_nb = abs(program_parameter.required_nb)-(*argc);
......@@ -358,7 +361,6 @@ static void blc_program_interpret_parameters(int *argc, char **argv[]){
tmp_parameter=nullptr;
APPEND_ITEM(program_parameter.string_list_pt, &list_parameters_nb, &tmp_parameter);
break;
}
}
......@@ -367,8 +369,8 @@ static void blc_program_interpret_parameters(int *argc, char **argv[]){
void blc_program_parse_args(int *argc, char ***argv){
blc_program_name=basename(*argv[0]);
SYSTEM_ERROR_CHECK(asprintf((char**)&blc_program_id, "%s%d", blc_program_name, getpid()), -1, "Argv0: '%s'", *argv[0]);
blc_program_option_interpret(argc, argv);
blc_program_interpret_parameters(argc, argv);
if (blc_program_option_interpret(argc, argv)) blc_program_interpret_parameters(argc, argv);
//else it was 'help'
}
void blc_program_parse_args_and_print_title(int *argc, char ***argv){
......
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