summaryrefslogtreecommitdiff
path: root/src/fe-common/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/fe-common/core')
-rw-r--r--src/fe-common/core/fe-core-commands.c28
-rw-r--r--src/fe-common/core/fe-log.c36
-rw-r--r--src/fe-common/core/fe-settings.c25
-rw-r--r--src/fe-common/core/hilight-text.c35
-rw-r--r--src/fe-common/core/themes.c14
5 files changed, 91 insertions, 47 deletions
diff --git a/src/fe-common/core/fe-core-commands.c b/src/fe-common/core/fe-core-commands.c
index 4de1ae6a..3b725bae 100644
--- a/src/fe-common/core/fe-core-commands.c
+++ b/src/fe-common/core/fe-core-commands.c
@@ -31,7 +31,7 @@
#include "windows.h"
static const char *ret_texts[] = {
- NULL,
+ NULL,
"Not enough parameters given",
"Not connected to IRC server yet",
"Not joined to any channels yet",
@@ -230,15 +230,18 @@ static void cmd_version(char *data)
static void cmd_cat(const char *data)
{
- char *params, *fname, *fposstr;
- char tmpbuf[1024], *str;
LINEBUF_REC *buffer = NULL;
+ char *fname, *fposstr;
+ char tmpbuf[1024], *str;
+ void *free_arg;
int f, ret, recvlen, fpos;
- params = cmd_get_params(data, 2, &fname, &fposstr);
+ if (!cmd_get_params(data, &free_arg, 2, &fname, &fposstr))
+ return;
+
fname = convert_home(fname);
fpos = atoi(fposstr);
- g_free(params);
+ cmd_params_free(free_arg);
f = open(fname, O_RDONLY);
g_free(fname);
@@ -301,15 +304,24 @@ static void event_default_command(const char *data, void *server, WI_ITEM_REC *i
cmd_unknown(data, server, item);
}
-static void event_cmderror(gpointer errorp)
+static void event_cmderror(gpointer errorp, const char *arg)
{
int error;
error = GPOINTER_TO_INT(errorp);
- if (error == CMDERR_ERRNO)
+ switch (error) {
+ case CMDERR_ERRNO:
printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, g_strerror(errno));
- else
+ break;
+ case CMDERR_OPTION_UNKNOWN:
+ printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Unknown argument: %s", arg);
+ break;
+ case CMDERR_OPTION_ARG_MISSING:
+ printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Missing required argument for: %s", arg);
+ break;
+ default:
printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, ret_texts[error]);
+ }
}
void fe_core_commands_init(void)
diff --git a/src/fe-common/core/fe-log.c b/src/fe-common/core/fe-log.c
index c66859b3..1da7e229 100644
--- a/src/fe-common/core/fe-log.c
+++ b/src/fe-common/core/fe-log.c
@@ -45,18 +45,24 @@ static void cmd_log_open(const char *data)
{
/* /LOG OPEN [-noopen] [-autoopen] [-targets <targets>] [-window]
[-rotate hour|day|week|month] <fname> [<levels>] */
- char *params, *args, *targetarg, *rotatearg, *fname, *levels;
+ GHashTable *optlist;
+ char *targetarg, *rotatearg, *fname, *levels;
+ void *free_arg;
char window[MAX_INT_STRLEN];
LOG_REC *log;
int level, rotate;
- args = "targets rotate";
- params = cmd_get_params(data, 5 | PARAM_FLAG_MULTIARGS | PARAM_FLAG_GETREST,
- &args, &targetarg, &rotatearg, &fname, &levels);
+ if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS | PARAM_FLAG_GETREST,
+ "log open", &optlist, &fname, &levels))
+ return;
+
+ targetarg = g_hash_table_lookup(optlist, "targets");
+ rotatearg = g_hash_table_lookup(optlist, "rotate");
+
if (*fname == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
rotate = LOG_ROTATE_NEVER;
- if (stristr(args, "-rotate")) {
+ if (rotatearg != NULL) {
rotate = log_str2rotate(rotatearg);
if (rotate < 0) rotate = LOG_ROTATE_NEVER;
}
@@ -64,7 +70,7 @@ static void cmd_log_open(const char *data)
level = level2bits(levels);
if (level == 0) level = MSGLEVEL_ALL;
- if (stristr(args, "-window")) {
+ if (g_hash_table_lookup(optlist, "window")) {
/* log by window ref# */
ltoa(window, active_win->refnum);
targetarg = window;
@@ -72,12 +78,12 @@ static void cmd_log_open(const char *data)
log = log_create_rec(fname, level, targetarg);
if (log != NULL) {
- if (stristr(args, "-autoopen"))
+ if (g_hash_table_lookup(optlist, "autoopen"))
log->autoopen = TRUE;
log->rotate = rotate;
log_update(log);
- if (log->handle == -1 && stristr(args, "-noopen") == NULL) {
+ if (log->handle == -1 && g_hash_table_lookup(optlist, "noopen") == NULL) {
/* start logging */
if (log_start_logging(log)) {
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
@@ -88,7 +94,7 @@ static void cmd_log_open(const char *data)
}
}
- g_free(params);
+ cmd_params_free(free_arg);
}
static LOG_REC *log_find_from_data(const char *data)
@@ -191,10 +197,12 @@ static void cmd_window_log(const char *data)
{
/* /WINDOW LOG ON|OFF|TOGGLE [<filename>] */
LOG_REC *log;
- char *params, *set, *fname, window[MAX_INT_STRLEN];
+ char *set, *fname, window[MAX_INT_STRLEN];
+ void *free_arg;
int open_log, close_log;
- params = cmd_get_params(data, 2, &set, &fname);
+ if (!cmd_get_params(data, &free_arg, 2, &set, &fname))
+ return;
ltoa(window, active_win->refnum);
log = log_find_item(window);
@@ -209,7 +217,7 @@ static void cmd_window_log(const char *data)
close_log = log != NULL;
} else {
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_NOT_TOGGLE);
- g_free(params);
+ cmd_params_free(free_arg);
return;
}
@@ -232,7 +240,7 @@ static void cmd_window_log(const char *data)
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_LOG_CLOSED, log->fname);
}
- g_free(params);
+ cmd_params_free(free_arg);
}
/* Create log file entry to window, but don't start logging */
@@ -440,6 +448,8 @@ void fe_log_init(void)
signal_add("log create failed", (SIGNAL_FUNC) sig_log_create_failed);
signal_add("awaylog show", (SIGNAL_FUNC) sig_awaylog_show);
signal_add("setup changed", (SIGNAL_FUNC) read_settings);
+
+ command_set_options("log open", "noopen autoopen -targets window -rotate");
}
void fe_log_deinit(void)
diff --git a/src/fe-common/core/fe-settings.c b/src/fe-common/core/fe-settings.c
index f05faad0..299f437e 100644
--- a/src/fe-common/core/fe-settings.c
+++ b/src/fe-common/core/fe-settings.c
@@ -66,10 +66,12 @@ static void set_boolean(const char *key, const char *value)
static void cmd_set(char *data)
{
GSList *sets, *tmp;
- char *params, *key, *value, *last_section;
+ char *key, *value, *last_section;
+ void *free_arg;
int found;
- params = cmd_get_params(data, 2 | PARAM_FLAG_GETREST, &key, &value);
+ if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &key, &value))
+ return;
last_section = ""; found = 0;
sets = settings_get_sorted();
@@ -110,15 +112,17 @@ static void cmd_set(char *data)
if (!found)
printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Unknown setting %s", key);
- g_free(params);
+ cmd_params_free(free_arg);
}
static void cmd_toggle(const char *data)
{
- char *params, *key, *value;
+ char *key, *value;
+ void *free_arg;
int type;
- params = cmd_get_params(data, 2 | PARAM_FLAG_GETREST, &key, &value);
+ if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &key, &value))
+ return;
type = settings_get_type(key);
if (type == -1)
@@ -130,7 +134,7 @@ static void cmd_toggle(const char *data)
set_print(settings_get_record(key));
}
- g_free(params);
+ cmd_params_free(free_arg);
}
static void show_aliases(const char *alias)
@@ -173,11 +177,14 @@ static void alias_remove(const char *alias)
static void cmd_alias(const char *data)
{
- char *params, *alias, *value;
+ char *alias, *value;
+ void *free_arg;
g_return_if_fail(data != NULL);
- params = cmd_get_params(data, 2 | PARAM_FLAG_GETREST, &alias, &value);
+ if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &alias, &value))
+ return;
+
if (*alias == '-') {
if (alias[1] != '\0') alias_remove(alias+1);
} else if (*alias == '\0' || *value == '\0')
@@ -186,7 +193,7 @@ static void cmd_alias(const char *data)
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_ALIAS_ADDED, alias);
iconfig_set_str("aliases", alias, value);
}
- g_free(params);
+ cmd_params_free(free_arg);
}
static void cmd_unalias(const char *data)
diff --git a/src/fe-common/core/hilight-text.c b/src/fe-common/core/hilight-text.c
index f78d8904..d2da11cd 100644
--- a/src/fe-common/core/hilight-text.c
+++ b/src/fe-common/core/hilight-text.c
@@ -268,9 +268,11 @@ static void cmd_hilight_show(void)
static void cmd_hilight(const char *data)
{
/* /HILIGHT [-nick | -regexp | -word] [-color <color>] [-level <level>] [-channels <channels>] <text> */
- char *params, *args, *colorarg, *levelarg, *chanarg, *text;
- char **channels;
+ GHashTable *optlist;
HILIGHT_REC *rec;
+ char *colorarg, *levelarg, *chanarg, *text;
+ char **channels;
+ void *free_arg;
g_return_if_fail(data != NULL);
@@ -279,12 +281,17 @@ static void cmd_hilight(const char *data)
return;
}
- args = "color level channels";
- params = cmd_get_params(data, 5 | PARAM_FLAG_MULTIARGS | PARAM_FLAG_GETREST,
- &args, &colorarg, &levelarg, &chanarg, &text);
+ if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS |
+ PARAM_FLAG_GETREST, "hilight", &optlist, &text))
+ return;
+
+ chanarg = g_hash_table_lookup(optlist, "channels");
+ levelarg = g_hash_table_lookup(optlist, "level");
+ colorarg = g_hash_table_lookup(optlist, "color");
+
if (*text == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
- channels = *chanarg == '\0' ? NULL :
+ channels = (chanarg == NULL || *chanarg == '\0') ? NULL :
g_strsplit(replace_chars(chanarg, ',', ' '), " ", -1);
rec = hilight_find(text, channels);
@@ -302,17 +309,19 @@ static void cmd_hilight(const char *data)
}
hilights = g_slist_append(hilights, rec);
- rec->nickmask = stristr(args, "-nick") != NULL;
- rec->fullword = stristr(args, "-word") != NULL;
- rec->regexp = stristr(args, "-regexp") != NULL;
+ rec->nickmask = g_hash_table_lookup(optlist, "nick") != NULL;
+ rec->fullword = g_hash_table_lookup(optlist, "word") != NULL;
+ rec->regexp = g_hash_table_lookup(optlist, "regexp") != NULL;
- rec->level = level2bits(replace_chars(levelarg, ',', ' '));
- if (*colorarg != '\0') rec->color = g_strdup(colorarg);
+ rec->level = (levelarg == NULL || *levelarg == '\0') ? 0 :
+ level2bits(replace_chars(levelarg, ',', ' '));
+ if (colorarg != NULL && *colorarg != '\0')
+ rec->color = g_strdup(colorarg);
hilight_print(g_slist_index(hilights, rec)+1, rec);
hilight_add_config(rec);
- g_free(params);
+ cmd_params_free(free_arg);
}
static void cmd_dehilight(const char *data)
@@ -349,6 +358,8 @@ void hilight_text_init(void)
signal_add("setup reread", (SIGNAL_FUNC) read_hilight_config);
command_bind("hilight", NULL, (SIGNAL_FUNC) cmd_hilight);
command_bind("dehilight", NULL, (SIGNAL_FUNC) cmd_dehilight);
+
+ command_set_options("hilight", "-color -level -channels nick word regexp");
}
void hilight_text_deinit(void)
diff --git a/src/fe-common/core/themes.c b/src/fe-common/core/themes.c
index 879f558c..efe905bf 100644
--- a/src/fe-common/core/themes.c
+++ b/src/fe-common/core/themes.c
@@ -348,17 +348,21 @@ static void theme_show(THEME_SEARCH_REC *rec, const char *key, const char *value
static void cmd_format(const char *data)
{
- char *params, *module, *key, *value;
GSList *tmp, *modules;
+ char *module, *key, *value;
+ void *free_arg;
/* /FORMAT [<module>] [<key> [<value>]] */
- params = cmd_get_params(data, 3 | PARAM_FLAG_GETREST, &module, &key, &value);
+ if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST,
+ &module, &key, &value))
+ return;
modules = get_sorted_modules();
if (*module != '\0' && theme_search(modules, module) == NULL) {
/* first argument isn't module.. */
- g_free(params);
- params = cmd_get_params(data, 2 | PARAM_FLAG_GETREST, &key, &value);
+ cmd_params_free(free_arg);
+ if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &key, &value))
+ return;
module = "";
}
@@ -374,7 +378,7 @@ static void cmd_format(const char *data)
g_slist_foreach(modules, (GFunc) g_free, NULL);
g_slist_free(modules);
- g_free(params);
+ cmd_params_free(free_arg);
}
static void module_save(const char *module, MODULE_THEME_REC *rec, CONFIG_NODE *fnode)