Now handle negative search constraints with a leading '!'.
authorFrancois Fleuret <francois@fleuret.org>
Fri, 1 Feb 2013 23:23:16 +0000 (00:23 +0100)
committerFrancois Fleuret <francois@fleuret.org>
Fri, 1 Feb 2013 23:23:16 +0000 (00:23 +0100)
mymail.c

index 35a0344..b114e8b 100644 (file)
--- 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) {