From: Francois Fleuret Date: Fri, 1 Feb 2013 23:23:16 +0000 (+0100) Subject: Now handle negative search constraints with a leading '!'. X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=3702c6913e188ff3a7f7904a882c2737d3651ff6;p=mymail.git Now handle negative search constraints with a leading '!'. --- diff --git a/mymail.c b/mymail.c index 35a0344..b114e8b 100644 --- a/mymail.c +++ b/mymail.c @@ -181,7 +181,9 @@ void search_in_db(int nb_search_patterns, char *position_in_file_string; char *mail_filename; - for(n = 0; n < nb_search_patterns && hits[n]; n++); + for(n = 0; n < nb_search_patterns && + ((hits[n] && !search_requests[n].negation) || + (!hits[n] && search_requests[n].negation)); n++); if(n == nb_search_patterns) { FILE *mail_file; @@ -617,6 +619,13 @@ int main(int argc, char **argv) { for(n = 0; n < nb_search_patterns; n++) { search_regexp_string = segment_next_field(search_pattern[n]); + if(search_pattern[n][0] == '!') { + search_pattern[n]++; + search_requests[n].negation = 1; + } else { + search_requests[n].negation = 0; + } + search_requests[n].field_id = -1; for(m = 0; (m < MAX_ID) && search_requests[n].field_id == -1; m++) { if(strncmp(field_names[m], search_pattern[n], strlen(search_pattern[n])) == 0) {