Add -r option for realname

weechat-hashes
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 l Ar path
.Op Fl n Ar nick .Op Fl n Ar nick
.Op Fl p Ar port .Op Fl p Ar port
.Op Fl r Ar real
.Op Fl u Ar user .Op Fl u Ar user
.Op Fl w Ar pass .Op Fl w Ar pass
. .
@ -64,6 +65,12 @@ Connect to
.Ar port . .Ar port .
The default port is 6697. 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 .It Fl u Ar user
Set username to Set username to
.Ar user . .Ar user .

25
chat.c
View File

@ -25,20 +25,17 @@
#include "chat.h" #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) { void selfNick(const char *nick) {
free(self.nick); freedup(&self.nick, nick);
self.nick = strdup(nick);
if (!self.nick) err(EX_OSERR, "strdup");
} }
void selfUser(const char *user) { void selfUser(const char *user) {
free(self.user); freedup(&self.user, 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");
} }
static char *prompt(const char *prompt) { static char *prompt(const char *prompt) {
@ -65,15 +62,16 @@ int main(int argc, char *argv[]) {
char *webirc = NULL; char *webirc = NULL;
int opt; 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) { switch (opt) {
break; case 'N': self.notify = true; break; case 'N': self.notify = true;
break; case 'W': webirc = strdup(optarg); break; case 'W': webirc = strdup(optarg);
break; case 'h': host = 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 'l': logOpen(optarg);
break; case 'n': selfNick(optarg); break; case 'n': selfNick(optarg);
break; case 'p': port = strdup(optarg); break; case 'p': port = strdup(optarg);
break; case 'r': freedup(&self.real, optarg);
break; case 'u': selfUser(optarg); break; case 'u': selfUser(optarg);
break; case 'v': self.verbose = true; break; case 'v': self.verbose = true;
break; case 'w': pass = strdup(optarg); break; case 'w': pass = strdup(optarg);
@ -85,6 +83,7 @@ int main(int argc, char *argv[]) {
if (!host) host = prompt("Host: "); if (!host) host = prompt("Host: ");
if (!self.nick) self.nick = prompt("Name: "); if (!self.nick) self.nick = prompt("Name: ");
if (!self.user) selfUser(self.nick); if (!self.user) selfUser(self.nick);
if (!self.real) freedup(&self.real, self.nick);
inputTab(); inputTab();
uiInit(); uiInit();

3
chat.h
View File

@ -31,8 +31,10 @@
#define errx(...) do { uiHide(); errx(__VA_ARGS__); } while (0) #define errx(...) do { uiHide(); errx(__VA_ARGS__); } while (0)
struct { struct {
char *port;
char *nick; char *nick;
char *user; char *user;
char *real;
char *join; char *join;
bool verbose; bool verbose;
bool notify; bool notify;
@ -40,7 +42,6 @@ struct {
void selfNick(const char *nick); void selfNick(const char *nick);
void selfUser(const char *user); void selfUser(const char *user);
void selfJoin(const char *join);
void eventWait(const char *argv[static 2]); void eventWait(const char *argv[static 2]);
void eventPipe(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); if (irc.pass) ircFmt("PASS :%s\r\n", irc.pass);
ircFmt("NICK %s\r\n", self.nick); 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; return irc.sock;
} }