diff --git a/src/util/message.c b/src/util/message.c index b01993098..64c161d24 100644 --- a/src/util/message.c +++ b/src/util/message.c @@ -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); } } + diff --git a/src/util/message.h b/src/util/message.h index 40cc09086..5aa16232b 100644 --- a/src/util/message.h +++ b/src/util/message.h @@ -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; diff --git a/src/util/nrmessage.c b/src/util/nrmessage.c index 047d3565b..1fdde6935 100644 --- a/src/util/nrmessage.c +++ b/src/util/nrmessage.c @@ -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) { diff --git a/src/util/nrmessage.h b/src/util/nrmessage.h index c0d9257aa..15914841b 100644 --- a/src/util/nrmessage.h +++ b/src/util/nrmessage.h @@ -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);