/* Like notice_lang(), but replace %S by the source. This is an ugly hack * to simplify letting help messages display the name of the pseudoclient * that's sending them. */ void notice_help(const char *source, User *dest, int message, ...) { va_list args; char buf[4096], buf2[4096], outbuf[BUFSIZE]; char *s, *t; const char *fmt; if (!dest) return; va_start(args, message); fmt = getstring(dest->ni, 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) { t = s; s += strcspn(s, "\n"); if (*s) *s++ = 0; strscpy(outbuf, t, sizeof(outbuf)); strnrepl(outbuf, sizeof(outbuf), "\1\1", source); #ifdef IRC_UNDERNET_P10 send_cmd(source, "PRIVMSG %s :%s", dest->numerico, *outbuf ? outbuf : " "); #else send_cmd(source, "PRIVMSG %s :%s", dest->nick, *outbuf ? outbuf : " "); #endif } }
int strftime_lang(char *buf, int size, User *u, int format, struct tm *tm) { int language = u && u->ni ? u->ni->language : DEF_LANGUAGE; char tmpbuf[BUFSIZE], buf2[BUFSIZE]; char *s; int i, ret; strscpy(tmpbuf, langtexts[language][format], sizeof(tmpbuf)); if ((s = langtexts[language][STRFTIME_DAYS_SHORT]) != NULL) { for (i = 0; i < tm->tm_wday; i++) s += strcspn(s, "\n")+1; i = strcspn(s, "\n"); strncpy(buf2, s, i); buf2[i] = 0; strnrepl(tmpbuf, sizeof(tmpbuf), "%a", buf2); } if ((s = langtexts[language][STRFTIME_DAYS_LONG]) != NULL) { for (i = 0; i < tm->tm_wday; i++) s += strcspn(s, "\n")+1; i = strcspn(s, "\n"); strncpy(buf2, s, i); buf2[i] = 0; strnrepl(tmpbuf, sizeof(tmpbuf), "%A", buf2); } if ((s = langtexts[language][STRFTIME_MONTHS_SHORT]) != NULL) { for (i = 0; i < tm->tm_mon; i++) s += strcspn(s, "\n")+1; i = strcspn(s, "\n"); strncpy(buf2, s, i); buf2[i] = 0; strnrepl(tmpbuf, sizeof(tmpbuf), "%b", buf2); } /*donostiarra(2009) para adaptar mysql*/ if ((s = langtexts[language][STRFTIME_MESES_NUM]) != NULL) { for (i = 0; i < tm->tm_mon; i++) s += strcspn(s, "\n")+1; i = strcspn(s, "\n"); strncpy(buf2, s, i); buf2[i] = 0; strnrepl(tmpbuf, sizeof(tmpbuf), "%c", buf2); } if ((s = langtexts[language][STRFTIME_MONTHS_LONG]) != NULL) { for (i = 0; i < tm->tm_mon; i++) s += strcspn(s, "\n")+1; i = strcspn(s, "\n"); strncpy(buf2, s, i); buf2[i] = 0; strnrepl(tmpbuf, sizeof(tmpbuf), "%B", buf2); } ret = strftime(buf, size, tmpbuf, tm); if (ret == size) buf[size-1] = 0; return ret; }
/** * Like notice_lang(), but replace %S by the source. This is an ugly hack * to simplify letting help messages display the name of the pseudoclient * that's sending them. * @param source Orgin of the Message * @param u User Struct * @param int Index of the Message * @param ... any number of parameters * @return void */ void notice_help(char *source, 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_start(args, message); fmt = getstring(dest->na, 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) { t = s; s += strcspn(s, "\n"); if (*s) *s++ = 0; strscpy(outbuf, t, sizeof(outbuf)); strnrepl(outbuf, sizeof(outbuf), "\1\1", source); /* Send privmsg instead of notice if: * - UsePrivmsg is enabled * - The user is not registered and NSDefMsg is enabled * - The user is registered and has set /ns set msg on */ if (UsePrivmsg && ((!dest->na && (NSDefFlags & NI_MSG)) || (dest->na && (dest->na->nc->flags & NI_MSG)))) { anope_cmd_privmsg2(source, dest->nick, *outbuf ? outbuf : " "); } else { anope_cmd_notice2(source, dest->nick, *outbuf ? outbuf : " "); } } va_end(args); }