fix sections handling, remove it from nrmessage.

This commit is contained in:
Enno Rehling 2018-05-18 21:36:10 +02:00
parent c11a020846
commit 22f6d4feed
4 changed files with 44 additions and 40 deletions

View File

@ -122,6 +122,42 @@ message_type *mt_create(message_type * mtype, const char *args[], int nparameter
return mtype;
}
char *sections[MAXSECTIONS];
const char *section_find(const char *name)
{
int i;
if (name == NULL) {
return NULL;
}
for (i = 0; i != MAXSECTIONS && sections[i]; ++i) {
if (strcmp(sections[i], name) == 0) {
return sections[i];
}
}
return NULL;
}
const char *section_add(const char *name) {
int i;
if (name == NULL) {
return NULL;
}
for (i = 0; i != MAXSECTIONS && sections[i]; ++i) {
if (strcmp(sections[i], name) == 0) {
return sections[i];
}
}
assert(i < MAXSECTIONS);
assert(sections[i] == NULL);
if (i + 1 < MAXSECTIONS) {
sections[i + 1] = NULL;
}
return sections[i] = str_strdup(name);
}
message_type *mt_new(const char *name, const char *section)
{
message_type *mtype;
@ -134,7 +170,10 @@ message_type *mt_new(const char *name, const char *section)
mtype = (message_type *)malloc(sizeof(message_type));
mtype->key = 0;
mtype->name = str_strdup(name);
mtype->section = section;
mtype->section = section_find(section);
if (!mtype->section) {
mtype->section = section_add(section);
}
mtype->nparameters = 0;
mtype->pnames = NULL;
mtype->types = NULL;
@ -267,3 +306,4 @@ void message_done(void) {
free(at);
}
}

View File

@ -20,6 +20,9 @@ extern "C" {
#define MSG_MAXARGS 8
#define MT_NEW_END ((const char *)0)
#define MAXSECTIONS 16
extern char *sections[MAXSECTIONS];
typedef struct arg_type {
struct arg_type *next;

View File

@ -65,42 +65,6 @@ static nrmessage_type *nrt_find(const struct message_type * mtype)
return found;
}
char *sections[MAXSECTIONS];
const char *section_find(const char *name)
{
int i;
if (name == NULL) {
return NULL;
}
for (i = 0; i != MAXSECTIONS && sections[i]; ++i) {
if (strcmp(sections[i], name) == 0) {
return sections[i];
}
}
return NULL;
}
const char *section_add(const char *name) {
int i;
if (name == NULL) {
return NULL;
}
for (i = 0; i != MAXSECTIONS && sections[i]; ++i) {
if (strcmp(sections[i], name) == 0) {
return sections[i];
}
}
assert(i < MAXSECTIONS);
assert(sections[i] == NULL);
if (i + 1 < MAXSECTIONS) {
sections[i + 1] = NULL;
}
return sections[i] = str_strdup(name);
}
void
nrt_register(const struct message_type *mtype)
{

View File

@ -25,9 +25,6 @@ extern "C" {
struct message_type;
struct nrmessage_type;
#define MAXSECTIONS 8
extern char *sections[MAXSECTIONS];
void free_nrmesssages(void);
void nrt_register(const struct message_type *mtype);