mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-30 01:36:21 +00:00
Refactored cmd_join to use parse_options
This commit is contained in:
@@ -1551,7 +1551,6 @@ cmd_join(gchar **args, struct cmd_help_t help)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int num_args = g_strv_length(args);
|
|
||||||
char *room = NULL;
|
char *room = NULL;
|
||||||
char *nick = NULL;
|
char *nick = NULL;
|
||||||
char *passwd = NULL;
|
char *passwd = NULL;
|
||||||
@@ -1572,40 +1571,23 @@ cmd_join(gchar **args, struct cmd_help_t help)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Additional args supplied
|
// Additional args supplied
|
||||||
if (num_args > 1) {
|
GList *opt_keys = NULL;
|
||||||
char *opt1 = args[1];
|
opt_keys = g_list_append(opt_keys, "nick");
|
||||||
char *opt1val = args[2];
|
opt_keys = g_list_append(opt_keys, "password");
|
||||||
char *opt2 = args[3];
|
gboolean parsed;
|
||||||
char *opt2val = args[4];
|
|
||||||
if (opt1 != NULL) {
|
GHashTable *options = parse_options(args, 1, opt_keys, &parsed);
|
||||||
if (opt1val == NULL) {
|
if (!parsed) {
|
||||||
cons_show("Usage: %s", help.usage);
|
cons_show("Usage: %s", help.usage);
|
||||||
cons_show("");
|
cons_show("");
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
|
||||||
if (strcmp(opt1, "nick") == 0) {
|
|
||||||
nick = opt1val;
|
|
||||||
} else if (strcmp(opt1, "password") == 0) {
|
|
||||||
passwd = opt1val;
|
|
||||||
} else {
|
|
||||||
cons_show("Usage: %s", help.usage);
|
|
||||||
cons_show("");
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
if (opt2 != NULL) {
|
|
||||||
if (strcmp(opt2, "nick") == 0) {
|
|
||||||
nick = opt2val;
|
|
||||||
} else if (strcmp(opt2, "password") == 0) {
|
|
||||||
passwd = opt2val;
|
|
||||||
} else {
|
|
||||||
cons_show("Usage: %s", help.usage);
|
|
||||||
cons_show("");
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nick = g_hash_table_lookup(options, "nick");
|
||||||
|
passwd = g_hash_table_lookup(options, "password");
|
||||||
|
|
||||||
|
options_destroy(options);
|
||||||
|
|
||||||
// In the case that a nick wasn't provided by the optional args...
|
// In the case that a nick wasn't provided by the optional args...
|
||||||
if (nick == NULL) {
|
if (nick == NULL) {
|
||||||
nick = account->muc_nick;
|
nick = account->muc_nick;
|
||||||
|
|||||||
@@ -390,13 +390,13 @@ parse_options(gchar **args, int start, GList *keys, gboolean *res)
|
|||||||
GList *found_keys = NULL;
|
GList *found_keys = NULL;
|
||||||
for (curr = start; curr < g_strv_length(args); curr+= 2) {
|
for (curr = start; curr < g_strv_length(args); curr+= 2) {
|
||||||
// check if option valid
|
// check if option valid
|
||||||
if (g_list_find(keys, args[curr]) == NULL) {
|
if (g_list_find_custom(keys, args[curr], (GCompareFunc)g_strcmp0) == NULL) {
|
||||||
*res = FALSE;
|
*res = FALSE;
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if duplicate
|
// check if duplicate
|
||||||
if (g_list_find(found_keys, args[curr]) != NULL) {
|
if (g_list_find_custom(found_keys, args[curr], (GCompareFunc)g_strcmp0) != NULL) {
|
||||||
*res = FALSE;
|
*res = FALSE;
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user