comparison mcabber/src/screen.c @ 1521:33f8f795abd2

Check for regex support in glib This is needed for the "url_regex" option.
author Mikael Berthe <mikael@lilotux.net>
date Tue, 30 Sep 2008 19:50:46 +0200
parents 41d3457af815
children 5ef122b2bb75
comparison
equal deleted inserted replaced
1520:41d3457af815 1521:33f8f795abd2
142 char *seqstr; 142 char *seqstr;
143 guint mkeycode; 143 guint mkeycode;
144 gint value; 144 gint value;
145 } keyseq; 145 } keyseq;
146 146
147 #ifdef HAVE_GLIB_REGEX
147 static GRegex *url_regex; 148 static GRegex *url_regex;
149 #endif
148 150
149 GSList *keyseqlist; 151 GSList *keyseqlist;
150 static void add_keyseq(char *seqstr, guint mkeycode, gint value); 152 static void add_keyseq(char *seqstr, guint mkeycode, gint value);
151 153
152 void scr_WriteInWindow(const char *winId, const char *text, time_t timestamp, 154 void scr_WriteInWindow(const char *winId, const char *text, time_t timestamp,
745 // to update Log_Win_Height and set max{X,Y} 747 // to update Log_Win_Height and set max{X,Y}
746 748
747 inputLine[0] = 0; 749 inputLine[0] = 0;
748 ptr_inputline = inputLine; 750 ptr_inputline = inputLine;
749 751
750 if (settings_opt_get("url_regex")) 752 if (settings_opt_get("url_regex")) {
753 #ifdef HAVE_GLIB_REGEX
751 url_regex = g_regex_new(settings_opt_get("url_regex"), 754 url_regex = g_regex_new(settings_opt_get("url_regex"),
752 G_REGEX_OPTIMIZE, 0, NULL); 755 G_REGEX_OPTIMIZE, 0, NULL);
756 #else
757 scr_LogPrint(LPRINT_LOGNORM, "ERROR: Your glib version is too old, "
758 "cannot use url_regex.");
759 #endif // HAVE_GLIB_REGEX
760 }
753 761
754 Curses = TRUE; 762 Curses = TRUE;
755 return; 763 return;
756 } 764 }
757 765
759 { 767 {
760 if (!Curses) return; 768 if (!Curses) return;
761 clear(); 769 clear();
762 refresh(); 770 refresh();
763 endwin(); 771 endwin();
772 #ifdef HAVE_GLIB_REGEX
764 if (url_regex) 773 if (url_regex)
765 g_regex_unref(url_regex); 774 g_regex_unref(url_regex);
775 #endif
766 Curses = FALSE; 776 Curses = FALSE;
767 return; 777 return;
768 } 778 }
769 779
770 void scr_Beep(void) 780 void scr_Beep(void)
1996 scr_Resize(); 2006 scr_Resize();
1997 redrawwin(stdscr); 2007 redrawwin(stdscr);
1998 } 2008 }
1999 } 2009 }
2000 2010
2001 inline void scr_LogUrls(const gchar *string) 2011 #ifdef HAVE_GLIB_REGEX
2012 static inline void scr_LogUrls(const gchar *string)
2002 { 2013 {
2003 GMatchInfo *match_info; 2014 GMatchInfo *match_info;
2004 GError *error = NULL; 2015 GError *error = NULL;
2005 2016
2006 g_regex_match_full(url_regex, string, -1, 0, 0, &match_info, &error); 2017 g_regex_match_full(url_regex, string, -1, 0, 0, &match_info, &error);
2010 g_free(url); 2021 g_free(url);
2011 g_match_info_next(match_info, &error); 2022 g_match_info_next(match_info, &error);
2012 } 2023 }
2013 g_match_info_free(match_info); 2024 g_match_info_free(match_info);
2014 } 2025 }
2026 #endif
2015 2027
2016 inline void scr_WriteMessage(const char *bjid, const char *text, 2028 inline void scr_WriteMessage(const char *bjid, const char *text,
2017 time_t timestamp, guint prefix_flags, 2029 time_t timestamp, guint prefix_flags,
2018 unsigned mucnicklen) 2030 unsigned mucnicklen)
2019 { 2031 {
2036 if (!(prefix & 2048 if (!(prefix &
2037 ~HBB_PREFIX_NOFLAG & ~HBB_PREFIX_HLIGHT & ~HBB_PREFIX_HLIGHT_OUT & 2049 ~HBB_PREFIX_NOFLAG & ~HBB_PREFIX_HLIGHT & ~HBB_PREFIX_HLIGHT_OUT &
2038 ~HBB_PREFIX_PGPCRYPT & ~HBB_PREFIX_OTRCRYPT)) 2050 ~HBB_PREFIX_PGPCRYPT & ~HBB_PREFIX_OTRCRYPT))
2039 prefix |= HBB_PREFIX_IN; 2051 prefix |= HBB_PREFIX_IN;
2040 2052
2053 #ifdef HAVE_GLIB_REGEX
2041 if (url_regex) 2054 if (url_regex)
2042 scr_LogUrls(text); 2055 scr_LogUrls(text);
2056 #endif
2043 scr_WriteMessage(jidfrom, text, timestamp, prefix, mucnicklen); 2057 scr_WriteMessage(jidfrom, text, timestamp, prefix, mucnicklen);
2044 } 2058 }
2045 2059
2046 void scr_WriteOutgoingMessage(const char *jidto, const char *text, guint prefix) 2060 void scr_WriteOutgoingMessage(const char *jidto, const char *text, guint prefix)
2047 { 2061 {