ref: eaf9a2c0694335ea7d5139f83b3824f6127fb310
dir: /reply.c/
#include <u.h> #include <libc.h> #include <String.h> #include "dat.h" #include "fns.h" char* getreplies(Client *c) { return s_to_c((String*)c->replies.reply); } void flushreplies(Client *c) { String *s; if (!c->replies.reply) return; s = c->replies.reply; s_reset(s); } void reply(Client *c, Reply repl, ...) { char buf[1024]; int i; va_list arg; String *s; i = snprint(buf, sizeof buf, ":%s %03d ", sysnameb, repl.nr); va_start(arg, repl); i += vsnprint(&buf[i], sizeof(buf) - i, repl.msg, arg); va_end(arg); snprint(&buf[i], sizeof(buf) - i, "\r\n"); if (debug > 1) fprint(2, "reply: '%s'\n", buf); qlock(&c->replies); s = c->replies.reply; s_append(s, buf); qunlock(&c->replies); } void ircsend(Client *c, Client *sender, Reply repl, ...) { char buf[1024]; int i; va_list arg; String *s; if (sender) { i = snprint(buf, sizeof buf, ":%s!%s@%s ", sender->nick, sender->user->name, sender->user->host ? sender->user->host : sysnameb); } else { i = snprint(buf, sizeof buf, ":%s ", sysnameb); } va_start(arg, repl); i += vsnprint(&buf[i], sizeof(buf) - i, repl.msg, arg); va_end(arg); snprint(&buf[i], sizeof(buf) - i, "\r\n"); if (debug > 1) fprint(2, "ircsend: '%s'\n", buf); qlock(&c->replies); s = c->replies.reply; s_append(s, buf); qunlock(&c->replies); } void ircerror(Client *c, char *msg, ...) { char buf[1024]; int i; va_list arg; String *s; i = snprint(buf, sizeof buf, ":%s ERROR :", sysnameb); va_start(arg, msg); i += vsnprint(&buf[i], sizeof(buf) - i, msg, arg); va_end(arg); snprint(&buf[i], sizeof(buf) - i, "\r\n"); if (debug > 1) fprint(2, "error: '%s'\n", buf); qlock(&c->replies); s = c->replies.reply; s_append(s, buf); qunlock(&c->replies); }