Commit c3cd1cd0 authored by Arnaud Blanchard's avatar Arnaud Blanchard
Browse files

Add blc_add_arg in blc_tools (it was in blc_program before)

parent af871b3f
......@@ -276,6 +276,18 @@ void *insert_item(const char *file, const char *function, int line, void** point
void remove_item_position(const char *file, const char *function, int line, void** pointer, size_t pointer_content_size, int *items_nb, int position);
int get_item_position(const char *file, const char *function, int line, void const* const* array_pt, size_t pointer_content_size, int items_nb, size_t item_size, void* searched_item_pt);
///Add an argument to the list argv of arguments. Add eventually a value as well.
void blc_add_arg( int *argc, char ***argv, char const *arg, char const *value);
///Allocate and fill a command line with the array of argument. The array must be terminated by a NULL argument and must the returned command line me be freed after use.
///It does not handle spaces in argument !!!
char *blc_create_command_line_from_argv(char const *const *argv);
///Allocate and fill an array of argument by spiting the command_line. The array is terminated by a NULL argument and it must be freed after used.
///It does not handle spaces in argument !!!
char * const*blc_create_argv_from_command_line(char const *command_line);
END_EXTERN_C
///@}
#endif /* BLC_TOOLS_H */
......
......@@ -261,7 +261,7 @@ char const *blc_get_filename_extension(char const *filename){
next_ext=strchr(filename, '.');
if (next_ext==NULL) return NULL;
do{
ext=next_ext;
next_ext=strchr(ext+1, '.');
......@@ -270,11 +270,50 @@ char const *blc_get_filename_extension(char const *filename){
return ext+1;
}
extern "C"{
START_EXTERN_C
char* blc_uint32_to_string(uint32_t *string, uint32_t x){
*string=htonl(x);
return (char*)string;
}
void blc_add_arg( int *argc, char ***argv, char const *arg, char const *value){
APPEND_ITEM(argv, argc, &arg);
if (value!=NULL) APPEND_ITEM(argv, argc, &value);
}
char *blc_create_command_line_from_argv(char const *const *argv){
int command_line_size, i;
char *command_line, *pos;
command_line_size=0;
for(i=0; argv[i] != NULL; i++) command_line_size+=strlen(argv[i])+1; // + 1 for the space
command_line=MANY_ALLOCATIONS(command_line_size+1, char);
pos=command_line;
for(i=0; argv[i] != NULL; i++)
pos+=sprintf(pos, "%s ", argv[i]);
return command_line;
}
char * const*blc_create_argv_from_command_line(char const *command_line)
{
char * const*argv=NULL;
char *arg_pt;
char const *pos;
char tmp_arg[NAME_MAX+1];
int length, argc=0;
pos=command_line;
while(sscanf(pos, SCAN_CONV(NAME_MAX, "s")"%n", tmp_arg, &length)==1)
{
arg_pt = strdup(tmp_arg);
APPEND_ITEM(&argv, &argc, &arg_pt);
pos+=length;
}
arg_pt=NULL;
APPEND_ITEM(&argv, &argc, &arg_pt);
return argv;
}
END_EXTERN_C
Supports Markdown
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