+ // There must be a more elegant way of moving the cursor at a
+ // location met during display
+
+ int cursor_x = 0;
+
+ if(title) {
+ addstr(title);
+ addstr(" ");
+ cursor_x += strlen(title) + 1;
+ }
+
+ sprintf(buffer, "%d/%d ", nb_printed_lines, nb_lines);
+ addstr(buffer);
+ cursor_x += strlen(buffer);
+
+ addnstr(pattern, cursor_position);
+ cursor_x += cursor_position;
+
+ if(pattern[cursor_position]) {
+ addstr(pattern + cursor_position);
+ } else {
+ addstr(" ");
+ }
+
+ if(use_regexp || case_sensitive) {
+ addstr("[");
+ if(use_regexp) {
+ addstr("regexp");
+ }
+
+ if(case_sensitive) {
+ if(use_regexp) {
+ addstr(",");
+ }
+ addstr("case");
+ }
+ addstr("]");
+ }
+
+ move(0, cursor_x);
+
+ if(with_colors) {
+ attroff(COLOR_PAIR(COLOR_MODELINE));
+ } else {
+ attroff(A_REVERSE);
+ }
+
+ // We are done
+
+ refresh();
+ free_matcher(&matcher);
+}
+
+//////////////////////////////////////////////////////////////////////
+
+void read_file(const char *input_filename,
+ int nb_lines_max, int *nb_lines, char **lines,
+ int hash_table_size, int *hash_table) {
+
+ char buffer[buffer_size], raw_line[buffer_size];;
+
+ ifstream file(input_filename);
+
+ if(file.fail()) {
+ cerr << "Can not open " << input_filename << endl;
+ exit(1);
+ }
+
+ while(*nb_lines < nb_lines_max && !file.eof()) {
+
+ file.getline(raw_line, buffer_size);
+
+ if(raw_line[0]) {
+
+ if(file.fail()) {
+ cerr << "Line too long:" << endl;
+ cerr << raw_line << endl;
+ exit(1);
+ }
+
+ char *s, *t;
+ const char *u;
+
+ s = buffer;
+ t = raw_line;
+ while(*t) {
+ u = unctrl(*t++);
+ while(*u) { *s++ = *u++; }
+ }
+ *s = '\0';
+
+ s = buffer;
+
+ if(zsh_history && *s == ':') {
+ while(*s && *s != ';') s++;
+ if(*s == ';') s++;
+ }
+
+ if(bash_history && (*s == ' ' || (*s >= '0' && *s <= '9'))) {
+ while(*s == ' ' || (*s >= '0' && *s <= '9')) s++;
+ }
+
+ int dup;
+
+ if(hash_table) {
+ dup = test_and_add(s, *nb_lines, lines, hash_table, hash_table_size);
+ } else {
+ dup = -1;
+ }
+
+ if(dup < 0) {
+ lines[*nb_lines] = new char[strlen(s) + 1];
+ strcpy(lines[*nb_lines], s);
+ } else {
+ // The string was already in there, so we do not allocate a
+ // new string but use the pointer to the first occurence of it
+ lines[*nb_lines] = lines[dup];
+ lines[dup] = 0;
+ }
+
+ (*nb_lines)++;
+ }
+ }