diff options
Diffstat (limited to 'src/fe-common')
-rw-r--r-- | src/fe-common/core/chat-completion.c | 14 | ||||
-rw-r--r-- | src/fe-common/core/completion.c | 25 | ||||
-rw-r--r-- | src/fe-common/core/fe-ignore.c | 5 | ||||
-rw-r--r-- | src/fe-common/core/fe-server.c | 17 | ||||
-rw-r--r-- | src/fe-common/core/hilight-text.c | 50 | ||||
-rw-r--r-- | src/fe-common/core/hilight-text.h | 12 |
6 files changed, 55 insertions, 68 deletions
diff --git a/src/fe-common/core/chat-completion.c b/src/fe-common/core/chat-completion.c index 1f00feaf..97cd0565 100644 --- a/src/fe-common/core/chat-completion.c +++ b/src/fe-common/core/chat-completion.c @@ -1011,13 +1011,17 @@ static void sig_complete_target(GList **list, WINDOW_REC *window, } } +static void event_text(const char *data, SERVER_REC *server, WI_ITEM_REC *item); + /* expand \n, \t and \\ */ static char *expand_escapes(const char *line, SERVER_REC *server, WI_ITEM_REC *item) { char *ptr, *ret; - int chr; + const char *prev; + int chr; + prev = line; ret = ptr = g_malloc(strlen(line)+1); for (; *line != '\0'; line++) { if (*line != '\\') { @@ -1036,9 +1040,11 @@ static char *expand_escapes(const char *line, SERVER_REC *server, /* newline .. we need to send another "send text" event to handle it (or actually the text before the newline..) */ - if (ret != ptr) { - *ptr = '\0'; - signal_emit("send text", 3, ret, server, item); + if (prev != line) { + char *prev_line = g_strndup(prev, (line - prev) - 1); + event_text(prev_line, server, item); + g_free(prev_line); + prev = line + 1; ptr = ret; } } else if (chr != -1) { diff --git a/src/fe-common/core/completion.c b/src/fe-common/core/completion.c index a97adc21..78b1b24b 100644 --- a/src/fe-common/core/completion.c +++ b/src/fe-common/core/completion.c @@ -137,8 +137,9 @@ char *word_complete(WINDOW_REC *window, const char *line, int *pos, int erase, i int old_startpos, old_wordlen; GString *result; - char *word, *wordstart, *linestart, *ret; - int continue_complete, want_space; + const char *cmdchars; + char *word, *wordstart, *linestart, *ret, *data; + int continue_complete, want_space, expand_escapes; g_return_val_if_fail(line != NULL, NULL); g_return_val_if_fail(pos != NULL, NULL); @@ -241,14 +242,24 @@ char *word_complete(WINDOW_REC *window, const char *line, int *pos, int erase, i if (complist == NULL) return NULL; + /* get the cmd char */ + cmdchars = settings_get_str("cmdchars"); + + /* get the expand_escapes setting */ + expand_escapes = settings_get_bool("expand_escapes"); + + /* escape if the word doesn't begin with '/' and expand_escapes are turned on */ + data = strchr(cmdchars, *line) == NULL && expand_escapes ? + escape_string(complist->data) : g_strdup(complist->data); + /* word completed */ - *pos = startpos+strlen(complist->data); + *pos = startpos + strlen(data); /* replace the word in line - we need to return a full new line */ result = g_string_new(line); g_string_erase(result, startpos, wordlen); - g_string_insert(result, startpos, complist->data); + g_string_insert(result, startpos, data); if (want_space) { if (!isseparator(result->str[*pos])) @@ -256,13 +267,17 @@ char *word_complete(WINDOW_REC *window, const char *line, int *pos, int erase, i (*pos)++; } - wordlen = strlen(complist->data); + wordlen = strlen(data); last_line_pos = *pos; g_free_not_null(last_line); last_line = g_strdup(result->str); ret = result->str; g_string_free(result, FALSE); + + /* free the data */ + g_free(data); + return ret; } diff --git a/src/fe-common/core/fe-ignore.c b/src/fe-common/core/fe-ignore.c index 800e881d..03fd4dd2 100644 --- a/src/fe-common/core/fe-ignore.c +++ b/src/fe-common/core/fe-ignore.c @@ -58,13 +58,8 @@ static void ignore_print(int index, IGNORE_REC *rec) g_string_append(options, "-regexp "); if (rec->pattern == NULL) g_string_append(options, "[INVALID! -pattern missing] "); -#ifdef USE_GREGEX else if (rec->preg == NULL) g_string_append(options, "[INVALID!] "); -#else - else if (!rec->regexp_compiled) - g_string_append(options, "[INVALID!] "); -#endif } if (rec->fullword) g_string_append(options, "-full "); if (rec->replies) g_string_append(options, "-replies "); diff --git a/src/fe-common/core/fe-server.c b/src/fe-common/core/fe-server.c index e8e9f33f..810afe83 100644 --- a/src/fe-common/core/fe-server.c +++ b/src/fe-common/core/fe-server.c @@ -117,7 +117,18 @@ static void cmd_server_add_modify(const char *data, gboolean add) return; if (*addr == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS); - port = *portstr == '\0' ? DEFAULT_SERVER_ADD_PORT : atoi(portstr); + + value = g_hash_table_lookup(optlist, "port"); + + if (*portstr != '\0') + port = atoi(portstr); + else if (value != NULL && *value != '\0') + port = atoi(value); + else if (g_hash_table_lookup(optlist, "tls") || + g_hash_table_lookup(optlist, "ssl")) + port = DEFAULT_SERVER_ADD_TLS_PORT; + else + port = DEFAULT_SERVER_ADD_PORT; chatnet = g_hash_table_lookup(optlist, "network"); @@ -139,8 +150,8 @@ static void cmd_server_add_modify(const char *data, gboolean add) rec->address = g_strdup(addr); rec->port = port; } else { - value = g_hash_table_lookup(optlist, "port"); - if (value != NULL && *value != '\0') rec->port = atoi(value); + if (*portstr != '\0' || g_hash_table_lookup(optlist, "port")) + rec->port = port; if (*password != '\0') g_free_and_null(rec->password); if (g_hash_table_lookup(optlist, "host")) { diff --git a/src/fe-common/core/hilight-text.c b/src/fe-common/core/hilight-text.c index dd38be87..62e6f0de 100644 --- a/src/fe-common/core/hilight-text.c +++ b/src/fe-common/core/hilight-text.c @@ -26,6 +26,7 @@ #include "misc.h" #include "lib-config/iconfig.h" #include "settings.h" +#include "iregex.h" #include "servers.h" #include "channels.h" @@ -101,11 +102,7 @@ static void hilight_destroy(HILIGHT_REC *rec) { g_return_if_fail(rec != NULL); -#ifdef USE_GREGEX - if (rec->preg != NULL) g_regex_unref(rec->preg); -#else - if (rec->regexp_compiled) regfree(&rec->preg); -#endif + if (rec->preg != NULL) i_regex_unref(rec->preg); if (rec->channels != NULL) g_strfreev(rec->channels); g_free_not_null(rec->color); g_free_not_null(rec->act_color); @@ -122,19 +119,10 @@ static void hilights_destroy_all(void) static void hilight_init_rec(HILIGHT_REC *rec) { -#ifdef USE_GREGEX if (rec->preg != NULL) - g_regex_unref(rec->preg); + i_regex_unref(rec->preg); - rec->preg = g_regex_new(rec->text, G_REGEX_OPTIMIZE | G_REGEX_RAW | G_REGEX_CASELESS, 0, NULL); -#else - if (rec->regexp_compiled) regfree(&rec->preg); - if (!rec->regexp) - rec->regexp_compiled = FALSE; - else - rec->regexp_compiled = regcomp(&rec->preg, rec->text, - rec->case_sensitive ? REG_EXTENDED : (REG_EXTENDED|REG_ICASE)) == 0; -#endif + rec->preg = i_regex_new(rec->text, G_REGEX_OPTIMIZE | G_REGEX_CASELESS, 0, NULL); } void hilight_create(HILIGHT_REC *rec) @@ -207,30 +195,15 @@ static gboolean hilight_match_text(HILIGHT_REC *rec, const char *text, gboolean ret = FALSE; if (rec->regexp) { -#ifdef USE_GREGEX if (rec->preg != NULL) { - GMatchInfo *match; - - g_regex_match (rec->preg, text, 0, &match); + MatchInfo *match; + i_regex_match(rec->preg, text, 0, &match); - if (g_match_info_matches(match)) - ret = g_match_info_fetch_pos(match, 0, match_beg, match_end); + if (i_match_info_matches(match)) + ret = i_match_info_fetch_pos(match, 0, match_beg, match_end); - g_match_info_free(match); - } -#else - regmatch_t rmatch[1]; - - if (rec->regexp_compiled && - regexec(&rec->preg, text, 1, rmatch, 0) == 0) { - if (rmatch[0].rm_so > 0 && - match_beg != NULL && match_end != NULL) { - *match_beg = rmatch[0].rm_so; - *match_end = rmatch[0].rm_eo; - } - ret = TRUE; + i_match_info_free(match); } -#endif } else { char *match; @@ -524,13 +497,8 @@ static void hilight_print(int index, HILIGHT_REC *rec) if (rec->case_sensitive) g_string_append(options, "-matchcase "); if (rec->regexp) { g_string_append(options, "-regexp "); -#ifdef USE_GREGEX if (rec->preg == NULL) g_string_append(options, "[INVALID!] "); -#else - if (!rec->regexp_compiled) - g_string_append(options, "[INVALID!] "); -#endif } if (rec->priority != 0) diff --git a/src/fe-common/core/hilight-text.h b/src/fe-common/core/hilight-text.h index 76beec1f..1d942f29 100644 --- a/src/fe-common/core/hilight-text.h +++ b/src/fe-common/core/hilight-text.h @@ -1,10 +1,7 @@ #ifndef __HILIGHT_TEXT_H #define __HILIGHT_TEXT_H -#ifndef USE_GREGEX -# include <regex.h> -#endif - +#include "iregex.h" #include "formats.h" struct _HILIGHT_REC { @@ -24,12 +21,7 @@ struct _HILIGHT_REC { unsigned int fullword:1; /* match `text' only for full words */ unsigned int regexp:1; /* `text' is a regular expression */ unsigned int case_sensitive:1;/* `text' must match case */ -#ifdef USE_GREGEX - GRegex *preg; -#else - unsigned int regexp_compiled:1; /* should always be TRUE, unless regexp is invalid */ - regex_t preg; -#endif + Regex *preg; char *servertag; }; |