From a9a15a3dadb15300913fed3234ff5315cf99a4de Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Thu, 31 Jan 2013 17:02:27 +0100 Subject: [PATCH] Cosmetics. --- mymail.c | 52 ++++++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/mymail.c b/mymail.c index a241a86..313b8d5 100644 --- a/mymail.c +++ b/mymail.c @@ -60,8 +60,6 @@ struct parsable_field { char *db_filename; char *db_root_path; -int multi_db_files; - int paranoid; int action_index; @@ -101,7 +99,7 @@ void print_usage(FILE *out) { print_version(out); fprintf(out, "Written by Francois Fleuret .\n"); fprintf(out, "\n"); - fprintf(out, "Usage: mymail [options] [ [ ...]]\n"); + fprintf(out, "Usage: mymail [options] [ [ ...]]\n"); fprintf(out, "\n"); fprintf(out, " -h, --help\n"); fprintf(out, " show this help\n"); @@ -109,10 +107,12 @@ void print_usage(FILE *out) { fprintf(out, " print the version number\n"); fprintf(out, " -i, --index\n"); fprintf(out, " index mails\n"); - fprintf(out, " -d , --db-file \n"); - fprintf(out, " set the data-base file\n"); fprintf(out, " -s , --search \n"); fprintf(out, " search for matching mails in the data-base file\n"); + fprintf(out, " -d , --db-file \n"); + fprintf(out, " set the data-base file\n"); + fprintf(out, " -r , --db-root \n"); + fprintf(out, " set the data-base root path for recursive search\n"); } /*********************************************************************/ @@ -195,7 +195,8 @@ void search_in_db(int nb_search_patterns, else { for(n = 0; n < nb_search_patterns; n++) { hits[n] |= - (strcmp(search_name[n], name) == 0 && regexec(®exp[n], value, 0, 0, 0) == 0); + (strncmp(search_name[n], name, strlen(search_name[n])) == 0 && + regexec(®exp[n], value, 0, 0, 0) == 0); } } } @@ -414,10 +415,9 @@ static struct option long_options[] = { { "help", no_argument, 0, 'h' }, { "version", no_argument, 0, 'v' }, { "db-file", 1, 0, 'd' }, - { "db-root", 1, 0, 'p' }, - { "search-pattern", 1, 0, 's' }, + { "db-root", 1, 0, 'r' }, + { "search", 1, 0, 's' }, { "index", 0, 0, 'i' }, - { "multi-db-files", 0, 0, 'm' }, { 0, 0, 0, 0 } }; @@ -452,17 +452,20 @@ int main(int argc, char **argv) { int nb_search_patterns; char *search_pattern[MAX_NB_SEARCH_PATTERNS]; + /* for(f = 0; f < argc; f++) { */ + /* printf("arg %d \"%s\"\n", f, argv[f]); */ + /* } */ + paranoid = 0; action_index = 0; db_filename = 0; db_root_path = 0; - multi_db_files = 0; setlocale(LC_ALL, ""); nb_search_patterns = 0; - while ((c = getopt_long(argc, argv, "hvimp:s:d:p:", + while ((c = getopt_long(argc, argv, "hvip:s:d:r:", long_options, NULL)) != -1) { switch(c) { @@ -479,15 +482,11 @@ int main(int argc, char **argv) { action_index = 1; break; - case 'm': - multi_db_files = 1; - break; - case 'd': db_filename = strdup(optarg); break; - case 'p': + case 'r': db_root_path = strdup(optarg); break; @@ -509,11 +508,7 @@ int main(int argc, char **argv) { char *default_db_filename = getenv("MYMAIL_DB_FILE"); if(!default_db_filename) { - if(multi_db_files) { - default_db_filename = "mymail.db"; - } else { - default_db_filename = "/tmp/mymail.db"; - } + default_db_filename = "mymail.db"; } db_filename = strdup(default_db_filename); @@ -522,17 +517,18 @@ int main(int argc, char **argv) { if(!db_root_path) { char *default_db_root_path = getenv("MYMAIL_DB_ROOT"); - if(!default_db_root_path) { - if(multi_db_files) { - default_db_root_path = "mymail.db"; - } else { - default_db_root_path = "/tmp/mymail.db"; - } + if(default_db_root_path) { + db_root_path = strdup(default_db_root_path); } + } - db_root_path = strdup(default_db_root_path); + if(!db_root_path) { + fprintf(stderr, + "mymail: db root path is not set\n"); + exit(EXIT_FAILURE); } + if(error) { print_usage(stderr); exit(EXIT_FAILURE); -- 2.20.1