aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cmd.c61
-rw-r--r--src/edbox.h2
-rw-r--r--src/irc.c110
-rw-r--r--src/screen.c4
4 files changed, 124 insertions, 53 deletions
diff --git a/src/cmd.c b/src/cmd.c
index c5cad90..f4e94b6 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -15,6 +15,7 @@ static char *target;
static void do_color(void);
static void do_info(void);
static void do_j(void);
+static void do_j1(void);
static void do_list(void);
static void do_me(void);
static void do_msg(void);
@@ -23,6 +24,7 @@ static void do_ping(void);
static void do_query(void);
static void do_quit(void);
static void do_quote(void);
+static void do_topic(void);
static void do_ver(void);
typedef struct {
@@ -38,7 +40,9 @@ cmd_t command_defs[] = {
{ "COLOR", do_color, 1 },
{ "INFO", do_info, 0 },
{ "J", do_j, 1 },
+ { "J1", do_j1, 1 },
{ "JOIN", do_j, 1 },
+ { "JOIN1", do_j1, 1 },
{ "LIST", do_list, 1 },
{ "M", do_msg, 1 },
{ "ME", do_me, 1 },
@@ -49,6 +53,7 @@ cmd_t command_defs[] = {
{ "QUERY", do_query, 1 },
{ "QUIT", do_quit, 0 },
{ "QUOTE", do_quote, 1 },
+ { "TOPIC", do_topic, 0 },
{ "VER", do_ver, 0 },
{ "VERSION", do_ver, 0 },
{ 0, 0 }
@@ -130,12 +135,17 @@ static char *nextarg(char *arg) {
return 0;
}
-static void do_j(void) {
- /* TODO: add to channel list, once we have one */
+static void do_j1(void) {
txbuf_set_str2("JOIN ", arg1);
txbuf_send();
}
+static void do_j(void) {
+ if(!scr_getbyname(arg1))
+ scr_create(arg1, 1);
+ do_j1();
+}
+
static void do_quit(void) {
txbuf_set_str("QUIT");
if(arg1)
@@ -162,6 +172,25 @@ static void do_part(void) {
txbuf_send();
}
+static void do_topic(void) {
+ if(arg1[0] == '#') {
+ target = arg1;
+ arg2 = nextarg(arg1);
+ } else {
+ arg2 = arg1;
+ }
+
+ if(!target) {
+ err_target_req();
+ return;
+ }
+
+ txbuf_set_str2("TOPIC ", target);
+ if(arg2)
+ txbuf_append_str2(" :", arg2);
+ txbuf_send();
+}
+
static void do_server_info(void) {
txbuf_send_str("INFO");
}
@@ -194,9 +223,15 @@ static void do_me(void) {
return;
}
- txbuf_set_str3("PRIVMSG ", target, " :" " \x01" " ACTION ");
+ txbuf_set_str3("PRIVMSG ", target, " :" "\x01" "ACTION ");
txbuf_append_str2(arg1, "\x01");
txbuf_send();
+
+ scr_print_current("\x02* ");
+ scr_print_current(usernick);
+ scr_print_current("\x02 ");
+ scr_print_current(arg1);
+ scr_print_current("\n");
}
static void do_ping(void) {
@@ -251,9 +286,12 @@ static void do_msg(void) {
char s;
arg2 = nextarg(arg1);
if(arg2) {
- // TODO: print message to screen!
- // s = scr_getbyname(arg1);
- // if(!s) s = SCR_PRIV;
+ scr_print_current("->*");
+ scr_print_current(arg1);
+ scr_print_current("* ");
+ scr_print_current(arg2);
+ scr_print_current("\n");
+
txbuf_set_str3("PRIVMSG ", arg1, " :");
txbuf_append_str(arg2);
txbuf_send();
@@ -265,9 +303,11 @@ static void do_msg(void) {
static int cmd_local(void) {
arg1 = nextarg(command);
+ /*
scr_print_current("command: ");
scr_print_current(command);
scr_print_current("\n");
+ */
for(cmd_def = &command_defs[0]; cmd_def->cmd; cmd_def++) {
if(streq_i(command, cmd_def->cmd)) {
@@ -276,12 +316,12 @@ static int cmd_local(void) {
} else {
(*(cmd_def->func))();
}
- scr_print_current("(did local command)\n");
+ // scr_print_current("(did local command)\n");
return 1;
}
}
- scr_print_current("(not a local command)\n");
+ // scr_print_current("(not a local command)\n");
return 0;
}
@@ -305,7 +345,10 @@ static void cmd_slash(void) {
void cmd_command(char *cmd) {
command = cmd;
- target = scr_get_cur_name();
+ if(scr_current > 1)
+ target = scr_get_cur_name();
+ else
+ target = 0;
if(cmd[0] == '/' && cmd[1] && cmd[1] != '/')
cmd_slash();
diff --git a/src/edbox.h b/src/edbox.h
index a410cec..3344353 100644
--- a/src/edbox.h
+++ b/src/edbox.h
@@ -2,7 +2,7 @@
/**** public API ****/
-#define EDBOX_SIZE 160
+#define EDBOX_SIZE 240
/* clear the contents of the edit box (whether it's visible or not) */
void edbox_clear(void);
diff --git a/src/irc.c b/src/irc.c
index e48ef6d..1f7aad3 100644
--- a/src/irc.c
+++ b/src/irc.c
@@ -95,16 +95,14 @@ static void do_privmsg(void) {
static void do_join(void) {
if(streq_i(usernick, msg_src)) {
- /* if our nick is the source, create the screen if needed. if a
- screen can't be created, no harm done. */
- if(scr_active == SCR_SERVER)
- scr_create(msg_dest, 1);
+ scr_print_active("You have ");
} else {
scr_print_active(msg_src);
- scr_print_active(" has joined ");
- scr_print_active(msg_dest);
- scr_eol_active();
+ scr_print_active(" has ");
}
+ scr_print_active("joined ");
+ scr_print_active(msg_dest);
+ scr_eol_active();
}
static void do_nick(void) {
@@ -115,7 +113,7 @@ static void do_nick(void) {
scr_print_active(msg_src);
scr_print_active(" is ");
}
- scr_print_active(" now known as ");
+ scr_print_active("now known as ");
scr_print_active(msg_dest);
scr_eol_active();
}
@@ -158,11 +156,14 @@ static void do_kick(void) {
static void do_mode(void) {
int i;
- scr_print_active(msg_src);
+ if(msg_src)
+ scr_print_active(msg_src);
+ else
+ scr_print_active("Server");
scr_print_active(" sets mode: ");
for(i = 0; i < msg_argcount; i++) {
- scr_print_active(" ");
scr_print_active(msg_args[i]);
+ scr_print_active(" ");
}
if(msg_text) scr_print_active(msg_text);
scr_eol_active();
@@ -227,16 +228,6 @@ static void do_numeric(void) {
break;
/*
- case RPL_NAMREPLY:
- "Users in ##channel", msg_text
-
- case RPL_TOPIC:
- case RPL_NOTOPIC:
- set the topic for the screen, if there is one
-
- case RPL_TOPICWHOTIME:
- "Topic was set by <nick>", don't try to parse the UNIX timestamp.
-
case RPL_WHOISCERTFP:
case RPL_WHOISREGNICK:
case RPL_WHOISUSER:
@@ -252,16 +243,8 @@ static void do_numeric(void) {
case RPL_WHOISSECURE:
case RPL_WHOWASUSER:
These always go to the server window.
-
- case RPL_ENDOFWHOIS:
- case RPL_ENDOFWHOWAS:
- Don't print.
*/
- case RPL_ENDOFNAMES:
- /* don't print, just noise */
- break;
-
case ERR_NICKNAMEINUSE:
do_catchall(0);
if(!regged) {
@@ -276,20 +259,29 @@ static void do_numeric(void) {
case ERR_NOMOTD:
break;
+ case RPL_NAMREPLY:
+ scr_print_active(msg_args[2]);
+ scr_print_active(" users: ");
+ scr_print_active(msg_text);
+ scr_print_active("\n");
+ break;
+
+ case RPL_ENDOFNAMES:
+ /* don't print, just noise */
+ break;
+
case RPL_TOPIC:
- s = scr_getbyname(msg_args[1]);
- scr_print(s, "Topic for ");
- scr_print(s, msg_args[1]);
- scr_print(s, ": ");
- scr_print(s, msg_text);
- scr_putc(s, '\n');
+ scr_print_active("Topic for ");
+ scr_print_active(msg_args[1]);
+ scr_print_active(": ");
+ scr_print_active(msg_text);
+ scr_print_active("\n");
break;
case RPL_TOPICWHOTIME:
- s = scr_getbyname(msg_args[1]);
- scr_print(s, "Topic set by: ");
- scr_print(s, msg_args[1]);
- scr_putc(s, '\n');
+ scr_print_active("Topic set by ");
+ scr_print_active(msg_args[2]);
+ scr_print_active("\n");
break;
default:
@@ -306,12 +298,19 @@ static void invalid_msg(char type) {
void select_screen(void) {
char s;
- if(!msg_src || !msg_dest) {
+ if(!msg_dest) {
s = SCR_SERVER;
- } else {
+ } else if(*msg_dest == '#') {
s = scr_getbyname(msg_dest);
- if(!s && msg_dest[0] != '#')
- s = SCR_PRIV;
+ if(!s) s = SCR_SERVER;
+ } else {
+ s = scr_getbyname(msg_src);
+ if(!s) {
+ if(streq_i(msg_cmd, "PRIVMSG")) /* or maybe NOTICE? */
+ s = SCR_PRIV;
+ else
+ s = SCR_SERVER;
+ }
}
scr_activate(s);
}
@@ -355,6 +354,12 @@ static void parse_msg(void) {
/* ignore empty message */
if(!*msg) return;
+ /*
+ scr_print_active("RAW: ");
+ scr_print_active(msg);
+ scr_print_active("\n");
+ */
+
/* if there's a final multiword arg... */
/* FIXME: channel names can have colons, which breaks this... */
p = strstr(msg + 1, " :"); /* +1 to skip leading colon in msg source */
@@ -394,12 +399,29 @@ static void parse_msg(void) {
p = strtok(0, " ");
if(p) {
msg_args[msg_argcount] = p;
+ /* if any arg is a channel name, use it for the dest */
+ if(*p == '#')
+ msg_dest = p;
} else {
break;
}
}
}
- if(msg_argcount) msg_dest = msg_args[0];
+
+ /*
+ if(msg_dest) {
+ scr_print_current("got here, msg_dest is: ");
+ scr_print_current(msg_dest);
+ scr_print_current("\n");
+ }
+ */
+
+ if(!msg_dest) {
+ if(msg_argcount)
+ msg_dest = msg_args[0];
+ else if(msg_text)
+ msg_dest = msg_text;
+ }
if(msg_src) {
if((p = strstr(msg_src, "!"))) {
@@ -517,6 +539,8 @@ static void start_keystroke(void) {
scr_display(s);
} else if(i == CH_CURS_UP || i == '-') {
scrollback();
+ } else if(i == 0x1b) { /* escape */
+ scr_destroy(scr_current);
}
}
diff --git a/src/screen.c b/src/screen.c
index e7f83b4..617ea2f 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -61,6 +61,7 @@ void scr_init(void) {
scr_display(0);
}
+/* TODO: don't create screen if it already exists! */
char scr_create(const char *name, char display) {
int i;
@@ -91,6 +92,7 @@ void scr_destroy(char s) {
scr_names[s][0] = 0;
if(scr_current == s)
scr_display(0);
+ scr_clear(s);
}
void scr_set_topic(char s, const char *topic) {
@@ -163,6 +165,8 @@ void scr_refresh(void) {
char scr_getbyname(const char *name) {
char i;
+ if(!name) return 0;
+
for(i = 2; i < MAX_SCREENS; i++) {
if(strcasecmp(name, scr_names[i]) == 0)
return i;