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
f53e5de4
Unverified
Commit
f53e5de4
authored
Dec 19, 2019
by
Mark Lindner
Committed by
GitHub
Dec 19, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #152 from thomastrapp/master
Add option to override duplicate settings
parents
36ddd216
56a5cdb8
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
101 additions
and
2 deletions
+101
-2
doc/libconfig.texi
doc/libconfig.texi
+13
-0
lib/libconfig.c
lib/libconfig.c
+6
-1
lib/libconfig.h
lib/libconfig.h
+1
-0
lib/libconfig.h++
lib/libconfig.h++
+2
-1
tests/testdata/override_setting.cfg
tests/testdata/override_setting.cfg
+20
-0
tests/tests.c
tests/tests.c
+59
-0
No files found.
doc/libconfig.texi
View file @
f53e5de4
...
...
@@ -950,6 +950,13 @@ when writing floating point values (corresponding to @code{printf()}
This option controls whether the @code
{
config
_
write
_
file()
}
function performs
an @i
{
fsync
}
operation after writing the configuration and before closing the
file. By default this option is turned off.
@item CONFIG
_
OPTION
_
ALLOW
_
OVERRIDES
(@b
{
Since @i
{
v1.7.3
}}
)
This option controls whether duplicate settings override previous settings
with the same name. If this option is turned off, duplicate settings are
rejected. By default this option is turned off.
@end table
@end deftypefun
...
...
@@ -1596,6 +1603,12 @@ This option controls whether the @code{writeFile()} method performs an @i{fsync}
operation after writing the configuration and before closing the file. By
default this option is turned off.
@item Config::OptionAllowOverrides
(@b
{
Since @i
{
v1.7.3
}}
)
This option controls whether duplicate settings override previous settings
with the same name. If this option is turned off, duplicate settings are
rejected. By default this option is turned off.
@end table
@end deftypemethod
...
...
lib/libconfig.c
View file @
f53e5de4
...
...
@@ -1628,7 +1628,12 @@ config_setting_t *config_setting_add(config_setting_t *parent,
}
if
(
config_setting_get_member
(
parent
,
name
)
!=
NULL
)
return
(
NULL
);
/* already exists */
{
if
(
config_get_option
(
parent
->
config
,
CONFIG_OPTION_ALLOW_OVERRIDES
))
config_setting_remove
(
parent
,
name
);
else
return
(
NULL
);
/* already exists */
}
return
(
config_setting_create
(
parent
,
name
,
type
));
}
...
...
lib/libconfig.h
View file @
f53e5de4
...
...
@@ -65,6 +65,7 @@ extern "C" {
#define CONFIG_OPTION_OPEN_BRACE_ON_SEPARATE_LINE 0x10
#define CONFIG_OPTION_ALLOW_SCIENTIFIC_NOTATION 0x20
#define CONFIG_OPTION_FSYNC 0x40
#define CONFIG_OPTION_ALLOW_OVERRIDES 0x80
#define CONFIG_TRUE (1)
#define CONFIG_FALSE (0)
...
...
lib/libconfig.h++
View file @
f53e5de4
...
...
@@ -455,7 +455,8 @@ class LIBCONFIGXX_API Config
OptionColonAssignmentForNonGroups
=
0x08
,
OptionOpenBraceOnSeparateLine
=
0x10
,
OptionAllowScientificNotation
=
0x20
,
OptionFsync
=
0x40
OptionFsync
=
0x40
,
OptionAllowOverrides
=
0x80
};
Config
();
...
...
tests/testdata/override_setting.cfg
0 → 100644
View file @
f53e5de4
group:
{
@include "more.cfg"
message = "overridden";
array = (1,2);
array = (3);
inner = {
name = "value";
none = "none";
};
inner = {
name = "other-value";
name = "overridden";
other = "other";
};
};
int = 1;
int = 2;
string = "value";
string = "overridden";
tests/tests.c
View file @
f53e5de4
...
...
@@ -487,6 +487,64 @@ TT_TEST(EscapedStrings)
/* ------------------------------------------------------------------------- */
TT_TEST
(
OverrideSetting
)
{
config_t
cfg
;
int
ok
;
int
ival
;
const
char
*
str
;
config_init
(
&
cfg
);
config_set_options
(
&
cfg
,
CONFIG_OPTION_ALLOW_OVERRIDES
);
config_set_include_dir
(
&
cfg
,
"./testdata"
);
ok
=
config_read_file
(
&
cfg
,
"testdata/override_setting.cfg"
);
if
(
!
ok
)
{
printf
(
"error: %s:%d
\n
"
,
config_error_text
(
&
cfg
),
config_error_line
(
&
cfg
));
}
TT_ASSERT_TRUE
(
ok
);
ok
=
config_lookup_string
(
&
cfg
,
"group.message"
,
&
str
);
TT_ASSERT_TRUE
(
ok
);
TT_ASSERT_STR_EQ
(
"overridden"
,
str
);
ok
=
config_lookup_string
(
&
cfg
,
"group.inner.name"
,
&
str
);
TT_ASSERT_TRUE
(
ok
);
TT_ASSERT_STR_EQ
(
"overridden"
,
str
);
ok
=
config_lookup_string
(
&
cfg
,
"group.inner.other"
,
&
str
);
TT_ASSERT_TRUE
(
ok
);
TT_ASSERT_STR_EQ
(
"other"
,
str
);
ok
=
config_lookup_string
(
&
cfg
,
"group.inner.none"
,
&
str
);
TT_ASSERT_FALSE
(
ok
);
ok
=
config_lookup_string
(
&
cfg
,
"group.inner.other"
,
&
str
);
TT_ASSERT_TRUE
(
ok
);
TT_ASSERT_STR_EQ
(
"other"
,
str
);
ok
=
config_lookup_string
(
&
cfg
,
"string"
,
&
str
);
TT_ASSERT_TRUE
(
ok
);
TT_ASSERT_STR_EQ
(
"overridden"
,
str
);
ok
=
config_lookup_int
(
&
cfg
,
"int"
,
&
ival
);
TT_ASSERT_TRUE
(
ok
);
TT_ASSERT_INT_EQ
(
ival
,
2
);
ok
=
config_lookup_int
(
&
cfg
,
"group.array.[0]"
,
&
ival
);
TT_ASSERT_TRUE
(
ok
);
TT_ASSERT_INT_EQ
(
ival
,
3
);
ok
=
config_lookup_int
(
&
cfg
,
"group.array.[1]"
,
&
ival
);
TT_ASSERT_FALSE
(
ok
);
config_destroy
(
&
cfg
);
}
/* ------------------------------------------------------------------------- */
int
main
(
int
argc
,
char
**
argv
)
{
int
failures
;
...
...
@@ -504,6 +562,7 @@ int main(int argc, char **argv)
TT_SUITE_TEST
(
LibConfigTests
,
BigInt7
);
TT_SUITE_TEST
(
LibConfigTests
,
RemoveSetting
);
TT_SUITE_TEST
(
LibConfigTests
,
EscapedStrings
);
TT_SUITE_TEST
(
LibConfigTests
,
OverrideSetting
);
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