From 5971f1caf503b74a4349cc737137157dfde6680f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 17 Jun 2005 19:12:55 +0000 Subject: [PATCH] =?UTF-8?q?Zu=20lange=20Kampfmeldung=20zerst=C3=B6rt=20imm?= =?UTF-8?q?er=20noch=20den=20Server.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/gamecode/report.c | 37 +++++++++++++++--------------------- src/common/util/nrmessage.c | 11 ++++++----- src/common/util/nrmessage.h | 2 +- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index 95f47de7b..028aa1334 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -66,6 +66,7 @@ #endif /* util includes */ +#include #include #include #include @@ -816,26 +817,21 @@ rp_messages(FILE * F, message_list * msgs, faction * viewer, int indent, boolean int k = 0; struct mlist * m = msgs->begin; while (m) { - boolean debug = viewer->options & want(O_DEBUG); #ifdef MSG_LEVELS if (!debug && get_msglevel(viewer->warnings, viewer->msglevels, m->type) < m->level) continue; #endif /* messagetype * mt = m->type; */ if (strcmp(nr_section(m->msg), category->name)==0) { - char lbuf[8192], *s = lbuf; - nr_render(m->msg, viewer->locale, s, sizeof(lbuf), viewer); + char lbuf[8192], *bufp = lbuf; + size_t rsize, size = sizeof(lbuf); + if (!k && categorized) { const char * name; char cat_identifier[24]; sprintf(cat_identifier, "section_%s", category->name); name = LOC(viewer->locale, cat_identifier); - if (debug) { - if (name!=lbuf) strcpy(lbuf, name); - sprintf(lbuf+strlen(name), " [%s]", cat_identifier); - name = lbuf; - } k = 1; rnl(F); if (centered) centre(F, name, true); @@ -847,22 +843,19 @@ rp_messages(FILE * F, message_list * msgs, faction * viewer, int indent, boolean rnl(F); } if (indent>0) { - strcpy(lbuf, " "); - strcpy(lbuf+indent, s); - s = lbuf; + rsize = strlcpy(lbuf, " ", indent); + if (rsize>size) rsize = size-1; + size -= rsize; + bufp += rsize; + + rsize = nr_render(m->msg, viewer->locale, bufp, size, viewer); + if (rsize>size) rsize = size-1; + size -= rsize; + bufp += rsize; } -#ifdef MSG_LEVELS - if (debug) { - int mylevel = get_msglevel(viewer->warnings, viewer->msglevels, m->type); - int level = msg_level(m); - if (s!=lbuf) strcpy(lbuf, s); - sprintf(buf+strlen(s), " [%d:%d(%d)]", m->type->hashkey, level, mylevel); - s = lbuf; - } -#endif - rpsnr(F, s, 2); + rpsnr(F, lbuf, 2); } - m=m->next; + m = m->next; } } } diff --git a/src/common/util/nrmessage.c b/src/common/util/nrmessage.c index 1eb14ef33..f1ecc1371 100644 --- a/src/common/util/nrmessage.c +++ b/src/common/util/nrmessage.c @@ -16,6 +16,7 @@ #include "nrmessage_struct.h" /* util includes */ +#include "bsdstring.h" #include "log.h" #include "message.h" #include "language.h" @@ -88,21 +89,21 @@ nrt_register(const struct message_type * mtype, const struct locale * lang, cons } } -int -nr_render(const struct message * msg, const struct locale * lang, char * buffer, size_t bufsize, const void * userdata) +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); if (nrt) { const char * m = translate(nrt->string, userdata, nrt->vars, msg->parameters); if (m) { - strcpy(buffer, m); - return 0; + return strlcpy(buffer, m, size); } else { log_error(("Couldn't render message %s\n", nrt->mtype->name)); } } - return -1; + if (size>0 && buffer) buffer[0] = 0; + return 0; } int diff --git a/src/common/util/nrmessage.h b/src/common/util/nrmessage.h index 045af8760..b738a9473 100644 --- a/src/common/util/nrmessage.h +++ b/src/common/util/nrmessage.h @@ -29,7 +29,7 @@ extern struct nrmessage_type * nrt_find(const struct locale *, extern const char * nrt_string(const struct nrmessage_type *type); extern const char * nrt_section(const struct nrmessage_type * mt); -extern int nr_render(const struct message * msg, const struct locale * lang, +extern size_t nr_render(const struct message * msg, const struct locale * lang, char * buffer, size_t size, const void * userdata); extern int nr_level(const struct message *msg); extern const char * nr_section(const struct message *msg);