--- /dev/null
+
+#
+# Copyright (c) 2013 Francois Fleuret
+# Written by Francois Fleuret <francois@fleuret.org>
+#
+# This file is part of mymail.
+#
+# mymail is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3 as
+# published by the Free Software Foundation.
+#
+# mymail is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with mymail. If not, see <http://www.gnu.org/licenses/>.
+#
+
+BINARY_PATH = $(DESTDIR)/usr/bin
+MAN_PATH = $(DESTDIR)/usr/share/man/man1
+
+LDFLAGS=-lcurses
+
+UNAME=\"$(shell uname -srmn)\"
+
+ifeq ($(DEBUG),yes)
+ OPTIMIZE_FLAG = -ggdb3 -DDEBUG -fno-omit-frame-pointer
+else
+ OPTIMIZE_FLAG = -O2
+endif
+
+CFLAGS = -Wall -Wextra -ansi -pedantic -DUNAME="$(UNAME)" $(OPTIMIZE_FLAG)
+
+all: mymail
+
+mymail: mymail.o
+ $(CC) -o $@ $^ $(LDFLAGS)
+
+install: mymail
+ mkdir -p $(BINARY_PATH) $(MAN_PATH)
+ install -m 755 mymail $(BINARY_PATH)
+ install -m 755 bash-mymail.sh $(BINARY_PATH)
+ install -m 644 mymail.1 $(MAN_PATH)
+ gzip $(MAN_PATH)/mymail.1
+
+uninstall:
+ rm $(BINARY_PATH)/mymail
+ rm $(BINARY_PATH)/bash-mymail.sh
+ rm $(MAN_PATH)/mymail.1.gz
+
+clean:
+ rm -f *.o mymail
--- /dev/null
+
+/*
+ * Copyright (c) 2013 Francois Fleuret
+ * Written by Francois Fleuret <francois@fleuret.org>
+ *
+ * This file is part of mymail.
+ *
+ * mymail is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * mymail is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with mymail. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+/*
+
+ To use it as a super-history-search for bash:
+ mymail --bash <(history)
+
+*/
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <ncurses.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <termios.h>
+#include <regex.h>
+#include <locale.h>
+#include <getopt.h>
+#include <limits.h>
+
+#define VERSION "1.1.7"
+
+#define BUFFER_SIZE 16384
+
+/********************************************************************/
+
+/* malloc with error checking. */
+
+void *safe_malloc(size_t n) {
+ void *p = malloc(n);
+ if(!p && n != 0) {
+ fprintf(stderr,
+ "mymail: can not allocate memory: %s\n", strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ return p;
+}
+
+/*********************************************************************/
+
+void usage(FILE *out) {
+
+ fprintf(out, "mymail version %s (%s)\n", VERSION, UNAME);
+ fprintf(out, "Written by Francois Fleuret <francois@fleuret.org>.\n");
+ fprintf(out, "\n");
+ fprintf(out, "Usage: mymail [options] [<filename1> [<filename2> ...]]\n");
+ fprintf(out, "\n");
+}
+
+void read_file(const char *input_filename,
+ int nb_lines_max, int *nb_lines) {
+
+ char raw_line[BUFFER_SIZE];
+ char *s;
+ FILE *file;
+ int l;
+
+ file = fopen(input_filename, "r");
+
+ if(!file) {
+ fprintf(stderr, "mymail: Can not open `%s'.\n", input_filename);
+ exit(EXIT_FAILURE);
+ }
+
+ while(*nb_lines < nb_lines_max && fgets(raw_line, BUFFER_SIZE, file)) {
+ l = strlen(raw_line);
+ fgets(raw_line + l, BUFFER_SIZE - l, file);
+ for(s = raw_line + strlen(raw_line) - 1; s > raw_line && *s == '\n'; s--) {
+ *s = '\0';
+ }
+ /* store_line(hash_table, raw_line, nb_lines, lines); */
+ }
+
+ fclose(file);
+}
+
+/*********************************************************************/
+
+/* For long options that have no equivalent short option, use a
+ non-character as a pseudo short option, starting with CHAR_MAX + 1. */
+enum
+{
+ OPT_BASH_MODE = CHAR_MAX + 1
+};
+
+static struct option long_options[] = {
+ { "help", no_argument, 0, 'h' },
+ { 0, 0, 0, 0 }
+};
+
+int main(int argc, char **argv) {
+ int error = 0, show_help = 0;
+ char c;
+
+ setlocale(LC_ALL, "");
+
+ while ((c = getopt_long(argc, argv, "o:s:x:vwmqf:ibzdeajyunt:r:l:c:-h",
+ long_options, NULL)) != -1) {
+
+ switch(c) {
+
+ case 'h':
+ show_help = 1;
+ break;
+
+ default:
+ error = 1;
+ break;
+ }
+ }
+
+ if(error) {
+ usage(stderr);
+ exit(EXIT_FAILURE);
+ }
+
+ if(show_help) {
+ usage(stdout);
+ exit(EXIT_SUCCESS);
+ }
+
+ exit(EXIT_SUCCESS);
+}