Commit 55732deb authored by Raphael Defosseux's avatar Raphael Defosseux

Astyling the common files

Signed-off-by: default avatarRaphael Defosseux <raphael.defosseux@eurecom.fr>
parent df5fe4ff
This diff is collapsed.
This diff is collapsed.
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
*/ */
/*! \file common/config/config_load_configmodule.h /*! \file common/config/config_load_configmodule.h
* \brief: configuration module, include file to be used by the source code calling the * \brief: configuration module, include file to be used by the source code calling the
* configuration module initialization * configuration module initialization
* \author Francois TABURET * \author Francois TABURET
* \date 2017 * \date 2017
* \version 0.1 * \version 0.1
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
* \warning * \warning
*/ */
#ifndef INCLUDE_CONFIG_LOADCONFIGMODULE_H #ifndef INCLUDE_CONFIG_LOADCONFIGMODULE_H
#define INCLUDE_CONFIG_LOADCONFIGMODULE_H #define INCLUDE_CONFIG_LOADCONFIGMODULE_H
#include <string.h> #include <string.h>
...@@ -61,8 +61,7 @@ typedef int(*configmodule_initfunc_t)(char *cfgP[],int numP); ...@@ -61,8 +61,7 @@ typedef int(*configmodule_initfunc_t)(char *cfgP[],int numP);
typedef int(*configmodule_getfunc_t)(paramdef_t *,int numparams, char *prefix); typedef int(*configmodule_getfunc_t)(paramdef_t *,int numparams, char *prefix);
typedef int(*configmodule_getlistfunc_t)(paramlist_def_t *, paramdef_t *,int numparams, char *prefix); typedef int(*configmodule_getlistfunc_t)(paramlist_def_t *, paramdef_t *,int numparams, char *prefix);
typedef void(*configmodule_endfunc_t)(void); typedef void(*configmodule_endfunc_t)(void);
typedef struct configmodule_interface typedef struct configmodule_interface {
{
int argc; int argc;
char **argv; char **argv;
uint32_t *argv_info; uint32_t *argv_info;
...@@ -75,7 +74,7 @@ typedef struct configmodule_interface ...@@ -75,7 +74,7 @@ typedef struct configmodule_interface
configmodule_endfunc_t end; configmodule_endfunc_t end;
uint32_t numptrs; uint32_t numptrs;
uint32_t rtflags; uint32_t rtflags;
char *ptrs[CONFIG_MAX_ALLOCATEDPTRS]; char *ptrs[CONFIG_MAX_ALLOCATEDPTRS];
} configmodule_interface_t; } configmodule_interface_t;
#ifdef CONFIG_LOADCONFIG_MAIN #ifdef CONFIG_LOADCONFIG_MAIN
...@@ -85,17 +84,17 @@ static char config_helpstr [] = "\n lte-softmodem -O [config mode]<:dbgl[debugfl ...@@ -85,17 +84,17 @@ static char config_helpstr [] = "\n lte-softmodem -O [config mode]<:dbgl[debugfl
debugflags can also be defined in the config_libconfig section of the config file\n \ debugflags can also be defined in the config_libconfig section of the config file\n \
debugflags: mask, 1->print parameters, 2->print memory allocations debug messages\n \ debugflags: mask, 1->print parameters, 2->print memory allocations debug messages\n \
4->print command line processing debug messages\n "; 4->print command line processing debug messages\n ";
#define CONFIG_SECTIONNAME "config" #define CONFIG_SECTIONNAME "config"
#define CONFIGPARAM_DEBUGFLAGS_IDX 0 #define CONFIGPARAM_DEBUGFLAGS_IDX 0
static paramdef_t Config_Params[] = { static paramdef_t Config_Params[] = {
/*-----------------------------------------------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------------------------------------------*/
/* config parameters for config module */ /* config parameters for config module */
/* optname helpstr paramflags XXXptr defXXXval type numelt */ /* optname helpstr paramflags XXXptr defXXXval type numelt */
/*-----------------------------------------------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------------------------------------------*/
{"debugflags", config_helpstr, 0, uptr:NULL, defintval:0, TYPE_MASK, 0}, {"debugflags", config_helpstr, 0, uptr:NULL, defintval:0, TYPE_MASK, 0},
}; };
#else #else
...@@ -104,7 +103,7 @@ extern configmodule_interface_t *cfgptr; ...@@ -104,7 +103,7 @@ extern configmodule_interface_t *cfgptr;
#define printf_params(...) if ( (cfgptr->rtflags & (CONFIG_PRINTPARAMS)) != 0 ) { printf ( __VA_ARGS__ ); } #define printf_params(...) if ( (cfgptr->rtflags & (CONFIG_PRINTPARAMS)) != 0 ) { printf ( __VA_ARGS__ ); }
#define printf_ptrs(...) if ( (cfgptr->rtflags & (CONFIG_DEBUGPTR)) != 0 ) { printf ( __VA_ARGS__ ); } #define printf_ptrs(...) if ( (cfgptr->rtflags & (CONFIG_DEBUGPTR)) != 0 ) { printf ( __VA_ARGS__ ); }
#define printf_cmdl(...) if ( (cfgptr->rtflags & (CONFIG_DEBUGCMDLINE)) != 0 ) { printf ( __VA_ARGS__ ); } #define printf_cmdl(...) if ( (cfgptr->rtflags & (CONFIG_DEBUGCMDLINE)) != 0 ) { printf ( __VA_ARGS__ ); }
#define CONFIG_ENABLECMDLINEONLY (1<<1) #define CONFIG_ENABLECMDLINEONLY (1<<1)
......
...@@ -59,78 +59,77 @@ ...@@ -59,78 +59,77 @@
#define CONFIG_MAX_NUMCHECKVAL 20 #define CONFIG_MAX_NUMCHECKVAL 20
typedef struct paramdef paramdef_t; typedef struct paramdef paramdef_t;
typedef union checkedparam { typedef union checkedparam {
struct { struct {
int (*f1)(paramdef_t *param); /* check an integer against a list of authorized values */ int (*f1)(paramdef_t *param); /* check an integer against a list of authorized values */
int okintval[CONFIG_MAX_NUMCHECKVAL]; /* integer array, store possible values */ int okintval[CONFIG_MAX_NUMCHECKVAL]; /* integer array, store possible values */
int num_okintval; /* number of valid values in the checkingval array */ int num_okintval; /* number of valid values in the checkingval array */
} s1; } s1;
struct { struct {
int (*f1a)(paramdef_t *param); /* check an integer against a list of authorized values and set param value */ int (*f1a)(paramdef_t *param); /* check an integer against a list of authorized values and set param value */
/* to the corresponding item in setintval array (mainly for RRC params) */ /* to the corresponding item in setintval array (mainly for RRC params) */
int okintval[CONFIG_MAX_NUMCHECKVAL]; /* integer array, store possible values in config file */ int okintval[CONFIG_MAX_NUMCHECKVAL]; /* integer array, store possible values in config file */
int setintval[CONFIG_MAX_NUMCHECKVAL]; /* integer array, values set in the paramdef structure */ int setintval[CONFIG_MAX_NUMCHECKVAL]; /* integer array, values set in the paramdef structure */
int num_okintval; /* number of valid values in the checkingval array */ int num_okintval; /* number of valid values in the checkingval array */
} s1a; } s1a;
struct { struct {
int (*f2)(paramdef_t *param); /* check an integer against an authorized range, defined by its min and max value */ int (*f2)(paramdef_t *param); /* check an integer against an authorized range, defined by its min and max value */
int okintrange[CONFIG_MAX_NUMCHECKVAL]; /* integer array, store min and max values */ int okintrange[CONFIG_MAX_NUMCHECKVAL]; /* integer array, store min and max values */
} s2; } s2;
struct { struct {
int (*f3)(paramdef_t *param); /* check a string against a list of authorized values */ int (*f3)(paramdef_t *param); /* check a string against a list of authorized values */
char *okstrval[CONFIG_MAX_NUMCHECKVAL]; /* string array, store possible values */ char *okstrval[CONFIG_MAX_NUMCHECKVAL]; /* string array, store possible values */
int num_okstrval; /* number of valid values in the checkingval array */ int num_okstrval; /* number of valid values in the checkingval array */
} s3; } s3;
struct { struct {
int (*f3a)(paramdef_t *param); /* check a string against a list of authorized values and set param value */ int (*f3a)(paramdef_t *param); /* check a string against a list of authorized values and set param value */
/* to the corresponding item in setintval array (mainly for RRC params) */ /* to the corresponding item in setintval array (mainly for RRC params) */
char *okstrval[CONFIG_MAX_NUMCHECKVAL]; /* string array, store possible values */ char *okstrval[CONFIG_MAX_NUMCHECKVAL]; /* string array, store possible values */
int setintval[CONFIG_MAX_NUMCHECKVAL]; /* integer array, values set in the paramdef structure */ int setintval[CONFIG_MAX_NUMCHECKVAL]; /* integer array, values set in the paramdef structure */
int num_okstrval; /* number of valid values in the checkingval array */ int num_okstrval; /* number of valid values in the checkingval array */
} s3a; } s3a;
struct { struct {
int (*f4)(paramdef_t *param); /* generic check function, no arguments but the param description */ int (*f4)(paramdef_t *param); /* generic check function, no arguments but the param description */
} s4; } s4;
struct { struct {
void (*checkfunc)(void) ; void (*checkfunc)(void) ;
} s5; } s5;
} checkedparam_t; } checkedparam_t;
/* paramdef is used to describe a parameter, array of paramdef_t strustures is used as the main parameter in */ /* paramdef is used to describe a parameter, array of paramdef_t strustures is used as the main parameter in */
/* config apis used to retrieve parameters values */ /* config apis used to retrieve parameters values */
typedef struct paramdef typedef struct paramdef {
{ char optname[MAX_OPTNAME_SIZE]; /* parameter name, can be used as long command line option */
char optname[MAX_OPTNAME_SIZE]; /* parameter name, can be used as long command line option */ char *helpstr; /* help string */
char *helpstr; /* help string */ unsigned int paramflags; /* value is a "ored" combination of above PARAMFLAG_XXXX values */
unsigned int paramflags; /* value is a "ored" combination of above PARAMFLAG_XXXX values */ union { /* pointer to the parameter value, completed by the config module */
union { /* pointer to the parameter value, completed by the config module */ char **strptr;
char **strptr; char **strlistptr;
char **strlistptr; uint8_t *u8ptr;
uint8_t *u8ptr; int8_t *i8ptr;
int8_t *i8ptr; uint16_t *u16ptr;
uint16_t *u16ptr; int16_t *i16ptr;
int16_t *i16ptr; uint32_t *uptr;
uint32_t *uptr; int32_t *iptr;
int32_t *iptr; uint64_t *u64ptr;
uint64_t *u64ptr; int64_t *i64ptr;
int64_t *i64ptr; double *dblptr;
double *dblptr; void *voidptr;
void *voidptr; } ;
} ; union { /* default parameter value, to be used when PARAMFLAG_MANDATORY is not specified */
union { /* default parameter value, to be used when PARAMFLAG_MANDATORY is not specified */ char *defstrval;
char *defstrval; char **defstrlistval;
char **defstrlistval; uint32_t defuintval;
uint32_t defuintval; int defintval;
int defintval; uint64_t defint64val;
uint64_t defint64val; int *defintarrayval;
int *defintarrayval; double defdblval;
double defdblval; } ;
} ; char type; /* parameter value type, as listed below as TYPE_XXXX macro */
char type; /* parameter value type, as listed below as TYPE_XXXX macro */ int numelt; /* number of elements in a list or array parameters or max size of string value */
int numelt; /* number of elements in a list or array parameters or max size of string value */ checkedparam_t *chkPptr; /* possible pointer to the structure containing the info used to check parameter values */
checkedparam_t *chkPptr; /* possible pointer to the structure containing the info used to check parameter values */ int *processedvalue; /* used to store integer values computed from string original value */
int *processedvalue; /* used to store integer values computed from string original value */
} paramdef_t; } paramdef_t;
#define TYPE_INT TYPE_INT32 #define TYPE_INT TYPE_INT32
...@@ -160,9 +159,9 @@ typedef struct paramdef ...@@ -160,9 +159,9 @@ typedef struct paramdef
#define ANY_IPV4ADDR_STRING "0.0.0.0" #define ANY_IPV4ADDR_STRING "0.0.0.0"
typedef struct paramlist_def { typedef struct paramlist_def {
char listname[MAX_OPTNAME_SIZE]; char listname[MAX_OPTNAME_SIZE];
paramdef_t **paramarray; paramdef_t **paramarray;
int numelt ; int numelt ;
} paramlist_def_t; } paramlist_def_t;
/* macro helpers for module users */ /* macro helpers for module users */
......
This diff is collapsed.
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
*/ */
/*! \file common/config/config_userapi.h /*! \file common/config/config_userapi.h
* \brief: configuration module, include file to be used by the source code calling the * \brief: configuration module, include file to be used by the source code calling the
* configuration module to access configuration parameters * configuration module to access configuration parameters
* \author Francois TABURET * \author Francois TABURET
* \date 2017 * \date 2017
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
* \warning * \warning
*/ */
#ifndef INCLUDE_CONFIG_USERAPI_H #ifndef INCLUDE_CONFIG_USERAPI_H
#define INCLUDE_CONFIG_USERAPI_H #define INCLUDE_CONFIG_USERAPI_H
#include "config_load_configmodule.h" #include "config_load_configmodule.h"
#ifdef __cplusplus #ifdef __cplusplus
...@@ -48,7 +48,7 @@ extern "C" ...@@ -48,7 +48,7 @@ extern "C"
#define CONFIG_ISPARAMFLAGSET(P,F) ( !!(P.paramflags & F)) #define CONFIG_ISPARAMFLAGSET(P,F) ( !!(P.paramflags & F))
/* utility functions, to be used by configuration module and/or configuration libraries */ /* utility functions, to be used by configuration module and/or configuration libraries */
extern configmodule_interface_t *config_get_if(void); extern configmodule_interface_t *config_get_if(void);
extern char * config_check_valptr(paramdef_t *cfgoptions, char **ptr, int length) ; extern char *config_check_valptr(paramdef_t *cfgoptions, char **ptr, int length) ;
extern void config_printhelp(paramdef_t *,int numparams); extern void config_printhelp(paramdef_t *,int numparams);
extern int config_process_cmdline(paramdef_t *params,int numparams, char *prefix); extern int config_process_cmdline(paramdef_t *params,int numparams, char *prefix);
extern void config_assign_processedint(paramdef_t *cfgoption, int val); extern void config_assign_processedint(paramdef_t *cfgoption, int val);
......
This diff is collapsed.
This diff is collapsed.
...@@ -8,27 +8,35 @@ char **unique_ids; ...@@ -8,27 +8,35 @@ char **unique_ids;
int unique_ids_size; int unique_ids_size;
int unique_ids_maxsize; int unique_ids_maxsize;
int cmp(const void *p1, const void *p2) int cmp(const void *p1, const void *p2) {
{ return strcmp(*(char *const *)p1, *(char *const *)p2);
return strcmp(*(char * const *)p1, *(char * const *)p2);
} }
/* return 1 if s was not already known, 0 if it was */ /* return 1 if s was not already known, 0 if it was */
int new_unique_id(char *s, char *input_file) int new_unique_id(char *s, char *input_file) {
{
if (unique_ids_size) if (unique_ids_size)
if (bsearch(&s, unique_ids, unique_ids_size, sizeof(char *), cmp) != NULL) { if (bsearch(&s, unique_ids, unique_ids_size, sizeof(char *), cmp) != NULL) {
printf("error: ID %s is not unique in %s\n", s, input_file); printf("error: ID %s is not unique in %s\n", s, input_file);
return 0; return 0;
} }
if (unique_ids_size == unique_ids_maxsize) { if (unique_ids_size == unique_ids_maxsize) {
unique_ids_maxsize += 256; unique_ids_maxsize += 256;
unique_ids = realloc(unique_ids, unique_ids_maxsize * sizeof(char *)); unique_ids = realloc(unique_ids, unique_ids_maxsize * sizeof(char *));
if (unique_ids == NULL) { printf("error: out of memory\n"); abort(); }
if (unique_ids == NULL) {
printf("error: out of memory\n");
abort();
}
} }
unique_ids[unique_ids_size] = strdup(s); unique_ids[unique_ids_size] = strdup(s);
if (unique_ids[unique_ids_size] == NULL)
{ printf("error: out of memory\n"); abort(); } if (unique_ids[unique_ids_size] == NULL) {
printf("error: out of memory\n");
abort();
}
unique_ids_size++; unique_ids_size++;
qsort(unique_ids, unique_ids_size, sizeof(char *), cmp); qsort(unique_ids, unique_ids_size, sizeof(char *), cmp);
return 1; return 1;
...@@ -38,14 +46,17 @@ char *bufname; ...@@ -38,14 +46,17 @@ char *bufname;
int bufname_size; int bufname_size;
int bufname_maxsize; int bufname_maxsize;
void putname(int c) void putname(int c) {
{
if (bufname_size == bufname_maxsize) { if (bufname_size == bufname_maxsize) {
bufname_maxsize += 256; bufname_maxsize += 256;
bufname = realloc(bufname, bufname_maxsize); bufname = realloc(bufname, bufname_maxsize);
if (bufname == NULL)
{ printf("error: memory allocation error\n"); exit(1); } if (bufname == NULL) {
printf("error: memory allocation error\n");
exit(1);
}
} }
bufname[bufname_size] = c; bufname[bufname_size] = c;
bufname_size++; bufname_size++;
} }
...@@ -54,42 +65,54 @@ char *bufvalue; ...@@ -54,42 +65,54 @@ char *bufvalue;
int bufvalue_size; int bufvalue_size;
int bufvalue_maxsize; int bufvalue_maxsize;
void putvalue(int c) void putvalue(int c) {
{
if (bufvalue_size == bufvalue_maxsize) { if (bufvalue_size == bufvalue_maxsize) {
bufvalue_maxsize += 256; bufvalue_maxsize += 256;
bufvalue = realloc(bufvalue, bufvalue_maxsize); bufvalue = realloc(bufvalue, bufvalue_maxsize);
if (bufvalue == NULL)
{ printf("error: memory allocation error\n"); exit(1); } if (bufvalue == NULL) {
printf("error: memory allocation error\n");
exit(1);
}
} }
bufvalue[bufvalue_size] = c; bufvalue[bufvalue_size] = c;
bufvalue_size++; bufvalue_size++;
} }
void smash_spaces(FILE *f) void smash_spaces(FILE *f) {
{
int c; int c;
while (1) { while (1) {
c = fgetc(f); c = fgetc(f);
if (isspace(c)) continue; if (isspace(c)) continue;
if (c == ' ') continue; if (c == ' ') continue;
if (c == '\t') continue; if (c == '\t') continue;
if (c == '\n') continue; if (c == '\n') continue;
if (c == 10 || c == 13) continue; if (c == 10 || c == 13) continue;
if (c == '#') { if (c == '#') {
while (1) { while (1) {
c = fgetc(f); c = fgetc(f);
if (c == '\n' || c == EOF) break; if (c == '\n' || c == EOF) break;
} }
continue; continue;
} }
break; break;
} }
if (c != EOF) ungetc(c, f); if (c != EOF) ungetc(c, f);
} }
void get_line(FILE *f, char **name, char **value) void get_line(FILE *f, char **name, char **value) {
{
int c; int c;
bufname_size = 0; bufname_size = 0;
bufvalue_size = 0; bufvalue_size = 0;
...@@ -97,23 +120,39 @@ void get_line(FILE *f, char **name, char **value) ...@@ -97,23 +120,39 @@ void get_line(FILE *f, char **name, char **value)
*value = NULL; *value = NULL;
smash_spaces(f); smash_spaces(f);
c = fgetc(f); c = fgetc(f);
while (!(c == '=' || isspace(c) || c == EOF)) { putname(c); c = fgetc(f); }
while (!(c == '=' || isspace(c) || c == EOF)) {
putname(c);
c = fgetc(f);
}
if (c == EOF) return; if (c == EOF) return;
putname(0); putname(0);
while (!(c == EOF || c == '=')) c = fgetc(f); while (!(c == EOF || c == '=')) c = fgetc(f);
if (c == EOF) return; if (c == EOF) return;
smash_spaces(f); smash_spaces(f);
c = fgetc(f); c = fgetc(f);
while (!(c == 10 || c == 13 || c == EOF)) { putvalue(c); c = fgetc(f); }
while (!(c == 10 || c == 13 || c == EOF)) {
putvalue(c);
c = fgetc(f);
}
putvalue(0); putvalue(0);
if (bufname_size <= 1) return; if (bufname_size <= 1) return;
if (bufvalue_size <= 1) return; if (bufvalue_size <= 1) return;
*name = bufname; *name = bufname;
*value = bufvalue; *value = bufvalue;
} }
int main(int n, char **v) int main(int n, char **v) {
{
FILE *in; FILE *in;
FILE *out; FILE *out;
char *name; char *name;
...@@ -121,36 +160,54 @@ int main(int n, char **v) ...@@ -121,36 +160,54 @@ int main(int n, char **v)
char *in_name; char *in_name;
char *out_name; char *out_name;
if (n != 3) { printf("error: gimme <source> <dest>\n"); exit(1); } if (n != 3) {
printf("error: gimme <source> <dest>\n");
exit(1);
}
n = 0; n = 0;
in_name = v[1]; in_name = v[1];
out_name = v[2]; out_name = v[2];
in = fopen(in_name, "r");
if (in == NULL) {
perror(in_name);
exit(1);
}
in = fopen(in_name, "r"); if (in == NULL) { perror(in_name); exit(1); } out = fopen(out_name, "w");
out = fopen(out_name, "w"); if (out == NULL) { perror(out_name); exit(1); }
if (out == NULL) {
perror(out_name);
exit(1);
}
fprintf(out, "/* generated file, do not edit by hand */\n\n"); fprintf(out, "/* generated file, do not edit by hand */\n\n");
while (1) { while (1) {
get_line(in, &name, &value); get_line(in, &name, &value);
if (name == NULL) break; if (name == NULL) break;
if (isspace(value[strlen(value)-1])) { if (isspace(value[strlen(value)-1])) {
printf("error: bad value '%s' (no space at the end please!)\n", value); printf("error: bad value '%s' (no space at the end please!)\n", value);
unlink(out_name); unlink(out_name);
exit(1); exit(1);
} }
if (!strcmp(name, "ID")) { if (!strcmp(name, "ID")) {
if (!new_unique_id(value, in_name)) { unlink(out_name); exit(1); } if (!new_unique_id(value, in_name)) {
unlink(out_name);
exit(1);
}
fprintf(out, "#define T_%s T_ID(%d)\n", value, n); fprintf(out, "#define T_%s T_ID(%d)\n", value, n);
n++; n++;
} }
} }
fprintf(out, "#define T_NUMBER_OF_IDS %d\n", n);
fprintf(out, "#define T_NUMBER_OF_IDS %d\n", n);
fclose(in); fclose(in);
fclose(out); fclose(out);
return 0; return 0;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment