diff options
-rw-r--r-- | include/anope.h | 12 | ||||
-rw-r--r-- | include/extern.h | 6 | ||||
-rw-r--r-- | src/language.cpp | 2 | ||||
-rw-r--r-- | src/send.cpp | 70 |
4 files changed, 39 insertions, 51 deletions
diff --git a/include/anope.h b/include/anope.h index 7c3dcc65b..003927378 100644 --- a/include/anope.h +++ b/include/anope.h @@ -206,22 +206,22 @@ namespace Anope inline string replace_all_cs(const string &_orig, const string &_repl) { Anope::string new_string = *this; - size_type pos = new_string.find(_orig), orig_length = _orig.length(); + size_type pos = new_string.find(_orig), orig_length = _orig.length(), repl_length = _repl.length(); while (pos != npos) { - new_string.replace(pos, pos + orig_length, _repl); - pos = new_string.find(_orig, pos + orig_length); + new_string = new_string.substr(0, pos) + _repl + new_string.substr(pos + orig_length); + pos = new_string.find(_orig, pos + repl_length); } return new_string; } inline string replace_all_ci(const string &_orig, const string &_repl) { Anope::string new_string = *this; - size_type pos = new_string.find_ci(_orig), orig_length = _orig.length(); + size_type pos = new_string.find_ci(_orig), orig_length = _orig.length(), repl_length = _repl.length(); while (pos != npos) { - new_string.replace(pos, pos + orig_length, _repl); - pos = new_string.find_ci(_orig, pos + orig_length); + new_string = new_string.substr(0, pos) + _repl + new_string.substr(pos + orig_length); + pos = new_string.find_ci(_orig, pos + repl_length); } return new_string; } diff --git a/include/extern.h b/include/extern.h index 308a33de6..7d625ec91 100644 --- a/include/extern.h +++ b/include/extern.h @@ -175,7 +175,7 @@ E int strftime_lang(char *buf, int size, User *u, int format, struct tm *tm); E void syntax_error(const Anope::string &service, User *u, const Anope::string &command, int msgnum); E const char *getstring(NickAlias *na, int index); E const char *getstring(const NickCore *nc, int index); -E const char *getstring(User *nc, int index); +E const char *getstring(const User *nc, int index); E const char *getstring(int index); /**** log.c ****/ @@ -343,8 +343,8 @@ E void send_cmd(const Anope::string &source, const char *fmt, ...) FORMAT(printf E void notice_server(const Anope::string &source, const Server *s, const char *fmt, ...) FORMAT(printf, 3, 4); -E void notice_lang(const Anope::string &source, User *dest, int message, ...); // MARK_DEPRECATED; -E void notice_help(const Anope::string &source, User *dest, int message, ...); // MARK_DEPRECATED; +E void notice_lang(const Anope::string &source, const User *dest, int message, ...); // MARK_DEPRECATED; +E void notice_help(const Anope::string &source, const User *dest, int message, ...); // MARK_DEPRECATED; /**** sessions.c ****/ diff --git a/src/language.cpp b/src/language.cpp index f38f69dad..318f10f38 100644 --- a/src/language.cpp +++ b/src/language.cpp @@ -338,7 +338,7 @@ const char *getstring(const NickCore *nc, int index) return langtexts[langidx][index]; } -const char *getstring(User *u, int index) +const char *getstring(const User *u, int index) { return getstring(u->Account(), index); } diff --git a/src/send.cpp b/src/send.cpp index 7f724a1e2..a213d73d6 100644 --- a/src/send.cpp +++ b/src/send.cpp @@ -24,7 +24,7 @@ void send_cmd(const Anope::string &source, const char *fmt, ...) { va_list args; - static char buf[BUFSIZE]; + char buf[BUFSIZE] = ""; va_start(args, fmt); @@ -65,11 +65,11 @@ void send_cmd(const Anope::string &source, const char *fmt, ...) */ void notice_server(const Anope::string &source, const Server *s, const char *fmt, ...) { - va_list args; - char buf[BUFSIZE] = ""; - if (fmt) { + va_list args; + char buf[BUFSIZE] = ""; + va_start(args, fmt); vsnprintf(buf, BUFSIZE - 1, fmt, args); @@ -91,32 +91,25 @@ void notice_server(const Anope::string &source, const Server *s, const char *fmt * @param ... any number of parameters * @return void */ -void notice_lang(const Anope::string &source, User *dest, int message, ...) +void notice_lang(const Anope::string &source, const User *dest, int message, ...) { - va_list args; - char buf[4096]; /* because messages can be really big */ - char *s, *t; - const char *fmt; - if (!dest || !message) return; + + va_list args; va_start(args, message); - fmt = getstring(dest, message); + const char *fmt = getstring(dest, message); if (!fmt) return; - memset(buf, 0, 4096); + + char buf[4096] = ""; /* because messages can be really big */ vsnprintf(buf, sizeof(buf), fmt, args); - s = buf; - while (*s) - { - t = s; - s += strcspn(s, "\n"); - if (*s) - *s++ = 0; - dest->SendMessage(source, "%s", *t ? t : " "); - } + sepstream lines(buf, '\n'); + Anope::string line; + while (lines.GetToken(line)) + dest->SendMessage(source, "%s", line.empty() ? " " : line.c_str()); va_end(args); } @@ -132,36 +125,31 @@ void notice_lang(const Anope::string &source, User *dest, int message, ...) * @param ... any number of parameters * @return void */ -void notice_help(const Anope::string &source, User * dest, int message, ...) +void notice_help(const Anope::string &source, const User *dest, int message, ...) { - va_list args; - char buf[4096], buf2[4096], outbuf[BUFSIZE]; - char *s, *t; - const char *fmt; - if (!dest || !message) return; + + va_list args; va_start(args, message); - fmt = getstring(dest, message); + const char *fmt = getstring(dest, message); if (!fmt) return; + /* Some sprintf()'s eat %S or turn it into just S, so change all %S's * into \1\1... we assume this doesn't occur anywhere else in the * string. */ - strscpy(buf2, fmt, sizeof(buf2)); - strnrepl(buf2, sizeof(buf2), "%S", "\1\1"); - vsnprintf(buf, sizeof(buf), buf2, args); - s = buf; - while (*s) + char buf[4096]; + Anope::string buf2 = fmt; + buf2 = buf2.replace_all_cs("%S", "\1\1"); + vsnprintf(buf, sizeof(buf), buf2.c_str(), args); + + sepstream lines(buf, '\n'); + Anope::string line; + while (lines.GetToken(line)) { - t = s; - s += strcspn(s, "\n"); - if (*s) - *s++ = 0; - strscpy(outbuf, t, sizeof(outbuf)); - strnrepl(outbuf, sizeof(outbuf), "\1\1", source.c_str()); - - dest->SendMessage(source, "%s", *outbuf ? outbuf : " "); + line = line.replace_all_cs("\1\1", source); + dest->SendMessage(source, "%s", line.empty() ? " " : line.c_str()); } va_end(args); } |