Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
rdma-mwe
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
Titouan Soulard
rdma-mwe
Commits
18460064
Commit
18460064
authored
Jan 04, 2024
by
Titouan Soulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
libpotoml: allow getting parameters from subsets
parent
eb08a9d1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
89 additions
and
6 deletions
+89
-6
common/hashtable.c
common/hashtable.c
+3
-3
include/common/hashtable.h
include/common/hashtable.h
+3
-3
include/libpotoml/toml.h
include/libpotoml/toml.h
+10
-0
libpotoml/toml.c
libpotoml/toml.c
+73
-0
No files found.
common/hashtable.c
View file @
18460064
...
...
@@ -9,7 +9,7 @@
// After these operations, a simple character folding algorithm is
// applied, based on multiplying by a prime number, choosen here for
// operations on chars.
unsigned
char
common_hashtable_compute_hash
(
char
*
str
,
unsigned
char
modulus
)
{
unsigned
char
common_hashtable_compute_hash
(
c
onst
c
har
*
str
,
unsigned
char
modulus
)
{
unsigned
char
result
=
0
;
unsigned
char
extended_char
;
...
...
@@ -62,7 +62,7 @@ void common_hashtable_free(struct CommonHashtableTable *hashtable) {
// Elements are stored in a plane of the hashtable size, and collisions are
// solved by finding the first empty place after the theoretical (hash-given)
// element's position.
struct
CommonHashtableElement
*
common_hashtable_find
(
struct
CommonHashtableTable
*
hashtable
,
char
*
name
)
{
struct
CommonHashtableElement
*
common_hashtable_find
(
struct
CommonHashtableTable
*
hashtable
,
c
onst
c
har
*
name
)
{
struct
CommonHashtableElement
*
el
;
unsigned
char
initial_pos
;
unsigned
char
pos
;
...
...
@@ -80,7 +80,7 @@ struct CommonHashtableElement *common_hashtable_find(struct CommonHashtableTable
return
NULL
;
}
bool
common_hashtable_insert
(
struct
CommonHashtableTable
*
hashtable
,
char
*
name
,
void
*
content
)
{
bool
common_hashtable_insert
(
struct
CommonHashtableTable
*
hashtable
,
c
onst
c
har
*
name
,
void
*
content
)
{
struct
CommonHashtableElement
*
el
;
unsigned
char
initial_pos
;
unsigned
char
pos
;
...
...
include/common/hashtable.h
View file @
18460064
...
...
@@ -17,9 +17,9 @@ struct CommonHashtableElement {
void
*
content
;
};
unsigned
char
common_hashtable_compute_hash
(
char
*
str
,
unsigned
char
modulus
);
unsigned
char
common_hashtable_compute_hash
(
c
onst
c
har
*
str
,
unsigned
char
modulus
);
bool
common_hashtable_initialize
(
struct
CommonHashtableTable
*
hashtable
,
unsigned
char
hashtable_size
);
void
common_hashtable_free
(
struct
CommonHashtableTable
*
hashtable
);
struct
CommonHashtableElement
*
common_hashtable_find
(
struct
CommonHashtableTable
*
hashtable
,
char
*
name
);
bool
common_hashtable_insert
(
struct
CommonHashtableTable
*
hashtable
,
char
*
name
,
void
*
content
);
struct
CommonHashtableElement
*
common_hashtable_find
(
struct
CommonHashtableTable
*
hashtable
,
c
onst
c
har
*
name
);
bool
common_hashtable_insert
(
struct
CommonHashtableTable
*
hashtable
,
c
onst
c
har
*
name
,
void
*
content
);
include/libpotoml/toml.h
View file @
18460064
...
...
@@ -26,7 +26,17 @@ enum PotomlState {
PotomlPropertyValueDouble
=
0x41
,
};
struct
PotomlTomlSubset
{
struct
CommonHashtableTable
*
hashtable
;
char
*
section_name
;
size_t
section_name_length
;
};
char
potoml_toml_parse
(
struct
CommonHashtableTable
*
hashtable
,
char
*
toml
);
char
potoml_toml_parse_file
(
struct
CommonHashtableTable
*
hashtable
,
char
*
toml_file_path
);
struct
PotomlTomlSubset
*
potoml_toml_create_subset
(
struct
CommonHashtableTable
*
hashtable
,
const
char
*
section_name
);
char
*
potoml_toml_get_string
(
struct
PotomlTomlSubset
*
subset
,
const
char
*
property
);
double
potoml_toml_get_double
(
struct
PotomlTomlSubset
*
subset
,
const
char
*
property
);
void
potoml_toml_subset_free
(
struct
PotomlTomlSubset
*
subset
);
void
potoml_toml_free
(
struct
CommonHashtableTable
*
hashtable
);
libpotoml/toml.c
View file @
18460064
...
...
@@ -160,6 +160,79 @@ char potoml_toml_parse_file(struct CommonHashtableTable *hashtable, char *toml_f
return
out
;
}
struct
PotomlTomlSubset
*
potoml_toml_create_subset
(
struct
CommonHashtableTable
*
hashtable
,
const
char
*
section_name
)
{
struct
PotomlTomlSubset
*
subset
;
size_t
section_name_length
=
strlen
(
section_name
);
char
*
owned_section_name
=
malloc
((
section_name_length
+
2
)
*
sizeof
(
char
));
if
(
!
owned_section_name
)
return
NULL
;
// Append dot to section name
strcpy
(
owned_section_name
,
section_name
);
strcat
(
owned_section_name
,
"."
);
subset
=
(
struct
PotomlTomlSubset
*
)
malloc
(
sizeof
(
struct
PotomlTomlSubset
));
if
(
!
subset
)
return
NULL
;
subset
->
hashtable
=
hashtable
;
subset
->
section_name
=
owned_section_name
;
subset
->
section_name_length
=
section_name_length
+
1
;
return
subset
;
}
char
*
potoml_toml_get_string
(
struct
PotomlTomlSubset
*
subset
,
const
char
*
property
)
{
struct
CommonHashtableElement
*
el
;
size_t
property_length
;
char
*
full_property
;
property_length
=
strlen
(
property
);
full_property
=
(
char
*
)
malloc
((
property_length
+
subset
->
section_name_length
+
1
)
*
sizeof
(
char
));
strcpy
(
full_property
,
subset
->
section_name
);
strcat
(
full_property
,
property
);
el
=
common_hashtable_find
(
subset
->
hashtable
,
full_property
);
if
(
!
el
)
{
return
NULL
;
}
free
(
full_property
);
return
(
char
*
)
el
->
content
;
}
double
potoml_toml_get_double
(
struct
PotomlTomlSubset
*
subset
,
const
char
*
property
)
{
struct
CommonHashtableElement
*
el
;
size_t
property_length
;
double
value
;
char
*
full_property
;
value
=
0
.
0
;
property_length
=
strlen
(
property
);
full_property
=
(
char
*
)
malloc
(
property_length
+
subset
->
section_name_length
+
1
);
strcpy
(
full_property
,
subset
->
section_name
);
strcat
(
full_property
,
property
);
el
=
common_hashtable_find
(
subset
->
hashtable
,
full_property
);
if
(
el
)
{
// Clone instead of giving reference for double
value
=
*
((
double
*
)
el
->
content
);
}
free
(
full_property
);
return
value
;
}
void
potoml_toml_subset_free
(
struct
PotomlTomlSubset
*
subset
)
{
free
((
void
*
)
subset
->
section_name
);
free
((
void
*
)
subset
);
}
void
potoml_toml_free
(
struct
CommonHashtableTable
*
hashtable
)
{
unsigned
char
i
;
struct
CommonHashtableElement
*
el
;
...
...
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