blc_program.h 4.73 KB
Newer Older
Arnaud Blanchard's avatar
Arnaud Blanchard committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/* Basic Library for C/C++ (blclib)
 Copyright  ETIS — ENSEA, Université de Cergy-Pontoise, CNRS (2011 - 2015)
 
 Author: Arnaud Blanchard
 
 This software is governed by the CeCILL v2.1 license under French law and abiding by the rules of distribution of free software.
 You can use, modify and/ or redistribute the software under the terms of the CeCILL v2.1 license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info".
 As a counterpart to the access to the source code and  rights to copy, modify and redistribute granted by the license,
  users are provided only with a limited warranty and the software's author, the holder of the economic rights,  and the successive licensors have only limited liability.
  In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software,
  that may mean  that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge.
 Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured
  and, more generally, to use and operate it in the same conditions as regards security.
  The fact that you are presently reading this means that you have had knowledge of the CeCILL v2.1 license and that you accept its terms. */

/*
 The usage formating follows the format of argparse in Python ( https://docs.python.org/3/library/argparse.html ).
 Otherwise, we can be inspired from http://docopt.org
 */

/**
 @defgroup blc_program Program
 Functions to parse and manage arguments
  @{*/

#ifndef BLC_PROGRAM_H
#define BLC_PROGRAM_H

Arnaud Blanchard's avatar
Arnaud Blanchard committed
29
#include "blc_core.h"
Arnaud Blanchard's avatar
Arnaud Blanchard committed
30
31
#include "blc_command.h"

32

Arnaud Blanchard's avatar
Arnaud Blanchard committed
33
34
35
36
37
38
START_EXTERN_C

///Set the desciption of the program used for help. A copy of desciption is done (strdup).
void blc_program_set_description(char const *description);

/** Add parameter required or not after the program name.
Arnaud Blanchard's avatar
Arnaud Blanchard committed
39
required_nb:positif number a fix number of parameters, 0 for facultatif parameter
Arnaud Blanchard's avatar
Arnaud Blanchard committed
40
41
results ist a null terminated list of parameters. ( like argv)
 */
42
void blc_program_add_parameter(char const **results, char const *name, int required_nb, char const *help, char const *default_value);
Arnaud Blanchard's avatar
Arnaud Blanchard committed
43
44
45
46
47
48
49
50
51
52

void blc_program_add_multiple_parameters(char ***result_list, char const *name, int required_nb, char const *help);


//void blc_program_add_channel_parameter(blc_channel *channel, int required_nb, char const *help);
//void blc_program_add_channel_option(blc_channel *channel, char letter, char const *long_option, char const *help, char const* default_value);
void blc_program_add_input_pipe_option(FILE *file, char letter, char const *long_option, char const *help, char * default_value);
void blc_program_add_output_pipe_option(FILE *file, char letter, char const *long_option, char const *help, char * default_value);
//void blc_program_add_channel_parameter(blc_channel *channel, int required_nb, char const *help);

Arnaud Blanchard's avatar
Arnaud Blanchard committed
53
54
55
/**Add a possible option to the program. 
 The argument following the option, if any, will be put in result otherwise "1" will be put in result.
 */
56
void blc_program_add_option( char  const**result, char letter, char const *long_option, char const *parameter_type, const char *help, char const* default_value);
Arnaud Blanchard's avatar
Arnaud Blanchard committed
57
58

///Interpret the program arguments and update the results values as it should.
59
60
///The program name will be set in **blc_program_name**.
void blc_program_parse_args(int *argc, char ***argv);
Arnaud Blanchard's avatar
Arnaud Blanchard committed
61
62

///Do program_option_interpret but print the name of the program (argv[0]) underlined with '='.
63
void blc_program_parse_args_and_print_title(int *argc, char ***argv);
Arnaud Blanchard's avatar
Arnaud Blanchard committed
64
65

///Display the different possible argument for the  program.
66
void blc_program_args_display_help();
Arnaud Blanchard's avatar
Arnaud Blanchard committed
67
68
69
70
71
72

/** Start a textual program.
 * This has to be called after defining the parameters of the program
 * - Parse the arguments of the programs
 * - display the title
 * - check the color possibility of the terminal stderr
73
 * - eventually your 'exit_cb' if it not NULL.
Arnaud Blanchard's avatar
Arnaud Blanchard committed
74
75
76
 * - set internal variables setting if the input and output terminal are tty*/
void blc_program_init(int *argc, char ***argv, void(*exit_cb)(void));

77
78
79
80
/** Check wether threre is no more argument to parse. Otherwise publish information and quit. 
 This should be used after 'blc_program_init',  'blc_program_option_interpret', or 'blc_program_option_interpret_and_print_title' if you do not plan to parse them yourself.*/
void blc_program_check_full_parsing(int argc, char **argv);

Arnaud Blanchard's avatar
Arnaud Blanchard committed
81
82
83
84
85
86
87
88
89
/** Stop a textual program
 * - Send a quitting message with the name of the app on stderr.
 * - quit with no error (0).
 */
void blc_quit();

END_EXTERN_C
#endif
///@}