Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
5b7ba786
Commit
5b7ba786
authored
Jun 23, 2018
by
Etienne Samson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examples: add a helper for boolean-style options
parent
8e063eb6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
0 deletions
+28
-0
examples/common.c
+19
-0
examples/common.h
+9
-0
No files found.
examples/common.c
View file @
5b7ba786
...
...
@@ -184,6 +184,25 @@ static int match_int_internal(
return
1
;
}
int
match_bool_arg
(
int
*
out
,
struct
args_info
*
args
,
const
char
*
opt
)
{
const
char
*
found
=
args
->
argv
[
args
->
pos
];
if
(
!
strcmp
(
found
,
opt
))
{
*
out
=
1
;
return
1
;
}
if
(
!
strncmp
(
found
,
"--no-"
,
strlen
(
"--no-"
))
&&
!
strcmp
(
found
+
strlen
(
"--no-"
),
opt
+
2
))
{
*
out
=
0
;
return
1
;
}
*
out
=
-
1
;
return
0
;
}
int
is_integer
(
int
*
out
,
const
char
*
str
,
int
allow_negative
)
{
return
match_int_internal
(
out
,
str
,
allow_negative
,
NULL
);
...
...
examples/common.h
View file @
5b7ba786
...
...
@@ -91,6 +91,15 @@ extern int match_int_arg(
int
*
out
,
struct
args_info
*
args
,
const
char
*
opt
,
int
allow_negative
);
/**
* Check current `args` entry against a "bool" `opt` (ie. --[no-]progress).
* If `opt` matches positively, out will be set to 1, or if `opt` matches
* negatively, out will be set to 0, and in both cases 1 will be returned.
* If neither the positive or the negative form of opt matched, out will be -1,
* and 0 will be returned.
*/
extern
int
match_bool_arg
(
int
*
out
,
struct
args_info
*
args
,
const
char
*
opt
);
/**
* Basic output function for plain text diff output
* Pass `FILE*` such as `stdout` or `stderr` as payload (or NULL == `stdout`)
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment