diff options
Diffstat (limited to 'src/cmd.c')
| -rw-r--r-- | src/cmd.c | 138 |
1 files changed, 36 insertions, 102 deletions
@@ -7,9 +7,13 @@ #include "screen.h" #include "edbox.h" #include "config.h" +#include "streq.h" +#include "timers.h" /* A "command" is actually anything the user types, whether or - not it starts with a /character. */ + not it starts with a / character. */ + +extern void num_to_numbuf(unsigned int n); /* printnum.s */ char *command, *arg1, *arg2, *arg3; static char *target; @@ -25,16 +29,14 @@ static void do_j1(void); static void do_list(void); static void do_me(void); static void do_msg(void); -static void do_names(void); -static void do_part(void); 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); static void do_reset(void); static void do_reboot(void); +static void do_optional_chan(void); typedef struct { char *cmd; @@ -46,6 +48,7 @@ typedef struct { OP DEOP VOICE DEVOICE KICK BAN KB IGNORE UNIGNORE MODE INVITE */ cmd_t command_defs[] = { + { "MSG", do_msg, 1 }, /* this must come first, do not move! */ { "AWAY", do_away, 1 }, { "ALERT", do_bell, 1 }, { "CLICK", do_click, 0 }, @@ -59,15 +62,14 @@ cmd_t command_defs[] = { { "LIST", do_list, 1 }, { "M", do_msg, 1 }, { "ME", do_me, 1 }, - { "MSG", do_msg, 1 }, - { "NAMES", do_names, 0 }, - { "PART", do_part, 0 }, + { "NAMES", do_optional_chan, 0 }, + { "PART", do_optional_chan, 0 }, { "PING", do_ping, 0 }, { "Q", do_query, 1 }, { "QUERY", do_query, 1 }, { "QUIT", do_quit, 0 }, { "QUOTE", do_quote, 1 }, - { "TOPIC", do_topic, 0 }, + { "TOPIC", do_optional_chan, 0 }, { "REBOOT", do_reboot, 0 }, { "RESET", do_reset, 0 }, { "VER", do_ver, 0 }, @@ -87,15 +89,8 @@ static void cmd_chan_text(void) { /* 0x02 = ^B = enable bold */ scr_print_active("<\x02"); - scr_print_active(conf->nick); - scr_print_active("\x02"); - - /* - if(!scr_current) { - scr_print_active("/"); - scr_print_active(target); - } - */ + scr_print_active(config.nick); + scr_putc_active('\x02'); scr_print_active("> "); scr_print_active(command); @@ -125,31 +120,6 @@ static void err_no_scr_target(void) { scr_print_current("No channel/nick for screen\n"); } -/* arg points to something like: - "part #channel I'm outta here\0" - after nextarg(), arg points to "part\0" only, and ret points - to "#channel I'm outta here\0". */ -static char *nextarg(char *arg) { - /* iterate over the first word */ - while(*arg && *arg != ' ') - arg++; - - /* if we found a space, replace it with a null terminator */ - if(*arg) - *arg++ = 0; - else - return 0; /* found no space, there's no next arg! */ - - /* skip space(s) */ - while(*arg && *arg == ' ') - arg++; - - if(*arg) - return arg; - - return 0; -} - static char have_commas(void) { if(strchr(arg1, ',')) { err_marker(); @@ -164,7 +134,7 @@ static void join_arg1(void) { txbuf_send(); } -static void mass_join(int scr) { +static void mass_join(char scr) { if(have_commas()) return; do { @@ -204,7 +174,7 @@ static void do_quit(void) { static void pause(void) { OS.rtclok[2] = 0; - while(OS.rtclok[2] < hz) + while(OS.rtclok[2] < timers.hz) /* NOP */; } @@ -217,26 +187,7 @@ static void do_reboot(void) { asm("jmp $e477"); } -static void do_part(void) { - if(arg1[0] == '#') { - target = arg1; - arg2 = nextarg(arg1); - } else { - arg2 = arg1; - } - - if(!target) { - err_no_scr_target(); - return; - } - - txbuf_set_str2("PART ", target); - if(arg2) - txbuf_append_str2(" :", arg2); - txbuf_send(); -} - -static void do_topic(void) { +static void do_optional_chan(void) { if(arg1[0] == '#') { target = arg1; arg2 = nextarg(arg1); @@ -249,28 +200,12 @@ static void do_topic(void) { return; } - txbuf_set_str2("TOPIC ", target); + txbuf_set_str3(cmd_def->cmd, " ", target); if(arg2) txbuf_append_str2(" :", arg2); txbuf_send(); } -static void do_names(void) { - if(arg1[0] == '#') { - target = arg1; - arg2 = nextarg(arg1); - } else { - arg2 = arg1; - } - - if(!target) { - err_no_scr_target(); - return; - } - txbuf_set_str2("NAMES ", target); - txbuf_send(); -} - static void do_server_info(void) { txbuf_send_str("INFO"); } @@ -293,7 +228,7 @@ unsigned int read_rtclok(void) { } static void rtclok_to_numbuf(void) { - itoa(read_rtclok(), numbuf, 10); + num_to_numbuf(read_rtclok()); } void cmd_server_ping(void) { @@ -314,16 +249,18 @@ void cmd_ctcp_ping(char *nick) { do_ctcp_ping(); } -static void do_ctcp_info(void) { - arg2 = "CLIENTINFO"; +static void do_no_arg_ctcp(char *type) { + arg2 = type; arg3 = 0; send_ctcp(); } +static void do_ctcp_info(void) { + do_no_arg_ctcp("CLIENTINFO"); +} + static void do_ctcp_ver(void) { - arg2 = "VERSION"; - arg3 = 0; - send_ctcp(); + do_no_arg_ctcp("VERSION"); } static void do_ctcp(void) { @@ -357,7 +294,7 @@ static void do_me(void) { txbuf_send(); scr_print_current("\x02* "); - scr_print_current(conf->nick); + scr_print_current(config.nick); scr_print_current("\x02 "); scr_print_current(arg1); scr_eol_current(); @@ -395,9 +332,9 @@ static void do_ver(void) { static void do_color(void) { arg2 = nextarg(arg1); - OS.color2 = atoi(arg1); + OS.color2 = a2uint(arg1); if(arg2) - OS.color1 = atoi(arg2); + OS.color1 = a2uint(arg2); } static void do_query(void) { @@ -444,7 +381,7 @@ static void do_click(void) { OS.noclik ^= 1; } -static int cmd_local(void) { +static char cmd_local(void) { arg1 = nextarg(command); /* @@ -486,29 +423,25 @@ static void cmd_slash(void) { cmd_remote(); } -void cmd_command(char *cmd) { - command = cmd; +void cmd_execute(void) { + if(!*edit_box) return; + command = edit_box; if(scr_current > 1) target = scr_get_cur_name(); else target = 0; - if(cmd[0] == '/' && cmd[1] && cmd[1] != '/') + if(command[0] == '/' && command[1] && command[1] != '/') cmd_slash(); else if(target) cmd_chan_text(); else if(scr_current == SCR_PRIV || scr_current == SCR_SERVER) - cmd_send_pm(cmd); + cmd_send_pm(command); else err_no_scr_target(); } -void cmd_execute(void) { - if(!*edit_box) return; - cmd_command(edit_box); -} - void cmd_rejoin_chans(void) { char i; @@ -519,10 +452,10 @@ void cmd_rejoin_chans(void) { } } - if(!*(conf->extra_channels)) + if(!*(config.extra_channels)) return; - strncpy(edit_box, conf->extra_channels, 128); + strncpy(edit_box, config.extra_channels, 128); arg1 = edit_box; mass_join(0); edbox_clear(); @@ -530,6 +463,7 @@ void cmd_rejoin_chans(void) { /* args contains the destination, space, the msg */ void cmd_send_pm(char *args) { + cmd_def = command_defs; /* element 0 of command_defs must be MSG! */ arg1 = args; do_msg(); } |
