From: Francois Fleuret Date: Mon, 28 Jan 2013 15:30:57 +0000 (+0100) Subject: Added the full usage + now initializes full_line. X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=17557f7799a9b15adab76086f1f22481f1d10bd1;p=mymail.git Added the full usage + now initializes full_line. --- diff --git a/mymail.c b/mymail.c index 001d14d..2617d02 100644 --- a/mymail.c +++ b/mymail.c @@ -88,12 +88,26 @@ void *safe_malloc(size_t n) { /*********************************************************************/ -void usage(FILE *out) { +void print_version(FILE *out) { fprintf(out, "mymail version %s (%s)\n", VERSION, UNAME); +} + +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, "\n"); + fprintf(out, " -h, --help\n"); + fprintf(out, " show this help\n"); + fprintf(out, " -v, --version\n"); + 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"); } /*********************************************************************/ @@ -195,6 +209,7 @@ void index_mbox(const char *input_filename, position_in_file = 0; end_of_full_line = 0; + full_line[0] = '\0'; while(fgets(raw_line, BUFFER_SIZE, file)) { if(strncmp(raw_line, "From ", 5) == 0) { @@ -308,7 +323,8 @@ enum { static struct option long_options[] = { { "help", no_argument, 0, 'h' }, - { "db-file", 1, 0, 'p' }, + { "version", no_argument, 0, 'v' }, + { "db-file", 1, 0, 'd' }, { "search-pattern", 1, 0, 's' }, { "index", 0, 0, 'i' }, { 0, 0, 0, 0 } @@ -340,7 +356,7 @@ int main(int argc, char **argv) { setlocale(LC_ALL, ""); - while ((c = getopt_long(argc, argv, "hip:s:", + while ((c = getopt_long(argc, argv, "hvip:s:", long_options, NULL)) != -1) { switch(c) { @@ -349,13 +365,17 @@ int main(int argc, char **argv) { show_help = 1; break; + case 'v': + print_version(stdout); + break; + case 'i': action_index = 1; break; case 'p': db_filename = strdup(optarg); - printf("db_filename=\"%s\"\n", db_filename); + /* printf("db_filename=\"%s\"\n", db_filename); */ break; case 's': @@ -379,12 +399,12 @@ int main(int argc, char **argv) { } if(error) { - usage(stderr); + print_usage(stderr); exit(EXIT_FAILURE); } if(show_help) { - usage(stdout); + print_usage(stdout); exit(EXIT_SUCCESS); } @@ -436,11 +456,6 @@ int main(int argc, char **argv) { exit(EXIT_FAILURE); } - /* printf("Starting search in %s for field \"%s\" matching \"%s\".\n", */ - /* db_filename, */ - /* search_name, */ - /* search_regexp_string); */ - db_file = fopen(db_filename, "r"); if(!db_file) {