1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-02-02 15:08:15 -05:00

Tidy start commands

This commit is contained in:
James Booth 2012-02-18 23:09:21 +00:00
parent 547704b65a
commit 34fba754ea

View File

@ -5,6 +5,11 @@
#include "windows.h" #include "windows.h"
#include "util.h" #include "util.h"
static int _cmd_start_quit(void);
static int _cmd_start_help(void);
static int _cmd_start_connect(char *inp);
static int _cmd_start_default(char *inp);
static int _cmd_quit(void); static int _cmd_quit(void);
static int _cmd_help(void); static int _cmd_help(void);
static int _cmd_who(void); static int _cmd_who(void);
@ -31,46 +36,18 @@ int handle_start_command(char *inp)
// get the command "/command" // get the command "/command"
char *command = strtok(inp_cpy, " "); char *command = strtok(inp_cpy, " ");
// handle invalid commands
if (!_valid_start_command(command)) { if (!_valid_start_command(command)) {
cons_bad_command(command); cons_bad_command(command);
gui_refresh(); gui_refresh();
result = AWAIT_COMMAND; result = AWAIT_COMMAND;
// quit
} else if (strcmp(command, "/quit") == 0) { } else if (strcmp(command, "/quit") == 0) {
result = QUIT_PROF; result = _cmd_start_quit();
// help
} else if (strcmp(command, "/help") == 0) { } else if (strcmp(command, "/help") == 0) {
cons_help(); result = _cmd_start_help();
gui_refresh();
result = AWAIT_COMMAND;
// connect
} else if (strcmp(command, "/connect") == 0) { } else if (strcmp(command, "/connect") == 0) {
if (strlen(inp) < 10) { result = _cmd_start_connect(inp);
cons_bad_connect();
gui_refresh();
result = AWAIT_COMMAND;
} else { } else {
char *user; result = _cmd_start_default(inp);
user = strndup(inp+9, strlen(inp)-9);
status_bar_get_password();
status_bar_refresh();
char passwd[20];
inp_get_password(passwd);
int connect_status = jabber_connect(user, passwd);
if (connect_status == CONNECTING)
result = START_MAIN;
else
result = AWAIT_COMMAND;
}
} else {
cons_bad_command(inp);
gui_refresh();
result = AWAIT_COMMAND;
} }
inp_clear(); inp_clear();
@ -101,6 +78,52 @@ int handle_command(char *cmd)
} }
static int _cmd_start_quit(void)
{
return QUIT_PROF;
}
static int _cmd_start_help(void)
{
cons_help();
gui_refresh();
return AWAIT_COMMAND;
}
static int _cmd_start_connect(char *inp)
{
int result = AWAIT_COMMAND;
if (strlen(inp) < 10) {
cons_bad_connect();
gui_refresh();
result = AWAIT_COMMAND;
} else {
char *user;
user = strndup(inp+9, strlen(inp)-9);
status_bar_get_password();
status_bar_refresh();
char passwd[20];
inp_get_password(passwd);
int connect_status = jabber_connect(user, passwd);
if (connect_status == CONNECTING)
result = START_MAIN;
else
result = AWAIT_COMMAND;
}
return result;
}
static int _cmd_start_default(char *inp)
{
cons_bad_command(inp);
gui_refresh();
return AWAIT_COMMAND;
}
static int _cmd_quit(void) static int _cmd_quit(void)
{ {
return FALSE; return FALSE;