3 * Copyright (c) 2013 Francois Fleuret
4 * Written by Francois Fleuret <francois@fleuret.org>
6 * This file is part of mymail.
8 * mymail is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 3 as
10 * published by the Free Software Foundation.
12 * mymail is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with mymail. If not, see <http://www.gnu.org/licenses/>.
24 This command is a dumb mail indexer. It can either (1) scan
25 directories containing mbox files, and create a db file containing
26 for each mail a list of fields computed from the header, or (2)
27 read such a db file and get all the mails matching regexp-defined
28 conditions on the fields.
30 It is low-tech, simple, light and fast.
48 #define MYMAIL_DB_MAGIC_TOKEN "mymail_index_file"
49 #define VERSION "0.9.1"
51 #define MAX_NB_SEARCH_CONDITIONS 10
53 #define BUFFER_SIZE 65536
54 #define TOKEN_BUFFER_SIZE 1024
56 regex_t leading_from_line_regexp;
59 char *db_filename_regexp_string;
61 char *db_filename_list;
62 char output_filename[PATH_MAX + 1];
70 /********************************************************************/
85 static char *field_names[] = {
97 /********************************************************************/
99 struct search_condition {
103 time_t interval_start, interval_stop;
106 /********************************************************************/
108 struct parsable_field {
114 static struct parsable_field fields_to_parse[] = {
118 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
123 "^\\([Ff][Rr][Oo][Mm]:\\|[Rr][Ee][Pp][Ll][Yy]-[Tt][Oo]:\\|[Ss][Ee][Nn][Dd][Ee][Rr]:\\)",
124 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
129 "^\\([Tt][Oo]\\|[Cc][Cc]\\|[Bb][Cc][Cc]\\): ",
130 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
135 "^[Ss][Uu][Bb][Jj][Ee][Cc][Tt]: ",
136 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
141 "^[Dd][Aa][Tt][Ee]: ",
142 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
147 /********************************************************************/
149 int xor(int a, int b) {
150 return (a && !b) || (!a && b);
153 char *parse_token(char *token_buffer, size_t token_buffer_size,
154 char separator, char *string) {
155 char *u = token_buffer;
156 while(u < token_buffer + token_buffer_size - 1 && *string &&
157 *string != separator) {
158 *(u++) = *(string++);
160 while(*string == separator) string++;
165 void remove_eof(char *c) {
166 while(*c && *c != '\n' && *c != '\r') c++;
170 /********************************************************************/
172 /* malloc with error checking. */
174 void *safe_malloc(size_t n) {
178 "mymail: cannot allocate memory: %s\n", strerror(errno));
184 /*********************************************************************/
186 void print_version(FILE *out) {
187 fprintf(out, "mymail version %s (%s)\n", VERSION, UNAME);
190 void print_usage(FILE *out) {
192 fprintf(out, "Written by Francois Fleuret <francois@fleuret.org>.\n");
194 fprintf(out, "Usage: mymail [options] [<mbox dir1> [<mbox dir2> ...]|<db file1> [<db file2> ...]]\n");
196 fprintf(out, " -h, --help\n");
197 fprintf(out, " show this help\n");
198 fprintf(out, " -v, --version\n");
199 fprintf(out, " print the version number\n");
200 fprintf(out, " -q, --quiet\n");
201 fprintf(out, " do not print information during search\n");
202 fprintf(out, " -p <db filename pattern>, --db-pattern <db filename pattern>\n");
203 fprintf(out, " set the db filename pattern for recursive search\n");
204 fprintf(out, " -r <db root path>, --db-root <db root path>\n");
205 fprintf(out, " set the db root path for recursive search\n");
206 fprintf(out, " -l <db filename list>, --db-list <db filename list>\n");
207 fprintf(out, " set the semicolon-separated list of db files for search\n");
208 fprintf(out, " -s <search pattern>, --search <search pattern>\n");
209 fprintf(out, " search for matching mails in the db file\n");
210 fprintf(out, " -d <db filename>, --db-file <db filename>\n");
211 fprintf(out, " set the db filename for indexing\n");
212 fprintf(out, " -i, --index\n");
213 fprintf(out, " index mails\n");
214 fprintf(out, " -o <output filename>, --output <output filename>\n");
215 fprintf(out, " set the result file, use stdout if unset\n");
218 /*********************************************************************/
220 time_t time_for_past_day(int day) {
226 delta_day = (7 + tm->tm_wday - day) % 7 + 1;
227 return t - delta_day * 3600 * 24 + tm->tm_sec + 60 * tm->tm_min + 3600 * tm->tm_hour;
230 /*********************************************************************/
232 int ignore_entry(const char *name) {
234 /* strcmp(name, ".") == 0 || */
235 /* strcmp(name, "..") == 0 || */
236 (name[0] == '.' && name[1] != '/');
239 int is_a_leading_from_line(char *s) {
240 return strncmp(s, "From ", 5) == 0 &&
241 regexec(&leading_from_line_regexp, s, 0, 0, 0) == 0;
244 int mbox_line_match_search(struct search_condition *condition,
245 int mbox_id, char *mbox_value) {
247 if(condition->field_id == ID_INTERVAL) {
248 if(mbox_id == ID_LEADING_LINE) {
254 while(*c && *c != ' ') c++; while(*c && *c == ' ') c++;
255 strptime(c, "%a %b %e %k:%M:%S %Y", &tm);
258 return (t >= condition->interval_start &&
259 (condition->interval_stop == 0 ||
260 t <= condition->interval_stop));
268 (condition->field_id == mbox_id)
272 (condition->field_id == ID_PARTICIPANT && (mbox_id == ID_LEADING_LINE ||
273 mbox_id == ID_FROM ||
277 (condition->field_id == ID_FROM && mbox_id == ID_LEADING_LINE)
281 regexec(&condition->regexp, mbox_value, 0, 0, 0) == 0;
285 void update_body_hits(char *mail_filename, int position_in_mail,
286 int nb_search_conditions, struct search_condition *search_conditions,
287 int nb_body_conditions,
291 int last_mbox_line_was_empty;
292 char raw_mbox_line[BUFFER_SIZE];
298 mail_file = fopen(mail_filename, "r");
302 "mymail: Cannot open mbox '%s' for body scan.\n",
307 fseek(mail_file, position_in_mail, SEEK_SET);
309 if(fgets(raw_mbox_line, BUFFER_SIZE, mail_file)) {
310 while(nb_body_hits < nb_body_conditions) {
311 last_mbox_line_was_empty = (raw_mbox_line[0] == '\n');
313 if(last_mbox_line_was_empty) { header = 0; }
316 for(n = 0; n < nb_search_conditions; n++) {
317 if(search_conditions[n].field_id == ID_BODY && !hits[n]) {
319 (regexec(&search_conditions[n].regexp, raw_mbox_line, 0, 0, 0) == 0);
327 if(!fgets(raw_mbox_line, BUFFER_SIZE, mail_file) ||
328 (last_mbox_line_was_empty &&
329 is_a_leading_from_line(raw_mbox_line)))
337 void search_in_db(const char *db_filename,
338 int nb_search_conditions,
339 struct search_condition *search_conditions,
342 int hits[MAX_NB_SEARCH_CONDITIONS];
343 char raw_db_line[BUFFER_SIZE];
344 char raw_mbox_line[BUFFER_SIZE];
345 char current_mail_filename[PATH_MAX + 1];
346 unsigned long int current_position_in_mail;
347 char mbox_name[TOKEN_BUFFER_SIZE], *mbox_value;
349 int already_written, m, n;
350 int last_mbox_line_was_empty;
351 int nb_body_conditions, nb_fulfilled_body_conditions;
355 printf("Searching in '%s' ... ", db_filename);
359 db_file = fopen(db_filename, "r");
363 "mymail: Cannot open \"%s\" for reading: %s\n",
369 if(fgets(raw_db_line, BUFFER_SIZE, db_file)) {
370 if(strncmp(raw_db_line, MYMAIL_DB_MAGIC_TOKEN, strlen(MYMAIL_DB_MAGIC_TOKEN))) {
372 "mymail: Header line in '%s' does not match the mymail db format.\n",
378 "mymail: Cannot read the header line in '%s'.\n",
383 current_position_in_mail = 0;
386 for(n = 0; n < nb_search_conditions; n++) { hits[n] = 0; }
388 nb_body_conditions = 0;
389 for(n = 0; n < nb_search_conditions; n++) {
390 if(search_conditions[n].field_id == ID_BODY) {
391 nb_body_conditions++;
395 strcpy(current_mail_filename, "");
397 while(fgets(raw_db_line, BUFFER_SIZE, db_file)) {
398 mbox_value = parse_token(mbox_name, TOKEN_BUFFER_SIZE, ' ', raw_db_line);
400 if(strcmp("mail", mbox_name) == 0) {
401 char position_in_file_string[TOKEN_BUFFER_SIZE];
403 if(current_mail_filename[0]) {
405 /* We first check all conditions but the body ones */
407 for(n = 0; n < nb_search_conditions &&
408 ((search_conditions[n].field_id == ID_BODY) ||
409 xor(hits[n], search_conditions[n].negation)); n++);
411 if(n == nb_search_conditions) {
413 /* all conditions but the body ones are fine, check the body
416 if(nb_body_conditions > 0) {
417 update_body_hits(current_mail_filename, current_position_in_mail,
418 nb_search_conditions, search_conditions,
423 nb_fulfilled_body_conditions = 0;
425 for(n = 0; n < nb_search_conditions; n++) {
426 if(search_conditions[n].field_id == ID_BODY &&
427 xor(hits[n], search_conditions[n].negation)) {
428 nb_fulfilled_body_conditions++;
432 if(nb_body_conditions == nb_fulfilled_body_conditions) {
435 mail_file = fopen(current_mail_filename, "r");
439 "mymail: Cannot open mbox '%s' for mail extraction.\n",
440 current_mail_filename);
444 fseek(mail_file, current_position_in_mail, SEEK_SET);
446 if(fgets(raw_mbox_line, BUFFER_SIZE, mail_file)) {
447 last_mbox_line_was_empty = 0;
448 fprintf(output_file, "%s", raw_mbox_line);
450 if(!fgets(raw_mbox_line, BUFFER_SIZE, mail_file) ||
451 (last_mbox_line_was_empty &&
452 is_a_leading_from_line(raw_mbox_line))
455 last_mbox_line_was_empty = (raw_mbox_line[0] == '\n');
456 fprintf(output_file, "%s", raw_mbox_line);
465 for(n = 0; n < nb_search_conditions; n++) { hits[n] = 0; }
467 mbox_value = parse_token(position_in_file_string, TOKEN_BUFFER_SIZE, ' ', mbox_value);
468 mbox_value = parse_token(current_mail_filename, TOKEN_BUFFER_SIZE, ' ', mbox_value);
469 current_position_in_mail = atol(position_in_file_string);
470 remove_eof(current_mail_filename);
476 for(m = 0; (m < MAX_ID) && mbox_id == -1; m++) {
477 if(strncmp(field_names[m], mbox_name, strlen(mbox_name)) == 0) {
481 for(n = 0; n < nb_search_conditions; n++) {
482 hits[n] |= mbox_line_match_search(&search_conditions[n],
483 mbox_id, mbox_value);
496 void recursive_search_in_db(const char *entry_name, regex_t *db_filename_regexp,
497 int nb_search_conditions,
498 struct search_condition *search_conditions,
501 struct dirent *dir_e;
503 char subname[PATH_MAX + 1];
505 if(lstat(entry_name, &sb) != 0) {
507 "mymail: Cannot stat \"%s\": %s\n",
513 dir = opendir(entry_name);
516 while((dir_e = readdir(dir))) {
517 if(!ignore_entry(dir_e->d_name)) {
518 snprintf(subname, PATH_MAX, "%s/%s", entry_name, dir_e->d_name);
519 recursive_search_in_db(subname, db_filename_regexp,
520 nb_search_conditions, search_conditions,
528 const char *s = entry_name, *filename = entry_name;
529 while(*s) { if(*s == '/') { filename = s+1; } s++; }
531 if(regexec(db_filename_regexp, filename, 0, 0, 0) == 0) {
532 search_in_db(entry_name, nb_search_conditions, search_conditions, output_file);
537 /*********************************************************************/
539 void index_one_mbox_line(int nb_fields_to_parse, struct parsable_field *fields_to_parse,
540 char *raw_mbox_line, FILE *db_file) {
543 for(f = 0; f < nb_fields_to_parse; f++) {
544 if(regexec(&fields_to_parse[f].regexp, raw_mbox_line, 1, &matches, 0) == 0) {
545 fprintf(db_file, "%s %s\n",
546 field_names[fields_to_parse[f].id],
547 raw_mbox_line + matches.rm_eo);
552 void index_mbox(const char *mbox_filename,
553 int nb_fields_to_parse, struct parsable_field *fields_to_parse,
555 char raw_mbox_line[BUFFER_SIZE], full_line[BUFFER_SIZE];
556 char *end_of_full_line;
558 int in_header, new_header, last_mbox_line_was_empty;
559 unsigned long int position_in_file;
561 file = fopen(mbox_filename, "r");
564 fprintf(stderr, "mymail: Cannot open '%s'.\n", mbox_filename);
565 if(paranoid) { exit(EXIT_FAILURE); }
572 position_in_file = 0;
573 end_of_full_line = 0;
575 last_mbox_line_was_empty = 1;
577 while(fgets(raw_mbox_line, BUFFER_SIZE, file)) {
578 if(last_mbox_line_was_empty &&
579 is_a_leading_from_line(raw_mbox_line)) {
582 "Got a ^\"From \" in the header in %s:%lu.\n",
583 mbox_filename, position_in_file);
584 fprintf(stderr, "%s", raw_mbox_line);
585 if(paranoid) { exit(EXIT_FAILURE); }
589 } else if(raw_mbox_line[0] == '\n') {
590 if(in_header) { in_header = 0; }
593 last_mbox_line_was_empty = (raw_mbox_line[0] == '\n');
597 fprintf(db_file, "mail %lu %s\n", position_in_file, mbox_filename);
601 if(raw_mbox_line[0] == ' ' || raw_mbox_line[0] == '\t') {
602 char *start = raw_mbox_line;
603 while(*start == ' ' || *start == '\t') start++;
604 *(end_of_full_line++) = ' ';
605 strcpy(end_of_full_line, start);
606 while(*end_of_full_line && *end_of_full_line != '\n') {
609 *end_of_full_line = '\0';
614 if(!((raw_mbox_line[0] >= 'a' && raw_mbox_line[0] <= 'z') ||
615 (raw_mbox_line[0] >= 'A' && raw_mbox_line[0] <= 'Z'))) {
617 "Header line syntax error %s:%lu.\n",
618 mbox_filename, position_in_file);
619 fprintf(stderr, "%s", raw_mbox_line);
624 index_one_mbox_line(nb_fields_to_parse, fields_to_parse, full_line, db_file);
627 end_of_full_line = full_line;
628 strcpy(end_of_full_line, raw_mbox_line);
629 while(*end_of_full_line && *end_of_full_line != '\n') {
632 *end_of_full_line = '\0';
637 position_in_file += strlen(raw_mbox_line);
643 void recursive_index_mbox(FILE *db_file,
644 const char *entry_name,
645 int nb_fields_to_parse, struct parsable_field *fields_to_parse) {
647 struct dirent *dir_e;
649 char subname[PATH_MAX + 1];
651 if(lstat(entry_name, &sb) != 0) {
653 "mymail: Cannot stat \"%s\": %s\n",
659 dir = opendir(entry_name);
662 while((dir_e = readdir(dir))) {
663 if(!ignore_entry(dir_e->d_name)) {
664 snprintf(subname, PATH_MAX, "%s/%s", entry_name, dir_e->d_name);
665 recursive_index_mbox(db_file, subname, nb_fields_to_parse, fields_to_parse);
670 index_mbox(entry_name, nb_fields_to_parse, fields_to_parse, db_file);
674 /*********************************************************************/
676 /* For long options that have no equivalent short option, use a
677 non-character as a pseudo short option, starting with CHAR_MAX + 1. */
679 OPT_BASH_MODE = CHAR_MAX + 1
682 static struct option long_options[] = {
683 { "help", no_argument, 0, 'h' },
684 { "version", no_argument, 0, 'v' },
685 { "quiet", no_argument, 0, 'q' },
686 { "db-file", 1, 0, 'd' },
687 { "db-pattern", 1, 0, 'p' },
688 { "db-root", 1, 0, 'r' },
689 { "db-list", 1, 0, 'l' },
690 { "search", 1, 0, 's' },
691 { "index", 0, 0, 'i' },
692 { "output", 1, 0, 'o' },
696 /*********************************************************************/
698 void init_condition(struct search_condition *condition, char *string) {
699 char full_search_field[TOKEN_BUFFER_SIZE], *search_field;
702 string = parse_token(full_search_field, TOKEN_BUFFER_SIZE, ' ', string);
703 search_field = full_search_field;
705 if(search_field[0] == '!') {
707 condition->negation = 1;
709 condition->negation = 0;
712 if(strcmp(search_field, "6h") == 0) {
713 condition->field_id = ID_INTERVAL;
714 condition->interval_start = time(0) - 3600 * 6;
715 condition->interval_stop = 0;
718 else if(strcmp(search_field, "24h") == 0 ||
719 strcmp(search_field, "today") == 0) {
720 condition->field_id = ID_INTERVAL;
721 condition->interval_start = time(0) - 3600 * 24;
722 condition->interval_stop = 0;
725 else if(strcmp(search_field, "monday") == 0) {
726 condition->field_id = ID_INTERVAL;
727 condition->interval_start = time_for_past_day(1);
728 condition->interval_stop = condition->interval_start + 3600 * 24;
731 else if(strcmp(search_field, "tuesday") == 0) {
732 condition->field_id = ID_INTERVAL;
733 condition->interval_start = time_for_past_day(2);
734 condition->interval_stop = condition->interval_start + 3600 * 24;
737 else if(strcmp(search_field, "wednesday") == 0) {
738 condition->field_id = ID_INTERVAL;
739 condition->interval_start = time_for_past_day(3);
740 condition->interval_stop = condition->interval_start + 3600 * 24;
743 else if(strcmp(search_field, "thursday") == 0) {
744 condition->field_id = ID_INTERVAL;
745 condition->interval_start = time_for_past_day(4);
746 condition->interval_stop = condition->interval_start + 3600 * 24;
749 else if(strcmp(search_field, "friday") == 0) {
750 condition->field_id = ID_INTERVAL;
751 condition->interval_start = time_for_past_day(5);
752 condition->interval_stop = condition->interval_start + 3600 * 24;
755 else if(strcmp(search_field, "saturday") == 0) {
756 condition->field_id = ID_INTERVAL;
757 condition->interval_start = time_for_past_day(6);
758 condition->interval_stop = condition->interval_start + 3600 * 24;
761 else if(strcmp(search_field, "sunday") == 0) {
762 condition->field_id = ID_INTERVAL;
763 condition->interval_start = time_for_past_day(7);
764 condition->interval_stop = condition->interval_start + 3600 * 24;
767 else if(strcmp(search_field, "yesterday") == 0) {
768 condition->field_id = ID_INTERVAL;
769 condition->interval_start = time(0) - 2 * 3600 * 24;
770 condition->interval_stop = condition->interval_start + 3600 * 24;
774 condition->field_id = -1;
776 for(m = 0; (m < MAX_ID) && condition->field_id == -1; m++) {
777 if(strncmp(field_names[m], search_field, strlen(search_field)) == 0) {
778 condition->field_id = m;
782 if(condition->field_id == -1) {
784 "mymail: Syntax error in field name \"%s\".\n",
789 if(regcomp(&condition->regexp,
793 "mymail: Syntax error in regexp \"%s\" for field \"%s\".\n",
795 field_names[condition->field_id]);
801 void free_condition(struct search_condition *condition) {
802 if(condition->field_id != ID_INTERVAL) {
803 regfree(&condition->regexp);
807 /*********************************************************************/
808 /*********************************************************************/
809 /*********************************************************************/
811 int main(int argc, char **argv) {
812 int error = 0, show_help = 0;
813 const int nb_fields_to_parse = sizeof(fields_to_parse) / sizeof(struct parsable_field);
816 int nb_search_conditions;
818 struct search_condition search_conditions[MAX_NB_SEARCH_CONDITIONS];
820 if(regcomp(&leading_from_line_regexp,
821 "^From [^ ]* \\(Mon\\|Tue\\|Wed\\|Thu\\|Fri\\|Sat\\|Sun\\) \\(Jan\\|Feb\\|Mar\\|Apr\\|May\\|Jun\\|Jul\\|Aug\\|Sep\\|Oct\\|Nov\\|Dec\\) [ 123][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9][0-9][0-9][0-9]\n$",
824 "mymail: Cannot compile leading \"from\" line regexp. That is strange.\n");
832 db_filename_list = 0;
835 setlocale(LC_ALL, "");
837 nb_search_conditions = 0;
839 while ((c = getopt_long(argc, argv, "hvqip:s:d:r:l:o:",
840 long_options, NULL)) != -1) {
849 print_version(stdout);
861 db_filename = strdup(optarg);
865 db_filename_regexp_string = strdup(optarg);
869 strncpy(output_filename, optarg, PATH_MAX);
873 db_root_path = strdup(optarg);
877 db_filename_list = strdup(optarg);
881 if(nb_search_conditions == MAX_NB_SEARCH_CONDITIONS) {
882 fprintf(stderr, "mymail: Too many search patterns.\n");
885 init_condition(&search_conditions[nb_search_conditions], optarg);
886 nb_search_conditions++;
896 char *default_db_filename = getenv("MYMAIL_DB_FILE");
898 if(!default_db_filename) {
899 default_db_filename = "mymail.db";
902 db_filename = strdup(default_db_filename);
905 if(!db_filename_regexp_string) {
906 char *default_db_filename_regexp_string = getenv("MYMAIL_DB_PATTERN");
908 if(!default_db_filename_regexp_string) {
909 default_db_filename_regexp_string = "^mymail.db$";
912 db_filename_regexp_string = strdup(default_db_filename_regexp_string);
916 char *default_db_root_path = getenv("MYMAIL_DB_ROOT");
918 if(default_db_root_path) {
919 db_root_path = strdup(default_db_root_path);
923 if(!db_filename_list) {
924 char *default_db_filename_list = getenv("MYMAIL_DB_LIST");
926 if(default_db_filename_list) {
927 db_filename_list = strdup(default_db_filename_list);
931 if(output_filename[0]) {
932 output_file = fopen(output_filename, "w");
936 "mymail: Cannot open result file \"%s\" for writing: %s\n",
942 output_file = stdout;
959 db_file = fopen(db_filename, "w");
963 "mymail: Cannot open \"%s\" for writing: %s\n",
969 for(f = 0; f < nb_fields_to_parse; f++) {
970 if(regcomp(&fields_to_parse[f].regexp,
971 fields_to_parse[f].regexp_string,
974 "mymail: Syntax error in regexp \"%s\" for field \"%s\".\n",
975 fields_to_parse[f].regexp_string,
976 field_names[fields_to_parse[f].id]);
981 fprintf(db_file, "%s version_%s raw\n", MYMAIL_DB_MAGIC_TOKEN, VERSION);
983 while(optind < argc) {
984 recursive_index_mbox(db_file,
986 nb_fields_to_parse, fields_to_parse);
993 for(f = 0; f < nb_fields_to_parse; f++) {
994 regfree(&fields_to_parse[f].regexp);
1000 if(nb_search_conditions > 0) {
1002 /* Recursive search if db_root_path is set */
1005 regex_t db_filename_regexp;
1006 if(regcomp(&db_filename_regexp,
1007 db_filename_regexp_string,
1010 "mymail: Syntax error in regexp \"%s\".\n",
1011 db_filename_regexp_string);
1015 recursive_search_in_db(db_root_path, &db_filename_regexp,
1016 nb_search_conditions, search_conditions,
1019 regfree(&db_filename_regexp);
1022 /* Search in all db files listed in db_filename_list */
1024 if(db_filename_list) {
1025 char db_filename[PATH_MAX + 1];
1028 s = db_filename_list;
1031 s = parse_token(db_filename, PATH_MAX + 1, ';', s);
1033 if(db_filename[0]) {
1034 search_in_db(db_filename, nb_search_conditions, search_conditions, output_file);
1039 /* Search in all db files listed in the command arguments */
1041 while(optind < argc) {
1042 search_in_db(argv[optind], nb_search_conditions, search_conditions, output_file);
1048 for(n = 0; n < nb_search_conditions; n++) {
1049 free_condition(&search_conditions[n]);
1052 if(output_file != stdout) {
1053 fflush(output_file);
1054 fclose(output_file);
1058 free(db_filename_regexp_string);
1060 free(db_filename_list);
1062 regfree(&leading_from_line_regexp);