Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
libconfig
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
libconfig
Commits
462425bb
Commit
462425bb
authored
Dec 30, 2015
by
jltallon
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #44 from jltallon/issue41
Merge fix for issue #41 from random85 ; Documentation and fixes by me
parents
f9cc4e36
6c996c08
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
2 deletions
+58
-2
doc/libconfig.texi
doc/libconfig.texi
+4
-0
lib/libconfig.c
lib/libconfig.c
+23
-2
tests/tests.c
tests/tests.c
+31
-0
No files found.
doc/libconfig.texi
View file @
462425bb
...
...
@@ -1091,6 +1091,10 @@ This function removes and destroys the setting named @var{name} from
the parent setting @var
{
parent
}
, which must be a group. Any child
settings of the setting are recursively destroyed as well.
The @var
{
name
}
parameter can also specify a setting @i
{
path
}
relative to
the provided @var
{
parent
}
.
(In that case, the setting will be looked up and removed.)
The function returns @code
{
CONFIG
_
TRUE
}
on success. If @var
{
parent
}
is
not a group, or if it has no setting with the given name, it returns
@code
{
CONFIG
_
FALSE
}
.
...
...
lib/libconfig.c
View file @
462425bb
...
...
@@ -1598,6 +1598,8 @@ int config_setting_remove(config_setting_t *parent, const char *name)
{
unsigned
int
idx
;
config_setting_t
*
setting
;
const
char
*
settingName
;
const
char
*
lastFound
;
if
(
!
parent
)
return
(
CONFIG_FALSE
);
...
...
@@ -1605,10 +1607,29 @@ int config_setting_remove(config_setting_t *parent, const char *name)
if
(
parent
->
type
!=
CONFIG_TYPE_GROUP
)
return
(
CONFIG_FALSE
);
if
(
!
(
setting
=
__config_list_search
(
parent
->
value
.
list
,
name
,
&
idx
)))
setting
=
config_setting_lookup
(
parent
,
name
);
if
(
!
setting
)
return
(
CONFIG_FALSE
);
__config_list_remove
(
parent
->
value
.
list
,
idx
);
settingName
=
name
;
do
{
lastFound
=
settingName
;
while
(
settingName
&&
!
strchr
(
PATH_TOKENS
,
*
settingName
))
++
settingName
;
if
(
*
settingName
==
'\0'
)
{
settingName
=
lastFound
;
break
;
}
}
while
(
*++
settingName
);
if
(
!
(
setting
=
__config_list_search
(
setting
->
parent
->
value
.
list
,
settingName
,
&
idx
)))
return
(
CONFIG_FALSE
);
__config_list_remove
(
setting
->
parent
->
value
.
list
,
idx
);
__config_setting_destroy
(
setting
);
return
(
CONFIG_TRUE
);
...
...
tests/tests.c
View file @
462425bb
...
...
@@ -411,6 +411,36 @@ TT_TEST(BigInt7)
/* ------------------------------------------------------------------------- */
TT_TEST
(
RemoveSetting
)
{
char
*
buf
;
config_t
cfg
;
int
rc
;
config_setting_t
*
rootSetting
;
buf
=
"a:{b:3;c:4;}"
;
config_init
(
&
cfg
);
rc
=
config_read_string
(
&
cfg
,
buf
);
TT_ASSERT_TRUE
(
rc
);
rootSetting
=
config_root_setting
(
&
cfg
);
rc
=
config_setting_remove
(
rootSetting
,
"a.c"
);
TT_ASSERT_TRUE
(
rc
);
// a and a.b are found
rootSetting
=
config_lookup
(
&
cfg
,
"a"
);
TT_EXPECT_PTR_NOTNULL
(
rootSetting
);
rootSetting
=
config_lookup
(
&
cfg
,
"a.b"
);
TT_EXPECT_PTR_NOTNULL
(
rootSetting
);
rootSetting
=
config_lookup
(
&
cfg
,
"a.c"
);
TT_EXPECT_PTR_NULL
(
rootSetting
);
config_destroy
(
&
cfg
);
}
/* ------------------------------------------------------------------------- */
int
main
(
int
argc
,
char
**
argv
)
{
int
failures
;
...
...
@@ -426,6 +456,7 @@ int main(int argc, char **argv)
TT_SUITE_TEST
(
LibConfigTests
,
BigInt5
);
TT_SUITE_TEST
(
LibConfigTests
,
BigInt6
);
TT_SUITE_TEST
(
LibConfigTests
,
BigInt7
);
TT_SUITE_TEST
(
LibConfigTests
,
RemoveSetting
);
TT_SUITE_RUN
(
LibConfigTests
);
failures
=
TT_SUITE_NUM_FAILURES
(
LibConfigTests
);
TT_SUITE_END
(
LibConfigTests
);
...
...
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