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
ec2ea363
Commit
ec2ea363
authored
Dec 30, 2015
by
jltallon
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #46 from jltallon/master
Robustness & bug fixes for tab_width handling
parents
56ead941
5bf47fa1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
15 deletions
+30
-15
lib/libconfig.c
lib/libconfig.c
+25
-7
lib/libconfig.h
lib/libconfig.h
+5
-8
No files found.
lib/libconfig.c
View file @
ec2ea363
...
@@ -47,10 +47,11 @@
...
@@ -47,10 +47,11 @@
#define PATH_TOKENS ":./"
#define PATH_TOKENS ":./"
#define CHUNK_SIZE 16
#define CHUNK_SIZE 16
#define FLOAT_PRECISION
DBL_DIG
#define FLOAT_PRECISION
2
#define TAB2DIGITS(x) (((x) & 0xFF00) >> 8)
#define TAB2DIGITS(x) (((x) & 0xFF00) >> 8)
#define DIGITS2TAB(x) (((x) & 0xFF) << 8)
#define DIGITS2TAB(x) (((x) & 0xFF) << 8)
#define TAB2TAB(x) ((x) & 0xF)
#define _new(T) (T *)calloc(1, sizeof(T))
/* zeroed */
#define _new(T) (T *)calloc(1, sizeof(T))
/* zeroed */
#define _delete(P) free((void *)(P))
#define _delete(P) free((void *)(P))
...
@@ -371,7 +372,7 @@ static void __config_write_value(const config_t *config,
...
@@ -371,7 +372,7 @@ static void __config_write_value(const config_t *config,
fputc
(
'\n'
,
stream
);
fputc
(
'\n'
,
stream
);
if
(
depth
>
1
)
if
(
depth
>
1
)
__config_indent
(
stream
,
depth
,
config
->
tab_width
);
__config_indent
(
stream
,
depth
,
TAB2TAB
(
config
->
tab_width
)
);
}
}
fprintf
(
stream
,
"{
\n
"
);
fprintf
(
stream
,
"{
\n
"
);
...
@@ -387,7 +388,7 @@ static void __config_write_value(const config_t *config,
...
@@ -387,7 +388,7 @@ static void __config_write_value(const config_t *config,
}
}
if
(
depth
>
1
)
if
(
depth
>
1
)
__config_indent
(
stream
,
depth
,
config
->
tab_width
);
__config_indent
(
stream
,
depth
,
TAB2TAB
(
config
->
tab_width
)
);
if
(
depth
>
0
)
if
(
depth
>
0
)
fputc
(
'}'
,
stream
);
fputc
(
'}'
,
stream
);
...
@@ -650,7 +651,7 @@ static void __config_write_setting(const config_t *config,
...
@@ -650,7 +651,7 @@ static void __config_write_setting(const config_t *config,
config
,
CONFIG_OPTION_COLON_ASSIGNMENT_FOR_NON_GROUPS
)
?
':'
:
'='
;
config
,
CONFIG_OPTION_COLON_ASSIGNMENT_FOR_NON_GROUPS
)
?
':'
:
'='
;
if
(
depth
>
1
)
if
(
depth
>
1
)
__config_indent
(
stream
,
depth
,
config
->
tab_width
);
__config_indent
(
stream
,
depth
,
TAB2TAB
(
config
->
tab_width
)
);
if
(
setting
->
name
)
if
(
setting
->
name
)
...
@@ -758,13 +759,30 @@ void config_destroy(config_t *config)
...
@@ -758,13 +759,30 @@ void config_destroy(config_t *config)
}
}
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
void
config_set_tab_width
(
config_t
*
config
,
unsigned
short
width
)
{
/* As per documentation: valid range= 0..15 */
config
->
tab_width
=
(
width
<=
15
)
?
width
:
15
;
}
/* ------------------------------------------------------------------------- */
unsigned
short
config_get_tab_width
(
const
config_t
*
config
)
{
return
TAB2TAB
(
config
->
tab_width
);
}
/* ------------------------------------------------------------------------- */
void
config_set_float_precision
(
config_t
*
config
,
void
config_set_float_precision
(
config_t
*
config
,
unsigned
short
digits
)
unsigned
short
digits
)
{
{
config
->
tab_width
|=
DIGITS2TAB
(
digits
);
config
->
tab_width
|=
DIGITS2TAB
(
digits
);
}
}
unsigned
short
config_get_float_precision
(
config_t
*
config
)
unsigned
short
config_get_float_precision
(
con
st
con
fig_t
*
config
)
{
{
return
TAB2DIGITS
(
config
->
tab_width
);
return
TAB2DIGITS
(
config
->
tab_width
);
}
}
...
@@ -786,8 +804,8 @@ void config_init(config_t *config)
...
@@ -786,8 +804,8 @@ void config_init(config_t *config)
* (ab)using the existing macros' 0x0F mask in order to preserve
* (ab)using the existing macros' 0x0F mask in order to preserve
* API & ABI compatibility ; changes are fully backwards compatible
* API & ABI compatibility ; changes are fully backwards compatible
*/
*/
config
->
tab_width
=
2
;
config
->
tab_width
=
FLOAT_PRECISION
;
config
->
tab_width
|=
DIGITS2TAB
(
FLOAT_PRECISION
);
/* float_digits */
config
->
tab_width
|=
DIGITS2TAB
(
2
);
/* float_digits */
}
}
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
...
...
lib/libconfig.h
View file @
ec2ea363
...
@@ -144,7 +144,11 @@ extern LIBCONFIG_API void config_set_include_dir(config_t *config,
...
@@ -144,7 +144,11 @@ extern LIBCONFIG_API void config_set_include_dir(config_t *config,
extern
LIBCONFIG_API
void
config_set_float_precision
(
config_t
*
config
,
extern
LIBCONFIG_API
void
config_set_float_precision
(
config_t
*
config
,
unsigned
short
digits
);
unsigned
short
digits
);
extern
LIBCONFIG_API
unsigned
short
config_get_float_precision
(
config_t
*
config
);
extern
LIBCONFIG_API
unsigned
short
config_get_float_precision
(
const
config_t
*
config
);
extern
LIBCONFIG_API
void
config_set_tab_width
(
config_t
*
config
,
unsigned
short
width
);
extern
LIBCONFIG_API
unsigned
short
config_get_tab_width
(
const
config_t
*
config
);
extern
LIBCONFIG_API
void
config_init
(
config_t
*
config
);
extern
LIBCONFIG_API
void
config_init
(
config_t
*
config
);
extern
LIBCONFIG_API
void
config_destroy
(
config_t
*
config
);
extern
LIBCONFIG_API
void
config_destroy
(
config_t
*
config
);
...
@@ -298,13 +302,6 @@ extern LIBCONFIG_API int config_lookup_string(const config_t *config,
...
@@ -298,13 +302,6 @@ extern LIBCONFIG_API int config_lookup_string(const config_t *config,
#define
/* short */
config_get_default_format(
/* config_t * */
C) \
#define
/* short */
config_get_default_format(
/* config_t * */
C) \
((C)->default_format)
((C)->default_format)
#define
/* void */
config_set_tab_width(
/* config_t * */
C, \
/* unsigned short */
W) \
(C)->tab_width = ((W) & 0x0F)
#define
/* unsigned char */
config_get_tab_width(
/* const config_t * */
C) \
((C)->tab_width & 0x0F)
#define
/* unsigned short */
config_setting_source_line( \
#define
/* unsigned short */
config_setting_source_line( \
/* const config_setting_t * */
S) \
/* const config_setting_t * */
S) \
((S)->line)
((S)->line)
...
...
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