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 To use it as a super-history-search for bash:
25 mymail --bash <(history)
38 #include <sys/ioctl.h>
45 #define VERSION "1.1.7"
47 #define BUFFER_SIZE 16384
49 /********************************************************************/
51 /* malloc with error checking. */
53 void *safe_malloc(size_t n) {
57 "mymail: can not allocate memory: %s\n", strerror(errno));
63 /*********************************************************************/
65 void usage(FILE *out) {
67 fprintf(out, "mymail version %s (%s)\n", VERSION, UNAME);
68 fprintf(out, "Written by Francois Fleuret <francois@fleuret.org>.\n");
70 fprintf(out, "Usage: mymail [options] [<filename1> [<filename2> ...]]\n");
74 void read_file(const char *input_filename,
75 int nb_lines_max, int *nb_lines) {
77 char raw_line[BUFFER_SIZE];
82 file = fopen(input_filename, "r");
85 fprintf(stderr, "mymail: Can not open `%s'.\n", input_filename);
89 while(*nb_lines < nb_lines_max && fgets(raw_line, BUFFER_SIZE, file)) {
91 fgets(raw_line + l, BUFFER_SIZE - l, file);
92 for(s = raw_line + strlen(raw_line) - 1; s > raw_line && *s == '\n'; s--) {
95 /* store_line(hash_table, raw_line, nb_lines, lines); */
101 /*********************************************************************/
103 /* For long options that have no equivalent short option, use a
104 non-character as a pseudo short option, starting with CHAR_MAX + 1. */
107 OPT_BASH_MODE = CHAR_MAX + 1
110 static struct option long_options[] = {
111 { "help", no_argument, 0, 'h' },
115 int main(int argc, char **argv) {
116 int error = 0, show_help = 0;
119 setlocale(LC_ALL, "");
121 while ((c = getopt_long(argc, argv, "o:s:x:vwmqf:ibzdeajyunt:r:l:c:-h",
122 long_options, NULL)) != -1) {