Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Matthieu Dorier
codes
Commits
adb0645a
Commit
adb0645a
authored
Mar 09, 2015
by
Jonathan Jenkins
Browse files
typedef tweaking for future refactors
parent
4928a7b8
Changes
9
Hide whitespace changes
Inline
Side-by-side
codes/configfile.h
View file @
adb0645a
...
...
@@ -39,7 +39,7 @@ typedef struct
#define ROOT_SECTION ((SectionHandle) 0)
typedef
struct
struct
ConfigVTable
{
/* File path of the configuration file. Used in computing the relative path
* of file fields */
...
...
@@ -94,20 +94,18 @@ typedef struct
void
*
data
;
}
ConfigVTable
;
typedef
ConfigVTable
*
ConfigHandle
;
};
/* utility debug function: write config tree to stdout;
* If all OK: ret >= 0, otherwise ret < 0 and *err is set
* to error message
* */
int
cf_dump
(
ConfigHandle
cf
,
SectionHandle
h
,
char
**
err
);
int
cf_dump
(
struct
ConfigVTable
*
cf
,
SectionHandle
h
,
char
**
err
);
/* Compare two config trees: return true if equal, false if not */
int
cf_equal
(
ConfigHandle
h1
,
ConfigHandle
h2
);
int
cf_equal
(
struct
ConfigVTable
*
h1
,
struct
ConfigVTable
*
h2
);
static
inline
int
cf_free
(
ConfigHandle
cf
)
static
inline
int
cf_free
(
struct
ConfigVTable
*
cf
)
{
if
(
!
cf
)
return
1
;
...
...
@@ -117,49 +115,49 @@ static inline int cf_free (ConfigHandle cf)
return
1
;
}
static
inline
int
cf_getSectionSize
(
ConfigHandle
cf
,
SectionHandle
section
,
static
inline
int
cf_getSectionSize
(
struct
ConfigVTable
*
cf
,
SectionHandle
section
,
unsigned
int
*
count
)
{
return
cf
->
getSectionSize
(
cf
->
data
,
section
,
count
);
}
static
inline
int
cf_closeSection
(
ConfigHandle
cf
,
SectionHandle
section
)
static
inline
int
cf_closeSection
(
struct
ConfigVTable
*
cf
,
SectionHandle
section
)
{
return
cf
->
closeSection
(
cf
->
data
,
section
);
}
static
inline
int
cf_openSection
(
ConfigHandle
cf
,
SectionHandle
section
,
static
inline
int
cf_openSection
(
struct
ConfigVTable
*
cf
,
SectionHandle
section
,
const
char
*
sectionname
,
SectionHandle
*
newsection
)
{
return
cf
->
openSection
(
cf
->
data
,
section
,
sectionname
,
newsection
);
}
static
inline
int
cf_getKey
(
ConfigHandle
cf
,
SectionHandle
section
,
static
inline
int
cf_getKey
(
struct
ConfigVTable
*
cf
,
SectionHandle
section
,
const
char
*
keyname
,
char
*
buf
,
size_t
maxbuf
)
{
return
cf
->
getKey
(
cf
->
data
,
section
,
keyname
,
buf
,
maxbuf
);
}
static
inline
int
cf_getMultiKey
(
ConfigHandle
cf
,
SectionHandle
section
,
static
inline
int
cf_getMultiKey
(
struct
ConfigVTable
*
cf
,
SectionHandle
section
,
const
char
*
keyname
,
char
***
buf
,
size_t
*
e
)
{
return
cf
->
getMultiKey
(
cf
->
data
,
section
,
keyname
,
buf
,
e
);
}
static
inline
int
cf_listSection
(
ConfigHandle
cf
,
SectionHandle
section
,
static
inline
int
cf_listSection
(
struct
ConfigVTable
*
cf
,
SectionHandle
section
,
SectionEntry
*
entries
,
size_t
*
maxentries
)
{
return
cf
->
listSection
(
cf
->
data
,
section
,
entries
,
maxentries
);
}
static
inline
int
cf_createSection
(
ConfigHandle
handle
,
SectionHandle
static
inline
int
cf_createSection
(
struct
ConfigVTable
*
handle
,
SectionHandle
section
,
const
char
*
name
,
SectionHandle
*
newsection
)
{
return
handle
->
createSection
(
handle
->
data
,
section
,
name
,
newsection
);
}
static
inline
int
cf_createKey
(
ConfigHandle
handle
,
SectionHandle
section
,
static
inline
int
cf_createKey
(
struct
ConfigVTable
*
handle
,
SectionHandle
section
,
const
char
*
key
,
const
char
**
data
,
unsigned
int
count
)
{
return
handle
->
createKey
(
handle
->
data
,
section
,
key
,
data
,
count
);
...
...
codes/configuration.h
View file @
adb0645a
...
...
@@ -53,6 +53,8 @@ typedef struct config_lpgroups_s
config_anno_map_t
lpannos
[
CONFIGURATION_MAX_TYPES
];
}
config_lpgroups_t
;
typedef
struct
ConfigVTable
*
ConfigHandle
;
/*
* Load a configuration on the system (collectively)
*
...
...
codes/txt_configfile.h
View file @
adb0645a
...
...
@@ -21,31 +21,31 @@ extern "C" {
/**
* returns Config
Hand
le, if all is OK *err is set to 0,
* returns Config
VTab
le, if all is OK *err is set to 0,
* otherwise *err is set to a pointer to the error string
* (which needs to be freed by the user)
* NOTE that even if an error occurred, a partial Config
Hand
le tree
* NOTE that even if an error occurred, a partial Config
VTab
le tree
* can be returned.
*/
ConfigHandle
txtfile_openConfig
(
const
char
*
filename
,
char
**
err
);
struct
ConfigVTable
*
txtfile_openConfig
(
const
char
*
filename
,
char
**
err
);
/**
* returns Config
Hand
le, if all is OK *err is set to 0,
* returns Config
VTab
le, if all is OK *err is set to 0,
* otherwise *err is set to a pointer to the error string
* (which needs to be freed by the user)
* NOTE that even if an error occurred, a partial Config
Hand
le tree
* NOTE that even if an error occurred, a partial Config
VTab
le tree
* can be returned.
*/
ConfigHandle
txtfile_openStream
(
FILE
*
f
,
char
**
err
);
struct
ConfigVTable
*
txtfile_openStream
(
FILE
*
f
,
char
**
err
);
/**
* Write Config
Hand
le to disk (in a format supported by _open).
* Write Config
VTab
le to disk (in a format supported by _open).
* Returns >=0 if all went OK, < 0 otherwise in which
* case *err is set to a pointer to an error string, which needs to be
* freed by the user.
*/
int
txtfile_writeConfig
(
ConfigHandle
h
,
SectionHandle
h2
,
FILE
*
out
,
char
**
err
);
int
txtfile_writeConfig
(
struct
ConfigVTable
*
h
,
SectionHandle
h2
,
FILE
*
out
,
char
**
err
);
#ifdef __cplusplus
}
/* extern "C" */
...
...
src/modelconfig/configfile.c
View file @
adb0645a
...
...
@@ -18,7 +18,7 @@
#include "codes/configfile.h"
#include "codes/txt_configfile.h"
static
int
cf_equal_helper
(
ConfigHandle
h1
,
SectionHandle
s1
,
ConfigHandle
h2
,
static
int
cf_equal_helper
(
struct
ConfigVTable
*
h1
,
SectionHandle
s1
,
struct
ConfigVTable
*
h2
,
SectionHandle
s2
)
{
unsigned
int
sectionsize1
;
...
...
@@ -169,13 +169,13 @@ static int cf_equal_helper (ConfigHandle h1, SectionHandle s1, ConfigHandle h2,
return
ret
;
}
int
cf_equal
(
ConfigHandle
h1
,
ConfigHandle
h2
)
int
cf_equal
(
struct
ConfigVTable
*
h1
,
struct
ConfigVTable
*
h2
)
{
return
cf_equal_helper
(
h1
,
ROOT_SECTION
,
h2
,
ROOT_SECTION
);
}
int
cf_dump
(
ConfigHandle
cf
,
SectionHandle
h
,
char
**
err
)
int
cf_dump
(
struct
ConfigVTable
*
cf
,
SectionHandle
h
,
char
**
err
)
{
return
txtfile_writeConfig
(
cf
,
h
,
stdout
,
err
);
}
...
...
src/modelconfig/configglue.c
View file @
adb0645a
...
...
@@ -47,7 +47,7 @@ int cfgp_parser_error(ParserParams * p, const char * err,
return
-
1
;
}
void
cfgp_initparams
(
ParserParams
*
p
,
ConfigHandle
h
)
void
cfgp_initparams
(
ParserParams
*
p
,
struct
ConfigVTable
*
h
)
{
p
->
configfile
=
h
;
p
->
stacktop
=
0
;
...
...
src/modelconfig/configglue.h
View file @
adb0645a
...
...
@@ -14,7 +14,7 @@
typedef
struct
{
ConfigHandle
configfile
;
struct
ConfigVTable
*
configfile
;
SectionHandle
sectionstack
[
20
];
unsigned
int
stacktop
;
...
...
@@ -35,9 +35,9 @@ typedef struct
char
*
lexer_error_string
;
}
ParserParams
;
void
cfgp_initparams
(
ParserParams
*
p
,
ConfigHandle
h
);
void
cfgp_initparams
(
ParserParams
*
p
,
struct
ConfigVTable
*
h
);
/* Free private data (but not the Config
Hand
le) */
/* Free private data (but not the Config
VTab
le) */
void
cfgp_freeparams
(
ParserParams
*
p
);
int
cfgp_parser_error
(
ParserParams
*
p
,
const
char
*
str
,
...
...
@@ -46,7 +46,7 @@ int cfgp_parser_error (ParserParams * p, const char* str,
int
cfgp_lex_error
(
ParserParams
*
p
,
int
lineno
,
int
colno
,
const
char
*
msg
);
/* Return true if parse and lex went ok; false otherwise, and puts
* error message in buf. Note: Config
Hand
le might still contain the partial
* error message in buf. Note: Config
VTab
le might still contain the partial
* parsed tree */
int
cfgp_parse_ok
(
const
ParserParams
*
p
,
char
*
buf
,
int
bufsize
);
...
...
src/modelconfig/configstoreadapter.c
View file @
adb0645a
...
...
@@ -211,7 +211,7 @@ static int cfsa_getSectionSize (void * handle, SectionHandle section,
static
ConfigVTable
cfsa_template
=
{
static
struct
ConfigVTable
cfsa_template
=
{
.
getKey
=
cfsa_getKey
,
.
getMultiKey
=
cfsa_getMultiKey
,
.
listSection
=
cfsa_listSection
,
...
...
@@ -224,15 +224,15 @@ static ConfigVTable cfsa_template = {
.
data
=
0
};
ConfigHandle
cfsa_create
(
mcs_entry
*
e
)
struct
ConfigVTable
*
cfsa_create
(
mcs_entry
*
e
)
{
ConfigHandle
newh
=
malloc
(
sizeof
(
ConfigVTable
));
struct
ConfigVTable
*
newh
=
malloc
(
sizeof
(
struct
ConfigVTable
));
*
newh
=
cfsa_template
;
newh
->
data
=
e
;
return
newh
;
}
ConfigHandle
cfsa_create_empty
()
struct
ConfigVTable
*
cfsa_create_empty
()
{
return
cfsa_create
(
mcs_initroot
());
}
...
...
src/modelconfig/configstoreadapter.h
View file @
adb0645a
...
...
@@ -15,9 +15,9 @@ extern "C" {
#endif
/* Create a new configfile interface backed by a configstore */
ConfigHandle
cfsa_create
(
mcs_entry
*
e
);
struct
ConfigVTable
*
cfsa_create
(
mcs_entry
*
e
);
ConfigHandle
cfsa_create_empty
();
struct
ConfigVTable
*
cfsa_create_empty
();
#ifdef __cplusplus
}
/* extern "C" */
...
...
src/modelconfig/txt_configfile.c
View file @
adb0645a
...
...
@@ -30,10 +30,10 @@ static inline int mymin (int v1, int v2)
return
(
v1
<
v2
?
v1
:
v2
);
}
static
int
dump_section
(
FILE
*
f
,
ConfigHandle
h
,
SectionHandle
s
,
unsigned
static
int
dump_section
(
FILE
*
f
,
struct
ConfigVTable
*
h
,
SectionHandle
s
,
unsigned
int
indent
);
static
int
dump_entry
(
FILE
*
f
,
ConfigHandle
h
,
SectionHandle
s
,
static
int
dump_entry
(
FILE
*
f
,
struct
ConfigVTable
*
h
,
SectionHandle
s
,
unsigned
int
indent
,
const
SectionEntry
*
entry
)
{
int
ret
=
1
;
...
...
@@ -89,7 +89,7 @@ static int dump_entry (FILE * f, ConfigHandle h, SectionHandle s,
return
ret
;
}
static
int
dump_section
(
FILE
*
f
,
ConfigHandle
h
,
SectionHandle
s
,
unsigned
static
int
dump_section
(
FILE
*
f
,
struct
ConfigVTable
*
h
,
SectionHandle
s
,
unsigned
int
indent
)
{
unsigned
int
sectionsize
;
...
...
@@ -129,7 +129,7 @@ fail:
}
int
txtfile_writeConfig
(
ConfigHandle
cf
,
SectionHandle
h
,
FILE
*
f
,
char
**
err
)
int
txtfile_writeConfig
(
struct
ConfigVTable
*
cf
,
SectionHandle
h
,
FILE
*
f
,
char
**
err
)
{
int
ret
;
assert
(
err
);
...
...
@@ -146,7 +146,7 @@ int txtfile_writeConfig (ConfigHandle cf, SectionHandle h, FILE * f, char ** err
return
ret
;
}
ConfigHandle
txtfile_openStream
(
FILE
*
f
,
char
**
err
)
struct
ConfigVTable
*
txtfile_openStream
(
FILE
*
f
,
char
**
err
)
{
long
size
;
ParserParams
p
;
...
...
@@ -201,10 +201,10 @@ ConfigHandle txtfile_openStream (FILE * f, char ** err)
return
p
.
configfile
;
}
ConfigHandle
txtfile_openConfig
(
const
char
*
filename
,
char
**
error
)
struct
ConfigVTable
*
txtfile_openConfig
(
const
char
*
filename
,
char
**
error
)
{
FILE
*
f
;
ConfigHandle
ret
;
struct
ConfigVTable
*
ret
;
f
=
fopen
(
filename
,
"r"
);
...
...
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