diff options
-rw-r--r-- | catgirl.1 | 7 | ||||
-rw-r--r-- | chat.c | 25 | ||||
-rw-r--r-- | chat.h | 3 | ||||
-rw-r--r-- | irc.c | 2 |
4 files changed, 22 insertions, 15 deletions
diff --git a/catgirl.1 b/catgirl.1 index 3c17bc7..ef15890 100644 --- a/catgirl.1 +++ b/catgirl.1 @@ -15,6 +15,7 @@ .Op Fl l Ar path .Op Fl n Ar nick .Op Fl p Ar port +.Op Fl r Ar real .Op Fl u Ar user .Op Fl w Ar pass . @@ -64,6 +65,12 @@ Connect to .Ar port . The default port is 6697. . +.It Fl r Ar real +Set realname to +.Ar real . +The default realname is +the same as the nickname. +. .It Fl u Ar user Set username to .Ar user . diff --git a/chat.c b/chat.c index 152bf84..1de145d 100644 --- a/chat.c +++ b/chat.c @@ -25,20 +25,17 @@ #include "chat.h" +static void freedup(char **field, const char *str) { + free(*field); + *field = strdup(str); + if (!*field) err(EX_OSERR, "strdup"); +} + void selfNick(const char *nick) { - free(self.nick); - self.nick = strdup(nick); - if (!self.nick) err(EX_OSERR, "strdup"); + freedup(&self.nick, nick); } void selfUser(const char *user) { - free(self.user); - self.user = strdup(user); - if (!self.user) err(EX_OSERR, "strdup"); -} -void selfJoin(const char *join) { - free(self.join); - self.join = strdup(join); - if (!self.join) err(EX_OSERR, "strdup"); + freedup(&self.user, user); } static char *prompt(const char *prompt) { @@ -65,15 +62,16 @@ int main(int argc, char *argv[]) { char *webirc = NULL; int opt; - while (0 < (opt = getopt(argc, argv, "NW:h:j:l:n:p:u:vw:"))) { + while (0 < (opt = getopt(argc, argv, "NW:h:j:l:n:p:r:u:vw:"))) { switch (opt) { break; case 'N': self.notify = true; break; case 'W': webirc = strdup(optarg); break; case 'h': host = strdup(optarg); - break; case 'j': selfJoin(optarg); + break; case 'j': freedup(&self.join, optarg); break; case 'l': logOpen(optarg); break; case 'n': selfNick(optarg); break; case 'p': port = strdup(optarg); + break; case 'r': freedup(&self.real, optarg); break; case 'u': selfUser(optarg); break; case 'v': self.verbose = true; break; case 'w': pass = strdup(optarg); @@ -85,6 +83,7 @@ int main(int argc, char *argv[]) { if (!host) host = prompt("Host: "); if (!self.nick) self.nick = prompt("Name: "); if (!self.user) selfUser(self.nick); + if (!self.real) freedup(&self.real, self.nick); inputTab(); uiInit(); diff --git a/chat.h b/chat.h index abbb050..31b31a2 100644 --- a/chat.h +++ b/chat.h @@ -31,8 +31,10 @@ #define errx(...) do { uiHide(); errx(__VA_ARGS__); } while (0) struct { + char *port; char *nick; char *user; + char *real; char *join; bool verbose; bool notify; @@ -40,7 +42,6 @@ struct { void selfNick(const char *nick); void selfUser(const char *user); -void selfJoin(const char *join); void eventWait(const char *argv[static 2]); void eventPipe(const char *argv[static 2]); diff --git a/irc.c b/irc.c index f85bfc9..e4eefa3 100644 --- a/irc.c +++ b/irc.c @@ -109,7 +109,7 @@ int ircConnect(void) { if (irc.pass) ircFmt("PASS :%s\r\n", irc.pass); ircFmt("NICK %s\r\n", self.nick); - ircFmt("USER %s 0 * :%s\r\n", self.user, self.nick); + ircFmt("USER %s 0 * :%s\r\n", self.user, self.real); return irc.sock; } |