+ color_fg_modeline = COLOR_WHITE;
+ color_bg_modeline = COLOR_BLACK;
+ color_fg_highlight = COLOR_BLACK;
+ color_bg_highlight = COLOR_YELLOW;
+
+ setlocale(LC_ALL, "");
+
+ char input_filename[buffer_size], output_filename[buffer_size];
+
+ strcpy(input_filename, "");
+ strcpy(output_filename, "");
+
+ int i = 1;
+ int error = 0, show_help = 0;
+
+ while(!error && !show_help && i < argc) {
+
+ if(strcmp(argv[i], "-o") == 0) {
+ check_opt(argc, argv, i, 1, "<output filename>");
+ strncpy(output_filename, argv[i+1], buffer_size);
+ i += 2;
+ }
+
+ else if(strcmp(argv[i], "-s") == 0) {
+ check_opt(argc, argv, i, 1, "<pattern separator>");
+ pattern_separator = argv[i+1][0];
+ i += 2;
+ }
+
+ else if(strcmp(argv[i], "-v") == 0) {
+ output_to_vt_buffer = 1;
+ i++;
+ }
+
+ else if(strcmp(argv[i], "-m") == 0) {
+ with_colors = 0;
+ i++;
+ }
+
+ else if(strcmp(argv[i], "-f") == 0) {
+ check_opt(argc, argv, i, 1, "<input filename>");
+ strncpy(input_filename, argv[i+1], buffer_size);
+ i += 2;
+ }
+
+ else if(strcmp(argv[i], "-i") == 0) {
+ inverse_order = 1;
+ i++;
+ }
+
+ else if(strcmp(argv[i], "-b") == 0) {
+ bash_history = 1;
+ i++;
+ }
+
+ else if(strcmp(argv[i], "-z") == 0) {
+ zsh_history = 1;
+ i++;
+ }
+
+ else if(strcmp(argv[i], "-d") == 0) {
+ remove_duplicates = 1;
+ i++;
+ }
+
+ else if(strcmp(argv[i], "-e") == 0) {
+ use_regexp = 1;
+ i++;
+ }
+
+ else if(strcmp(argv[i], "-a") == 0) {
+ case_sensitive = 1;
+ i++;
+ }
+
+ else if(strcmp(argv[i], "-t") == 0) {
+ check_opt(argc, argv, i, 1, "<title>");
+ delete[] title;
+ title = new char[strlen(argv[i+1]) + 1];
+ strcpy(title, argv[i+1]);
+ i += 2;
+ }
+
+ else if(strcmp(argv[i], "-l") == 0) {
+ check_opt(argc, argv, i, 1, "<maximum number of lines>");
+ nb_lines_max = atoi(argv[i+1]);
+ i += 2;
+ }
+
+ else if(strcmp(argv[i], "-c") == 0) {
+ check_opt(argc, argv, i, 4, "<fg modeline> <bg modeline> <fg highlight> <bg highlight>");
+ color_fg_modeline = atoi(argv[i+1]);
+ color_bg_modeline = atoi(argv[i+2]);
+ color_fg_highlight = atoi(argv[i+3]);
+ color_bg_highlight = atoi(argv[i+4]);
+ i += 5;
+ }
+
+ else if(strcmp(argv[i], "-h") == 0) {
+ show_help = 1;
+ i++;
+ }
+
+ else {
+ cerr << "Unknown argument " << argv[i] << "." << endl;
+ error = 1;
+ }
+ }
+
+ if(show_help || error) {
+ cerr << "Selector version " << VERSION << "-R" << REVISION_NUMBER
+ << endl
+ << "Written by Francois Fleuret <francois@fleuret.org>."
+ << endl
+ << endl
+ << "Usage: " << argv[0] << " [options] -f <file>" << endl
+ << endl
+ << " -h show this help" << endl
+ << " -v inject the selected line in the tty" << endl
+ << " -d remove duplicated lines" << endl
+ << " -b remove the bash history line prefix" << endl
+ << " -z remove the zsh history line prefix" << endl
+ << " -i invert the order of lines" << endl
+ << " -e start in regexp mode" << endl
+ << " -a case sensitive" << endl
+ << " -m monochrome mode" << endl
+ << " -t <title>" << endl
+ << " add a title in the modeline" << endl
+ << " -c <fg modeline> <bg modeline> <fg highlight> <bg highlight>" << endl
+ << " set the display colors" << endl
+ << " -o <output filename>" << endl
+ << " set a file to write the selected line to" << endl
+ << " -s <pattern separator>" << endl
+ << " set the symbol to separate substrings in the pattern" << endl
+ << " -l <max number of lines>" << endl
+ << " set the maximum number of lines to take into account" << endl
+ << endl;
+
+ exit(error);
+ }
+
+ char **lines = new char *[nb_lines_max];
+
+ if(!input_filename[0]) {
+ cerr << "You must specify a input file with -f." << endl;
+ exit(1);