Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
blc_program
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blaar
blibs
blc_program
Commits
e0117410
Commit
e0117410
authored
6 years ago
by
Arnaud Blanchard
Browse files
Options
Downloads
Patches
Plain Diff
Update README.md
parent
8a20cfbc
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
README.md
+67
-6
67 additions, 6 deletions
README.md
with
67 additions
and
6 deletions
README.md
+
67
−
6
View file @
e0117410
BLC program
===========
Copyright :
[
ETIS
](
http://www.etis.ensea.fr/neurocyber
)
- ENSEA, University of Cergy-Pontoise, CNRS (2011-2016)
Author :
[
Arnaud Blanchard
](
http://arnaudblanchard.thoughtsheet.com
)
Licence :
[
CeCILL v2.1
](
http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
)
Library providing command line program facilities
### Library providing command line program facilities
-
Parsing arguments
-
Interacting with the user
-
Interacting with the user in a terminal
BLC program
============
Exemple based on **t_parse_arguments**
------------------------------------------------
code
```
c++
#include
"blc_program.h"
int
main
(
int
argc
,
char
**
argv
){
char
const
*
text_option
,
*
first_parameter
,
*
optional_parameter
,
*
flag
;
//The text that appear when help is called.
blc_program_set_description
(
"Program to show how to parse arguments."
);
//Define the options to be parsed with 'blc_program_option_interpret'.
blc_program_add_option
(
&
flag
,
'f'
,
"flag"
,
NULL
,
"Show how to read a flag"
,
NULL
);
blc_program_add_option
(
&
text_option
,
's'
,
"simple"
,
"string"
,
"Simple text as option"
,
"Default text"
);
//Require one argument.
blc_program_add_parameter
(
&
first_parameter
,
"string"
,
1
,
"Required parameter "
,
NULL
);
//Accept a second optional argument.
blc_program_add_parameter
(
&
optional_parameter
,
"string"
,
0
,
"Show how to accept simple text as option"
,
NULL
);
//Interprets the arguments, associates variables and print program name as title.
blc_program_option_interpret_and_print_title
(
&
argc
,
&
argv
);
//We display on stderr. It is a good habit to use for interaction with the user
fprintf
(
stderr
,
"Display help:
\n
"
);
//Display all the possible options / arguments
blc_program_option_display_help
();
//After interpret options, we can use the variable **blc_program_name**
fprintf
(
stderr
,
"Parsed arguments:
\n
"
);
//We present the parsed variables
fprintf
(
stderr
,
"- The simple option text is: '%s'
\n
"
,
text_option
);
if
(
flag
)
fprintf
(
stderr
,
"- The flag is activated, its content (usually useless) is : '%s'
\n
"
,
flag
);
else
fprintf
(
stderr
,
"- The flag is not activated.
\n
"
);
fprintf
(
stderr
,
"- The first argument is: '%s'
\n
"
,
first_parameter
);
if
(
optional_parameter
)
fprintf
(
stderr
,
"- The optional argument is: '%s'
\n
"
,
optional_parameter
);
else
fprintf
(
stderr
,
"- No optional argument
\n
"
);
return
0
;
}
```
Execute:
`../run.sh t_parse_arguments arg1 arg2`
Result
```
Display help:
usage: t_parse_args [-f] [-s string] string [string]
Program to show how to parse arguments.
positional arguments:
string Required parameter string Show how to accept simple text as option
optional arguments:
-f, --flag Show how to read a flag
-s, --simple string Simple text as option (default: Default text)
Parsed arguments:
- The simple option text is: 'Default text'
- The flag is not activated.
- The first argument is: 'arg1'
- The optional argument is: 'arg2'
```
### [Online documentation](https://framagit.org/blaar/blc_program/wikis/home)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment