/*********************************************************************/
-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 <francois@fleuret.org>.\n");
fprintf(out, "\n");
fprintf(out, "Usage: mymail [options] [<filename1> [<filename2> ...]]\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 filename>, --db-file <db filename>\n");
+ fprintf(out, " set the data-base file\n");
+ fprintf(out, " -s <search pattern>, --search <search pattern>\n");
+ fprintf(out, " search for matching mails in the data-base file\n");
}
/*********************************************************************/
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) {
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 }
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) {
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':
}
if(error) {
- usage(stderr);
+ print_usage(stderr);
exit(EXIT_FAILURE);
}
if(show_help) {
- usage(stdout);
+ print_usage(stdout);
exit(EXIT_SUCCESS);
}
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) {