Rework the configuration file interface.
This change will make it easier to extend the configuration file contents to include arbitrary new data structures. Signed-off-by: Richard Cochran <richardcochran@gmail.com>master
parent
32d461d4ed
commit
da69203517
9
config.c
9
config.c
|
@ -20,13 +20,16 @@
|
|||
#include <string.h>
|
||||
#include "config.h"
|
||||
|
||||
static void scan_line(char *s, struct defaultDS *dds, struct port_defaults *pod)
|
||||
static void scan_line(char *s, struct config *cfg)
|
||||
{
|
||||
int val;
|
||||
Integer8 i8;
|
||||
UInteger16 u16;
|
||||
UInteger8 u8;
|
||||
|
||||
struct defaultDS *dds = cfg->dds;
|
||||
struct port_defaults *pod = cfg->pod;
|
||||
|
||||
if (1 == sscanf(s, " twoStepFlag %d", &val)) {
|
||||
|
||||
if (val) /* TODO - implement one step */
|
||||
|
@ -79,7 +82,7 @@ static void scan_line(char *s, struct defaultDS *dds, struct port_defaults *pod)
|
|||
}
|
||||
}
|
||||
|
||||
int config_read(char *name, struct defaultDS *dds, struct port_defaults *pod)
|
||||
int config_read(char *name, struct config *cfg)
|
||||
{
|
||||
FILE *fp;
|
||||
char line[1024];
|
||||
|
@ -92,7 +95,7 @@ int config_read(char *name, struct defaultDS *dds, struct port_defaults *pod)
|
|||
}
|
||||
|
||||
while (fgets(line, sizeof(line), fp)) {
|
||||
scan_line(line, dds, pod);
|
||||
scan_line(line, cfg);
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
|
7
config.h
7
config.h
|
@ -22,6 +22,11 @@
|
|||
|
||||
#include "ds.h"
|
||||
|
||||
int config_read(char *name, struct defaultDS *dds, struct port_defaults *pod);
|
||||
struct config {
|
||||
struct defaultDS *dds;
|
||||
struct port_defaults *pod;
|
||||
};
|
||||
|
||||
int config_read(char *name, struct config *cfg);
|
||||
|
||||
#endif
|
||||
|
|
6
ptp4l.c
6
ptp4l.c
|
@ -32,6 +32,7 @@
|
|||
static int running = 1;
|
||||
static struct defaultDS ds;
|
||||
static struct port_defaults pod;
|
||||
static struct config cfg_settings;
|
||||
|
||||
static int generate_clock_identity(struct ClockIdentity *ci, char *name)
|
||||
{
|
||||
|
@ -175,7 +176,10 @@ int main(int argc, char *argv[])
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (config && config_read(config, &ds, &pod)) {
|
||||
cfg_settings.dds = &ds;
|
||||
cfg_settings.pod = &pod;
|
||||
|
||||
if (config && config_read(config, &cfg_settings)) {
|
||||
fprintf(stderr, "failed to read configuration file\n");
|
||||
return -1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue