summaryrefslogtreecommitdiff
path: root/src/fe-text/gui-windows.c
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2001-03-03 17:45:35 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2001-03-03 17:45:35 +0000
commit95c17bafc46714702092dacdab7d58bb005a158d (patch)
treeceb38718e072e4f418f2a16c52e5e0e835b3d6b5 /src/fe-text/gui-windows.c
parenta47ce2c449575f0c3212779bdfc1e69cab41aab1 (diff)
downloadirssi-95c17bafc46714702092dacdab7d58bb005a158d.zip
/LASTLOG: -case option for case-sensitive matches. -force option is now
required to print lastlogs longer than 1000 lines. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1310 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/fe-text/gui-windows.c')
-rw-r--r--src/fe-text/gui-windows.c170
1 files changed, 114 insertions, 56 deletions
diff --git a/src/fe-text/gui-windows.c b/src/fe-text/gui-windows.c
index 832e5a57..f791cc9a 100644
--- a/src/fe-text/gui-windows.c
+++ b/src/fe-text/gui-windows.c
@@ -789,81 +789,139 @@ static void signal_window_changed(WINDOW_REC *window)
screen_refresh_thaw();
}
-GList *gui_window_find_text(WINDOW_REC *window, const char *text,
- GList *startline, int regexp, int fullword)
+void gui_window_line2text(LINE_REC *line, int coloring, GString *str)
{
-#ifdef HAVE_REGEX_H
- regex_t preg;
-#endif
- GList *tmp;
- GList *matches;
- gchar *str, *ptr;
- gint n, size;
+ int color;
+ unsigned char cmd;
+ char *ptr, *tmp;
+
+ g_return_if_fail(line != NULL);
+ g_return_if_fail(str != NULL);
+
+ g_string_truncate(str, 0);
+
+ color = 0;
+ for (ptr = line->text;;) {
+ if (*ptr != 0) {
+ g_string_append_c(str, *ptr);
+ ptr++;
+ continue;
+ }
+
+ ptr++;
+ cmd = (unsigned char) *ptr;
+ ptr++;
+
+ if (cmd == LINE_CMD_EOL || cmd == LINE_CMD_FORMAT) {
+ /* end of line */
+ break;
+ }
+
+ if (cmd == LINE_CMD_CONTINUE) {
+ /* line continues in another address.. */
+ memcpy(&tmp, ptr, sizeof(char *));
+ ptr = tmp;
+ continue;
+ }
- g_return_val_if_fail(window != NULL, NULL);
- g_return_val_if_fail(text != NULL, NULL);
+ if (!coloring) {
+ /* no colors, skip coloring commands */
+ continue;
+ }
- matches = NULL; size = 1024; str = g_malloc(1024);
+ if ((cmd & 0x80) == 0) {
+ /* set color */
+ color = cmd;
+ g_string_sprintfa(str, "\004%c%c",
+ (color & 0x0f)+'0',
+ ((color & 0xf0) >> 4)+'0');
+ } else switch (cmd) {
+ case LINE_CMD_UNDERLINE:
+ g_string_append_c(str, 31);
+ break;
+ case LINE_CMD_COLOR0:
+ g_string_sprintfa(str, "\004%c%c",
+ '0', ((color & 0xf0) >> 4)+'0');
+ break;
+ case LINE_CMD_COLOR8:
+ g_string_sprintfa(str, "\004%c%c",
+ '8', ((color & 0xf0) >> 4)+'0');
+ color &= 0xfff0;
+ color |= 8|ATTR_COLOR8;
+ break;
+ case LINE_CMD_BLINK:
+ color |= 0x80;
+ g_string_sprintfa(str, "\004%c%c", (color & 0x0f)+'0',
+ ((color & 0xf0) >> 4)+'0');
+ break;
+ case LINE_CMD_INDENT:
+ break;
+ }
+ }
+}
+GList *gui_window_find_text(WINDOW_REC *window, GList *startline,
+ int level, int nolevel, const char *text,
+ int regexp, int fullword, int case_sensitive)
+{
#ifdef HAVE_REGEX_H
- if (regcomp(&preg, text, REG_ICASE|REG_EXTENDED|REG_NOSUB) != 0)
- return 0;
+ regex_t preg;
#endif
+ GList *tmp;
+ GList *matches;
+ GString *str;
- if (startline == NULL) startline = WINDOW_GUI(window)->lines;
- for (tmp = startline; tmp != NULL; tmp = tmp->next)
- {
- LINE_REC *rec = tmp->data;
+ g_return_val_if_fail(window != NULL, NULL);
+ g_return_val_if_fail(text != NULL, NULL);
- if (*text == '\0') {
- matches = g_list_append(matches, rec);
- continue;
+ if (regexp) {
+#ifdef HAVE_REGEX_H
+ int flags = REG_EXTENDED | REG_NOSUB |
+ (case_sensitive ? 0 : REG_ICASE);
+ if (regcomp(&preg, text, flags) != 0)
+ return NULL;
+#else
+ return NULL;
+#endif
}
- for (n = 0, ptr = rec->text; ; ptr++)
- {
- if (*ptr != 0)
- {
- if (n+2 > size)
- {
- size += 1024;
- str = g_realloc(str, size);
- }
- str[n++] = toupper(*ptr);
- }
- else
- {
- ptr++;
+ matches = NULL;
+ str = g_string_new(NULL);
+
+ if (startline == NULL)
+ startline = WINDOW_GUI(window)->lines;
+
+ for (tmp = startline; tmp != NULL; tmp = tmp->next) {
+ LINE_REC *rec = tmp->data;
- if ((guchar) *ptr == LINE_CMD_CONTINUE)
- {
- gchar *tmp;
+ if ((rec->level & level) == 0 || (rec->level & nolevel) != 0)
+ continue;
- memcpy(&tmp, ptr+1, sizeof(gchar *));
- ptr = tmp-1;
+ if (*text == '\0') {
+ /* no search word, everything matches */
+ matches = g_list_append(matches, rec);
+ continue;
}
- else if ((guchar) *ptr == LINE_CMD_EOL ||
- (guchar) *ptr == LINE_CMD_FORMAT)
- break;
- }
- }
- str[n] = '\0';
- if (
+ gui_window_line2text(rec, FALSE, str);
+
+ if (
#ifdef HAVE_REGEX_H
- regexp ? regexec(&preg, str, 0, NULL, 0) == 0 :
+ regexp ? regexec(&preg, str->str, 0, NULL, 0) == 0 :
#endif
- fullword ? stristr_full(str, text) != NULL :
- stristr(str, text) != NULL) {
- /* matched */
- matches = g_list_append(matches, rec);
+ fullword ? strstr_full_case(str->str, text,
+ !case_sensitive) != NULL :
+ case_sensitive ? strstr(str->str, text) != NULL :
+ stristr(str->str, text) != NULL) {
+ /* matched */
+ matches = g_list_append(matches, rec);
+ }
}
- }
#ifdef HAVE_REGEX_H
- regfree(&preg);
+ if (regexp) regfree(&preg);
#endif
- if (str != NULL) g_free(str);
- return matches;
+ g_string_free(str, TRUE);
+ return matches;
}
static void gui_update_bottom_startline(GUI_WINDOW_REC *gui)