Commit 4bcb70ba authored by Arnaud Blanchard's avatar Arnaud Blanchard
Browse files

Add possibility to parse multiple parameters

parent a337fbbd
......@@ -18,7 +18,7 @@ find_package(blc_core REQUIRED)
#source files
set(sources src/blc_loop.cpp src/blc_program.cpp src/blc_command.cpp)
add_definitions(${BL_DEFINITIONS} -std=c++14)
add_definitions(${BL_DEFINITIONS} -std=c++14 -Wall -W)
include_directories(include ${BL_INCLUDE_DIRS})
#shared lib
......
......@@ -113,7 +113,7 @@ void blc_command_remove(const char *command_name){
if (strcmp(blc_commands[i].name, command_name) == 0) break;
}
if (i==-1) EXIT_ON_ERROR("You try to remove a command '%s' that does not exist", command_name);
REMOVE_ITEM_POSITION(&blc_commands, &blc_commands_nb, i);
}
......@@ -151,8 +151,8 @@ void blc_command_interpret_string(char const *input_string, size_t size){
parameter2_size = getline(&parameter2, &line_capability, stdin)-1;
parameter2[parameter2_size]=0;
}
if (command->callback == NULL) EXIT_ON_ERROR("Command callback is NULL for command '%s'", command->name);
command->callback(parameter2, command->user_data);
if (command->callback == nullptr) EXIT_ON_ERROR("Command callback is NULL for command '%s'", command->name);
else command->callback(parameter2, command->user_data);
FREE(parameter2);
line_capability=0;
break; //Command has been found
......@@ -164,9 +164,9 @@ void blc_command_interpret_string(char const *input_string, size_t size){
break;
}
else continue; //Maybe it is a command with a longer name, we continue to check
/* if ((command->prompt != NULL) && (command->prompt[0]!='|')) continue; // If we do not wait for parameter, the command must be exact.
else
return;*/
/* if ((command->prompt != NULL) && (command->prompt[0]!='|')) continue; // If we do not wait for parameter, the command must be exact.
else
return;*/
}
}
}
......@@ -174,11 +174,11 @@ void blc_command_interpret_string(char const *input_string, size_t size){
}
void blc_command_interpret_block(){
char *line=NULL;
char *line=nullptr;
size_t line_capability=0;
ssize_t line_size;
//We do not consider error if it was an interruption. @TODO check wether the content of lin is correct.
//We do not consider error if it was an interruption. @TODO check wether the content of line is correct.
do{
line_size = getline(&line, &line_capability, stdin);
}while ((line_size==-1) && (errno==EINTR));
......
......@@ -106,13 +106,16 @@ static void blc_command_send_to_all(char const *argument){
}
void blc_command_ask_quit(){
if (blc_status==BLC_PAUSE) BLC_PTHREAD_CHECK(pthread_mutex_unlock(&mutex_lock_keyboard), NULL);
//In pause we unlock the keyboard
if (blc_status==BLC_PAUSE) BLC_PTHREAD_CHECK(pthread_mutex_unlock(&mutex_lock_keyboard), nullptr);
//In step by step we switch to quitting mode
if (blc_status!=BLC_STEPS) blc_status=BLC_QUIT;
if (blocking_semaphore){
if (sem_trywait(blocking_semaphore)==0){
sem_post(blocking_semaphore); // we succeed, it was not a problem, I free it.
blocking_semaphore=NULL;
blocking_semaphore=nullptr;
}
else if (errno==EAGAIN) sem_post(blocking_semaphore);
else EXIT_ON_SYSTEM_ERROR("unlocking semaphore for quitting");
......@@ -122,7 +125,7 @@ void blc_command_ask_quit(){
static void step_forward_cb(const char* steps_nb_str, void*){
int steps_nb, pos;
if (steps_nb_str){
if (sscanf(steps_nb_str, "%d%n", &steps_nb, &pos)!=1 || pos !=strlen(steps_nb_str) || steps_nb<1){
if (sscanf(steps_nb_str, "%d%n", &steps_nb, &pos)!=1 || pos != (int)strlen(steps_nb_str) || steps_nb<1){
color_eprintf(BLC_YELLOW, "'%s' is not a valid step number\n", steps_nb_str);
return;
}
......@@ -168,7 +171,7 @@ static void *loop_check_stuck(void*){
sleep(checking_time);
if(blc_status==BLC_RUN){ //in BLC_PAUSE it is normal to block
if (iteration==blc_loop_iteration) {
if (iteration==(int)blc_loop_iteration) {
color_eprintf(BLC_YELLOW, "'%s' seems blocked on iteration '%d'. The loop has been stopped for more than %ds\n", blc_program_id, iteration, checking_time);
if (blc_profile_file) fflush(blc_profile_file); //It may help for debuggage
was_stucked=1;
......@@ -192,35 +195,32 @@ static void *command_thread_interpret_loop(void *){
return NULL;
}
///This create one or two threads.
void blc_command_loop_init(long loop_period){
if (blc_command_loop_period==-3) EXIT_ON_ERROR("You already are in a blc_command_loop");
blc_loop_iteration=0;
intermediate_iteration=0;
blc_command_loop_period=loop_period;
if (blc_command_loop_period==-2){
blc_command_loop_period=-1;
}
else BLC_PTHREAD_CHECK(pthread_mutex_lock(&mutex_lock_keyboard), NULL);
/*We do not block the keyboard in -2 mode */
if (blc_command_loop_period!=-2) BLC_PTHREAD_CHECK(pthread_mutex_lock(&mutex_lock_keyboard), nullptr);
else blc_command_loop_period=-1;
if (blc_input_terminal){
blc_command_display_help(); //We display help only for keyboard
}
if (blc_input_terminal) blc_command_display_help(); //We display help only for keyboard
if (blc_command_loop_period!=-1) blc_command_add("", (type_blc_command_cb)pause_cb, NULL, "set on/off pause", NULL);
blc_command_add("h", (type_blc_command_cb)blc_command_display_help, NULL, "display this help", NULL);
blc_command_add("q", (type_blc_command_cb)blc_command_ask_quit, NULL, "quit the application", NULL);
if (blc_command_loop_period != -1) blc_command_add("", (type_blc_command_cb)pause_cb, NULL, "set on/off pause", nullptr);
blc_command_add("h", (type_blc_command_cb)blc_command_display_help, nullptr, "display this help", nullptr);
blc_command_add("q", (type_blc_command_cb)blc_command_ask_quit, nullptr, "quit the application", nullptr);
if (blc_command_loop_period!=-1) { //we lock on keyboard. But if the program lock we still read keyboard
SYSTEM_ERROR_CHECK(pthread_create(&loop_check_stuck_thread, NULL, loop_check_stuck, NULL), -1, NULL);
blc_command_add("s", (type_blc_command_cb)display_stats, NULL, "display time stats", NULL); //We did not do stat on keyboard
SYSTEM_ERROR_CHECK(pthread_create(&loop_check_stuck_thread, nullptr, loop_check_stuck, nullptr), -1, nullptr);
blc_command_add("s", (type_blc_command_cb)display_stats, nullptr, "display time stats", nullptr); //We did not do stat on keyboard
fprintf(stderr, "=== %s: running ===\n", blc_program_id);
}
blc_command_add("|", (type_blc_command_cb)blc_command_send_to_stdout, "command", "sends the command to stdout", NULL);
blc_command_add("&", (type_blc_command_cb)blc_command_send_to_all, "command", "inteprets command and sends it to stdout", NULL);
blc_command_add("|", (type_blc_command_cb)blc_command_send_to_stdout, "command", "sends the command to stdout", nullptr);
blc_command_add("&", (type_blc_command_cb)blc_command_send_to_all, "command", "inteprets command and sends it to stdout", nullptr);
BLC_PTHREAD_CHECK(pthread_create(&loop_thread, NULL, command_thread_interpret_loop, NULL), NULL);
BLC_PTHREAD_CHECK(pthread_create(&loop_thread, nullptr, command_thread_interpret_loop, nullptr), nullptr);
}
int blc_command_loop_start(){
......@@ -235,7 +235,7 @@ int blc_command_loop_start(){
pause_cb();
}
//If we quit, we quit now before blockinhs semaphores.
//If we quit, we quit now before blocking semaphores.
if (blc_status==BLC_QUIT) return 0;
//We eventually wait for keyboard return key
......
......@@ -37,18 +37,22 @@
#include "blc_tools.h"
#include "blc_command.h"
#include <vector>
using namespace std;
/**
It manages arguments of programs and help
*/
typedef void*(*type_pthread_cb)(void*);
//typedef type_program_option_result;
enum {STRING, STRING_LIST, BLC_CHANNEL, INPUT_PIPE, OUTPUT_PIPE};
// This is a bit redundant with struct option but has we need to send an array of struct option to getopt_long, we need two independant arrays: one with struct option and one with type_program_option.
typedef struct {
struct Program_option{
int type;
union{
// blc_channel *channel;
......@@ -60,9 +64,9 @@ typedef struct {
char const *parameter;
char const *help;
char const *default_value;
}type_program_option;
};
struct program_parameter{
struct Program_parameter{
int type;
union{
// blc_channel *channel;
......@@ -83,10 +87,8 @@ int blc_input_terminal, blc_output_terminal;
// Static means it is only existing in this file
static char const *program_description=NULL;
static type_program_option *blc_program_options=NULL;
static int blc_program_options_nb=0;
static struct program_parameter *blc_program_parameters=NULL;
static int blc_program_parameters_nb;
static vector <Program_option> program_options;
static vector <Program_parameter> program_parameters;
START_EXTERN_C
......@@ -97,7 +99,7 @@ void blc_program_set_description(char const *description)
void blc_program_add_parameter(char const**result, char const *name, int required, char const *help, char const *default_value)
{
struct program_parameter parameter;
Program_parameter parameter;
parameter.type=STRING;
parameter.string_pt=result;
......@@ -106,12 +108,14 @@ void blc_program_add_parameter(char const**result, char const *name, int require
parameter.help=help;
parameter.default_value=default_value;
APPEND_ITEM(&blc_program_parameters, &blc_program_parameters_nb, &parameter);
program_parameters.push_back(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)
{
struct program_parameter parameter;
Program_parameter parameter;
*result_list=nullptr;
......@@ -121,11 +125,12 @@ void blc_program_add_multiple_parameters(char ***result_list, char const *name,
parameter.required_nb=required_nb;
parameter.help=help;
parameter.default_value=nullptr;
APPEND_ITEM(&blc_program_parameters, &blc_program_parameters_nb, &parameter);
program_parameters.push_back(parameter);
}
void blc_program_add_option(char const **result, char letter, char const *long_option, char const *parameter, char const *help, char const* default_value){
type_program_option tmp_program_option;
Program_option tmp_program_option;
// if ((parameter) && (default_value)) EXIT_ON_ERROR("option '%s': you cannot required an parameter '%s' and having a default value '%s'", long_option, parameter, default_value);
......@@ -137,12 +142,16 @@ void blc_program_add_option(char const **result, char letter, char const *long_o
tmp_program_option.parameter = parameter;
tmp_program_option.help = help;
tmp_program_option.default_value = default_value;
APPEND_ITEM(&blc_program_options, &blc_program_options_nb, &tmp_program_option);
program_options.push_back(tmp_program_option);
}
void blc_program_add_input_pipe_option(FILE *file, char letter, char const *long_option, char const *help, char* default_value)
{
type_program_option tmp_program_option;
Program_option tmp_program_option;
tmp_program_option.type=INPUT_PIPE;
tmp_program_option.pipe = file;
......@@ -151,12 +160,12 @@ void blc_program_add_input_pipe_option(FILE *file, char letter, char const *long
tmp_program_option.parameter = "input_pipe";
tmp_program_option.help = help;
tmp_program_option.default_value=default_value;
APPEND_ITEM(&blc_program_options, &blc_program_options_nb, &tmp_program_option);
program_options.push_back(tmp_program_option);
}
void blc_program_add_output_pipe_option(FILE *file, char letter, char const *long_option, char const *help, char * default_value)
{
type_program_option tmp_program_option;
Program_option tmp_program_option;
tmp_program_option.type=OUTPUT_PIPE;
tmp_program_option.pipe = file;
......@@ -165,7 +174,7 @@ void blc_program_add_output_pipe_option(FILE *file, char letter, char const *lon
tmp_program_option.parameter = "output_pipe";
tmp_program_option.help = help;
tmp_program_option.default_value=default_value;
APPEND_ITEM(&blc_program_options, &blc_program_options_nb, &tmp_program_option);
program_options.push_back(tmp_program_option);
}
static void blc_program_option_interpret(int *argc, char **argv[])
......@@ -176,26 +185,25 @@ static void blc_program_option_interpret(int *argc, char **argv[])
int options_nb=0;
struct option *long_options = NULL, tmp_option;
struct stat stat_data;
type_program_option *program_option;
char pipe_name[PATH_MAX+1];
blc_program_name = basename(*argv[0]);
//We store enough room for all the optional letters + ':' + terminating null char
optstring = MANY_ALLOCATIONS(blc_program_options_nb*2+1, char);
optstring = MANY_ALLOCATIONS(program_options.size()*2+1, char);
//We define this list and initialise the result
FOR_EACH_INV(program_option, blc_program_options, blc_program_options_nb)
for(auto const &program_option : program_options)
{
optstring[optstring_size++]=program_option->letter;
tmp_option.name = (const char*)program_option->name;
if (program_option->parameter){
optstring[optstring_size++]=program_option.letter;
tmp_option.name = (const char*)program_option.name;
if (program_option.parameter){
tmp_option.has_arg=required_argument; //optional_argument does not work on OSX !!
}
else tmp_option.has_arg=no_argument;
if (tmp_option.has_arg==required_argument) optstring[optstring_size++]=':'; //optional_argument does not work on OSX !!
tmp_option.flag = NULL;
tmp_option.val=program_option->letter;
tmp_option.val=program_option.letter;
APPEND_ITEM(&long_options, &options_nb, &tmp_option);
}
// We stop the string and long_options array by a NULL value */
......@@ -209,24 +217,24 @@ static void blc_program_option_interpret(int *argc, char **argv[])
//Wrong option
if (ret=='?') EXIT_ON_ERROR("Invalid program arguments. Use '%s --help' for help", blc_program_name);
FOR_EACH_INV(program_option, blc_program_options, blc_program_options_nb)
for(auto const &program_option : program_options)
{
if (ret == program_option->letter) //TODO see what to do with special char '?' and ':'
if (ret == program_option.letter) //TODO see what to do with special char '?' and ':'
{
if (optarg == NULL) {
if (program_option->default_value) *program_option->string_pt=program_option->default_value;
else *program_option->string_pt="1";
if (program_option.default_value) *program_option.string_pt=program_option.default_value;
else *program_option.string_pt="1";
}
else{
switch (program_option->type){
switch (program_option.type){
case STRING:
*program_option->string_pt = optarg;
*program_option.string_pt = optarg;
break;
//Pipe not in use anymore
case INPUT_PIPE:
SPRINTF(pipe_name, "/tmp/blc_pipes/%s", optarg);
SYSTEM_ERROR_CHECK(freopen(optarg, "r", program_option->pipe), NULL, NULL);
SYSTEM_ERROR_CHECK(freopen(optarg, "r", program_option.pipe), NULL, NULL);
break;
case OUTPUT_PIPE:
mkdir("/tmp/blc_pipes", S_IRWXU);
......@@ -237,14 +245,14 @@ static void blc_program_option_interpret(int *argc, char **argv[])
{
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);
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_SYSTEM_ERROR("Creating output pipe '%s'.", pipe_name);
}
break;
default:EXIT_ON_ERROR("Type %d not managed.", program_option->type);
default:EXIT_ON_ERROR("Type %d not managed.", program_option.type);
}
}
}
......@@ -257,11 +265,11 @@ static void blc_program_option_interpret(int *argc, char **argv[])
FREE(long_options);
//Set default values
FOR_EACH_INV(program_option, blc_program_options, blc_program_options_nb)
for(auto const &program_option:program_options)
{
switch (program_option->type){
switch (program_option.type){
case STRING:
if (*program_option->string_pt==NULL) *program_option->string_pt=(char*)program_option->default_value;
if (*program_option.string_pt==NULL) *program_option.string_pt=(char*)program_option.default_value;
break;
}
}
......@@ -271,19 +279,19 @@ static void blc_program_option_interpret(int *argc, char **argv[])
static void blc_program_interpret_parameters(int *argc, char **argv[]){
char *tmp_parameter=NULL, *tmp_arg;
char *tmp_parameter=NULL, *tmp_arg=nullptr;
int missing_parameters_nb;
int i, j;
int i ;
size_t linecap;
ssize_t parameter_read;
int list_parameters_nb=0;
FOR(i, blc_program_parameters_nb){
switch(blc_program_parameters[i].type){
for(auto const &program_parameter :program_parameters){
switch(program_parameter.type){
case STRING :
if ((*argc)==0){//There is no more argument to interpret
if (blc_program_parameters[i].required_nb){
if (isatty(STDIN_FILENO)) fprintf(stderr, "%s: %s? ", blc_program_parameters[i].help, blc_program_parameters[i].name);
if (program_parameter.required_nb){
if (isatty(STDIN_FILENO)) fprintf(stderr, "%s: %s? ", program_parameter.help, program_parameter.name);
parameter_read=getline(&tmp_parameter, &linecap, stdin);
if (parameter_read==-1){
......@@ -294,15 +302,15 @@ 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;
(*blc_program_parameters[i].string_pt)=tmp_parameter;
(*program_parameter.string_pt)=tmp_parameter;
linecap=0;
tmp_parameter=NULL;
// }else EXIT_ON_ERROR("Missing '%s' argument : %s", blc_program_parameters[i].name, blc_program_parameters[i].help);
}
else *blc_program_parameters[i].string_pt=blc_program_parameters[i].default_value;
else *program_parameter.string_pt=program_parameter.default_value;
}
else {
*blc_program_parameters[i].string_pt=(*argv)[0];
*program_parameter.string_pt=(*argv)[0];
(*argc)--;
(*argv)++;
}
......@@ -310,18 +318,18 @@ static void blc_program_interpret_parameters(int *argc, char **argv[]){
case STRING_LIST:
if (isatty(STDIN_FILENO)) {
missing_parameters_nb = blc_program_parameters[i].required_nb-(*argc-optind-i);
missing_parameters_nb = abs(program_parameter.required_nb)-(*argc);
if (missing_parameters_nb>0){
FOR(j, missing_parameters_nb){
fprintf(stderr, "%s: %s? ", blc_program_parameters[i].help, blc_program_parameters[i].name);
FOR(i, missing_parameters_nb){
fprintf(stderr, "%s: %s(%d) ? ", program_parameter.help, program_parameter.name, i);
linecap=0;
SYSTEM_ERROR_CHECK(parameter_read=getline(&tmp_arg, &linecap, stdin), -1, "Reading input for parameter"); //getline(blc_program_parameters[i].string_pt, sizeof(blc_program_parameters[i].string_pt), stdin), NULL, "Wrong channel input name");
tmp_arg=nullptr; //This forces a new allocation
SYSTEM_ERROR_CHECK(parameter_read=getline(&tmp_arg, &linecap, stdin), -1, "Reading input for parameter");
tmp_arg[parameter_read-1]=0;//Remove the last return;
APPEND_ITEM(argv, argc, &tmp_arg);
APPEND_ITEM(program_parameter.string_list_pt, &list_parameters_nb, &tmp_arg);
}
parameter_read=0;
APPEND_ITEM(argv, argc, &parameter_read);
argc--;//The last NULL parameter does not count
APPEND_ITEM(program_parameter.string_list_pt, &list_parameters_nb, &tmp_arg);
}
}
else {
......@@ -335,23 +343,24 @@ 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(blc_program_parameters[i].string_list_pt, &list_parameters_nb, tmp_parameter);
linecap=0;
fprintf(stderr, "Parameters '%s' %ld\n", tmp_parameter, parameter_read );
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);
}//EXIT_ON_ERROR("Missing '%s' arguments : %s you must have %d arguments", blc_program_parameters[i].name, blc_program_parameters[i].help, missing_parameters_nb);
}
if (blc_program_parameters[i].required_nb==-1){
if (program_parameter.required_nb<=0 ){
while((*argc)){
APPEND_ITEM((blc_program_parameters[i].string_list_pt), &list_parameters_nb, **argv);
APPEND_ITEM(program_parameter.string_list_pt, &list_parameters_nb, *argv);
(*argc)--;
(*argv)++;
}
}
else EXIT_ON_ERROR("Precise number of parameter is not managed");
APPEND_ITEM(blc_program_parameters[i].string_pt, &list_parameters_nb, tmp_parameter);
tmp_parameter=nullptr;
APPEND_ITEM(program_parameter.string_list_pt, &list_parameters_nb, &tmp_parameter);
break;
}
......@@ -374,65 +383,63 @@ void blc_program_parse_args_and_print_title(int *argc, char ***argv){
/*Display format as python argparse*/
void blc_program_args_display_help()
{
struct program_parameter *parameter;
int i, option_length_max, tmp_length=0;
type_program_option *program_option;
//conventions want the help on stderr (avoid to interfere with normal output)
fprintf(stderr, "\nusage: %s", blc_program_name);
option_length_max=0;
FOR_EACH(program_option, blc_program_options, blc_program_options_nb)
for(auto &program_option : program_options)
{
if (program_option->letter)
if (program_option.letter)
{
fprintf(stderr, " [-%c", program_option->letter);
fprintf(stderr, " [-%c", program_option.letter);
tmp_length=3;
if (program_option->parameter){
fprintf(stderr, " %s", program_option->parameter);
tmp_length+=strlen(program_option->parameter);
if (program_option.parameter){
fprintf(stderr, " %s", program_option.parameter);
tmp_length+=strlen(program_option.parameter);
}
fprintf(stderr, "]");
}
option_length_max=MAX(option_length_max, (int)strlen(program_option->name)+tmp_length);
option_length_max=MAX(option_length_max, (int)strlen(program_option.name)+tmp_length);
}
FOR_EACH(parameter, blc_program_parameters, blc_program_parameters_nb)
for(auto const &parameter : program_parameters)
{
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);
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);
option_length_max=MAX(option_length_max, (int)strlen(parameter->name));
option_length_max=MAX(option_length_max, (int)strlen(parameter.name));
}
fprintf(stderr, "\n");
if (program_description) fprintf(stderr, "\n%s\n", program_description);
option_length_max+=10;
if (blc_program_parameters_nb) fprintf(stderr, POSITIONAL_ARGUMENTS_TITLE);
FOR_EACH(parameter, blc_program_parameters, blc_program_parameters_nb){
fprintf(stderr, " %-*s %s\n", option_length_max-2, parameter->name, parameter->help);
if (parameter->default_value) fprintf(stderr, " (default: %s)\n", parameter->default_value);
if (program_parameters.size()) fprintf(stderr, POSITIONAL_ARGUMENTS_TITLE);
for(auto const &parameter: program_parameters){
fprintf(stderr, " %-*s %s\n", option_length_max-2, parameter.name, parameter.help);
if (parameter.default_value) fprintf(stderr, " (default: %s)\n", parameter.default_value);
}
fprintf(stderr, OPTIONAL_ARGUMENTS_TITLE);
FOR_EACH(program_option, blc_program_options, blc_program_options_nb)
for(auto const &program_option :program_options)
{
if (program_option->letter) {
tmp_length=fprintf(stderr, " -%c", program_option->letter);
if ( program_option->name) tmp_length+=fprintf(stderr, ",");
if (program_option.letter) {
tmp_length=fprintf(stderr, " -%c", program_option.letter);
if ( program_option.name) tmp_length+=fprintf(stderr, ",");
}
else tmp_length=0;
if (program_option->name) tmp_length+=fprintf(stderr, " --%s", program_option->name);
if (program_option->parameter) tmp_length+=fprintf(stderr, " %s", program_option->parameter);
if (program_option.name) tmp_length+=fprintf(stderr, " --%s", program_option.name);
if (program_option.parameter) tmp_length+=fprintf(stderr, " %s", program_option.parameter);
fprintf(stderr, "%*c", option_length_max - tmp_length, ' ');
fprintf(stderr, "%s", program_option->help);
if (program_option->default_value) {
fprintf(stderr, "%s", program_option.help);
if (program_option.default_value) {
// if (program_option->type==BLC_CHANNEL) fprintf(stderr, " (default: %s<pid>)\n", program_option->default_value);
// else
fprintf(stderr, " (default: %s)\n", program_option->default_value);
fprintf(stderr, " (default: %s)\n", program_option.default_value);
}
else fprintf(stderr, "\n");
}
......@@ -548,10 +555,10 @@ void blc_program_check_full_parsing(int argc, char **argv){
void blc_quit()
{
if (blc_profile_file) fclose(blc_profile_file);
if (blc_program_id[0]) { //We test if it is not ""
if (blc_program_id==nullptr) EXIT_ON_ERROR("blc_quit has already be called");
else {
fprintf(stderr, "Quitting %s\n", blc_program_id);
FREE(blc_program_id);
if (blc_program_id[0]) FREE(blc_program_id);
}
}
END_EXTERN_C
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