+ if(action_index) {
+ FILE *db_file = fopen(db_filename, "w");
+ if(!db_file) {
+ fprintf(stderr,
+ "mymail: Can not open \"%s\" for writing: %s\n",
+ db_filename,
+ strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ for(f = 0; f < nb_fields_to_parse; f++) {
+ if(regcomp(&fields_to_parse[f].regexp,
+ fields_to_parse[f].regexp_string,
+ REG_ICASE)) {
+ fprintf(stderr,
+ "mymail: Syntax error in regexp \"%s\" for field \"%s\".\n",
+ fields_to_parse[f].regexp_string,
+ fields_to_parse[f].name);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ while(optind < argc) {
+ process_entry(argv[optind],
+ nb_fields_to_parse, fields_to_parse, db_file);
+ optind++;
+ }
+
+ fclose(db_file);
+
+ for(f = 0; f < nb_fields_to_parse; f++) {
+ regfree(&fields_to_parse[f].regexp);
+ }
+ }
+
+ else {
+ if(search_pattern) {
+ char *search_name;
+ char *search_regexp;
+ search_name = search_pattern;
+ search_regexp = search_pattern;
+ while(*search_regexp && *search_regexp != ' ') search_regexp++;
+ *search_regexp = '\0'; search_regexp++;
+ while(*search_regexp && *search_regexp == ' ') search_regexp++;
+ if(!*search_regexp) {
+ fprintf(stderr,
+ "Syntax error in the search pattern.\n");
+ exit(EXIT_FAILURE);
+ }
+ printf("Starting search in %s for field \"%s\" matching \"%s\".\n",
+ db_filename,
+ search_name,
+ search_regexp);
+ free(search_pattern);
+ }