From dda37aaee666b7530999117d2101cefdbae50eef Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 26 Mar 2006 18:26:52 +0000 Subject: [PATCH] =?UTF-8?q?http://eressea.upb.de/mantis/view.php=3Fid=3D87?= =?UTF-8?q?0=20Eigener=20Block=20f=C3=BCr=20BOTSCHAFTen=20im=20NR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ausserdem den ungenutzten REPORT Befehl entfernt. --- src/common/gamecode/laws.c | 41 --------- src/common/gamecode/report.c | 14 +-- src/common/kernel/eressea.c | 1 - src/common/kernel/eressea.h | 1 - src/common/kernel/message.c | 31 ------- src/common/kernel/message.h | 11 --- src/common/kernel/xmlreader.c | 1 - src/common/util/nrmessage.c | 167 +++++++++++++++++++++------------- src/common/util/nrmessage.h | 19 ++-- src/res/de/strings.xml | 5 +- src/res/en/strings.xml | 5 +- src/res/messages.xml | 4 +- 12 files changed, 132 insertions(+), 168 deletions(-) diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index 79dfda44f..f946e8fa4 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -2034,21 +2034,6 @@ mail_cmd(unit * u, struct order * ord) } /* ------------------------------------------------------------- */ -static void -report_option(unit * u, const char * sec, struct order * ord) -{ - const messageclass * mc; - const char *s; - - mc = mc_find(sec); - - if (mc == NULL) { - cmistake(u, ord, 135, MSG_EVENT); - return; - } - s = getstrtoken(); -} - static int banner_cmd(unit * u, struct order * ord) { @@ -2123,28 +2108,6 @@ password_cmd(unit * u, struct order * ord) return 0; } -static int -report_cmd(unit * u, struct order * ord) -{ - const char * s; - int i; - - init_tokens(ord); - skip_token(); - s = getstrtoken(); - - i = atoi(s); - sprintf(buf, "%d", i); - if (!strcmp(buf, s)) { - /* int level; - level = geti(); - not implemented yet. set individual levels for f->msglevels */ - } else { - report_option(u, s, ord); - } - return 0; -} - static int send_cmd(unit * u, struct order * ord) { @@ -2225,10 +2188,6 @@ set_passw(void) if (password_cmd(u, ord)!=0) ord = NULL; break; - case K_REPORT: - if (report_cmd(u, ord)!=0) ord = NULL; - break; - case K_SEND: if (send_cmd(u, ord)!=0) ord = NULL; break; diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index 3b0aaebce..b9faa76ff 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -585,24 +585,24 @@ rpunit(FILE * F, const faction * f, const unit * u, int indent, int mode) static void rp_messages(FILE * F, message_list * msgs, faction * viewer, int indent, boolean categorized) { - messageclass * category; + nrsection * section; if (!msgs) return; - for (category=msgclasses; category; category=category->next) { + for (section = sections; section; section=section->next) { int k = 0; struct mlist * m = msgs->begin; while (m) { /* messagetype * mt = m->type; */ - if (strcmp(nr_section(m->msg), category->name)==0) { + if (strcmp(nr_section(m->msg), section->name)==0) { char lbuf[8192]; if (!k && categorized) { - const char * category_title; + const char * section_title; char cat_identifier[24]; rnl(F); - sprintf(cat_identifier, "section_%s", category->name); - category_title = LOC(viewer->locale, cat_identifier); - centre(F, category_title, true); + sprintf(cat_identifier, "section_%s", section->name); + section_title = LOC(viewer->locale, cat_identifier); + centre(F, section_title, true); rnl(F); k = 1; } diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index 160a7595d..3aa0c6632 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -381,7 +381,6 @@ const char *keywords[MAXKEYWORDS] = "ZERSTOEREN", "ZUECHTEN", "DEFAULT", - "REPORT", "URSPRUNG", "EMAIL", "MEINUNG", diff --git a/src/common/kernel/eressea.h b/src/common/kernel/eressea.h index 419c2af89..2f191da5a 100644 --- a/src/common/kernel/eressea.h +++ b/src/common/kernel/eressea.h @@ -403,7 +403,6 @@ enum { K_DESTROY, K_BREED, K_DEFAULT, - K_REPORT, K_URSPRUNG, K_EMAIL, K_VOTE, diff --git a/src/common/kernel/message.c b/src/common/kernel/message.c index 4adae0b30..4ea2dddf7 100644 --- a/src/common/kernel/message.c +++ b/src/common/kernel/message.c @@ -58,37 +58,6 @@ typedef struct msg_setting { #include "region.h" #include "eressea.h" -messageclass * msgclasses; - -const messageclass * -mc_find(const char * name) -{ - messageclass ** mcp = &msgclasses; - if (name==NULL) return NULL; - for (;*mcp;mcp=&(*mcp)->next) { - messageclass * mc = *mcp; - if (!strcmp(mc->name, name)) break; - } - return *mcp; -} - -const messageclass * -mc_add(const char * name) -{ - messageclass ** mcp = &msgclasses; - if (name==NULL) return NULL; - for (;*mcp;mcp=&(*mcp)->next) { - messageclass * mc = *mcp; - if (!strcmp(mc->name, name)) break; - } - if (!*mcp) { - messageclass * mc = calloc(sizeof(messageclass), 1); - mc->name = strdup(name); - *mcp = mc; - } - return *mcp; -} - static void arg_set(variant args[], const message_type * mtype, const char * buffer, variant v) { diff --git a/src/common/kernel/message.h b/src/common/kernel/message.h index ddf6c1051..6c804a718 100644 --- a/src/common/kernel/message.h +++ b/src/common/kernel/message.h @@ -21,7 +21,6 @@ extern "C" { #include struct message; -struct messageclass; struct faction; struct msglevel; @@ -36,11 +35,6 @@ typedef struct message_list { extern void free_messagelist(message_list * msgs); -typedef struct messageclass { - struct messageclass * next; - const char * name; -} messageclass; - typedef struct msglevel { /* used to set specialized msg-levels */ struct msglevel *next; @@ -53,11 +47,6 @@ extern struct message * msg_feedback(const struct unit *, struct order *cmd, const char * name, const char* sig, ...); extern struct message * add_message(struct message_list** pm, struct message * m); -/* message sections */ -extern struct messageclass * msgclasses; -extern const struct messageclass * mc_add(const char * name); -extern const struct messageclass * mc_find(const char * name); - #define ADDMSG(msgs, mcreate) { message * m = mcreate; if (m) { assert(m->refcount>=1); add_message(msgs, m); msg_release(m); } } extern void cmistake(const struct unit * u, struct order *ord, int mno, int mtype); diff --git a/src/common/kernel/xmlreader.c b/src/common/kernel/xmlreader.c index 7b400a2af..0f96a6814 100644 --- a/src/common/kernel/xmlreader.c +++ b/src/common/kernel/xmlreader.c @@ -1758,7 +1758,6 @@ parse_messages(xmlDocPtr doc) section = xmlGetProp(node, BAD_CAST "section"); if (section==NULL) section = BAD_CAST default_section; - mc_add((const char*)section); /* strings */ xpath->node = node; diff --git a/src/common/util/nrmessage.c b/src/common/util/nrmessage.c index ea7f845d5..84b18c982 100644 --- a/src/common/util/nrmessage.c +++ b/src/common/util/nrmessage.c @@ -6,9 +6,9 @@ | | Ingo Wilken +-------------------+ Stefan Reich - This program may not be used, modified or distributed + This program may not be used, modified or distributed without prior permission by the authors of Eressea. - + */ #include @@ -31,101 +31,138 @@ #define NRT_MAXHASH 1021 static nrmessage_type * messagetypes[NRT_MAXHASH]; -const char * +const char * nrt_string(const struct nrmessage_type *type) { - return type->string; + return type->string; } -nrmessage_type * +nrmessage_type * nrt_find(const struct locale * lang, const struct message_type * mtype) { - nrmessage_type * found = NULL; - unsigned int hash = hashstring(mtype->name) % NRT_MAXHASH; - nrmessage_type * type = messagetypes[hash]; - while (type) { - if (type->mtype==mtype) { - if (found==NULL) found = type; - else if (type->lang==NULL) found = type; - if (lang==type->lang) { - found = type; - break; - } - } - type = type->next; - } + nrmessage_type * found = NULL; + unsigned int hash = hashstring(mtype->name) % NRT_MAXHASH; + nrmessage_type * type = messagetypes[hash]; + while (type) { + if (type->mtype==mtype) { + if (found==NULL) found = type; + else if (type->lang==NULL) found = type; + if (lang==type->lang) { + found = type; + break; + } + } + type = type->next; + } if (lang && found->lang!=lang) { log_warning(("could not find nr-type %s for locale %s, substituting with %s\n", mtype->name, locale_name(lang), locale_name(found->lang))); } - return found; + return found; } -void +nrsection * sections; + +const nrsection * +section_find(const char * name) +{ + nrsection ** mcp = §ions; + if (name==NULL) return NULL; + for (;*mcp;mcp=&(*mcp)->next) { + nrsection * mc = *mcp; + if (!strcmp(mc->name, name)) break; + } + return *mcp; +} + +const nrsection * +section_add(const char * name) +{ + nrsection ** mcp = §ions; + if (name==NULL) return NULL; + for (;*mcp;mcp=&(*mcp)->next) { + nrsection * mc = *mcp; + if (!strcmp(mc->name, name)) break; + } + if (!*mcp) { + nrsection * mc = calloc(sizeof(nrsection), 1); + mc->name = strdup(name); + *mcp = mc; + } + return *mcp; +} + +void nrt_register(const struct message_type * mtype, const struct locale * lang, const char * string, int level, const char * section) { - unsigned int hash = hashstring(mtype->name) % NRT_MAXHASH; - nrmessage_type * nrt = messagetypes[hash]; - while (nrt && (nrt->lang!=lang || nrt->mtype!=mtype)) { - nrt = nrt->next; - } - if (!nrt) { - int i; - char zNames[256]; - char * c = zNames; - nrt = malloc(sizeof(nrmessage_type)); - nrt->lang = lang; - nrt->mtype = mtype; - nrt->next = messagetypes[hash]; - nrt->level=level; - if (section) nrt->section = strdup(section); - else nrt->section = NULL; - messagetypes[hash] = nrt; - assert(string && *string); - nrt->string = strdup(string); + unsigned int hash = hashstring(mtype->name) % NRT_MAXHASH; + nrmessage_type * nrt = messagetypes[hash]; + while (nrt && (nrt->lang!=lang || nrt->mtype!=mtype)) { + nrt = nrt->next; + } + if (!nrt) { + int i; + char zNames[256]; + char * c = zNames; + nrt = malloc(sizeof(nrmessage_type)); + nrt->lang = lang; + nrt->mtype = mtype; + nrt->next = messagetypes[hash]; + nrt->level=level; + if (section) { + const nrsection * s = section_find(section); + if (s==NULL) { + s = section_add(section); + } + nrt->section = s->name; + } + else nrt->section = NULL; + messagetypes[hash] = nrt; + assert(string && *string); + nrt->string = strdup(string); *c = '\0'; - for (i=0;i!=mtype->nparameters;++i) { - if (i!=0) *c++ = ' '; - c+= strlen(strcpy(c, mtype->pnames[i])); - } - nrt->vars = strdup(zNames); - /* TODO: really necessary to strdup them all? here? better to extend the caller? hash? */ - } + for (i=0;i!=mtype->nparameters;++i) { + if (i!=0) *c++ = ' '; + c+= strlen(strcpy(c, mtype->pnames[i])); + } + nrt->vars = strdup(zNames); + /* TODO: really necessary to strdup them all? here? better to extend the caller? hash? */ + } } size_t nr_render(const struct message * msg, const struct locale * lang, char * buffer, size_t size, const void * userdata) { - struct nrmessage_type * nrt = nrt_find(lang, msg->type); + struct nrmessage_type * nrt = nrt_find(lang, msg->type); - if (nrt) { - const char * m = translate(nrt->string, userdata, nrt->vars, msg->parameters); - if (m) { - return strlcpy(buffer, m, size); - } else { - log_error(("Couldn't render message %s\n", nrt->mtype->name)); - } - } + if (nrt) { + const char * m = translate(nrt->string, userdata, nrt->vars, msg->parameters); + if (m) { + return strlcpy(buffer, m, size); + } else { + log_error(("Couldn't render message %s\n", nrt->mtype->name)); + } + } if (size>0 && buffer) buffer[0] = 0; - return 0; + return 0; } -int +int nr_level(const struct message *msg) { - nrmessage_type * nrt = nrt_find(NULL, msg->type); - return nrt->level; + nrmessage_type * nrt = nrt_find(NULL, msg->type); + return nrt->level; } -const char * +const char * nr_section(const struct message *msg) { - nrmessage_type * nrt = nrt_find(default_locale, msg->type); - return nrt->section; + nrmessage_type * nrt = nrt_find(default_locale, msg->type); + return nrt->section; } -const char * +const char * nrt_section(const nrmessage_type * nrt) { - return nrt->section; + return nrt->section; } diff --git a/src/common/util/nrmessage.h b/src/common/util/nrmessage.h index b738a9473..d9a931570 100644 --- a/src/common/util/nrmessage.h +++ b/src/common/util/nrmessage.h @@ -6,7 +6,7 @@ | | Ingo Wilken +-------------------+ Stefan Reich - This program may not be used, modified or distributed + This program may not be used, modified or distributed without prior permission by the authors of Eressea. */ @@ -21,11 +21,18 @@ struct message; struct message_type; struct nrmessage_type; -extern void nrt_register(const struct message_type * mtype, - const struct locale * lang, const char * script, - int level, const char * section); -extern struct nrmessage_type * nrt_find(const struct locale *, - const struct message_type *); +typedef struct nrsection { + char * name; + struct nrsection * next; +} nrsection; + +extern nrsection * sections; + +extern void nrt_register(const struct message_type * mtype, + const struct locale * lang, const char * script, + int level, const char * section); +extern struct nrmessage_type * nrt_find(const struct locale *, + const struct message_type *); extern const char * nrt_string(const struct nrmessage_type *type); extern const char * nrt_section(const struct nrmessage_type * mt); diff --git a/src/res/de/strings.xml b/src/res/de/strings.xml index 60b53cdce..895df01d1 100644 --- a/src/res/de/strings.xml +++ b/src/res/de/strings.xml @@ -674,7 +674,10 @@ - Meldungen und Ereignisse + Ereignisse + + + Botschaften Warnungen und Fehler diff --git a/src/res/en/strings.xml b/src/res/en/strings.xml index de74e097b..bd87e76d5 100644 --- a/src/res/en/strings.xml +++ b/src/res/en/strings.xml @@ -257,8 +257,11 @@ an unknown unit + + Dispatches + - Messages and Events + Events Warnings and Errors diff --git a/src/res/messages.xml b/src/res/messages.xml index 86d22a7f2..b77a647e6 100644 --- a/src/res/messages.xml +++ b/src/res/messages.xml @@ -611,7 +611,7 @@ "$unit($unit) in $region($region): '$order($command)' - $race($race,0) do not give things away." "$unit($unit) in $region($region): '$order($command)' - $race($race,0) do not give things away." - + @@ -620,7 +620,7 @@ "Eine Botschaft von $unit($sender) aus $region($region): '$string'" "A message by $unit($sender) from $region($region): '$string'" - +