Add -r option for realname

master
Curtis McEnroe 2018-12-02 23:08:49 -05:00
parent 99c8a9fec0
commit 0e1297e068
No known key found for this signature in database
GPG Key ID: CEA2F97ADCFCD77C
4 changed files with 22 additions and 15 deletions

View File

@ -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 .

25
chat.c
View File

@ -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();

3
chat.h
View File

@ -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]);

2
irc.c
View File

@ -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;
}