Changeset 41c9a96
- Timestamp:
- Jul 24, 2009, 12:59:23 AM (15 years ago)
- Branches:
- master, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 64c9165
- Parents:
- ab225e0
- git-author:
- Anders Kaseorg <andersk@mit.edu> (07/24/09 00:51:10)
- git-committer:
- Anders Kaseorg <andersk@mit.edu> (07/24/09 00:59:23)
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
filterelement.c
rd43edd2 r41c9a96 61 61 { 62 62 char * val = owl_filterelement_get_field(m, fe->field); 63 return !owl_regex_compare(&(fe->re), val );63 return !owl_regex_compare(&(fe->re), val, NULL, NULL); 64 64 } 65 65 -
fmtext.c
r4d86e06 r41c9a96 285 285 char attr; 286 286 short fg, bg, pair; 287 int search_results, search_len;288 287 289 288 if (w==NULL) { … … 292 291 } 293 292 294 search_results = (do_search295 ? owl_fmtext_search(f, owl_global_get_search_string(&g))296 : 0);297 search_len = (search_results298 ? strlen(owl_global_get_search_string(&g))299 : 0);300 293 s = f->textbuff; 301 294 /* Set default attributes. */ … … 316 309 tmp = p[0]; 317 310 p[0] = '\0'; 318 if ( search_results) {311 if (owl_global_is_search_active(&g)) { 319 312 /* Search is active, so highlight search results. */ 320 char tmp2 , *ss;321 ss = stristr(s, owl_global_get_search_string(&g));322 while ( ss) {313 char tmp2; 314 int start, end; 315 while (owl_regex_compare(owl_global_get_search_re(&g), s, &start, &end) == 0) { 323 316 /* Found search string, highlight it. */ 324 317 325 tmp2 = s s[0];326 s s[0] = '\0';318 tmp2 = s[start]; 319 s[start] = '\0'; 327 320 waddstr(w, s); 328 s s[0] = tmp2;321 s[start] = tmp2; 329 322 330 323 _owl_fmtext_wattrset(w, attr ^ OWL_FMTEXT_ATTR_REVERSE); 331 324 _owl_fmtext_wcolor_set(w, pair); 332 325 333 tmp2 = s s[search_len];334 s s[search_len] = '\0';335 waddstr(w, s s);336 s s[search_len] = tmp2;326 tmp2 = s[end]; 327 s[end] = '\0'; 328 waddstr(w, s + start); 329 s[end] = tmp2; 337 330 338 331 _owl_fmtext_wattrset(w, attr); 339 332 _owl_fmtext_wcolor_set(w, pair); 340 333 341 s = ss + search_len; 342 ss = stristr(s, owl_global_get_search_string(&g)); 334 s += end; 343 335 } 344 336 } … … 563 555 * insensitive search. 564 556 */ 565 int owl_fmtext_search(owl_fmtext *f, char *string)566 { 567 if ( stristr(f->textbuff, string)) return(1);557 int owl_fmtext_search(owl_fmtext *f, owl_regex *re) 558 { 559 if (owl_regex_compare(re, f->textbuff, NULL, NULL) == 0) return(1); 568 560 return(0); 569 561 } -
functions.c
rab225e0 r41c9a96 2967 2967 /* direction is OWL_DIRECTION_DOWNWARDS or OWL_DIRECTION_UPWARDS or 2968 2968 * OWL_DIRECTION_NONE */ 2969 owl_global_set_search_string(&g, string); 2969 owl_regex re; 2970 2971 if (string && owl_regex_create_quoted(&re, string) == 0) { 2972 owl_global_set_search_re(&g, &re); 2973 owl_regex_free(&re); 2974 } else { 2975 owl_global_set_search_re(&g, NULL); 2976 } 2970 2977 2971 2978 if (direction == OWL_DIRECTION_NONE) … … 3020 3027 for (i=start; i<viewsize && i>=0;) { 3021 3028 m=owl_view_get_element(v, i); 3022 if (owl_message_search(m, owl_global_get_search_ string(&g))) {3029 if (owl_message_search(m, owl_global_get_search_re(&g))) { 3023 3030 owl_global_set_curmsg(&g, i); 3024 3031 owl_function_calculate_topmsg(direction); -
global.c
r898eb15 r41c9a96 65 65 owl_fmtext_init_colorpair_mgr(&(g->cpmgr)); 66 66 g->debug=OWL_DEBUG; 67 g->searchstring=NULL;67 owl_regex_init(&g->search_re); 68 68 g->starttime=time(NULL); /* assumes we call init only a start time */ 69 69 g->lastinputtime=g->starttime; … … 708 708 709 709 int owl_global_is_search_active(owl_global *g) { 710 if (g->searchstring != NULL) return(1); 711 return(0); 712 } 713 714 void owl_global_set_search_string(owl_global *g, char *string) { 715 if (g->searchstring != NULL) owl_free(g->searchstring); 716 g->searchstring = string ? owl_strdup(string) : NULL; 717 } 718 719 char *owl_global_get_search_string(owl_global *g) { 720 if (g->searchstring==NULL) return(""); 721 return(g->searchstring); 710 if (owl_regex_is_set(&g->search_re)) return(1); 711 return(0); 712 } 713 714 void owl_global_set_search_re(owl_global *g, owl_regex *re) { 715 if (owl_regex_is_set(&g->search_re)) { 716 owl_regex_free(&g->search_re); 717 owl_regex_init(&g->search_re); 718 } 719 if (re != NULL) 720 owl_regex_copy(re, &g->search_re); 721 } 722 723 owl_regex *owl_global_get_search_re(owl_global *g) { 724 return &g->search_re; 722 725 } 723 726 -
message.c
r4d86e06 r41c9a96 673 673 * case insensitive because the functions it uses are 674 674 */ 675 int owl_message_search(owl_message *m, char *string)675 int owl_message_search(owl_message *m, owl_regex *re) 676 676 { 677 677 678 678 owl_message_format(m); /* is this necessary? */ 679 679 680 return (owl_fmtext_search(&(m->fmtext->fmtext), string));680 return (owl_fmtext_search(&(m->fmtext->fmtext), re)); 681 681 } 682 682 -
owl.h
r898eb15 r41c9a96 547 547 int newmsgproc_pid; 548 548 int malloced, freed; 549 char *searchstring;549 owl_regex search_re; 550 550 aim_session_t aimsess; 551 551 aim_conn_t bosconn; -
regex.c
rd43edd2 r41c9a96 46 46 } 47 47 48 int owl_regex_compare(owl_regex *re, char *string )48 int owl_regex_compare(owl_regex *re, char *string, int *start, int *end) 49 49 { 50 50 int out, ret; 51 regmatch_t match; 51 52 52 53 /* if the regex is not set we match */ … … 55 56 } 56 57 57 ret=regexec(&(re->re), string, 0, NULL, 0);58 ret=regexec(&(re->re), string, 1, &match, 0); 58 59 out=ret; 59 60 if (re->negate) { 60 61 out=!out; 62 match.rm_so = 0; 63 match.rm_eo = strlen(string); 61 64 } 65 if (start != NULL) *start = match.rm_so; 66 if (end != NULL) *end = match.rm_eo; 62 67 return(out); 63 68 } … … 76 81 void owl_regex_copy(owl_regex *a, owl_regex *b) 77 82 { 78 b->negate=a->negate; 79 b->string=owl_strdup(a->string); 80 memcpy(&(b->re), &(a->re), sizeof(regex_t)); 83 owl_regex_create(b, a->string); 81 84 } 82 85
Note: See TracChangeset
for help on using the changeset viewer.